knip 6.45.1 → 6.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -18
- package/dist/ConfigurationChief.d.ts +6 -0
- package/dist/ConfigurationChief.js +2 -2
- package/dist/DependencyDeputy.d.ts +12 -14
- package/dist/DependencyDeputy.js +33 -21
- package/dist/IssueCollector.d.ts +1 -0
- package/dist/IssueCollector.js +4 -1
- package/dist/PackagePeeker.d.ts +0 -9
- package/dist/PackagePeeker.js +0 -38
- package/dist/ProjectPrincipal.d.ts +1 -1
- package/dist/ProjectPrincipal.js +3 -1
- package/dist/WorkspaceWorker.js +7 -7
- package/dist/binaries/bash-parser.js +5 -8
- package/dist/binaries/command.js +2 -2
- package/dist/binaries/fallback.d.ts +5 -1
- package/dist/binaries/fallback.js +41 -10
- package/dist/binaries/plugins.d.ts +1 -0
- package/dist/binaries/plugins.js +75 -39
- package/dist/binaries/resolvers/bun.js +2 -2
- package/dist/binaries/resolvers/npm.js +2 -2
- package/dist/binaries/resolvers/npx.js +2 -2
- package/dist/binaries/resolvers/nub.js +2 -2
- package/dist/binaries/resolvers/pnpm.js +29 -21
- package/dist/binaries/resolvers/pnpx.js +20 -8
- package/dist/binaries/resolvers/vp.js +1 -1
- package/dist/binaries/resolvers/yarn.js +1 -1
- package/dist/binaries/util.d.ts +4 -1
- package/dist/binaries/util.js +10 -13
- package/dist/constants.js +18 -0
- package/dist/graph/SubpathReferences.d.ts +1 -1
- package/dist/graph/SubpathReferences.js +4 -3
- package/dist/graph/build.js +11 -12
- package/dist/plugins/_template/index.js +2 -2
- package/dist/plugins/angular/index.js +3 -8
- package/dist/plugins/astro/resolveFromAST.js +2 -2
- package/dist/plugins/astro-markdoc/index.js +2 -2
- package/dist/plugins/astro-og-canvas/index.js +1 -1
- package/dist/plugins/aws-cdk/index.js +3 -3
- package/dist/plugins/babel/index.js +5 -3
- package/dist/plugins/borp/index.js +2 -2
- package/dist/plugins/bun/index.js +3 -3
- package/dist/plugins/capacitor/index.js +33 -6
- package/dist/plugins/capacitor/types.d.ts +10 -0
- package/dist/plugins/changesets/index.js +2 -2
- package/dist/plugins/commitizen/index.js +2 -2
- package/dist/plugins/commitlint/index.js +2 -2
- package/dist/plugins/convex/index.js +2 -2
- package/dist/plugins/cspell/index.js +2 -2
- package/dist/plugins/cucumber/index.js +2 -2
- package/dist/plugins/cypress/index.js +3 -3
- package/dist/plugins/docusaurus/helpers.js +6 -6
- package/dist/plugins/docusaurus/index.js +3 -3
- package/dist/plugins/dotenv/index.js +6 -2
- package/dist/plugins/drizzle/index.js +2 -2
- package/dist/plugins/electron-builder/index.d.ts +3 -0
- package/dist/plugins/electron-builder/index.js +61 -0
- package/dist/plugins/electron-forge/index.js +2 -2
- package/dist/plugins/electron-vite/index.js +4 -3
- package/dist/plugins/electron-vite/types.d.ts +3 -0
- package/dist/plugins/eleventy/index.js +2 -2
- package/dist/plugins/ember/compiler.d.ts +2 -0
- package/dist/plugins/ember/compiler.js +14 -0
- package/dist/plugins/ember/index.d.ts +6 -0
- package/dist/plugins/ember/index.js +160 -0
- package/dist/plugins/ember/types.d.ts +13 -0
- package/dist/plugins/ember/types.js +1 -0
- package/dist/plugins/ember/visitors/importSync.d.ts +2 -0
- package/dist/plugins/ember/visitors/importSync.js +32 -0
- package/dist/plugins/ember-template-lint/index.d.ts +3 -0
- package/dist/plugins/ember-template-lint/index.js +20 -0
- package/dist/plugins/env-cmd/index.d.ts +3 -0
- package/dist/plugins/env-cmd/index.js +16 -0
- package/dist/plugins/esbuild/index.js +2 -2
- package/dist/plugins/eslint/helpers.js +6 -6
- package/dist/plugins/eslint/index.js +0 -1
- package/dist/plugins/eslint/resolveFromAST.js +11 -3
- package/dist/plugins/evalite/index.js +2 -2
- package/dist/plugins/expo/helpers.js +10 -10
- package/dist/plugins/expo-router/index.js +3 -3
- package/dist/plugins/filesystem-routing/index.js +4 -4
- package/dist/plugins/flue/index.js +4 -4
- package/dist/plugins/gatsby/index.js +3 -3
- package/dist/plugins/github-action/index.js +2 -2
- package/dist/plugins/github-actions/index.js +2 -2
- package/dist/plugins/graphql-codegen/index.js +8 -6
- package/dist/plugins/index.d.ts +6 -0
- package/dist/plugins/index.js +12 -0
- package/dist/plugins/jasmine/index.js +3 -4
- package/dist/plugins/jest/index.js +3 -3
- package/dist/plugins/karma/helpers.js +2 -2
- package/dist/plugins/karma/index.js +5 -1
- package/dist/plugins/knex/index.js +13 -7
- package/dist/plugins/laravel-vite-plugin/resolveFromAST.js +2 -2
- package/dist/plugins/linthtml/index.js +2 -2
- package/dist/plugins/lunaria/index.js +3 -3
- package/dist/plugins/maestro/index.d.ts +3 -0
- package/dist/plugins/maestro/index.js +54 -0
- package/dist/plugins/maestro/types.d.ts +21 -0
- package/dist/plugins/maestro/types.js +1 -0
- package/dist/plugins/markdownlint/index.js +3 -3
- package/dist/plugins/marko/index.js +4 -4
- package/dist/plugins/mastra/index.js +3 -3
- package/dist/plugins/mdx/index.js +3 -3
- package/dist/plugins/mdxlint/index.js +2 -2
- package/dist/plugins/metro/index.js +5 -5
- package/dist/plugins/mikro-orm/index.js +3 -4
- package/dist/plugins/mise/scripts.js +2 -3
- package/dist/plugins/mocha/index.js +8 -7
- package/dist/plugins/netlify/index.js +4 -4
- package/dist/plugins/next/index.js +5 -5
- package/dist/plugins/next-mdx/resolveFromAST.js +2 -2
- package/dist/plugins/nitro/index.js +4 -4
- package/dist/plugins/node/index.d.ts +16 -0
- package/dist/plugins/node/index.js +89 -23
- package/dist/plugins/nodemon/index.js +1 -1
- package/dist/plugins/npm-package-json-lint/index.js +2 -2
- package/dist/plugins/nuxt/index.js +16 -14
- package/dist/plugins/nx/index.js +3 -3
- package/dist/plugins/nyc/index.js +39 -2
- package/dist/plugins/oclif/index.js +5 -3
- package/dist/plugins/openclaw/index.js +5 -5
- package/dist/plugins/oxlint/index.js +2 -2
- package/dist/plugins/panda-css/index.js +2 -2
- package/dist/plugins/parcel/index.js +2 -2
- package/dist/plugins/payload/index.js +3 -3
- package/dist/plugins/playwright/index.js +4 -4
- package/dist/plugins/pm2/index.js +2 -2
- package/dist/plugins/pnpm/index.js +1 -1
- package/dist/plugins/postcss/index.js +2 -2
- package/dist/plugins/preconstruct/index.js +2 -2
- package/dist/plugins/prettier/index.js +4 -3
- package/dist/plugins/prisma/index.js +5 -5
- package/dist/plugins/quasar/resolveFromAST.js +8 -8
- package/dist/plugins/qwik/resolveFromAST.js +3 -3
- package/dist/plugins/raycast/index.js +2 -2
- package/dist/plugins/react-cosmos/index.js +2 -2
- package/dist/plugins/react-native/index.js +1 -1
- package/dist/plugins/react-router/index.js +6 -6
- package/dist/plugins/relay/index.js +3 -3
- package/dist/plugins/release-it/index.js +2 -5
- package/dist/plugins/remark/helpers.js +2 -2
- package/dist/plugins/retry-cli/index.js +0 -1
- package/dist/plugins/rolldown/index.js +2 -2
- package/dist/plugins/rollup/index.js +2 -2
- package/dist/plugins/rsbuild/index.js +3 -3
- package/dist/plugins/rslib/index.js +2 -2
- package/dist/plugins/rslint/index.d.ts +3 -0
- package/dist/plugins/rslint/index.js +16 -0
- package/dist/plugins/rspack/index.js +4 -0
- package/dist/plugins/rstest/index.js +4 -4
- package/dist/plugins/semantic-release/index.js +2 -2
- package/dist/plugins/serverless-framework/index.js +4 -4
- package/dist/plugins/solidjs-vite-plugin/resolveFromAST.js +3 -3
- package/dist/plugins/sst/resolveFromAST.js +2 -2
- package/dist/plugins/starlight/resolveFromAST.js +3 -3
- package/dist/plugins/stencil/resolveFromAST.js +5 -5
- package/dist/plugins/storybook/index.js +2 -2
- package/dist/plugins/stryker/index.js +2 -2
- package/dist/plugins/stylelint/index.js +4 -4
- package/dist/plugins/sveltekit/resolveFromAST.js +7 -5
- package/dist/plugins/swc/index.js +8 -5
- package/dist/plugins/tailwind/index.js +3 -2
- package/dist/plugins/tanstack-router/index.js +5 -2
- package/dist/plugins/textlint/helpers.js +2 -2
- package/dist/plugins/ts-node/index.js +23 -6
- package/dist/plugins/tsd/index.js +1 -1
- package/dist/plugins/tsdown/index.js +4 -4
- package/dist/plugins/tsup/index.js +3 -3
- package/dist/plugins/tsx/index.js +4 -3
- package/dist/plugins/turbo/index.js +2 -2
- package/dist/plugins/typedoc/index.js +4 -3
- package/dist/plugins/typescript/index.js +4 -4
- package/dist/plugins/varlock/scan.js +6 -3
- package/dist/plugins/vite/helpers.js +2 -2
- package/dist/plugins/vite-plugin-pages/index.js +2 -2
- package/dist/plugins/vite-plugin-pwa/resolveFromAST.js +2 -2
- package/dist/plugins/vite-plugin-vue-layouts-next/index.js +2 -2
- package/dist/plugins/vitest/index.js +14 -18
- package/dist/plugins/webdriver-io/index.js +13 -1
- package/dist/plugins/webpack/index.js +7 -12
- package/dist/plugins/wrangler/index.js +3 -3
- package/dist/plugins/wxt/index.js +2 -2
- package/dist/plugins/yarn/index.js +5 -5
- package/dist/session/incremental.d.ts +1 -1
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +6 -0
- package/dist/types/args.d.ts +4 -3
- package/dist/types/config.d.ts +2 -0
- package/dist/types/module-graph.d.ts +1 -1
- package/dist/types/package-json.d.ts +1 -0
- package/dist/types/workspace.d.ts +10 -8
- package/dist/typescript/ast-nodes.js +4 -5
- package/dist/typescript/get-imports-and-exports.js +5 -2
- package/dist/typescript/visitors/exports.js +6 -32
- package/dist/typescript/visitors/imports.d.ts +1 -1
- package/dist/typescript/visitors/imports.js +15 -24
- package/dist/typescript/visitors/walk.d.ts +5 -0
- package/dist/typescript/visitors/walk.js +75 -30
- package/dist/util/codeowners.js +4 -1
- package/dist/util/input.d.ts +3 -6
- package/dist/util/input.js +6 -20
- package/dist/util/parse-and-convert-gitignores.js +5 -4
- package/dist/util/parse-args.d.ts +2 -1
- package/dist/util/parse-args.js +13 -3
- package/dist/util/plugin.js +6 -4
- package/dist/util/watch.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/schema.json +36 -5
package/README.md
CHANGED
|
@@ -26,25 +26,47 @@ performance, less maintenance and easier refactorings.
|
|
|
26
26
|
- Follow [@webpro.nl on Bluesky][13] for updates
|
|
27
27
|
- [Sponsor Knip!][14]
|
|
28
28
|
|
|
29
|
+
## Getting started
|
|
30
|
+
|
|
31
|
+
Install Knip and run it to lint your project:
|
|
32
|
+
|
|
33
|
+
```shell
|
|
34
|
+
npm init @knip/config
|
|
35
|
+
npm run knip
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
See [Getting Started][15] for more package managers and installation options.
|
|
39
|
+
|
|
40
|
+
## Coding agents
|
|
41
|
+
|
|
42
|
+
Let your coding agent configure Knip using the [Knip MCP Server][16]:
|
|
43
|
+
|
|
44
|
+
```text
|
|
45
|
+
Install the Knip MCP Server (@knip/mcp) and use it to configure Knip in this
|
|
46
|
+
project.
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
You may need to restart your agent session after installing the server.
|
|
50
|
+
|
|
29
51
|
## Contributors
|
|
30
52
|
|
|
31
|
-
Special thanks to [the wonderful people who have contributed to Knip][
|
|
53
|
+
Special thanks to [the wonderful people who have contributed to Knip][17]!
|
|
32
54
|
|
|
33
55
|
## Knip
|
|
34
56
|
|
|
35
|
-
/'knɪp/ means "(to) cut" and is [pronounced with a hard "K"][
|
|
57
|
+
/'knɪp/ means "(to) cut" and is [pronounced with a hard "K"][18] 🇳🇱
|
|
36
58
|
|
|
37
59
|
## License
|
|
38
60
|
|
|
39
|
-
Knip is free and open-source software licensed under the [ISC License][
|
|
61
|
+
Knip is free and open-source software licensed under the [ISC License][19].
|
|
40
62
|
|
|
41
63
|
Parts of Knip have been inspired by and/or partially copy code from the
|
|
42
64
|
following projects:
|
|
43
65
|
|
|
44
|
-
- [@npmcli/package-json][
|
|
45
|
-
- [@pnpm/deps.graph-sequencer][
|
|
46
|
-
- [file-entry-cache][
|
|
47
|
-
- [json-parse-even-better-errors][
|
|
66
|
+
- [@npmcli/package-json][20] ([ISC][21])
|
|
67
|
+
- [@pnpm/deps.graph-sequencer][22] ([MIT][23])
|
|
68
|
+
- [file-entry-cache][24] ([MIT][25])
|
|
69
|
+
- [json-parse-even-better-errors][26] ([MIT][27])
|
|
48
70
|
|
|
49
71
|
[1]: https://www.npmx.dev/package/knip
|
|
50
72
|
[2]: https://img.shields.io/npm/v/knip?color=f56e0f
|
|
@@ -60,14 +82,16 @@ following projects:
|
|
|
60
82
|
[12]: https://github.com/webpro-nl/knip/blob/main/.github/CONTRIBUTING.md
|
|
61
83
|
[13]: https://bsky.app/profile/webpro.nl
|
|
62
84
|
[14]: https://knip.dev/sponsors
|
|
63
|
-
[15]: https://knip.dev
|
|
64
|
-
[16]: https://
|
|
65
|
-
[17]:
|
|
66
|
-
[18]: https://
|
|
67
|
-
[19]:
|
|
68
|
-
[20]: https://github.com/
|
|
69
|
-
[21]: https://github.com/
|
|
70
|
-
[22]: https://github.com/
|
|
71
|
-
[23]: https://github.com/
|
|
72
|
-
[24]: https://github.com/
|
|
73
|
-
[25]: https://github.com/
|
|
85
|
+
[15]: https://knip.dev/overview/getting-started
|
|
86
|
+
[16]: https://knip.dev/reference/integrations#mcp-server
|
|
87
|
+
[17]: https://knip.dev/#created-by-awesome-contributors
|
|
88
|
+
[18]: https://www.youtube.com/watch?v=PE7h7KvQoUI&t=9s
|
|
89
|
+
[19]: ./LICENSE
|
|
90
|
+
[20]: https://github.com/npm/package-json
|
|
91
|
+
[21]: https://github.com/npm/package-json/blob/main/LICENSE
|
|
92
|
+
[22]: https://github.com/pnpm/pnpm/tree/main/deps/graph-sequencer
|
|
93
|
+
[23]: https://github.com/pnpm/pnpm/blob/main/LICENSE
|
|
94
|
+
[24]: https://github.com/jaredwray/cacheable/tree/main/packages/file-entry-cache
|
|
95
|
+
[25]: https://github.com/jaredwray/cacheable/blob/main/packages/file-entry-cache/LICENSE
|
|
96
|
+
[26]: https://github.com/npm/json-parse-even-better-errors
|
|
97
|
+
[27]: https://github.com/npm/json-parse-even-better-errors/blob/main/LICENSE.md
|
|
@@ -114,9 +114,13 @@ export declare class ConfigurationChief {
|
|
|
114
114
|
docusaurus?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
115
115
|
dotenv?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
116
116
|
drizzle?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
117
|
+
"electron-builder"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
117
118
|
"electron-forge"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
118
119
|
"electron-vite"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
119
120
|
eleventy?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
121
|
+
ember?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
122
|
+
"ember-template-lint"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
123
|
+
"env-cmd"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
120
124
|
esbuild?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
121
125
|
eslint?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
122
126
|
evalite?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
@@ -152,6 +156,7 @@ export declare class ConfigurationChief {
|
|
|
152
156
|
"lockfile-lint"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
153
157
|
"lost-pixel"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
154
158
|
lunaria?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
159
|
+
maestro?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
155
160
|
markdownlint?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
156
161
|
marko?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
157
162
|
mastra?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
@@ -220,6 +225,7 @@ export declare class ConfigurationChief {
|
|
|
220
225
|
rollup?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
221
226
|
rsbuild?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
222
227
|
rslib?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
228
|
+
rslint?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
223
229
|
rspack?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
224
230
|
rstest?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
225
231
|
sanity?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
@@ -307,11 +307,11 @@ export class ConfigurationChief {
|
|
|
307
307
|
}
|
|
308
308
|
getNegatedWorkspacePatterns(name) {
|
|
309
309
|
const descendentWorkspaces = this.getDescendentWorkspaces(name);
|
|
310
|
-
const
|
|
310
|
+
const prefix = `${name}/`;
|
|
311
311
|
const ignoredWorkspaces = this.getIgnoredWorkspacesFor(name);
|
|
312
312
|
const endMatch = /\/\*{1,2}$|\/$|$/;
|
|
313
313
|
return [...ignoredWorkspaces, ...descendentWorkspaces]
|
|
314
|
-
.map(workspaceName => workspaceName.
|
|
314
|
+
.map(workspaceName => (workspaceName.startsWith(prefix) ? workspaceName.slice(prefix.length) : workspaceName))
|
|
315
315
|
.map(workspaceName => `!${workspaceName.replace(endMatch, '/**')}`);
|
|
316
316
|
}
|
|
317
317
|
countWorkspacesForConfigKey(configKey) {
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { IgnoreItem, Workspace } from './ConfigurationChief.ts';
|
|
2
2
|
import type { ConfigurationHint, Counters, Issue, Issues, IssueType } from './types/issues.ts';
|
|
3
3
|
import type { PackageJson } from './types/package-json.ts';
|
|
4
|
-
import type { DependencyArray, DependencySet, HostDependencies, InstalledBinaries, WorkspaceManifests } from './types/workspace.ts';
|
|
4
|
+
import type { DependencyArray, DependencySet, HostDependencies, InstalledBinaries, WorkspaceIgnores, WorkspaceManifests } from './types/workspace.ts';
|
|
5
5
|
import type { MainOptions } from './util/create-options.ts';
|
|
6
|
+
interface IgnoreItems {
|
|
7
|
+
ignoreDependencies: IgnoreItem[];
|
|
8
|
+
ignoreBinaries: IgnoreItem[];
|
|
9
|
+
ignoreUnresolved: IgnoreItem[];
|
|
10
|
+
}
|
|
6
11
|
interface DependencyReferenceOptions {
|
|
7
12
|
specifier: string;
|
|
8
13
|
isDevOnly?: boolean;
|
|
@@ -22,18 +27,17 @@ export declare class DependencyDeputy {
|
|
|
22
27
|
hostDependencies: Map<string, HostDependencies>;
|
|
23
28
|
installedBinaries: Map<string, InstalledBinaries>;
|
|
24
29
|
hasTypesIncluded: Map<string, Set<string>>;
|
|
30
|
+
rootIgnores: WorkspaceIgnores | undefined;
|
|
25
31
|
constructor({ isProduction, isStrict, isReportDependencies }: MainOptions);
|
|
26
|
-
|
|
32
|
+
private toWorkspaceIgnores;
|
|
33
|
+
addWorkspace({ name, dir, manifestPath, manifestStr, manifest, ...ignores }: IgnoreItems & {
|
|
27
34
|
name: string;
|
|
28
35
|
dir: string;
|
|
29
36
|
manifestPath: string;
|
|
30
37
|
manifestStr: string;
|
|
31
38
|
manifest: PackageJson;
|
|
32
|
-
ignoreDependencies: IgnoreItem[];
|
|
33
|
-
ignoreBinaries: IgnoreItem[];
|
|
34
|
-
ignoreUnresolved: IgnoreItem[];
|
|
35
39
|
}): void;
|
|
36
|
-
getWorkspaceManifest(workspaceName: string): {
|
|
40
|
+
getWorkspaceManifest(workspaceName: string): (WorkspaceIgnores & {
|
|
37
41
|
workspaceDir: string;
|
|
38
42
|
manifestPath: string;
|
|
39
43
|
manifestStr: string;
|
|
@@ -46,14 +50,8 @@ export declare class DependencyDeputy {
|
|
|
46
50
|
allDependencies: DependencySet;
|
|
47
51
|
engines: Record<string, string>;
|
|
48
52
|
isPrivate: boolean;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
ignoreUnresolved: (string | RegExp)[];
|
|
52
|
-
unusedIgnoreDependencies: Set<string | RegExp>;
|
|
53
|
-
unusedIgnoreBinaries: Set<string | RegExp>;
|
|
54
|
-
unusedIgnoreUnresolved: Set<string | RegExp>;
|
|
55
|
-
ignoreConfigKeys: Record<'ignoreDependencies' | 'ignoreBinaries' | 'ignoreUnresolved', Map<string | RegExp, string | undefined>>;
|
|
56
|
-
} | undefined;
|
|
53
|
+
}) | undefined;
|
|
54
|
+
setRootIgnores(ignores: IgnoreItems): void;
|
|
57
55
|
setWorkspacePkgNames(pkgNames: Iterable<string>): void;
|
|
58
56
|
getProductionDependencies(workspaceName: string): DependencyArray;
|
|
59
57
|
getDevDependencies(workspaceName: string): DependencyArray;
|
package/dist/DependencyDeputy.js
CHANGED
|
@@ -26,6 +26,7 @@ export class DependencyDeputy {
|
|
|
26
26
|
hostDependencies;
|
|
27
27
|
installedBinaries;
|
|
28
28
|
hasTypesIncluded;
|
|
29
|
+
rootIgnores;
|
|
29
30
|
constructor({ isProduction, isStrict, isReportDependencies }) {
|
|
30
31
|
this.isProduction = isProduction;
|
|
31
32
|
this.isStrict = isStrict;
|
|
@@ -35,7 +36,24 @@ export class DependencyDeputy {
|
|
|
35
36
|
this.installedBinaries = new Map();
|
|
36
37
|
this.hasTypesIncluded = new Map();
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
toWorkspaceIgnores({ ignoreDependencies, ignoreBinaries, ignoreUnresolved }) {
|
|
40
|
+
const toId = (id) => filterIsProduction(id, this.isProduction);
|
|
41
|
+
const ignoreConfigKeys = {
|
|
42
|
+
ignoreDependencies: toIgnoreMap(ignoreDependencies, toId),
|
|
43
|
+
ignoreBinaries: toIgnoreMap(ignoreBinaries, toId),
|
|
44
|
+
ignoreUnresolved: toIgnoreMap(ignoreUnresolved),
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
ignoreDependencies: [...ignoreConfigKeys.ignoreDependencies.keys()],
|
|
48
|
+
ignoreBinaries: [...ignoreConfigKeys.ignoreBinaries.keys()],
|
|
49
|
+
ignoreUnresolved: [...ignoreConfigKeys.ignoreUnresolved.keys()],
|
|
50
|
+
unusedIgnoreDependencies: new Set(ignoreConfigKeys.ignoreDependencies.keys()),
|
|
51
|
+
unusedIgnoreBinaries: new Set(ignoreConfigKeys.ignoreBinaries.keys()),
|
|
52
|
+
unusedIgnoreUnresolved: new Set(ignoreConfigKeys.ignoreUnresolved.keys()),
|
|
53
|
+
ignoreConfigKeys,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
addWorkspace({ name, dir, manifestPath, manifestStr, manifest, ...ignores }) {
|
|
39
57
|
const dependencies = Object.keys(manifest.dependencies ?? {});
|
|
40
58
|
const peerDependencies = Object.keys(manifest.peerDependencies ?? {});
|
|
41
59
|
const optionalDependencies = Object.keys(manifest.optionalDependencies ?? {});
|
|
@@ -69,23 +87,11 @@ export class DependencyDeputy {
|
|
|
69
87
|
uninstalledOptionalDependencies.add(dependency);
|
|
70
88
|
}
|
|
71
89
|
}
|
|
72
|
-
const toId = (id) => filterIsProduction(id, this.isProduction);
|
|
73
|
-
const ignoreConfigKeys = {
|
|
74
|
-
ignoreDependencies: toIgnoreMap(id, toId),
|
|
75
|
-
ignoreBinaries: toIgnoreMap(ib, toId),
|
|
76
|
-
ignoreUnresolved: toIgnoreMap(iu),
|
|
77
|
-
};
|
|
78
90
|
this._manifests.set(name, {
|
|
91
|
+
...this.toWorkspaceIgnores(ignores),
|
|
79
92
|
workspaceDir: dir,
|
|
80
93
|
manifestPath,
|
|
81
94
|
manifestStr,
|
|
82
|
-
ignoreDependencies: [...ignoreConfigKeys.ignoreDependencies.keys()],
|
|
83
|
-
ignoreBinaries: [...ignoreConfigKeys.ignoreBinaries.keys()],
|
|
84
|
-
ignoreUnresolved: [...ignoreConfigKeys.ignoreUnresolved.keys()],
|
|
85
|
-
unusedIgnoreDependencies: new Set(ignoreConfigKeys.ignoreDependencies.keys()),
|
|
86
|
-
unusedIgnoreBinaries: new Set(ignoreConfigKeys.ignoreBinaries.keys()),
|
|
87
|
-
unusedIgnoreUnresolved: new Set(ignoreConfigKeys.ignoreUnresolved.keys()),
|
|
88
|
-
ignoreConfigKeys,
|
|
89
95
|
dependencies,
|
|
90
96
|
devDependencies,
|
|
91
97
|
peerDependencies: new Set(peerDependencies),
|
|
@@ -100,6 +106,9 @@ export class DependencyDeputy {
|
|
|
100
106
|
getWorkspaceManifest(workspaceName) {
|
|
101
107
|
return this._manifests.get(workspaceName);
|
|
102
108
|
}
|
|
109
|
+
setRootIgnores(ignores) {
|
|
110
|
+
this.rootIgnores = this.toWorkspaceIgnores(ignores);
|
|
111
|
+
}
|
|
103
112
|
setWorkspacePkgNames(pkgNames) {
|
|
104
113
|
this.workspacePkgNames = new Set(pkgNames);
|
|
105
114
|
}
|
|
@@ -268,14 +277,14 @@ export class DependencyDeputy {
|
|
|
268
277
|
};
|
|
269
278
|
const isNotReferencedDependency = (dependency) => !isReferencedDependency(dependency);
|
|
270
279
|
for (const symbol of this.getProductionDependencies(workspace).filter(isNotReferencedDependency)) {
|
|
271
|
-
const position = peeker.
|
|
280
|
+
const position = peeker.getPropertyLocation('dependencies', symbol) ?? peeker.getPropertyLocation('peerDependencies', symbol);
|
|
272
281
|
dependencyIssues.push({ type: 'dependencies', workspace, filePath, symbol, fixes: [], ...position });
|
|
273
282
|
}
|
|
274
283
|
const manifest = this._manifests.get(workspace);
|
|
275
284
|
for (const symbol of this.getDevDependencies(workspace)) {
|
|
276
285
|
if (!manifest.dependencies.includes(symbol) && !isNotReferencedDependency(symbol))
|
|
277
286
|
continue;
|
|
278
|
-
const position = peeker.
|
|
287
|
+
const position = peeker.getPropertyLocation('devDependencies', symbol);
|
|
279
288
|
devDependencyIssues.push({ type: 'devDependencies', filePath, workspace, symbol, fixes: [], ...position });
|
|
280
289
|
}
|
|
281
290
|
for (const symbol of this.getOptionalPeerDependencies(workspace)) {
|
|
@@ -283,7 +292,7 @@ export class DependencyDeputy {
|
|
|
283
292
|
continue;
|
|
284
293
|
if (manifest.dependencies.includes(symbol) || manifest.devDependencies.includes(symbol))
|
|
285
294
|
continue;
|
|
286
|
-
const pos = peeker.
|
|
295
|
+
const pos = peeker.getPropertyLocation('peerDependencies', symbol);
|
|
287
296
|
optionalPeerDependencyIssues.push({
|
|
288
297
|
type: 'optionalPeerDependencies',
|
|
289
298
|
filePath,
|
|
@@ -323,7 +332,7 @@ export class DependencyDeputy {
|
|
|
323
332
|
manifest.unusedIgnoreDependencies.delete(ignoreItem);
|
|
324
333
|
}
|
|
325
334
|
else if (issue.workspace !== ROOT_WORKSPACE_NAME) {
|
|
326
|
-
const manifest = this.
|
|
335
|
+
const manifest = this._manifests.get(ROOT_WORKSPACE_NAME) ?? this.rootIgnores;
|
|
327
336
|
if (manifest) {
|
|
328
337
|
const ignoreItem = findMatch(manifest.ignoreDependencies, packageName);
|
|
329
338
|
if (ignoreItem) {
|
|
@@ -352,7 +361,7 @@ export class DependencyDeputy {
|
|
|
352
361
|
manifest.unusedIgnoreBinaries.delete(ignoreItem);
|
|
353
362
|
}
|
|
354
363
|
else {
|
|
355
|
-
const manifest = this.
|
|
364
|
+
const manifest = this._manifests.get(ROOT_WORKSPACE_NAME) ?? this.rootIgnores;
|
|
356
365
|
if (manifest) {
|
|
357
366
|
const ignoreItem = findMatch(manifest.ignoreBinaries, issue.symbol);
|
|
358
367
|
if (ignoreItem) {
|
|
@@ -380,7 +389,7 @@ export class DependencyDeputy {
|
|
|
380
389
|
manifest.unusedIgnoreUnresolved.delete(ignoreItem);
|
|
381
390
|
}
|
|
382
391
|
else {
|
|
383
|
-
const manifest = this.
|
|
392
|
+
const manifest = this._manifests.get(ROOT_WORKSPACE_NAME) ?? this.rootIgnores;
|
|
384
393
|
if (manifest) {
|
|
385
394
|
const ignoreItem = findMatch(manifest.ignoreUnresolved, issue.symbol);
|
|
386
395
|
if (ignoreItem) {
|
|
@@ -405,7 +414,10 @@ export class DependencyDeputy {
|
|
|
405
414
|
}
|
|
406
415
|
getConfigurationHints() {
|
|
407
416
|
const configurationHints = [];
|
|
408
|
-
|
|
417
|
+
const workspaceIgnores = this.rootIgnores
|
|
418
|
+
? [...this._manifests, [ROOT_WORKSPACE_NAME, this.rootIgnores]]
|
|
419
|
+
: this._manifests;
|
|
420
|
+
for (const [workspaceName, manifest] of workspaceIgnores) {
|
|
409
421
|
const toHint = (type, identifier) => {
|
|
410
422
|
const configKey = manifest.ignoreConfigKeys[type].get(identifier);
|
|
411
423
|
return configKey ? { workspaceName, identifier, type, configKey } : { workspaceName, identifier, type };
|
package/dist/IssueCollector.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export declare class IssueCollector {
|
|
|
43
43
|
processed: number;
|
|
44
44
|
unused: number;
|
|
45
45
|
}): void;
|
|
46
|
+
addReferencedFile(filePath: string): void;
|
|
46
47
|
addFilesIssues(filePaths: string[]): void;
|
|
47
48
|
addIssue(issue: Issue): true | undefined;
|
|
48
49
|
addConfigurationHint(issue: ConfigurationHint): void;
|
package/dist/IssueCollector.js
CHANGED
|
@@ -110,6 +110,9 @@ export class IssueCollector {
|
|
|
110
110
|
this.counters.processed += processed;
|
|
111
111
|
this.counters.total += processed + unused;
|
|
112
112
|
}
|
|
113
|
+
addReferencedFile(filePath) {
|
|
114
|
+
this.referencedFiles.add(filePath);
|
|
115
|
+
}
|
|
113
116
|
addFilesIssues(filePaths) {
|
|
114
117
|
for (const filePath of filePaths) {
|
|
115
118
|
if (!this.workspaceFilter(filePath))
|
|
@@ -148,7 +151,7 @@ export class IssueCollector {
|
|
|
148
151
|
return;
|
|
149
152
|
issue.severity = this.rules[issue.type];
|
|
150
153
|
const issues = this.issues[issue.type];
|
|
151
|
-
issues[key] = issues[key] ??
|
|
154
|
+
issues[key] = issues[key] ?? Object.create(null);
|
|
152
155
|
const symbol = issue.parentSymbol ? `${issue.parentSymbol}.${issue.symbol}` : issue.symbol;
|
|
153
156
|
if (!issues[key][symbol]) {
|
|
154
157
|
issues[key][symbol] = issue;
|
package/dist/PackagePeeker.d.ts
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
export declare class PackagePeeker {
|
|
2
|
-
private lines;
|
|
3
|
-
private sections;
|
|
4
|
-
private ready;
|
|
5
2
|
private manifestStr;
|
|
6
3
|
constructor(manifestStr: string);
|
|
7
|
-
private init;
|
|
8
|
-
getLocation(type: 'dependencies' | 'devDependencies' | 'optionalPeerDependencies', packageName: string): {
|
|
9
|
-
line: number;
|
|
10
|
-
col: number;
|
|
11
|
-
pos: number;
|
|
12
|
-
} | undefined;
|
|
13
4
|
getCatalogReferenceLocation(packageName: string, catalogName: string): {
|
|
14
5
|
line: number;
|
|
15
6
|
col: number;
|
package/dist/PackagePeeker.js
CHANGED
|
@@ -1,46 +1,8 @@
|
|
|
1
1
|
export class PackagePeeker {
|
|
2
|
-
lines = [];
|
|
3
|
-
sections = {};
|
|
4
|
-
ready = false;
|
|
5
2
|
manifestStr;
|
|
6
3
|
constructor(manifestStr) {
|
|
7
4
|
this.manifestStr = manifestStr;
|
|
8
5
|
}
|
|
9
|
-
init() {
|
|
10
|
-
this.lines = this.manifestStr.split('\n');
|
|
11
|
-
let pos = 0;
|
|
12
|
-
for (let i = 0; i < this.lines.length; i++) {
|
|
13
|
-
const line = this.lines[i];
|
|
14
|
-
const section = line.includes('"dependencies"')
|
|
15
|
-
? 'dependencies'
|
|
16
|
-
: line.includes('"devDependencies"')
|
|
17
|
-
? 'devDependencies'
|
|
18
|
-
: line.includes('"optionalPeerDependencies"')
|
|
19
|
-
? 'optionalPeerDependencies'
|
|
20
|
-
: undefined;
|
|
21
|
-
if (section)
|
|
22
|
-
this.sections[section] = { startLine: i, startPos: pos };
|
|
23
|
-
pos += line.length + 1;
|
|
24
|
-
}
|
|
25
|
-
this.ready = true;
|
|
26
|
-
}
|
|
27
|
-
getLocation(type, packageName) {
|
|
28
|
-
if (!this.ready)
|
|
29
|
-
this.init();
|
|
30
|
-
const lines = this.lines;
|
|
31
|
-
const section = this.sections[type];
|
|
32
|
-
if (lines.length === 0 || !section)
|
|
33
|
-
return;
|
|
34
|
-
let pos = section.startPos + lines[section.startLine].length + 1;
|
|
35
|
-
for (let i = section.startLine + 1; i < lines.length; i++) {
|
|
36
|
-
const line = lines[i];
|
|
37
|
-
if (line.includes(`"${packageName}"`)) {
|
|
38
|
-
const col = line.indexOf(packageName);
|
|
39
|
-
return { line: i + 1, col: col + 1, pos: pos + col };
|
|
40
|
-
}
|
|
41
|
-
pos += line.length + 1;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
6
|
getCatalogReferenceLocation(packageName, catalogName) {
|
|
45
7
|
const property = `"${packageName}"`;
|
|
46
8
|
const value = `"catalog:${catalogName === 'default' ? '' : catalogName}"`;
|
|
@@ -56,7 +56,7 @@ export declare class ProjectPrincipal {
|
|
|
56
56
|
releaseEntryClaims(): void;
|
|
57
57
|
removeProjectPath(filePath: string): void;
|
|
58
58
|
walkAndAnalyze(analyzeFile: (filePath: string, parseResult: ParseResult | undefined, sourceText: string, cachedFile?: FileNode) => Iterable<string> | undefined, onSpecifier: (specifier: string, filePath: string) => void): Promise<void>;
|
|
59
|
-
getUsedResolvedFiles(onSpecifier: (specifier: string, filePath: string) => void): Promise<Set<string>>;
|
|
59
|
+
getUsedResolvedFiles(onSpecifier: (specifier: string, filePath: string, importedFilePath: string | undefined) => void): Promise<Set<string>>;
|
|
60
60
|
private resolveSpecifier;
|
|
61
61
|
getUnreferencedFiles(): string[];
|
|
62
62
|
private getCachedFile;
|
package/dist/ProjectPrincipal.js
CHANGED
|
@@ -9,6 +9,7 @@ import { createCustomModuleResolver, createGlobAliasResolver } from './typescrip
|
|
|
9
9
|
import { SourceFileManager } from './typescript/SourceFileManager.js';
|
|
10
10
|
import { compact } from './util/array.js';
|
|
11
11
|
import { debugLog } from './util/debug.js';
|
|
12
|
+
import { getSubpathImport } from './util/modules.js';
|
|
12
13
|
import { timerify } from './util/Performance.js';
|
|
13
14
|
import { extname, isInNodeModules, toAbsolute } from './util/path.js';
|
|
14
15
|
const copyFileNode = (file) => ({
|
|
@@ -274,9 +275,10 @@ export class ProjectPrincipal {
|
|
|
274
275
|
const result = tryParseFile(filePath, sourceText);
|
|
275
276
|
if (!result)
|
|
276
277
|
continue;
|
|
278
|
+
const isProjectPath = this.projectPaths.has(filePath);
|
|
277
279
|
for (const specifier of extractSpecifiers(result, sourceText, filePath)) {
|
|
278
|
-
onSpecifier(specifier, filePath);
|
|
279
280
|
const resolved = this.resolveSpecifier(specifier, filePath);
|
|
281
|
+
onSpecifier(specifier, filePath, isProjectPath && getSubpathImport(specifier) ? resolved : undefined);
|
|
280
282
|
if (resolved && !isInNodeModules(resolved))
|
|
281
283
|
visited.add(resolved);
|
|
282
284
|
}
|
package/dist/WorkspaceWorker.js
CHANGED
|
@@ -14,7 +14,7 @@ import { compact } from './util/array.js';
|
|
|
14
14
|
import { debugLog, debugLogArray, debugLogObject } from './util/debug.js';
|
|
15
15
|
import { _glob, hasNoProductionSuffix, hasProductionSuffix, negate } from './util/glob.js';
|
|
16
16
|
import { expandIgnorePatterns } from './util/parse-and-convert-gitignores.js';
|
|
17
|
-
import { isConfig, isEntry, toDebugString, toEntry
|
|
17
|
+
import { isConfig, isEntry, toDebugString, toEntry } from './util/input.js';
|
|
18
18
|
import { filterTransitiveDependencies } from './util/filter-transitive-dependencies.js';
|
|
19
19
|
import { timerify } from './util/Performance.js';
|
|
20
20
|
import { basename, dirname, extname, join, relative, toRelative } from './util/path.js';
|
|
@@ -324,9 +324,9 @@ export class WorkspaceWorker {
|
|
|
324
324
|
getInputsFromScripts: createGetInputsFromScripts(containingFilePath),
|
|
325
325
|
};
|
|
326
326
|
if (config.entry) {
|
|
327
|
-
const
|
|
327
|
+
const entryOptions = isProduction && plugin.production?.length ? { production: true } : undefined;
|
|
328
328
|
for (const id of config.entry)
|
|
329
|
-
inputs.push(
|
|
329
|
+
inputs.push(toEntry(id, entryOptions));
|
|
330
330
|
}
|
|
331
331
|
else if ((!plugin.resolveConfig && !plugin.resolveFromAST) ||
|
|
332
332
|
(!configFilePaths.some(path => basename(path) !== 'package.json') &&
|
|
@@ -337,7 +337,7 @@ export class WorkspaceWorker {
|
|
|
337
337
|
inputs.push(toEntry(id));
|
|
338
338
|
if (plugin.production)
|
|
339
339
|
for (const id of plugin.production)
|
|
340
|
-
inputs.push(
|
|
340
|
+
inputs.push(toEntry(id, { production: true }));
|
|
341
341
|
}
|
|
342
342
|
if (typeof plugin.setup === 'function')
|
|
343
343
|
await plugin.setup();
|
|
@@ -361,7 +361,7 @@ export class WorkspaceWorker {
|
|
|
361
361
|
continue;
|
|
362
362
|
}
|
|
363
363
|
let parsed;
|
|
364
|
-
if (!isManifest) {
|
|
364
|
+
if (!isManifest && (!plugin.parseConfig || plugin.resolveFromAST)) {
|
|
365
365
|
if (parsedConfigCache.has(configFilePath)) {
|
|
366
366
|
parsed = parsedConfigCache.get(configFilePath);
|
|
367
367
|
}
|
|
@@ -381,7 +381,7 @@ export class WorkspaceWorker {
|
|
|
381
381
|
const cache = {};
|
|
382
382
|
let hasLoadConfigError = false;
|
|
383
383
|
if (plugin.resolveConfig) {
|
|
384
|
-
if (parsed && isExternalReExportsOnly(parsed)) {
|
|
384
|
+
if (!plugin.parseConfig && parsed && isExternalReExportsOnly(parsed)) {
|
|
385
385
|
cache.resolveConfig = [];
|
|
386
386
|
}
|
|
387
387
|
if (!cache.resolveConfig) {
|
|
@@ -518,7 +518,7 @@ export class WorkspaceWorker {
|
|
|
518
518
|
if (pattern.startsWith('!'))
|
|
519
519
|
continue;
|
|
520
520
|
const id = pattern.replace(/!$/, '');
|
|
521
|
-
if (includedPaths.has(join(dir, id))) {
|
|
521
|
+
if ((hasNoProductionSuffix(pattern) && patterns.includes(`${pattern}!`)) || includedPaths.has(join(dir, id))) {
|
|
522
522
|
hints.push(hint(`${type}-redundant`, pattern));
|
|
523
523
|
}
|
|
524
524
|
else if (!hasMatch(picomatch(id))) {
|
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
import { forEachChild, parse } from 'unbash';
|
|
2
2
|
import { debugLogObject } from '../util/debug.js';
|
|
3
|
-
import { extractBinary
|
|
3
|
+
import { extractBinary } from '../util/modules.js';
|
|
4
4
|
import { relative } from '../util/path.js';
|
|
5
|
-
import {
|
|
5
|
+
import { truncate } from '../util/string.js';
|
|
6
6
|
import { isScriptExpansion } from '../util/scripts.js';
|
|
7
7
|
import { getDependenciesFromCommand } from './command.js';
|
|
8
|
-
import {
|
|
8
|
+
import { toForwardedScript } from './plugins.js';
|
|
9
9
|
export const getDependenciesFromScript = (script, options) => {
|
|
10
10
|
if (!script)
|
|
11
11
|
return [];
|
|
12
12
|
const fromArgs = (args, opts) => {
|
|
13
13
|
if (args.length === 0)
|
|
14
14
|
return [];
|
|
15
|
-
|
|
16
|
-
if (!isValidBinary(substringBefore(first, ' ')))
|
|
17
|
-
return [];
|
|
18
|
-
return getDependenciesFromScript(toScript(args), {
|
|
15
|
+
return getDependenciesFromScript(toForwardedScript(args), {
|
|
19
16
|
...options,
|
|
20
17
|
isForwardedArgs: false,
|
|
21
18
|
...opts,
|
|
22
19
|
});
|
|
23
20
|
};
|
|
24
|
-
const fromWords = (args, opts) => getDependenciesFromScript(
|
|
21
|
+
const fromWords = (args, opts) => getDependenciesFromScript(toForwardedScript(args), opts);
|
|
25
22
|
const definedFunctions = new Set();
|
|
26
23
|
const collectFunctionNames = (statements) => {
|
|
27
24
|
for (const stmt of statements)
|
package/dist/binaries/command.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Plugins, pluginArgsMap } from '../plugins.js';
|
|
2
|
-
import {
|
|
2
|
+
import { toModule } from '../util/input.js';
|
|
3
3
|
import { extractBinary, isInNodeModulesBin, isRelativeNodeModulesBin } from '../util/modules.js';
|
|
4
4
|
import { getCommandWords } from '../util/scripts.js';
|
|
5
5
|
import { resolve as fallbackResolve, spawningBinaries } from './fallback.js';
|
|
@@ -14,7 +14,7 @@ export const getInputsFromNodeOptions = (prefix) => {
|
|
|
14
14
|
const args = parseNodeArgs(item.value.value.split(' '));
|
|
15
15
|
if (args.require)
|
|
16
16
|
for (const id of [args.require].flat())
|
|
17
|
-
inputs.push(
|
|
17
|
+
inputs.push(toModule(id));
|
|
18
18
|
}
|
|
19
19
|
return inputs;
|
|
20
20
|
};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Word } from 'unbash';
|
|
2
|
+
import type { BinaryResolver, ScriptArg } from '../types/config.ts';
|
|
3
|
+
export declare const shellSpawningBinaries: string[];
|
|
2
4
|
export declare const spawningBinaries: string[];
|
|
5
|
+
export declare const getEnvAssignmentCount: (values: string[]) => number;
|
|
3
6
|
export declare const isWrapper: (binary: string) => boolean;
|
|
7
|
+
export declare const getWrappedScripts: (binary: string, words: Word[]) => ScriptArg[][];
|
|
4
8
|
export declare const resolve: BinaryResolver;
|
|
@@ -1,24 +1,55 @@
|
|
|
1
|
-
import parseArgs from '../util/parse-args.js';
|
|
1
|
+
import parseArgs, {} from '../util/parse-args.js';
|
|
2
2
|
import { compact } from '../util/array.js';
|
|
3
|
-
import {
|
|
3
|
+
import { toModule, toEntry } from '../util/input.js';
|
|
4
4
|
import { isValidBinary } from '../util/modules.js';
|
|
5
5
|
import { isAbsolute } from '../util/path.js';
|
|
6
|
-
import {
|
|
7
|
-
export const
|
|
8
|
-
const
|
|
6
|
+
import { argsFrom, toCommandBinary } from './util.js';
|
|
7
|
+
export const shellSpawningBinaries = ['cross-env-shell'];
|
|
8
|
+
export const spawningBinaries = ['cross-env', ...shellSpawningBinaries];
|
|
9
|
+
const isEnvAssignment = /^\w+=/;
|
|
10
|
+
export const getEnvAssignmentCount = (values) => {
|
|
11
|
+
let count = 0;
|
|
12
|
+
while (count < values.length && isEnvAssignment.test(values[count]))
|
|
13
|
+
count++;
|
|
14
|
+
return count;
|
|
15
|
+
};
|
|
16
|
+
const endOfCommandBinaries = ['doppler', 'dotenvx', 'infisical', 'op'];
|
|
17
|
+
const commandFlagBinaries = new Map([
|
|
18
|
+
['doppler', ['command']],
|
|
19
|
+
['infisical', ['command', 'c']],
|
|
20
|
+
]);
|
|
9
21
|
const positionals = new Set(['babel-node', 'esbuild', 'execa', 'jiti', 'oxnode', 'vite-node', 'zx']);
|
|
10
22
|
const positionalBinaries = new Set(['concurrently']);
|
|
11
23
|
export const isWrapper = (binary) => spawningBinaries.includes(binary) || endOfCommandBinaries.includes(binary) || positionalBinaries.has(binary);
|
|
24
|
+
const parse = (binary, words) => parseArgs(words, {
|
|
25
|
+
boolean: ['quiet', 'verbose'],
|
|
26
|
+
string: commandFlagBinaries.get(binary) ?? [],
|
|
27
|
+
'--': endOfCommandBinaries.includes(binary),
|
|
28
|
+
});
|
|
29
|
+
const toWrappedScripts = (binary, words, parsed) => {
|
|
30
|
+
const scripts = [];
|
|
31
|
+
if (parsed['--'] && parsed['--'].length > 0)
|
|
32
|
+
scripts.push(argsFrom(words, '--').slice(1));
|
|
33
|
+
if (positionalBinaries.has(binary))
|
|
34
|
+
for (const script of parsed._)
|
|
35
|
+
scripts.push([script]);
|
|
36
|
+
for (const flag of commandFlagBinaries.get(binary) ?? [])
|
|
37
|
+
if (parsed[flag])
|
|
38
|
+
scripts.push([parsed[flag]]);
|
|
39
|
+
return scripts;
|
|
40
|
+
};
|
|
41
|
+
export const getWrappedScripts = (binary, words) => endOfCommandBinaries.includes(binary) || commandFlagBinaries.has(binary) || positionalBinaries.has(binary)
|
|
42
|
+
? toWrappedScripts(binary, words, parse(binary, words))
|
|
43
|
+
: [];
|
|
12
44
|
export const resolve = (binary, words, options) => {
|
|
13
45
|
const { fromArgs } = options;
|
|
14
|
-
const parsed =
|
|
46
|
+
const parsed = parse(binary, words);
|
|
15
47
|
const bin = binary.startsWith('.') || (binary.includes('/') && !isAbsolute(binary))
|
|
16
48
|
? toEntry(binary)
|
|
17
49
|
: isValidBinary(binary)
|
|
18
50
|
? toCommandBinary(binary, options)
|
|
19
51
|
: undefined;
|
|
20
|
-
const pos = positionals.has(binary) ? [
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
return compact([bin, ...pos, ...newCommand, ...commands]);
|
|
52
|
+
const pos = positionals.has(binary) ? [toModule(parsed._[0])] : [];
|
|
53
|
+
const commands = toWrappedScripts(binary, words, parsed).flatMap(script => fromArgs(script));
|
|
54
|
+
return compact([bin, ...pos, ...commands]);
|
|
24
55
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Word } from 'unbash';
|
|
2
2
|
import type { BinaryResolver, GetScriptCommands, ScriptArg } from '../types/config.ts';
|
|
3
3
|
export declare const isWrapper: (binary: string) => boolean;
|
|
4
|
+
export declare const toForwardedScript: (args: ScriptArg[]) => string;
|
|
4
5
|
export declare const getWrappedCommand: (binary: string, words: Word[], cwd?: string) => ScriptArg[] | undefined;
|
|
5
6
|
export declare const getScriptCommands: GetScriptCommands;
|
|
6
7
|
export declare const resolve: BinaryResolver;
|