knip 6.31.0 → 6.32.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 (59) hide show
  1. package/dist/ConfigurationChief.d.ts +18 -0
  2. package/dist/DependencyDeputy.d.ts +2 -1
  3. package/dist/DependencyDeputy.js +2 -2
  4. package/dist/WorkspaceWorker.js +12 -14
  5. package/dist/binaries/bash-parser.js +20 -8
  6. package/dist/binaries/fallback.js +6 -4
  7. package/dist/binaries/plugins.js +8 -4
  8. package/dist/binaries/resolvers/bun.js +7 -7
  9. package/dist/binaries/resolvers/bunx.d.ts +2 -1
  10. package/dist/binaries/resolvers/bunx.js +10 -6
  11. package/dist/binaries/resolvers/find.js +5 -5
  12. package/dist/binaries/resolvers/npm.js +5 -5
  13. package/dist/binaries/resolvers/npx.js +3 -4
  14. package/dist/binaries/resolvers/nub.js +4 -4
  15. package/dist/binaries/resolvers/pnpm.js +12 -9
  16. package/dist/binaries/resolvers/pnpx.d.ts +2 -1
  17. package/dist/binaries/resolvers/pnpx.js +4 -4
  18. package/dist/binaries/resolvers/yarn.js +17 -13
  19. package/dist/binaries/util.d.ts +6 -4
  20. package/dist/binaries/util.js +25 -3
  21. package/dist/compilers/index.d.ts +30 -0
  22. package/dist/graph/analyze.js +1 -0
  23. package/dist/graph/build.js +1 -0
  24. package/dist/plugins/babel/types.d.ts +1 -0
  25. package/dist/plugins/borp/index.d.ts +3 -0
  26. package/dist/plugins/borp/index.js +61 -0
  27. package/dist/plugins/borp/types.d.ts +4 -0
  28. package/dist/plugins/borp/types.js +1 -0
  29. package/dist/plugins/docusaurus/index.js +3 -4
  30. package/dist/plugins/expo/index.js +3 -1
  31. package/dist/plugins/index.d.ts +3 -0
  32. package/dist/plugins/index.js +6 -0
  33. package/dist/plugins/jest/index.js +6 -2
  34. package/dist/plugins/mocha/index.js +59 -0
  35. package/dist/plugins/playwright/index.js +1 -1
  36. package/dist/plugins/pre-commit/index.d.ts +3 -0
  37. package/dist/plugins/pre-commit/index.js +23 -0
  38. package/dist/plugins/rollup/index.js +5 -1
  39. package/dist/plugins/tsd/index.d.ts +3 -0
  40. package/dist/plugins/tsd/index.js +43 -0
  41. package/dist/plugins/tsd/types.d.ts +4 -0
  42. package/dist/plugins/tsd/types.js +1 -0
  43. package/dist/schema/configuration.d.ts +45 -0
  44. package/dist/schema/plugins.d.ts +15 -0
  45. package/dist/schema/plugins.js +3 -0
  46. package/dist/types/PluginNames.d.ts +2 -2
  47. package/dist/types/PluginNames.js +3 -0
  48. package/dist/types/config.d.ts +4 -2
  49. package/dist/util/create-input-handler.js +2 -0
  50. package/dist/util/create-options.d.ts +30 -0
  51. package/dist/util/package-json.d.ts +3 -0
  52. package/dist/util/package-json.js +6 -2
  53. package/dist/util/parse-args.d.ts +2 -1
  54. package/dist/util/parse-args.js +8 -1
  55. package/dist/util/scripts.js +9 -5
  56. package/dist/version.d.ts +1 -1
  57. package/dist/version.js +1 -1
  58. package/package.json +3 -3
  59. package/schema.json +12 -0
@@ -97,6 +97,11 @@ export declare class ConfigurationChief {
97
97
  entry?: string | string[] | undefined;
98
98
  project?: string | string[] | undefined;
99
99
  } | undefined;
