From 13c1f5ff6bc18f05be2f9fee32331d89fc58af94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Seery?= Date: Tue, 3 May 2022 17:55:12 -0300 Subject: [PATCH] refactor: remove serialize-javascript (#3278) * Replaced serialize-javascript with devalue * Changeset --- .changeset/forty-goats-dance.md | 5 +++++ packages/astro/package.json | 2 +- packages/astro/src/@types/serialize-javascript.d.ts | 3 --- packages/astro/src/core/create-vite.ts | 8 -------- packages/astro/src/runtime/server/hydration.ts | 4 ++-- pnpm-lock.yaml | 10 ++++++++-- 6 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 .changeset/forty-goats-dance.md delete mode 100644 packages/astro/src/@types/serialize-javascript.d.ts diff --git a/.changeset/forty-goats-dance.md b/.changeset/forty-goats-dance.md new file mode 100644 index 000000000000..112cbb68e1c6 --- /dev/null +++ b/.changeset/forty-goats-dance.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Internal: replaces `serialize-javascript` with `devalue` diff --git a/packages/astro/package.json b/packages/astro/package.json index e161fedf6536..c53ecfee25e7 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -92,6 +92,7 @@ "ci-info": "^3.3.0", "common-ancestor-path": "^1.0.1", "debug": "^4.3.4", + "devalue": "^2.0.1", "diff": "^5.0.0", "eol": "^0.9.1", "es-module-lexer": "^0.10.5", @@ -120,7 +121,6 @@ "resolve": "^1.22.0", "rollup": "^2.70.2", "semver": "^7.3.7", - "serialize-javascript": "^6.0.0", "shiki": "^0.10.1", "shorthash": "^0.0.2", "sirv": "^2.0.2", diff --git a/packages/astro/src/@types/serialize-javascript.d.ts b/packages/astro/src/@types/serialize-javascript.d.ts deleted file mode 100644 index 35ee081b2f5b..000000000000 --- a/packages/astro/src/@types/serialize-javascript.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -declare module 'serialize-javascript' { - export default function serialize(value: any): string; -} diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index eca7cd2646e6..acb97c5f486a 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -21,7 +21,6 @@ const ALWAYS_EXTERNAL = new Set([ ...builtinModules.map((name) => `node:${name}`), '@sveltejs/vite-plugin-svelte', 'micromark-util-events-to-acorn', - 'serialize-javascript', 'node-fetch', 'prismjs', 'shiki', @@ -91,13 +90,6 @@ export async function createVite( css: { postcss: astroConfig.style.postcss || {}, }, - resolve: { - alias: { - // This is needed for Deno compatibility, as the non-browser version - // of this module depends on Node `crypto` - randombytes: 'randombytes/browser', - }, - }, // Note: SSR API is in beta (https://vitejs.dev/guide/ssr.html) ssr: { external: [...ALWAYS_EXTERNAL], diff --git a/packages/astro/src/runtime/server/hydration.ts b/packages/astro/src/runtime/server/hydration.ts index e7267fe16e3c..bfb7245da152 100644 --- a/packages/astro/src/runtime/server/hydration.ts +++ b/packages/astro/src/runtime/server/hydration.ts @@ -1,12 +1,12 @@ import type { AstroComponentMetadata, SSRLoadedRenderer } from '../../@types/astro'; import type { SSRElement, SSRResult } from '../../@types/astro'; import { hydrationSpecifier, serializeListValue } from './util.js'; -import serializeJavaScript from 'serialize-javascript'; +import devalue from 'devalue'; // Serializes props passed into a component so that they can be reused during hydration. // The value is any export function serializeProps(value: any) { - return serializeJavaScript(value); + return devalue(value); } const HydrationDirectives = ['load', 'idle', 'media', 'visible', 'only']; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4ca49705bf46..18f908f2c83f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -498,6 +498,7 @@ importers: ci-info: ^3.3.0 common-ancestor-path: ^1.0.1 debug: ^4.3.4 + devalue: ^2.0.1 diff: ^5.0.0 eol: ^0.9.1 es-module-lexer: ^0.10.5 @@ -528,7 +529,6 @@ importers: rollup: ^2.70.2 sass: ^1.50.1 semver: ^7.3.7 - serialize-javascript: ^6.0.0 shiki: ^0.10.1 shorthash: ^0.0.2 sirv: ^2.0.2 @@ -560,6 +560,7 @@ importers: ci-info: 3.3.0 common-ancestor-path: 1.0.1 debug: 4.3.4 + devalue: 2.0.1 diff: 5.0.0 eol: 0.9.1 es-module-lexer: 0.10.5 @@ -588,7 +589,6 @@ importers: resolve: 1.22.0 rollup: 2.70.2 semver: 7.3.7 - serialize-javascript: 6.0.0 shiki: 0.10.1 shorthash: 0.0.2 sirv: 2.0.2 @@ -5507,6 +5507,10 @@ packages: defined: 1.0.0 minimist: 1.2.6 + /devalue/2.0.1: + resolution: {integrity: sha512-I2TiqT5iWBEyB8GRfTDP0hiLZ0YeDJZ+upDxjBfOC2lebO5LezQMv7QvIUTzdb64jQyAKLf1AHADtGN+jw6v8Q==} + dev: false + /didyoumean/1.2.2: resolution: {integrity: sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==} @@ -8713,6 +8717,7 @@ packages: resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==} dependencies: safe-buffer: 5.2.1 + dev: true /raw-body/2.5.1: resolution: {integrity: sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==} @@ -9211,6 +9216,7 @@ packages: resolution: {integrity: sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==} dependencies: randombytes: 2.1.0 + dev: true /set-blocking/2.0.0: resolution: {integrity: sha1-BF+XgtARrppoA93TgrJDkrPYkPc=}