knip 4.1.0 → 4.2.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.
Files changed (65) hide show
  1. package/dist/ConfigurationChief.d.ts +14 -12
  2. package/dist/ConfigurationChief.js +37 -25
  3. package/dist/ConfigurationValidator.d.ts +56 -0
  4. package/dist/ConfigurationValidator.js +1 -0
  5. package/dist/DependencyDeputy.d.ts +16 -17
  6. package/dist/DependencyDeputy.js +40 -27
  7. package/dist/IssueFixer.js +1 -1
  8. package/dist/ProjectPrincipal.d.ts +1 -1
  9. package/dist/ProjectPrincipal.js +4 -4
  10. package/dist/WorkspaceWorker.d.ts +15 -23
  11. package/dist/WorkspaceWorker.js +31 -53
  12. package/dist/binaries/bash-parser.d.ts +2 -6
  13. package/dist/binaries/bash-parser.js +7 -6
  14. package/dist/binaries/index.js +2 -4
  15. package/dist/binaries/resolvers/bun.js +2 -3
  16. package/dist/binaries/resolvers/fallback.js +0 -1
  17. package/dist/binaries/resolvers/index.d.ts +15 -11
  18. package/dist/binaries/resolvers/index.js +26 -11
  19. package/dist/binaries/resolvers/npx.js +4 -5
  20. package/dist/binaries/resolvers/pnpm.js +2 -3
  21. package/dist/binaries/resolvers/ts-node.d.ts +2 -0
  22. package/dist/binaries/resolvers/ts-node.js +16 -0
  23. package/dist/binaries/resolvers/yarn.js +3 -4
  24. package/dist/binaries/types.d.ts +7 -11
  25. package/dist/compilers/index.d.ts +13 -3
  26. package/dist/compilers/index.js +3 -8
  27. package/dist/index.js +36 -20
  28. package/dist/manifest/helpers.d.ts +8 -2
  29. package/dist/manifest/helpers.js +14 -1
  30. package/dist/manifest/index.d.ts +3 -8
  31. package/dist/manifest/index.js +6 -21
  32. package/dist/plugins/ava/index.js +2 -6
  33. package/dist/plugins/eleventy/index.js +4 -4
  34. package/dist/plugins/eslint/helpers.d.ts +2 -2
  35. package/dist/plugins/github-actions/index.js +5 -13
  36. package/dist/plugins/husky/index.js +2 -6
  37. package/dist/plugins/index.d.ts +1 -0
  38. package/dist/plugins/index.js +1 -0
  39. package/dist/plugins/lefthook/index.js +3 -3
  40. package/dist/plugins/lint-staged/index.js +1 -2
  41. package/dist/plugins/netlify/helpers.d.ts +2 -0
  42. package/dist/plugins/netlify/helpers.js +4 -0
  43. package/dist/plugins/netlify/index.d.ts +10 -0
  44. package/dist/plugins/netlify/index.js +38 -0
  45. package/dist/plugins/netlify/types.d.ts +11 -0
  46. package/dist/plugins/netlify/types.js +1 -0
  47. package/dist/plugins/nx/index.js +2 -2
  48. package/dist/plugins/release-it/index.js +2 -2
  49. package/dist/plugins/vitest/index.js +7 -8
  50. package/dist/plugins/wireit/index.js +2 -2
  51. package/dist/types/config.d.ts +0 -2
  52. package/dist/types/package-json.d.ts +3 -2
  53. package/dist/types/plugins.d.ts +11 -6
  54. package/dist/types/workspace.d.ts +11 -9
  55. package/dist/typescript/createHosts.js +2 -2
  56. package/dist/util/fs.d.ts +1 -0
  57. package/dist/util/fs.js +5 -0
  58. package/dist/util/loader.js +4 -1
  59. package/dist/util/modules.d.ts +1 -1
  60. package/dist/util/regex.d.ts +0 -1
  61. package/dist/util/regex.js +0 -1
  62. package/dist/version.d.ts +1 -1
  63. package/dist/version.js +1 -1
  64. package/package.json +2 -1
  65. package/schema.json +4 -0
@@ -1,5 +1,5 @@
1
1
  import ts from 'typescript';
2
- import { dummyCompilers, getExtensions } from './compilers/index.js';
2
+ import { dummyCompilers, getCompilerExtensions } from './compilers/index.js';
3
3
  import { DEFAULT_EXTENSIONS } from './constants.js';
4
4
  import { IGNORED_FILE_EXTENSIONS } from './constants.js';
5
5
  import { createHosts } from './typescript/createHosts.js';
@@ -51,7 +51,7 @@ export class ProjectPrincipal {
51
51
  allowNonTsExtensions: true,
52
52
  };
53
53
  const [syncCompilers, asyncCompilers] = compilers;
