knip 6.46.1 → 6.48.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 (101) hide show
  1. package/dist/ConfigurationChief.d.ts +6 -0
  2. package/dist/IssueFixer.js +2 -6
  3. package/dist/WorkspaceWorker.d.ts +1 -0
  4. package/dist/WorkspaceWorker.js +10 -6
  5. package/dist/binaries/create-script-parser-context.js +2 -1
  6. package/dist/binaries/fallback.js +2 -3
  7. package/dist/binaries/plugins.js +1 -5
  8. package/dist/binaries/resolvers/npx.js +6 -8
  9. package/dist/binaries/resolvers/pnpx.js +3 -7
  10. package/dist/binaries/util.d.ts +4 -0
  11. package/dist/binaries/util.js +12 -2
  12. package/dist/compilers/mdx.js +7 -1
  13. package/dist/plugins/angular/helpers.d.ts +7 -0
  14. package/dist/plugins/angular/helpers.js +58 -0
  15. package/dist/plugins/angular/index.js +5 -50
  16. package/dist/plugins/angular/types.d.ts +2 -2
  17. package/dist/plugins/astro/index.js +6 -1
  18. package/dist/plugins/cucumber/index.js +19 -7
  19. package/dist/plugins/cucumber/types.d.ts +1 -0
  20. package/dist/plugins/cypress/index.js +5 -0
  21. package/dist/plugins/docusaurus/helpers.js +19 -5
  22. package/dist/plugins/drizzle/index.js +5 -0
  23. package/dist/plugins/ember/index.js +4 -8
  24. package/dist/plugins/env/index.d.ts +3 -0
  25. package/dist/plugins/env/index.js +27 -0
  26. package/dist/plugins/esbuild/index.js +5 -0
  27. package/dist/plugins/firebase/index.d.ts +3 -0
  28. package/dist/plugins/firebase/index.js +12 -0
  29. package/dist/plugins/github-action/index.js +13 -3
  30. package/dist/plugins/github-actions/index.d.ts +2 -1
  31. package/dist/plugins/github-actions/index.js +4 -2
  32. package/dist/plugins/github-actions/types.d.ts +5 -0
  33. package/dist/plugins/graphql-codegen/index.js +2 -0
  34. package/dist/plugins/index.d.ts +6 -0
  35. package/dist/plugins/index.js +12 -0
  36. package/dist/plugins/mocha/index.js +6 -0
  37. package/dist/plugins/mocha/types.d.ts +3 -0
  38. package/dist/plugins/netlify/index.js +12 -2
  39. package/dist/plugins/netlify/types.d.ts +3 -0
  40. package/dist/plugins/node/index.d.ts +2 -2
  41. package/dist/plugins/node/index.js +14 -3
  42. package/dist/plugins/nodemon/index.js +19 -0
  43. package/dist/plugins/nx/index.js +14 -1
  44. package/dist/plugins/plop/index.js +4 -0
  45. package/dist/plugins/prisma/index.js +2 -0
  46. package/dist/plugins/remark/helpers.js +1 -8
  47. package/dist/plugins/rollup/index.js +1 -1
  48. package/dist/plugins/serverless-framework/index.js +14 -5
  49. package/dist/plugins/serverless-framework/types.d.ts +4 -1
  50. package/dist/plugins/sst/index.js +13 -0
  51. package/dist/plugins/sst/resolveFromAST.js +35 -16
  52. package/dist/plugins/start-server-and-test/index.d.ts +3 -0
  53. package/dist/plugins/start-server-and-test/index.js +10 -0
  54. package/dist/plugins/storybook/index.js +3 -3
  55. package/dist/plugins/storybook/types.d.ts +5 -3
  56. package/dist/plugins/textlint/helpers.js +1 -5
  57. package/dist/plugins/trigger-dev/index.d.ts +3 -0
  58. package/dist/plugins/trigger-dev/index.js +28 -0
  59. package/dist/plugins/ts-node/index.d.ts +6 -0
  60. package/dist/plugins/ts-node/index.js +19 -0
  61. package/dist/plugins/ts-node-dev/index.d.ts +3 -0
  62. package/dist/plugins/ts-node-dev/index.js +46 -0
  63. package/dist/plugins/tsup/index.js +2 -0
  64. package/dist/plugins/tsx/index.js +1 -1
  65. package/dist/plugins/typedoc/index.js +5 -2
  66. package/dist/plugins/typescript/index.d.ts +12 -1
  67. package/dist/plugins/typescript/index.js +12 -4
  68. package/dist/plugins/vite/helpers.js +1 -4
  69. package/dist/plugins/vite-node/index.d.ts +3 -0
  70. package/dist/plugins/vite-node/index.js +11 -0
  71. package/dist/plugins/vite-plus/index.d.ts +4 -1
  72. package/dist/plugins/vite-plus/index.js +19 -4
  73. package/dist/plugins/vite-plus/types.d.ts +12 -0
  74. package/dist/plugins/vite-plus/types.js +1 -0
  75. package/dist/plugins/vitepress/index.js +14 -0
  76. package/dist/plugins/vitest/index.js +5 -0
  77. package/dist/plugins/vitest/types.d.ts +2 -1
  78. package/dist/plugins/web-test-runner/index.js +8 -2
  79. package/dist/plugins/webdriver-io/index.js +6 -2
  80. package/dist/plugins/wrangler/index.js +4 -0
  81. package/dist/session/index.d.ts +1 -0
  82. package/dist/session/index.js +1 -0
  83. package/dist/types/PluginNames.d.ts +2 -2
  84. package/dist/types/PluginNames.js +6 -0
  85. package/dist/types/tsconfig-json.d.ts +5 -0
  86. package/dist/typescript/ast-helpers.d.ts +3 -1
  87. package/dist/typescript/ast-helpers.js +14 -4
  88. package/dist/typescript/visitors/exports.js +11 -8
  89. package/dist/typescript/visitors/imports.js +10 -8
  90. package/dist/typescript/visitors/members.js +10 -8
  91. package/dist/util/create-input-handler.js +5 -3
  92. package/dist/util/package-json.d.ts +1 -0
  93. package/dist/util/package-json.js +21 -9
  94. package/dist/util/remove-export.d.ts +1 -0
  95. package/dist/util/remove-export.js +2 -0
  96. package/dist/version.d.ts +1 -1
  97. package/dist/version.js +1 -1
  98. package/package.json +1 -1
  99. package/schema.json +24 -0
  100. package/dist/plugins/vite-plus/resolveFromAST.d.ts +0 -2
  101. package/dist/plugins/vite-plus/resolveFromAST.js +0 -37
