knip 5.47.0 → 5.49.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 (82) hide show
  1. package/dist/ConfigurationChief.d.ts +3 -0
  2. package/dist/ProjectPrincipal.d.ts +2 -2
  3. package/dist/ProjectPrincipal.js +9 -7
  4. package/dist/WorkspaceWorker.d.ts +9 -8
  5. package/dist/WorkspaceWorker.js +100 -72
  6. package/dist/cli.js +2 -2
  7. package/dist/compilers/index.d.ts +31 -0
  8. package/dist/graph/analyze.js +0 -2
  9. package/dist/graph/build.js +62 -33
  10. package/dist/plugins/astro/index.d.ts +1 -0
  11. package/dist/plugins/astro/index.js +3 -1
  12. package/dist/plugins/ava/index.js +1 -1
  13. package/dist/plugins/cucumber/index.js +1 -1
  14. package/dist/plugins/cypress/index.js +1 -1
  15. package/dist/plugins/github-actions/index.js +1 -1
  16. package/dist/plugins/index.d.ts +27 -2
  17. package/dist/plugins/index.js +6 -0
  18. package/dist/plugins/jest/index.js +3 -1
  19. package/dist/plugins/ladle/index.js +1 -1
  20. package/dist/plugins/mocha/index.js +2 -2
  21. package/dist/plugins/next/index.d.ts +3 -2
  22. package/dist/plugins/next/index.js +19 -8
  23. package/dist/plugins/next/resolveFromAST.d.ts +2 -0
  24. package/dist/plugins/next/resolveFromAST.js +15 -0
  25. package/dist/plugins/node/index.js +1 -1
  26. package/dist/plugins/nodemon/index.js +1 -1
  27. package/dist/plugins/nuxt/index.d.ts +1 -1
  28. package/dist/plugins/nuxt/index.js +2 -2
  29. package/dist/plugins/playwright/index.js +1 -3
  30. package/dist/plugins/preconstruct/index.js +1 -1
  31. package/dist/plugins/react-cosmos/index.js +1 -1
  32. package/dist/plugins/react-router/index.js +4 -2
  33. package/dist/plugins/sst/index.d.ts +9 -0
  34. package/dist/plugins/sst/index.js +17 -0
  35. package/dist/plugins/sst/resolveFromAST.d.ts +2 -0
  36. package/dist/plugins/sst/resolveFromAST.js +47 -0
  37. package/dist/plugins/starlight/index.d.ts +9 -0
  38. package/dist/plugins/starlight/index.js +18 -0
  39. package/dist/plugins/starlight/resolveFromAST.d.ts +2 -0
  40. package/dist/plugins/starlight/resolveFromAST.js +20 -0
  41. package/dist/plugins/storybook/index.js +5 -2
  42. package/dist/plugins/tanstack-router/index.d.ts +12 -0
  43. package/dist/plugins/tanstack-router/index.js +46 -0
  44. package/dist/plugins/tanstack-router/resolveFromAST.d.ts +2 -0
  45. package/dist/plugins/tanstack-router/resolveFromAST.js +28 -0
  46. package/dist/plugins/tanstack-router/types.d.ts +7 -0
  47. package/dist/plugins/tanstack-router/types.js +1 -0
  48. package/dist/plugins/unbuild/index.js +1 -1
  49. package/dist/plugins/vitest/index.js +1 -1
  50. package/dist/reporters/codeowners.js +8 -6
  51. package/dist/reporters/json.js +3 -3
  52. package/dist/schema/configuration.d.ts +172 -1
  53. package/dist/schema/configuration.js +3 -1
  54. package/dist/schema/plugins.d.ts +69 -0
  55. package/dist/schema/plugins.js +3 -0
  56. package/dist/types/PluginNames.d.ts +2 -2
  57. package/dist/types/PluginNames.js +3 -0
  58. package/dist/types/config.d.ts +8 -0
  59. package/dist/typescript/ast-helpers.d.ts +4 -0
  60. package/dist/typescript/ast-helpers.js +62 -0
  61. package/dist/typescript/create-hosts.d.ts +3 -2
  62. package/dist/typescript/create-hosts.js +1 -3
  63. package/dist/util/Performance.js +7 -7
  64. package/dist/util/codeowners.d.ts +2 -0
  65. package/dist/util/codeowners.js +32 -0
  66. package/dist/util/errors.d.ts +1 -1
  67. package/dist/util/errors.js +2 -2
  68. package/dist/util/glob-core.js +1 -1
  69. package/dist/util/input.d.ts +1 -0
  70. package/dist/util/math.d.ts +6 -0
  71. package/dist/util/math.js +11 -0
  72. package/dist/util/object.d.ts +0 -1
  73. package/dist/util/object.js +0 -16
  74. package/dist/util/package-json.d.ts +1 -3
  75. package/dist/util/package-json.js +28 -5
  76. package/dist/util/plugin.d.ts +0 -2
  77. package/dist/util/plugin.js +1 -14
  78. package/dist/util/to-source-path.js +9 -12
  79. package/dist/version.d.ts +1 -1
  80. package/dist/version.js +1 -1
  81. package/package.json +3 -5
  82. package/schema.json +12 -0
