knip 6.30.0 → 6.32.0
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/dist/ConfigurationChief.d.ts +24 -0
- package/dist/DependencyDeputy.d.ts +2 -1
- package/dist/DependencyDeputy.js +2 -2
- package/dist/binaries/bash-parser.js +20 -8
- package/dist/binaries/fallback.js +6 -4
- package/dist/binaries/plugins.js +8 -4
- package/dist/binaries/resolvers/bun.js +7 -7
- package/dist/binaries/resolvers/bunx.d.ts +2 -1
- package/dist/binaries/resolvers/bunx.js +10 -6
- package/dist/binaries/resolvers/find.js +5 -5
- package/dist/binaries/resolvers/npm.js +5 -5
- package/dist/binaries/resolvers/npx.js +3 -4
- package/dist/binaries/resolvers/nub.js +4 -4
- package/dist/binaries/resolvers/pnpm.js +12 -9
- package/dist/binaries/resolvers/pnpx.d.ts +2 -1
- package/dist/binaries/resolvers/pnpx.js +4 -4
- package/dist/binaries/resolvers/yarn.js +17 -13
- package/dist/binaries/util.d.ts +6 -4
- package/dist/binaries/util.js +25 -3
- package/dist/compilers/index.d.ts +40 -0
- package/dist/graph/analyze.js +1 -0
- package/dist/graph/build.js +1 -0
- package/dist/plugins/babel/types.d.ts +1 -0
- package/dist/plugins/borp/index.d.ts +3 -0
- package/dist/plugins/borp/index.js +61 -0
- package/dist/plugins/borp/types.d.ts +4 -0
- package/dist/plugins/borp/types.js +1 -0
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/index.js +8 -0
- package/dist/plugins/jest/index.js +6 -2
- package/dist/plugins/marko/compiler.d.ts +2 -0
- package/dist/plugins/marko/compiler.js +85 -0
- package/dist/plugins/marko/index.d.ts +3 -0
- package/dist/plugins/marko/index.js +63 -0
- package/dist/plugins/marko/taglibs.d.ts +4 -0
- package/dist/plugins/marko/taglibs.js +111 -0
- package/dist/plugins/marko/types.d.ts +9 -0
- package/dist/plugins/marko/types.js +1 -0
- package/dist/plugins/mocha/index.js +59 -0
- package/dist/plugins/playwright/index.js +1 -1
- package/dist/plugins/pre-commit/index.d.ts +3 -0
- package/dist/plugins/pre-commit/index.js +23 -0
- package/dist/plugins/rollup/index.js +5 -1
- package/dist/plugins/tsd/index.d.ts +3 -0
- package/dist/plugins/tsd/index.js +43 -0
- package/dist/plugins/tsd/types.d.ts +4 -0
- package/dist/plugins/tsd/types.js +1 -0
- package/dist/schema/configuration.d.ts +60 -0
- package/dist/schema/plugins.d.ts +20 -0
- package/dist/schema/plugins.js +4 -0
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +4 -0
- package/dist/types/config.d.ts +4 -2
- package/dist/util/create-input-handler.js +2 -0
- package/dist/util/create-options.d.ts +40 -0
- package/dist/util/package-json.d.ts +4 -0
- package/dist/util/package-json.js +6 -2
- package/dist/util/parse-args.d.ts +2 -1
- package/dist/util/parse-args.js +8 -1
- package/dist/util/scripts.js +9 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/schema.json +16 -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;
|
|
@@ -352,6 +357,11 @@ export declare class ConfigurationChief {
|
|
|
352
357
|
entry?: string | string[] | undefined;
|
|
353
358
|
project?: string | string[] | undefined;
|
|
354
359
|
} | undefined;
|
|
360
|
+
marko?: string | boolean | string[] | {
|
|
361
|
+
config?: string | string[] | undefined;
|
|
362
|
+
entry?: string | string[] | undefined;
|
|
363
|
+
project?: string | string[] | undefined;
|
|
364
|
+
} | undefined;
|
|
355
365
|
mdx?: string | boolean | string[] | {
|
|
356
366
|
config?: string | string[] | undefined;
|
|
357
367
|
entry?: string | string[] | undefined;
|
|
@@ -547,6 +557,11 @@ export declare class ConfigurationChief {
|
|
|
547
557
|
entry?: string | string[] | undefined;
|
|
548
558
|
project?: string | string[] | undefined;
|
|
549
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;
|
|
550
565
|
preconstruct?: string | boolean | string[] | {
|
|
551
566
|
config?: string | string[] | undefined;
|
|
552
567
|
entry?: string | string[] | undefined;
|
|
@@ -777,6 +792,11 @@ export declare class ConfigurationChief {
|
|
|
777
792
|
entry?: string | string[] | undefined;
|
|
778
793
|
project?: string | string[] | undefined;
|
|
779
794
|
} | undefined;
|
|
795
|
+
tsd?: string | boolean | string[] | {
|
|
796
|
+
config?: string | string[] | undefined;
|
|
797
|
+
entry?: string | string[] | undefined;
|
|
798
|
+
project?: string | string[] | undefined;
|
|
799
|
+
} | undefined;
|
|
780
800
|
tsdown?: string | boolean | string[] | {
|
|
781
801
|
config?: string | string[] | undefined;
|
|
782
802
|
entry?: string | string[] | undefined;
|
|
@@ -982,6 +1002,7 @@ export declare class ConfigurationChief {
|
|
|
982
1002
|
ava?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
983
1003
|
babel?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
984
1004
|
biome?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1005
|
+
borp?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
985
1006
|
bumpp?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
986
1007
|
bun?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
987
1008
|
c8?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
@@ -1033,6 +1054,7 @@ export declare class ConfigurationChief {
|
|
|
1033
1054
|
"lost-pixel"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1034
1055
|
lunaria?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1035
1056
|
markdownlint?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1057
|
+
marko?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1036
1058
|
mdx?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1037
1059
|
mdxlint?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1038
1060
|
metro?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
@@ -1072,6 +1094,7 @@ export declare class ConfigurationChief {
|
|
|
1072
1094
|
pm2?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1073
1095
|
pnpm?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1074
1096
|
postcss?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1097
|
+
"pre-commit"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1075
1098
|
preconstruct?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1076
1099
|
prettier?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1077
1100
|
prisma?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
@@ -1118,6 +1141,7 @@ export declare class ConfigurationChief {
|
|
|
1118
1141
|
temporal?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1119
1142
|
travis?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1120
1143
|
"ts-node"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1144
|
+
tsd?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1121
1145
|
tsdown?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1122
1146
|
tsup?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
|
|
1123
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 }
|
|
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(): {
|
package/dist/DependencyDeputy.js
CHANGED
|
@@ -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 (
|
|
128
|
+
if (specifier.startsWith('node:') || isBuiltin(specifier))
|
|
129
129
|
return true;
|
|
130
130
|
if (IGNORED_RUNTIME_DEPENDENCIES.has(packageName))
|
|
131
131
|
return true;
|
|
@@ -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
|
|
33
|
+
if (args.length === 0)
|
|
34
34
|
return [];
|
|
35
|
-
|
|
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
|
|
86
|
+
const words = node.suffix;
|
|
75
87
|
if (binary === '!' || binary === 'test')
|
|
76
|
-
return fromArgs(
|
|
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,
|
|
98
|
+
return resolver(binary, words, { ...options, fromArgs });
|
|
87
99
|
}
|
|
88
100
|
if (pluginArgsMap.has(binary)) {
|
|
89
|
-
return [...resolverFromPlugins(binary,
|
|
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,
|
|
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,
|
|
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,
|
|
9
|
-
const parsed = parseArgs(
|
|
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(
|
|
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
|
};
|
package/dist/binaries/plugins.js
CHANGED
|
@@ -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,
|
|
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,
|
|
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
|
|
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,
|
|
54
|
+
export const resolve = (_binary, words, options) => {
|
|
55
55
|
const binary = toBinary(_binary);
|
|
56
|
-
const parsed = parseArgs(
|
|
56
|
+
const parsed = parseArgs(words, { string: ['cwd'] });
|
|
57
57
|
const [command, script] = parsed._;
|
|
58
58
|
if (command === 'x') {
|
|
59
|
-
const
|
|
60
|
-
return [binary, ...resolveX(
|
|
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(
|
|
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(
|
|
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(
|
|
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: (
|
|
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 = (
|
|
6
|
+
export const resolveX = (words, options) => {
|
|
7
7
|
const { fromArgs } = options;
|
|
8
|
-
const parsed = parseArgs(
|
|
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 [
|
|
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,
|
|
20
|
-
return resolveX(
|
|
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,
|
|
5
|
-
const execIdx =
|
|
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 <
|
|
9
|
-
const v =
|
|
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(
|
|
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,
|
|
2
|
+
import { argsAfter, expandScript } from '../util.js';
|
|
3
|
+
export const resolve = (_binary, words, options) => {
|
|
4
4
|
const { fromArgs, manifest } = options;
|
|
5
|
-
const parsed = parseArgs(
|
|
5
|
+
const parsed = parseArgs(words, { '--': true });
|
|
6
6
|
const [command, script] = parsed._;
|
|
7
|
-
const _childArgs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(
|
|
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,
|
|
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,
|
|
6
|
+
export const resolve = (_binary, words, options) => {
|
|
7
7
|
const { fromArgs } = options;
|
|
8
|
-
const parsed = parseArgs(
|
|
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(
|
|
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,
|
|
26
|
+
export const resolve = (_binary, words, options) => {
|
|
27
27
|
const binary = toBinary(_binary);
|
|
28
28
|
const { manifest, cwd, fromArgs } = options;
|
|
29
|
-
const parsed = parseArgs(
|
|
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 =
|
|
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', ...
|
|
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,
|
|
85
|
-
const parsed = parseArgs(
|
|
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
|
|
93
|
-
return resolveDlx(
|
|
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(
|
|
98
|
+
const childInputs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(argsAfter(words, '--'), { knownBinsOnly: true }) : [];
|
|
99
99
|
if (command === 'exec') {
|
|
100
|
-
|
|
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(
|
|
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(
|
|
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: (
|
|
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 = (
|
|
11
|
-
const parsed = parseArgs(
|
|
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,
|
|
22
|
-
return resolveDlx(
|
|
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 = (
|
|
41
|
-
const parsed = parseArgs(
|
|
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,
|
|
51
|
+
export const resolve = (_binary, words, options) => {
|
|
52
52
|
const { manifest, fromArgs, cwd, rootCwd, getManifest } = options;
|
|
53
|
-
const parsed = parseArgs(
|
|
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(
|
|
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(
|
|
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
|
|
74
|
-
return resolveDlx(
|
|
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(
|
|
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
|
-
|
|
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
|
};
|
package/dist/binaries/util.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type {
|
|
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:
|
|
4
|
-
export declare const argsAfter: (args:
|
|
5
|
-
export declare const
|
|
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;
|
package/dist/binaries/util.js
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
import parseArgs from '../util/parse-args.js';
|
|
2
|
-
|
|
2
|
+
const valueOf = (arg) => (typeof arg === 'string' ? arg : arg.value);
|
|
3
|
+
export const argsFrom = (args, from) => args.slice(args.findIndex(arg => valueOf(arg) === from));
|
|
3
4
|
export const argsAfter = (args, token) => {
|
|
4
|
-
const index = args.
|
|
5
|
-
return index === -1 ? [] : args.slice(index + 1).filter(arg => arg !== '--');
|
|
5
|
+
const index = args.findIndex(arg => valueOf(arg) === token);
|
|
6
|
+
return index === -1 ? [] : args.slice(index + 1).filter(arg => valueOf(arg) !== '--');
|
|
7
|
+
};
|
|
8
|
+
export const toWordArgs = (values, words) => {
|
|
9
|
+
const args = [];
|
|
10
|
+
let cursor = 0;
|
|
11
|
+
for (const value of values) {
|
|
12
|
+
const str = String(value);
|
|
13
|
+
let match = -1;
|
|
14
|
+
for (let index = cursor; index < words.length; index++) {
|
|
15
|
+
if (words[index].value === str) {
|
|
16
|
+
match = index;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (match === -1)
|
|
21
|
+
args.push(str);
|
|
22
|
+
else {
|
|
23
|
+
args.push(words[match]);
|
|
24
|
+
cursor = match + 1;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return args;
|
|
6
28
|
};
|
|
7
29
|
export const expandScript = (name, forwardedArgs, scripts, options, opts = {}) => {
|
|
8
30
|
const source = scripts?.[name];
|