From 0ddfe8786c514dcacd64d469dc4a6e83bb5e00c3 Mon Sep 17 00:00:00 2001 From: Danilo Woznica Date: Fri, 7 Apr 2023 14:49:50 +0000 Subject: [PATCH] Update 3 files --- .../src/clients/node/client.utils.ts | 17 +++++++---------- sandpack-client/src/clients/node/index.ts | 4 +--- sandpack-react/.storybook/preview-head.html | 5 ----- 3 files changed, 8 insertions(+), 18 deletions(-) delete mode 100644 sandpack-react/.storybook/preview-head.html diff --git a/sandpack-client/src/clients/node/client.utils.ts b/sandpack-client/src/clients/node/client.utils.ts index 7d9dc09b0..a5dec28bb 100644 --- a/sandpack-client/src/clients/node/client.utils.ts +++ b/sandpack-client/src/clients/node/client.utils.ts @@ -1,5 +1,3 @@ -import { Buffer } from "buffer"; - import type { ShellCommandOptions } from "@codesandbox/nodebox/build/modules/shell"; import { invariant } from "outvariant"; @@ -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 = ( diff --git a/sandpack-client/src/clients/node/index.ts b/sandpack-client/src/clients/node/index.ts index 7eb94ca86..36c792c90 100644 --- a/sandpack-client/src/clients/node/index.ts +++ b/sandpack-client/src/clients/node/index.ts @@ -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, @@ -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 }); } diff --git a/sandpack-react/.storybook/preview-head.html b/sandpack-react/.storybook/preview-head.html deleted file mode 100644 index 65faca25d..000000000 --- a/sandpack-react/.storybook/preview-head.html +++ /dev/null @@ -1,5 +0,0 @@ -