@@ -872,6 +872,32 @@ export declare const pluginsSchema: z.ZodObject<{
872
872
  entry?: string | string[] | undefined;
873
873
  project?: string | string[] | undefined;
874
874
  }>]>;
875
+ sst: z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
876
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
877
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
878
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
879
+ }, "strip", z.ZodTypeAny, {
880
+ config?: string | string[] | undefined;
881
+ entry?: string | string[] | undefined;
882
+ project?: string | string[] | undefined;
883
+ }, {
884
+ config?: string | string[] | undefined;
885
+ entry?: string | string[] | undefined;
886
+ project?: string | string[] | undefined;
887
+ }>]>;
888
+ starlight: z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
889
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
890
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
891
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
892
+ }, "strip", z.ZodTypeAny, {
893
+ config?: string | string[] | undefined;
894
+ entry?: string | string[] | undefined;
895
+ project?: string | string[] | undefined;
896
+ }, {
897
+ config?: string | string[] | undefined;
898
+ entry?: string | string[] | undefined;
899
+ project?: string | string[] | undefined;
900
+ }>]>;
875
901
  storybook: z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
876
902
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
877
903
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -950,6 +976,19 @@ export declare const pluginsSchema: z.ZodObject<{
950
976
  entry?: string | string[] | undefined;
951
977
  project?: string | string[] | undefined;
952
978
  }>]>;
979
+ 'tanstack-router': z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
980
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
981
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
982
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
983
+ }, "strip", z.ZodTypeAny, {
984
+ config?: string | string[] | undefined;
985
+ entry?: string | string[] | undefined;
986
+ project?: string | string[] | undefined;
987
+ }, {
988
+ config?: string | string[] | undefined;
989
+ entry?: string | string[] | undefined;
990
+ project?: string | string[] | undefined;
991
+ }>]>;
953
992
  travis: z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
954
993
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
955
994
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -1541,6 +1580,16 @@ export declare const pluginsSchema: z.ZodObject<{
1541
1580
  entry?: string | string[] | undefined;
1542
1581
  project?: string | string[] | undefined;
1543
1582
  };
