knip 4.1.0 → 4.2.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 (60) hide show
  1. package/dist/ConfigurationChief.d.ts +14 -12
  2. package/dist/ConfigurationChief.js +37 -25
  3. package/dist/ConfigurationValidator.d.ts +56 -0
  4. package/dist/ConfigurationValidator.js +1 -0
  5. package/dist/DependencyDeputy.d.ts +16 -17
  6. package/dist/DependencyDeputy.js +40 -27
  7. package/dist/IssueFixer.js +1 -1
  8. package/dist/ProjectPrincipal.d.ts +1 -1
  9. package/dist/ProjectPrincipal.js +4 -4
  10. package/dist/WorkspaceWorker.d.ts +15 -23
  11. package/dist/WorkspaceWorker.js +31 -53
  12. package/dist/binaries/bash-parser.d.ts +2 -6
  13. package/dist/binaries/bash-parser.js +5 -5
  14. package/dist/binaries/index.js +2 -4
  15. package/dist/binaries/resolvers/bun.js +2 -3
  16. package/dist/binaries/resolvers/npx.js +4 -5
  17. package/dist/binaries/resolvers/pnpm.js +2 -3
  18. package/dist/binaries/resolvers/yarn.js +3 -4
  19. package/dist/binaries/types.d.ts +7 -11
  20. package/dist/compilers/index.d.ts +13 -3
  21. package/dist/compilers/index.js +3 -8
  22. package/dist/index.js +36 -20
  23. package/dist/manifest/helpers.d.ts +8 -2
  24. package/dist/manifest/helpers.js +14 -1
  25. package/dist/manifest/index.d.ts +3 -8
  26. package/dist/manifest/index.js +6 -21
  27. package/dist/plugins/ava/index.js +2 -6
  28. package/dist/plugins/eleventy/index.js +4 -4
  29. package/dist/plugins/eslint/helpers.d.ts +2 -2
  30. package/dist/plugins/github-actions/index.js +5 -13
  31. package/dist/plugins/husky/index.js +2 -6
  32. package/dist/plugins/index.d.ts +1 -0
  33. package/dist/plugins/index.js +1 -0
  34. package/dist/plugins/lefthook/index.js +3 -3
  35. package/dist/plugins/lint-staged/index.js +1 -2
  36. package/dist/plugins/netlify/helpers.d.ts +2 -0
  37. package/dist/plugins/netlify/helpers.js +4 -0
  38. package/dist/plugins/netlify/index.d.ts +10 -0
  39. package/dist/plugins/netlify/index.js +38 -0
  40. package/dist/plugins/netlify/types.d.ts +11 -0
  41. package/dist/plugins/netlify/types.js +1 -0
  42. package/dist/plugins/nx/index.js +2 -2
  43. package/dist/plugins/release-it/index.js +2 -2
  44. package/dist/plugins/vitest/index.js +7 -8
  45. package/dist/plugins/wireit/index.js +2 -2
  46. package/dist/types/config.d.ts +0 -2
  47. package/dist/types/package-json.d.ts +3 -2
  48. package/dist/types/plugins.d.ts +11 -6
  49. package/dist/types/workspace.d.ts +11 -9
  50. package/dist/typescript/createHosts.js +2 -2
  51. package/dist/util/fs.d.ts +1 -0
  52. package/dist/util/fs.js +5 -0
  53. package/dist/util/loader.js +4 -1
  54. package/dist/util/modules.d.ts +1 -1
  55. package/dist/util/regex.d.ts +0 -1
  56. package/dist/util/regex.js +0 -1
  57. package/dist/version.d.ts +1 -1
  58. package/dist/version.js +1 -1
  59. package/package.json +2 -1
  60. package/schema.json +4 -0
@@ -1,7 +1,6 @@
1
- /// <reference types="npmcli__package-json" />
2
1
  import { createPkgGraph } from '@pnpm/workspace.pkgs-graph';
3
2
  import type { Configuration, WorkspaceConfiguration } from './types/config.js';
