From 50cf5fdd9870a31ed3d99f771ff2ad5499ea2008 Mon Sep 17 00:00:00 2001 From: Mogeko Date: Mon, 17 Jun 2024 12:37:03 +0800 Subject: [PATCH 1/2] build: rewrite scripts with TypeScript --- .github/changeset-version.cjs | 14 ------------- .github/changeset-version.ts | 25 +++++++++++++++++++++++ package.json | 6 ++++-- scripts/meta.cjs | 37 ----------------------------------- scripts/meta.ts | 30 ++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 53 deletions(-) delete mode 100644 .github/changeset-version.cjs create mode 100644 .github/changeset-version.ts delete mode 100644 scripts/meta.cjs create mode 100644 scripts/meta.ts diff --git a/.github/changeset-version.cjs b/.github/changeset-version.cjs deleted file mode 100644 index 6bc15b3..0000000 --- a/.github/changeset-version.cjs +++ /dev/null @@ -1,14 +0,0 @@ -// ORIGINALLY FROM CLOUDFLARE WRANGLER: -// https://github.com/cloudflare/wrangler2/blob/main/.github/changeset-version.js - -const { execSync } = require("node:child_process"); - -// This script is used by the `release.yml` workflow to update the version of the packages being released. -// The standard step is only to run `changeset version` but this does not update the pnpm-lock.yaml file. -// So we also run `pnpm install`, which does this update. -// This is a workaround until this is handled automatically by `changeset version`. -// See https://github.com/changesets/changesets/issues/421. -execSync("pnpm changeset version"); - -// Run `pnpm install` to update the pnpm-lock.yaml file. -execSync("pnpm install --lockfile-only"); diff --git a/.github/changeset-version.ts b/.github/changeset-version.ts new file mode 100644 index 0000000..f205374 --- /dev/null +++ b/.github/changeset-version.ts @@ -0,0 +1,25 @@ +// ORIGINALLY FROM CLOUDFLARE WRANGLER: +// https://github.com/cloudflare/wrangler2/blob/main/.github/changeset-version.js + +import { exec } from "node:child_process"; +import util from "node:util"; + +const execPromise = util.promisify(exec); + +try { + const results = [ + // This script is used by the `release.yml` workflow to update the version of the packages being released. + // The standard step is only to run `changeset version` but this does not update the pnpm-lock.yaml file. + // So we also run `pnpm install`, which does this update. + // This is a workaround until this is handled automatically by `changeset version`. + // See https://github.com/changesets/changesets/issues/421. + await execPromise("pnpm changeset version"), + // Run `pnpm install` to update the pnpm-lock.yaml file. + await execPromise("pnpm install --lockfile-only"), + ]; + + console.log(results.map(({ stdout, stderr }) => stdout || stderr).join("\n")); +} catch (error) { + console.error(error.message); + process.exit(1); +} diff --git a/package.json b/package.json index f8ad3ab..290b032 100644 --- a/package.json +++ b/package.json @@ -18,16 +18,18 @@ "build": "turbo run build && pnpm run meta", "test": "turbo run test", "cov": "turbo run cov", - "meta": "node ./scripts/meta.cjs", + "meta": "vite-node ./scripts/meta.ts", "lint": "turbo run lint", "fmt": "turbo run fmt" }, "devDependencies": { "@changesets/changelog-github": "^0.5.0", "@changesets/cli": "^2.27.5", + "@types/node": "^20.14.2", "prettier": "^3.3.2", "turbo": "^2.0.4", - "typescript": "^5.4.5" + "typescript": "^5.4.5", + "vite-node": "^1.6.0" }, "packageManager": "pnpm@9.3.0", "engines": { diff --git a/scripts/meta.cjs b/scripts/meta.cjs deleted file mode 100644 index 4486450..0000000 --- a/scripts/meta.cjs +++ /dev/null @@ -1,37 +0,0 @@ -const fs = require("node:fs").promises; -const path = require("node:path"); - -async function main() { - const pkg = require(path.resolve(__dirname, "../package.json")); - const releasePath = path.resolve(__dirname, "../release"); - const releaseFiles = await fs.readdir(releasePath); - const baseURL = - process.env.BASE_URL || "https://mogeko.github.io/userscripts"; - - const meta = { - name: pkg.name, - description: pkg.description, - homepage: pkg.homepage, - author: pkg.author, - license: pkg.license, - resource: releaseFiles - .filter((file) => !file.endsWith("index.json")) - .map((file) => [baseURL, file].join("/")), - packer: "https://www.npmjs.com/package/vite", - env: { - NODE_VERSION: process.version, - RUNNER_OS: process.env.RUNNER_OS, - RUNNER_ARCH: process.env.RUNNER_ARCH, - }, - date: new Date(Date.now()).toISOString(), - }; - - fs.writeFile( - path.resolve(__dirname, "../release/index.json"), - JSON.stringify(meta, null, 2) - ); - - return meta; -} - -main(); diff --git a/scripts/meta.ts b/scripts/meta.ts new file mode 100644 index 0000000..e568268 --- /dev/null +++ b/scripts/meta.ts @@ -0,0 +1,30 @@ +import fs from "node:fs/promises"; +import path from "node:path"; +import pkg from "../package.json"; + +const releasePath = path.resolve(__dirname, "../release"); +const releaseFiles = await fs.readdir(releasePath); +const baseURL = process.env.BASE_URL || "https://mogeko.github.io/userscripts"; + +const meta = { + name: pkg.name, + description: pkg.description, + homepage: pkg.homepage, + author: pkg.author, + license: pkg.license, + resource: releaseFiles + .filter((file) => !file.endsWith("index.json")) + .map((file) => [baseURL, file].join("/")), + packer: "https://www.npmjs.com/package/vite", + env: { + NODE_VERSION: process.version, + RUNNER_OS: process.env.RUNNER_OS, + RUNNER_ARCH: process.env.RUNNER_ARCH, + }, + date: new Date(Date.now()).toISOString(), +}; + +await fs.writeFile( + path.resolve(__dirname, "../release/index.json"), + JSON.stringify(meta, null, 2) +); From 9c76dddd6b99e86df481728c387ed7c931ba54b5 Mon Sep 17 00:00:00 2001 From: Mogeko Date: Mon, 17 Jun 2024 12:39:13 +0800 Subject: [PATCH 2/2] fix: fix `pnpm-lock.yaml` --- pnpm-lock.yaml | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8cdab00..9abfe79 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@changesets/cli': specifier: ^2.27.5 version: 2.27.5 + '@types/node': + specifier: ^20.14.2 + version: 20.14.2 prettier: specifier: ^3.3.2 version: 3.3.2 @@ -23,6 +26,9 @@ importers: typescript: specifier: ^5.4.5 version: 5.4.5 + vite-node: + specifier: ^1.6.0 + version: 1.6.0(@types/node@20.14.2) packages/_template: devDependencies: @@ -40,7 +46,7 @@ importers: version: 5.3.1(@types/node@20.14.2) vite-plugin-monkey: specifier: ^4.0.3 - version: 4.0.3(vite@5.3.1) + version: 4.0.3(vite@5.3.1(@types/node@20.14.2)) packages/_tsconfig: devDependencies: @@ -64,7 +70,7 @@ importers: version: 5.3.1(@types/node@20.14.2) vite-plugin-monkey: specifier: ^4.0.3 - version: 4.0.3(vite@5.3.1) + version: 4.0.3(vite@5.3.1(@types/node@20.14.2)) packages/douban2rarbg: devDependencies: @@ -76,7 +82,7 @@ importers: version: 20.14.2 '@vitest/coverage-v8': specifier: ^1.6.0 - version: 1.6.0(vitest@1.6.0) + version: 1.6.0(vitest@1.6.0(@types/node@20.14.2)(jsdom@24.1.0)) jsdom: specifier: ^24.1.0 version: 24.1.0 @@ -91,7 +97,7 @@ importers: version: 5.3.1(@types/node@20.14.2) vite-plugin-monkey: specifier: ^4.0.3 - version: 4.0.3(vite@5.3.1) + version: 4.0.3(vite@5.3.1(@types/node@20.14.2)) vitest: specifier: ^1.6.0 version: 1.6.0(@types/node@20.14.2)(jsdom@24.1.0) @@ -112,7 +118,7 @@ importers: version: 5.3.1(@types/node@20.14.2) vite-plugin-monkey: specifier: ^4.0.3 - version: 4.0.3(vite@5.3.1) + version: 4.0.3(vite@5.3.1(@types/node@20.14.2)) packages/exclude-dv: devDependencies: @@ -130,7 +136,7 @@ importers: version: 5.3.1(@types/node@20.14.2) vite-plugin-monkey: specifier: ^4.0.3 - version: 4.0.3(vite@5.3.1) + version: 4.0.3(vite@5.3.1(@types/node@20.14.2)) packages/ghproxy-gist-raw: devDependencies: @@ -148,7 +154,7 @@ importers: version: 5.3.1(@types/node@20.14.2) vite-plugin-monkey: specifier: ^4.0.3 - version: 4.0.3(vite@5.3.1) + version: 4.0.3(vite@5.3.1(@types/node@20.14.2)) packages/ghproxy-raw: devDependencies: @@ -166,7 +172,7 @@ importers: version: 5.3.1(@types/node@20.14.2) vite-plugin-monkey: specifier: ^4.0.3 - version: 4.0.3(vite@5.3.1) + version: 4.0.3(vite@5.3.1(@types/node@20.14.2)) packages/ghproxy-releases: devDependencies: @@ -184,7 +190,7 @@ importers: version: 5.3.1(@types/node@20.14.2) vite-plugin-monkey: specifier: ^4.0.3 - version: 4.0.3(vite@5.3.1) + version: 4.0.3(vite@5.3.1(@types/node@20.14.2)) packages: @@ -2589,7 +2595,7 @@ snapshots: '@types/tough-cookie@4.0.2': {} - '@vitest/coverage-v8@1.6.0(vitest@1.6.0)': + '@vitest/coverage-v8@1.6.0(vitest@1.6.0(@types/node@20.14.2)(jsdom@24.1.0))': dependencies: '@ampproject/remapping': 2.2.1 '@bcoe/v8-coverage': 0.2.3 @@ -4180,7 +4186,7 @@ snapshots: - supports-color - terser - vite-plugin-monkey@4.0.3(vite@5.3.1): + vite-plugin-monkey@4.0.3(vite@5.3.1(@types/node@20.14.2)): dependencies: acorn-walk: 8.3.2 cross-spawn: 7.0.3 @@ -4191,20 +4197,20 @@ snapshots: open: 9.1.0 picocolors: 1.0.1 systemjs: 6.14.2 + optionalDependencies: vite: 5.3.1(@types/node@20.14.2) vite@5.3.1(@types/node@20.14.2): dependencies: - '@types/node': 20.14.2 esbuild: 0.21.5 postcss: 8.4.38 rollup: 4.13.0 optionalDependencies: + '@types/node': 20.14.2 fsevents: 2.3.3 vitest@1.6.0(@types/node@20.14.2)(jsdom@24.1.0): dependencies: - '@types/node': 20.14.2 '@vitest/expect': 1.6.0 '@vitest/runner': 1.6.0 '@vitest/snapshot': 1.6.0 @@ -4214,7 +4220,6 @@ snapshots: chai: 4.4.1 debug: 4.3.4 execa: 8.0.1 - jsdom: 24.1.0 local-pkg: 0.5.0 magic-string: 0.30.8 pathe: 1.1.1 @@ -4226,6 +4231,9 @@ snapshots: vite: 5.3.1(@types/node@20.14.2) vite-node: 1.6.0(@types/node@20.14.2) why-is-node-running: 2.2.2 + optionalDependencies: + '@types/node': 20.14.2 + jsdom: 24.1.0 transitivePeerDependencies: - less - lightningcss