Skip to content

Commit

Permalink
give module id an invalid name to prevent invalid replacement (#3546)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Rich-Harris authored Jan 26, 2022
1 parent aed5366 commit 90664c9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-carrots-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-netlify': patch
---

Fix string replacement in CJS builds
2 changes: 1 addition & 1 deletion packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function ({ split = false } = {}) {
const redirects = [];

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

if (esm) {
Expand Down
3 changes: 2 additions & 1 deletion packages/adapter-netlify/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default [
}
],
plugins: [nodeResolve(), commonjs(), json()],
external: ['APP', ...require('module').builtinModules]
external: (id) => id === '0APP' || id.startsWith('node:'),
preserveEntrySignatures: true
}
];
2 changes: 1 addition & 1 deletion packages/adapter-netlify/src/handler.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
declare module 'APP' {
declare module '0APP' {
export { App } from '@sveltejs/kit';
}
2 changes: 1 addition & 1 deletion packages/adapter-netlify/src/handler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './shims';
import { App } from 'APP';
import { App } from '0APP';

/**
* @param {import('@sveltejs/kit').SSRManifest} manifest
Expand Down

0 comments on commit 90664c9

Please sign in to comment.