100
+ borp?: string | boolean | string[] | {
101
+ config?: string | string[] | undefined;
102
+ entry?: string | string[] | undefined;
103
+ project?: string | string[] | undefined;
104
+ } | undefined;
100
105
  bumpp?: string | boolean | string[] | {
101
106
  config?: string | string[] | undefined;
102
107
  entry?: string | string[] | undefined;
@@ -552,6 +557,11 @@ export declare class ConfigurationChief {
552
557
  entry?: string | string[] | undefined;
553
558
  project?: string | string[] | undefined;
554
559
  } | undefined;
560
+ 'pre-commit'?: string | boolean | string[] | {
561
+ config?: string | string[] | undefined;
562
+ entry?: string | string[] | undefined;
563
+ project?: string | string[] | undefined;
564
+ } | undefined;
555
565
  preconstruct?: string | boolean | string[] | {
556
566
  config?: string | string[] | undefined;
557
567
  entry?: string | string[] | undefined;
@@ -782,6 +792,11 @@ export declare class ConfigurationChief {
782
792
  entry?: string | string[] | undefined;
783
793
  project?: string | string[] | undefined;
784
794
  } | undefined;
795
+ tsd?: string | boolean | string[] | {
796
+ config?: string | string[] | undefined;
797
+ entry?: string | string[] | undefined;
798
+ project?: string | string[] | undefined;
799
+ } | undefined;
785
800
  tsdown?: string | boolean | string[] | {
786
801
  config?: string | string[] | undefined;
787
802
  entry?: string | string[] | undefined;
@@ -987,6 +1002,7 @@ export declare class ConfigurationChief {
987
1002
  ava?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
988
1003
  babel?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
989
1004
  biome?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1005
+ borp?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
990
1006
  bumpp?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
991
1007
  bun?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
992
1008
  c8?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -1078,6 +1094,7 @@ export declare class ConfigurationChief {
1078
1094
  pm2?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1079
1095
  pnpm?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1080
1096
  postcss?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1097
+ "pre-commit"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1081
1098
  preconstruct?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1082
1099
  prettier?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1083
1100
  prisma?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -1124,6 +1141,7 @@ export declare class ConfigurationChief {
1124
1141
  temporal?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1125
1142
  travis?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1126
1143
  "ts-node"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1144
+ tsd?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1127
1145
  tsdown?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1128
1146
  tsup?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1129
1147
  tsx?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -4,6 +4,7 @@ import type { PackageJson } from './types/package-json.ts';
4
4
  import type { DependencyArray, DependencySet, HostDependencies, InstalledBinaries, WorkspaceManifests } from './types/workspace.ts';
5
5
  import type { MainOptions } from './util/create-options.ts';
6
6
  interface DependencyReferenceOptions {
7
+ specifier: string;
7
8
  isDevOnly?: boolean;
8
9
  isTypeOnly?: boolean;
9
10
  isResolved?: boolean;
@@ -64,7 +65,7 @@ export declare class DependencyDeputy {
64
65
  isPeerOptional: boolean;
65
66
  }[];
66
67
  getOptionalPeerDependencies(workspaceName: string): DependencySet;
67
- maybeAddReferencedExternalDependency(workspace: Workspace, packageName: string, { isDevOnly, isTypeOnly, isResolved, isPublishedType }?: DependencyReferenceOptions): boolean;
68
+ maybeAddReferencedExternalDependency(workspace: Workspace, packageName: string, { specifier, isDevOnly, isTypeOnly, isResolved, isPublishedType }: DependencyReferenceOptions): boolean;
68
69
  maybeAddReferencedBinary(workspace: Workspace, binaryName: string): Set<string> | undefined;
69
70
  private isInDependencies;
70
71
  settleDependencyIssues(): {
@@ -122,10 +122,10 @@ export class DependencyDeputy {
122
122
  getOptionalPeerDependencies(workspaceName) {
123
123
  return this._manifests.get(workspaceName)?.optionalPeerDependencies ?? new Set();
124
124
  }
125
- maybeAddReferencedExternalDependency(workspace, packageName, { isDevOnly, isTypeOnly, isResolved, isPublishedType } = {}) {
125
+ maybeAddReferencedExternalDependency(workspace, packageName, { specifier, isDevOnly, isTypeOnly, isResolved, isPublishedType }) {
126
126
  if (!this.isReportDependencies)
127
127
  return true;
128
- if (packageName.startsWith('node:') || isBuiltin(packageName))
128
+ if (specifier.startsWith('node:') || isBuiltin(specifier))
129
129
  return true;
130
130
  if (IGNORED_RUNTIME_DEPENDENCIES.has(packageName))
131
131
  return true;
@@ -223,7 +223,6 @@ export class WorkspaceWorker {
223
223
  const hasProductionInput = (input) => productionInputsFromManifest.find(d => d.specifier === input.specifier && d.type === input.type);
224
224
  const createGetInputsFromScripts = (containingFilePath) => (scripts, options) => _getInputsFromScripts(scripts, { ...baseOptions, ...options, containingFilePath });
225
225
  const inputs = [];
226
- const enabledPlugins = new Set(this.enabledPlugins);
227
226
  const configFilesMap = this.configFilesMap;
228
227
  const seen = new Map();
229
228
  const parsedConfigCache = new Map();
@@ -434,21 +433,20 @@ export class WorkspaceWorker {
434
433
  break;
435
434
  const [pluginName, dependencies] = entry;
436
435
  configFiles.delete(pluginName);
437
- if (enabledPlugins.has(pluginName)) {
438
- const seenConfigFiles = getSeenConfigFiles(pluginName);
439
- const unprocessed = [];
440
- for (const filePath of dependencies) {
441
- if (!seenConfigFiles.has(filePath))
442
- unprocessed.push(filePath);
443
- }
444
- if (unprocessed.length > 0) {
445
- for (const input of await runPlugin(pluginName, unprocessed, true))
446
- inputs.push(input);
447
- }
448
- }
449
- else {
436
+ if (this.config[pluginName] === false) {
450
437
  for (const id of dependencies)
451
438
  inputs.push(toEntry(id));
439
+ continue;
440
+ }
441
+ const seenConfigFiles = getSeenConfigFiles(pluginName);
442
+ const unprocessed = [];
443
+ for (const filePath of dependencies) {
444
+ if (!seenConfigFiles.has(filePath))
445
+ unprocessed.push(filePath);
446
+ }
447
+ if (unprocessed.length > 0) {
448
+ for (const input of await runPlugin(pluginName, unprocessed, true))
449
+ inputs.push(input);
452
450
  }
453
451
  }
454
452
  }
@@ -30,9 +30,21 @@ export const getDependenciesFromScript = (script, options) => {
30
30
  if (!script)
31
31
  return [];
32
32
  const fromArgs = (args, opts) => {
33
- if (args.length === 0 || !isValidBinary(substringBefore(args[0], ' ')))
33
+ if (args.length === 0)
34
34
  return [];
35
- return getDependenciesFromScript(args.filter(arg => arg !== '--').join(' '), {
35
+ const first = typeof args[0] === 'string' ? args[0] : args[0].value;
36
+ if (!isValidBinary(substringBefore(first, ' ')))
37
+ return [];
38
+ const parts = [];
39
+ for (const arg of args) {
40
+ if (typeof arg === 'string') {
41
+ if (arg !== '--')
42
+ parts.push(arg);
43
+ }
44
+ else if (arg.value !== '--')
45
+ parts.push(arg.text);
46
+ }
47
+ return getDependenciesFromScript(parts.join(' '), {
36
48
  ...options,
37
49
  knownBinsOnly: false,
38
50
  ...opts,
@@ -71,9 +83,9 @@ export const getDependenciesFromScript = (script, options) => {
71
83
  return [];
72
84
  if (definedFunctions.has(binary))
73
85
  return [];
74
- const args = node.suffix.map(w => w.value);
86
+ const words = node.suffix;
75
87
  if (binary === '!' || binary === 'test')
76
- return fromArgs(args);
88
+ return fromArgs(words);
77
89
  const fromNodeOptions = node.prefix
78
90
  .filter(a => a.name === 'NODE_OPTIONS' && a.value)
79
91
  .map(a => a.value.value)
@@ -83,10 +95,10 @@ export const getDependenciesFromScript = (script, options) => {
83
95
  .map(id => toDeferResolve(id));
84
96
  if (binary in KnownResolvers) {
85
97
  const resolver = KnownResolvers[binary];
86
- return resolver(binary, args, { ...options, fromArgs });
98
+ return resolver(binary, words, { ...options, fromArgs });
87
99
  }
88
100
  if (pluginArgsMap.has(binary)) {
89
- return [...resolverFromPlugins(binary, args, { ...options, fromArgs }), ...fromNodeOptions];
101
+ return [...resolverFromPlugins(binary, words, { ...options, fromArgs }), ...fromNodeOptions];
90
102
  }
91
103
  if (spawningBinaries.includes(binary)) {
92
104
  const rest = node.suffix
@@ -96,7 +108,7 @@ export const getDependenciesFromScript = (script, options) => {
96
108
  return [toBinary(binary), ...getDependenciesFromScript(rest, options)];
97
109
  }
98
110
  if (binary in Plugins) {
99
- const inputs = fallbackResolve(binary, args, { ...options, fromArgs });
111
+ const inputs = fallbackResolve(binary, words, { ...options, fromArgs });
100
112
  if (options.knownBinsOnly)
101
113
  for (const input of inputs)
102
114
  input.optional = true;
@@ -104,7 +116,7 @@ export const getDependenciesFromScript = (script, options) => {
104
116
  }
105
117
  if (options.knownBinsOnly && !text?.startsWith('.'))
106
118
  return [];
107
- return [...fallbackResolve(binary, args, { ...options, fromArgs }), ...fromNodeOptions];
119
+ return [...fallbackResolve(binary, words, { ...options, fromArgs }), ...fromNodeOptions];
108
120
  };
109
121
  try {
110
122
  const parsed = parse(script);
@@ -2,18 +2,20 @@ import parseArgs from '../util/parse-args.js';
2
2
  import { compact } from '../util/array.js';
3
3
  import { toBinary, toDeferResolve, toEntry } from '../util/input.js';
4
4
  import { isValidBinary } from '../util/modules.js';
5
+ import { isAbsolute } from '../util/path.js';
6
+ import { argsAfter } from './util.js';
5
7
  const endOfCommandBinaries = ['dotenvx', 'env-cmd', 'op'];
6
8
  const positionals = new Set(['babel-node', 'esbuild', 'execa', 'jiti', 'oxnode', 'vite-node', 'zx']);
7
9
  const positionalBinaries = new Set(['concurrently']);
8
- export const resolve = (binary, args, { fromArgs }) => {
9
- const parsed = parseArgs(args, { boolean: ['quiet', 'verbose'], '--': endOfCommandBinaries.includes(binary) });
10
- const bin = binary.startsWith('.') || binary.includes('/')
10
+ export const resolve = (binary, words, { fromArgs }) => {
11
+ const parsed = parseArgs(words, { boolean: ['quiet', 'verbose'], '--': endOfCommandBinaries.includes(binary) });
12
+ const bin = binary.startsWith('.') || (binary.includes('/') && !isAbsolute(binary))
11
13
  ? toEntry(binary)
12
14
  : isValidBinary(binary)
13
15
  ? toBinary(binary)
14
16
  : undefined;
15
17
  const pos = positionals.has(binary) ? [toDeferResolve(parsed._[0])] : [];
16
- const newCommand = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--']) : [];
18
+ const newCommand = parsed['--'] && parsed['--'].length > 0 ? fromArgs(argsAfter(words, '--')) : [];
17
19
  const commands = positionalBinaries.has(binary) ? parsed._.flatMap(cmd => fromArgs([cmd])) : [];
18
20
  return compact([bin, ...pos, ...newCommand, ...commands]);
19
21
  };
@@ -5,18 +5,22 @@ import { toBinary, toConfig, toDeferResolve, toDeferResolveEntry, toEntry } from
5
5
  import { extractBinary } from '../util/modules.js';
6
6
  import { dirname } from '../util/path.js';
7
7
  import { resolve as fallbackResolve } from './fallback.js';
8
+ import { toWordArgs } from './util.js';
8
9
  const isGlobLikeMatch = /(^!|[*+\\(|{^$])/;
9
10
  const isGlobLike = (value) => isGlobLikeMatch.test(value);
10
11
  const nodeLoadersArgs = { import: ['r', 'experimental-loader', 'require', 'loader'] };
11
- export const resolve = (binary, _args, options) => {
12
+ export const resolve = (binary, words, options) => {
12
13
  const { cwd, fromArgs, containingFilePath, manifest } = options;
13
14
  const [pluginName, pluginArgs] = pluginArgsMap.get(binary) ?? [];
14
15
  if (!pluginArgs)
15
- return fallbackResolve(binary, _args, options);
16
+ return fallbackResolve(binary, words, options);
16
17
  const inputOpts = {};
17
18
  if (cwd && dirname(containingFilePath) !== cwd)
18
19
  Object.assign(inputOpts, { dir: cwd });
19
- const args = typeof pluginArgs.args === 'function' ? pluginArgs.args(_args) : _args;
20
+ const values = [];
21
+ for (const word of words)
22
+ values.push(word.value);
23
+ const args = typeof pluginArgs.args === 'function' ? pluginArgs.args(values) : values;
20
24
  const parsed = parseArgs(args, {
21
25
  string: [
22
26
  ...(pluginArgs.nodeImportArgs ? ['import'] : []),
@@ -47,7 +51,7 @@ export const resolve = (binary, _args, options) => {
47
51
  const resolved = compact(pluginArgs.resolve ? pluginArgs.resolve.flatMap(mapToParsedKey) : []);
48
52
  const resolvedImports = pluginArgs.nodeImportArgs && parsed.import ? [parsed.import].flat() : [];
49
53
  const resolvedFromArgs = typeof pluginArgs.fromArgs === 'function'
50
- ? fromArgs(pluginArgs.fromArgs(parsed, args))
54
+ ? fromArgs(toWordArgs(pluginArgs.fromArgs(parsed, args), words))
51
55
  : Array.isArray(pluginArgs.fromArgs)
52
56
  ? fromArgs(pluginArgs.fromArgs.flatMap(mapToParsedKey).filter(Boolean))
53
57
  : [];
@@ -51,20 +51,20 @@ const commands = new Set([
51
51
  'why',
52
52
  'x',
53
53
  ]);
54
- export const resolve = (_binary, args, options) => {
54
+ export const resolve = (_binary, words, options) => {
55
55
  const binary = toBinary(_binary);
56
- const parsed = parseArgs(args, { string: ['cwd'] });
56
+ const parsed = parseArgs(words, { string: ['cwd'] });
57
57
  const [command, script] = parsed._;
58
58
  if (command === 'x') {
59
- const argsForX = args.filter(arg => arg !== 'x');
60
- return [binary, ...resolveX(argsForX, options)];
59
+ const wordsForX = words.filter(word => word.value !== 'x');
60
+ return [binary, ...resolveX(wordsForX, options)];
61
61
  }
62
62
  const { manifest, cwd, fromArgs } = options;
63
63
  if (command === 'run' && manifest.scriptNames.has(script)) {
64
- return [binary, ...(expandScript(script, argsAfter(args, script), manifest.scripts, options) ?? [])];
64
+ return [binary, ...(expandScript(script, argsAfter(words, script), manifest.scripts, options) ?? [])];
65
65
  }
66
66
  if (manifest.scriptNames.has(command)) {
67
- return [binary, ...(expandScript(command, argsAfter(args, command), manifest.scripts, options) ?? [])];
67
+ return [binary, ...(expandScript(command, argsAfter(words, command), manifest.scripts, options) ?? [])];
68
68
  }
69
69
  if (command !== 'run' && commands.has(command))
70
70
  return [binary];
@@ -78,7 +78,7 @@ export const resolve = (_binary, args, options) => {
78
78
  const dir = parsed.cwd ? join(cwd, parsed.cwd) : undefined;
79
79
  const opts = dir ? { cwd: dir } : {};
80
80
  if (command !== 'run')
81
- return [binary, ...fromArgs(args, opts)];
81
+ return [binary, ...fromArgs(words, opts)];
82
82
  const input = toBinary(filePath, { optional: true });
83
83
  if (dir)
84
84
  input.dir = dir;
@@ -1,3 +1,4 @@
1
+ import type { Word } from 'unbash';
1
2
  import type { BinaryResolver, BinaryResolverOptions } from '../../types/config.ts';
2
- export declare const resolveX: (args: string[], options: BinaryResolverOptions) => import("../../util/input.ts").Input[];
3
+ export declare const resolveX: (words: Word[], options: BinaryResolverOptions) => import("../../util/input.ts").Input[];
3
4
  export declare const resolve: BinaryResolver;
@@ -3,19 +3,23 @@ import { toBinary, toDependency } from '../../util/input.js';
3
3
  import { stripVersionFromSpecifier } from '../../util/modules.js';
4
4
  import { isInternal } from '../../util/path.js';
5
5
  import { argsFrom } from '../util.js';
6
- export const resolveX = (args, options) => {
6
+ export const resolveX = (words, options) => {
7
7
  const { fromArgs } = options;
8
- const parsed = parseArgs(args, { boolean: ['bun'] });
8
+ const parsed = parseArgs(words, { boolean: ['bun'] });
9
9
  const packageSpecifier = parsed._[0];
10
10
  const specifier = packageSpecifier ? stripVersionFromSpecifier(packageSpecifier) : '';
11
11
  const packages = parsed.package && !parsed.yes ? [parsed.package].flat().map(stripVersionFromSpecifier) : [];
12
12
  const command = parsed['shell-mode'] ? fromArgs([parsed['shell-mode']]) : [];
13
- const restArgs = argsFrom(args, packageSpecifier);
14
13
  const isBinary = specifier && !packageSpecifier.includes('@') && !isInternal(specifier);
15
14
  const dependency = isBinary ? toBinary(specifier, { optional: true }) : toDependency(specifier, { optional: true });
16
15
  const specifiers = specifier ? [dependency] : [];
17
- return [...specifiers, ...packages.map(id => toDependency(id)), ...command, ...fromArgs(restArgs).slice(1)];
16
+ return [
17
+ ...specifiers,
18
+ ...packages.map(id => toDependency(id)),
19
+ ...command,
20
+ ...fromArgs(argsFrom(words, packageSpecifier)).slice(1),
21
+ ];
18
22
  };
19
- export const resolve = (_binary, args, options) => {
20
- return resolveX(args, options);
23
+ export const resolve = (_binary, words, options) => {
24
+ return resolveX(words, options);
21
25
  };
@@ -1,16 +1,16 @@
1
1
  import { toBinary } from '../../util/input.js';
2
2
  const execFlags = new Set(['-exec', '-execdir']);
3
3
  const execTerminators = new Set([';', '\\;', '+']);
4
- export const resolve = (binary, args, { fromArgs }) => {
5
- const execIdx = args.findIndex(a => execFlags.has(a));
4
+ export const resolve = (binary, words, { fromArgs }) => {
5
+ const execIdx = words.findIndex(word => execFlags.has(word.value));
6
6
  if (execIdx >= 0) {
7
7
  const cmdWords = [];
8
- for (let i = execIdx + 1; i < args.length; i++) {
9
- const v = args[i];
8
+ for (let i = execIdx + 1; i < words.length; i++) {
9
+ const v = words[i].value;
10
10
  if (execTerminators.has(v))
11
11
  break;
12
12
  if (v !== '{}')
13
- cmdWords.push(v);
13
+ cmdWords.push(words[i]);
14
14
  }
15
15
  if (cmdWords.length > 0)
16
16
  return [toBinary(binary), ...fromArgs(cmdWords)];
@@ -1,14 +1,14 @@
1
1
  import parseArgs from '../../util/parse-args.js';
2
- import { expandScript } from '../util.js';
3
- export const resolve = (_binary, args, options) => {
2
+ import { argsAfter, expandScript } from '../util.js';
3
+ export const resolve = (_binary, words, options) => {
4
4
  const { fromArgs, manifest } = options;
5
- const parsed = parseArgs(args, { '--': true });
5
+ const parsed = parseArgs(words, { '--': true });
6
6
  const [command, script] = parsed._;
7
- const _childArgs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--'], { knownBinsOnly: true }) : [];
7
+ const _childArgs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(argsAfter(words, '--'), { knownBinsOnly: true }) : [];
8
8
  if (command === 'exec')
9
9
  return _childArgs;
10
10
  if (command === 'run' && manifest.scriptNames.has(script)) {
11
- return expandScript(script, parsed['--'] ?? [], manifest.scripts, options) ?? _childArgs;
11
+ return expandScript(script, argsAfter(words, '--'), manifest.scripts, options) ?? _childArgs;
12
12
  }
13
13
  return [];
14
14
  };
@@ -3,9 +3,9 @@ import { toBinary, toDependency } from '../../util/input.js';
3
3
  import { stripVersionFromSpecifier } from '../../util/modules.js';
4
4
  import { isInternal } from '../../util/path.js';
5
5
  import { argsFrom } from '../util.js';
6
- export const resolve = (_binary, args, options) => {
6
+ export const resolve = (_binary, words, options) => {
7
7
  const { fromArgs } = options;
8
- const parsed = parseArgs(args, {
8
+ const parsed = parseArgs(words, {
9
9
  boolean: ['yes', 'no', 'quiet'],
10
10
  alias: { yes: 'y', no: 'no-install', package: 'p', call: 'c' },
11
11
  });
@@ -13,7 +13,6 @@ export const resolve = (_binary, args, options) => {
13
13
  const specifier = packageSpecifier ? stripVersionFromSpecifier(packageSpecifier) : '';
14
14
  const packages = parsed.package && !parsed.yes ? [parsed.package].flat().map(stripVersionFromSpecifier) : [];
15
15
  const command = parsed.call ? fromArgs([parsed.call]) : [];
16
- const restArgs = argsFrom(args, packageSpecifier);
17
16
  const isBinary = specifier && !packageSpecifier.includes('@') && !isInternal(specifier);
18
17
  const opts = parsed.no ? undefined : { optional: true };
19
18
  const dependency = isBinary ? toBinary(specifier, opts) : toDependency(specifier, opts);
@@ -22,6 +21,6 @@ export const resolve = (_binary, args, options) => {
22
21
  ...specifiers,
23
22
  ...packages.map(id => toDependency(id, { optional: true })),
24
23
  ...command,
25
- ...fromArgs(restArgs).slice(1),
24
+ ...fromArgs(argsFrom(words, packageSpecifier)).slice(1),
26
25
  ];
27
26
  };
@@ -23,13 +23,13 @@ const commands = new Set([
23
23
  'update',
24
24
  'why',
25
25
  ]);
26
- export const resolve = (_binary, args, options) => {
26
+ export const resolve = (_binary, words, options) => {
27
27
  const binary = toBinary(_binary);
28
28
  const { manifest, cwd, fromArgs } = options;
29
- const parsed = parseArgs(args, { string: ['filter'], boolean: ['recursive'], alias: { recursive: 'r' } });
29
+ const parsed = parseArgs(words, { string: ['filter'], boolean: ['recursive'], alias: { recursive: 'r' } });
30
30
  const [command, script] = parsed._;
31
31
  if (runtimes.has(command)) {
32
- const rest = args.filter(arg => arg !== command);
32
+ const rest = words.filter(word => word.value !== command);
33
33
  return [binary, ...resolveX(rest, options)];
34
34
  }
35
35
  if (parsed.recursive || parsed.filter)
@@ -42,5 +42,5 @@ export const resolve = (_binary, args, options) => {
42
42
  }
43
43
  if (command && (commands.has(command) || manifest.scriptNames.has(command)))
44
44
  return [binary];
45
- return [binary, ...fromArgs(['node', ...args])];
45
+ return [binary, ...fromArgs(['node', ...words])];
46
46
  };
@@ -1,7 +1,7 @@
1
1
  import parseArgs from '../../util/parse-args.js';
2
2
  import { toBinary } from '../../util/input.js';
3
3
  import { isValidBinary } from '../../util/modules.js';
4
- import { argsAfter, expandScript } from '../util.js';
4
+ import { argsAfter, expandScript, toWordArgs } from '../util.js';
5
5
  import { resolveDlx } from './pnpx.js';
6
6
  const commands = [
7
7
  'add',
@@ -81,34 +81,37 @@ const commands = [
81
81
  'why',
82
82
  'with',
83
83
  ];
84
- export const resolve = (_binary, args, options) => {
85
- const parsed = parseArgs(args, {
84
+ export const resolve = (_binary, words, options) => {
85
+ const parsed = parseArgs(words, {
86
86
  boolean: ['aggregate-output', 'if-present', 'parallel', 'recursive', 'reverse', 'shell-mode', 'silent', 'stream'],
87
87
  alias: { recursive: 'r', silent: 's', 'shell-mode': 'c', filter: 'F' },
88
88
  '--': true,
89
89
  });
90
90
  const [command] = parsed._;
91
91
  if (command === 'dlx') {
92
- const argsForDlx = args.filter(arg => arg !== 'dlx');
93
- return resolveDlx(argsForDlx, options);
92
+ const wordsForDlx = words.filter(word => word.value !== 'dlx');
93
+ return resolveDlx(wordsForDlx, options);
94
94
  }
95
95
  const { manifest, fromArgs } = options;
96
96
  if (parsed.filter && !parsed.recursive)
97
97
  return [];
98
- const childInputs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--'], { knownBinsOnly: true }) : [];
98
+ const childInputs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(argsAfter(words, '--'), { knownBinsOnly: true }) : [];
99
99
  if (command === 'exec') {
100
- return childInputs.length > 0 ? childInputs : fromArgs(parsed._.slice(1));
100
+ if (childInputs.length > 0)
101
+ return childInputs;
102
+ const rest = parsed._.slice(1);
103
+ return rest.length === 1 ? fromArgs(rest.map(String)) : fromArgs(toWordArgs(rest, words));
101
104
  }
102
105
  if (command === 'run') {
103
106
  const script = parsed._[1];
104
107
  if (script && manifest.scriptNames.has(script)) {
105
- return expandScript(script, argsAfter(args, script), manifest.scripts, options) ?? childInputs;
108
+ return expandScript(script, argsAfter(words, script), manifest.scripts, options) ?? childInputs;
106
109
  }
107
110
  return childInputs;
108
111
  }
109
112
  const isScript = manifest.scriptNames.has(command);
110
113
  if (isScript)
111
- return expandScript(command, argsAfter(args, command), manifest.scripts, options) ?? childInputs;
114
+ return expandScript(command, argsAfter(words, command), manifest.scripts, options) ?? childInputs;
112
115
  if (commands.includes(command))
113
116
  return childInputs;
114
117
  return command && isValidBinary(command) ? [toBinary(command)] : [];
@@ -1,3 +1,4 @@
1
+ import type { Word } from 'unbash';
1
2
  import type { BinaryResolver, BinaryResolverOptions } from '../../types/config.ts';
2
- export declare const resolveDlx: (args: string[], options: BinaryResolverOptions) => import("../../util/input.ts").Input[];
3
+ export declare const resolveDlx: (words: Word[], options: BinaryResolverOptions) => import("../../util/input.ts").Input[];
3
4
  export declare const resolve: BinaryResolver;
@@ -7,8 +7,8 @@ const toDependencyInputs = (packageSpecifier) => {
7
7
  const reference = getCatalogReference(packageSpecifier);
8
8
  return reference ? [dependency, toCatalog(reference.packageName, reference.catalogName)] : [dependency];
9
9
  };
10
- export const resolveDlx = (args, options) => {
11
- const parsed = parseArgs(args, {
10
+ export const resolveDlx = (words, options) => {
11
+ const parsed = parseArgs(words, {
12
12
  boolean: ['silent'],
13
13
  alias: { package: 'p', 'shell-mode': 'c' },
14
14
  });
@@ -18,6 +18,6 @@ export const resolveDlx = (args, options) => {
18
18
  const dependencyInputs = packageSpecifier ? toDependencyInputs(packageSpecifier) : [];
19
19
  return [...dependencyInputs, ...packages.flatMap(toDependencyInputs), ...command];
20
20
  };
21
- export const resolve = (_binary, args, options) => {
22
- return resolveDlx(args, options);
21
+ export const resolve = (_binary, words, options) => {
22
+ return resolveDlx(words, options);
23
23
  };
@@ -2,7 +2,7 @@ import parseArgs from '../../util/parse-args.js';
2
2
  import { isBinary, isDependency, toBinary, toDependency } from '../../util/input.js';
3
3
  import { stripVersionFromSpecifier } from '../../util/modules.js';
4
4
  import { join } from '../../util/path.js';
5
- import { argsAfter, argsFrom, expandScript } from '../util.js';
5
+ import { argsAfter, argsFrom, expandScript, toWordArgs } from '../util.js';
6
6
  const commands = [
7
7
  'add',
8
8
  'bin',
@@ -37,30 +37,30 @@ const commands = [
37
37
  'workspace',
38
38
  'workspaces',
39
39
  ];
40
- const resolveDlx = (args, options) => {
41
- const parsed = parseArgs(args, {
40
+ const resolveDlx = (words, options) => {
41
+ const parsed = parseArgs(words, {
42
42
  boolean: ['quiet'],
43
43
  alias: { package: 'p', quiet: 'q' },
44
44
  });
45
45
  const packageSpecifier = parsed._[0];
46
46
  const specifier = packageSpecifier ? stripVersionFromSpecifier(packageSpecifier) : '';
47
47
  const packages = parsed.package && !parsed.yes ? [parsed.package].flat().map(stripVersionFromSpecifier) : [];
48
- const command = specifier ? options.fromArgs(parsed._) : [];
48
+ const command = specifier ? options.fromArgs(toWordArgs(parsed._, words)) : [];
49
49
  return [...packages.map(id => toDependency(id)), ...command].map(id => isDependency(id) || isBinary(id) ? Object.assign(id, { optional: true }) : id);
50
50
  };
51
- export const resolve = (_binary, args, options) => {
51
+ export const resolve = (_binary, words, options) => {
52
52
  const { manifest, fromArgs, cwd, rootCwd, getManifest } = options;
53
- const parsed = parseArgs(args, { boolean: ['top-level'], string: ['cwd'], '--': true });
53
+ const parsed = parseArgs(words, { boolean: ['top-level'], string: ['cwd'], '--': true });
54
54
  const dir = parsed['top-level'] ? rootCwd : parsed.cwd ? join(cwd, parsed.cwd) : undefined;
55
55
  const [command, binary] = parsed._;
56
56
  if (!command && !binary)
57
57
  return [];
58
58
  const dirManifest = (dir && getManifest(dir)) || manifest;
59
- const _childArgs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--'], { knownBinsOnly: true }) : [];
59
+ const _childArgs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(argsAfter(words, '--'), { knownBinsOnly: true }) : [];
60
60
  if (command === 'run') {
61
61
  if (dirManifest.scriptNames.has(binary)) {
62
62
  const opts = dir ? { cwd: dir, manifest: dirManifest } : {};
63
- return expandScript(binary, argsAfter(args, binary), dirManifest.scripts, options, opts) ?? _childArgs;
63
+ return expandScript(binary, argsAfter(words, binary), dirManifest.scripts, options, opts) ?? _childArgs;
64
64
  }
65
65
  const bin = toBinary(binary, { optional: true });
66
66
  if (dir)
@@ -68,17 +68,21 @@ export const resolve = (_binary, args, options) => {
68
68
  return [bin, ..._childArgs];
69
69
  }
70
70
  if (command === 'node')
71
- return fromArgs(parsed._);
71
+ return fromArgs(toWordArgs(parsed._, words));
72
72
  if (command === 'dlx') {
73
- const argsForDlx = args.filter(arg => arg !== 'dlx');
74
- return resolveDlx(argsForDlx, options);
73
+ const wordsForDlx = words.filter(word => word.value !== 'dlx');
74
+ return resolveDlx(wordsForDlx, options);
75
75
  }
76
76
  if (dirManifest.scriptNames.has(command)) {
77
77
  const opts = dir ? { cwd: dir, manifest: dirManifest } : {};
78
- return expandScript(command, argsAfter(args, command), dirManifest.scripts, options, opts) ?? _childArgs;
78
+ return expandScript(command, argsAfter(words, command), dirManifest.scripts, options, opts) ?? _childArgs;
79
79
  }
80
80
  if (commands.includes(command))
81
81
  return _childArgs;
82
82
  const opts = dir ? { cwd: dir } : {};
83
- return fromArgs(argsFrom(args, command === 'exec' ? binary : command), opts);
83
+ if (command === 'exec') {
84
+ const rest = argsFrom(words, binary);
85
+ return rest.length === 1 ? fromArgs([rest[0].value], opts) : fromArgs(rest, opts);
86
+ }
87
+ return fromArgs(argsFrom(words, command), opts);
84
88
  };
@@ -1,6 +1,8 @@
1
- import type { BinaryResolverOptions, GetInputsFromScriptsOptions } from '../types/config.ts';
1
+ import type { Word } from 'unbash';
2
+ import type { BinaryResolverOptions, GetInputsFromScriptsOptions, ScriptArg } from '../types/config.ts';
2
3
  import type { Input } from '../util/input.ts';
3
- export declare const argsFrom: (args: string[], from: string) => string[];
4
- export declare const argsAfter: (args: string[], token: string) => string[];
5
- export declare const expandScript: (name: string, forwardedArgs: string[], scripts: Record<string, string> | undefined, options: BinaryResolverOptions, opts?: Partial<GetInputsFromScriptsOptions>) => Input[] | undefined;
4
+ export declare const argsFrom: <T extends string | Word>(args: readonly T[], from: string) => T[];
5
+ export declare const argsAfter: <T extends string | Word>(args: readonly T[], token: string) => T[];
6
+ export declare const toWordArgs: (values: (string | number)[], words: Word[]) => ScriptArg[];
7
+ export declare const expandScript: (name: string, forwardedArgs: ScriptArg[], scripts: Record<string, string> | undefined, options: BinaryResolverOptions, opts?: Partial<GetInputsFromScriptsOptions>) => Input[] | undefined;
6
8
  export declare const parseNodeArgs: (args: string[]) => import("../util/parse-args.ts").ParsedArgs;