From 718cebd52667d15719763d66b37c9ac4890fcb74 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Mon, 12 Jun 2023 20:48:04 +0800 Subject: [PATCH] Update example dependencies versions with a script (#7367) --- .prettierrc.js => .prettierrc.cjs | 8 -- package.json | 9 +- patches/@changesets__cli@2.23.0.patch | 14 --- pnpm-lock.yaml | 145 +++++++++++++++++------- scripts/deps/update-example-versions.js | 74 ++++++++++++ 5 files changed, 183 insertions(+), 67 deletions(-) rename .prettierrc.js => .prettierrc.cjs (61%) delete mode 100644 patches/@changesets__cli@2.23.0.patch create mode 100644 scripts/deps/update-example-versions.js diff --git a/.prettierrc.js b/.prettierrc.cjs similarity index 61% rename from .prettierrc.js rename to .prettierrc.cjs index d43df33f5..0909ba219 100644 --- a/.prettierrc.js +++ b/.prettierrc.cjs @@ -8,14 +8,6 @@ module.exports = { useTabs: true, plugins: ['./node_modules/prettier-plugin-astro'], overrides: [ - { - // Changesets run Prettier using our configuration, however it uses a very old version of Prettier that does - // not support our plugin and it ends up doing more harm than good. As such, we'll disable our plugin for changelogs - files: ['CHANGELOG.md'], - options: { - plugins: [], - }, - }, { files: ['.*', '*.json', '*.md', '*.toml', '*.yml'], options: { diff --git a/package.json b/package.json index 5c369d22d..14c20296a 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "test:e2e:match": "cd packages/astro && pnpm playwright install && pnpm run test:e2e:match", "benchmark": "astro-benchmark", "lint": "eslint --cache .", - "version": "changeset version && pnpm install --no-frozen-lockfile && pnpm run format", + "version": "changeset version && node ./scripts/deps/update-example-versions.js && pnpm install --no-frozen-lockfile && pnpm run format", "preinstall": "npx only-allow pnpm" }, "workspaces": [ @@ -68,9 +68,6 @@ "allowAny": [ "astro" ] - }, - "patchedDependencies": { - "@changesets/cli@2.23.0": "patches/@changesets__cli@2.23.0.patch" } }, "dependencies": { @@ -78,8 +75,8 @@ "astro-benchmark": "workspace:*" }, "devDependencies": { - "@changesets/changelog-github": "0.4.4", - "@changesets/cli": "2.23.0", + "@changesets/changelog-github": "^0.4.8", + "@changesets/cli": "^2.26.1", "@types/node": "^18.7.21", "@typescript-eslint/eslint-plugin": "^5.58.0", "@typescript-eslint/parser": "^5.58.0", diff --git a/patches/@changesets__cli@2.23.0.patch b/patches/@changesets__cli@2.23.0.patch deleted file mode 100644 index 621c0596e..000000000 --- a/patches/@changesets__cli@2.23.0.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/dist/cli.cjs.dev.js b/dist/cli.cjs.dev.js -index 5511d0c05d3b7472876dcc8410e938ccf612654f..aa75e3982b68e1226ba1877a7f32017e517480f5 100644 ---- a/dist/cli.cjs.dev.js -+++ b/dist/cli.cjs.dev.js -@@ -279,6 +279,9 @@ async function confirmMajorRelease(pkgJSON) { - } - - async function getPackagesToRelease(changedPackages, allPackages) { -+ const isPrivate = (name) => name === 'astro-scripts' || name.startsWith('@example/') || name.startsWith('@test/') || name.startsWith('@e2e/'); -+ changedPackages = changedPackages.filter(name => !isPrivate(name)); -+ allPackages = allPackages.filter(({ packageJson: { name }}) => !isPrivate(name)); - function askInitialReleaseQuestion(defaultChoiceList) { - return askCheckboxPlus( // TODO: Make this wording better - // TODO: take objects and be fancy with matching \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 82a7e337a..51ca99c86 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,11 +9,6 @@ overrides: packageExtensionsChecksum: 01871422d489547c532184effb134b35 -patchedDependencies: - '@changesets/cli@2.23.0': - hash: kcozqtpxuwjzskw6zg5royevn4 - path: patches/@changesets__cli@2.23.0.patch - importers: .: @@ -26,11 +21,11 @@ importers: version: link:benchmark devDependencies: '@changesets/changelog-github': - specifier: 0.4.4 - version: 0.4.4 + specifier: ^0.4.8 + version: 0.4.8 '@changesets/cli': - specifier: 2.23.0 - version: 2.23.0(patch_hash=kcozqtpxuwjzskw6zg5royevn4) + specifier: ^2.26.1 + version: 2.26.1 '@types/node': specifier: ^18.7.21 version: 18.16.3 @@ -4390,7 +4385,7 @@ importers: version: 9.2.2 vite: specifier: ^4.3.1 - version: 4.3.1(@types/node@18.16.3)(sass@1.52.2) + version: 4.3.1(@types/node@14.18.21) packages/integrations/netlify/test/edge-functions/fixtures/dynimport: dependencies: @@ -4908,7 +4903,7 @@ importers: version: 3.0.0(vite@4.3.1)(vue@3.2.47) '@vue/babel-plugin-jsx': specifier: ^1.1.1 - version: 1.1.1(@babel/core@7.21.8) + version: 1.1.1 '@vue/compiler-sfc': specifier: ^3.2.39 version: 3.2.39 @@ -5472,7 +5467,7 @@ packages: astro: '*' svelte: ^3.54.0 dependencies: - '@sveltejs/vite-plugin-svelte': 2.4.1(svelte@3.58.0)(vite@4.3.1) + '@sveltejs/vite-plugin-svelte': 2.4.1(svelte@3.58.0) astro: link:packages/astro svelte: 3.58.0 svelte2tsx: 0.5.23(svelte@3.58.0)(typescript@5.0.2) @@ -7054,8 +7049,8 @@ packages: '@changesets/types': 5.2.1 dev: true - /@changesets/changelog-github@0.4.4: - resolution: {integrity: sha512-htSILqCkyYtTB5/LoVKwx7GCJQGxAiBcYbfUKWiz/QoDARuM01owYtMXhV6/iytJZq/Dqqz3PjMZUNB4MphpbQ==} + /@changesets/changelog-github@0.4.8: + resolution: {integrity: sha512-jR1DHibkMAb5v/8ym77E4AMNWZKB5NPzw5a5Wtqm1JepAuIF+hrKp2u04NKM14oBZhHglkCfrla9uq8ORnK/dw==} dependencies: '@changesets/get-github-info': 0.5.2 '@changesets/types': 5.2.1 @@ -7064,8 +7059,8 @@ packages: - encoding dev: true - /@changesets/cli@2.23.0(patch_hash=kcozqtpxuwjzskw6zg5royevn4): - resolution: {integrity: sha512-Gi3tMi0Vr6eNd8GX6q73tbOm9XOzGfuLEm4PYVeWG2neg5DlRGNOjYwrFULJ/An3N9MHtHn4r5h1Qvnju9Ijug==} + /@changesets/cli@2.26.1: + resolution: {integrity: sha512-XnTa+b51vt057fyAudvDKGB0Sh72xutQZNAdXkCqPBKO2zvs2yYZx5hFZj1u9cbtpwM6Sxtcr02/FQJfZOzemQ==} hasBin: true dependencies: '@babel/runtime': 7.21.5 @@ -7076,12 +7071,12 @@ packages: '@changesets/errors': 0.1.4 '@changesets/get-dependents-graph': 1.3.5 '@changesets/get-release-plan': 3.0.16 - '@changesets/git': 1.5.0 + '@changesets/git': 2.0.0 '@changesets/logger': 0.0.5 '@changesets/pre': 1.0.14 '@changesets/read': 0.5.9 '@changesets/types': 5.2.1 - '@changesets/write': 0.1.9 + '@changesets/write': 0.2.3 '@manypkg/get-packages': 1.1.3 '@types/is-ci': 3.0.0 '@types/semver': 6.2.3 @@ -7102,7 +7097,6 @@ packages: term-size: 2.2.1 tty-table: 4.2.1 dev: true - patched: true /@changesets/config@2.3.0: resolution: {integrity: sha512-EgP/px6mhCx8QeaMAvWtRrgyxW08k/Bx2tpGT+M84jEdX37v3VKfh4Cz1BkwrYKuMV2HZKeHOh8sHvja/HcXfQ==} @@ -7157,17 +7151,6 @@ packages: resolution: {integrity: sha512-SVqwYs5pULYjYT4op21F2pVbcrca4qA/bAA3FmFXKMN7Y+HcO8sbZUTx3TAy2VXulP2FACd1aC7f2nTuqSPbqg==} dev: true - /@changesets/git@1.5.0: - resolution: {integrity: sha512-Xo8AT2G7rQJSwV87c8PwMm6BAc98BnufRMsML7m7Iw8Or18WFvFmxqG5aOL5PBvhgq9KrKvaeIBNIymracSuHg==} - dependencies: - '@babel/runtime': 7.21.5 - '@changesets/errors': 0.1.4 - '@changesets/types': 5.2.1 - '@manypkg/get-packages': 1.1.3 - is-subdir: 1.2.0 - spawndamnit: 2.0.0 - dev: true - /@changesets/git@2.0.0: resolution: {integrity: sha512-enUVEWbiqUTxqSnmesyJGWfzd51PY4H7mH9yUw0hPVpZBJ6tQZFMU3F3mT/t9OJ/GjyiM4770i+sehAn6ymx6A==} dependencies: @@ -7224,14 +7207,14 @@ packages: resolution: {integrity: sha512-myLfHbVOqaq9UtUKqR/nZA/OY7xFjQMdfgfqeZIBK4d0hA6pgxArvdv8M+6NUzzBsjWLOtvApv8YHr4qM+Kpfg==} dev: true - /@changesets/write@0.1.9: - resolution: {integrity: sha512-E90ZrsrfJVOOQaP3Mm5Xd7uDwBAqq3z5paVEavTHKA8wxi7NAL8CmjgbGxSFuiP7ubnJA2BuHlrdE4z86voGOg==} + /@changesets/write@0.2.3: + resolution: {integrity: sha512-Dbamr7AIMvslKnNYsLFafaVORx4H0pvCA2MHqgtNCySMe1blImEyAEOzDmcgKAkgz4+uwoLz7demIrX+JBr/Xw==} dependencies: '@babel/runtime': 7.21.5 '@changesets/types': 5.2.1 fs-extra: 7.0.1 human-id: 1.0.2 - prettier: 1.19.1 + prettier: 2.8.8 dev: true /@cloudflare/kv-asset-handler@0.2.0: @@ -8594,6 +8577,24 @@ packages: string.prototype.matchall: 4.0.8 dev: false + /@sveltejs/vite-plugin-svelte-inspector@1.0.2(@sveltejs/vite-plugin-svelte@2.4.1)(svelte@3.58.0): + resolution: {integrity: sha512-Cy1dUMcYCnDVV/hPLXa43YZJ2jGKVW5rA0xuNL9dlmYhT0yoS1g7+FOFSRlgk0BXKk/Oc7grs+8BVA5Iz2fr8A==} + engines: {node: ^14.18.0 || >= 16} + peerDependencies: + '@sveltejs/vite-plugin-svelte': ^2.2.0 + svelte: ^3.54.0 || ^4.0.0-next.0 + vite: ^4.0.0 + peerDependenciesMeta: + vite: + optional: true + dependencies: + '@sveltejs/vite-plugin-svelte': 2.4.1(svelte@3.58.0) + debug: 4.3.4 + svelte: 3.58.0 + transitivePeerDependencies: + - supports-color + dev: false + /@sveltejs/vite-plugin-svelte-inspector@1.0.2(@sveltejs/vite-plugin-svelte@2.4.1)(svelte@3.58.0)(vite@4.3.1): resolution: {integrity: sha512-Cy1dUMcYCnDVV/hPLXa43YZJ2jGKVW5rA0xuNL9dlmYhT0yoS1g7+FOFSRlgk0BXKk/Oc7grs+8BVA5Iz2fr8A==} engines: {node: ^14.18.0 || >= 16} @@ -8613,6 +8614,28 @@ packages: - supports-color dev: false + /@sveltejs/vite-plugin-svelte@2.4.1(svelte@3.58.0): + resolution: {integrity: sha512-bNNKvoRY89ptY7udeBSCmTdCVwkjmMcZ0j/z9J5MuedT8jPjq0zrknAo/jF1sToAza4NVaAgR9AkZoD9oJJmnA==} + engines: {node: ^14.18.0 || >= 16} + peerDependencies: + svelte: ^3.54.0 || ^4.0.0-next.0 + vite: ^4.0.0 + peerDependenciesMeta: + vite: + optional: true + dependencies: + '@sveltejs/vite-plugin-svelte-inspector': 1.0.2(@sveltejs/vite-plugin-svelte@2.4.1)(svelte@3.58.0) + debug: 4.3.4 + deepmerge: 4.3.1 + kleur: 4.1.5 + magic-string: 0.30.0 + svelte: 3.58.0 + svelte-hmr: 0.15.1(svelte@3.58.0) + vitefu: 0.2.4(vite@4.3.1) + transitivePeerDependencies: + - supports-color + dev: false + /@sveltejs/vite-plugin-svelte@2.4.1(svelte@3.58.0)(vite@4.3.1): resolution: {integrity: sha512-bNNKvoRY89ptY7udeBSCmTdCVwkjmMcZ0j/z9J5MuedT8jPjq0zrknAo/jF1sToAza4NVaAgR9AkZoD9oJJmnA==} engines: {node: ^14.18.0 || >= 16} @@ -9327,6 +9350,23 @@ packages: resolution: {integrity: sha512-hz4R8tS5jMn8lDq6iD+yWL6XNB699pGIVLk7WSJnn1dbpjaazsjZQkieJoRX6gW5zpYSCFqQ7jUquPNY65tQYA==} dev: false + /@vue/babel-plugin-jsx@1.1.1: + resolution: {integrity: sha512-j2uVfZjnB5+zkcbc/zsOc0fSNGCMMjaEXP52wdwdIfn0qjFfEYpYZBFKFg+HHnQeJCVrjOeO0YxgaL7DMrym9w==} + dependencies: + '@babel/helper-module-imports': 7.21.4 + '@babel/plugin-syntax-jsx': 7.21.4(@babel/core@7.18.2) + '@babel/template': 7.20.7 + '@babel/traverse': 7.18.2 + '@babel/types': 7.21.5 + '@vue/babel-helper-vue-transform-on': 1.0.2 + camelcase: 6.3.0 + html-tags: 3.3.1 + svg-tags: 1.0.0 + transitivePeerDependencies: + - '@babel/core' + - supports-color + dev: false + /@vue/babel-plugin-jsx@1.1.1(@babel/core@7.21.8): resolution: {integrity: sha512-j2uVfZjnB5+zkcbc/zsOc0fSNGCMMjaEXP52wdwdIfn0qjFfEYpYZBFKFg+HHnQeJCVrjOeO0YxgaL7DMrym9w==} dependencies: @@ -15499,12 +15539,6 @@ packages: synckit: 0.8.5 dev: false - /prettier@1.19.1: - resolution: {integrity: sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==} - engines: {node: '>=4'} - hasBin: true - dev: true - /prettier@2.8.8: resolution: {integrity: sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==} engines: {node: '>=10.13.0'} @@ -17630,6 +17664,39 @@ packages: - supports-color dev: false + /vite@4.3.1(@types/node@14.18.21): + resolution: {integrity: sha512-EPmfPLAI79Z/RofuMvkIS0Yr091T2ReUoXQqc5ppBX/sjFRhHKiPPF/R46cTdoci/XgeQpB23diiJxq5w30vdg==} + engines: {node: ^14.18.0 || >=16.0.0} + hasBin: true + peerDependencies: + '@types/node': '>= 14' + less: '*' + sass: '*' + stylus: '*' + sugarss: '*' + terser: ^5.4.0 + peerDependenciesMeta: + '@types/node': + optional: true + less: + optional: true + sass: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + dependencies: + '@types/node': 14.18.21 + esbuild: 0.17.18 + postcss: 8.4.23 + rollup: 3.21.8 + optionalDependencies: + fsevents: 2.3.2 + dev: true + /vite@4.3.1(@types/node@18.16.3)(sass@1.52.2): resolution: {integrity: sha512-EPmfPLAI79Z/RofuMvkIS0Yr091T2ReUoXQqc5ppBX/sjFRhHKiPPF/R46cTdoci/XgeQpB23diiJxq5w30vdg==} engines: {node: ^14.18.0 || >=16.0.0} diff --git a/scripts/deps/update-example-versions.js b/scripts/deps/update-example-versions.js new file mode 100644 index 000000000..13018a791 --- /dev/null +++ b/scripts/deps/update-example-versions.js @@ -0,0 +1,74 @@ +import path from 'node:path'; +import fs from 'node:fs/promises'; +import { globby as glob } from 'globby'; + +/* + This file updates the dependencies' versions in `examples/*` to match the workspace packages' versions. + This should be run after `changeset version` so the release PR updates all the versions together. +*/ + +const rootUrl = new URL('../..', import.meta.url); +const rootPackageJson = JSON.parse(await fs.readFile(new URL('./package.json', rootUrl), 'utf-8')); + +// get all workspace package name to versions +/** @type {Map} */ +const packageToVersions = new Map(); + +// Changeset detects workspace packages to publish via `workspaces` in package.json. +// Although this conflicts with the `pnpm-workspace.yaml` config, it's easier to configure what gets +// published through this field, so this file also respects this field when updating the versions. +const workspaceDirs = await glob(rootPackageJson.workspaces, { + onlyDirectories: true, + cwd: rootUrl, +}); +for (const workspaceDir of workspaceDirs) { + const packageJsonPath = path.join(workspaceDir, './package.json'); + const packageJson = await readAndParsePackageJson(packageJsonPath); + if (!packageJson) continue; + + if (!packageJson.name) { + throw new Error(`${packageJsonPath} does not contain a "name" field.`); + } + if (!packageJson.version) { + throw new Error(`${packageJsonPath} does not contain a "version" field.`); + } + + packageToVersions.set(packageJson.name, packageJson.version); +} + +// Update all examples' package.json +const exampleDirs = await glob('examples/*', { + onlyDirectories: true, + cwd: rootUrl, +}); +for (const exampleDir of exampleDirs) { + const packageJsonPath = path.join(exampleDir, './package.json'); + const packageJson = await readAndParsePackageJson(packageJsonPath); + if (!packageJson) continue; + + // Update dependencies + for (const depName of Object.keys(packageJson.dependencies ?? [])) { + if (packageToVersions.has(depName)) { + packageJson.dependencies[depName] = `^${packageToVersions.get(depName)}`; + } + } + + // Update devDependencies + for (const depName of Object.keys(packageJson.devDependencies ?? [])) { + if (packageToVersions.has(depName)) { + packageJson.devDependencies[depName] = `^${packageToVersions.get(depName)}`; + } + } + + await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n'); +} + +/** + * @param {string} packageJsonPath + * @returns {Promise | undefined>} + */ +async function readAndParsePackageJson(packageJsonPath) { + try { + return JSON.parse(await fs.readFile(packageJsonPath, 'utf-8')); + } catch {} +}