Skip to content

Commit

Permalink
Update 3 files
Browse files Browse the repository at this point in the history
  • Loading branch information
danilowoz committed Apr 7, 2023
1 parent 93df1ec commit 0ddfe87
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
17 changes: 7 additions & 10 deletions sandpack-client/src/clients/node/client.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Buffer } from "buffer";

import type { ShellCommandOptions } from "@codesandbox/nodebox/build/modules/shell";
import { invariant } from "outvariant";

Expand All @@ -15,21 +13,20 @@ export function generateRandomId() {
return (+`${now}${randomNumber}${count}`).toString(16);
}

export const writeBuffer = (
content: string | Uint8Array,
encoding: BufferEncoding = "utf8"
): Uint8Array => {
export const writeBuffer = (content: string | Uint8Array): Uint8Array => {
if (typeof content === "string") {
return Buffer.from(content, encoding);
return new TextEncoder().encode(content);
} else {
return content;
}
};

export const readBuffer = (content: string | Uint8Array): string => {
if (typeof content === "string") return content;

return Buffer.from(content).toString("utf-8");
if (typeof content === "string") {
return content;
} else {
return new TextDecoder().decode(content);
}
};

export const fromBundlerFilesToFS = (
Expand Down
4 changes: 1 addition & 3 deletions sandpack-client/src/clients/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable no-console,@typescript-eslint/no-explicit-any,prefer-rest-params,@typescript-eslint/explicit-module-boundary-types */

import { Buffer } from "buffer";

import { PREVIEW_LOADED_MESSAGE_TYPE, Nodebox } from "@codesandbox/nodebox";
import type {
FilesMap,
Expand Down Expand Up @@ -383,7 +381,7 @@ export class SandpackNode extends SandpackClient {
Object.entries(modules).forEach(([key, value]) => {
if (
!this._modulesCache.get(key) ||
Buffer.compare(value, this._modulesCache.get(key)) !== 0
readBuffer(value) !== readBuffer(this._modulesCache.get(key))
) {
this.emulator.fs.writeFile(key, value, { recursive: true });
}
Expand Down
5 changes: 0 additions & 5 deletions sandpack-react/.storybook/preview-head.html

This file was deleted.

0 comments on commit 0ddfe87

Please sign in to comment.