From 8a3993c93e4940e60eee87b626ebc30674915007 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 25 Jan 2022 23:35:26 -0500 Subject: [PATCH 1/4] give module id an invalid name to prevent invalid replacement - fixes #3526 --- packages/adapter-netlify/index.js | 2 +- packages/adapter-netlify/rollup.config.js | 3 ++- packages/adapter-netlify/src/handler.d.ts | 2 +- packages/adapter-netlify/src/handler.js | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/adapter-netlify/index.js b/packages/adapter-netlify/index.js index 2aa36a2452c4..ca79dd2fb0a2 100644 --- a/packages/adapter-netlify/index.js +++ b/packages/adapter-netlify/index.js @@ -51,7 +51,7 @@ export default function ({ split = false } = {}) { const redirects = []; const replace = { - APP: './server/app.js' + '0APP': './server/app.js' }; if (esm) { diff --git a/packages/adapter-netlify/rollup.config.js b/packages/adapter-netlify/rollup.config.js index 2d88582be5e4..7564de03ee9c 100644 --- a/packages/adapter-netlify/rollup.config.js +++ b/packages/adapter-netlify/rollup.config.js @@ -19,6 +19,7 @@ export default [ } ], plugins: [nodeResolve(), commonjs(), json()], - external: ['APP', ...require('module').builtinModules] + external: (id) => id === '0APP' || id.startsWith('node:'), + preserveEntrySignatures: true } ]; diff --git a/packages/adapter-netlify/src/handler.d.ts b/packages/adapter-netlify/src/handler.d.ts index 556c999c9007..75ea691df713 100644 --- a/packages/adapter-netlify/src/handler.d.ts +++ b/packages/adapter-netlify/src/handler.d.ts @@ -1,3 +1,3 @@ -declare module 'APP' { +declare module '0APP' { export { App } from '@sveltejs/kit'; } diff --git a/packages/adapter-netlify/src/handler.js b/packages/adapter-netlify/src/handler.js index e75fdd97a85f..e23c8f96d17b 100644 --- a/packages/adapter-netlify/src/handler.js +++ b/packages/adapter-netlify/src/handler.js @@ -1,5 +1,5 @@ import './shims'; -import { App } from 'APP'; +import { App } from '0APP'; /** * @param {import('@sveltejs/kit').SSRManifest} manifest From ae98d62d675a8791cdac6aaea4012c2593c7de8b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 25 Jan 2022 23:39:26 -0500 Subject: [PATCH 2/4] changeset --- .changeset/gorgeous-carrots-do.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/gorgeous-carrots-do.md diff --git a/.changeset/gorgeous-carrots-do.md b/.changeset/gorgeous-carrots-do.md new file mode 100644 index 000000000000..75b344ac35b5 --- /dev/null +++ b/.changeset/gorgeous-carrots-do.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-netlify': patch +--- + +Fix string replacement in CJS builds From 0e2563912a2adefea1e97004fdfeea4ce7e453ba Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 26 Jan 2022 09:20:26 -0500 Subject: [PATCH 3/4] Update packages/adapter-netlify/index.js --- packages/adapter-netlify/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/adapter-netlify/index.js b/packages/adapter-netlify/index.js index ca79dd2fb0a2..223db104b966 100644 --- a/packages/adapter-netlify/index.js +++ b/packages/adapter-netlify/index.js @@ -51,7 +51,7 @@ export default function ({ split = false } = {}) { const redirects = []; const replace = { - '0APP': './server/app.js' + '0APP': './server/app.js' // digit prefix prevents CJS build from using this as a variable name }; if (esm) { From 4a4d866379da9d38e4b6a6241cdd1a6f9cf1571b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 26 Jan 2022 12:23:33 -0500 Subject: [PATCH 4/4] Update packages/adapter-netlify/index.js --- packages/adapter-netlify/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/adapter-netlify/index.js b/packages/adapter-netlify/index.js index 223db104b966..3ebb45324d03 100644 --- a/packages/adapter-netlify/index.js +++ b/packages/adapter-netlify/index.js @@ -51,7 +51,7 @@ export default function ({ split = false } = {}) { const redirects = []; const replace = { - '0APP': './server/app.js' // digit prefix prevents CJS build from using this as a variable name + '0APP': './server/app.js' // digit prefix prevents CJS build from using this as a variable name, which would also get replaced }; if (esm) {