1583
+ sst: string | boolean | string[] | {
1584
+ config?: string | string[] | undefined;
1585
+ entry?: string | string[] | undefined;
1586
+ project?: string | string[] | undefined;
1587
+ };
1588
+ starlight: string | boolean | string[] | {
1589
+ config?: string | string[] | undefined;
1590
+ entry?: string | string[] | undefined;
1591
+ project?: string | string[] | undefined;
1592
+ };
1544
1593
  storybook: string | boolean | string[] | {
1545
1594
  config?: string | string[] | undefined;
1546
1595
  entry?: string | string[] | undefined;
@@ -1571,6 +1620,11 @@ export declare const pluginsSchema: z.ZodObject<{
1571
1620
  entry?: string | string[] | undefined;
1572
1621
  project?: string | string[] | undefined;
1573
1622
  };
1623
+ 'tanstack-router': string | boolean | string[] | {
1624
+ config?: string | string[] | undefined;
1625
+ entry?: string | string[] | undefined;
1626
+ project?: string | string[] | undefined;
1627
+ };
1574
1628
  travis: string | boolean | string[] | {
1575
1629
  config?: string | string[] | undefined;
1576
1630
  entry?: string | string[] | undefined;
@@ -2002,6 +2056,16 @@ export declare const pluginsSchema: z.ZodObject<{
2002
2056
  entry?: string | string[] | undefined;
2003
2057
  project?: string | string[] | undefined;
2004
2058
  };
2059
+ sst: string | boolean | string[] | {
2060
+ config?: string | string[] | undefined;
2061
+ entry?: string | string[] | undefined;
2062
+ project?: string | string[] | undefined;
2063
+ };
2064
+ starlight: string | boolean | string[] | {
2065
+ config?: string | string[] | undefined;
2066
+ entry?: string | string[] | undefined;
2067
+ project?: string | string[] | undefined;
2068
+ };
2005
2069
  storybook: string | boolean | string[] | {
2006
2070
  config?: string | string[] | undefined;
2007
2071
  entry?: string | string[] | undefined;
@@ -2032,6 +2096,11 @@ export declare const pluginsSchema: z.ZodObject<{
2032
2096
  entry?: string | string[] | undefined;
2033
2097
  project?: string | string[] | undefined;
2034
2098
  };
2099
+ 'tanstack-router': string | boolean | string[] | {
2100
+ config?: string | string[] | undefined;
2101
+ entry?: string | string[] | undefined;
2102
+ project?: string | string[] | undefined;
2103
+ };
2035
2104
  travis: string | boolean | string[] | {
2036
2105
  config?: string | string[] | undefined;
2037
2106
  entry?: string | string[] | undefined;
@@ -76,12 +76,15 @@ export const pluginsSchema = z.object({
76
76
  sentry: pluginSchema,
77
77
  'simple-git-hooks': pluginSchema,
78
78
  'size-limit': pluginSchema,
79
+ sst: pluginSchema,
80
+ starlight: pluginSchema,
79
81
  storybook: pluginSchema,
80
82
  stryker: pluginSchema,
81
83
  stylelint: pluginSchema,
82
84
  svelte: pluginSchema,
83
85
  syncpack: pluginSchema,
84
86
  tailwind: pluginSchema,
87
+ 'tanstack-router': pluginSchema,
85
88
  travis: pluginSchema,
86
89
  'ts-node': pluginSchema,
87
90
  tsup: pluginSchema,
@@ -1,2 +1,2 @@
1
- export type PluginName = 'angular' | 'astro' | 'ava' | 'babel' | 'c8' | 'capacitor' | 'changesets' | 'commitizen' | 'commitlint' | 'cspell' | 'cucumber' | 'cypress' | 'dependency-cruiser' | 'dotenv' | 'drizzle' | 'eleventy' | 'eslint' | 'expo' | 'gatsby' | 'github-action' | 'github-actions' | 'glob' | 'graphql-codegen' | 'husky' | 'jest' | 'karma' | 'ladle' | 'lefthook' | 'lint-staged' | 'linthtml' | 'lockfile-lint' | 'lost-pixel' | 'markdownlint' | 'metro' | 'mocha' | 'moonrepo' | 'msw' | 'nest' | 'netlify' | 'next' | 'node' | 'nodemon' | 'npm-package-json-lint' | 'nuxt' | 'nx' | 'nyc' | 'oclif' | 'playwright' | 'playwright-ct' | 'playwright-test' | 'plop' | 'postcss' | 'preconstruct' | 'prettier' | 'react-cosmos' | 'react-router' | 'release-it' | 'remark' | 'remix' | 'rollup' | 'rsbuild' | 'rspack' | 'semantic-release' | 'sentry' | 'simple-git-hooks' | 'size-limit' | 'storybook' | 'stryker' | 'stylelint' | 'svelte' | 'syncpack' | 'tailwind' | 'travis' | 'ts-node' | 'tsup' | 'tsx' | 'typedoc' | 'typescript' | 'unbuild' | 'unocss' | 'vercel-og' | 'vike' | 'vite' | 'vitest' | 'vue' | 'webdriver-io' | 'webpack' | 'wireit' | 'wrangler' | 'xo' | 'yarn' | 'yorkie';
2
- export declare const pluginNames: readonly ["angular", "astro", "ava", "babel", "c8", "capacitor", "changesets", "commitizen", "commitlint", "cspell", "cucumber", "cypress", "dependency-cruiser", "dotenv", "drizzle", "eleventy", "eslint", "expo", "gatsby", "github-action", "github-actions", "glob", "graphql-codegen", "husky", "jest", "karma", "ladle", "lefthook", "lint-staged", "linthtml", "lockfile-lint", "lost-pixel", "markdownlint", "metro", "mocha", "moonrepo", "msw", "nest", "netlify", "next", "node", "nodemon", "npm-package-json-lint", "nuxt", "nx", "nyc", "oclif", "playwright", "playwright-ct", "playwright-test", "plop", "postcss", "preconstruct", "prettier", "react-cosmos", "react-router", "release-it", "remark", "remix", "rollup", "rsbuild", "rspack", "semantic-release", "sentry", "simple-git-hooks", "size-limit", "storybook", "stryker", "stylelint", "svelte", "syncpack", "tailwind", "travis", "ts-node", "tsup", "tsx", "typedoc", "typescript", "unbuild", "unocss", "vercel-og", "vike", "vite", "vitest", "vue", "webdriver-io", "webpack", "wireit", "wrangler", "xo", "yarn", "yorkie"];
1
+ export type PluginName = 'angular' | 'astro' | 'ava' | 'babel' | 'c8' | 'capacitor' | 'changesets' | 'commitizen' | 'commitlint' | 'cspell' | 'cucumber' | 'cypress' | 'dependency-cruiser' | 'dotenv' | 'drizzle' | 'eleventy' | 'eslint' | 'expo' | 'gatsby' | 'github-action' | 'github-actions' | 'glob' | 'graphql-codegen' | 'husky' | 'jest' | 'karma' | 'ladle' | 'lefthook' | 'lint-staged' | 'linthtml' | 'lockfile-lint' | 'lost-pixel' | 'markdownlint' | 'metro' | 'mocha' | 'moonrepo' | 'msw' | 'nest' | 'netlify' | 'next' | 'node' | 'nodemon' | 'npm-package-json-lint' | 'nuxt' | 'nx' | 'nyc' | 'oclif' | 'playwright' | 'playwright-ct' | 'playwright-test' | 'plop' | 'postcss' | 'preconstruct' | 'prettier' | 'react-cosmos' | 'react-router' | 'release-it' | 'remark' | 'remix' | 'rollup' | 'rsbuild' | 'rspack' | 'semantic-release' | 'sentry' | 'simple-git-hooks' | 'size-limit' | 'sst' | 'starlight' | 'storybook' | 'stryker' | 'stylelint' | 'svelte' | 'syncpack' | 'tailwind' | 'tanstack-router' | 'travis' | 'ts-node' | 'tsup' | 'tsx' | 'typedoc' | 'typescript' | 'unbuild' | 'unocss' | 'vercel-og' | 'vike' | 'vite' | 'vitest' | 'vue' | 'webdriver-io' | 'webpack' | 'wireit' | 'wrangler' | 'xo' | 'yarn' | 'yorkie';
2
+ export declare const pluginNames: readonly ["angular", "astro", "ava", "babel", "c8", "capacitor", "changesets", "commitizen", "commitlint", "cspell", "cucumber", "cypress", "dependency-cruiser", "dotenv", "drizzle", "eleventy", "eslint", "expo", "gatsby", "github-action", "github-actions", "glob", "graphql-codegen", "husky", "jest", "karma", "ladle", "lefthook", "lint-staged", "linthtml", "lockfile-lint", "lost-pixel", "markdownlint", "metro", "mocha", "moonrepo", "msw", "nest", "netlify", "next", "node", "nodemon", "npm-package-json-lint", "nuxt", "nx", "nyc", "oclif", "playwright", "playwright-ct", "playwright-test", "plop", "postcss", "preconstruct", "prettier", "react-cosmos", "react-router", "release-it", "remark", "remix", "rollup", "rsbuild", "rspack", "semantic-release", "sentry", "simple-git-hooks", "size-limit", "sst", "starlight", "storybook", "stryker", "stylelint", "svelte", "syncpack", "tailwind", "tanstack-router", "travis", "ts-node", "tsup", "tsx", "typedoc", "typescript", "unbuild", "unocss", "vercel-og", "vike", "vite", "vitest", "vue", "webdriver-io", "webpack", "wireit", "wrangler", "xo", "yarn", "yorkie"];
@@ -65,12 +65,15 @@ export const pluginNames = [
65
65
  'sentry',
66
66
  'simple-git-hooks',
67
67
  'size-limit',
68
+ 'sst',
69
+ 'starlight',
68
70
  'storybook',
69
71
  'stryker',
70
72
  'stylelint',
71
73
  'svelte',
72
74
  'syncpack',
73
75
  'tailwind',
76
+ 'tanstack-router',
74
77
  'travis',
75
78
  'ts-node',
76
79
  'tsup',
@@ -1,3 +1,4 @@
1
+ import type ts from 'typescript';
1
2
  import type { z } from 'zod';
2
3
  import type { AsyncCompilers, SyncCompilers } from '../compilers/types.js';
3
4
  import type { knipConfigurationSchema } from '../schema/configuration.js';
@@ -91,6 +92,12 @@ export interface PluginOptions extends BaseOptions {
91
92
  export type ResolveEntryPaths<T = any> = (config: T, options: PluginOptions) => Promise<Input[]> | Input[];
92
93
  export type ResolveConfig<T = any> = (config: T, options: PluginOptions) => Promise<Input[]> | Input[];
93
94
  export type Resolve = (options: PluginOptions) => Promise<Input[]> | Input[];
95
+ export type GetSourceFile = (filePath: string) => ts.SourceFile | undefined;
96
+ export type GetReferencedInternalFilePath = (input: Input) => string | undefined;
97
+ export type ResolveFromAST = (sourceFile: ts.SourceFile, options: PluginOptions & {
98
+ getSourceFile: GetSourceFile;
99
+ getReferencedInternalFilePath: GetReferencedInternalFilePath;
100
+ }) => Input[];
94
101
  export interface Plugin {
95
102
  title: string;
96
103
  args?: Args;
@@ -105,6 +112,7 @@ export interface Plugin {
105
112
  resolveEntryPaths?: ResolveEntryPaths;
106
113
  resolveConfig?: ResolveConfig;
107
114
  resolve?: Resolve;
115
+ resolveFromAST?: ResolveFromAST;
108
116
  }
109
117
  export type PluginMap = Record<PluginName, Plugin>;
110
118
  export type Entries = [PluginName, Plugin][];
@@ -32,3 +32,7 @@ export declare const getExportKeywordNode: (node: ts.Node) => ts.ExportKeyword |
32
32
  export declare const getDefaultKeywordNode: (node: ts.Node) => ts.DefaultKeyword | undefined;
33
33
  export declare const hasRequireCall: (node: ts.Node) => boolean;
34
34
  export declare const isModuleExportsAccess: (node: ts.PropertyAccessExpression) => boolean;
35
+ export declare const getImportMap: (sourceFile: ts.SourceFile) => Map<string, string>;
36
+ export declare const getDefaultImportName: (importMap: ReturnType<typeof getImportMap>, specifier: string) => string | undefined;
37
+ export declare const getPropertyValues: (node: ts.ObjectLiteralExpression, propertyName: string) => Set<string>;
38
+ export declare const getPropertyValueEntries: (node: ts.ObjectLiteralExpression, propertyNames: Set<string>) => [string, string][];
@@ -197,3 +197,65 @@ export const hasRequireCall = (node) => {
197
197
  return node.getChildren().some(child => hasRequireCall(child));
198
198
  };
199
199
  export const isModuleExportsAccess = (node) => ts.isIdentifier(node.expression) && node.expression.escapedText === 'module' && node.name.escapedText === 'exports';
200
+ export const getImportMap = (sourceFile) => {
201
+ const importMap = new Map();
202
+ for (const statement of sourceFile.statements) {
203
+ if (ts.isImportDeclaration(statement)) {
204
+ const importClause = statement.importClause;
205
+ const importPath = stripQuotes(statement.moduleSpecifier.getText());
206
+ if (importClause?.name)
207
+ importMap.set(importClause.name.text, importPath);
208
+ if (importClause?.namedBindings && ts.isNamedImports(importClause.namedBindings)) {
209
+ for (const element of importClause.namedBindings.elements)
210
+ importMap.set(element.name.text, importPath);
211
+ }
212
+ }
213
+ }
214
+ return importMap;
215
+ };
216
+ export const getDefaultImportName = (importMap, specifier) => {
217
+ for (const [importName, importSpecifier] of importMap) {
218
+ if (importSpecifier === specifier)
219
+ return importName;
220
+ }
221
+ };
222
+ export const getPropertyValues = (node, propertyName) => {
223
+ const values = new Set();
224
+ if (ts.isObjectLiteralExpression(node)) {
225
+ const props = node.properties.find(prop => ts.isPropertyAssignment(prop) && prop.name.getText() === propertyName);
226
+ if (props && ts.isPropertyAssignment(props)) {
227
+ const initializer = props.initializer;
228
+ if (ts.isStringLiteral(initializer)) {
229
+ values.add(initializer.text);
230
+ }
231
+ else if (ts.isArrayLiteralExpression(initializer)) {
232
+ for (const element of initializer.elements) {
233
+ if (ts.isStringLiteral(element))
234
+ values.add(element.text);
235
+ }
236
+ }
237
+ else if (ts.isObjectLiteralExpression(initializer)) {
238
+ for (const prop of initializer.properties) {
239
+ if (ts.isPropertyAssignment(prop)) {
240
+ if (ts.isStringLiteral(prop.initializer))
241
+ values.add(prop.initializer.text);
242
+ }
243
+ }
244
+ }
245
+ }
246
+ }
247
+ return values;
248
+ };
249
+ export const getPropertyValueEntries = (node, propertyNames) => {
250
+ const entries = [];
251
+ for (const prop of node.properties) {
252
+ if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {
253
+ if (propertyNames.has(prop.name.text)) {
254
+ if (ts.isStringLiteral(prop.initializer)) {
255
+ entries.push([prop.name.text, prop.initializer.text]);
256
+ }
257
+ }
258
+ }
259
+ }
260
+ return entries;
261
+ };
@@ -1,7 +1,7 @@
1
1
  import ts from 'typescript';
2
2
  import type { AsyncCompilers, SyncCompilers } from '../compilers/types.js';
3
3
  import type { ToSourceFilePath } from '../util/to-source-path.js';
4
- import { SourceFileManager } from './SourceFileManager.js';
4
+ import type { SourceFileManager } from './SourceFileManager.js';
5
5
  type CreateHostsOptions = {
6
6
  cwd: string;
7
7
  compilerOptions: ts.CompilerOptions;
@@ -10,8 +10,9 @@ type CreateHostsOptions = {
10
10
  isSkipLibs: boolean;
11
11
  toSourceFilePath: ToSourceFilePath;
12
12
  useResolverCache: boolean;
13
+ fileManager: SourceFileManager;
13
14
  };
14
- export declare const createHosts: ({ cwd, compilerOptions, entryPaths, compilers, isSkipLibs, toSourceFilePath, useResolverCache, }: CreateHostsOptions) => {
15
+ export declare const createHosts: ({ cwd, compilerOptions, fileManager, entryPaths, compilers, isSkipLibs, toSourceFilePath, useResolverCache, }: CreateHostsOptions) => {
15
16
  fileManager: SourceFileManager;
16
17
  compilerHost: ts.CompilerHost;
17
18
  resolveModuleNames: (moduleNames: string[], containingFile: string) => Array<ts.ResolvedModuleFull | undefined>;
@@ -2,11 +2,9 @@ import { EOL } from 'node:os';
2
2
  import path from 'node:path';
3
3
  import ts from 'typescript';
4
4
  import { getCompilerExtensions } from '../compilers/index.js';
5
- import { SourceFileManager } from './SourceFileManager.js';
6
5
  import { createCustomModuleResolver } from './resolve-module-names.js';
7
6
  const libLocation = path.dirname(ts.getDefaultLibFilePath({}));
8
- export const createHosts = ({ cwd, compilerOptions, entryPaths, compilers, isSkipLibs, toSourceFilePath, useResolverCache, }) => {
9
- const fileManager = new SourceFileManager({ compilers, isSkipLibs });
7
+ export const createHosts = ({ cwd, compilerOptions, fileManager, entryPaths, compilers, isSkipLibs, toSourceFilePath, useResolverCache, }) => {
10
8
  const compilerExtensions = getCompilerExtensions(compilers);
11
9
  const resolveModuleNames = createCustomModuleResolver(compilerOptions, compilerExtensions, toSourceFilePath, useResolverCache, isSkipLibs);
12
10
  const languageServiceHost = {
@@ -3,9 +3,9 @@ import { constants } from 'node:perf_hooks';
3
3
  import { memoryUsage } from 'node:process';
4
4
  import EasyTable from 'easy-table';
5
5
  import prettyMilliseconds from 'pretty-ms';
6
- import Summary from 'summary';
7
6
  import parsedArgValues from './cli-arguments.js';
8
7
  import { debugLog } from './debug.js';
8
+ import { getStats } from './math.js';
9
9
  const { performance: isEnabled = false } = parsedArgValues;
10
10
  export const timerify = (fn, name = fn.name) => {
11
11
  if (!isEnabled)
@@ -71,13 +71,13 @@ class Performance {
71
71
  const entriesByName = this.getEntriesByName();
72
72
  const table = new EasyTable();
73
73
  for (const [name, values] of Object.entries(entriesByName)) {
74
- const stats = new Summary(values);
74
+ const stats = getStats(values);
75
75
  table.cell('Name', name);
76
- table.cell('size', stats.size(), EasyTable.number(0));
77
- table.cell('min', stats.min(), EasyTable.number(2));
78
- table.cell('max', stats.max(), EasyTable.number(2));
79
- table.cell('median', stats.median(), EasyTable.number(2));
80
- table.cell('sum', stats.sum(), EasyTable.number(2));
76
+ table.cell('size', values.length, EasyTable.number(0));
77
+ table.cell('min', stats.min, EasyTable.number(2));
78
+ table.cell('max', stats.max, EasyTable.number(2));
79
+ table.cell('median', stats.median, EasyTable.number(2));
80
+ table.cell('sum', stats.sum, EasyTable.number(2));
81
81
  table.newRow();
82
82
  }
83
83
  table.sort(['sum|des']);
@@ -0,0 +1,2 @@
1
+ export declare function parseCodeowners(content: string): (filePath: string) => string[];
2
+ export declare function createOwnershipEngine(filePath: string): (filePath: string) => string[];
@@ -0,0 +1,32 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import picomatch from 'picomatch';
3
+ import { debugLog } from './debug.js';
4
+ import { convertGitignoreToPicomatchIgnorePatterns } from './glob-core.js';
5
+ export function parseCodeowners(content) {
6
+ const matchers = content
7
+ .split(/\r?\n/)
8
+ .filter(line => line && !line.startsWith('#'))
9
+ .map(rule => {
10
+ const [path, ...owners] = rule.split(/\s+/);
11
+ const { patterns } = convertGitignoreToPicomatchIgnorePatterns(path);
12
+ return { owners, match: picomatch(patterns) };
13
+ });
14
+ return (filePath) => {
15
+ for (const matcher of [...matchers].reverse()) {
16
+ if (matcher.match(filePath)) {
17
+ return matcher.owners;
18
+ }
19
+ }
20
+ return [];
21
+ };
22
+ }
23
+ export function createOwnershipEngine(filePath) {
24
+ try {
25
+ const content = readFileSync(filePath, 'utf8');
26
+ return parseCodeowners(content);
27
+ }
28
+ catch (error) {
29
+ debugLog('*', `Failed to load codeowners file from ${filePath}`);
30
+ throw error;
31
+ }
32
+ }
@@ -7,7 +7,7 @@ export declare class ConfigurationError extends Error {
7
7
  export declare class LoaderError extends Error {
8
8
  }
9
9
  export declare const isKnownError: (error: Error) => error is ConfigurationError | LoaderError | ZodError<any>;
10
- export declare const hasCause: (error: Error) => error is ErrorWithCause;
10
+ export declare const isDisplayReason: (error: Error) => error is ErrorWithCause;
11
11
  export declare const isConfigurationError: (error: Error) => error is ConfigurationError;
12
12
  export declare const getKnownError: (error: Error) => Error;
13
13
  export {};
@@ -1,11 +1,11 @@
1
1
  import { ZodError } from 'zod';
2
- import { fromZodError } from 'zod-validation-error';
2
+ import { fromZodError, isValidationError } from 'zod-validation-error';
3
3
  export class ConfigurationError extends Error {
4
4
  }
5
5
  export class LoaderError extends Error {
6
6
  }
7
7
  export const isKnownError = (error) => error instanceof ConfigurationError || error instanceof LoaderError || error instanceof ZodError;
8
- export const hasCause = (error) => error.cause instanceof Error;
8
+ export const isDisplayReason = (error) => !isValidationError(error) && error.cause instanceof Error;
9
9
  export const isConfigurationError = (error) => error instanceof ConfigurationError;
10
10
  export const getKnownError = (error) => {
11
11
  if (error instanceof ZodError)
@@ -187,7 +187,7 @@ export async function glob(patterns, options) {
187
187
  const ignore = cachedIgnores || compact(_ignore);
188
188
  const { dir, label, ...fgOptions } = { ...options, ignore };
189
189
  const paths = await fg.glob(patterns, fgOptions);
190
- debugLogObject(relative(options.cwd, dir) || ROOT_WORKSPACE_NAME, label ? `Finding ${label} paths` : 'Finding paths', () => ({ patterns, ...fgOptions, ignore: cachedIgnores ? `// identical to ${dir}` : ignore, paths }));
190
+ debugLogObject(relative(options.cwd, dir) || ROOT_WORKSPACE_NAME, label ? `Finding ${label}` : 'Finding paths', () => ({ patterns, ...fgOptions, ignore: cachedIgnores ? `// identical to ${dir}` : ignore, paths }));
191
191
  if (willCache)
192
192
  cachedGlobIgnores.set(options.dir, ignore);
193
193
  return paths;
@@ -7,6 +7,7 @@ export interface Input {
7
7
  optional?: boolean;
8
8
  dir?: string;
9
9
  containingFilePath?: string;
10
+ skipExportsAnalysis?: string;
10
11
  }
11
12
  export interface ConfigInput extends Input {
12
13
  type: 'config';
@@ -0,0 +1,6 @@
1
+ export declare function getStats(values: number[]): {
2
+ min: number;
3
+ max: number;
4
+ sum: number;
5
+ median: number;
6
+ };
@@ -0,0 +1,11 @@
1
+ export function getStats(values) {
2
+ if (values.length === 0)
3
+ return { min: 0, max: 0, sum: 0, median: 0 };
4
+ const sorted = values.toSorted((a, b) => a - b);
5
+ const min = sorted[0];
6
+ const max = sorted[sorted.length - 1];
7
+ const sum = sorted.reduce((a, b) => a + b, 0);
8
+ const mid = Math.floor(sorted.length / 2);
9
+ const median = sorted.length % 2 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
10
+ return { min, max, sum, median };
11
+ }
@@ -1,5 +1,4 @@
1
1
  export declare const getValuesByKeyDeep: (obj: any, key: string) => unknown[];
2
2
  export declare const findByKeyDeep: <T>(obj: any, key: string) => T[];
3
- export declare const getStringValues: (obj: any) => string[];
4
3
  export declare const getKeysByValue: <T>(obj: T, value: unknown) => (keyof T)[];
5
4
  export declare const get: <T>(obj: T, path: string) => any;
@@ -32,22 +32,6 @@ export const findByKeyDeep = (obj, key) => {
32
32
  }
33
33
  return objects;
34
34
  };
35
- export const getStringValues = (obj) => {
36
- if (typeof obj === 'string')
37
- return [obj];
38
- let values = [];
39
- for (const prop in obj) {
40
- if (obj[prop]) {
41
- if (typeof obj[prop] === 'string') {
42
- values.push(obj[prop]);
43
- }
44
- else if (typeof obj[prop] === 'object') {
45
- values = values.concat(getStringValues(obj[prop]));
46
- }
47
- }
48
- }
49
- return values;
50
- };
51
35
  export const getKeysByValue = (obj, value) => {
52
36
  const keys = [];
53
37
  for (const key in obj) {
@@ -7,10 +7,8 @@ interface ExtendedPackageJson extends PackageJson {
7
7
  }
8
8
  export declare const load: (filePath: string) => Promise<ExtendedPackageJson>;
9
9
  export declare const save: (filePath: string, content: ExtendedPackageJson) => Promise<void>;
10
- export declare const getEntryPathsFromManifest: (manifest: PackageJson, sharedGlobOptions: {
10
+ export declare const getEntryPathsFromManifest: (manifest: PackageJson, options: {
11
11
  cwd: string;
12
- dir: string;
13
- gitignore: boolean;
14
12
  ignore: string[];
15
13
  }) => Promise<string[]>;
16
14
  export {};
@@ -1,6 +1,5 @@
1
1
  import { readFile, writeFile } from 'node:fs/promises';
2
2
  import { _glob } from './glob.js';
3
- import { getStringValues } from './object.js';
4
3
  const INDENT = Symbol.for('indent');
5
4
  const NEWLINE = Symbol.for('newline');
6
5
  const DEFAULT_NEWLINE = '\n';
@@ -19,6 +18,23 @@ const parseJson = (raw) => {
19
18
  }
20
19
  return result;
21
20
  };
21
+ const getEntriesFromExports = (obj) => {
22
+ if (typeof obj === 'string')
23
+ return [obj];
24
+ let values = [];
25
+ for (const prop in obj) {
26
+ if (typeof obj[prop] === 'string') {
27
+ values.push(obj[prop]);
28
+ }
29
+ else if (obj[prop] === null) {
30
+ values.push(`!${prop}`);
31
+ }
32
+ else if (typeof obj[prop] === 'object') {
33
+ values = values.concat(getEntriesFromExports(obj[prop]));
34
+ }
35
+ }
36
+ return values;
37
+ };
22
38
  export const load = async (filePath) => {
23
39
  const file = await readFile(filePath, 'utf8');
24
40
  return parseJson(file);
@@ -30,7 +46,7 @@ export const save = async (filePath, content) => {
30
46
  const fileContent = `${JSON.stringify(content, null, space)}\n`.replace(/\n/g, EOL);
31
47
  await writeFile(filePath, fileContent);
32
48
  };
33
- export const getEntryPathsFromManifest = (manifest, sharedGlobOptions) => {
49
+ export const getEntryPathsFromManifest = (manifest, options) => {
34
50
  const { main, module, browser, bin, exports, types, typings } = manifest;
35
51
  const entryPaths = new Set();
36
52
  if (typeof main === 'string')
@@ -47,12 +63,19 @@ export const getEntryPathsFromManifest = (manifest, sharedGlobOptions) => {
47
63
  entryPaths.add(id);
48
64
  }
49
65
  if (exports) {
50
- for (const item of getStringValues(exports))
51
- entryPaths.add(item);
66
+ for (const item of getEntriesFromExports(exports)) {
67
+ if (item === './*')
68
+ continue;
69
+ const expanded = item
70
+ .replace(/\/\*$/, '/**')
71
+ .replace(/\/\*\./, '/**/*.')
72
+ .replace(/\/\*\//, '/**/');
73
+ entryPaths.add(expanded);
74
+ }
52
75
  }
53
76
  if (typeof types === 'string')
54
77
  entryPaths.add(types);
55
78
  if (typeof typings === 'string')
56
79
  entryPaths.add(typings);
57
- return _glob({ ...sharedGlobOptions, patterns: Array.from(entryPaths), label: 'package.json entry' });
80
+ return _glob({ patterns: Array.from(entryPaths), ...options, gitignore: false, label: 'package.json entry paths' });
58
81
  };
@@ -1,6 +1,5 @@
1
1
  export { _load as load } from './loader.js';
2
2
  import type { Plugin, PluginOptions, RawPluginConfiguration } from '../types/config.js';
3
- import { type Input } from './input.js';
4
3
  export declare const hasDependency: (dependencies: Set<string>, values: (string | RegExp)[]) => boolean;
5
4
  export declare const normalizePluginConfig: (pluginConfig: RawPluginConfiguration) => boolean | {
6
5
  config: string[] | null;
@@ -8,4 +7,3 @@ export declare const normalizePluginConfig: (pluginConfig: RawPluginConfiguratio
8
7
  project: string[] | null;
9
8
  };
10
9
  export declare const loadConfigForPlugin: (configFilePath: string, plugin: Plugin, options: PluginOptions, pluginName: string) => Promise<any>;
11
- export declare const getFinalEntryPaths: (plugin: Plugin, options: PluginOptions, configEntryPaths: Input[]) => Input[];
@@ -1,6 +1,5 @@
1
1
  export { _load as load } from './loader.js';
2
2
  import { arrayify } from './array.js';
3
- import { toEntry, toProductionEntry } from './input.js';
4
3
  import { _load as load } from './loader.js';
5
4
  import { get } from './object.js';
6
5
  import { basename } from './path.js';
@@ -35,21 +34,9 @@ export const normalizePluginConfig = (pluginConfig) => {
35
34
  export const loadConfigForPlugin = async (configFilePath, plugin, options, pluginName) => {
36
35
  const { packageJsonPath } = plugin;
37
36
  const { manifest } = options;
38
- const localConfig = basename(configFilePath) === 'package.json'
37
+ return basename(configFilePath) === 'package.json'
39
38
  ? typeof packageJsonPath === 'function'
40
39
  ? packageJsonPath(manifest)
41
40
  : get(manifest, packageJsonPath ?? pluginName)
42
41
  : await load(configFilePath);
43
- return localConfig;
44
- };
45
- export const getFinalEntryPaths = (plugin, options, configEntryPaths) => {
46
- const { config, isProduction } = options;
47
- if (plugin.title === 'Storybook')
48
- return [...(config.entry ?? []).map(toEntry), ...configEntryPaths];
49
- const toEntryPathProtocol = isProduction && plugin.production && plugin.production.length > 0 ? toProductionEntry : toEntry;
50
- if (config.entry)
51
- return config.entry.map(id => toEntryPathProtocol(id));
52
- if (configEntryPaths.length > 0)
53
- return configEntryPaths;
54
- return [...(plugin.entry ?? []).map(toEntry), ...(plugin.production ?? []).map(id => toProductionEntry(id))];
55
42
  };
@@ -14,25 +14,22 @@ export const augmentWorkspace = (workspace, dir, compilerOptions) => {
14
14
  };
15
15
  export const getToSourcePathHandler = (chief) => {
16
16
  const toSourceMapCache = new Map();
17
- const toSourcePath = (filePath) => {
17
+ return (filePath) => {
18
18
  if (!isInternal(filePath) || hasJSExt.test(filePath) || hasTSExt.test(filePath))
19
19
  return;
20
20
  if (toSourceMapCache.has(filePath))
21
21
  return toSourceMapCache.get(filePath);
22
22
  const workspace = chief.findWorkspaceByFilePath(filePath);
23
- if (workspace) {
24
- if (workspace.srcDir && workspace.outDir) {
25
- if (filePath.startsWith(workspace.outDir)) {
26
- const pattern = filePath.replace(workspace.outDir, workspace.srcDir).replace(matchExt, defaultExtensions);
27
- const [srcFilePath] = fastGlob.sync(pattern);
28
- toSourceMapCache.set(filePath, srcFilePath);
29
- if (srcFilePath && srcFilePath !== filePath) {
30
- debugLog('*', `Rewiring ${toRelative(filePath)} → ${toRelative(srcFilePath)}`);
31
- return srcFilePath;
32
- }
23
+ if (workspace?.srcDir && workspace.outDir) {
24
+ if (filePath.startsWith(workspace.outDir)) {
25
+ const pattern = filePath.replace(workspace.outDir, workspace.srcDir).replace(matchExt, defaultExtensions);
26
+ const [srcFilePath] = fastGlob.sync(pattern);
27
+ toSourceMapCache.set(filePath, srcFilePath);
28
+ if (srcFilePath && srcFilePath !== filePath) {
29
+ debugLog('*', `Source mapping ${toRelative(filePath)} → ${toRelative(srcFilePath)}`);
30
+ return srcFilePath;
33
31
  }
34
32
  }
35
33
  }
36
34
  };
37
- return toSourcePath;
38
35
  };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.47.0";
1
+ export declare const version = "5.49.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.47.0';
1
+ export const version = '5.49.0';