knip 6.15.0 → 6.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/ConfigurationChief.d.ts +20 -0
  2. package/dist/ConfigurationChief.js +2 -1
  3. package/dist/ProjectPrincipal.d.ts +4 -1
  4. package/dist/ProjectPrincipal.js +21 -13
  5. package/dist/binaries/fallback.js +1 -1
  6. package/dist/binaries/plugins.js +1 -1
  7. package/dist/binaries/resolvers/bun.js +1 -1
  8. package/dist/binaries/resolvers/bunx.js +1 -1
  9. package/dist/binaries/resolvers/npm.js +1 -1
  10. package/dist/binaries/resolvers/npx.js +1 -1
  11. package/dist/binaries/resolvers/pnpm.js +1 -1
  12. package/dist/binaries/resolvers/pnpx.js +1 -1
  13. package/dist/binaries/resolvers/yarn.js +1 -1
  14. package/dist/binaries/util.d.ts +1 -2
  15. package/dist/binaries/util.js +1 -1
  16. package/dist/compilers/index.d.ts +31 -0
  17. package/dist/graph/analyze.js +8 -7
  18. package/dist/graph/build.js +4 -3
  19. package/dist/plugins/_custom-elements/custom-element-visitor.d.ts +7 -0
  20. package/dist/plugins/_custom-elements/custom-element-visitor.js +106 -0
  21. package/dist/plugins/bun/index.js +1 -1
  22. package/dist/plugins/catalyst/index.d.ts +3 -0
  23. package/dist/plugins/catalyst/index.js +16 -0
  24. package/dist/plugins/execa/visitors/execa.js +4 -17
  25. package/dist/plugins/fast/index.d.ts +3 -0
  26. package/dist/plugins/fast/index.js +16 -0
  27. package/dist/plugins/index.d.ts +3 -0
  28. package/dist/plugins/index.js +6 -0
  29. package/dist/plugins/lit/index.d.ts +3 -0
  30. package/dist/plugins/lit/index.js +25 -0
  31. package/dist/plugins/nano-spawn/visitors/nano-spawn.js +4 -17
  32. package/dist/plugins/relay/index.js +1 -1
  33. package/dist/plugins/stencil/index.js +17 -1
  34. package/dist/plugins/sveltejs-package/helpers.js +1 -1
  35. package/dist/schema/configuration.d.ts +51 -0
  36. package/dist/schema/configuration.js +1 -0
  37. package/dist/schema/plugins.d.ts +15 -0
  38. package/dist/schema/plugins.js +3 -0
  39. package/dist/types/PluginNames.d.ts +2 -2
  40. package/dist/types/PluginNames.js +3 -0
  41. package/dist/types/args.d.ts +1 -1
  42. package/dist/types/config.d.ts +2 -0
  43. package/dist/types/module-graph.d.ts +1 -0
  44. package/dist/types/project.d.ts +1 -0
  45. package/dist/typescript/ast-helpers.js +21 -20
  46. package/dist/typescript/ast-nodes.d.ts +1 -0
  47. package/dist/typescript/ast-nodes.js +19 -0
  48. package/dist/typescript/get-imports-and-exports.js +18 -2
  49. package/dist/typescript/resolve-module-names.d.ts +11 -1
  50. package/dist/typescript/resolve-module-names.js +49 -12
  51. package/dist/typescript/visitors/calls.d.ts +3 -2
  52. package/dist/typescript/visitors/calls.js +88 -16
  53. package/dist/typescript/visitors/exports.js +12 -0
  54. package/dist/typescript/visitors/walk.d.ts +7 -0
  55. package/dist/typescript/visitors/walk.js +36 -1
  56. package/dist/util/create-options.d.ts +31 -0
  57. package/dist/util/load-tsconfig.js +2 -0
  58. package/dist/util/parse-args.d.ts +14 -0
  59. package/dist/util/parse-args.js +112 -0
  60. package/dist/version.d.ts +1 -1
  61. package/dist/version.js +1 -1
  62. package/package.json +1 -3
  63. package/schema.json +61 -43
@@ -112,6 +112,11 @@ export declare class ConfigurationChief {
112
112
  entry?: string | string[] | undefined;
113
113
  project?: string | string[] | undefined;
114
114
  } | undefined;
