knip 6.23.0 → 6.25.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.
Files changed (128) hide show
  1. package/LICENSE +1 -1
  2. package/dist/ConfigurationChief.d.ts +13 -1
  3. package/dist/ConfigurationChief.js +3 -0
  4. package/dist/ProjectPrincipal.d.ts +2 -0
  5. package/dist/ProjectPrincipal.js +7 -6
  6. package/dist/WorkspaceWorker.d.ts +3 -1
  7. package/dist/WorkspaceWorker.js +5 -2
  8. package/dist/binaries/bash-parser.js +55 -83
  9. package/dist/binaries/index.js +3 -0
  10. package/dist/binaries/resolvers/yarn.js +4 -3
  11. package/dist/compilers/compilers.d.ts +2 -0
  12. package/dist/compilers/compilers.js +15 -4
  13. package/dist/compilers/index.d.ts +30 -6
  14. package/dist/compilers/index.js +25 -10
  15. package/dist/compilers/less.d.ts +7 -0
  16. package/dist/compilers/less.js +37 -0
  17. package/dist/compilers/mdx.d.ts +1 -2
  18. package/dist/compilers/mdx.js +14 -8
  19. package/dist/compilers/scss.d.ts +3 -2
  20. package/dist/compilers/scss.js +17 -14
  21. package/dist/compilers/shared.d.ts +6 -0
  22. package/dist/compilers/shared.js +9 -0
  23. package/dist/compilers/style-preprocessors.d.ts +2 -0
  24. package/dist/compilers/style-preprocessors.js +41 -0
  25. package/dist/compilers/stylus.d.ts +7 -0
  26. package/dist/compilers/stylus.js +36 -0
  27. package/dist/constants.d.ts +5 -1
  28. package/dist/constants.js +7 -0
  29. package/dist/graph/analyze.js +37 -2
  30. package/dist/graph/build.js +23 -1
  31. package/dist/graph-explorer/explorer.d.ts +1 -0
  32. package/dist/graph-explorer/explorer.js +2 -0
  33. package/dist/graph-explorer/operations/find-all-cycles.d.ts +3 -0
  34. package/dist/graph-explorer/operations/find-all-cycles.js +43 -0
  35. package/dist/graph-explorer/operations/find-cycles.js +3 -9
  36. package/dist/graph-explorer/utils.d.ts +10 -1
  37. package/dist/graph-explorer/utils.js +53 -0
  38. package/dist/plugins/astro/compiler-mdx.js +11 -2
  39. package/dist/plugins/astro/compiler.js +8 -4
  40. package/dist/plugins/bun/index.js +28 -14
  41. package/dist/plugins/eve/index.d.ts +3 -0
  42. package/dist/plugins/eve/index.js +22 -0
  43. package/dist/plugins/execa/visitors/execa.js +10 -18
  44. package/dist/plugins/fumadocs/index.d.ts +3 -0
  45. package/dist/plugins/fumadocs/index.js +18 -0
  46. package/dist/plugins/github-actions/index.js +3 -2
  47. package/dist/plugins/graphql-codegen/index.js +9 -7
  48. package/dist/plugins/index.d.ts +2 -0
  49. package/dist/plugins/index.js +4 -0
  50. package/dist/plugins/jest/index.js +13 -3
  51. package/dist/plugins/next/index.js +23 -10
  52. package/dist/plugins/node/index.js +4 -1
  53. package/dist/plugins/nuxt/index.js +4 -2
  54. package/dist/plugins/pnpm/index.js +21 -1
  55. package/dist/plugins/pnpm/types.d.ts +6 -0
  56. package/dist/plugins/pnpm/types.js +1 -0
  57. package/dist/plugins/prettier/index.js +19 -3
  58. package/dist/plugins/prettier/types.d.ts +6 -1
  59. package/dist/plugins/prisma/compiler.js +3 -0
  60. package/dist/plugins/rspack/index.js +5 -0
  61. package/dist/plugins/serverless-framework/index.js +12 -1
  62. package/dist/plugins/serverless-framework/types.d.ts +5 -2
  63. package/dist/plugins/stencil/index.js +59 -1
  64. package/dist/plugins/storybook/index.js +7 -0
  65. package/dist/plugins/svelte/compiler.d.ts +2 -1
  66. package/dist/plugins/svelte/compiler.js +8 -1
  67. package/dist/plugins/tailwind/compiler.js +3 -0
  68. package/dist/plugins/tailwind/index.js +5 -1
  69. package/dist/plugins/typedoc/index.js +9 -3
  70. package/dist/plugins/typedoc/types.d.ts +2 -0
  71. package/dist/plugins/vite/visitors/importMetaGlob.js +1 -8
  72. package/dist/plugins/vue/compiler.d.ts +2 -1
  73. package/dist/plugins/vue/compiler.js +8 -1
  74. package/dist/plugins/webpack/visitors/requireContext.js +2 -13
  75. package/dist/plugins/yarn/index.js +13 -4
  76. package/dist/plugins/yarn/types.d.ts +10 -0
  77. package/dist/plugins/yarn/types.js +1 -0
  78. package/dist/plugins/zx/visitors/zx.js +4 -4
  79. package/dist/reporters/compact.js +1 -2
  80. package/dist/reporters/cycles.d.ts +3 -0
  81. package/dist/reporters/cycles.js +79 -0
  82. package/dist/reporters/index.d.ts +1 -0
  83. package/dist/reporters/index.js +2 -0
  84. package/dist/reporters/json.d.ts +3 -0
  85. package/dist/reporters/json.js +2 -1
  86. package/dist/reporters/symbols.js +1 -2
  87. package/dist/reporters/util/util.d.ts +3 -1
  88. package/dist/reporters/util/util.js +5 -1
  89. package/dist/schema/configuration.d.ts +40 -6
  90. package/dist/schema/configuration.js +6 -0
  91. package/dist/schema/plugins.d.ts +10 -0
  92. package/dist/schema/plugins.js +2 -0
  93. package/dist/types/PluginNames.d.ts +2 -2
  94. package/dist/types/PluginNames.js +2 -0
  95. package/dist/types/config.d.ts +10 -0
  96. package/dist/types/issues.d.ts +3 -0
  97. package/dist/types/module-graph.d.ts +7 -0
  98. package/dist/types/package-json.d.ts +4 -1
  99. package/dist/types.d.ts +1 -1
  100. package/dist/typescript/SourceFileManager.js +3 -2
  101. package/dist/typescript/ast-nodes.d.ts +4 -1
  102. package/dist/typescript/ast-nodes.js +60 -2
  103. package/dist/typescript/comments.js +22 -3
  104. package/dist/typescript/get-imports-and-exports.js +10 -0
  105. package/dist/typescript/glob-imports.d.ts +3 -0
  106. package/dist/typescript/glob-imports.js +49 -0
  107. package/dist/typescript/resolve-module-names.d.ts +2 -0
  108. package/dist/typescript/resolve-module-names.js +35 -1
  109. package/dist/typescript/visitors/calls.js +4 -6
  110. package/dist/typescript/visitors/imports.js +8 -8
  111. package/dist/typescript/visitors/script-visitors.js +4 -4
  112. package/dist/typescript/visitors/walk.js +6 -1
  113. package/dist/util/cli-arguments.d.ts +2 -1
  114. package/dist/util/cli-arguments.js +4 -2
  115. package/dist/util/create-options.d.ts +32 -5
  116. package/dist/util/create-options.js +4 -1
  117. package/dist/util/get-included-issue-types.d.ts +1 -0
  118. package/dist/util/get-included-issue-types.js +4 -2
  119. package/dist/util/issue-initializers.js +1 -1
  120. package/dist/util/load-tsconfig.js +17 -4
  121. package/dist/util/module-graph.js +1 -0
  122. package/dist/util/modules.js +25 -4
  123. package/dist/util/scripts.d.ts +7 -0
  124. package/dist/util/scripts.js +75 -0
  125. package/dist/version.d.ts +1 -1
  126. package/dist/version.js +1 -1
  127. package/package.json +1 -1
  128. package/schema.json +40 -1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  ISC License (ISC)
