From c4cebe873487f03e6a8bc5b5b151d6b292297316 Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Mon, 9 Oct 2023 18:35:11 +0200 Subject: [PATCH] Try parseArgs fallback for Bun --- .github/workflows/integration.yml | 1 - bun-compat.diff | 42 ------------------------------- package-lock.json | 9 ++++++- package.json | 2 ++ scripts/create-new-plugin.ts | 2 +- src/util/cli-arguments.ts | 2 +- src/util/parseArgs.ts | 8 ++++++ 7 files changed, 20 insertions(+), 46 deletions(-) delete mode 100644 bun-compat.diff create mode 100644 src/util/parseArgs.ts diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 1875ddcab..f74c25932 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -11,7 +11,6 @@ jobs: steps: - uses: actions/checkout@v3 - uses: oven-sh/setup-bun@v1 - - run: git apply bun-compat.diff - run: bun install - run: bun run build - run: bun link diff --git a/bun-compat.diff b/bun-compat.diff deleted file mode 100644 index 18628fa6d..000000000 --- a/bun-compat.diff +++ /dev/null @@ -1,42 +0,0 @@ -diff --git a/package.json b/package.json -index e39a2b6..c6b3ed2 100644 ---- a/package.json -+++ b/package.json -@@ -44,6 +44,7 @@ - "dependencies": { - "@ericcornelissen/bash-parser": "^0.5.2", - "@npmcli/map-workspaces": "^3.0.4", -+ "@pkgjs/parseargs": "github:pkgjs/parseargs", - "@pnpm/logger": "5.0.0", - "@pnpm/workspace.pkgs-graph": "2.0.6", - "@snyk/github-codeowners": "^1.1.0", -@@ -74,6 +75,7 @@ - "@types/minimist": "1.2.3", - "@types/node": "20.8.3", - "@types/npmcli__map-workspaces": "3.0.2", -+ "@types/pkgjs__parseargs": "0.10.1", - "@types/webpack": "5.28.3", - "@typescript-eslint/eslint-plugin": "6.7.4", - "@typescript-eslint/parser": "6.7.4", -diff --git a/scripts/create-new-plugin.ts b/scripts/create-new-plugin.ts -index d6c8cb6..cfc5a04 100644 ---- a/scripts/create-new-plugin.ts -+++ b/scripts/create-new-plugin.ts -@@ -1,6 +1,6 @@ - import fs from 'node:fs/promises'; - import path from 'node:path'; --import { parseArgs } from 'node:util'; -+import { parseArgs } from '@pkgjs/parseargs'; - - const { - values: { name }, -diff --git a/src/util/cli-arguments.ts b/src/util/cli-arguments.ts -index 48be9e8..77c1b01 100644 ---- a/src/util/cli-arguments.ts -+++ b/src/util/cli-arguments.ts -@@ -1,4 +1,4 @@ --import { parseArgs } from 'node:util'; -+import { parseArgs } from '@pkgjs/parseargs'; - - export const helpText = `✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects - diff --git a/package-lock.json b/package-lock.json index 95ff72ffb..8a98a4919 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@ericcornelissen/bash-parser": "^0.5.2", "@npmcli/map-workspaces": "^3.0.4", + "@pkgjs/parseargs": "0.11.0", "@pnpm/logger": "5.0.0", "@pnpm/workspace.pkgs-graph": "2.0.7", "@snyk/github-codeowners": "^1.1.0", @@ -44,6 +45,7 @@ "@types/minimist": "1.2.3", "@types/node": "20.8.3", "@types/npmcli__map-workspaces": "3.0.2", + "@types/pkgjs__parseargs": "0.10.1", "@types/webpack": "5.28.3", "@typescript-eslint/eslint-plugin": "6.7.4", "@typescript-eslint/parser": "6.7.4", @@ -1292,7 +1294,6 @@ "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", - "optional": true, "engines": { "node": ">=14" } @@ -2201,6 +2202,12 @@ "@types/ssri": "*" } }, + "node_modules/@types/pkgjs__parseargs": { + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/@types/pkgjs__parseargs/-/pkgjs__parseargs-0.10.1.tgz", + "integrity": "sha512-FPz4DPKmK9X7F9u4nQFt10D5vfT8zlKYcLckihZjO1Gx7GK8tTXdCu2Dvh/Ooo5r0FJg4y9kUmWC7+JqbLABaw==", + "dev": true + }, "node_modules/@types/responselike": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz", diff --git a/package.json b/package.json index d080dd1f5..d50a9fc13 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "dependencies": { "@ericcornelissen/bash-parser": "^0.5.2", "@npmcli/map-workspaces": "^3.0.4", + "@pkgjs/parseargs": "0.11.0", "@pnpm/logger": "5.0.0", "@pnpm/workspace.pkgs-graph": "2.0.7", "@snyk/github-codeowners": "^1.1.0", @@ -74,6 +75,7 @@ "@types/minimist": "1.2.3", "@types/node": "20.8.3", "@types/npmcli__map-workspaces": "3.0.2", + "@types/pkgjs__parseargs": "0.10.1", "@types/webpack": "5.28.3", "@typescript-eslint/eslint-plugin": "6.7.4", "@typescript-eslint/parser": "6.7.4", diff --git a/scripts/create-new-plugin.ts b/scripts/create-new-plugin.ts index d6c8cb61b..66f04e083 100644 --- a/scripts/create-new-plugin.ts +++ b/scripts/create-new-plugin.ts @@ -1,6 +1,6 @@ import fs from 'node:fs/promises'; import path from 'node:path'; -import { parseArgs } from 'node:util'; +import { parseArgs } from '../src/util/parseArgs.js'; const { values: { name }, diff --git a/src/util/cli-arguments.ts b/src/util/cli-arguments.ts index 48be9e836..300f10a83 100644 --- a/src/util/cli-arguments.ts +++ b/src/util/cli-arguments.ts @@ -1,4 +1,4 @@ -import { parseArgs } from 'node:util'; +import { parseArgs } from './parseArgs.js'; export const helpText = `✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects diff --git a/src/util/parseArgs.ts b/src/util/parseArgs.ts new file mode 100644 index 000000000..5c18d7c43 --- /dev/null +++ b/src/util/parseArgs.ts @@ -0,0 +1,8 @@ +let parseArgs: typeof import('node:util').parseArgs; +try { + parseArgs = (await import('node:util')).parseArgs; +} catch (error) { + // @ts-expect-error Almost compatible, let's use the built-in types + parseArgs = (await import('@pkgjs/parseargs')).parseArgs; +} +export { parseArgs };