@@ -120,6 +120,7 @@ export declare class ConfigurationChief {
120
120
  eleventy?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
121
121
  ember?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
122
122
  "ember-template-lint"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
123
+ env?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
123
124
  "env-cmd"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
124
125
  esbuild?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
125
126
  eslint?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -131,6 +132,7 @@ export declare class ConfigurationChief {
131
132
  "expressive-code"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
132
133
  fast?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
133
134
  "filesystem-routing"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
135
+ firebase?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
134
136
  flue?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
135
137
  fumadocs?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
136
138
  gatsby?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -237,6 +239,7 @@ export declare class ConfigurationChief {
237
239
  "solidjs-vite-plugin"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
238
240
  sst?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
239
241
  starlight?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
242
+ "start-server-and-test"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
240
243
  stencil?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
241
244
  storybook?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
242
245
  stryker?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -255,7 +258,9 @@ export declare class ConfigurationChief {
255
258
  temporal?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
256
259
  textlint?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
257
260
  travis?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
261
+ "trigger-dev"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
258
262
  "ts-node"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
263
+ "ts-node-dev"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
259
264
  tsd?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
260
265
  tsdown?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
261
266
  tsrs?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -278,6 +283,7 @@ export declare class ConfigurationChief {
278
283
  "vercel-og"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
279
284
  vike?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
280
285
  vite?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
286
+ "vite-node"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
281
287
  "vite-plugin-pages"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
282
288
  "vite-plugin-pwa"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
283
289
  "vite-plugin-vue-layouts-next"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -3,8 +3,7 @@ import { DEFAULT_CATALOG } from './util/catalog.js';
3
3
  import { debugLogArray, debugLogObject } from './util/debug.js';
4
4
  import { load, save } from './util/package-json.js';
5
5
  import { extname, join } from './util/path.js';
6
- import { removeExport } from './util/remove-export.js';
7
- const MODULE_MARKER = /^[ \t]*(import|export)\b/m;
6
+ import { keepModuleMarker, removeExport } from './util/remove-export.js';
8
7
  export const fix = async (issues, counters, options) => {
9
8
  const fixer = new IssueFixer(options);
10
9
  const touchedFiles = await fixer.fixIssues(issues);
@@ -80,10 +79,7 @@ class IssueFixer {
80
79
  if (fix[0] >= (disjointFixes.at(-1)?.[1] ?? 0))
81
80
  disjointFixes.push(fix);
82
81
  }
83
- let sourceFileText = disjointFixes.reduceRight((text, [start, end, flags]) => removeExport({ text, start, end, flags }), originalSource);
84
- if (MODULE_MARKER.test(originalSource) && !MODULE_MARKER.test(sourceFileText)) {
85
- sourceFileText = `${sourceFileText.trimEnd()}\n\nexport {};\n`;
86
- }
82
+ const sourceFileText = keepModuleMarker(originalSource, disjointFixes.reduceRight((text, [start, end, flags]) => removeExport({ text, start, end, flags }), originalSource));
87
83
  await writeFile(absFilePath, sourceFileText);
88
84
  touchedFiles.add(absFilePath);
89
85
  for (const type of types) {
@@ -68,6 +68,7 @@ export declare class WorkspaceWorker {
68
68
  private getPluginConfig;
69
69
  getPluginConfigPatterns(): string[];
70
70
  getPluginEntryFilePatterns(patterns: string[], base?: string): string[];
71
+ private getNegatedDevelopmentEntryFiles;
71
72
  getProductionEntryFilePatterns(): string[];
72
73
  getProductionProjectFilePatterns(): string[];
73
74
  private getConfigurationFilePatterns;
@@ -152,23 +152,27 @@ export class WorkspaceWorker {
152
152
  : this.ignoredWorkspacePatterns;
153
153
  return [patterns, negateWorkspaces, ignoredWorkspaces.map(negate)].flat();
154
154
  }
155
+ getNegatedDevelopmentEntryFiles() {
156
+ const { entry } = this.config;
157
+ return entry.filter(pattern => hasNoProductionSuffix(pattern) && !entry.includes(`${pattern}!`)).map(negate);
158
+ }
155
159
  getProductionEntryFilePatterns() {
156
160
  const entry = this.config.entry.filter(hasProductionSuffix);
157
161
  if (entry.length === 0)
158
162
  return [];
159
- const negatedEntryFiles = this.config.entry.filter(hasNoProductionSuffix).map(negate);
163
+ const negatedEntryFiles = this.getNegatedDevelopmentEntryFiles();
160
164
  return [entry, negatedEntryFiles, this.negatedWorkspacePatterns].flat();
161
165
  }
162
166
  getProductionProjectFilePatterns() {
163
167
  const project = this.config.project;
164
168
  if (project.length === 0)
165
169
  return this.getProductionEntryFilePatterns();
166
- const _project = this.config.project.map(pattern => {
167
- if (!(pattern.endsWith('!') || pattern.startsWith('!')))
168
- return negate(pattern);
169
- return pattern;
170
+ const _project = project.flatMap(pattern => {
171
+ if (pattern.endsWith('!') || pattern.startsWith('!'))
172
+ return [pattern];
173
+ return project.includes(`${pattern}!`) ? [] : [negate(pattern)];
170
174
  });
171
- const negatedEntryFiles = this.config.entry.filter(hasNoProductionSuffix).map(negate);
175
+ const negatedEntryFiles = this.getNegatedDevelopmentEntryFiles();
172
176
  const negatedPluginConfigPatterns = this.getPluginConfigPatterns().map(negate);
173
177
  const negatedPluginProjectFilePatterns = this.getPluginProjectFilePatterns().map(negate);
174
178
  return [
@@ -1,6 +1,7 @@
1
+ import { ROOT_WORKSPACE_NAME } from '../constants.js';
1
2
  import { createManifest } from '../util/package-json.js';
2
3
  export const createScriptParserContext = (chief) => {
3
- const rawRootManifest = chief.getManifestForWorkspace('.');
4
+ const rawRootManifest = chief.getManifestForWorkspace(ROOT_WORKSPACE_NAME);
4
5
  const rootManifest = rawRootManifest ? createManifest(rawRootManifest) : undefined;
5
6
  const manifests = new Map();
6
7
  const getManifest = (dir) => {
@@ -3,10 +3,9 @@ import { compact } from '../util/array.js';
3
3
  import { toModule, toEntry } from '../util/input.js';
4
4
  import { isValidBinary } from '../util/modules.js';
5
5
  import { isAbsolute } from '../util/path.js';
6
- import { argsFrom, toCommandBinary } from './util.js';
6
+ import { argsFrom, isEnvAssignment, toCommandBinary } from './util.js';
7
7
  export const shellSpawningBinaries = ['cross-env-shell'];
8
8
  export const spawningBinaries = ['cross-env', ...shellSpawningBinaries];
9
- const isEnvAssignment = /^\w+=/;
10
9
  export const getEnvAssignmentCount = (values) => {
11
10
  let count = 0;
12
11
  while (count < values.length && isEnvAssignment.test(values[count]))
@@ -18,7 +17,7 @@ const commandFlagBinaries = new Map([
18
17
  ['doppler', ['command']],
19
18
  ['infisical', ['command', 'c']],
20
19
  ]);
21
- const positionals = new Set(['babel-node', 'esbuild', 'execa', 'jiti', 'oxnode', 'vite-node', 'zx']);
20
+ const positionals = new Set(['babel-node', 'execa', 'jiti', 'oxnode', 'zx']);
22
21
  const positionalBinaries = new Set(['concurrently']);
23
22
  export const isWrapper = (binary) => spawningBinaries.includes(binary) || endOfCommandBinaries.includes(binary) || positionalBinaries.has(binary);
24
23
  const parse = (binary, words) => parseArgs(words, {
@@ -7,12 +7,8 @@ import { extractBinary, isInNodeModulesBin } from '../util/modules.js';
7
7
  import { dirname } from '../util/path.js';
8
8
  import { collectCommands, getCommandWords } from '../util/scripts.js';
9
9
  import { getEnvAssignmentCount, getWrappedScripts, isWrapper as isFallbackWrapper, resolve as fallbackResolve, shellSpawningBinaries, spawningBinaries, } from './fallback.js';
10
- import { isGlobLike, nodeLoadersArgs, toCommandBinary, toWordArgs } from './util.js';
10
+ import { isGlobLike, nodeLoadersArgs, toCommandBinary, toShellAssignment, toWordArgs } from './util.js';
11
11
  export const isWrapper = (binary) => !!pluginArgsMap.get(binary)?.[1].fromArgs || isFallbackWrapper(binary);
12
- const toShellAssignment = (assignment) => {
13
- const index = assignment.indexOf('=');
14
- return `${assignment.slice(0, index)}='${assignment.slice(index + 1).replaceAll("'", "'\\''")}'`;
15
- };
16
12
  const toCrossEnvCommand = (args) => {
17
13
  const command = args.slice();
18
14
  const count = getEnvAssignmentCount(args);
@@ -1,8 +1,8 @@
1
1
  import parseArgs from '../../util/parse-args.js';
2
2
  import { toBinary, toModule, toDependency } from '../../util/input.js';
3
- import { stripVersionFromSpecifier } from '../../util/modules.js';
3
+ import { extractBinary, stripVersionFromSpecifier } from '../../util/modules.js';
4
4
  import { isInternal } from '../../util/path.js';
5
- import { argsFrom, npmBooleanAliases, npmBooleanFlags } from '../util.js';
5
+ import { argsFrom, npmBooleanAliases, npmBooleanFlags, removeOuterCommand } from '../util.js';
6
6
  const noInstallFlags = new Set(['--no', '--no-install', '--yes=false', '--no-yes']);
7
7
  export const resolve = (_binary, words, options) => {
8
8
  const { fromArgs, cwd } = options;
@@ -24,10 +24,8 @@ export const resolve = (_binary, words, options) => {
24
24
  const opts = noInstall ? undefined : { optional: true };
25
25
  const dependency = isBinary ? toBinary(specifier, opts) : toPackage(specifier, opts);
26
26
  const specifiers = dependency ? [dependency] : [];
27
- return [
28
- ...specifiers,
29
- ...packages.map(id => toPackage(id, { optional: true })),
30
- ...command,
31
- ...fromArgs(argsFrom(words, packageSpecifier)).slice(1),
32
- ];
27
+ const forwarded = packageSpecifier ? fromArgs(argsFrom(words, packageSpecifier)) : [];
28
+ if (forwarded.length > 0)
29
+ removeOuterCommand(forwarded, extractBinary(packageSpecifier));
30
+ return [...specifiers, ...packages.map(id => toPackage(id, { optional: true })), ...command, ...forwarded];
33
31
  };
@@ -2,6 +2,7 @@ import parseArgs from '../../util/parse-args.js';
2
2
  import { getCatalogReference } from '../../util/catalog.js';
3
3
  import { toCatalog, toDependency } from '../../util/input.js';
4
4
  import { extractBinary, stripVersionFromSpecifier } from '../../util/modules.js';
5
+ import { removeOuterCommand } from '../util.js';
5
6
  const toDependencyInputs = (packageSpecifier) => {
6
7
  const dependency = toDependency(stripVersionFromSpecifier(packageSpecifier), { optional: true });
7
8
  const reference = getCatalogReference(packageSpecifier);
@@ -22,13 +23,8 @@ export const resolveDlx = (words, options) => {
22
23
  const dependencyInputs = packageSpecifier ? toDependencyInputs(packageSpecifier) : [];
23
24
  const executable = packageSpecifier ? extractBinary(String(packageSpecifier)) : '';
24
25
  const forwarded = executable && !flags.dir ? options.fromArgs([executable, ...words.slice(commandIndex + 1)]) : [];
25
- const isOuterCommand = forwarded[0]?.specifier === executable;
26
- return [
27
- ...dependencyInputs,
28
- ...packages.flatMap(toDependencyInputs),
29
- ...command,
30
- ...(isOuterCommand ? forwarded.slice(1) : forwarded),
31
- ];
26
+ removeOuterCommand(forwarded, executable);
27
+ return [...dependencyInputs, ...packages.flatMap(toDependencyInputs), ...command, ...forwarded];
32
28
  };
33
29
  export const resolve = (_binary, words, options) => {
34
30
  return resolveDlx(words, options);
@@ -5,6 +5,7 @@ import { type Input } from '../util/input.ts';
5
5
  export declare const toCommandBinary: (binary: string, { optionalBinaries }: GetInputsFromScriptsOptions, inputOptions?: {
6
6
  dir?: string;
7
7
  }) => Input;
8
+ export declare const removeOuterCommand: (inputs: Input[], executable: string) => void;
8
9
  export declare const npmBooleanFlags: string[];
9
10
  export declare const npmBooleanAliases: {
10
11
  force: string;
@@ -18,8 +19,11 @@ export declare const npmBooleanAliases: {
18
19
  export declare const nodeLoadersArgs: {
19
20
  import: string[];
20
21
  };
22
+ export declare const isEnvAssignment: RegExp;
23
+ export declare const toShellAssignment: (assignment: string) => string;
21
24
  export declare const isGlobLike: (value: string) => boolean;
22
25
  export declare const argsFrom: <T extends string | Word>(args: readonly T[], from: string) => T[];
26
+ export declare const argsFromPositional: (parsed: ParsedArgs, args: string[], position: number) => string[];
23
27
  export declare const spawningArgs: (parsed: ParsedArgs, args: string[]) => string[];
24
28
  export declare const argsAfter: <T extends string | Word>(args: readonly T[], token: string) => T[];
25
29
  export declare const toWordArgs: (values: (string | number)[], words: Word[]) => ScriptArg[];
@@ -1,6 +1,10 @@
1
1
  import parseArgs, {} from '../util/parse-args.js';
2
2
  import { toBinary } from '../util/input.js';
3
3
  export const toCommandBinary = (binary, { optionalBinaries }, inputOptions = {}) => toBinary(binary, optionalBinaries ? { ...inputOptions, optional: true } : inputOptions);
4
+ export const removeOuterCommand = (inputs, executable) => {
5
+ if (inputs[0]?.specifier === executable)
6
+ inputs.shift();
7
+ };
4
8
  export const npmBooleanFlags = [
5
9
  'color',
6
10
  'd',
@@ -36,16 +40,22 @@ export const npmBooleanAliases = {
36
40
  };
37
41
  const valueOf = (arg) => (typeof arg === 'string' ? arg : arg.value);
38
42
  export const nodeLoadersArgs = { import: ['r', 'experimental-loader', 'require', 'loader'] };
43
+ export const isEnvAssignment = /^\w+=/;
44
+ export const toShellAssignment = (assignment) => {
45
+ const index = assignment.indexOf('=');
46
+ return `${assignment.slice(0, index)}='${assignment.slice(index + 1).replaceAll("'", "'\\''")}'`;
47
+ };
39
48
  const isGlobLikeMatch = /(^!|[*+\\(|{^$])/;
40
49
  export const isGlobLike = (value) => isGlobLikeMatch.test(value);
41
50
  export const argsFrom = (args, from) => {
42
51
  const index = args.findIndex(arg => valueOf(arg) === from);
43
52
  return index === -1 ? [] : args.slice(index);
44
53
  };
45
- export const spawningArgs = (parsed, args) => {
46
- const index = parsed.positionalIndices?.[0];
54
+ export const argsFromPositional = (parsed, args, position) => {
55
+ const index = parsed.positionalIndices?.[position];
47
56
  return index === undefined ? (parsed['--'] ?? []) : args.slice(index);
48
57
  };
58
+ export const spawningArgs = (parsed, args) => argsFromPositional(parsed, args, 0);
49
59
  export const argsAfter = (args, token) => {
50
60
  const index = args.findIndex(arg => valueOf(arg) === token);
51
61
  return index === -1 ? [] : args.slice(index + 1).filter(arg => valueOf(arg) !== '--');
@@ -11,8 +11,9 @@ const dependencies = [
11
11
  'remark-mdx',
12
12
  ];
13
13
  const mdxImportMatcher = /^import[^'"]+['"][^'"]+['"]/gm;
14
+ const mdxReExportMatcher = /^export\s*\{([^}]*)\}\s*from\s*(['"][^'"]+['"])/gm;
14
15
  const compiler = (text) => {
15
- if (!text.includes('import'))
16
+ if (!text.includes('import') && !text.includes('export'))
16
17
  return '';
17
18
  const imports = [];
18
19
  const source = text
@@ -23,6 +24,11 @@ const compiler = (text) => {
23
24
  mdxImportMatcher.lastIndex = 0;
24
25
  while ((match = mdxImportMatcher.exec(source)))
25
26
  imports.push(match[0]);
27
+ mdxReExportMatcher.lastIndex = 0;
28
+ while ((match = mdxReExportMatcher.exec(source))) {
29
+ const names = match[1].replace(/\s+as\s+[\w$]+/g, '').replace(/\bdefault\b/, 'default as _');
30
+ imports.push(`import {${names}} from ${match[2]}`);
31
+ }
26
32
  return imports.join('\n');
27
33
  };
28
34
  export default { dependencies, compiler };
@@ -0,0 +1,7 @@
1
+ import { type Input } from '../../util/input.ts';
2
+ interface BuilderTarget {
3
+ options?: unknown;
4
+ configurations?: unknown;
5
+ }
6
+ export declare const getBuilderEntries: (targetName: string, target: BuilderTarget, dir: string, toSpecifier?: (specifier: string) => string) => Input[];
7
+ export {};
@@ -0,0 +1,58 @@
1
+ import { toEntryPath, toModule } from '../../util/input.js';
2
+ import { isObject } from '../../util/validation.js';
3
+ const PRODUCTION_CONFIG_NAME = 'production';
4
+ const BUILD_TARGET_NAME = 'build';
5
+ const isPath = (value) => typeof value === 'string' && value.length > 0;
6
+ const getBundleInput = (value) => (isObject(value) ? value.input : value);
7
+ const getReplacementPath = (value) => (isObject(value) ? (value.with ?? value.replaceWith) : undefined);
8
+ const toPaths = (value, getPath = item => item) => {
9
+ const paths = [];
10
+ for (const item of Array.isArray(value) ? value : [value]) {
11
+ const path = getPath(item);
12
+ if (isPath(path))
13
+ paths.push(path);
14
+ }
15
+ return paths;
16
+ };
17
+ const entriesByOption = (opts) => new Map([
18
+ ['main', toPaths(opts.main)],
19
+ ['scripts', toPaths(opts.scripts, getBundleInput)],
20
+ ['styles', toPaths(opts.styles, getBundleInput)],
21
+ ['polyfills', toPaths(opts.polyfills)],
22
+ ['fileReplacements', toPaths(opts.fileReplacements, getReplacementPath)],
23
+ ['browser', toPaths(opts.browser)],
24
+ ['server', toPaths(opts.server)],
25
+ ['ssrEntry', toPaths(isObject(opts.ssr) ? opts.ssr.entry : undefined)],
26
+ ]);
27
+ export const getBuilderEntries = (targetName, target, dir, toSpecifier = specifier => specifier) => {
28
+ const { options: opts, configurations: configs } = target;
29
+ const defaultEntriesByOption = isObject(opts) ? entriesByOption(opts) : new Map();
30
+ const entriesByOptionByConfig = new Map();
31
+ if (isObject(configs)) {
32
+ for (const [configName, configOpts] of Object.entries(configs)) {
33
+ if (isObject(configOpts))
34
+ entriesByOptionByConfig.set(configName, entriesByOption(configOpts));
35
+ }
36
+ }
37
+ const productionEntriesByOption = entriesByOptionByConfig.get(PRODUCTION_CONFIG_NAME) ?? new Map();
38
+ const isBuildTarget = targetName === BUILD_TARGET_NAME;
39
+ const toInput = (option, entry, isProduction) => {
40
+ const specifier = toSpecifier(entry);
41
+ const opts = { dir, production: isProduction };
42
+ return option === 'polyfills' ? toModule(specifier, opts) : toEntryPath(specifier, opts);
43
+ };
44
+ const inputs = [];
45
+ for (const [configName, entriesByOption] of entriesByOptionByConfig) {
46
+ for (const [option, entries] of entriesByOption) {
47
+ for (const entry of entries) {
48
+ inputs.push(toInput(option, entry, isBuildTarget && configName === PRODUCTION_CONFIG_NAME));
49
+ }
50
+ }
51
+ }
52
+ for (const [option, entries] of defaultEntriesByOption) {
53
+ for (const entry of entries) {
54
+ inputs.push(toInput(option, entry, isBuildTarget && !productionEntriesByOption.get(option)?.length));
55
+ }
56
+ }
57
+ return inputs;
58
+ };
@@ -1,7 +1,8 @@
1
- import { toConfig, toModule, toEntryPath, toDependency, toEntry } from '../../util/input.js';
1
+ import { toConfig, toDependency, toEntry } from '../../util/input.js';
2
2
  import { hasDependency } from '../../util/plugin.js';
3
3
  import { createComponentStyleUrlsVisitor } from '../_component-style-urls/component-style-urls-visitor.js';
4
4
  import * as karma from '../karma/helpers.js';
5
+ import { getBuilderEntries } from './helpers.js';
5
6
  const title = 'Angular';
6
7
  const enablers = ['@angular/cli'];
7
8
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
@@ -14,7 +15,7 @@ const resolveConfig = async (config, options) => {
14
15
  if (!project.architect)
15
16
  continue;
16
17
  for (const [targetName, target] of Object.entries(project.architect)) {
17
- const { options: opts, configurations: configs } = target;
18
+ const { options: opts } = target;
18
19
  const [packageName] = typeof target.builder === 'string' ? target.builder.split(':') : [];
19
20
  if (packageName)
20
21
  inputs.add(toDependency(packageName));
@@ -23,26 +24,8 @@ const resolveConfig = async (config, options) => {
23
24
  inputs.add(toConfig('typescript', opts.tsConfig));
24
25
  }
25
26
  }
26
- const defaultEntriesByOption = opts ? entriesByOption(opts) : new Map();
27
- const entriesByOptionByConfig = new Map(configs ? Object.entries(configs).map(([name, opts]) => [name, entriesByOption(opts)]) : []);
28
- const productionEntriesByOption = entriesByOptionByConfig.get(PRODUCTION_CONFIG_NAME) ?? new Map();
29
- const isBuildTarget = targetName === BUILD_TARGET_NAME;
30
- const toInput = (option, specifier, isProduction) => {
31
- const opts = { dir: options.cwd, production: isProduction };
32
- return option === 'polyfills' ? toModule(specifier, opts) : toEntryPath(specifier, opts);
33
- };
34
- for (const [configName, entriesByOption] of entriesByOptionByConfig) {
35
- for (const [option, entries] of entriesByOption) {
36
- for (const entry of entries) {
37
- inputs.add(toInput(option, entry, isBuildTarget && configName === PRODUCTION_CONFIG_NAME));
38
- }
39
- }
40
- }
41
- for (const [option, entries] of defaultEntriesByOption) {
42
- for (const entry of entries) {
43
- inputs.add(toInput(option, entry, isBuildTarget && !productionEntriesByOption.get(option)?.length));
44
- }
45
- }
27
+ for (const input of getBuilderEntries(targetName, target, options.cwd))
28
+ inputs.add(input);
46
29
  if (target.builder && isAngularBuilderRefWithName({ builderRef: target.builder, name: 'karma' }) && opts) {
47
30
  const karmaBuilderOptions = opts;
48
31
  const testFilePatterns = karmaBuilderOptions.include ?? ['**/*.spec.ts'];
@@ -68,38 +51,10 @@ const resolveConfig = async (config, options) => {
68
51
  }
69
52
  return Array.from(inputs);
70
53
  };
71
- const entriesByOption = (opts) => new Map(Object.entries({
72
- main: 'main' in opts && opts.main && typeof opts.main === 'string' ? [opts.main] : [],
73
- scripts: 'scripts' in opts && opts.scripts && Array.isArray(opts.scripts)
74
- ? opts.scripts.map(scriptStringOrObject => typeof scriptStringOrObject === 'string' ? scriptStringOrObject : scriptStringOrObject.input)
75
- : [],
76
- styles: 'styles' in opts && opts.styles && Array.isArray(opts.styles)
77
- ? opts.styles.map(styleStringOrObject => typeof styleStringOrObject === 'string' ? styleStringOrObject : styleStringOrObject.input)
78
- : [],
79
- polyfills: 'polyfills' in opts && opts.polyfills
80
- ? Array.isArray(opts.polyfills)
81
- ? opts.polyfills
82
- : [opts.polyfills]
83
- : [],
84
- fileReplacements: 'fileReplacements' in opts && opts.fileReplacements && Array.isArray(opts.fileReplacements)
85
- ? opts.fileReplacements.map(fileReplacement => 'with' in fileReplacement ? fileReplacement.with : fileReplacement.replaceWith)
86
- : [],
87
- browser: 'browser' in opts && opts.browser && typeof opts.browser === 'string' ? [opts.browser] : [],
88
- server: 'server' in opts && opts.server && typeof opts.server === 'string' ? [opts.server] : [],
89
- ssrEntry: 'ssr' in opts &&
90
- opts.ssr &&
91
- typeof opts.ssr === 'object' &&
92
- 'entry' in opts.ssr &&
93
- typeof opts.ssr.entry === 'string'
94
- ? [opts.ssr.entry]
95
- : [],
96
- }));
97
54
  const isAngularBuilderRefWithName = ({ builderRef, name }) => {
98
55
  const [pkg, builderName] = builderRef.split(':');
99
56
  return (pkg === '@angular-devkit/build-angular' || pkg === '@angular/build') && builderName === name;
100
57
  };
101
- const PRODUCTION_CONFIG_NAME = 'production';
102
- const BUILD_TARGET_NAME = 'build';
103
58
  const isAngularSpecifier = (specifier) => specifier === '@angular/core';
104
59
  const registerVisitors = ({ ctx, registerVisitor }) => {
105
60
  registerVisitor(createComponentStyleUrlsVisitor(ctx, isAngularSpecifier));
@@ -1,5 +1,5 @@
1
1
  type FileVersion = number;
2
- export type Project = Project1 & {
2
+ type Project = Project1 & {
3
3
  cli?: {
4
4
  [k: string]: unknown;
5
5
  };
@@ -620,7 +620,7 @@ interface AppShellTarget {
620
620
  inputIndexPath?: string;
621
621
  outputIndexPath?: string;
622
622
  }
623
- export interface WebpackBrowserSchemaForBuildFacade {
623
+ interface WebpackBrowserSchemaForBuildFacade {
624
624
  assets?: ({
625
625
  followSymlinks?: boolean;
626
626
  glob: string;
@@ -1,4 +1,4 @@
1
- import { toDependency } from '../../util/input.js';
1
+ import { toConfig, toDependency } from '../../util/input.js';
2
2
  import { hasDependency } from '../../util/plugin.js';
3
3
  import compiler from './compiler.js';
4
4
  import mdxCompiler from './compiler-mdx.js';
@@ -24,6 +24,10 @@ const resolve = options => {
24
24
  }
25
25
  return inputs;
26
26
  };
27
+ const args = {
28
+ string: ['config', 'root'],
29
+ resolveInputs: (parsed, { cwd }) => parsed.config && !parsed.root ? [toConfig('astro', parsed.config, { dir: cwd })] : [],
30
+ };
27
31
  const plugin = {
28
32
  title,
29
33
  enablers,
@@ -34,5 +38,6 @@ const plugin = {
34
38
  registerCompilers,
35
39
  resolveFromAST,
36
40
  resolve,
41
+ args,
37
42
  };
38
43
  export default plugin;
@@ -1,4 +1,5 @@
1
1
  import { toModule, toEntry } from '../../util/input.js';
2
+ import { isDirectory } from '../../util/fs.js';
2
3
  import { hasDependency } from '../../util/plugin.js';
3
4
  const title = 'Cucumber';
4
5
  const enablers = ['@cucumber/cucumber'];
@@ -25,23 +26,33 @@ const toFormatterName = (format) => {
25
26
  const [name, quotedName] = format.match(/^"([^"]*)"|^[^:]*/) ?? [format];
26
27
  return quotedName ?? name;
27
28
  };
28
- const resolveProfile = (config) => {
29
- const imports = (config?.import ? config.import : entry).map(id => toEntry(id));
30
- const requires = (config?.require ? config.require : []).map(id => toEntry(id));
29
+ const toSupportEntry = (id, cwd, extension) => toEntry(isDirectory(cwd, id) ? `${id}/**/*${extension}` : id);
30
+ const resolveProfile = (cwd, config) => {
31
+ const imports = (config?.import ? config.import : entry).map(id => toSupportEntry(id, cwd, '.@(js|cjs|mjs)'));
32
+ const requires = (config?.require ? config.require : []).map(id => toSupportEntry(id, cwd, '.js'));
33
+ const modules = (config?.requireModule ? config.requireModule : []).map(id => toModule(id));
31
34
  const formatters = (config?.format ? config.format : [])
32
35
  .map(toFormatterName)
33
36
  .filter(name => !builtinFormatters.has(name))
34
37
  .map(id => toModule(id));
35
- return [...imports, ...requires, ...formatters];
38
+ return [...imports, ...requires, ...modules, ...formatters];
36
39
  };
37
40
  const resolveConfig = (config, options) => {
38
41
  if (typeof config !== 'object' || config === null)
39
- return resolveProfile();
42
+ return resolveProfile(options.cwd);
40
43
  const isProfiles = /\.(json|ya?ml)$/.test(options.configFileName) || 'default' in config;
41
44
  if (!isProfiles)
42
- return resolveProfile(config);
45
+ return resolveProfile(options.cwd, config);
43
46
  const profiles = 'default' in config ? Object.values(config) : [undefined, ...Object.values(config)];
44
- return profiles.flatMap(resolveProfile);
47
+ return profiles.flatMap(profile => resolveProfile(options.cwd, profile));
48
+ };
49
+ const args = {
50
+ binaries: ['cucumber-js'],
51
+ config: true,
52
+ resolve: ['require-module'],
53
+ string: ['require'],
54
+ alias: { require: ['r'] },
55
+ resolveInputs: (parsed, { cwd }) => [parsed.require ?? []].flat().map(id => toSupportEntry(id, cwd, '.js')),
45
56
  };
46
57
  const plugin = {
47
58
  title,
@@ -50,5 +61,6 @@ const plugin = {
50
61
  config,
51
62
  entry,
52
63
  resolveConfig,
64
+ args,
53
65
  };
54
66
  export default plugin;
@@ -2,6 +2,7 @@ export type CucumberConfig = {
2
2
  publishQuiet?: boolean;
3
3
  import?: string[];
4
4
  require?: string[];
5
+ requireModule?: string[];
5
6
  format?: Format[];
6
7
  parallel?: number;
7
8
  };
@@ -25,6 +25,10 @@ const resolveConfig = async (localConfig, options) => {
25
25
  : SUPPORT_FILE_PATTERNS.map(id => toEntry(id))),
26
26
  ];
27
27
  };
28
+ const args = {
29
+ config: ['config-file'],
30
+ alias: { 'config-file': ['C'] },
31
+ };
28
32
  const plugin = {
29
33
  title,
30
34
  enablers,
@@ -32,5 +36,6 @@ const plugin = {
32
36
  config,
33
37
  entry,
34
38
  resolveConfig,
39
+ args,
35
40
  };
36
41
  export default plugin;
@@ -1,4 +1,5 @@
1
1
  import { toDependency, toEntryPath } from '../../util/input.js';
2
+ import { getPackageNameFromModuleSpecifier } from '../../util/modules.js';
2
3
  import { isAbsolute, toAbsolute } from '../../util/path.js';
3
4
  import { findWebpackDependenciesFromConfig } from '../webpack/index.js';
4
5
  const isLocalPath = (name) => name.startsWith('.') || isAbsolute(name);
@@ -42,7 +43,20 @@ export const CORE_CLIENT_API = [
42
43
  'useIsomorphicLayoutEffect',
43
44
  'useRouteContext',
44
45
  ];
45
- const resolveModuleName = (name, type) => {
46
+ const getNamePatterns = (name, type) => {
47
+ if (!name.startsWith('@'))
48
+ return [name, `@docusaurus/${type}-${name}`, `docusaurus-${type}-${name}`];
49
+ const index = name.indexOf('/');
50
+ if (index === -1)
51
+ return [`${name}/docusaurus-${type}`];
52
+ return [name, `${name.slice(0, index)}/docusaurus-${type}-${name.slice(index + 1)}`];
53
+ };
54
+ const resolveModuleName = (name, type, manifest) => {
55
+ for (const pattern of getNamePatterns(name, type)) {
56
+ const packageName = getPackageNameFromModuleSpecifier(pattern);
57
+ if (packageName && manifest.allDependencies.has(packageName))
58
+ return pattern;
59
+ }
46
60
  if (name.includes(`${type}-`))
47
61
  return name;
48
62
  if (!name.startsWith('@')) {
@@ -57,14 +71,14 @@ const resolveSidebarPath = (config) => {
57
71
  const path = config?.sidebarPath ?? config?.docs?.sidebarPath;
58
72
  return typeof path === 'string' ? path : undefined;
59
73
  };
60
- const resolveArrayConfig = ([name, config], type, cwd) => {
74
+ const resolveArrayConfig = ([name, config], type, { cwd, manifest }) => {
61
75
  if (typeof name !== 'string')
62
76
  return [];
63
77
  const sidebarPath = type !== 'theme' ? resolveSidebarPath(config) : undefined;
64
78
  const sidebar = sidebarPath ? [toEntryPath(sidebarPath, { production: true, dir: cwd })] : [];
65
79
  if (isLocalPath(name))
66
80
  return [toEntryPath(toAbsolute(name, cwd), { production: true }), ...sidebar];
67
- return [toDependency(resolveModuleName(name, type), { production: type !== 'plugin' }), ...sidebar];
81
+ return [toDependency(resolveModuleName(name, type, manifest), { production: type !== 'plugin' }), ...sidebar];
68
82
  };
69
83
  export const resolveConfigItems = async (items, type, options) => {
70
84
  const inputs = new Set();
@@ -77,10 +91,10 @@ export const resolveConfigItems = async (items, type, options) => {
77
91
  if (isLocalPath(item))
78
92
  inputs.add(toEntryPath(toAbsolute(item, options.cwd), { production: true }));
79
93
  else
80
- inputs.add(toDependency(resolveModuleName(item, type), { production: type !== 'plugin' }));
94
+ inputs.add(toDependency(resolveModuleName(item, type, options.manifest), { production: type !== 'plugin' }));
81
95
  }
82
96
  else if (Array.isArray(item)) {
83
- for (const input of resolveArrayConfig(item, type, options.cwd))
97
+ for (const input of resolveArrayConfig(item, type, options))
84
98
  inputs.add(input);
85
99
  }
86
100
  else if (typeof item.configureWebpack === 'function') {
@@ -9,11 +9,16 @@ const resolveConfig = config => {
9
9
  return [];
10
10
  return [config.schema].flat().map(id => toEntry(id, { production: true }));
11
11
  };
12
+ const args = {
13
+ binaries: ['drizzle-kit'],
14
+ config: ['config'],
15
+ };
12
16
  const plugin = {
13
17
  title,
14
18
  enablers,
15
19
  isEnabled,
16
20
  config,
17
21
  resolveConfig,
22
+ args,
18
23
  };
19
24
  export default plugin;