2
2
 
3
- Copyright 2022-2025 Lars Kappert
3
+ Copyright 2022-2026 Lars Kappert
4
4
 
5
5
  Permission to use, copy, modify, and/or distribute this software for any purpose
6
6
  with or without fee is hereby granted, provided that the above copyright notice
@@ -207,6 +207,11 @@ export declare class ConfigurationChief {
207
207
  entry?: string | string[] | undefined;
208
208
  project?: string | string[] | undefined;
209
209
  } | undefined;
210
+ eve?: string | boolean | string[] | {
211
+ config?: string | string[] | undefined;
212
+ entry?: string | string[] | undefined;
213
+ project?: string | string[] | undefined;
214
+ } | undefined;
210
215
  execa?: string | boolean | string[] | {
211
216
  config?: string | string[] | undefined;
212
217
  entry?: string | string[] | undefined;
@@ -227,6 +232,11 @@ export declare class ConfigurationChief {
227
232
  entry?: string | string[] | undefined;
228
233
  project?: string | string[] | undefined;
229
234
  } | undefined;
235
+ fumadocs?: string | boolean | string[] | {
236
+ config?: string | string[] | undefined;
237
+ entry?: string | string[] | undefined;
238
+ project?: string | string[] | undefined;
239
+ } | undefined;
230
240
  gatsby?: string | boolean | string[] | {
231
241
  config?: string | string[] | undefined;
232
242
  entry?: string | string[] | undefined;
@@ -852,7 +862,7 @@ export declare class ConfigurationChief {
852
862
  ignoreMembers?: (string | RegExp)[] | undefined;
853
863
  ignoreUnresolved?: (string | RegExp)[] | undefined;
854
864
  ignoreExportsUsedInFile?: boolean | Record<string, boolean | undefined> | undefined;
855
- ignoreIssues?: Record<string, ("binaries" | "catalog" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[]> | undefined;
865
+ ignoreIssues?: Record<string, ("binaries" | "catalog" | "cycles" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[]> | undefined;
856
866
  includeEntryExports?: boolean | undefined;
857
867
  };
858
868
  getIgnores(workspaceName: string): {
@@ -899,10 +909,12 @@ export declare class ConfigurationChief {
899
909
  drizzle?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
900
910
  eleventy?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
901
911
  eslint?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
912
+ eve?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
902
913
  execa?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
903
914
  expo?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
904
915
  "expressive-code"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
905
916
  fast?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
917
+ fumadocs?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
906
918
  gatsby?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
907
919
  "github-action"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
908
920
  "github-actions"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -34,6 +34,7 @@ const defaultConfig = {
34
34
  ignoreBinaries: [],
35
35
  ignoreDependencies: [],
36
36
  ignoreFiles: [],
37
+ cycles: {},
37
38
  ignoreIssues: {},
38
39
  ignoreMembers: [],
39
40
  ignoreUnresolved: [],
@@ -103,6 +104,7 @@ export class ConfigurationChief {
103
104
  const ignoreMembers = rawConfig.ignoreMembers ?? [];
104
105
  const ignoreUnresolved = rawConfig.ignoreUnresolved ?? [];
105
106
  const ignoreExportsUsedInFile = rawConfig.ignoreExportsUsedInFile ?? false;
107
+ const cycles = rawConfig.cycles ?? {};
106
108
  const ignoreIssues = rawConfig.ignoreIssues ?? {};
107
109
  const ignoreWorkspaces = rawConfig.ignoreWorkspaces ?? defaultConfig.ignoreWorkspaces;
108
110
  const isIncludeEntryExports = rawConfig.includeEntryExports ?? this.isIncludeEntryExports;
@@ -116,6 +118,7 @@ export class ConfigurationChief {
116
118
  return {
117
119
  ignore,
118
120
  ignoreFiles,
121
+ cycles,
119
122
  ignoreBinaries,
120
123
  ignoreDependencies,
121
124
  ignoreMembers,
@@ -4,6 +4,7 @@ import type { AsyncCompilers, SyncCompilers } from './compilers/types.ts';
4
4
  import type { GetImportsAndExportsOptions, IgnoreExportsUsedInFile, PluginVisitorContext, PluginVisitorObject } from './types/config.ts';
5
5
  import type { FileNode, ModuleGraph } from './types/module-graph.ts';
6
6
  import type { Paths } from './types/project.ts';
7
+ import type { ResolveGlobPattern } from './typescript/resolve-module-names.ts';
7
8
  import { SourceFileManager } from './typescript/SourceFileManager.ts';
8
9
  import type { MainOptions } from './util/create-options.ts';
9
10
  import type { ToSourceFilePath, WorkspaceManifestHandler } from './util/to-source-path.ts';
@@ -27,6 +28,7 @@ export declare class ProjectPrincipal {
27
28
  private findWorkspaceManifestImports;
28
29
  fileManager: SourceFileManager;
29
30
  private resolveModule;
31
+ resolveGlobPattern: ResolveGlobPattern;
30
32
  resolvedFiles: Set<string>;
31
33
  deletedFiles: Set<string>;
32
34
  private onPathAdded;
@@ -6,7 +6,7 @@ import { DEFAULT_EXTENSIONS } from './constants.js';
6
6
  import { _getImportsAndExports } from './typescript/get-imports-and-exports.js';
7
7
  import { createBunShellVisitor } from './typescript/visitors/script-visitors.js';
8
8
  import { buildVisitor } from './typescript/visitors/walk.js';
9
- import { createCustomModuleResolver } from './typescript/resolve-module-names.js';
9
+ import { createCustomModuleResolver, createGlobAliasResolver } from './typescript/resolve-module-names.js';
10
10
  import { SourceFileManager } from './typescript/SourceFileManager.js';
11
11
  import { compact } from './util/array.js';
12
12
  import { timerify } from './util/Performance.js';
@@ -21,6 +21,7 @@ export class ProjectPrincipal {
21
21
  sourceText: '',
22
22
  addScript: () => { },
23
23
  addImport: () => { },
24
+ addImportGlob: () => { },
24
25
  markExportRegistered: () => { },
25
26
  };
26
27
  pluginVisitorObjects = [];
@@ -37,6 +38,7 @@ export class ProjectPrincipal {
37
38
  findWorkspaceManifestImports;
38
39
  fileManager;
39
40
  resolveModule = () => undefined;
41
+ resolveGlobPattern = pattern => [pattern];
40
42
  resolvedFiles = new Set();
41
43
  deletedFiles = new Set();
42
44
  onPathAdded;
@@ -90,6 +92,7 @@ export class ProjectPrincipal {
90
92
  const scopedPaths = this.paths.size > 0 ? Array.from(this.paths, ([scope, paths]) => ({ scope, paths })) : undefined;
91
93
  const scopedRootDirs = this.rootDirs.size > 0 ? Array.from(this.rootDirs, ([scope, rootDirs]) => ({ scope, rootDirs })) : undefined;
92
94
  this.resolveModule = createCustomModuleResolver({ scopedPaths, scopedRootDirs }, customCompilerExtensions, this.toSourceFilePath, this.findWorkspaceManifestImports, this.tsConfigFile);
95
+ this.resolveGlobPattern = createGlobAliasResolver(scopedPaths);
93
96
  }
94
97
  readFile(filePath) {
95
98
  return this.fileManager.readFile(filePath);
@@ -130,11 +133,9 @@ export class ProjectPrincipal {
130
133
  }
131
134
  async runAsyncCompilers() {
132
135
  const add = timerify(this.fileManager.compileAndAddSourceFile.bind(this.fileManager));
133
- const extensions = Array.from(this.asyncCompilers.keys());
134
- const files = Array.from(this.projectPaths).filter(filePath => extensions.includes(extname(filePath)));
135
- for (const filePath of files) {
136
- await add(filePath);
137
- }
136
+ for (const filePath of this.projectPaths)
137
+ if (this.asyncCompilers.has(extname(filePath)))
138
+ await add(filePath);
138
139
  }
139
140
  walkAndAnalyze(analyzeFile) {
140
141
  this.resolvedFiles.clear();
@@ -17,6 +17,7 @@ type WorkspaceManagerOptions = {
17
17
  rootManifest: Manifest | undefined;
18
18
  handleInput: HandleInput;
19
19
  findWorkspaceByFilePath: (filePath: string) => Workspace | undefined;
20
+ getManifest: (dir: string) => Manifest | undefined;
20
21
  readFile: (filePath: string) => string;
21
22
  negatedWorkspacePatterns: string[];
22
23
  ignoredWorkspacePatterns: string[];
@@ -38,6 +39,7 @@ export declare class WorkspaceWorker {
38
39
  dependencies: DependencySet;
39
40
  handleInput: HandleInput;
40
41
  findWorkspaceByFilePath: (filePath: string) => Workspace | undefined;
42
+ getManifest: (dir: string) => Manifest | undefined;
41
43
  readFile: (filePath: string) => string;
42
44
  negatedWorkspacePatterns: string[];
43
45
  ignoredWorkspacePatterns: string[];
@@ -47,7 +49,7 @@ export declare class WorkspaceWorker {
47
49
  enabledPluginsInAncestors: string[];
48
50
  cache: CacheConsultant<CacheItem>;
49
51
  configFilesMap: Map<string, Map<PluginName, Set<string>>>;
50
- constructor({ name, dir, config, manifest, dependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, findWorkspaceByFilePath, readFile, configFilesMap, options, }: WorkspaceManagerOptions);
52
+ constructor({ name, dir, config, manifest, dependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, findWorkspaceByFilePath, getManifest, readFile, configFilesMap, options, }: WorkspaceManagerOptions);
51
53
  init(): Promise<void>;
52
54
  private determineEnabledPlugins;
53
55
  private getConfigForPlugin;
@@ -32,6 +32,7 @@ export class WorkspaceWorker {
32
32
  dependencies;
33
33
  handleInput;
34
34
  findWorkspaceByFilePath;
35
+ getManifest;
35
36
  readFile;
36
37
  negatedWorkspacePatterns = [];
37
38
  ignoredWorkspacePatterns = [];
@@ -41,7 +42,7 @@ export class WorkspaceWorker {
41
42
  enabledPluginsInAncestors;
42
43
  cache;
43
44
  configFilesMap;
44
- constructor({ name, dir, config, manifest, dependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, findWorkspaceByFilePath, readFile, configFilesMap, options, }) {
45
+ constructor({ name, dir, config, manifest, dependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, findWorkspaceByFilePath, getManifest, readFile, configFilesMap, options, }) {
45
46
  this.name = name;
46
47
  this.dir = dir;
47
48
  this.config = config;
@@ -54,6 +55,7 @@ export class WorkspaceWorker {
54
55
  this.configFilesMap = configFilesMap;
55
56
  this.handleInput = handleInput;
56
57
  this.findWorkspaceByFilePath = findWorkspaceByFilePath;
58
+ this.getManifest = getManifest;
57
59
  this.readFile = readFile;
58
60
  this.options = options;
59
61
  this.cache = new CacheConsultant(`plugins-${name}`, options);
@@ -211,7 +213,8 @@ export class WorkspaceWorker {
211
213
  const isProduction = this.options.isProduction;
212
214
  const knownBinsOnly = false;
213
215
  const rootManifest = this.rootManifest;
214
- const baseOptions = { manifest, rootManifest, cwd, rootCwd, containingFilePath, knownBinsOnly };
216
+ const getManifest = this.getManifest;
217
+ const baseOptions = { manifest, rootManifest, cwd, rootCwd, containingFilePath, knownBinsOnly, getManifest };
215
218
  const baseScriptOptions = { ...baseOptions, isProduction, enabledPlugins: this.enabledPlugins };
216
219
  const [productionScripts, developmentScripts] = getFilteredScripts(manifest.scripts ?? {});
217
220
  const inputsFromManifest = _getInputsFromScripts(Object.values(developmentScripts), baseOptions);
@@ -5,6 +5,7 @@ import { toBinary, toDeferResolve } from '../util/input.js';
5
5
  import { extractBinary, isValidBinary } from '../util/modules.js';
6
6
  import { relative } from '../util/path.js';
7
7
  import { truncate } from '../util/string.js';
8
+ import { walkCommands } from '../util/scripts.js';
8
9
  import { resolve as fallbackResolve } from './fallback.js';
9
10
  import KnownResolvers from './resolvers/index.js';
10
11
  import { resolve as resolverFromPlugins } from './plugins.js';
@@ -46,93 +47,64 @@ export const getDependenciesFromScript = (script, options) => {
46
47
  const processScript = (s) => {
47
48
  collectFunctionNames(s.commands);
48
49
  const pending = [];
49
- const mainDeps = getDependenciesFromStatements(s.commands, pending);
50
+ const mainDeps = [];
51
+ for (const statement of s.commands) {
52
+ for (const command of walkCommands(statement.command))
53
+ mainDeps.push(...processCommand(command, pending));
54
+ }
50
55
  const expansionDeps = pending.flatMap(inner => processScript(inner));
51
56
  return [...mainDeps, ...expansionDeps];
52
57
  };
53
- const getDependenciesFromStatements = (statements, pending) => statements.flatMap(stmt => getDependenciesFromNode(stmt.command, pending));
54
- const getDependenciesFromNode = (node, pending) => {
55
- switch (node.type) {
56
- case 'Command': {
57
- const text = node.name?.value;
58
- const binary = text ? extractBinary(text) : text;
59
- if (node.name)
60
- collectExpansionScripts(node.name, pending);
61
- for (const prefix of node.prefix)
62
- if (prefix.value)
63
- collectExpansionScripts(prefix.value, pending);
64
- for (const suffix of node.suffix)
65
- collectExpansionScripts(suffix, pending);
66
- if (!binary || binary === '.' || binary === 'source' || binary === '[')
67
- return [];
68
- if (binary.startsWith('-') || binary.startsWith('..'))
69
- return [];
70
- if (definedFunctions.has(binary))
71
- return [];
72
- const args = node.suffix.map(w => w.value);
73
- if (['!', 'test'].includes(binary))
74
- return fromArgs(args);
75
- const fromNodeOptions = node.prefix
76
- .filter(a => a.name === 'NODE_OPTIONS' && a.value)
77
- .map(a => a.value.value)
78
- .map(arg => parseNodeArgs(arg.split(' ')))
79
- .filter(args => args.require)
80
- .flatMap(arg => arg.require)
81
- .map(id => toDeferResolve(id));
82
- if (binary in KnownResolvers) {
83
- const resolver = KnownResolvers[binary];
84
- return resolver(binary, args, { ...options, fromArgs });
85
- }
86
- if (pluginArgsMap.has(binary)) {
87
- return [...resolverFromPlugins(binary, args, { ...options, fromArgs }), ...fromNodeOptions];
88
- }
89
- if (spawningBinaries.includes(binary)) {
90
- const rest = node.suffix
91
- .filter(w => w.text !== '--')
92
- .map(w => w.text)
93
- .join(' ');
94
- return [toBinary(binary), ...getDependenciesFromScript(rest, options)];
95
- }
96
- if (binary in Plugins) {
97
- const inputs = fallbackResolve(binary, args, { ...options, fromArgs });
98
- if (options.knownBinsOnly)
99
- for (const input of inputs)
100
- input.optional = true;
101
- return [...inputs, ...fromNodeOptions];
102
- }
103
- if (options.knownBinsOnly && !text?.startsWith('.'))
104
- return [];
105
- return [...fallbackResolve(binary, args, { ...options, fromArgs }), ...fromNodeOptions];
106
- }
107
- case 'AndOr':
108
- case 'Pipeline':
109
- return node.commands.flatMap(n => getDependenciesFromNode(n, pending));
110
- case 'If':
111
- return [
112
- ...getDependenciesFromStatements(node.clause.commands, pending),
113
- ...getDependenciesFromStatements(node.then.commands, pending),
114
- ...(node.else ? getDependenciesFromNode(node.else, pending) : []),
115
- ];
116
- case 'While':
117
- return [
118
- ...getDependenciesFromStatements(node.clause.commands, pending),
119
- ...getDependenciesFromStatements(node.body.commands, pending),
120
- ];
121
- case 'For':
122
- case 'Select':
123
- case 'Subshell':
124
- case 'BraceGroup':
125
- return getDependenciesFromStatements(node.body.commands, pending);
126
- case 'CompoundList':
127
- return getDependenciesFromStatements(node.commands, pending);
128
- case 'Function':
129
- case 'Coproc':
130
- return getDependenciesFromNode(node.body, pending);
131
- case 'Statement':
132
- return getDependenciesFromNode(node.command, pending);
133
- default:
134
- return [];
58
+ const processCommand = (node, pending) => {
59
+ const text = node.name?.value;
60
+ const binary = text ? extractBinary(text) : text;
61
+ if (node.name)
62
+ collectExpansionScripts(node.name, pending);
63
+ for (const prefix of node.prefix)
64
+ if (prefix.value)
65
+ collectExpansionScripts(prefix.value, pending);
66
+ for (const suffix of node.suffix)
67
+ collectExpansionScripts(suffix, pending);
68
+ if (!binary || binary === '.' || binary === 'source' || binary === '[')
69
+ return [];
70
+ if (binary.startsWith('-') || binary.startsWith('..'))
71
+ return [];
72
+ if (definedFunctions.has(binary))
73
+ return [];
74
+ const args = node.suffix.map(w => w.value);
75
+ if (['!', 'test'].includes(binary))
76
+ return fromArgs(args);
77
+ const fromNodeOptions = node.prefix
78
+ .filter(a => a.name === 'NODE_OPTIONS' && a.value)
79
+ .map(a => a.value.value)
80
+ .map(arg => parseNodeArgs(arg.split(' ')))
81
+ .filter(args => args.require)
82
+ .flatMap(arg => arg.require)
83
+ .map(id => toDeferResolve(id));
84
+ if (binary in KnownResolvers) {
85
+ const resolver = KnownResolvers[binary];
86
+ return resolver(binary, args, { ...options, fromArgs });
135
87
  }
88
+ if (pluginArgsMap.has(binary)) {
89
+ return [...resolverFromPlugins(binary, args, { ...options, fromArgs }), ...fromNodeOptions];
90
+ }
91
+ if (spawningBinaries.includes(binary)) {
92
+ const rest = node.suffix
93
+ .filter(w => w.text !== '--')
94
+ .map(w => w.text)
95
+ .join(' ');
96
+ return [toBinary(binary), ...getDependenciesFromScript(rest, options)];
97
+ }
98
+ if (binary in Plugins) {
99
+ const inputs = fallbackResolve(binary, args, { ...options, fromArgs });
100
+ if (options.knownBinsOnly)
101
+ for (const input of inputs)
102
+ input.optional = true;
103
+ return [...inputs, ...fromNodeOptions];
104
+ }
105
+ if (options.knownBinsOnly && !text?.startsWith('.'))
106
+ return [];
107
+ return [...fallbackResolve(binary, args, { ...options, fromArgs }), ...fromNodeOptions];
136
108
  };
137
109
  try {
138
110
  const parsed = parse(script);
@@ -1,3 +1,4 @@
1
+ import { SCRIPT_INTERPOLATION } from '../constants.js';
1
2
  import { fromBinary, isBinary, isDependency } from '../util/input.js';
2
3
  import { timerify } from '../util/Performance.js';
3
4
  import { getDependenciesFromScript } from './bash-parser.js';
@@ -8,6 +9,8 @@ const getInputsFromScripts = (npmScripts, options) => {
8
9
  for (const input of results) {
9
10
  if (!input.specifier)
10
11
  continue;
12
+ if (input.specifier.includes(SCRIPT_INTERPOLATION))
13
+ continue;
11
14
  if (isDependency(input) && input.specifier.startsWith('http'))
12
15
  continue;
13
16
  if (isBinary(input) && !/^\b/.test(fromBinary(input)))
@@ -49,15 +49,16 @@ const resolveDlx = (args, options) => {
49
49
  return [...packages.map(id => toDependency(id)), ...command].map(id => isDependency(id) || isBinary(id) ? Object.assign(id, { optional: true }) : id);
50
50
  };
51
51
  export const resolve = (_binary, args, options) => {
52
- const { manifest, fromArgs, cwd, rootCwd } = options;
52
+ const { manifest, fromArgs, cwd, rootCwd, getManifest } = options;
53
53
  const parsed = parseArgs(args, { 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
+ const dirManifest = (dir && getManifest(dir)) || manifest;
58
59
  const _childArgs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--'], { knownBinsOnly: true }) : [];
59
60
  if (command === 'run') {
60
- if (manifest.scriptNames.has(binary))
61
+ if (dirManifest.scriptNames.has(binary))
61
62
  return _childArgs;
62
63
  const bin = toBinary(binary, { optional: true });
63
64
  if (dir)
@@ -70,7 +71,7 @@ export const resolve = (_binary, args, options) => {
70
71
  const argsForDlx = args.filter(arg => arg !== 'dlx');
71
72
  return resolveDlx(argsForDlx, options);
72
73
  }
73
- if ((!dir && manifest.scriptNames.has(command)) || commands.includes(command))
74
+ if (dirManifest.scriptNames.has(command) || commands.includes(command))
74
75
  return _childArgs;
75
76
  const opts = dir ? { cwd: dir } : {};
76
77
  return fromArgs(argsFrom(args, command === 'exec' ? binary : command), opts);
@@ -2,10 +2,12 @@ import type { CompilerSync } from './types.ts';
2
2
  export declare const fencedCodeBlockMatcher: RegExp;
3
3
  export declare const inlineCodeMatcher: RegExp;
4
4
  export declare const scriptExtractor: RegExp;
5
+ export declare const styleExtractor: RegExp;
5
6
  export declare const blockCommentMatcher: RegExp;
6
7
  export declare const lineCommentMatcher: RegExp;
7
8
  export declare const importMatcher: RegExp;
8
9
  export declare const importsWithinScripts: CompilerSync;
9
10
  export declare const scriptBodies: CompilerSync;
11
+ export declare const getStyleLang: (attrs: string) => string | undefined;
10
12
  export declare const frontmatterMatcher: RegExp;
11
13
  export declare const importsWithinFrontmatter: (text: string, keys?: string[]) => string;
@@ -1,26 +1,37 @@
1
1
  export const fencedCodeBlockMatcher = /```[\s\S]*?```/g;
2
2
  export const inlineCodeMatcher = /`[^`]+`/g;
3
3
  export const scriptExtractor = /<script\b((?:[^>"']|"[^"]*"|'[^']*')*)>([\s\S]*?)<\/script>/gi;
4
+ export const styleExtractor = /<style\b((?:[^>"']|"[^"]*"|'[^']*')*)>([\s\S]*?)<\/style>/gi;
5
+ const langAttrMatcher = /\blang\s*=\s*["']([^"']+)["']/i;
4
6
  export const blockCommentMatcher = /\/\*[\s\S]*?\*\//g;
5
7
  export const lineCommentMatcher = /^[ \t]*\/\/.*$/gm;
6
8
  export const importMatcher = /import(?:\s*\(\s*['"][^'"]+['"][^)]*\)|(?!\s*\()[^'"]+['"][^'"]+['"])/g;
7
9
  export const importsWithinScripts = (text) => {
8
10
  const scripts = [];
9
- for (const [, , scriptBody] of text.matchAll(scriptExtractor)) {
11
+ scriptExtractor.lastIndex = 0;
12
+ let scriptMatch;
13
+ while ((scriptMatch = scriptExtractor.exec(text))) {
14
+ const scriptBody = scriptMatch[2];
10
15
  const body = scriptBody.replace(blockCommentMatcher, '').replace(lineCommentMatcher, '');
11
- for (const importMatch of body.matchAll(importMatcher))
12
- scripts.push(importMatch);
16
+ let importMatch;
17
+ importMatcher.lastIndex = 0;
18
+ while ((importMatch = importMatcher.exec(body)))
19
+ scripts.push(importMatch[0]);
13
20
  }
14
21
  return scripts.join(';\n');
15
22
  };
16
23
  export const scriptBodies = (text) => {
17
24
  const scripts = [];
18
- for (const [, , body] of text.matchAll(scriptExtractor)) {
25
+ scriptExtractor.lastIndex = 0;
26
+ let match;
27
+ while ((match = scriptExtractor.exec(text))) {
28
+ const body = match[2];
19
29
  if (body)
20
30
  scripts.push(body);
21
31
  }
22
32
  return scripts.join(';\n');
23
33
  };
34
+ export const getStyleLang = (attrs) => attrs.match(langAttrMatcher)?.[1]?.toLowerCase();
24
35
  export const frontmatterMatcher = /^---\r?\n([\s\S]*?)\r?\n---/;
25
36
  export const importsWithinFrontmatter = (text, keys = []) => {
26
37
  const frontmatter = text.match(frontmatterMatcher)?.[1];
@@ -153,6 +153,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
153
153
  entry?: string | string[] | undefined;
154
154
  project?: string | string[] | undefined;
155
155
  } | undefined;
156
+ eve?: string | boolean | string[] | {
157
+ config?: string | string[] | undefined;
158
+ entry?: string | string[] | undefined;
159
+ project?: string | string[] | undefined;
160
+ } | undefined;
156
161
  execa?: string | boolean | string[] | {
157
162
  config?: string | string[] | undefined;
158
163
  entry?: string | string[] | undefined;
@@ -173,6 +178,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
173
178
  entry?: string | string[] | undefined;
174
179
  project?: string | string[] | undefined;
175
180
  } | undefined;
181
+ fumadocs?: string | boolean | string[] | {
182
+ config?: string | string[] | undefined;
183
+ entry?: string | string[] | undefined;
184
+ project?: string | string[] | undefined;
185
+ } | undefined;
176
186
  gatsby?: string | boolean | string[] | {
177
187
  config?: string | string[] | undefined;
178
188
  entry?: string | string[] | undefined;
@@ -789,7 +799,7 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
789
799
  project?: string | string[] | undefined;
790
800
  } | undefined;
791
801
  $schema?: string | undefined;
792
- rules?: Partial<Record<"binaries" | "catalog" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved", "error" | "off" | "warn">> | undefined;
802
+ rules?: Partial<Record<"binaries" | "catalog" | "cycles" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved", "error" | "off" | "warn">> | undefined;
793
803
  entry?: string | string[] | undefined;
794
804
  project?: string | string[] | undefined;
795
805
  paths?: Record<string, string[]> | undefined;
@@ -800,15 +810,19 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
800
810
  ignoreMembers?: (string | RegExp)[] | undefined;
801
811
  ignoreUnresolved?: (string | RegExp)[] | undefined;
802
812
  ignoreExportsUsedInFile?: boolean | Record<string, boolean | undefined> | undefined;
803
- ignoreIssues?: Record<string, ("binaries" | "catalog" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[]> | undefined;
813
+ ignoreIssues?: Record<string, ("binaries" | "catalog" | "cycles" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[]> | undefined;
814
+ cycles?: {
815
+ allow?: string[][] | undefined;
816
+ dynamicImports?: boolean | undefined;
817
+ } | undefined;
804
818
  ignoreWorkspaces?: string[] | undefined;
805
819
  includeEntryExports?: boolean | undefined;
806
820
  compilers?: Record<string, true | CompilerAsync | CompilerSync> | undefined;
807
821
  tags?: string[] | undefined;
808
822
  treatConfigHintsAsErrors?: boolean | undefined;
809
823
  treatTagHintsAsErrors?: boolean | undefined;
810
- include?: ("binaries" | "catalog" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[] | undefined;
811
- exclude?: ("binaries" | "catalog" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[] | undefined;
824
+ include?: ("binaries" | "catalog" | "cycles" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[] | undefined;
825
+ exclude?: ("binaries" | "catalog" | "cycles" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[] | undefined;
812
826
  workspaces?: Record<string, {
813
827
  angular?: string | boolean | string[] | {
814
828
  config?: string | string[] | undefined;
@@ -960,6 +974,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
960
974
  entry?: string | string[] | undefined;
961
975
  project?: string | string[] | undefined;
962
976
  } | undefined;
977
+ eve?: string | boolean | string[] | {
978
+ config?: string | string[] | undefined;
979
+ entry?: string | string[] | undefined;
980
+ project?: string | string[] | undefined;
981
+ } | undefined;
963
982
  execa?: string | boolean | string[] | {
964
983
  config?: string | string[] | undefined;
965
984
  entry?: string | string[] | undefined;
@@ -980,6 +999,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
980
999
  entry?: string | string[] | undefined;
981
1000
  project?: string | string[] | undefined;
982
1001
  } | undefined;
1002
+ fumadocs?: string | boolean | string[] | {
1003
+ config?: string | string[] | undefined;
1004
+ entry?: string | string[] | undefined;
1005
+ project?: string | string[] | undefined;
1006
+ } | undefined;
983
1007
  gatsby?: string | boolean | string[] | {
984
1008
  config?: string | string[] | undefined;
985
1009
  entry?: string | string[] | undefined;
@@ -1605,11 +1629,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1605
1629
  ignoreMembers?: (string | RegExp)[] | undefined;
1606
1630
  ignoreUnresolved?: (string | RegExp)[] | undefined;
1607
1631
  ignoreExportsUsedInFile?: boolean | Record<string, boolean | undefined> | undefined;
1608
- ignoreIssues?: Record<string, ("binaries" | "catalog" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[]> | undefined;
1632
+ ignoreIssues?: Record<string, ("binaries" | "catalog" | "cycles" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[]> | undefined;
1609
1633
  includeEntryExports?: boolean | undefined;
1610
1634
  }> | undefined;
1611
1635
  syncCompilers: Record<string, true | CompilerSync>;
1612
1636
  asyncCompilers: Record<string, CompilerAsync>;
1613
1637
  };
1614
- export declare const getIncludedCompilers: (syncCompilers: RawSyncCompilers, asyncCompilers: AsyncCompilers, dependencies: DependencySet) => Compilers;
1638
+ export declare const getIncludedCompilers: (syncCompilers: RawSyncCompilers, asyncCompilers: AsyncCompilers, dependencies: DependencySet, onReferencedDependency?: (packageName: string) => void) => Compilers;
1615
1639
  export declare const getCompilerExtensions: (compilers: [SyncCompilers, AsyncCompilers]) => string[];
@@ -1,5 +1,7 @@
1
+ import LESS from './less.js';
1
2
  import MDX from './mdx.js';
2
3
  import SCSS from './scss.js';
4
+ import STYLUS from './stylus.js';
3
5
  const isAsyncCompiler = (fn) => (fn ? fn.constructor.name === 'AsyncFunction' : false);
4
6
  export const normalizeCompilerExtension = (ext) => ext.replace(/^\.*/, '.');
5
7
  export const partitionCompilers = (rawLocalConfig) => {
@@ -26,16 +28,29 @@ export const partitionCompilers = (rawLocalConfig) => {
26
28
  }
27
29
  return { ...rawLocalConfig, syncCompilers, asyncCompilers };
28
30
  };
29
- const compilers = new Map([
30
- ['.mdx', MDX],
31
- ['.sass', SCSS],
32
- ['.scss', SCSS],
33
- ]);
34
- export const getIncludedCompilers = (syncCompilers, asyncCompilers, dependencies) => {
35
- const hasDependency = (packageName) => dependencies.has(packageName);
36
- for (const [extension, { condition, compiler }] of compilers) {
37
- if ((!syncCompilers.has(extension) && condition(hasDependency)) || syncCompilers.get(extension) === true) {
38
- syncCompilers.set(extension, compiler);
31
+ const compilers = [
32
+ { extensions: ['.mdx'], ...MDX },
33
+ { extensions: ['.sass', '.scss'], ...SCSS },
34
+ { extensions: ['.less'], ...LESS },
35
+ { extensions: ['.styl', '.stylus'], ...STYLUS },
36
+ ];
37
+ export const getIncludedCompilers = (syncCompilers, asyncCompilers, dependencies, onReferencedDependency) => {
38
+ for (const { extensions, dependencies: compilerDependencies, compiler } of compilers) {
39
+ let hasCompilerDependency = false;
40
+ for (const dependency of compilerDependencies) {
41
+ if (dependencies.has(dependency)) {
42
+ hasCompilerDependency = true;
43
+ if (onReferencedDependency)
44
+ onReferencedDependency(dependency);
45
+ else
46
+ break;
47
+ }
48
+ }
49
+ for (const extension of extensions) {
50
+ const existingCompiler = syncCompilers.get(extension);
51
+ if (existingCompiler === true || (existingCompiler === undefined && hasCompilerDependency)) {
52
+ syncCompilers.set(extension, compiler);
53
+ }
39
54
  }
40
55
  }
41
56
  return [syncCompilers, asyncCompilers];
@@ -0,0 +1,7 @@
1
+ import type { CompilerSync } from './types.ts';
2
+ export declare const compiler: CompilerSync;
3
+ declare const _default: {
4
+ dependencies: string[];
5
+ compiler: CompilerSync;
6
+ };
7
+ export default _default;