54
- this.extensions = new Set([...DEFAULT_EXTENSIONS, ...getExtensions(compilers)]);
54
+ this.extensions = new Set([...DEFAULT_EXTENSIONS, ...getCompilerExtensions(compilers)]);
55
55
  this.syncCompilers = syncCompilers;
56
56
  this.asyncCompilers = asyncCompilers;
57
57
  }
@@ -76,7 +76,7 @@ export class ProjectPrincipal {
76
76
  addCompilers(compilers) {
77
77
  this.syncCompilers = new Map([...this.syncCompilers, ...compilers[0]]);
78
78
  this.asyncCompilers = new Map([...this.asyncCompilers, ...compilers[1]]);
79
- this.extensions = new Set([...this.extensions, ...getExtensions(compilers)]);
79
+ this.extensions = new Set([...this.extensions, ...getCompilerExtensions(compilers)]);
80
80
  }
81
81
  createProgram() {
82
82
  this.backend.program = tsCreateProgram(Array.from(this.entryPaths), this.compilerOptions, this.backend.compilerHost, this.backend.program);
@@ -102,7 +102,7 @@ export class ProjectPrincipal {
102
102
  this.projectPaths.add(filePath);
103
103
  }
104
104
  }
105
- addReferencedDependencies(referencedDependencies, workspaceName) {
105
+ addReferencedDependencies(workspaceName, referencedDependencies) {
106
106
  referencedDependencies.forEach(referencedDependency => this.referencedDependencies.add([...referencedDependency, workspaceName]));
107
107
  }
108
108
  async runAsyncCompilers() {
@@ -1,12 +1,13 @@
1
1
  import type { Configuration, PluginName, WorkspaceConfiguration } from './types/config.js';
2
- import type { PackageJsonWithPlugins } from './types/package-json.js';
3
- import type { InstalledBinaries, HostDependencies } from './types/workspace.js';
2
+ import type { PackageJson } from './types/package-json.js';
3
+ import type { DependencySet } from './types/workspace.js';
4
4
  type WorkspaceManagerOptions = {
5
5
  name: string;
6
6
  dir: string;
7
7
  cwd: string;
8
8
  config: WorkspaceConfiguration;
9
- manifest: PackageJsonWithPlugins;
9
+ manifest: PackageJson;
10
+ dependencies: DependencySet;
10
11
  rootIgnore: Configuration['ignore'];
11
12
  negatedWorkspacePatterns: string[];
12
13
  enabledPluginsInAncestors: string[];
@@ -19,24 +20,19 @@ export declare class WorkspaceWorker {
19
20
  dir: string;
20
21
  cwd: string;
21
22
  config: WorkspaceConfiguration;
22
- manifest: PackageJsonWithPlugins;
23
+ manifest: PackageJson;
24
+ manifestScriptNames: Set<string>;
25
+ dependencies: DependencySet;
23
26
  isProduction: boolean;
24
27
  isStrict: boolean;
25
28
  rootIgnore: Configuration['ignore'];
26
29
  negatedWorkspacePatterns: string[];
27
- enabledPluginsInAncestors: string[];
28
- enabled: Record<PluginName, boolean>;
30
+ enabledPluginsMap: Record<"typescript" | "astro" | "svelte" | "vue" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "netlify" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "tsup" | "typedoc" | "unbuild" | "vite" | "vitest" | "webpack" | "wireit" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease", boolean>;
29
31
  enabledPlugins: PluginName[];
30
- referencedDependencies: ReferencedDependencies;
31
- hostDependencies: HostDependencies;
32
- installedBinaries: InstalledBinaries;
33
- hasTypesIncluded: Set<string>;
34
- entryFilePatterns: Set<string>;
35
- productionEntryFilePatterns: Set<string>;
36
- constructor({ name, dir, cwd, config, manifest, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }: WorkspaceManagerOptions);
32
+ enabledPluginsInAncestors: string[];
33
+ constructor({ name, dir, cwd, config, manifest, dependencies, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }: WorkspaceManagerOptions);
37
34
  init(): Promise<void>;
38
- private setEnabledPlugins;
39
- private initReferencedDependencies;
35
+ private determineEnabledPlugins;
40
36
  private getConfigForPlugin;
41
37
  getEntryFilePatterns(): string[];
42
38
  getProjectFilePatterns(testFilePatterns: string[]): string[];
@@ -46,15 +42,11 @@ export declare class WorkspaceWorker {
46
42
  getProductionProjectFilePatterns(negatedTestFilePatterns: string[]): string[];
47
43
  private getConfigurationFilePatterns;
48
44
  getIgnorePatterns(): string[];
49
- private findDependenciesByPlugins;
50
- findAllDependencies(): Promise<{
51
- hostDependencies: HostDependencies;
52
- installedBinaries: InstalledBinaries;
45
+ findDependenciesByPlugins(): Promise<{
46
+ entryFilePatterns: Set<string>;
47
+ productionEntryFilePatterns: Set<string>;
53
48
  referencedDependencies: ReferencedDependencies;
54
- hasTypesIncluded: Set<string>;
55
- enabledPlugins: ("typescript" | "astro" | "svelte" | "vue" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "tsup" | "typedoc" | "unbuild" | "vite" | "vitest" | "webpack" | "wireit" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease")[];
56
- entryFilePatterns: string[];
57
- productionEntryFilePatterns: string[];
49
+ enabledPlugins: ("typescript" | "astro" | "svelte" | "vue" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "netlify" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "tsup" | "typedoc" | "unbuild" | "vite" | "vitest" | "webpack" | "wireit" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease")[];
58
50
  }>;
59
51
  }
60
52
  export {};
@@ -1,85 +1,64 @@
1
- import * as npm from './manifest/index.js';
2
1
  import * as plugins from './plugins/index.js';
3
2
  import { debugLogArray, debugLogObject } from './util/debug.js';
4
3
  import { _pureGlob, negate, hasProductionSuffix, hasNoProductionSuffix, prependDirToPattern } from './util/glob.js';
5
4
  import { FAKE_PATH } from './util/loader.js';
6
5
  import { get, getKeysByValue } from './util/object.js';
7
- import { basename, join, toPosix } from './util/path.js';
6
+ import { basename, toPosix } from './util/path.js';
8
7
  import { fromEntryPattern, fromProductionEntryPattern, isEntryPattern, isProductionEntryPattern, } from './util/protocols.js';
9
8
  const nullConfig = { config: null, entry: null, project: null };
9
+ const initEnabledPluginsMap = () => Object.keys(plugins).reduce((enabled, pluginName) => ({ ...enabled, [pluginName]: false }), {});
10
10
  export class WorkspaceWorker {
11
11
  name;
12
12
  dir;
13
13
  cwd;
14
14
  config;
15
15
  manifest;
16
+ manifestScriptNames;
17
+ dependencies;
16
18
  isProduction;
17
19
  isStrict;
18
20
  rootIgnore;
19
21
  negatedWorkspacePatterns = [];
20
- enabledPluginsInAncestors;
21
- enabled;
22
+ enabledPluginsMap = initEnabledPluginsMap();
22
23
  enabledPlugins = [];
23
- referencedDependencies = new Set();
24
- hostDependencies = new Map();
25
- installedBinaries = new Map();
26
- hasTypesIncluded = new Set();
27
- entryFilePatterns = new Set();
28
- productionEntryFilePatterns = new Set();
29
- constructor({ name, dir, cwd, config, manifest, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }) {
24
+ enabledPluginsInAncestors;
25
+ constructor({ name, dir, cwd, config, manifest, dependencies, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }) {
30
26
  this.name = name;
31
27
  this.dir = dir;
32
28
  this.cwd = cwd;
33
29
  this.config = config;
34
30
  this.manifest = manifest;
31
+ this.manifestScriptNames = new Set(Object.keys(manifest.scripts ?? {}));
32
+ this.dependencies = dependencies;
35
33
  this.isProduction = isProduction;
36
34
  this.isStrict = isStrict;
37
35
  this.rootIgnore = rootIgnore;
38
36
  this.negatedWorkspacePatterns = negatedWorkspacePatterns;
39
37
  this.enabledPluginsInAncestors = enabledPluginsInAncestors;
40
- this.enabled = Object.keys(plugins).reduce((enabled, pluginName) => ({ ...enabled, [pluginName]: false }), {});
41
38
  }
42
39
  async init() {
43
- await this.setEnabledPlugins();
44
- await this.initReferencedDependencies();
40
+ this.enabledPlugins = await this.determineEnabledPlugins();
45
41
  }
46
- async setEnabledPlugins() {
42
+ async determineEnabledPlugins() {
47
43
  const manifest = this.manifest;
48
- const deps = Object.keys(manifest.dependencies ?? {});
49
- const devDeps = Object.keys(manifest.devDependencies ?? {});
50
- const dependencies = new Set([...deps, ...devDeps]);
51
44
  const pluginEntries = Object.entries(plugins);
52
45
  for (const [pluginName, plugin] of pluginEntries) {
53
46
  if (this.config[pluginName] === false)
54
47
  continue;
55
48
  if (this.config[pluginName]) {
56
- this.enabled[pluginName] = true;
49
+ this.enabledPluginsMap[pluginName] = true;
57
50
  continue;
58
51
  }
59
52
  const isEnabledInAncestor = this.enabledPluginsInAncestors.includes(pluginName);
60
53
  if (isEnabledInAncestor ||
61
- (await plugin.isEnabled({ cwd: this.dir, manifest, dependencies, config: this.config }))) {
62
- this.enabled[pluginName] = true;
54
+ (await plugin.isEnabled({ cwd: this.dir, manifest, dependencies: this.dependencies, config: this.config }))) {
55
+ this.enabledPluginsMap[pluginName] = true;
63
56
  }
64
57
  }
65
- this.enabledPlugins = getKeysByValue(this.enabled, true);
66
- const enabledPluginNames = this.enabledPlugins.map(name => plugins[name].NAME);
58
+ const enabledPlugins = getKeysByValue(this.enabledPluginsMap, true);
59
+ const enabledPluginNames = enabledPlugins.map(name => plugins[name].NAME);
67
60
  debugLogObject(this.name, 'Enabled plugins', enabledPluginNames);
68
- }
69
- async initReferencedDependencies() {
70
- const { dependencies, hostDependencies, installedBinaries, hasTypesIncluded } = await npm.findDependencies({
71
- manifest: this.manifest,
72
- isProduction: this.isProduction,
73
- isStrict: this.isStrict,
74
- dir: this.dir,
75
- cwd: this.cwd,
76
- });
77
- const filePath = join(this.dir, 'package.json');
78
- dependencies.forEach(dependency => this.referencedDependencies.add([filePath, dependency]));
79
- this.hostDependencies = hostDependencies;
80
- this.installedBinaries = installedBinaries;
81
- this.hasTypesIncluded = hasTypesIncluded;
82
- this.hasTypesIncluded = hasTypesIncluded;
61
+ return enabledPlugins;
83
62
  }
84
63
  getConfigForPlugin(pluginName) {
85
64
  const config = this.config[pluginName];
@@ -111,7 +90,7 @@ export class WorkspaceWorker {
111
90
  const patterns = [];
112
91
  for (const [pluginName, plugin] of Object.entries(plugins)) {
113
92
  const pluginConfig = this.getConfigForPlugin(pluginName);
114
- if (this.enabled[pluginName]) {
93
+ if (this.enabledPluginsMap[pluginName]) {
115
94
  const { entry, project } = pluginConfig;
116
95
  patterns.push(...(project ?? entry ?? ('PROJECT_FILE_PATTERNS' in plugin ? plugin.PROJECT_FILE_PATTERNS : [])));
117
96
  }
@@ -122,7 +101,7 @@ export class WorkspaceWorker {
122
101
  const patterns = [];
123
102
  for (const [pluginName, plugin] of Object.entries(plugins)) {
124
103
  const pluginConfig = this.getConfigForPlugin(pluginName);
125
- if (this.enabled[pluginName] && pluginConfig) {
104
+ if (this.enabledPluginsMap[pluginName] && pluginConfig) {
126
105
  const { config } = pluginConfig;
127
106
  const defaultConfigFiles = 'CONFIG_FILE_PATTERNS' in plugin ? plugin.CONFIG_FILE_PATTERNS : [];
128
107
  patterns.push(...(config ?? defaultConfigFiles));
@@ -171,10 +150,13 @@ export class WorkspaceWorker {
171
150
  return [...this.rootIgnore, ...this.config.ignore.map(pattern => prependDirToPattern(this.name, pattern))];
172
151
  }
173
152
  async findDependenciesByPlugins() {
153
+ const entryFilePatterns = new Set();
154
+ const productionEntryFilePatterns = new Set();
155
+ const referencedDependencies = new Set();
174
156
  const name = this.name;
175
157
  const cwd = this.dir;
176
158
  for (const [pluginName, plugin] of Object.entries(plugins)) {
177
- if (this.enabled[pluginName]) {
159
+ if (this.enabledPluginsMap[pluginName]) {
178
160
  const hasDependencyFinder = 'findDependencies' in plugin && typeof plugin.findDependencies === 'function';
179
161
  if (hasDependencyFinder) {
180
162
  const pluginConfig = this.getConfigForPlugin(pluginName);
@@ -192,6 +174,8 @@ export class WorkspaceWorker {
192
174
  const dependencies = await plugin.findDependencies(configFilePath, {
193
175
  cwd,
194
176
  manifest: this.manifest,
177
+ manifestScriptNames: this.manifestScriptNames,
178
+ dependencies: this.dependencies,
195
179
  config: pluginConfig,
196
180
  isProduction: this.isProduction,
197
181
  enabledPlugins: this.enabledPlugins,
@@ -199,13 +183,13 @@ export class WorkspaceWorker {
199
183
  dependencies.forEach(specifier => {
200
184
  pluginDependencies.add(specifier);
201
185
  if (isEntryPattern(specifier)) {
202
- this.entryFilePatterns.add(fromEntryPattern(specifier));
186
+ entryFilePatterns.add(fromEntryPattern(specifier));
203
187
  }
204
188
  else if (isProductionEntryPattern(specifier)) {
205
- this.productionEntryFilePatterns.add(fromProductionEntryPattern(specifier));
189
+ productionEntryFilePatterns.add(fromProductionEntryPattern(specifier));
206
190
  }
207
191
  else {
208
- this.referencedDependencies.add([configFilePath, toPosix(specifier)]);
192
+ referencedDependencies.add([configFilePath, toPosix(specifier)]);
209
193
  }
210
194
  });
211
195
  }
@@ -213,17 +197,11 @@ export class WorkspaceWorker {
213
197
  }
214
198
  }
215
199
  }
216
- }
217
- async findAllDependencies() {
218
- await this.findDependenciesByPlugins();
219
200
  return {
220
- hostDependencies: this.hostDependencies,
221
- installedBinaries: this.installedBinaries,
222
- referencedDependencies: this.referencedDependencies,
223
- hasTypesIncluded: this.hasTypesIncluded,
201
+ entryFilePatterns,
202
+ productionEntryFilePatterns,
203
+ referencedDependencies,
224
204
  enabledPlugins: this.enabledPlugins,
225
- entryFilePatterns: Array.from(this.entryFilePatterns),
226
- productionEntryFilePatterns: Array.from(this.productionEntryFilePatterns),
227
205
  };
228
206
  }
229
207
  }
@@ -1,6 +1,2 @@
1
- import type { PackageJson } from '@npmcli/package-json';
2
- export declare const getBinariesFromScript: (script: string, { cwd, manifest, knownGlobalsOnly }: {
3
- cwd: string;
4
- manifest: PackageJson;
5
- knownGlobalsOnly?: boolean | undefined;
6
- }) => string[];
1
+ import type { GetDependenciesFromScriptsOptions } from './types.js';
2
+ export declare const getBinariesFromScript: (script: string, options: GetDependenciesFromScriptsOptions) => string[];
@@ -1,12 +1,12 @@
1
1
  import parse from '@ericcornelissen/bash-parser';
2
2
  import { debugLogObject } from '../util/debug.js';
3
3
  import * as FallbackResolver from './resolvers/fallback.js';
4
- import * as KnownResolvers from './resolvers/index.js';
4
+ import KnownResolvers from './resolvers/index.js';
5
5
  import { stripBinaryPath } from './util.js';
6
- export const getBinariesFromScript = (script, { cwd, manifest, knownGlobalsOnly = false }) => {
6
+ export const getBinariesFromScript = (script, options) => {
7
7
  if (!script)
8
8
  return [];
9
- const fromArgs = (args) => getBinariesFromScript(args.filter(arg => arg !== '--').join(' '), { cwd, manifest });
9
+ const fromArgs = (args) => getBinariesFromScript(args.filter(arg => arg !== '--').join(' '), { ...options, knownGlobalsOnly: false });
10
10
  const getBinariesFromNodes = (nodes) => nodes.flatMap(node => {
11
11
  switch (node.type) {
12
12
  case 'Command': {
@@ -25,11 +25,12 @@ export const getBinariesFromScript = (script, { cwd, manifest, knownGlobalsOnly
25
25
  if (['!', 'test'].includes(binary))
26
26
  return fromArgs(args);
27
27
  if (binary in KnownResolvers) {
28
- return KnownResolvers[binary].resolve(binary, args, { cwd, manifest, fromArgs });
28
+ const resolver = KnownResolvers[binary];
29
+ return resolver(binary, args, { ...options, fromArgs });
29
30
  }
30
- if (knownGlobalsOnly)
31
+ if (options.knownGlobalsOnly)
31
32
  return [];
32
- return FallbackResolver.resolve(binary, args, { cwd, manifest, fromArgs });
33
+ return FallbackResolver.resolve(binary, args, { ...options, fromArgs });
33
34
  }
34
35
  case 'LogicalExpression':
35
36
  return getBinariesFromNodes([node.left, node.right]);
@@ -5,11 +5,9 @@ import { extname, isInternal } from '../util/path.js';
5
5
  import { timerify } from '../util/Performance.js';
6
6
  import { fromBinary, isBinary } from '../util/protocols.js';
7
7
  import { getBinariesFromScript } from './bash-parser.js';
8
- const defaultCwd = process.cwd();
9
- const getDependenciesFromScripts = (npmScripts, options = {}) => {
10
- const { cwd = defaultCwd, manifest = {}, knownGlobalsOnly = false } = options;
8
+ const getDependenciesFromScripts = (npmScripts, options) => {
11
9
  const scripts = typeof npmScripts === 'string' ? [npmScripts] : [...npmScripts];
12
- const results = scripts.flatMap(script => getBinariesFromScript(script, { cwd, manifest, knownGlobalsOnly }));
10
+ const results = scripts.flatMap(script => getBinariesFromScript(script, options));
13
11
  return compact(results.map(identifier => {
14
12
  if (identifier.startsWith('http'))
15
13
  return;
@@ -1,11 +1,10 @@
1
1
  import parseArgs from 'minimist';
2
2
  import { tryResolveFilePath } from '../util.js';
3
3
  const commands = ['add', 'create', 'init', 'install', 'link', 'pm', 'remove', 'run', 'update'];
4
- export const resolve = (_binary, args, { manifest, cwd, fromArgs }) => {
5
- const scripts = manifest.scripts ? Object.keys(manifest.scripts) : [];
4
+ export const resolve = (_binary, args, { manifestScriptNames, cwd, fromArgs }) => {
6
5
  const parsed = parseArgs(args);
7
6
  const [command, script] = parsed._;
8
- if (command === 'run' && scripts.includes(script))
7
+ if (command === 'run' && manifestScriptNames.has(script))
9
8
  return [];
10
9
  if (commands.includes(command))
11
10
  return [];
@@ -11,7 +11,6 @@ const argFilters = {
11
11
  esbuild: withPositional,
12
12
  execa: withPositional,
13
13
  vitest: withoutRequire,
14
- 'ts-node': withPositional,
15
14
  zx: withPositional,
16
15
  default: withoutPositional,
17
16
  };
@@ -1,11 +1,15 @@
1
- export * as bun from './bun.js';
2
- export * as c8 from './c8.js';
3
- export * as dotenv from './dotenv.js';
4
- export * as node from './node.js';
5
- export * as nodemon from './nodemon.js';
6
- export * as npx from './npx.js';
7
- export * as nx from './nx.js';
8
- export * as pnpm from './pnpm.js';
9
- export * as rollup from './rollup.js';
10
- export * as tsx from './tsx.js';
11
- export * as yarn from './yarn.js';
1
+ declare const _default: {
2
+ bun: import("../types.js").Resolver;
3
+ c8: import("../types.js").Resolver;
4
+ dotenv: import("../types.js").Resolver;
5
+ node: import("../types.js").Resolver;
6
+ nodemon: import("../types.js").Resolver;
7
+ npx: import("../types.js").Resolver;
8
+ nx: import("../types.js").Resolver;
9
+ pnpm: import("../types.js").Resolver;
10
+ rollup: import("../types.js").Resolver;
11
+ 'ts-node': import("../types.js").Resolver;
12
+ tsx: import("../types.js").Resolver;
13
+ yarn: import("../types.js").Resolver;
14
+ };
15
+ export default _default;
@@ -1,11 +1,26 @@
1
- export * as bun from './bun.js';
2
- export * as c8 from './c8.js';
3
- export * as dotenv from './dotenv.js';
4
- export * as node from './node.js';
5
- export * as nodemon from './nodemon.js';
6
- export * as npx from './npx.js';
7
- export * as nx from './nx.js';
8
- export * as pnpm from './pnpm.js';
9
- export * as rollup from './rollup.js';
10
- export * as tsx from './tsx.js';
11
- export * as yarn from './yarn.js';
1
+ import * as bun from './bun.js';
2
+ import * as c8 from './c8.js';
3
+ import * as dotenv from './dotenv.js';
4
+ import * as node from './node.js';
5
+ import * as nodemon from './nodemon.js';
6
+ import * as npx from './npx.js';
7
+ import * as nx from './nx.js';
8
+ import * as pnpm from './pnpm.js';
9
+ import * as rollup from './rollup.js';
10
+ import * as tsNode from './ts-node.js';
11
+ import * as tsx from './tsx.js';
12
+ import * as yarn from './yarn.js';
13
+ export default {
14
+ bun: bun.resolve,
15
+ c8: c8.resolve,
16
+ dotenv: dotenv.resolve,
17
+ node: node.resolve,
18
+ nodemon: nodemon.resolve,
19
+ npx: npx.resolve,
20
+ nx: nx.resolve,
21
+ pnpm: pnpm.resolve,
22
+ rollup: rollup.resolve,
23
+ 'ts-node': tsNode.resolve,
24
+ tsx: tsx.resolve,
25
+ yarn: yarn.resolve,
26
+ };
@@ -1,9 +1,9 @@
1
1
  import parseArgs from 'minimist';
2
2
  import { isInternal } from '../../util/path.js';
3
3
  import { toBinary } from '../../util/protocols.js';
4
- import { getBinariesFromScript } from '../bash-parser.js';
5
4
  import { argsFrom, stripVersionFromSpecifier } from '../util.js';
6
- export const resolve = (binary, args, { cwd, fromArgs, manifest }) => {
5
+ export const resolve = (binary, args, options) => {
6
+ const { fromArgs, dependencies } = options;
7
7
  const parsed = parseArgs(args, {
8
8
  boolean: ['yes', 'no'],
9
9
  alias: { yes: 'y', no: 'no-install', package: 'p', call: 'c' },
@@ -11,10 +11,9 @@ export const resolve = (binary, args, { cwd, fromArgs, manifest }) => {
11
11
  const packageSpecifier = parsed._[0];
12
12
  const specifier = packageSpecifier ? stripVersionFromSpecifier(packageSpecifier) : '';
13
13
  const packages = parsed.package ? [parsed.package].flat().map(stripVersionFromSpecifier) : [];
14
- const command = parsed.call ? getBinariesFromScript(parsed.call, { cwd, manifest }) : [];
14
+ const command = parsed.call ? fromArgs([parsed.call]) : [];
15
15
  const restArgs = argsFrom(args, packageSpecifier);
16
- const dependencies = manifest ? Object.keys({ ...manifest.dependencies, ...manifest.devDependencies }) : [];
17
- const isBinary = specifier && !packageSpecifier.includes('@') && !isInternal(specifier) && !dependencies.includes(specifier);
16
+ const isBinary = specifier && !packageSpecifier.includes('@') && !isInternal(specifier) && !dependencies.has(specifier);
18
17
  const dependency = isBinary ? toBinary(specifier) : specifier;
19
18
  const specifiers = dependency && !parsed.yes ? [dependency] : [];
20
19
  return [...specifiers, ...packages, ...command, ...fromArgs(restArgs).slice(1)];
@@ -51,11 +51,10 @@ const commands = [
51
51
  'upgrade',
52
52
  'why',
53
53
  ];
54
- export const resolve = (_binary, args, { manifest }) => {
55
- const scripts = manifest.scripts ? Object.keys(manifest.scripts) : [];
54
+ export const resolve = (_binary, args, { manifestScriptNames }) => {
56
55
  const parsed = parseArgs(args, { alias: { recursive: 'r' }, boolean: ['recursive'] });
57
56
  const [command, binary] = parsed._;
58
- if (scripts.includes(command) || commands.includes(command))
57
+ if (manifestScriptNames.has(command) || commands.includes(command))
59
58
  return [];
60
59
  if (command === 'exec')
61
60
  return [toBinary(binary)];
@@ -0,0 +1,2 @@
1
+ import type { Resolver } from '../types.js';
2
+ export declare const resolve: Resolver;
@@ -0,0 +1,16 @@
1
+ import parseArgs from 'minimist';
2
+ import { compact } from '../../util/array.js';
3
+ import { toBinary } from '../../util/protocols.js';
4
+ import { tryResolveFilePath, tryResolveSpecifiers } from '../util.js';
5
+ export const resolve = (binary, args, { cwd }) => {
6
+ const parsed = parseArgs(args, {
7
+ string: ['r'],
8
+ boolean: ['transpileOnly', 'compilerHost', 'ignoreDiagnostics', 'swc', 'preferTsExts'],
9
+ alias: { require: ['r'], transpileOnly: ['T'], compilerHost: ['H'], ignoreDiagnostics: ['D'] },
10
+ });
11
+ return compact([
12
+ toBinary(binary),
13
+ tryResolveFilePath(cwd, parsed._[0]),
14
+ ...tryResolveSpecifiers(cwd, [parsed.require].flat()),
15
+ ]);
16
+ };
@@ -32,13 +32,12 @@ const commands = [
32
32
  'workspace',
33
33
  'workspaces',
34
34
  ];
35
- export const resolve = (_binary, args, { manifest, fromArgs }) => {
36
- const scripts = manifest.scripts ? Object.keys(manifest.scripts) : [];
35
+ export const resolve = (_binary, args, { manifestScriptNames, fromArgs }) => {
37
36
  const parsed = parseArgs(args, {});
38
37
  const [command, binary] = parsed._;
39
- if (scripts.includes(command) || commands.includes(command))
38
+ if (manifestScriptNames.has(command) || commands.includes(command))
40
39
  return [];
41
- if (command === 'run' && scripts.includes(binary))
40
+ if (command === 'run' && manifestScriptNames.has(binary))
42
41
  return [];
43
42
  if (command === 'run' || command === 'exec')
44
43
  return [toBinary(binary)];
@@ -1,15 +1,11 @@
1
- /// <reference types="npmcli__package-json" />
2
- import type { PackageJson } from '@npmcli/package-json';
3
- type Options = {
4
- cwd?: string;
5
- manifest?: PackageJson;
1
+ import type { BaseOptions } from '../types/plugins.js';
2
+ export interface GetDependenciesFromScriptsOptions extends BaseOptions {
6
3
  knownGlobalsOnly?: boolean;
7
- };
8
- export type GetDependenciesFromScripts = (npmScripts: string | string[] | Set<string>, options?: Options) => string[];
4
+ }
5
+ export type GetDependenciesFromScripts = (npmScripts: string | string[] | Set<string>, options: GetDependenciesFromScriptsOptions) => string[];
9
6
  type FromArgs = (args: string[]) => string[];
10
- export type Resolver = (binary: string, args: string[], options: {
11
- cwd: string;
12
- manifest: PackageJson;
7
+ interface BinaryResolverOptions extends GetDependenciesFromScriptsOptions {
13
8
  fromArgs: FromArgs;
14
- }) => string[];
9
+ }
10
+ export type Resolver = (binary: string, args: string[], options: BinaryResolverOptions) => string[];
15
11
  export {};
@@ -1,6 +1,6 @@
1
1
  import type { AsyncCompilerFn, AsyncCompilers, SyncCompilerFn, SyncCompilers } from './types.js';
2
2
  import type { RawConfiguration } from '../types/config.js';
3
- import type { PackageJson } from '@npmcli/package-json';
3
+ import type { DependencySet } from '../types/workspace.js';
4
4
  export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
5
5
  syncCompilers: Record<string, SyncCompilerFn>;
6
6
  asyncCompilers: Record<string, AsyncCompilerFn>;
@@ -140,6 +140,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
140
140
  entry?: string | string[] | undefined;
141
141
  project?: string | string[] | undefined;
142
142
  } | undefined;
143
+ netlify?: string | boolean | string[] | {
144
+ config?: string | string[] | undefined;
145
+ entry?: string | string[] | undefined;
146
+ project?: string | string[] | undefined;
147
+ } | undefined;
143
148
  next?: string | boolean | string[] | {
144
149
  config?: string | string[] | undefined;
145
150
  entry?: string | string[] | undefined;
@@ -391,6 +396,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
391
396
  entry?: string | string[] | undefined;
392
397
  project?: string | string[] | undefined;
393
398
  } | undefined;
399
+ netlify?: string | boolean | string[] | {
400
+ config?: string | string[] | undefined;
401
+ entry?: string | string[] | undefined;
402
+ project?: string | string[] | undefined;
403
+ } | undefined;
394
404
  next?: string | boolean | string[] | {
395
405
  config?: string | string[] | undefined;
396
406
  entry?: string | string[] | undefined;
@@ -528,5 +538,5 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
528
538
  } | undefined;
529
539
  };
530
540
  export declare const dummyCompilers: Map<string, SyncCompilerFn>;
531
- export declare const mergeCompilers: (syncCompilers: SyncCompilers, asyncCompilers: AsyncCompilers, manifest: PackageJson) => [SyncCompilers, AsyncCompilers];
532
- export declare const getExtensions: (compilers: [SyncCompilers, AsyncCompilers]) => string[];
541
+ export declare const getIncludedCompilers: (syncCompilers: SyncCompilers, asyncCompilers: AsyncCompilers, dependencies: DependencySet) => [SyncCompilers, AsyncCompilers];
542
+ export declare const getCompilerExtensions: (compilers: [SyncCompilers, AsyncCompilers]) => string[];
@@ -31,13 +31,8 @@ const compilers = new Map([
31
31
  ]);
32
32
  const dummyCompiler = () => '';
33
33
  export const dummyCompilers = new Map(Array.from(DUMMY_VIRTUAL_FILE_EXTENSIONS).map(ext => [ext, dummyCompiler]));
34
- const getDependencies = (manifest) => [
35
- ...Object.keys(manifest?.dependencies ?? {}),
36
- ...Object.keys(manifest?.devDependencies ?? {}),
37
- ];
38
- export const mergeCompilers = (syncCompilers, asyncCompilers, manifest) => {
39
- const dependencies = getDependencies(manifest);
40
- const hasDependency = (packageName) => dependencies.includes(packageName);
34
+ export const getIncludedCompilers = (syncCompilers, asyncCompilers, dependencies) => {
35
+ const hasDependency = (packageName) => dependencies.has(packageName);
41
36
  for (const [extension, { condition, compiler }] of compilers.entries()) {
42
37
  if (!syncCompilers.has(extension) && condition(hasDependency)) {
43
38
  syncCompilers.set(extension, compiler);
@@ -45,7 +40,7 @@ export const mergeCompilers = (syncCompilers, asyncCompilers, manifest) => {
45
40
  }
46
41
  return [syncCompilers, asyncCompilers];
47
42
  };
48
- export const getExtensions = (compilers) => [
43
+ export const getCompilerExtensions = (compilers) => [
49
44
  ...compilers[0].keys(),
50
45
  ...compilers[1].keys(),
51
46
  ];