From dcd8da504a6e39fcc8e8694eaa274b36326084f1 Mon Sep 17 00:00:00 2001 From: Andrew Powell Date: Wed, 25 Oct 2023 13:58:22 -0400 Subject: [PATCH] chore(repo): use `@dot/versioner` for releases (#1612) chore(repo): use versioner for releases --- package.json | 1 + packages/alias/package.json | 2 +- packages/auto-install/package.json | 2 +- packages/babel/package.json | 2 +- packages/beep/package.json | 2 +- packages/buble/package.json | 2 +- packages/commonjs/package.json | 2 +- packages/data-uri/package.json | 2 +- packages/dsv/package.json | 2 +- packages/dynamic-import-vars/package.json | 2 +- packages/eslint/package.json | 2 +- packages/esm-shim/package.json | 2 +- packages/graphql/package.json | 2 +- packages/html/package.json | 2 +- packages/image/package.json | 2 +- packages/inject/package.json | 2 +- packages/json/package.json | 2 +- packages/legacy/package.json | 2 +- packages/multi-entry/package.json | 2 +- packages/node-resolve/package.json | 2 +- packages/pluginutils/package.json | 2 +- packages/replace/package.json | 2 +- packages/run/package.json | 2 +- packages/strip/package.json | 2 +- packages/sucrase/package.json | 2 +- packages/swc/package.json | 2 +- packages/terser/package.json | 2 +- packages/typescript/package.json | 2 +- packages/url/package.json | 2 +- packages/virtual/package.json | 2 +- packages/wasm/package.json | 2 +- packages/yaml/package.json | 2 +- pnpm-lock.yaml | 53 ++++- scripts/publish.js | 210 ------------------- scripts/release.ts | 244 ---------------------- 35 files changed, 81 insertions(+), 489 deletions(-) delete mode 100644 scripts/publish.js delete mode 100644 scripts/release.ts diff --git a/package.json b/package.json index b6203e6d4..2311dd7a1 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ }, "devDependencies": { "@ava/babel": "2.0.0", + "@dot/versioner": "^0.2.0", "@rollup/plugin-typescript": "^9.0.1", "@types/conventional-commits-parser": "^3.0.2", "@types/node": "14.18.30", diff --git a/packages/alias/package.json b/packages/alias/package.json index f6aef76e8..30aec8b1e 100755 --- a/packages/alias/package.json +++ b/packages/alias/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc --noEmit" }, diff --git a/packages/auto-install/package.json b/packages/auto-install/package.json index 55a77ca03..8d2346268 100755 --- a/packages/auto-install/package.json +++ b/packages/auto-install/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc --noEmit" }, diff --git a/packages/babel/package.json b/packages/babel/package.json index 8e8629e42..f4668c20f 100644 --- a/packages/babel/package.json +++ b/packages/babel/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" }, diff --git a/packages/beep/package.json b/packages/beep/package.json index a839fd171..734cfa834 100644 --- a/packages/beep/package.json +++ b/packages/beep/package.json @@ -22,7 +22,7 @@ "ci:lint": "pnpm lint", "ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}", "ci:test": "ava --verbose", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava" }, "files": [ diff --git a/packages/buble/package.json b/packages/buble/package.json index d53ba64d2..54f5cfb29 100644 --- a/packages/buble/package.json +++ b/packages/buble/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" }, diff --git a/packages/commonjs/package.json b/packages/commonjs/package.json index af564922a..aaa8eef48 100644 --- a/packages/commonjs/package.json +++ b/packages/commonjs/package.json @@ -34,7 +34,7 @@ "prepublishOnly": "pnpm build", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" }, diff --git a/packages/data-uri/package.json b/packages/data-uri/package.json index fbeb8fa9a..d74646536 100644 --- a/packages/data-uri/package.json +++ b/packages/data-uri/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build --sourcemap", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc --noEmit" }, diff --git a/packages/dsv/package.json b/packages/dsv/package.json index cc4a174f2..86b826d19 100755 --- a/packages/dsv/package.json +++ b/packages/dsv/package.json @@ -30,7 +30,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava" }, "files": [ diff --git a/packages/dynamic-import-vars/package.json b/packages/dynamic-import-vars/package.json index b5b2e8f4e..3031dd1cf 100644 --- a/packages/dynamic-import-vars/package.json +++ b/packages/dynamic-import-vars/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build --sourcemap", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava" }, "files": [ diff --git a/packages/eslint/package.json b/packages/eslint/package.json index 6579779e1..7681a688c 100755 --- a/packages/eslint/package.json +++ b/packages/eslint/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" }, diff --git a/packages/esm-shim/package.json b/packages/esm-shim/package.json index e9a2eaad3..fbbd2288c 100644 --- a/packages/esm-shim/package.json +++ b/packages/esm-shim/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" }, diff --git a/packages/graphql/package.json b/packages/graphql/package.json index b6e5cf69f..6280a1b7a 100644 --- a/packages/graphql/package.json +++ b/packages/graphql/package.json @@ -34,7 +34,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" }, diff --git a/packages/html/package.json b/packages/html/package.json index 8d2be9417..4bfdf7371 100644 --- a/packages/html/package.json +++ b/packages/html/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc --noEmit" }, diff --git a/packages/image/package.json b/packages/image/package.json index d80fb57aa..17eac8963 100644 --- a/packages/image/package.json +++ b/packages/image/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava" }, "files": [ diff --git a/packages/inject/package.json b/packages/inject/package.json index 6bdcbffb8..7ecabd25f 100644 --- a/packages/inject/package.json +++ b/packages/inject/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" }, diff --git a/packages/json/package.json b/packages/json/package.json index 8ef14c842..47b04a896 100755 --- a/packages/json/package.json +++ b/packages/json/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" }, diff --git a/packages/legacy/package.json b/packages/legacy/package.json index 8b5dc7a15..04b027ecd 100644 --- a/packages/legacy/package.json +++ b/packages/legacy/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava" }, "files": [ diff --git a/packages/multi-entry/package.json b/packages/multi-entry/package.json index 71beb2f70..699a0eac1 100755 --- a/packages/multi-entry/package.json +++ b/packages/multi-entry/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava" }, "files": [ diff --git a/packages/node-resolve/package.json b/packages/node-resolve/package.json index 79728585b..78b7c922d 100644 --- a/packages/node-resolve/package.json +++ b/packages/node-resolve/package.json @@ -34,7 +34,7 @@ "prepublishOnly": "pnpm build", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "pnpm test:ts && ava", "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" }, diff --git a/packages/pluginutils/package.json b/packages/pluginutils/package.json index 3960efe50..e86973629 100644 --- a/packages/pluginutils/package.json +++ b/packages/pluginutils/package.json @@ -36,7 +36,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build --sourcemap", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc --noEmit" }, diff --git a/packages/replace/package.json b/packages/replace/package.json index 70c542e8b..5ed23c508 100644 --- a/packages/replace/package.json +++ b/packages/replace/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" }, diff --git a/packages/run/package.json b/packages/run/package.json index b73efa197..c6e1dffa2 100644 --- a/packages/run/package.json +++ b/packages/run/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava" }, "files": [ diff --git a/packages/strip/package.json b/packages/strip/package.json index 574280622..b3272cede 100644 --- a/packages/strip/package.json +++ b/packages/strip/package.json @@ -32,7 +32,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava" }, "files": [ diff --git a/packages/sucrase/package.json b/packages/sucrase/package.json index 3100fbcc6..986376ab6 100644 --- a/packages/sucrase/package.json +++ b/packages/sucrase/package.json @@ -34,7 +34,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" }, diff --git a/packages/swc/package.json b/packages/swc/package.json index 7c6beb041..5fe74971f 100644 --- a/packages/swc/package.json +++ b/packages/swc/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" }, diff --git a/packages/terser/package.json b/packages/terser/package.json index b37298508..24f9a35a6 100644 --- a/packages/terser/package.json +++ b/packages/terser/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" }, diff --git a/packages/typescript/package.json b/packages/typescript/package.json index 6b9c87da7..0f0c23abf 100644 --- a/packages/typescript/package.json +++ b/packages/typescript/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc --noEmit" }, diff --git a/packages/url/package.json b/packages/url/package.json index 38cdfdabe..6883535d5 100644 --- a/packages/url/package.json +++ b/packages/url/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava" }, "files": [ diff --git a/packages/virtual/package.json b/packages/virtual/package.json index 60c1cb929..a396595dc 100755 --- a/packages/virtual/package.json +++ b/packages/virtual/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc --noEmit" }, diff --git a/packages/wasm/package.json b/packages/wasm/package.json index eaf06cdab..c4723c27b 100644 --- a/packages/wasm/package.json +++ b/packages/wasm/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava", "test:ts": "tsc --noEmit" }, diff --git a/packages/yaml/package.json b/packages/yaml/package.json index f8b76bccc..cd7c102ab 100755 --- a/packages/yaml/package.json +++ b/packages/yaml/package.json @@ -33,7 +33,7 @@ "prepare": "if [ ! -d 'dist' ]; then pnpm build; fi", "prerelease": "pnpm build", "pretest": "pnpm build", - "release": "pnpm --workspace-root plugin:release --pkg $npm_package_name", + "release": "pnpm --workspace-root package:release $(pwd)", "test": "ava" }, "files": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 25637f26c..0b62552ff 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + importers: .: @@ -7,6 +11,9 @@ importers: '@ava/babel': specifier: 2.0.0 version: 2.0.0 + '@dot/versioner': + specifier: ^0.2.0 + version: 0.2.0 '@rollup/plugin-typescript': specifier: ^9.0.1 version: 9.0.1(rollup@4.0.0-24)(typescript@4.8.4) @@ -2100,6 +2107,30 @@ packages: '@jridgewell/trace-mapping': 0.3.9 dev: true + /@dot/log@0.1.3: + resolution: {integrity: sha512-Gh6enQBMuD5zxI5Rz7lNY74PnlR6K0DvavOrrSuU4uhKsUf9BgJlHyFR5or5Uu3hK8xJyfmdf0cS7rDoFD3N/A==} + engines: {node: '>=18'} + dependencies: + chalk: 4.1.2 + loglevelnext: 5.0.6 + p-defer: 3.0.0 + dev: true + + /@dot/versioner@0.2.0: + resolution: {integrity: sha512-mT9c189tmfRUa8wcnD3zYQKMP9KfbtwqOTh5Y94tODDdSoAIfpS31Hs5ySxiQ7I+/PBdjLh+AUZ7rCOI9Rr/1Q==} + engines: {node: '>=18'} + hasBin: true + dependencies: + '@dot/log': 0.1.3 + chalk: 4.1.2 + conventional-commits-parser: 3.2.4 + execa: 5.1.1 + semver: 7.5.4 + source-map-support: 0.5.21 + write-pkg: 4.0.0 + yargs-parser: 21.1.1 + dev: true + /@eslint/eslintrc@1.3.3: resolution: {integrity: sha512-uj3pT6Mg+3t39fvLrj8iuCIJ38zKO9FpGtJ4BBJebJhEwjoT+KLVNCcHT5QC9NGRIEi7fZ0ZR8YRb884auB4Lg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -5650,6 +5681,11 @@ packages: wrap-ansi: 6.2.0 dev: true + /loglevelnext@5.0.6: + resolution: {integrity: sha512-GKtlPs++zQjG1DK88bpEDxP/6PlmKi5okl3T4MNq+S6bQYYWKbHKJ/kap2wwQi/24t4WfGwRnYab/8AGT4LGsg==} + engines: {node: '>= 12.22.1'} + dev: true + /lowercase-keys@2.0.0: resolution: {integrity: sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==} engines: {node: '>=8'} @@ -6077,6 +6113,11 @@ packages: engines: {node: '>=4'} dev: true + /p-defer@3.0.0: + resolution: {integrity: sha512-ugZxsxmtTln604yeYd29EGrNhazN2lywetzpKhfmQjW/VJmhpDmWbiX+h0zL8V91R0UXkhb3KtPmyq9PZw3aYw==} + engines: {node: '>=8'} + dev: true + /p-event@5.0.1: resolution: {integrity: sha512-dd589iCQ7m1L0bmC5NLlVYfy3TbBEsMUfWx9PyAgPeIcFZ/E2yaTZ4Rz4MiBmmJShviiftHVXOqfnfzJ6kyMrQ==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -7122,6 +7163,14 @@ packages: lru-cache: 6.0.0 dev: true + /semver@7.5.4: + resolution: {integrity: sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==} + engines: {node: '>=10'} + hasBin: true + dependencies: + lru-cache: 6.0.0 + dev: true + /serialize-error@7.0.1: resolution: {integrity: sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw==} engines: {node: '>=10'} @@ -7997,7 +8046,3 @@ packages: resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} engines: {node: '>=12.20'} dev: true - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false diff --git a/scripts/publish.js b/scripts/publish.js deleted file mode 100644 index bbac9b4db..000000000 --- a/scripts/publish.js +++ /dev/null @@ -1,210 +0,0 @@ -#!/usr/bin/env node - -/* eslint-disable import/no-extraneous-dependencies, import/no-dynamic-require, no-await-in-loop, global-require */ - -const { join } = require('path'); -const { readFileSync, writeFileSync } = require('fs'); - -const parser = require('conventional-commits-parser'); -const chalk = require('chalk'); -const execa = require('execa'); -const semver = require('semver'); -const writePackage = require('write-pkg'); - -const packagesPath = join(__dirname, '..', 'packages'); -const { log } = console; -const parserOptions = { - noteKeywords: ['BREAKING CHANGE', 'Breaking Change'] -}; -const reBreaking = new RegExp(`(${parserOptions.noteKeywords.join(')|(')})`); -const dryRun = process.argv.includes('--dry'); -const noPush = process.argv.includes('--no-push'); -const noTag = process.argv.includes('--no-tag'); - -const commitChanges = async (cwd, pluginName, version) => { - if (dryRun) { - log(chalk`{yellow Skipping Git Commit}`); - return; - } - - log(chalk`{blue Committing} CHANGELOG.md, package.json`); - let params = ['add', cwd]; - await execa('git', params); - - params = ['commit', '--m', `chore(release): ${pluginName} v${version}`]; - await execa('git', params); -}; - -const getCommits = async (pluginName) => { - log(chalk`{blue Gathering Commits}`); - - let params = ['tag', '--list', `${pluginName}-v*`, '--sort', '-v:refname']; - const { stdout: tags } = await execa('git', params); - const [latestTag] = tags.split('\n'); - - log(chalk`{blue Last Release Tag}: ${latestTag}`); - - // i wanted to use '--grep', `"(${pluginName})"` here, but there's something up with execa - // https://github.com/sindresorhus/execa/issues/406 - FIXED - // TODO: const params = ['log', '--grep', '"(pluginutils)"', 'pluginutils-v3.0.1..HEAD']; - params = ['--no-pager', 'log', `${latestTag}..HEAD`, '--format=%B%n-hash-%n%H🐒💨🙊']; - const rePlugin = new RegExp(`^[\\w\\!]+\\(${pluginName}\\)`, 'i'); - const { stdout } = await execa('git', params); - const commits = stdout - .split('🐒💨🙊') - .filter((commit) => { - const chunk = commit.trim(); - return chunk && rePlugin.test(chunk); - }) - .map((commit) => { - const node = parser.sync(commit); - - node.breaking = reBreaking.test(node.body || node.footer) || /!:/.test(node.header); - - return node; - }); - - return commits; -}; - -const getNewVersion = (version, commits) => { - log(chalk`{blue Determining New Version}`); - const intersection = process.argv.filter((arg) => - ['--major', '--minor', '--patch'].includes(arg) - ); - if (intersection.length) { - return semver.inc(version, intersection[0].substring(2)); - } - - const types = new Set(commits.map(({ type }) => type)); - const breaking = commits.some((commit) => !!commit.breaking); - const level = breaking ? 'major' : types.has('feat') || types.has('feature') ? 'minor' : 'patch'; - - return semver.inc(version, level); -}; - -const publish = async (cwd) => { - if (dryRun) { - log(chalk`{yellow Skipping Publish}`); - return; - } - - log(chalk`\n{cyan Publishing to NPM}`); - - await execa('pnpm', ['publish'], { cwd, stdio: 'inherit' }); -}; - -const push = async () => { - if (dryRun || noPush) { - log(chalk`{yellow Skipping Git Push}`); - return; - } - - log(chalk`{blue Pushing Release and Tags}`); - await execa('git', ['push']); - await execa('git', ['push', '--tags']); -}; - -const tag = async (cwd, pluginName, version) => { - if (dryRun || noTag) { - log(chalk`{yellow Skipping Git Tag}`); - return; - } - - const tagName = `${pluginName}-v${version}`; - log(chalk`\n{blue Tagging} {grey ${tagName}}`); - await execa('git', ['tag', tagName], { cwd, stdio: 'inherit' }); -}; - -const updateChangelog = (commits, cwd, pluginName, version) => { - log(chalk`{blue Gathering Changes}`); - - const plugin = pluginName === 'pluginutils' ? pluginName : `plugin-${pluginName}`; - const title = `# @rollup/${plugin} ChangeLog`; - const [date] = new Date().toISOString().split('T'); - const logPath = join(cwd, 'CHANGELOG.md'); - const logFile = readFileSync(logPath, 'utf-8'); - const oldNotes = logFile.startsWith(title) ? logFile.slice(title.length).trim() : logFile; - const notes = { breaking: [], fixes: [], features: [], updates: [] }; - - for (const { breaking, hash, header, type } of commits) { - const ref = /\(#\d+\)/.test(header) ? '' : ` (${hash.substring(0, 7)})`; - const message = header.trim().replace(`(${pluginName})`, '') + ref; - if (breaking) { - notes.breaking.push(message); - } else if (type === 'fix') { - notes.fixes.push(message); - } else if (type === 'feat' || type === 'feature') { - notes.features.push(message); - } else { - notes.updates.push(message); - } - } - - const parts = [ - `## v${version}`, - `_${date}_`, - notes.breaking.length ? `### Breaking Changes\n\n- ${notes.breaking.join('\n- ')}`.trim() : '', - notes.fixes.length ? `### Bugfixes\n\n- ${notes.fixes.join('\n- ')}`.trim() : '', - notes.features.length ? `### Features\n\n- ${notes.features.join('\n- ')}`.trim() : '', - notes.updates.length ? `### Updates\n\n- ${notes.updates.join('\n- ')}`.trim() : '' - ].filter(Boolean); - - const newLog = parts.join('\n\n'); - - if (dryRun) { - log(chalk`{blue New ChangeLog}:\n${newLog}`); - return; - } - - log(chalk`{blue Updating} CHANGELOG.md`); - const content = [title, newLog, oldNotes].filter(Boolean).join('\n\n'); - writeFileSync(logPath, content, 'utf-8'); -}; - -const updatePackage = async (cwd, pkg, version) => { - if (dryRun) { - log(chalk`{yellow Skipping package.json Update}`); - return; - } - - log(chalk`{blue Updating} package.json`); - pkg.version = version; // eslint-disable-line no-param-reassign - await writePackage(cwd, pkg); -}; - -(async () => { - try { - const [, , pluginName] = process.argv; - const cwd = join(packagesPath, pluginName); - const pkg = require(join(cwd, 'package.json')); - - if (dryRun) { - log(chalk`{magenta DRY RUN}: No files will be modified`); - } - - log(chalk`{cyan Publishing \`${pluginName}\`} from {grey packages/${pluginName}}\n`); - - const commits = await getCommits(pluginName); - - if (!commits.length) { - log(chalk`\n{red No Commits Found}. Did you mean to publish ${pluginName}?`); - return; - } - - log(chalk`{blue Found} {bold ${commits.length}} Commits\n`); - - const newVersion = getNewVersion(pkg.version, commits); - - log(chalk`{blue New Version}: ${newVersion}\n`); - - await updatePackage(cwd, pkg, newVersion); - await updateChangelog(commits, cwd, pluginName, newVersion); - await commitChanges(cwd, pluginName, newVersion); - await publish(cwd); - await tag(cwd, pluginName, newVersion); - await push(); - } catch (e) { - log(e); - } -})(); diff --git a/scripts/release.ts b/scripts/release.ts deleted file mode 100644 index 51384b760..000000000 --- a/scripts/release.ts +++ /dev/null @@ -1,244 +0,0 @@ -import 'source-map-support/register'; - -import { join } from 'path'; -import { existsSync, readFileSync, writeFileSync } from 'fs'; - -import parser from 'conventional-commits-parser'; -import chalk from 'chalk'; -import execa from 'execa'; -import semver from 'semver'; -import writePackage from 'write-pkg'; -import yargs from 'yargs-parser'; - -const { log } = console; -const parserOptions = { - noteKeywords: ['BREAKING CHANGE', 'Breaking Change'] -}; -const reBreaking = new RegExp(`(${parserOptions.noteKeywords.join(')|(')})`); -const dryRun = process.argv.includes('--dry'); -const noPublish = process.argv.includes('--no-publish'); -const noTag = process.argv.includes('--no-tag'); - -type Commit = parser.Commit; - -interface BreakingCommit { - breaking: boolean; -} - -interface Notes { - breaking: string[]; - features: string[]; - fixes: string[]; - updates: string[]; -} - -interface RepoPackage { - [key: string]: any; - name: string; - version: string; -} - -const commitChanges = async (cwd: string, shortName: string, version: string) => { - if (dryRun) { - log(chalk`{yellow Skipping Git Commit}`); - return; - } - - log(chalk`{blue Committing} CHANGELOG.md, package.json`); - let params = ['add', cwd]; - await execa('git', params); - - params = ['commit', '--m', `chore(release): ${shortName} v${version}`]; - await execa('git', params); -}; - -const getCommits = async (shortName: string) => { - log(chalk`{blue Gathering Commits}`); - - let params = ['tag', '--list', `${shortName}-v*`, '--sort', '-v:refname']; - const { stdout: tags } = await execa('git', params); - const [latestTag] = tags.split('\n'); - - log(chalk`{blue Last Release Tag}: ${latestTag || ''}`); - - params = ['--no-pager', 'log', `${latestTag}..HEAD`, '--format=%B%n-hash-%n%H🐒💨🙊']; - const rePlugin = new RegExp(`^[\\w\\!]+\\(([\\w,-]+)?${shortName}([\\w,-]+)?\\)`, 'i'); - let { stdout } = await execa('git', params); - - if (!stdout) { - if (latestTag) params.splice(2, 1, `${latestTag}`); - else params.splice(2, 1, 'HEAD'); - ({ stdout } = await execa('git', params)); - } - - const commits = stdout - .split('🐒💨🙊') - .filter((commit: string) => { - const chunk = commit.trim(); - return chunk && rePlugin.test(chunk); - }) - .map((commit) => { - const node = parser.sync(commit); - const body = (node.body || node.footer) as string; - - if (!node.type) node.type = parser.sync(node.header?.replace(/\(.+\)!?:/, ':') || '').type; - - (node as unknown as BreakingCommit).breaking = - reBreaking.test(body) || /!:/.test(node.header as string); - - return node; - }); - - return commits; -}; - -const getNewVersion = (version: string, commits: Commit[]): string | null => { - log(chalk`{blue Determining New Version}`); - const intersection = process.argv.filter((arg) => - ['--major', '--minor', '--patch'].includes(arg) - ); - if (intersection.length) { - // we found an edge case in the typescript-eslint plguin - // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion - return semver.inc(version, intersection[0].substring(2) as semver.ReleaseType); - } - - const types = new Set(commits.map(({ type }) => type)); - const breaking = commits.some((commit) => !!commit.breaking); - const level = breaking ? 'major' : types.has('feat') || types.has('feature') ? 'minor' : 'patch'; - - return semver.inc(version, level); -}; - -const publish = async (cwd: string) => { - if (dryRun || noPublish) { - log(chalk`{yellow Skipping Publish}`); - return; - } - - log(chalk`\n{cyan Publishing to NPM}`); - - await execa('npm', ['publish', '--no-git-checks'], { cwd, stdio: 'inherit' }); -}; - -const tag = async (cwd: string, shortName: string, version: string) => { - if (dryRun || noTag) { - log(chalk`{yellow Skipping Git Tag}`); - return; - } - - const tagName = `${shortName}-v${version}`; - log(chalk`\n{blue Tagging} {grey ${tagName}}`); - await execa('git', ['tag', tagName], { cwd, stdio: 'inherit' }); -}; - -const updateChangelog = (commits: Commit[], cwd: string, shortName: string, version: string) => { - log(chalk`{blue Gathering Changes}`); - - const plugin = shortName === 'pluginutils' ? shortName : `plugin-${shortName}`; - const title = `# @rollup/${plugin} ChangeLog`; - const [date] = new Date().toISOString().split('T'); - const logPath = join(cwd, 'CHANGELOG.md'); - const logFile = existsSync(logPath) ? readFileSync(logPath, 'utf-8') : ''; - const oldNotes = logFile.startsWith(title) ? logFile.slice(title.length).trim() : logFile; - const notes: Notes = { breaking: [], features: [], fixes: [], updates: [] }; - - for (const commit of commits) { - const { breaking, hash, header, type } = commit; - const ref = /\(#\d+\)/.test(header as string) - ? '' - : ` ([${hash?.substring(0, 7)}](https://github.com/rollup/plugins/commit/${hash}))`; - const message = - header - ?.trim() - .replace(/\(.+\)!?:/, ':') - .replace(/\((#(\d+))\)/, '[$1](https://github.com/rollup/plugins/pull/$2)') + ref; - - if (breaking) { - notes.breaking.push(message); - } else if (type === 'fix') { - notes.fixes.push(message); - } else if (type === 'feat' || type === 'feature') { - notes.features.push(message); - } else { - notes.updates.push(message); - } - } - - const parts = [ - `## v${version}`, - `_${date}_`, - notes.breaking.length ? `### Breaking Changes\n\n- ${notes.breaking.join('\n- ')}`.trim() : '', - notes.fixes.length ? `### Bugfixes\n\n- ${notes.fixes.join('\n- ')}`.trim() : '', - notes.features.length ? `### Features\n\n- ${notes.features.join('\n- ')}`.trim() : '', - notes.updates.length ? `### Updates\n\n- ${notes.updates.join('\n- ')}`.trim() : '' - ].filter(Boolean); - - const newLog = parts.join('\n\n'); - - if (dryRun) { - log(chalk`{blue New ChangeLog}:\n${newLog}`); - return; - } - - log(chalk`{blue Updating} CHANGELOG.md`); - let content = [title, newLog, oldNotes].filter(Boolean).join('\n\n'); - if (!content.endsWith('\n')) content += '\n'; - writeFileSync(logPath, content, 'utf-8'); -}; - -const updatePackage = async (cwd: string, pkg: RepoPackage, version: string) => { - if (dryRun) { - log(chalk`{yellow Skipping package.json Update}`); - return; - } - - log(chalk`{blue Updating} package.json`); - // eslint-disable-next-line no-param-reassign - pkg.version = version; - await writePackage(cwd, pkg); -}; - -(async () => { - try { - const argv = yargs(process.argv.slice(2)); - const packagePath = argv.packagePath || 'packages'; - const packageName = argv.pkg; - const shortName = packageName.replace(/^@.+\//, '').replace('plugin-', ''); - const cwd = join(process.cwd(), `/${packagePath}/`, shortName); - - if (!cwd || !existsSync(cwd)) { - throw new RangeError(`Could not find directory for package: ${packageName}`); - } - - const { default: pkg }: RepoPackage = await import(join(cwd, 'package.json')); - - if (dryRun) { - log(chalk`{magenta DRY RUN}: No files will be modified`); - } - - log(chalk`{cyan Releasing \`${packageName}\`} from {grey packages/${shortName}}\n`); - - const commits = await getCommits(shortName); - - if (!commits.length) { - log(chalk`\n{red No Commits Found}. Did you mean to publish ${packageName}?`); - process.exit(1); - } - - log(chalk`{blue Found} {bold ${commits.length}} Commits\n`); - - const newVersion = getNewVersion(pkg.version, commits) as string; - - log(chalk`{blue New Version}: ${newVersion}\n`); - - await updatePackage(cwd, pkg, newVersion); - updateChangelog(commits, cwd, shortName, newVersion); - await commitChanges(cwd, shortName, newVersion); - await publish(cwd); - await tag(cwd, shortName, newVersion); - } catch (e) { - log(e); - process.exit(1); - } -})();