Skip to content

Commit 90664c9

Browse files
authored
give module id an invalid name to prevent invalid replacement (#3546)
* give module id an invalid name to prevent invalid replacement - fixes #3526 * changeset * Update packages/adapter-netlify/index.js * Update packages/adapter-netlify/index.js
1 parent aed5366 commit 90664c9

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

.changeset/gorgeous-carrots-do.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-netlify': patch
3+
---
4+
5+
Fix string replacement in CJS builds

packages/adapter-netlify/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default function ({ split = false } = {}) {
5151
const redirects = [];
5252

5353
const replace = {
54-
APP: './server/app.js'
54+
'0APP': './server/app.js' // digit prefix prevents CJS build from using this as a variable name, which would also get replaced
5555
};
5656

5757
if (esm) {

packages/adapter-netlify/rollup.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default [
1919
}
2020
],
2121
plugins: [nodeResolve(), commonjs(), json()],
22-
external: ['APP', ...require('module').builtinModules]
22+
external: (id) => id === '0APP' || id.startsWith('node:'),
23+
preserveEntrySignatures: true
2324
}
2425
];
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
declare module 'APP' {
1+
declare module '0APP' {
22
export { App } from '@sveltejs/kit';
33
}

packages/adapter-netlify/src/handler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import './shims';
2-
import { App } from 'APP';
2+
import { App } from '0APP';
33

44
/**
55
* @param {import('@sveltejs/kit').SSRManifest} manifest

0 commit comments

Comments
 (0)