From 784ea4a78036ba0a94544163984c985bdac7e82c Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Tue, 25 Apr 2023 12:00:32 +0545 Subject: [PATCH 01/16] remove build step for adapter node --- packages/adapter-node/ambient.d.ts | 6 +++ packages/adapter-node/index.d.ts | 4 -- packages/adapter-node/index.js | 60 +++++++++++++++--------- packages/adapter-node/package.json | 15 +++--- packages/adapter-node/rollup.config.js | 44 ----------------- packages/adapter-node/src/env.js | 4 +- packages/adapter-node/src/handler.js | 13 ++--- packages/adapter-node/src/index.js | 4 +- packages/adapter-node/src/shims_empty.js | 0 pnpm-lock.yaml | 48 ++++++++++++------- 10 files changed, 94 insertions(+), 104 deletions(-) delete mode 100644 packages/adapter-node/rollup.config.js create mode 100644 packages/adapter-node/src/shims_empty.js diff --git a/packages/adapter-node/ambient.d.ts b/packages/adapter-node/ambient.d.ts index 7d45ea6dc64a..15b57f6ebdd8 100644 --- a/packages/adapter-node/ambient.d.ts +++ b/packages/adapter-node/ambient.d.ts @@ -1,5 +1,6 @@ declare module 'ENV' { export function env(key: string, fallback?: any): string; + export const ENV_PREFIX: string; } declare module 'HANDLER' { @@ -17,6 +18,11 @@ declare module 'SERVER' { export { Server } from '@sveltejs/kit'; } +interface ImportMeta { + SERVER_DIR: string; + ENV_PREFIX: string; +} + declare namespace App { export interface Platform { /** diff --git a/packages/adapter-node/index.d.ts b/packages/adapter-node/index.d.ts index 12ea6273dd66..c3b224198ddb 100644 --- a/packages/adapter-node/index.d.ts +++ b/packages/adapter-node/index.d.ts @@ -1,10 +1,6 @@ import { Adapter } from '@sveltejs/kit'; import './ambient.js'; -declare global { - const ENV_PREFIX: string; -} - interface AdapterOptions { out?: string; precompress?: boolean; diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index 8d5c1629a4cf..b408720f9b28 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -1,11 +1,15 @@ +import commonjs from '@rollup/plugin-commonjs'; +import json from '@rollup/plugin-json'; +import { nodeResolve } from '@rollup/plugin-node-resolve'; import { readFileSync, writeFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { rollup } from 'rollup'; -import { nodeResolve } from '@rollup/plugin-node-resolve'; -import commonjs from '@rollup/plugin-commonjs'; -import json from '@rollup/plugin-json'; -const files = fileURLToPath(new URL('./files', import.meta.url).href); +/** + * @param {string} path + * @returns + */ +const resolve = (path) => fileURLToPath(new URL(path, import.meta.url)); /** @type {import('.').default} */ export default function (opts = {}) { @@ -50,14 +54,40 @@ export default function (opts = {}) { // will get included in the bundled code const bundle = await rollup({ input: { - index: `${tmp}/index.js`, - manifest: `${tmp}/manifest.js` + handler: resolve('./src/handler.js'), + index: resolve('./src/index.js') }, external: [ // dependencies could have deep exports, so we need a regex ...Object.keys(pkg.dependencies || {}).map((d) => new RegExp(`^${d}(\\/.*)?$`)) ], plugins: [ + { + name: 'adapter-node-resolve', + resolveId(id) { + switch (id) { + case 'ENV': + return resolve('./src/env.js'); + case 'HANDLER': + return resolve('./src/handler.js'); + case 'MANIFEST': + return `${tmp}/manifest.js`; + case 'SERVER': + return `${tmp}/index.js`; + case 'SHIMS': + return resolve(polyfill ? './src/shims.js' : './src/shims_empty.js'); + } + }, + resolveImportMeta(property, { chunkId, moduleId }) { + if (property === 'SERVER_DIR' && moduleId === resolve('./src/handler.js')) { + const segments = chunkId.split('/').length - 1; + + return `new URL("${'../'.repeat(segments) || '.'}", import.meta.url)`; + } else if (property === 'ENV_PREFIX' && moduleId === resolve('./src/env.js')) { + return JSON.stringify(envPrefix); + } + } + }, nodeResolve({ preferBuiltins: true, exportConditions: ['node'] @@ -68,27 +98,11 @@ export default function (opts = {}) { }); await bundle.write({ - dir: `${out}/server`, + dir: `${out}`, format: 'esm', sourcemap: true, chunkFileNames: 'chunks/[name]-[hash].js' }); - - builder.copy(files, out, { - replace: { - ENV: './env.js', - HANDLER: './handler.js', - MANIFEST: './server/manifest.js', - SERVER: './server/index.js', - SHIMS: './shims.js', - ENV_PREFIX: JSON.stringify(envPrefix) - } - }); - - // If polyfills aren't wanted then clear the file - if (!polyfill) { - writeFileSync(`${out}/shims.js`, '', 'utf-8'); - } } }; } diff --git a/packages/adapter-node/package.json b/packages/adapter-node/package.json index 65e0bfb1dd88..88969811aecd 100644 --- a/packages/adapter-node/package.json +++ b/packages/adapter-node/package.json @@ -19,13 +19,11 @@ }, "types": "index.d.ts", "files": [ - "files", + "src", "index.js", "index.d.ts" ], "scripts": { - "dev": "rimraf files && rollup -cw", - "build": "rimraf files && rollup -c", "test": "echo \"tests temporarily disabled\" # c8 vitest run", "check": "tsc", "lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore", @@ -33,13 +31,9 @@ "prepublishOnly": "pnpm build" }, "devDependencies": { - "@polka/url": "^1.0.0-next.21", "@sveltejs/kit": "workspace:^", "@types/node": "^16.18.6", "c8": "^7.13.0", - "polka": "^1.0.0-next.22", - "rimraf": "^5.0.0", - "sirv": "^2.0.3", "typescript": "^4.9.4", "vitest": "^0.31.0" }, @@ -47,7 +41,12 @@ "@rollup/plugin-commonjs": "^25.0.0", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", - "rollup": "^3.7.0" + "@rollup/plugin-replace": "^5.0.2", + "rollup": "^3.7.0", + "@polka/url": "^1.0.0-next.21", + "undici": "~5.22.0", + "polka": "^1.0.0-next.22", + "sirv": "^2.0.2" }, "peerDependencies": { "@sveltejs/kit": "^1.0.0" diff --git a/packages/adapter-node/rollup.config.js b/packages/adapter-node/rollup.config.js deleted file mode 100644 index 16c4a20c37a7..000000000000 --- a/packages/adapter-node/rollup.config.js +++ /dev/null @@ -1,44 +0,0 @@ -import { nodeResolve } from '@rollup/plugin-node-resolve'; -import commonjs from '@rollup/plugin-commonjs'; -import json from '@rollup/plugin-json'; -import { builtinModules } from 'node:module'; - -export default [ - { - input: 'src/index.js', - output: { - file: 'files/index.js', - format: 'esm' - }, - plugins: [nodeResolve({ preferBuiltins: true }), commonjs(), json()], - external: ['ENV', 'HANDLER', ...builtinModules] - }, - { - input: 'src/env.js', - output: { - file: 'files/env.js', - format: 'esm' - }, - plugins: [nodeResolve(), commonjs(), json()], - external: ['HANDLER', ...builtinModules] - }, - { - input: 'src/handler.js', - output: { - file: 'files/handler.js', - format: 'esm', - inlineDynamicImports: true - }, - plugins: [nodeResolve(), commonjs(), json()], - external: ['ENV', 'MANIFEST', 'SERVER', 'SHIMS', ...builtinModules] - }, - { - input: 'src/shims.js', - output: { - file: 'files/shims.js', - format: 'esm' - }, - plugins: [nodeResolve(), commonjs()], - external: builtinModules - } -]; diff --git a/packages/adapter-node/src/env.js b/packages/adapter-node/src/env.js index 841bddf2c237..330032cde945 100644 --- a/packages/adapter-node/src/env.js +++ b/packages/adapter-node/src/env.js @@ -1,4 +1,6 @@ -/* global ENV_PREFIX */ +/* global __ENV_PREFIX */ + +export const ENV_PREFIX = import.meta.ENV_PREFIX; const expected = new Set([ 'SOCKET_PATH', diff --git a/packages/adapter-node/src/handler.js b/packages/adapter-node/src/handler.js index 8a1390a78f25..fefdc0f9882e 100644 --- a/packages/adapter-node/src/handler.js +++ b/packages/adapter-node/src/handler.js @@ -1,15 +1,16 @@ import 'SHIMS'; + import fs from 'node:fs'; import path from 'node:path'; -import sirv from 'sirv'; import { fileURLToPath } from 'node:url'; + import { parse as polka_url_parser } from '@polka/url'; import { getRequest, setResponse } from '@sveltejs/kit/node'; -import { Server } from 'SERVER'; -import { manifest, prerendered } from 'MANIFEST'; -import { env } from 'ENV'; +import sirv from 'sirv'; -/* global ENV_PREFIX */ +import { env, ENV_PREFIX } from './env.js'; +import { manifest, prerendered } from 'MANIFEST'; +import { Server } from 'SERVER'; const server = new Server(manifest); await server.init({ env: process.env }); @@ -20,7 +21,7 @@ const protocol_header = env('PROTOCOL_HEADER', '').toLowerCase(); const host_header = env('HOST_HEADER', 'host').toLowerCase(); const body_size_limit = parseInt(env('BODY_SIZE_LIMIT', '524288')); -const dir = path.dirname(fileURLToPath(import.meta.url)); +const dir = fileURLToPath(import.meta.SERVER_DIR); /** * @param {string} path diff --git a/packages/adapter-node/src/index.js b/packages/adapter-node/src/index.js index ea3feee05860..5832b244a51e 100644 --- a/packages/adapter-node/src/index.js +++ b/packages/adapter-node/src/index.js @@ -1,5 +1,5 @@ -import { handler } from 'HANDLER'; -import { env } from 'ENV'; +import { handler } from './handler.js'; +import { env } from './env.js'; import polka from 'polka'; export const path = env('SOCKET_PATH', false); diff --git a/packages/adapter-node/src/shims_empty.js b/packages/adapter-node/src/shims_empty.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3b5f36a585aa..6ab2470ffea5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -173,6 +173,9 @@ importers: packages/adapter-node: dependencies: + '@polka/url': + specifier: ^1.0.0-next.21 + version: 1.0.0-next.21 '@rollup/plugin-commonjs': specifier: ^25.0.0 version: 25.0.0(rollup@3.7.0) @@ -182,13 +185,22 @@ importers: '@rollup/plugin-node-resolve': specifier: ^15.0.1 version: 15.0.1(rollup@3.7.0) + '@rollup/plugin-replace': + specifier: ^5.0.2 + version: 5.0.2(rollup@3.7.0) + polka: + specifier: ^1.0.0-next.22 + version: 1.0.0-next.22 rollup: specifier: ^3.7.0 version: 3.7.0 + sirv: + specifier: ^2.0.2 + version: 2.0.3 + undici: + specifier: ~5.22.0 + version: 5.22.0 devDependencies: - '@polka/url': - specifier: ^1.0.0-next.21 - version: 1.0.0-next.21 '@sveltejs/kit': specifier: workspace:^ version: link:../kit @@ -198,15 +210,6 @@ importers: c8: specifier: ^7.13.0 version: 7.13.0 - polka: - specifier: ^1.0.0-next.22 - version: 1.0.0-next.22 - rimraf: - specifier: ^5.0.0 - version: 5.0.0 - sirv: - specifier: ^2.0.3 - version: 2.0.3 typescript: specifier: ^4.9.4 version: 4.9.4 @@ -1716,6 +1719,20 @@ packages: resolve: 1.22.1 rollup: 3.7.0 + /@rollup/plugin-replace@5.0.2(rollup@3.7.0): + resolution: {integrity: sha512-M9YXNekv/C/iHHK+cvORzfRYfPbq0RDD8r0G+bMiTXjNGKulPnCT9O3Ss46WfhI6ZOCgApOP7xAdmCQJ+U2LAA==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@rollup/pluginutils': 5.0.2(rollup@3.7.0) + magic-string: 0.27.0 + rollup: 3.7.0 + dev: false + /@rollup/pluginutils@4.2.1: resolution: {integrity: sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==} engines: {node: '>= 8.0.0'} @@ -4876,7 +4893,7 @@ packages: dependencies: '@polka/url': 1.0.0-next.21 trouter: 3.2.0 - dev: true + dev: false /postcss-load-config@3.1.4(postcss@8.4.23): resolution: {integrity: sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==} @@ -5127,7 +5144,7 @@ packages: /regexparam@1.3.0: resolution: {integrity: sha512-6IQpFBv6e5vz1QAqI+V4k8P2e/3gRrqfCJ9FI+O1FLQTO+Uz6RXZEZOPmTJ6hlGj7gkERzY5BRCv09whKP96/g==} engines: {node: '>=6'} - dev: true + dev: false /regexparam@2.0.1: resolution: {integrity: sha512-zRgSaYemnNYxUv+/5SeoHI0eJIgTL/A2pUtXUPLHQxUldagouJ9p+K6IbIZ/JiQuCEv2E2B1O11SjVQy3aMCkw==} @@ -5436,7 +5453,6 @@ packages: '@polka/url': 1.0.0-next.21 mrmime: 1.0.1 totalist: 3.0.0 - dev: true /sisteransi@1.0.5: resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} @@ -5931,7 +5947,7 @@ packages: engines: {node: '>=6'} dependencies: regexparam: 1.3.0 - dev: true + dev: false /ts-interface-checker@0.1.13: resolution: {integrity: sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==} From a3dc18c372e234369cec432e6c4da853769d335b Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Tue, 25 Apr 2023 16:36:57 +0545 Subject: [PATCH 02/16] make shims virtual for easier manipulation --- packages/adapter-node/index.js | 13 ++++++++----- packages/adapter-node/src/env.js | 2 -- packages/adapter-node/src/shims.js | 2 -- packages/adapter-node/src/shims_empty.js | 0 4 files changed, 8 insertions(+), 9 deletions(-) delete mode 100644 packages/adapter-node/src/shims.js delete mode 100644 packages/adapter-node/src/shims_empty.js diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index b408720f9b28..6e1b7cebab93 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -66,16 +66,19 @@ export default function (opts = {}) { name: 'adapter-node-resolve', resolveId(id) { switch (id) { - case 'ENV': - return resolve('./src/env.js'); - case 'HANDLER': - return resolve('./src/handler.js'); case 'MANIFEST': return `${tmp}/manifest.js`; case 'SERVER': return `${tmp}/index.js`; case 'SHIMS': - return resolve(polyfill ? './src/shims.js' : './src/shims_empty.js'); + return `\0SHIMS`; + } + }, + load(id) { + if (id === `\0SHIMS`) { + return polyfill + ? `import { installPolyfills } from '@sveltejs/kit/node/polyfills'; installPolyfills();` + : ''; } }, resolveImportMeta(property, { chunkId, moduleId }) { diff --git a/packages/adapter-node/src/env.js b/packages/adapter-node/src/env.js index 330032cde945..75a7dcc93b28 100644 --- a/packages/adapter-node/src/env.js +++ b/packages/adapter-node/src/env.js @@ -1,5 +1,3 @@ -/* global __ENV_PREFIX */ - export const ENV_PREFIX = import.meta.ENV_PREFIX; const expected = new Set([ diff --git a/packages/adapter-node/src/shims.js b/packages/adapter-node/src/shims.js deleted file mode 100644 index 2490311daa1e..000000000000 --- a/packages/adapter-node/src/shims.js +++ /dev/null @@ -1,2 +0,0 @@ -import { installPolyfills } from '@sveltejs/kit/node/polyfills'; -installPolyfills(); diff --git a/packages/adapter-node/src/shims_empty.js b/packages/adapter-node/src/shims_empty.js deleted file mode 100644 index e69de29bb2d1..000000000000 From aff0e4e62a6a0ddd2b72c377d49edfc4127f2445 Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Fri, 26 May 2023 06:45:24 +0545 Subject: [PATCH 03/16] remove unused module and build step --- packages/adapter-node/ambient.d.ts | 7 +------ packages/adapter-node/index.js | 3 ++- packages/adapter-node/package.json | 3 +-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/adapter-node/ambient.d.ts b/packages/adapter-node/ambient.d.ts index 15b57f6ebdd8..6843a8aa5ec7 100644 --- a/packages/adapter-node/ambient.d.ts +++ b/packages/adapter-node/ambient.d.ts @@ -1,8 +1,3 @@ -declare module 'ENV' { - export function env(key: string, fallback?: any): string; - export const ENV_PREFIX: string; -} - declare module 'HANDLER' { export const handler: import('polka').Middleware; } @@ -20,7 +15,7 @@ declare module 'SERVER' { interface ImportMeta { SERVER_DIR: string; - ENV_PREFIX: string; + ENV_PREFIX?: string; } declare namespace App { diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index 6e1b7cebab93..2217a84d3c23 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -104,7 +104,8 @@ export default function (opts = {}) { dir: `${out}`, format: 'esm', sourcemap: true, - chunkFileNames: 'chunks/[name]-[hash].js' + chunkFileNames: 'chunks/[name]-[hash].js', + hoistTransitiveImports: false, }); } }; diff --git a/packages/adapter-node/package.json b/packages/adapter-node/package.json index 88969811aecd..1d1e1fd663ff 100644 --- a/packages/adapter-node/package.json +++ b/packages/adapter-node/package.json @@ -27,8 +27,7 @@ "test": "echo \"tests temporarily disabled\" # c8 vitest run", "check": "tsc", "lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore", - "format": "pnpm lint --write", - "prepublishOnly": "pnpm build" + "format": "pnpm lint --write" }, "devDependencies": { "@sveltejs/kit": "workspace:^", From e2d4ec331e75d53288714c1adca6d570a3f0967e Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Fri, 26 May 2023 06:54:17 +0545 Subject: [PATCH 04/16] changeset --- .changeset/dirty-dolphins-suffer.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dirty-dolphins-suffer.md diff --git a/.changeset/dirty-dolphins-suffer.md b/.changeset/dirty-dolphins-suffer.md new file mode 100644 index 000000000000..cddc4b0ec7d4 --- /dev/null +++ b/.changeset/dirty-dolphins-suffer.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-node': patch +--- + +chore: remove build step for adapter node From bfb7ea6053492e55ffbf6256c6fe0f1503c15b89 Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Fri, 26 May 2023 07:59:23 +0545 Subject: [PATCH 05/16] format --- packages/adapter-node/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index 2217a84d3c23..12e6b9f7c23a 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -105,7 +105,7 @@ export default function (opts = {}) { format: 'esm', sourcemap: true, chunkFileNames: 'chunks/[name]-[hash].js', - hoistTransitiveImports: false, + hoistTransitiveImports: false }); } }; From bdf77359191ec493f8372935b29e479647080d1c Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Fri, 26 May 2023 08:21:51 +0545 Subject: [PATCH 06/16] fix lint --- packages/adapter-node/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index 12e6b9f7c23a..90ae661d0526 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -71,13 +71,13 @@ export default function (opts = {}) { case 'SERVER': return `${tmp}/index.js`; case 'SHIMS': - return `\0SHIMS`; + return '\0SHIMS'; } }, load(id) { - if (id === `\0SHIMS`) { + if (id === '\0SHIMS') { return polyfill - ? `import { installPolyfills } from '@sveltejs/kit/node/polyfills'; installPolyfills();` + ? 'import { installPolyfills } from \'@sveltejs/kit/node/polyfills\'; installPolyfills();' : ''; } }, From 7c53fb166695b4a6f5267be7b02c30a52d041ed8 Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Fri, 26 May 2023 08:27:46 +0545 Subject: [PATCH 07/16] I said FIX LINT --- packages/adapter-node/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index 90ae661d0526..8b81b39edec2 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -77,7 +77,7 @@ export default function (opts = {}) { load(id) { if (id === '\0SHIMS') { return polyfill - ? 'import { installPolyfills } from \'@sveltejs/kit/node/polyfills\'; installPolyfills();' + ? "import { installPolyfills } from '@sveltejs/kit/node/polyfills'; installPolyfills();" : ''; } }, From 651975d0a23a018fc85ed260f29656d53ce812c6 Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Sat, 27 May 2023 10:13:51 +0545 Subject: [PATCH 08/16] remove unused dependencies --- packages/adapter-node/package.json | 2 -- pnpm-lock.yaml | 20 -------------------- 2 files changed, 22 deletions(-) diff --git a/packages/adapter-node/package.json b/packages/adapter-node/package.json index 1d1e1fd663ff..9e37dc2f8bc0 100644 --- a/packages/adapter-node/package.json +++ b/packages/adapter-node/package.json @@ -40,10 +40,8 @@ "@rollup/plugin-commonjs": "^25.0.0", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", - "@rollup/plugin-replace": "^5.0.2", "rollup": "^3.7.0", "@polka/url": "^1.0.0-next.21", - "undici": "~5.22.0", "polka": "^1.0.0-next.22", "sirv": "^2.0.2" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6ab2470ffea5..8540330bca85 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -185,9 +185,6 @@ importers: '@rollup/plugin-node-resolve': specifier: ^15.0.1 version: 15.0.1(rollup@3.7.0) - '@rollup/plugin-replace': - specifier: ^5.0.2 - version: 5.0.2(rollup@3.7.0) polka: specifier: ^1.0.0-next.22 version: 1.0.0-next.22 @@ -197,9 +194,6 @@ importers: sirv: specifier: ^2.0.2 version: 2.0.3 - undici: - specifier: ~5.22.0 - version: 5.22.0 devDependencies: '@sveltejs/kit': specifier: workspace:^ @@ -1719,20 +1713,6 @@ packages: resolve: 1.22.1 rollup: 3.7.0 - /@rollup/plugin-replace@5.0.2(rollup@3.7.0): - resolution: {integrity: sha512-M9YXNekv/C/iHHK+cvORzfRYfPbq0RDD8r0G+bMiTXjNGKulPnCT9O3Ss46WfhI6ZOCgApOP7xAdmCQJ+U2LAA==} - engines: {node: '>=14.0.0'} - peerDependencies: - rollup: ^1.20.0||^2.0.0||^3.0.0 - peerDependenciesMeta: - rollup: - optional: true - dependencies: - '@rollup/pluginutils': 5.0.2(rollup@3.7.0) - magic-string: 0.27.0 - rollup: 3.7.0 - dev: false - /@rollup/pluginutils@4.2.1: resolution: {integrity: sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==} engines: {node: '>= 8.0.0'} From 1a182fcd63b0f67f6ad80f0be2d41bf5d9e63483 Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Sat, 27 May 2023 21:04:56 +0545 Subject: [PATCH 09/16] sort deps --- packages/adapter-node/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/adapter-node/package.json b/packages/adapter-node/package.json index 9e37dc2f8bc0..22ffd29f56e9 100644 --- a/packages/adapter-node/package.json +++ b/packages/adapter-node/package.json @@ -37,12 +37,12 @@ "vitest": "^0.31.0" }, "dependencies": { + "@polka/url": "^1.0.0-next.21", "@rollup/plugin-commonjs": "^25.0.0", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", - "rollup": "^3.7.0", - "@polka/url": "^1.0.0-next.21", "polka": "^1.0.0-next.22", + "rollup": "^3.7.0", "sirv": "^2.0.2" }, "peerDependencies": { From ea50ff79604bfff77864e18ffe36dd6917508b72 Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Sat, 27 May 2023 21:10:12 +0545 Subject: [PATCH 10/16] use adjacent tmp directory --- packages/adapter-node/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index 8b81b39edec2..4966b41b0a7d 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -2,6 +2,7 @@ import commonjs from '@rollup/plugin-commonjs'; import json from '@rollup/plugin-json'; import { nodeResolve } from '@rollup/plugin-node-resolve'; import { readFileSync, writeFileSync } from 'node:fs'; +import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { rollup } from 'rollup'; @@ -19,7 +20,8 @@ export default function (opts = {}) { name: '@sveltejs/adapter-node', async adapt(builder) { - const tmp = builder.getBuildDirectory('adapter-node'); + // use an adjacent temporary directory so that any relative paths in eg. sourcemaps don't break + const tmp = path.join(path.dirname(builder.getServerDirectory()), 'adapter-node'); builder.rimraf(out); builder.rimraf(tmp); From d6d912e25964536b0871703cb9967f6d93f8db6a Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Wed, 31 May 2023 07:11:26 +0545 Subject: [PATCH 11/16] apply suggestions --- packages/adapter-node/index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index 4966b41b0a7d..0a0af6c78c4d 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -8,7 +8,6 @@ import { rollup } from 'rollup'; /** * @param {string} path - * @returns */ const resolve = (path) => fileURLToPath(new URL(path, import.meta.url)); @@ -73,11 +72,11 @@ export default function (opts = {}) { case 'SERVER': return `${tmp}/index.js`; case 'SHIMS': - return '\0SHIMS'; + return '\0virtual:SHIMS'; } }, load(id) { - if (id === '\0SHIMS') { + if (id === '\0virtual:SHIMS') { return polyfill ? "import { installPolyfills } from '@sveltejs/kit/node/polyfills'; installPolyfills();" : ''; @@ -103,10 +102,10 @@ export default function (opts = {}) { }); await bundle.write({ - dir: `${out}`, + dir: out, format: 'esm', sourcemap: true, - chunkFileNames: 'chunks/[name]-[hash].js', + chunkFileNames: 'server/chunks/[name]-[hash].js', hoistTransitiveImports: false }); } From 248ec2f39be94d7fe301195f8e6249754b8ab24d Mon Sep 17 00:00:00 2001 From: gtmnayan <50981692+gtm-nayan@users.noreply.github.com> Date: Wed, 31 May 2023 07:12:00 +0545 Subject: [PATCH 12/16] Update .changeset/dirty-dolphins-suffer.md Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> --- .changeset/dirty-dolphins-suffer.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/dirty-dolphins-suffer.md b/.changeset/dirty-dolphins-suffer.md index cddc4b0ec7d4..69480129e1ef 100644 --- a/.changeset/dirty-dolphins-suffer.md +++ b/.changeset/dirty-dolphins-suffer.md @@ -2,4 +2,4 @@ '@sveltejs/adapter-node': patch --- -chore: remove build step for adapter node +chore: distribute this package without bundling it From 984e602d1c6f855e94c2c82c4df5a367d28d5900 Mon Sep 17 00:00:00 2001 From: gtmnayan <50981692+gtm-nayan@users.noreply.github.com> Date: Mon, 26 Jun 2023 17:33:40 +0545 Subject: [PATCH 13/16] fix(adapter-node): merge sourcemaps (#10069) --- .changeset/dirty-dolphins-suffer.md | 2 +- .changeset/three-hotels-share.md | 5 +++++ packages/adapter-node/index.js | 30 +++++++++++++++++++++++++++-- packages/adapter-node/package.json | 1 + pnpm-lock.yaml | 3 +++ 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 .changeset/three-hotels-share.md diff --git a/.changeset/dirty-dolphins-suffer.md b/.changeset/dirty-dolphins-suffer.md index 69480129e1ef..cddc4b0ec7d4 100644 --- a/.changeset/dirty-dolphins-suffer.md +++ b/.changeset/dirty-dolphins-suffer.md @@ -2,4 +2,4 @@ '@sveltejs/adapter-node': patch --- -chore: distribute this package without bundling it +chore: remove build step for adapter node diff --git a/.changeset/three-hotels-share.md b/.changeset/three-hotels-share.md new file mode 100644 index 000000000000..d470aec21ea7 --- /dev/null +++ b/.changeset/three-hotels-share.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-node': patch +--- + +feat: load sourcemaps so that they can be merged to point to original sourcefiles diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index 0a0af6c78c4d..f172ad173881 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -1,7 +1,9 @@ import commonjs from '@rollup/plugin-commonjs'; import json from '@rollup/plugin-json'; import { nodeResolve } from '@rollup/plugin-node-resolve'; -import { readFileSync, writeFileSync } from 'node:fs'; +import { createFilter, normalizePath } from '@rollup/pluginutils'; +import { existsSync, readFileSync, writeFileSync } from 'node:fs'; +import { readFile } from 'node:fs/promises'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { rollup } from 'rollup'; @@ -97,7 +99,8 @@ export default function (opts = {}) { exportConditions: ['node'] }), commonjs({ strictRequires: true }), - json() + json(), + merge_sourcemap_plugin(tmp) ] }); @@ -111,3 +114,26 @@ export default function (opts = {}) { } }; } + +/** + * Load sourcemaps for files in the tmp directory so that the final ones + * point to the original source files, instead of the generated files in outDir. + * @param {string} tmp + * @returns {import('rollup').Plugin} + */ +function merge_sourcemap_plugin(tmp) { + const should_process_sourcemaps = createFilter(`${normalizePath(tmp)}/**/*.js`); + + return { + name: 'adapter-node-sourcemap-loader', + async load(id) { + if (!should_process_sourcemaps(id)) return; + if (!existsSync(`${id}.map`)) return; + const [code, map] = await Promise.all([ + readFile(id, 'utf-8'), + readFile(`${id}.map`, 'utf-8') + ]); + return { code, map }; + } + }; +} diff --git a/packages/adapter-node/package.json b/packages/adapter-node/package.json index 22ffd29f56e9..483f6de0f76c 100644 --- a/packages/adapter-node/package.json +++ b/packages/adapter-node/package.json @@ -41,6 +41,7 @@ "@rollup/plugin-commonjs": "^25.0.0", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", + "@rollup/pluginutils": "^5.0.2", "polka": "^1.0.0-next.22", "rollup": "^3.7.0", "sirv": "^2.0.2" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aa2ba609e390..da0836606fc3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -189,6 +189,9 @@ importers: '@rollup/plugin-node-resolve': specifier: ^15.0.1 version: 15.0.1(rollup@3.7.0) + '@rollup/pluginutils': + specifier: ^5.0.2 + version: 5.0.2(rollup@3.7.0) polka: specifier: ^1.0.0-next.22 version: 1.0.0-next.22 From 527ddd294a5f8dc00cc6cfb131389f6abec4118c Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Mon, 26 Jun 2023 08:20:04 -0700 Subject: [PATCH 14/16] make changesets minor release --- .changeset/dirty-dolphins-suffer.md | 2 +- .changeset/three-hotels-share.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/dirty-dolphins-suffer.md b/.changeset/dirty-dolphins-suffer.md index cddc4b0ec7d4..e93cfad16158 100644 --- a/.changeset/dirty-dolphins-suffer.md +++ b/.changeset/dirty-dolphins-suffer.md @@ -1,5 +1,5 @@ --- -'@sveltejs/adapter-node': patch +'@sveltejs/adapter-node': minor --- chore: remove build step for adapter node diff --git a/.changeset/three-hotels-share.md b/.changeset/three-hotels-share.md index d470aec21ea7..60cd79ab45c7 100644 --- a/.changeset/three-hotels-share.md +++ b/.changeset/three-hotels-share.md @@ -1,5 +1,5 @@ --- -'@sveltejs/adapter-node': patch +'@sveltejs/adapter-node': minor --- feat: load sourcemaps so that they can be merged to point to original sourcefiles From a0a6f6d68122a4a275c4a37ba704acfdca3f4036 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Mon, 26 Jun 2023 08:20:47 -0700 Subject: [PATCH 15/16] Update packages/adapter-node/index.js --- packages/adapter-node/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index f172ad173881..61b1b27c3841 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -8,9 +8,7 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { rollup } from 'rollup'; -/** - * @param {string} path - */ +/** @param {string} path */ const resolve = (path) => fileURLToPath(new URL(path, import.meta.url)); /** @type {import('.').default} */ From 1a6ce3e9e33631f77dd40b5521bed5ae3e07af25 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 30 Jun 2023 06:40:55 -0700 Subject: [PATCH 16/16] Update packages/adapter-node/index.js Co-authored-by: gtmnayan <50981692+gtm-nayan@users.noreply.github.com> --- packages/adapter-node/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index 61b1b27c3841..69eaee9e3e91 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -107,6 +107,8 @@ export default function (opts = {}) { format: 'esm', sourcemap: true, chunkFileNames: 'server/chunks/[name]-[hash].js', + // without this rollup will insert some imports to try speed up + // module loading but it doesn't really affect anything on the server side hoistTransitiveImports: false }); }