From e541a4057a00f5ab6740fb51b7f88f17776da50a Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 17 Jan 2025 01:48:11 -0800 Subject: [PATCH] feat: remove the postinstall script in favor of template prepare script (#13304) since pnpm 10 they don't run at all, and previously they didn't run after the first install either for pnpm users --- .changeset/shaggy-tools-pump.md | 14 +++++ packages/kit/package.json | 7 +-- packages/kit/postinstall.js | 55 ------------------- packages/kit/test/apps/amp/package.json | 1 + packages/kit/test/apps/basics/package.json | 1 + packages/kit/test/apps/dev-only/package.json | 1 + packages/kit/test/apps/embed/package.json | 1 + .../test/apps/hash-based-routing/package.json | 1 + packages/kit/test/apps/no-ssr/package.json | 1 + packages/kit/test/apps/options-2/package.json | 1 + packages/kit/test/apps/options/package.json | 1 + packages/kit/test/apps/writes/package.json | 1 + .../package.json | 1 + .../package.json | 1 + .../package.json | 1 + .../package.json | 1 + .../apps/private-dynamic-env/package.json | 1 + .../package.json | 1 + .../apps/private-static-env/package.json | 1 + .../package.json | 1 + .../apps/server-only-folder/package.json | 1 + .../package.json | 1 + .../apps/server-only-module/package.json | 1 + .../package.json | 1 + .../service-worker-private-env/package.json | 1 + .../apps/syntax-error/package.json | 3 +- playgrounds/basic/package.json | 1 + pnpm-lock.yaml | 3 - 28 files changed, 41 insertions(+), 64 deletions(-) create mode 100644 .changeset/shaggy-tools-pump.md delete mode 100644 packages/kit/postinstall.js diff --git a/.changeset/shaggy-tools-pump.md b/.changeset/shaggy-tools-pump.md new file mode 100644 index 000000000000..93c9b2338f2d --- /dev/null +++ b/.changeset/shaggy-tools-pump.md @@ -0,0 +1,14 @@ +--- +'@sveltejs/kit': minor +--- + +feat: remove the `postinstall` script to support pnpm 10 + +NOTE: users should add `"prepare": "svelte-kit sync`" to their `package.json` in order to avoid the following warning upon first running Vite: +``` +▲ [WARNING] Cannot find base config file "./.svelte-kit/tsconfig.json" [tsconfig.json] + + tsconfig.json:2:12: + 2 │ "extends": "./.svelte-kit/tsconfig.json", + ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``` diff --git a/packages/kit/package.json b/packages/kit/package.json index 38c3bac6b552..d7339b433916 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -28,8 +28,7 @@ "mrmime": "^2.0.0", "sade": "^1.8.1", "set-cookie-parser": "^2.6.0", - "sirv": "^3.0.0", - "tiny-glob": "^0.2.9" + "sirv": "^3.0.0" }, "devDependencies": { "@playwright/test": "^1.44.1", @@ -59,8 +58,7 @@ "!src/core/**/fixtures", "!src/core/**/test", "types", - "svelte-kit.js", - "postinstall.js" + "svelte-kit.js" ], "scripts": { "lint": "prettier --config ../../.prettierrc --check .", @@ -72,7 +70,6 @@ "test:cross-platform:dev": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:dev", "test:cross-platform:build": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:build", "test:unit": "vitest --config kit.vitest.config.js run", - "postinstall": "node postinstall.js", "prepublishOnly": "pnpm generate:types", "generate:version": "node scripts/generate-version.js", "generate:types": "node scripts/generate-dts.js" diff --git a/packages/kit/postinstall.js b/packages/kit/postinstall.js deleted file mode 100644 index ac79151ebc44..000000000000 --- a/packages/kit/postinstall.js +++ /dev/null @@ -1,55 +0,0 @@ -import { load_config } from './src/core/config/index.js'; -import glob from 'tiny-glob/sync.js'; -import fs from 'node:fs'; -import process from 'node:process'; - -try { - const cwd = process.env.INIT_CWD ?? process.cwd(); - process.chdir(cwd); - - if (fs.existsSync('package.json')) { - const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); - - const workspaces = []; - - if (pkg.workspaces) { - // Find all npm and Yarn workspace glob patterns - // https://classic.yarnpkg.com/blog/2018/02/15/nohoist/ - // https://docs.npmjs.com/cli/v9/configuring-npm/package-json#workspaces - const patterns = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces.packages; - - for (const pattern of patterns) { - workspaces.push( - ...glob(pattern, { cwd, absolute: true }).filter((path) => - fs.statSync(path).isDirectory() - ) - ); - } - } else { - workspaces.push(cwd); - } - - for (const cwd of workspaces) { - process.chdir(cwd); - - if (!fs.existsSync('package.json')) continue; - if (!fs.existsSync('svelte.config.js')) continue; - - const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); - if (!pkg.dependencies?.['@sveltejs/kit'] && !pkg.devDependencies?.['@sveltejs/kit']) continue; - - // defer import until after the chdir so that peer dependency resolves correctly - const sync = await import('./src/core/sync/sync.js'); - - try { - const config = await load_config(); - sync.all(config, 'development'); - } catch (error) { - console.error('Error while trying to sync SvelteKit config'); - console.error(error); - } - } - } -} catch (error) { - console.error(error); -} diff --git a/packages/kit/test/apps/amp/package.json b/packages/kit/test/apps/amp/package.json index 7774f14aba80..25ebbbebc084 100644 --- a/packages/kit/test/apps/amp/package.json +++ b/packages/kit/test/apps/amp/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "test": "pnpm test:dev && pnpm test:build", "test:dev": "cross-env DEV=true playwright test", diff --git a/packages/kit/test/apps/basics/package.json b/packages/kit/test/apps/basics/package.json index 0ae5b0924880..2627746ce7fd 100644 --- a/packages/kit/test/apps/basics/package.json +++ b/packages/kit/test/apps/basics/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "test": "node test/setup.js && pnpm test:dev && pnpm test:build", "test:dev": "node -e \"fs.rmSync('test/errors.json', { force: true })\" && cross-env DEV=true playwright test", diff --git a/packages/kit/test/apps/dev-only/package.json b/packages/kit/test/apps/dev-only/package.json index 4dccabf51749..02f5605fc3f0 100644 --- a/packages/kit/test/apps/dev-only/package.json +++ b/packages/kit/test/apps/dev-only/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "test": "cross-env DEV=true playwright test" }, diff --git a/packages/kit/test/apps/embed/package.json b/packages/kit/test/apps/embed/package.json index 4559fd1341a0..ce95b4974ee9 100644 --- a/packages/kit/test/apps/embed/package.json +++ b/packages/kit/test/apps/embed/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "test": "pnpm test:dev && pnpm test:build", "test:dev": "cross-env DEV=true playwright test", diff --git a/packages/kit/test/apps/hash-based-routing/package.json b/packages/kit/test/apps/hash-based-routing/package.json index 31eb52c57468..e3f1186e3069 100644 --- a/packages/kit/test/apps/hash-based-routing/package.json +++ b/packages/kit/test/apps/hash-based-routing/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "test": "pnpm test:dev && pnpm test:build", "test:dev": "cross-env DEV=true playwright test", diff --git a/packages/kit/test/apps/no-ssr/package.json b/packages/kit/test/apps/no-ssr/package.json index 7f4348976632..f894c1cc0116 100644 --- a/packages/kit/test/apps/no-ssr/package.json +++ b/packages/kit/test/apps/no-ssr/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "test": "pnpm test:dev && pnpm test:build", "test:dev": "cross-env DEV=true playwright test", diff --git a/packages/kit/test/apps/options-2/package.json b/packages/kit/test/apps/options-2/package.json index 6b7c7de21657..ffb334b0d7c3 100644 --- a/packages/kit/test/apps/options-2/package.json +++ b/packages/kit/test/apps/options-2/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "test": "pnpm test:dev && pnpm test:build", "test:dev": "cross-env DEV=true playwright test", diff --git a/packages/kit/test/apps/options/package.json b/packages/kit/test/apps/options/package.json index 85c63b12321f..c2df38711db6 100644 --- a/packages/kit/test/apps/options/package.json +++ b/packages/kit/test/apps/options/package.json @@ -6,6 +6,7 @@ "dev": "vite dev -c vite.custom.config.js", "build": "vite build -c vite.custom.config.js --mode custom", "preview": "vite preview -c vite.custom.config.js", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "test": "pnpm test:dev && pnpm test:build", "test:dev": "cross-env DEV=true playwright test", diff --git a/packages/kit/test/apps/writes/package.json b/packages/kit/test/apps/writes/package.json index e5bf4b02eed4..93bf67a7556f 100644 --- a/packages/kit/test/apps/writes/package.json +++ b/packages/kit/test/apps/writes/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "test": "pnpm test:dev && pnpm test:build", "test:dev": "cross-env DEV=true playwright test", diff --git a/packages/kit/test/build-errors/apps/prerender-entry-generator-mismatch/package.json b/packages/kit/test/build-errors/apps/prerender-entry-generator-mismatch/package.json index cf4d9913e0d7..57b7a858d66c 100644 --- a/packages/kit/test/build-errors/apps/prerender-entry-generator-mismatch/package.json +++ b/packages/kit/test/build-errors/apps/prerender-entry-generator-mismatch/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check" }, "devDependencies": { diff --git a/packages/kit/test/build-errors/apps/prerenderable-incorrect-fragment/package.json b/packages/kit/test/build-errors/apps/prerenderable-incorrect-fragment/package.json index cf4d9913e0d7..57b7a858d66c 100644 --- a/packages/kit/test/build-errors/apps/prerenderable-incorrect-fragment/package.json +++ b/packages/kit/test/build-errors/apps/prerenderable-incorrect-fragment/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check" }, "devDependencies": { diff --git a/packages/kit/test/build-errors/apps/prerenderable-not-prerendered/package.json b/packages/kit/test/build-errors/apps/prerenderable-not-prerendered/package.json index 834924d345eb..476e7566e259 100644 --- a/packages/kit/test/build-errors/apps/prerenderable-not-prerendered/package.json +++ b/packages/kit/test/build-errors/apps/prerenderable-not-prerendered/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check" }, "devDependencies": { diff --git a/packages/kit/test/build-errors/apps/private-dynamic-env-dynamic-import/package.json b/packages/kit/test/build-errors/apps/private-dynamic-env-dynamic-import/package.json index b2effd8466cc..baf4b7995a73 100644 --- a/packages/kit/test/build-errors/apps/private-dynamic-env-dynamic-import/package.json +++ b/packages/kit/test/build-errors/apps/private-dynamic-env-dynamic-import/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "check:watch": "svelte-check --watch" }, diff --git a/packages/kit/test/build-errors/apps/private-dynamic-env/package.json b/packages/kit/test/build-errors/apps/private-dynamic-env/package.json index 6cc97fed6bf7..f1fb38292390 100644 --- a/packages/kit/test/build-errors/apps/private-dynamic-env/package.json +++ b/packages/kit/test/build-errors/apps/private-dynamic-env/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "check:watch": "svelte-check --watch" }, diff --git a/packages/kit/test/build-errors/apps/private-static-env-dynamic-import/package.json b/packages/kit/test/build-errors/apps/private-static-env-dynamic-import/package.json index c98b0c2e266a..e6cbe7084777 100644 --- a/packages/kit/test/build-errors/apps/private-static-env-dynamic-import/package.json +++ b/packages/kit/test/build-errors/apps/private-static-env-dynamic-import/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "check:watch": "svelte-check --watch" }, diff --git a/packages/kit/test/build-errors/apps/private-static-env/package.json b/packages/kit/test/build-errors/apps/private-static-env/package.json index 40edab1e2516..7217befce459 100644 --- a/packages/kit/test/build-errors/apps/private-static-env/package.json +++ b/packages/kit/test/build-errors/apps/private-static-env/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "check:watch": "svelte-check --watch" }, diff --git a/packages/kit/test/build-errors/apps/server-only-folder-dynamic-import/package.json b/packages/kit/test/build-errors/apps/server-only-folder-dynamic-import/package.json index 36c162f4cb18..123d621cc558 100644 --- a/packages/kit/test/build-errors/apps/server-only-folder-dynamic-import/package.json +++ b/packages/kit/test/build-errors/apps/server-only-folder-dynamic-import/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "check:watch": "svelte-check --watch" }, diff --git a/packages/kit/test/build-errors/apps/server-only-folder/package.json b/packages/kit/test/build-errors/apps/server-only-folder/package.json index 80c89040bbd3..a1ffc94d9d47 100644 --- a/packages/kit/test/build-errors/apps/server-only-folder/package.json +++ b/packages/kit/test/build-errors/apps/server-only-folder/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "check:watch": "svelte-check --watch" }, diff --git a/packages/kit/test/build-errors/apps/server-only-module-dynamic-import/package.json b/packages/kit/test/build-errors/apps/server-only-module-dynamic-import/package.json index a3ce9cb0317b..d41ec5f19afd 100644 --- a/packages/kit/test/build-errors/apps/server-only-module-dynamic-import/package.json +++ b/packages/kit/test/build-errors/apps/server-only-module-dynamic-import/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "check:watch": "svelte-check --watch" }, diff --git a/packages/kit/test/build-errors/apps/server-only-module/package.json b/packages/kit/test/build-errors/apps/server-only-module/package.json index d3f317627930..51ce8aebd0d0 100644 --- a/packages/kit/test/build-errors/apps/server-only-module/package.json +++ b/packages/kit/test/build-errors/apps/server-only-module/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "check:watch": "svelte-check --watch" }, diff --git a/packages/kit/test/build-errors/apps/service-worker-dynamic-public-env/package.json b/packages/kit/test/build-errors/apps/service-worker-dynamic-public-env/package.json index d420359daf0f..aaf360d34974 100644 --- a/packages/kit/test/build-errors/apps/service-worker-dynamic-public-env/package.json +++ b/packages/kit/test/build-errors/apps/service-worker-dynamic-public-env/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "check:watch": "svelte-check --watch" }, diff --git a/packages/kit/test/build-errors/apps/service-worker-private-env/package.json b/packages/kit/test/build-errors/apps/service-worker-private-env/package.json index 06f895237d94..466853ba6c0b 100644 --- a/packages/kit/test/build-errors/apps/service-worker-private-env/package.json +++ b/packages/kit/test/build-errors/apps/service-worker-private-env/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prepare": "svelte-kit sync", "check": "svelte-kit sync && tsc && svelte-check", "check:watch": "svelte-check --watch" }, diff --git a/packages/kit/test/build-errors/apps/syntax-error/package.json b/packages/kit/test/build-errors/apps/syntax-error/package.json index 194ea56a99fe..e2afad26e8e3 100644 --- a/packages/kit/test/build-errors/apps/syntax-error/package.json +++ b/packages/kit/test/build-errors/apps/syntax-error/package.json @@ -5,7 +5,8 @@ "scripts": { "dev": "vite dev", "build": "vite build", - "preview": "vite preview" + "preview": "vite preview", + "prepare": "svelte-kit sync" }, "devDependencies": { "@sveltejs/kit": "workspace:^", diff --git a/playgrounds/basic/package.json b/playgrounds/basic/package.json index 216d786a439a..777ff2d38116 100644 --- a/playgrounds/basic/package.json +++ b/playgrounds/basic/package.json @@ -7,6 +7,7 @@ "build": "vite build && npm run package", "preview": "vite preview", "package": "svelte-kit sync && svelte-package && publint", + "prepare": "svelte-kit sync", "prepublishOnly": "npm run package", "check": "svelte-kit sync && svelte-check", "check:watch": "svelte-kit sync && svelte-check --watch", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 59b71725e173..3988c1e69f71 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -375,9 +375,6 @@ importers: sirv: specifier: ^3.0.0 version: 3.0.0 - tiny-glob: - specifier: ^0.2.9 - version: 0.2.9 devDependencies: '@playwright/test': specifier: ^1.44.1