4
- import type { PackageJson } from '@npmcli/package-json';
3
+ import type { PackageJson } from './types/package-json.js';
5
4
  type ConfigurationManagerOptions = {
6
5
  cwd: string;
7
6
  isProduction: boolean;
@@ -15,7 +14,6 @@ export type Workspace = {
15
14
  ancestors: string[];
16
15
  config: WorkspaceConfiguration;
17
16
  manifestPath: string;
18
- manifest: PackageJson;
19
17
  };
20
18
  export declare class ConfigurationChief {
21
19
  cwd: string;
@@ -26,7 +24,7 @@ export declare class ConfigurationChief {
26
24
  manifestPath?: string;
27
25
  manifest?: PackageJson;
28
26
  ignoredWorkspacePatterns: string[];
29
- manifestWorkspaces: Map<string, string>;
27
+ workspaceManifests: Map<string, string>;
30
28
  additionalWorkspaceNames: Set<string>;
31
29
  availableWorkspaceNames: string[];
32
30
  availableWorkspacePkgNames: Set<string | undefined>;
@@ -35,8 +33,8 @@ export declare class ConfigurationChief {
35
33
  dir: string;
36
34
  manifest: PackageJson;
37
35
  }[];
38
- workspacesGraph: ReturnType<typeof createPkgGraph> | undefined;
39
- enabledWorkspaces: Workspace[];
36
+ packageGraph: ReturnType<typeof createPkgGraph> | undefined;
37
+ includedWorkspaces: Workspace[];
40
38
  resolvedConfigFilePath?: string;
41
39
  rawConfig?: any;
42
40
  constructor({ cwd, isProduction, isStrict, isIncludeEntryExports }: ConfigurationManagerOptions);
@@ -52,18 +50,23 @@ export declare class ConfigurationChief {
52
50
  private setWorkspaces;
53
51
  private getListedWorkspaces;
54
52
  private getIgnoredWorkspacePatterns;
55
- private getManifestWorkspaces;
53
+ private getWorkspaceManifests;
56
54
  private getConfiguredWorkspaceKeys;
57
55
  private getAdditionalWorkspaceNames;
58
56
  private getAvailableWorkspaceNames;
59
57
  private getAvailableWorkspaceManifests;
60
58
  private getAvailableWorkspacePkgNames;
61
- private getEnabledWorkspaces;
62
- getWorkspaces(): Workspace[];
59
+ private determineIncludedWorkspaces;
60
+ getManifestForWorkspace(dir: string): PackageJson;
61
+ getIncludedWorkspaces(): Workspace[];
63
62
  private getDescendentWorkspaces;
64
63
  private getIgnoredWorkspacesFor;
65
64
  getNegatedWorkspacePatterns(name: string): string[];
66
65
  private getConfigKeyForWorkspace;
66
+ getIgnores(workspaceName: string): {
67
+ ignoreBinaries: (string | RegExp)[];
68
+ ignoreDependencies: (string | RegExp)[];
69
+ };
67
70
  getConfigForWorkspace(workspaceName: string, extensions: string[]): {
68
71
  typescript?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
69
72
  astro?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -87,6 +90,7 @@ export declare class ConfigurationChief {
87
90
  linthtml?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
88
91
  markdownlint?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
89
92
  mocha?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
93
+ netlify?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
90
94
  next?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
91
95
  nx?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
92
96
  nyc?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -121,11 +125,9 @@ export declare class ConfigurationChief {
121
125
  project: string[];
122
126
  paths: any;
123
127
  ignore: string[];
124
- ignoreBinaries: (string | RegExp)[];
125
- ignoreDependencies: (string | RegExp)[];
126
128
  isIncludeEntryExports: any;
127
129
  };
128
- getIssueTypesToReport(): import("./types/issues.js").Report;
130
+ getIncludedIssueTypes(): import("./types/issues.js").Report;
129
131
  findWorkspaceByFilePath(filePath: string): Workspace | undefined;
130
132
  findWorkspaceByName(name: string): Workspace | undefined;
131
133
  getUnusedIgnoredWorkspaces(): string[];
@@ -54,14 +54,14 @@ export class ConfigurationChief {
54
54
  manifestPath;
55
55
  manifest;
56
56
  ignoredWorkspacePatterns = [];
57
- manifestWorkspaces = new Map();
57
+ workspaceManifests = new Map();
58
58
  additionalWorkspaceNames = new Set();
59
59
  availableWorkspaceNames = [];
60
60
  availableWorkspacePkgNames = new Set();
61
61
  availableWorkspaceDirs = [];
62
62
  availableWorkspaceManifests = [];
63
- workspacesGraph;
64
- enabledWorkspaces = [];
63
+ packageGraph;
64
+ includedWorkspaces = [];
65
65
  resolvedConfigFilePath;
66
66
  rawConfig;
67
67
  constructor({ cwd, isProduction, isStrict, isIncludeEntryExports }) {
@@ -112,7 +112,7 @@ export class ConfigurationChief {
112
112
  return this.config.rules;
113
113
  }
114
114
  getFilters() {
115
- if (this.workspacesGraph?.graph && workspaceArg)
115
+ if (this.packageGraph?.graph && workspaceArg)
116
116
  return { dir: join(this.cwd, workspaceArg) };
117
117
  return {};
118
118
  }
@@ -151,7 +151,7 @@ export class ConfigurationChief {
151
151
  }
152
152
  async setWorkspaces() {
153
153
  this.ignoredWorkspacePatterns = this.getIgnoredWorkspacePatterns();
154
- this.manifestWorkspaces = await this.getManifestWorkspaces();
154
+ this.workspaceManifests = await this.getWorkspaceManifests();
155
155
  this.additionalWorkspaceNames = await this.getAdditionalWorkspaceNames();
156
156
  this.availableWorkspaceNames = this.getAvailableWorkspaceNames();
157
157
  this.availableWorkspaceDirs = this.availableWorkspaceNames
@@ -160,8 +160,8 @@ export class ConfigurationChief {
160
160
  .map(dir => join(this.cwd, dir));
161
161
  this.availableWorkspaceManifests = this.getAvailableWorkspaceManifests(this.availableWorkspaceDirs);
162
162
  this.availableWorkspacePkgNames = this.getAvailableWorkspacePkgNames(this.availableWorkspaceManifests);
163
- this.workspacesGraph = createPkgGraph(this.availableWorkspaceManifests);
164
- this.enabledWorkspaces = this.getEnabledWorkspaces();
163
+ this.packageGraph = createPkgGraph(this.availableWorkspaceManifests);
164
+ this.includedWorkspaces = this.determineIncludedWorkspaces();
165
165
  }
166
166
  getListedWorkspaces() {
167
167
  return this.manifest?.workspaces
@@ -176,7 +176,7 @@ export class ConfigurationChief {
176
176
  .map(name => name.replace(/^!/, ''));
177
177
  return [...ignoredWorkspaces, ...this.config.ignoreWorkspaces];
178
178
  }
179
- async getManifestWorkspaces() {
179
+ async getWorkspaceManifests() {
180
180
  const workspaces = await mapWorkspaces({
181
181
  pkg: this.manifest ?? {},
182
182
  cwd: this.cwd,
@@ -200,12 +200,12 @@ export class ConfigurationChief {
200
200
  const dirs = workspaceKeys.filter(key => !key.includes('*'));
201
201
  const globbedDirs = await _dirGlob({ patterns, cwd: this.cwd });
202
202
  return new Set([...dirs, ...globbedDirs].filter(name => name !== ROOT_WORKSPACE_NAME &&
203
- !this.manifestWorkspaces.has(name) &&
203
+ !this.workspaceManifests.has(name) &&
204
204
  !micromatch.isMatch(name, this.ignoredWorkspacePatterns)));
205
205
  }
206
206
  getAvailableWorkspaceNames() {
207
207
  return [
208
- ...new Set([ROOT_WORKSPACE_NAME, ...this.manifestWorkspaces.keys(), ...this.additionalWorkspaceNames]),
208
+ ...new Set([ROOT_WORKSPACE_NAME, ...this.workspaceManifests.keys(), ...this.additionalWorkspaceNames]),
209
209
  ].filter(name => !micromatch.isMatch(name, this.ignoredWorkspacePatterns));
210
210
  }
211
211
  getAvailableWorkspaceManifests(availableWorkspaceDirs) {
@@ -227,7 +227,7 @@ export class ConfigurationChief {
227
227
  }
228
228
  return pkgNames;
229
229
  }
230
- getEnabledWorkspaces() {
230
+ determineIncludedWorkspaces() {
231
231
  if (workspaceArg && !existsSync(workspaceArg)) {
232
232
  throw new ConfigurationError(`Directory does not exist: ${workspaceArg}`);
233
233
  }
@@ -241,7 +241,7 @@ export class ConfigurationChief {
241
241
  const workspaceNames = workspaceArg
242
242
  ? [...this.availableWorkspaceNames.reduce(getAncestors(workspaceArg), []), workspaceArg]
243
243
  : this.availableWorkspaceNames;
244
- const graph = this.workspacesGraph?.graph;
244
+ const graph = this.packageGraph?.graph;
245
245
  const ws = new Set();
246
246
  if (workspaceArg && this.isStrict) {
247
247
  ws.add(workspaceArg);
@@ -249,17 +249,17 @@ export class ConfigurationChief {
249
249
  else if (graph && workspaceArg) {
250
250
  const seen = new Set();
251
251
  const initialWorkspaces = new Set(workspaceNames.map(name => join(this.cwd, name)));
252
- const workspaceDirsWithDependants = new Set(initialWorkspaces);
252
+ const workspaceDirsWithDependents = new Set(initialWorkspaces);
253
253
  const addDependents = (dir) => {
254
254
  seen.add(dir);
255
255
  const deps = graph[dir]?.dependencies ?? [];
256
256
  if (deps.length > 0 && Array.from(initialWorkspaces).some(dir => deps.includes(dir))) {
257
- workspaceDirsWithDependants.add(dir);
257
+ workspaceDirsWithDependents.add(dir);
258
258
  }
259
259
  deps.filter(dir => !seen.has(dir)).forEach(addDependents);
260
260
  };
261
261
  this.availableWorkspaceNames.map(name => join(this.cwd, name)).forEach(addDependents);
262
- workspaceDirsWithDependants.forEach(dir => ws.add(relative(this.cwd, dir) || ROOT_WORKSPACE_NAME));
262
+ workspaceDirsWithDependents.forEach(dir => ws.add(relative(this.cwd, dir) || ROOT_WORKSPACE_NAME));
263
263
  }
264
264
  else {
265
265
  workspaceNames.forEach(name => ws.add(name));
@@ -276,12 +276,14 @@ export class ConfigurationChief {
276
276
  config: this.getConfigForWorkspace(name, DEFAULT_EXTENSIONS),
277
277
  ancestors: this.availableWorkspaceNames.reduce(getAncestors(name), []),
278
278
  manifestPath: join(dir, 'package.json'),
279
- manifest: this.availableWorkspaceManifests?.find(item => item.dir === dir)?.manifest ?? {},
280
279
  };
281
280
  });
282
281
  }
283
- getWorkspaces() {
284
- return this.enabledWorkspaces;
282
+ getManifestForWorkspace(dir) {
283
+ return this.availableWorkspaceManifests?.find(item => item.dir === dir)?.manifest ?? {};
284
+ }
285
+ getIncludedWorkspaces() {
286
+ return this.includedWorkspaces;
285
287
  }
286
288
  getDescendentWorkspaces(name) {
287
289
  return this.availableWorkspaceNames
@@ -307,6 +309,18 @@ export class ConfigurationChief {
307
309
  .reverse()
308
310
  .find(pattern => micromatch.isMatch(workspaceName, pattern));
309
311
  }
312
+ getIgnores(workspaceName) {
313
+ const key = this.getConfigKeyForWorkspace(workspaceName);
314
+ const workspaces = this.rawConfig?.workspaces ?? {};
315
+ const workspaceConfig = (key
316
+ ? key === ROOT_WORKSPACE_NAME && !(ROOT_WORKSPACE_NAME in workspaces)
317
+ ? this.rawConfig
318
+ : workspaces[key]
319
+ : {}) ?? {};
320
+ const ignoreBinaries = arrayify(workspaceConfig.ignoreBinaries).map(toRegexOrString);
321
+ const ignoreDependencies = arrayify(workspaceConfig.ignoreDependencies).map(toRegexOrString);
322
+ return { ignoreBinaries, ignoreDependencies };
323
+ }
310
324
  getConfigForWorkspace(workspaceName, extensions) {
311
325
  const baseConfig = getDefaultWorkspaceConfig(extensions);
312
326
  const key = this.getConfigKeyForWorkspace(workspaceName);
@@ -320,8 +334,6 @@ export class ConfigurationChief {
320
334
  const project = workspaceConfig.project ? arrayify(workspaceConfig.project) : baseConfig.project;
321
335
  const paths = workspaceConfig.paths ?? {};
322
336
  const ignore = arrayify(workspaceConfig.ignore);
323
- const ignoreBinaries = arrayify(workspaceConfig.ignoreBinaries).map(toRegexOrString);
324
- const ignoreDependencies = arrayify(workspaceConfig.ignoreDependencies).map(toRegexOrString);
325
337
  const isIncludeEntryExports = workspaceConfig.includeEntryExports ?? this.config.isIncludeEntryExports;
326
338
  const plugins = {};
327
339
  for (const [name, pluginConfig] of Object.entries(this.config.rootPluginConfigs)) {
@@ -335,9 +347,9 @@ export class ConfigurationChief {
335
347
  plugins[pluginName] = normalizePluginConfig(pluginConfig);
336
348
  }
337
349
  }
338
- return { entry, project, paths, ignore, ignoreBinaries, ignoreDependencies, isIncludeEntryExports, ...plugins };
350
+ return { entry, project, paths, ignore, isIncludeEntryExports, ...plugins };
339
351
  }
340
- getIssueTypesToReport() {
352
+ getIncludedIssueTypes() {
341
353
  const cliArgs = { include, exclude, dependencies, exports };
342
354
  const excludesFromRules = getKeysByValue(this.config.rules, 'off');
343
355
  const config = {
@@ -349,14 +361,14 @@ export class ConfigurationChief {
349
361
  }
350
362
  findWorkspaceByFilePath(filePath) {
351
363
  const workspaceDir = this.availableWorkspaceDirs.find(workspaceDir => filePath.startsWith(workspaceDir + '/'));
352
- return this.enabledWorkspaces.find(workspace => workspace.dir === workspaceDir);
364
+ return this.includedWorkspaces.find(workspace => workspace.dir === workspaceDir);
353
365
  }
354
366
  findWorkspaceByName(name) {
355
- return this.enabledWorkspaces.find(workspace => workspace.name === name);
367
+ return this.includedWorkspaces.find(workspace => workspace.name === name);
356
368
  }
357
369
  getUnusedIgnoredWorkspaces() {
358
370
  const ignoredWorkspaceNames = this.config.ignoreWorkspaces;
359
- const workspaceNames = [...this.manifestWorkspaces.keys(), ...this.additionalWorkspaceNames];
371
+ const workspaceNames = [...this.workspaceManifests.keys(), ...this.additionalWorkspaceNames];
360
372
  return ignoredWorkspaceNames
361
373
  .filter(ignoredWorkspaceName => !workspaceNames.some(name => micromatch.isMatch(name, ignoredWorkspaceName)))
362
374
  .filter(ignoredWorkspaceName => {
@@ -335,6 +335,19 @@ export declare const ConfigurationValidator: z.ZodObject<{
335
335
  entry?: string | string[] | undefined;
336
336
  project?: string | string[] | undefined;
337
337
  }>]>>;
338
+ netlify: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
339
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
340
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
341
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
342
+ }, "strip", z.ZodTypeAny, {
343
+ config?: string | string[] | undefined;
344
+ entry?: string | string[] | undefined;
345
+ project?: string | string[] | undefined;
346
+ }, {
347
+ config?: string | string[] | undefined;
348
+ entry?: string | string[] | undefined;
349
+ project?: string | string[] | undefined;
350
+ }>]>>;
338
351
  next: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
339
352
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
340
353
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -809,6 +822,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
809
822
  entry?: string | string[] | undefined;
810
823
  project?: string | string[] | undefined;
811
824
  } | undefined;
825
+ netlify?: string | boolean | string[] | {
826
+ config?: string | string[] | undefined;
827
+ entry?: string | string[] | undefined;
828
+ project?: string | string[] | undefined;
829
+ } | undefined;
812
830
  next?: string | boolean | string[] | {
813
831
  config?: string | string[] | undefined;
814
832
  entry?: string | string[] | undefined;
@@ -1067,6 +1085,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
1067
1085
  entry?: string | string[] | undefined;
1068
1086
  project?: string | string[] | undefined;
1069
1087
  } | undefined;
1088
+ netlify?: string | boolean | string[] | {
1089
+ config?: string | string[] | undefined;
1090
+ entry?: string | string[] | undefined;
1091
+ project?: string | string[] | undefined;
1092
+ } | undefined;
1070
1093
  next?: string | boolean | string[] | {
1071
1094
  config?: string | string[] | undefined;
1072
1095
  entry?: string | string[] | undefined;
@@ -1502,6 +1525,19 @@ export declare const ConfigurationValidator: z.ZodObject<{
1502
1525
  entry?: string | string[] | undefined;
1503
1526
  project?: string | string[] | undefined;
1504
1527
  }>]>>;
1528
+ netlify: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
1529
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
1530
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
1531
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
1532
+ }, "strip", z.ZodTypeAny, {
1533
+ config?: string | string[] | undefined;
1534
+ entry?: string | string[] | undefined;
1535
+ project?: string | string[] | undefined;
1536
+ }, {
1537
+ config?: string | string[] | undefined;
1538
+ entry?: string | string[] | undefined;
1539
+ project?: string | string[] | undefined;
1540
+ }>]>>;
1505
1541
  next: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
1506
1542
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
1507
1543
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -1992,6 +2028,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
1992
2028
  entry?: string | string[] | undefined;
1993
2029
  project?: string | string[] | undefined;
1994
2030
  } | undefined;
2031
+ netlify?: string | boolean | string[] | {
2032
+ config?: string | string[] | undefined;
2033
+ entry?: string | string[] | undefined;
2034
+ project?: string | string[] | undefined;
2035
+ } | undefined;
1995
2036
  next?: string | boolean | string[] | {
1996
2037
  config?: string | string[] | undefined;
1997
2038
  entry?: string | string[] | undefined;
@@ -2243,6 +2284,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
2243
2284
  entry?: string | string[] | undefined;
2244
2285
  project?: string | string[] | undefined;
2245
2286
  } | undefined;
2287
+ netlify?: string | boolean | string[] | {
2288
+ config?: string | string[] | undefined;
2289
+ entry?: string | string[] | undefined;
2290
+ project?: string | string[] | undefined;
2291
+ } | undefined;
2246
2292
  next?: string | boolean | string[] | {
2247
2293
  config?: string | string[] | undefined;
2248
2294
  entry?: string | string[] | undefined;
@@ -2517,6 +2563,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
2517
2563
  entry?: string | string[] | undefined;
2518
2564
  project?: string | string[] | undefined;
2519
2565
  } | undefined;
2566
+ netlify?: string | boolean | string[] | {
2567
+ config?: string | string[] | undefined;
2568
+ entry?: string | string[] | undefined;
2569
+ project?: string | string[] | undefined;
2570
+ } | undefined;
2520
2571
  next?: string | boolean | string[] | {
2521
2572
  config?: string | string[] | undefined;
2522
2573
  entry?: string | string[] | undefined;
@@ -2768,6 +2819,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
2768
2819
  entry?: string | string[] | undefined;
2769
2820
  project?: string | string[] | undefined;
2770
2821
  } | undefined;
2822
+ netlify?: string | boolean | string[] | {
2823
+ config?: string | string[] | undefined;
2824
+ entry?: string | string[] | undefined;
2825
+ project?: string | string[] | undefined;
2826
+ } | undefined;
2771
2827
  next?: string | boolean | string[] | {
2772
2828
  config?: string | string[] | undefined;
2773
2829
  entry?: string | string[] | undefined;
@@ -85,6 +85,7 @@ const pluginsSchema = z.object({
85
85
  linthtml: pluginSchema,
86
86
  markdownlint: pluginSchema,
87
87
  mocha: pluginSchema,
88
+ netlify: pluginSchema,
88
89
  next: pluginSchema,
89
90
  'node-test-runner': pluginSchema,
90
91
  'npm-package-json-lint': pluginSchema,
@@ -1,8 +1,7 @@
1
- /// <reference types="npmcli__package-json" />
2
1
  import type { Workspace } from './ConfigurationChief.js';
3
2
  import type { ConfigurationHints, Issue } from './types/issues.js';
4
- import type { WorkspaceManifests, HostDependencies, InstalledBinaries } from './types/workspace.js';
5
- import type { PackageJson } from '@npmcli/package-json';
3
+ import type { PackageJson } from './types/package-json.js';
4
+ import type { WorkspaceManifests, HostDependencies, InstalledBinaries, DependencySet, DependencyArray } from './types/workspace.js';
6
5
  type Options = {
7
6
  isProduction: boolean;
8
7
  isStrict: boolean;
@@ -19,43 +18,43 @@ export declare class DependencyDeputy {
19
18
  ignoreBinaries: (string | RegExp)[];
20
19
  ignoreDependencies: (string | RegExp)[];
21
20
  constructor({ isProduction, isStrict }: Options);
22
- addWorkspace({ name, dir, manifestPath, manifest, ignoreDependencies, ignoreBinaries, }: {
21
+ addWorkspace({ name, cwd, dir, manifestPath, manifest, ignoreDependencies, ignoreBinaries, }: {
23
22
  name: string;
23
+ cwd: string;
24
24
  dir: string;
25
25
  manifestPath: string;
26
26
  manifest: PackageJson;
27
27
  ignoreDependencies: (string | RegExp)[];
28
28
  ignoreBinaries: (string | RegExp)[];
29
29
  }): void;
30
- addIgnored(ignoreBinaries: (string | RegExp)[], ignoreDependencies: (string | RegExp)[]): void;
30
+ setIgnored(ignoreBinaries: (string | RegExp)[], ignoreDependencies: (string | RegExp)[]): void;
31
31
  getWorkspaceManifest(workspaceName: string): {
32
32
  workspaceDir: string;
33
33
  manifestPath: string;
34
- scripts: string[];
35
- dependencies: string[];
36
- peerDependencies: string[];
37
- optionalPeerDependencies: string[];
38
- optionalDependencies: string[];
39
- devDependencies: string[];
40
- allDependencies: string[];
34
+ dependencies: DependencyArray;
35
+ devDependencies: DependencyArray;
36
+ peerDependencies: DependencySet;
37
+ optionalPeerDependencies: DependencyArray;
38
+ allDependencies: DependencySet;
41
39
  ignoreDependencies: (string | RegExp)[];
42
40
  ignoreBinaries: (string | RegExp)[];
43
41
  } | undefined;
44
- getProductionDependencies(workspaceName: string): string[];
45
- getDevDependencies(workspaceName: string): string[];
42
+ getProductionDependencies(workspaceName: string): DependencyArray;
43
+ getDevDependencies(workspaceName: string): DependencyArray;
44
+ getDependencies(workspaceName: string): DependencySet;
46
45
  setInstalledBinaries(workspaceName: string, installedBinaries: Map<string, Set<string>>): void;
47
46
  getInstalledBinaries(workspaceName: string): InstalledBinaries | undefined;
48
47
  setHasTypesIncluded(workspaceName: string, hasTypesIncluded: Set<string>): void;
49
48
  getHasTypesIncluded(workspaceName: string): InstalledBinaries | undefined;
50
49
  addReferencedDependency(workspaceName: string, packageName: string): void;
51
50
  addReferencedBinary(workspaceName: string, binaryName: string): void;
52
- addHostDependencies(workspaceName: string, hostDependencies: HostDependencies): void;
51
+ setHostDependencies(workspaceName: string, hostDependencies: HostDependencies): void;
53
52
  getHostDependenciesFor(workspaceName: string, dependency: string): {
54
53
  name: string;
55
54
  isPeerOptional: boolean;
56
55
  }[];
57
- getPeerDependencies(workspaceName: string): string[];
58
- getOptionalPeerDependencies(workspaceName: string): string[];
56
+ getPeerDependencies(workspaceName: string): DependencySet;
57
+ getOptionalPeerDependencies(workspaceName: string): DependencyArray;
59
58
  maybeAddReferencedExternalDependency(workspace: Workspace, packageName: string): boolean;
60
59
  maybeAddReferencedBinary(workspace: Workspace, binaryName: string): boolean;
61
60
  private isInDependencies;
@@ -1,7 +1,8 @@
1
1
  import { isBuiltin } from 'node:module';
2
2
  import { IGNORE_DEFINITELY_TYPED, IGNORED_DEPENDENCIES, IGNORED_GLOBAL_BINARIES, IGNORED_RUNTIME_DEPENDENCIES, ROOT_WORKSPACE_NAME, } from './constants.js';
3
+ import { getDependencyMetaData } from './manifest/index.js';
3
4
  import { isDefinitelyTyped, getDefinitelyTypedFor, getPackageFromDefinitelyTyped } from './util/modules.js';
4
- import { hasMatch, hasMatchInArray, hasMatchInSet, toRegexOrString, findKey } from './util/regex.js';
5
+ import { hasMatch, hasMatchInSet, toRegexOrString, findKey } from './util/regex.js';
5
6
  export class DependencyDeputy {
6
7
  isProduction;
7
8
  isStrict;
@@ -22,8 +23,7 @@ export class DependencyDeputy {
22
23
  this.installedBinaries = new Map();
23
24
  this.hasTypesIncluded = new Map();
24
25
  }
25
- addWorkspace({ name, dir, manifestPath, manifest, ignoreDependencies, ignoreBinaries, }) {
26
- const scripts = Object.values(manifest.scripts ?? {});
26
+ addWorkspace({ name, cwd, dir, manifestPath, manifest, ignoreDependencies, ignoreBinaries, }) {
27
27
  const dependencies = Object.keys(manifest.dependencies ?? {});
28
28
  const peerDependencies = Object.keys(manifest.peerDependencies ?? {});
29
29
  const optionalDependencies = Object.keys(manifest.optionalDependencies ?? {});
@@ -34,21 +34,32 @@ export class DependencyDeputy {
34
34
  : [];
35
35
  const devDependencies = Object.keys(manifest.devDependencies ?? {});
36
36
  const allDependencies = [...dependencies, ...devDependencies, ...peerDependencies, ...optionalDependencies];
37
+ const packageNames = [
38
+ ...dependencies,
39
+ ...(this.isStrict ? peerDependencies : []),
40
+ ...(this.isProduction ? [] : devDependencies),
41
+ ];
42
+ const { hostDependencies, installedBinaries, hasTypesIncluded } = getDependencyMetaData({
43
+ packageNames,
44
+ dir,
45
+ cwd,
46
+ });
47
+ this.setHostDependencies(name, hostDependencies);
48
+ this.setInstalledBinaries(name, installedBinaries);
49
+ this.setHasTypesIncluded(name, hasTypesIncluded);
37
50
  this._manifests.set(name, {
38
51
  workspaceDir: dir,
39
52
  manifestPath,
40
53
  ignoreDependencies,
41
54
  ignoreBinaries,
42
- scripts,
43
55
  dependencies,
44
- peerDependencies,
45
- optionalPeerDependencies,
46
- optionalDependencies,
47
56
  devDependencies,
48
- allDependencies,
57
+ peerDependencies: new Set(peerDependencies),
58
+ optionalPeerDependencies,
59
+ allDependencies: new Set(allDependencies),
49
60
  });
50
61
  }
51
- addIgnored(ignoreBinaries, ignoreDependencies) {
62
+ setIgnored(ignoreBinaries, ignoreDependencies) {
52
63
  this.ignoreBinaries = ignoreBinaries.map(toRegexOrString);
53
64
  this.ignoreDependencies = ignoreDependencies.map(toRegexOrString);
54
65
  }
@@ -66,6 +77,12 @@ export class DependencyDeputy {
66
77
  getDevDependencies(workspaceName) {
67
78
  return this._manifests.get(workspaceName)?.devDependencies ?? [];
68
79
  }
80
+ getDependencies(workspaceName) {
81
+ const manifest = this._manifests.get(workspaceName);
82
+ if (!manifest)
83
+ return new Set();
84
+ return new Set([...manifest.dependencies, ...manifest.devDependencies]);
85
+ }
69
86
  setInstalledBinaries(workspaceName, installedBinaries) {
70
87
  this.installedBinaries.set(workspaceName, installedBinaries);
71
88
  }
@@ -90,16 +107,16 @@ export class DependencyDeputy {
90
107
  }
91
108
  this.referencedBinaries.get(workspaceName)?.add(binaryName);
92
109
  }
93
- addHostDependencies(workspaceName, hostDependencies) {
110
+ setHostDependencies(workspaceName, hostDependencies) {
94
111
  this.hostDependencies.set(workspaceName, hostDependencies);
95
112
  }
96
113
  getHostDependenciesFor(workspaceName, dependency) {
97
- return Array.from(this.hostDependencies.get(workspaceName)?.get(dependency) ?? []);
114
+ return this.hostDependencies.get(workspaceName)?.get(dependency) ?? [];
98
115
  }
99
116
  getPeerDependencies(workspaceName) {
100
117
  const manifest = this._manifests.get(workspaceName);
101
118
  if (!manifest)
102
- return [];
119
+ return new Set();
103
120
  return manifest.peerDependencies;
104
121
  }
105
122
  getOptionalPeerDependencies(workspaceName) {
@@ -158,8 +175,9 @@ export class DependencyDeputy {
158
175
  const manifest = this._manifests.get(workspaceName);
159
176
  if (!manifest)
160
177
  return false;
161
- const dependencies = this.isStrict ? this.getProductionDependencies(workspaceName) : manifest.allDependencies;
162
- return dependencies.includes(packageName);
178
+ if (this.isStrict)
179
+ return this.getProductionDependencies(workspaceName).includes(packageName);
180
+ return manifest.allDependencies.has(packageName);
163
181
  }
164
182
  settleDependencyIssues() {
165
183
  const dependencyIssues = [];
@@ -238,6 +256,7 @@ export class DependencyDeputy {
238
256
  const referencedDependencies = this.referencedDependencies.get(workspaceName);
239
257
  const referencedBinaries = this.referencedBinaries.get(workspaceName);
240
258
  const installedBinaries = this.getInstalledBinaries(workspaceName);
259
+ const installedBinaryNames = new Set(installedBinaries?.keys() ?? []);
241
260
  const ignoredBinaries = this._manifests.get(workspaceName)?.ignoreBinaries ?? [];
242
261
  const ignoredDependencies = this._manifests.get(workspaceName)?.ignoreDependencies ?? [];
243
262
  referencedDependencies?.forEach(pkg => {
@@ -264,10 +283,7 @@ export class DependencyDeputy {
264
283
  });
265
284
  if (workspaceName === ROOT_WORKSPACE_NAME)
266
285
  continue;
267
- const dependencies = [
268
- ...this.getProductionDependencies(workspaceName),
269
- ...this.getDevDependencies(workspaceName),
270
- ];
286
+ const dependencies = this.getDependencies(workspaceName);
271
287
  const peerDependencies = this.getPeerDependencies(workspaceName);
272
288
  ignoreDependencies
273
289
  .filter(packageName => {
@@ -276,7 +292,7 @@ export class DependencyDeputy {
276
292
  if (this.ignoreDependencies.includes(packageName))
277
293
  return true;
278
294
  const isReferenced = hasMatchInSet(referencedDependencies, packageName);
279
- const isListed = hasMatchInArray(dependencies, packageName) && !hasMatchInArray(peerDependencies, packageName);
295
+ const isListed = hasMatchInSet(dependencies, packageName) && !hasMatchInSet(peerDependencies, packageName);
280
296
  return (isListed && isReferenced) || (!this.isProduction && !isReferenced && !isListed);
281
297
  })
282
298
  .forEach(identifier => {
@@ -289,23 +305,20 @@ export class DependencyDeputy {
289
305
  if (this.ignoreBinaries.includes(binaryName))
290
306
  return true;
291
307
  const isReferenced = hasMatchInSet(referencedBinaries, binaryName);
292
- const isInstalled = hasMatchInArray(Array.from(installedBinaries?.keys() ?? []), binaryName);
308
+ const isInstalled = hasMatchInSet(installedBinaryNames, binaryName);
293
309
  return (isReferenced && isInstalled) || (!this.isProduction && !isInstalled && !isReferenced);
294
310
  })
295
311
  .forEach(identifier => configurationHints.add({ workspaceName, identifier, type: 'ignoreBinaries' }));
296
312
  }
297
- const installedBinaries = this.getInstalledBinaries(ROOT_WORKSPACE_NAME);
298
- const dependencies = [
299
- ...this.getProductionDependencies(ROOT_WORKSPACE_NAME),
300
- ...this.getDevDependencies(ROOT_WORKSPACE_NAME),
301
- ];
313
+ const installedBinaryNames = new Set(this.getInstalledBinaries(ROOT_WORKSPACE_NAME)?.keys());
314
+ const dependencies = this.getDependencies(ROOT_WORKSPACE_NAME);
302
315
  const peerDependencies = this.getPeerDependencies(ROOT_WORKSPACE_NAME);
303
316
  Array.from(rootIgnoreDependencies.keys())
304
317
  .filter(packageName => {
305
318
  if (hasMatchInSet(IGNORED_DEPENDENCIES, packageName))
306
319
  return true;
307
320
  const isReferenced = rootIgnoreDependencies.get(packageName) !== 0;
308
- const isListed = hasMatchInArray(dependencies, packageName) && !hasMatchInArray(peerDependencies, packageName);
321
+ const isListed = hasMatchInSet(dependencies, packageName) && !hasMatchInSet(peerDependencies, packageName);
309
322
  return (isReferenced && isListed) || (!this.isProduction && !isReferenced && !isListed);
310
323
  })
311
324
  .forEach(identifier => configurationHints.add({ workspaceName: ROOT_WORKSPACE_NAME, identifier, type: 'ignoreDependencies' }));
@@ -314,7 +327,7 @@ export class DependencyDeputy {
314
327
  if (hasMatchInSet(IGNORED_GLOBAL_BINARIES, binaryName))
315
328
  return true;
316
329
  const isReferenced = rootIgnoreBinaries.get(binaryName) !== 0;
317
- const isInstalled = hasMatchInArray(Array.from(installedBinaries?.keys() ?? []), binaryName);
330
+ const isInstalled = hasMatchInSet(installedBinaryNames, binaryName);
318
331
  return (isReferenced && isInstalled) || (!this.isProduction && !isReferenced && !isInstalled);
319
332
  })
320
333
  .forEach(identifier => configurationHints.add({ workspaceName: ROOT_WORKSPACE_NAME, identifier, type: 'ignoreBinaries' }));
@@ -1,5 +1,5 @@
1
1
  import { readFile, writeFile } from 'fs/promises';
2
- import NPMCliPackageJson from '@npmcli/package-json';
2
+ import NPMCliPackageJson, {} from '@npmcli/package-json';
3
3
  import { dirname, join } from './util/path.js';
4
4
  export class IssueFixer {
5
5
  isEnabled = false;
@@ -46,7 +46,7 @@ export declare class ProjectPrincipal {
46
46
  skipExportsAnalysis: boolean;
47
47
  }): void;
48
48
  addProjectPath(filePath: string): void;
49
- addReferencedDependencies(referencedDependencies: ReferencedDependencies, workspaceName: string): void;
49
+ addReferencedDependencies(workspaceName: string, referencedDependencies: ReferencedDependencies): void;
50
50
  runAsyncCompilers(): Promise<void>;
51
51
  getUsedResolvedFiles(): string[];
52
52
  private getProgramSourceFiles;