115
+ catalyst?: string | boolean | string[] | {
116
+ config?: string | string[] | undefined;
117
+ entry?: string | string[] | undefined;
118
+ project?: string | string[] | undefined;
119
+ } | undefined;
115
120
  changelogen?: string | boolean | string[] | {
116
121
  config?: string | string[] | undefined;
117
122
  entry?: string | string[] | undefined;
@@ -212,6 +217,11 @@ export declare class ConfigurationChief {
212
217
  entry?: string | string[] | undefined;
213
218
  project?: string | string[] | undefined;
214
219
  } | undefined;
220
+ fast?: string | boolean | string[] | {
221
+ config?: string | string[] | undefined;
222
+ entry?: string | string[] | undefined;
223
+ project?: string | string[] | undefined;
224
+ } | undefined;
215
225
  gatsby?: string | boolean | string[] | {
216
226
  config?: string | string[] | undefined;
217
227
  entry?: string | string[] | undefined;
@@ -287,6 +297,11 @@ export declare class ConfigurationChief {
287
297
  entry?: string | string[] | undefined;
288
298
  project?: string | string[] | undefined;
289
299
  } | undefined;
300
+ lit?: string | boolean | string[] | {
301
+ config?: string | string[] | undefined;
302
+ entry?: string | string[] | undefined;
303
+ project?: string | string[] | undefined;
304
+ } | undefined;
290
305
  'lockfile-lint'?: string | boolean | string[] | {
291
306
  config?: string | string[] | undefined;
292
307
  entry?: string | string[] | undefined;
@@ -826,6 +841,7 @@ export declare class ConfigurationChief {
826
841
  ignoreDependencies?: (string | RegExp)[] | undefined;
827
842
  ignoreMembers?: (string | RegExp)[] | undefined;
828
843
  ignoreUnresolved?: (string | RegExp)[] | undefined;
844
+ ignoreExportsUsedInFile?: boolean | Record<string, boolean | undefined> | undefined;
829
845
  includeEntryExports?: boolean | undefined;
830
846
  };
831
847
  getIgnores(workspaceName: string): {
@@ -839,6 +855,7 @@ export declare class ConfigurationChief {
839
855
  paths: Record<string, string[]>;
840
856
  ignore: string[];
841
857
  ignoreFiles: string[];
858
+ ignoreExportsUsedInFile: Record<string, boolean | undefined> | import("./types/config.ts").IgnoreExportsUsedInFile;
842
859
  isIncludeEntryExports: boolean;
843
860
  angular?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
844
861
  astro?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -851,6 +868,7 @@ export declare class ConfigurationChief {
851
868
  bun?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
852
869
  c8?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
853
870
  capacitor?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
871
+ catalyst?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
854
872
  changelogen?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
855
873
  changelogithub?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
856
874
  changesets?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -871,6 +889,7 @@ export declare class ConfigurationChief {
871
889
  execa?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
872
890
  expo?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
873
891
  "expressive-code"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
892
+ fast?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
874
893
  gatsby?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
875
894
  "github-action"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
876
895
  "github-actions"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -886,6 +905,7 @@ export declare class ConfigurationChief {
886
905
  lefthook?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
887
906
  "lint-staged"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
888
907
  linthtml?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
908
+ lit?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
889
909
  "lockfile-lint"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
890
910
  "lost-pixel"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
891
911
  markdownlint?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -332,6 +332,7 @@ export class ConfigurationChief {
332
332
  const paths = workspaceConfig.paths ?? {};
333
333
  const ignore = arrayify(workspaceConfig.ignore);
334
334
  const ignoreFiles = arrayify(workspaceConfig.ignoreFiles);
335
+ const ignoreExportsUsedInFile = workspaceConfig.ignoreExportsUsedInFile ?? this.config.ignoreExportsUsedInFile;
335
336
  const isIncludeEntryExports = workspaceConfig.includeEntryExports ?? this.config.isIncludeEntryExports;
336
337
  const plugins = {};
337
338
  for (const [pluginName, pluginConfig] of Object.entries(this.config.rootPluginConfigs)) {
@@ -343,7 +344,7 @@ export class ConfigurationChief {
343
344
  plugins[pluginName] = normalizePluginConfig(pluginConfig);
344
345
  }
345
346
  }
346
- return { entry, project, paths, ignore, ignoreFiles, isIncludeEntryExports, ...plugins };
347
+ return { entry, project, paths, ignore, ignoreFiles, ignoreExportsUsedInFile, isIncludeEntryExports, ...plugins };
347
348
  }
348
349
  findWorkspaceByFilePath(filePath) {
349
350
  if (this.workspaceByFileCache.has(filePath))
@@ -15,9 +15,11 @@ export declare class ProjectPrincipal {
15
15
  pluginCtx: PluginVisitorContext;
16
16
  pluginVisitorObjects: PluginVisitorObject[];
17
17
  private _visitor;
18
+ private _localRefsVisitor;
18
19
  syncCompilers: SyncCompilers;
19
20
  asyncCompilers: AsyncCompilers;
20
21
  private paths;
22
+ private rootDirs;
21
23
  private extensions;
22
24
  cache: CacheConsultant<FileNode>;
23
25
  toSourceFilePath: ToSourceFilePath;
@@ -29,7 +31,8 @@ export declare class ProjectPrincipal {
29
31
  private onPathAdded;
30
32
  constructor(options: MainOptions, toSourceFilePath: ToSourceFilePath, findWorkspaceManifestImports?: WorkspaceManifestHandler);
31
33
  addCompilers(compilers: [SyncCompilers, AsyncCompilers]): void;
32
- addPaths(paths: Paths, basePath: string): void;
34
+ addPaths(paths: Paths, basePath: string, scope: string): void;
35
+ addRootDirs(rootDirs: string[] | undefined, scope: string): void;
33
36
  init(): void;
34
37
  readFile(filePath: string): string;
35
38
  private hasAcceptedExtension;
@@ -21,12 +21,15 @@ export class ProjectPrincipal {
21
21
  sourceText: '',
22
22
  addScript: () => { },
23
23
  addImport: () => { },
24
+ markExportRegistered: () => { },
24
25
  };
25
26
  pluginVisitorObjects = [];
26
27
  _visitor;
28
+ _localRefsVisitor;
27
29
  syncCompilers = new Map();
28
30
  asyncCompilers = new Map();
29
- paths = {};
31
+ paths = new Map();
32
+ rootDirs = new Map();
30
33
  extensions = new Set(DEFAULT_EXTENSIONS);
31
34
  cache;
32
35
  toSourceFilePath;
@@ -60,18 +63,21 @@ export class ProjectPrincipal {
60
63
  }
61
64
  }
62
65
  }
63
- addPaths(paths, basePath) {
66
+ addPaths(paths, basePath, scope) {
64
67
  if (!paths)
65
68
  return;
69
+ const scoped = this.paths.get(scope) ?? {};
66
70
  for (const key in paths) {
67
71
  const prefixes = paths[key].map(prefix => toAbsolute(prefix, basePath));
68
- if (key in this.paths) {
69
- this.paths[key] = compact([...this.paths[key], ...prefixes]);
70
- }
71
- else {
72
- this.paths[key] = prefixes;
73
- }
72
+ scoped[key] = key in scoped ? compact([...scoped[key], ...prefixes]) : prefixes;
74
73
  }
74
+ this.paths.set(scope, scoped);
75
+ }
76
+ addRootDirs(rootDirs, scope) {
77
+ if (!rootDirs?.length)
78
+ return;
79
+ const scoped = this.rootDirs.get(scope) ?? [];
80
+ this.rootDirs.set(scope, compact([...scoped, ...rootDirs]));
75
81
  }
76
82
  init() {
77
83
  this.extensions = new Set([
@@ -79,8 +85,9 @@ export class ProjectPrincipal {
79
85
  ...getCompilerExtensions([this.syncCompilers, this.asyncCompilers]),
80
86
  ]);
81
87
  const customCompilerExtensions = getCompilerExtensions([this.syncCompilers, this.asyncCompilers]);
82
- const pathsOrUndefined = Object.keys(this.paths).length > 0 ? this.paths : undefined;
83
- this.resolveModule = createCustomModuleResolver({ paths: pathsOrUndefined }, customCompilerExtensions, this.toSourceFilePath, this.findWorkspaceManifestImports);
88
+ const scopedPaths = this.paths.size > 0 ? Array.from(this.paths, ([scope, paths]) => ({ scope, paths })) : undefined;
89
+ const scopedRootDirs = this.rootDirs.size > 0 ? Array.from(this.rootDirs, ([scope, rootDirs]) => ({ scope, rootDirs })) : undefined;
90
+ this.resolveModule = createCustomModuleResolver({ scopedPaths, scopedRootDirs }, customCompilerExtensions, this.toSourceFilePath, this.findWorkspaceManifestImports);
84
91
  }
85
92
  readFile(filePath) {
86
93
  return this.fileManager.readFile(filePath);
@@ -215,9 +222,10 @@ export class ProjectPrincipal {
215
222
  options = { ...options, isFixExports: false, isFixTypes: false };
216
223
  }
217
224
  }
218
- if (!this._visitor)
219
- this._visitor = buildVisitor(this.pluginVisitorObjects, !!ignoreExportsUsedInFile);
220
- return _getImportsAndExports(filePath, sourceText, this.resolveModule, options, ignoreExportsUsedInFile, skipExports, this._visitor, this.pluginVisitorObjects.length > 0 ? this.pluginCtx : undefined, parseResult);
225
+ const visitor = ignoreExportsUsedInFile
226
+ ? (this._localRefsVisitor ??= buildVisitor(this.pluginVisitorObjects, true))
227
+ : (this._visitor ??= buildVisitor(this.pluginVisitorObjects, false));
228
+ return _getImportsAndExports(filePath, sourceText, this.resolveModule, options, ignoreExportsUsedInFile, skipExports, visitor, this.pluginVisitorObjects.length > 0 ? this.pluginCtx : undefined, parseResult);
221
229
  }
222
230
  invalidateFile(filePath) {
223
231
  this.fileManager.invalidate(filePath);
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ 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';
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../util/parse-args.js';
2
2
  import { pluginArgsMap } from '../plugins.js';
3
3
  import { compact } from '../util/array.js';
4
4
  import { toBinary, toConfig, toDeferResolve, toDeferResolveEntry, toEntry } from '../util/input.js';
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../../util/parse-args.js';
2
2
  import { toBinary, toEntry } from '../../util/input.js';
3
3
  import { isAbsolute, join } from '../../util/path.js';
4
4
  import { _resolveSync } from '../../util/resolve.js';
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../../util/parse-args.js';
2
2
  import { toBinary, toDependency } from '../../util/input.js';
3
3
  import { stripVersionFromSpecifier } from '../../util/modules.js';
4
4
  import { isInternal } from '../../util/path.js';
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../../util/parse-args.js';
2
2
  export const resolve = (_binary, args, options) => {
3
3
  const { fromArgs, manifest } = options;
4
4
  const parsed = parseArgs(args, { '--': true });
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../../util/parse-args.js';
2
2
  import { toBinary, toDependency } from '../../util/input.js';
3
3
  import { stripVersionFromSpecifier } from '../../util/modules.js';
4
4
  import { isInternal } from '../../util/path.js';
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
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
4
  import { resolveDlx } from './pnpx.js';
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../../util/parse-args.js';
2
2
  import { toDependency } from '../../util/input.js';
3
3
  import { stripVersionFromSpecifier } from '../../util/modules.js';
4
4
  export const resolveDlx = (args, options) => {
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ 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';
@@ -1,3 +1,2 @@
1
- import parseArgs from 'minimist';
2
1
  export declare const argsFrom: (args: string[], from: string) => string[];
3
- export declare const parseNodeArgs: (args: string[]) => parseArgs.ParsedArgs;
2
+ export declare const parseNodeArgs: (args: string[]) => import("../util/parse-args.ts").ParsedArgs;
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../util/parse-args.js';
2
2
  export const argsFrom = (args, from) => args.slice(args.indexOf(from));
3
3
  export const parseNodeArgs = (args) => parseArgs(args, {
4
4
  string: ['r'],
@@ -58,6 +58,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
58
58
  entry?: string | string[] | undefined;
59
59
  project?: string | string[] | undefined;
60
60
  } | undefined;
61
+ catalyst?: string | boolean | string[] | {
62
+ config?: string | string[] | undefined;
63
+ entry?: string | string[] | undefined;
64
+ project?: string | string[] | undefined;
65
+ } | undefined;
61
66
  changelogen?: string | boolean | string[] | {
62
67
  config?: string | string[] | undefined;
63
68
  entry?: string | string[] | undefined;
@@ -158,6 +163,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
158
163
  entry?: string | string[] | undefined;
159
164
  project?: string | string[] | undefined;
160
165
  } | undefined;
166
+ fast?: string | boolean | string[] | {
167
+ config?: string | string[] | undefined;
168
+ entry?: string | string[] | undefined;
169
+ project?: string | string[] | undefined;
170
+ } | undefined;
161
171
  gatsby?: string | boolean | string[] | {
162
172
  config?: string | string[] | undefined;
163
173
  entry?: string | string[] | undefined;
@@ -233,6 +243,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
233
243
  entry?: string | string[] | undefined;
234
244
  project?: string | string[] | undefined;
235
245
  } | undefined;
246
+ lit?: string | boolean | string[] | {
247
+ config?: string | string[] | undefined;
248
+ entry?: string | string[] | undefined;
249
+ project?: string | string[] | undefined;
250
+ } | undefined;
236
251
  'lockfile-lint'?: string | boolean | string[] | {
237
252
  config?: string | string[] | undefined;
238
253
  entry?: string | string[] | undefined;
@@ -840,6 +855,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
840
855
  entry?: string | string[] | undefined;
841
856
  project?: string | string[] | undefined;
842
857
  } | undefined;
858
+ catalyst?: string | boolean | string[] | {
859
+ config?: string | string[] | undefined;
860
+ entry?: string | string[] | undefined;
861
+ project?: string | string[] | undefined;
862
+ } | undefined;
843
863
  changelogen?: string | boolean | string[] | {
844
864
  config?: string | string[] | undefined;
845
865
  entry?: string | string[] | undefined;
@@ -940,6 +960,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
940
960
  entry?: string | string[] | undefined;
941
961
  project?: string | string[] | undefined;
942
962
  } | undefined;
963
+ fast?: string | boolean | string[] | {
964
+ config?: string | string[] | undefined;
965
+ entry?: string | string[] | undefined;
966
+ project?: string | string[] | undefined;
967
+ } | undefined;
943
968
  gatsby?: string | boolean | string[] | {
944
969
  config?: string | string[] | undefined;
945
970
  entry?: string | string[] | undefined;
@@ -1015,6 +1040,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1015
1040
  entry?: string | string[] | undefined;
1016
1041
  project?: string | string[] | undefined;
1017
1042
  } | undefined;
1043
+ lit?: string | boolean | string[] | {
1044
+ config?: string | string[] | undefined;
1045
+ entry?: string | string[] | undefined;
1046
+ project?: string | string[] | undefined;
1047
+ } | undefined;
1018
1048
  'lockfile-lint'?: string | boolean | string[] | {
1019
1049
  config?: string | string[] | undefined;
1020
1050
  entry?: string | string[] | undefined;
@@ -1554,6 +1584,7 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1554
1584
  ignoreDependencies?: (string | RegExp)[] | undefined;
1555
1585
  ignoreMembers?: (string | RegExp)[] | undefined;
1556
1586
  ignoreUnresolved?: (string | RegExp)[] | undefined;
1587
+ ignoreExportsUsedInFile?: boolean | Record<string, boolean | undefined> | undefined;
1557
1588
  includeEntryExports?: boolean | undefined;
1558
1589
  }> | undefined;
1559
1590
  syncCompilers: Record<string, true | CompilerSync>;
@@ -11,8 +11,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
11
11
  const shouldIgnore = getShouldIgnoreHandler(options.isProduction);
12
12
  const shouldIgnoreTags = getShouldIgnoreTagHandler(options.tags);
13
13
  const explorer = createGraphExplorer(graph, entryPaths);
14
- const ignoreExportsUsedInFile = chief.config.ignoreExportsUsedInFile;
15
- const isReferencedInUsedExport = (exportedItem, filePath, includeEntryExports, visited) => {
14
+ const isReferencedInUsedExport = (exportedItem, filePath, includeEntryExports, ignoreExportsUsedInFile, visited) => {
16
15
  if (!exportedItem.referencedIn)
17
16
  return false;
18
17
  const file = graph.get(filePath);
@@ -26,7 +25,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
26
25
  !shouldCountRefs(ignoreExportsUsedInFile, inExport.type)) {
27
26
  continue;
28
27
  }
29
- if (inExport.hasRefsInFile)
28
+ if (inExport.hasRefsInFile || inExport.isRegistered)
30
29
  return true;
31
30
  if (explorer.isReferenced(filePath, containingExport, { traverseEntries: includeEntryExports })[0])
32
31
  return true;
@@ -34,7 +33,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
34
33
  const v = visited ?? new Set();
35
34
  if (!v.has(containingExport)) {
36
35
  v.add(containingExport);
37
- if (isReferencedInUsedExport(inExport, filePath, includeEntryExports, v))
36
+ if (isReferencedInUsedExport(inExport, filePath, includeEntryExports, ignoreExportsUsedInFile, v))
38
37
  return true;
39
38
  }
40
39
  }
@@ -50,7 +49,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
50
49
  continue;
51
50
  const workspace = chief.findWorkspaceByFilePath(filePath);
52
51
  if (workspace) {
53
- const { isIncludeEntryExports } = workspace.config;
52
+ const { isIncludeEntryExports, ignoreExportsUsedInFile } = workspace.config;
54
53
  const isEntry = entryPaths.has(filePath);
55
54
  if (!isIncludeEntryExports && isEntry) {
56
55
  continue;
@@ -66,7 +65,8 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
66
65
  traverseEntries: isIncludeEntryExports,
67
66
  });
68
67
  if (isIgnored &&
69
- (isReferenced || isReferencedInUsedExport(exportedItem, filePath, isIncludeEntryExports))) {
68
+ (isReferenced ||
69
+ isReferencedInUsedExport(exportedItem, filePath, isIncludeEntryExports, ignoreExportsUsedInFile))) {
70
70
  for (const tagName of exportedItem.jsDocTags) {
71
71
  if (options.tags[1].includes(tagName) || (isInternalProd && tagName === INTERNAL_TAG)) {
72
72
  collector.addTagHint({ type: 'tag', filePath, identifier, tagName });
@@ -140,7 +140,8 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
140
140
  const isType = ['enum', 'type', 'interface'].includes(exportedItem.type);
141
141
  if (isIgnored ||
142
142
  exportedItem.hasRefsInFile ||
143
- isReferencedInUsedExport(exportedItem, filePath, isIncludeEntryExports) ||
143
+ exportedItem.isRegistered ||
144
+ isReferencedInUsedExport(exportedItem, filePath, isIncludeEntryExports, ignoreExportsUsedInFile) ||
144
145
  (hasStrictlyNsRefs &&
145
146
  ((!options.includedIssueTypes.nsTypes && isType) || !(options.includedIssueTypes.nsExports || isType)))) {
146
147
  continue;
@@ -128,7 +128,8 @@ export async function build({ chief, collector, counselor, deputy, principal, is
128
128
  }
129
129
  for (const dep of getManifestImportDependencies(manifest))
130
130
  deputy.addReferencedDependency(name, dep);
131
- principal.addPaths(config.paths, dir);
131
+ principal.addPaths(config.paths, dir, dir);
132
+ principal.addRootDirs(compilerOptions.rootDirs, dir);
132
133
  const inputsFromPlugins = await worker.runPlugins();
133
134
  for (const id of inputsFromPlugins)
134
135
  inputs.add(Object.assign(id, { skipExportsAnalysis: !id.allowIncludeExports }));
@@ -168,7 +169,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
168
169
  projectFilePatterns.add(toWorkspaceRelative(specifier));
169
170
  }
170
171
  else if (isAlias(input)) {
171
- principal.addPaths({ [input.specifier]: input.prefixes }, input.dir ?? dir);
172
+ principal.addPaths({ [input.specifier]: input.prefixes }, input.dir ?? dir, dir);
172
173
  }
173
174
  else if (isIgnore(input)) {
174
175
  if (input.issueType === 'dependencies' || input.issueType === 'unlisted') {
@@ -302,7 +303,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
302
303
  analyzedFiles.add(filePath);
303
304
  const workspace = chief.findWorkspaceByFilePath(filePath);
304
305
  if (workspace) {
305
- const file = pp.analyzeSourceFile(filePath, analyzeOpts, chief.config.ignoreExportsUsedInFile, parseResult, sourceText, cachedFile);
306
+ const file = pp.analyzeSourceFile(filePath, analyzeOpts, workspace.config.ignoreExportsUsedInFile, parseResult, sourceText, cachedFile);
306
307
  const unresolvedImports = new Set();
307
308
  for (const unresolvedImport of file.imports.unresolved) {
308
309
  const { specifier } = unresolvedImport;
@@ -0,0 +1,7 @@
1
+ import type { PluginVisitorContext, PluginVisitorObject } from '../../types/config.ts';
2
+ interface CustomElementVisitorOptions {
3
+ decoratorName?: string;
4
+ baseClassName?: string;
5
+ }
6
+ export declare function createCustomElementVisitor(ctx: PluginVisitorContext, isRegistrationSpecifier: (specifier: string) => boolean, { decoratorName, baseClassName }?: CustomElementVisitorOptions): PluginVisitorObject;
7
+ export {};
@@ -0,0 +1,106 @@
1
+ function isCustomElementDecorated(node, names, namespaces, decoratorName) {
2
+ const decorators = node.decorators;
3
+ if (!decorators || decorators.length === 0)
4
+ return false;
5
+ for (const decorator of decorators) {
6
+ const expression = decorator.expression;
7
+ if (expression?.type === 'Identifier') {
8
+ if (names.has(expression.name))
9
+ return true;
10
+ continue;
11
+ }
12
+ if (expression?.type !== 'CallExpression')
13
+ continue;
14
+ const callee = expression.callee;
15
+ if (callee.type === 'Identifier') {
16
+ if (names.has(callee.name))
17
+ return true;
18
+ }
19
+ else if (callee.type === 'MemberExpression' &&
20
+ !callee.computed &&
21
+ callee.object.type === 'Identifier' &&
22
+ callee.property.type === 'Identifier' &&
23
+ callee.property.name === decoratorName &&
24
+ namespaces.has(callee.object.name)) {
25
+ return true;
26
+ }
27
+ }
28
+ return false;
29
+ }
30
+ function extendsBaseClass(node, baseNames) {
31
+ const superClass = node.superClass;
32
+ if (!superClass)
33
+ return false;
34
+ if (superClass.type === 'Identifier')
35
+ return baseNames.has(superClass.name);
36
+ if (superClass.type === 'CallExpression') {
37
+ for (const arg of superClass.arguments) {
38
+ if (arg.type === 'Identifier' && baseNames.has(arg.name))
39
+ return true;
40
+ }
41
+ }
42
+ return false;
43
+ }
44
+ export function createCustomElementVisitor(ctx, isRegistrationSpecifier, { decoratorName = 'customElement', baseClassName } = {}) {
45
+ const decoratorNames = new Set();
46
+ const namespaces = new Set();
47
+ const baseNames = new Set();
48
+ const definedClasses = new Set();
49
+ let depth = 0;
50
+ const visitor = {
51
+ Program() {
52
+ decoratorNames.clear();
53
+ namespaces.clear();
54
+ baseNames.clear();
55
+ definedClasses.clear();
56
+ depth = 0;
57
+ },
58
+ BlockStatement() {
59
+ depth++;
60
+ },
61
+ 'BlockStatement:exit'() {
62
+ depth--;
63
+ },
64
+ ImportDeclaration(node) {
65
+ if (!node.source || !isRegistrationSpecifier(node.source.value))
66
+ return;
67
+ for (const spec of node.specifiers ?? []) {
68
+ if (spec.type === 'ImportSpecifier' && spec.imported.type === 'Identifier') {
69
+ if (spec.imported.name === decoratorName)
70
+ decoratorNames.add(spec.local.name);
71
+ else if (baseClassName && spec.imported.name === baseClassName)
72
+ baseNames.add(spec.local.name);
73
+ }
74
+ else if (spec.type === 'ImportNamespaceSpecifier') {
75
+ namespaces.add(spec.local.name);
76
+ }
77
+ }
78
+ },
79
+ ClassDeclaration(node) {
80
+ if (depth !== 0 || !node.id?.name)
81
+ return;
82
+ if (isCustomElementDecorated(node, decoratorNames, namespaces, decoratorName))
83
+ ctx.markExportRegistered(node.id.name);
84
+ else if (baseClassName && extendsBaseClass(node, baseNames))
85
+ definedClasses.add(node.id.name);
86
+ },
87
+ ExportDefaultDeclaration(node) {
88
+ if (node.declaration.type === 'ClassDeclaration' &&
89
+ isCustomElementDecorated(node.declaration, decoratorNames, namespaces, decoratorName))
90
+ ctx.markExportRegistered('default');
91
+ },
92
+ };
93
+ if (baseClassName) {
94
+ visitor.CallExpression = node => {
95
+ const callee = node.callee;
96
+ if (callee.type === 'MemberExpression' &&
97
+ !callee.computed &&
98
+ callee.object.type === 'Identifier' &&
99
+ callee.property.type === 'Identifier' &&
100
+ (callee.property.name === 'define' || callee.property.name === 'defineAsync') &&
101
+ definedClasses.has(callee.object.name))
102
+ ctx.markExportRegistered(callee.object.name);
103
+ };
104
+ }
105
+ return visitor;
106
+ }
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../../util/parse-args.js';
2
2
  import { toDeferResolve, toEntry } from '../../util/input.js';
3
3
  const title = 'Bun';
4
4
  const enablers = ['bun'];
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.ts';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,16 @@
1
+ import { hasDependency } from '../../util/plugin.js';
2
+ import { createCustomElementVisitor } from '../_custom-elements/custom-element-visitor.js';
3
+ const title = 'Catalyst';
4
+ const enablers = ['@github/catalyst'];
5
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
+ const isCatalystSpecifier = (specifier) => specifier === '@github/catalyst';
7
+ const registerVisitors = ({ ctx, registerVisitor }) => {
8
+ registerVisitor(createCustomElementVisitor(ctx, isCatalystSpecifier, { decoratorName: 'controller' }));
9
+ };
10
+ const plugin = {
11
+ title,
12
+ enablers,
13
+ isEnabled,
14
+ registerVisitors,
15
+ };
16
+ export default plugin;
@@ -1,4 +1,4 @@
1
- import { getStringValue, isStringLiteral } from '../../../typescript/ast-nodes.js';
1
+ import { getSafeScriptFromArgs, getStringValue, isStringLiteral } from '../../../typescript/ast-nodes.js';
2
2
  const tags = new Set(['$', '$sync']);
3
3
  const methods = new Set(['execa', 'execaSync', 'execaCommand', 'execaCommandSync', '$sync']);
4
4
  export function createExecaVisitor(ctx) {
@@ -29,22 +29,9 @@ export function createExecaVisitor(ctx) {
29
29
  }
30
30
  }
31
31
  else {
32
- const executable = node.arguments[0];
33
- if (executable && isStringLiteral(executable)) {
34
- const executableStr = getStringValue(executable);
35
- const args = node.arguments[1];
36
- if (args?.type === 'ArrayExpression') {
37
- const argStrings = [];
38
- for (const a of args.elements) {
39
- if (a && isStringLiteral(a))
40
- argStrings.push(getStringValue(a));
41
- }
42
- ctx.addScript([executableStr, ...argStrings].join(' '));
43
- }
44
- else {
45
- ctx.addScript(executableStr);
46
- }
47
- }
32
+ const script = getSafeScriptFromArgs(node.arguments[0], node.arguments[1]);
33
+ if (script)
34
+ ctx.addScript(script);
48
35
  }
49
36
  },
50
37
  };
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.ts';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,16 @@
1
+ import { hasDependency } from '../../util/plugin.js';
2
+ import { createCustomElementVisitor } from '../_custom-elements/custom-element-visitor.js';
3
+ const title = 'FAST';
4
+ const enablers = ['@microsoft/fast-element'];
5
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
+ const isFastSpecifier = (specifier) => specifier === '@microsoft/fast-element';
7
+ const registerVisitors = ({ ctx, registerVisitor }) => {
8
+ registerVisitor(createCustomElementVisitor(ctx, isFastSpecifier, { baseClassName: 'FASTElement' }));
9
+ };
10
+ const plugin = {
11
+ title,
12
+ enablers,
13
+ isEnabled,
14
+ registerVisitors,
15
+ };
16
+ export default plugin;