fork-ts-checker-webpack-plugin 9.1.1 → 10.0.0-alpha.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 (117) hide show
  1. package/README.md +23 -13
  2. package/lib/files-change.js +5 -6
  3. package/lib/formatter/basic-formatter.js +3 -4
  4. package/lib/formatter/code-frame-formatter.d.ts +3 -2
  5. package/lib/formatter/code-frame-formatter.js +14 -5
  6. package/lib/formatter/formatter-config.js +3 -3
  7. package/lib/formatter/formatter-options.d.ts +1 -1
  8. package/lib/formatter/stats-formatter.js +4 -5
  9. package/lib/formatter/webpack-formatter.js +6 -11
  10. package/lib/hooks/intercept-done-to-get-dev-server-tap.js +1 -2
  11. package/lib/hooks/report-issues.d.ts +8 -0
  12. package/lib/hooks/report-issues.js +22 -0
  13. package/lib/hooks/tap-after-compile-to-add-dependencies.js +4 -14
  14. package/lib/hooks/tap-after-compile-to-get-issues.js +7 -29
  15. package/lib/hooks/tap-after-environment-to-patch-watching.js +1 -2
  16. package/lib/hooks/tap-done-to-async-get-issues.js +13 -34
  17. package/lib/hooks/tap-error-to-log-message.js +6 -9
  18. package/lib/hooks/tap-start-to-run-workers.js +13 -24
  19. package/lib/hooks/tap-stop-to-terminate-workers.js +1 -2
  20. package/lib/infrastructure-logger.js +1 -2
  21. package/lib/issue/issue-config.js +1 -2
  22. package/lib/issue/issue-location.js +2 -3
  23. package/lib/issue/issue-match.js +3 -4
  24. package/lib/issue/issue-position.js +1 -2
  25. package/lib/issue/issue-predicate.js +2 -3
  26. package/lib/issue/issue-severity.js +2 -3
  27. package/lib/issue/issue-webpack-error.js +21 -18
  28. package/lib/issue/issue.js +2 -3
  29. package/lib/plugin-config.js +1 -2
  30. package/lib/plugin-hooks.d.ts +4 -4
  31. package/lib/plugin-hooks.js +1 -2
  32. package/lib/plugin-options.json +4 -8
  33. package/lib/plugin-pools.js +17 -7
  34. package/lib/plugin-state.d.ts +0 -1
  35. package/lib/plugin-state.js +1 -2
  36. package/lib/plugin.d.ts +2 -2
  37. package/lib/plugin.js +39 -24
  38. package/lib/rpc/expose-rpc.js +6 -16
  39. package/lib/rpc/rpc-error.js +2 -0
  40. package/lib/rpc/rpc-worker.d.ts +1 -2
  41. package/lib/rpc/rpc-worker.js +26 -17
  42. package/lib/rpc/wrap-rpc.d.ts +0 -1
  43. package/lib/rpc/wrap-rpc.js +4 -14
  44. package/lib/typescript/type-script-package.d.ts +4 -0
  45. package/lib/typescript/type-script-package.js +88 -0
  46. package/lib/typescript/type-script-support.js +26 -27
  47. package/lib/typescript/type-script-worker-config.d.ts +2 -3
  48. package/lib/typescript/type-script-worker-config.js +24 -4
  49. package/lib/typescript/type-script-worker-options.d.ts +4 -3
  50. package/lib/typescript/type-script-worker-options.js +4 -0
  51. package/lib/typescript/worker/get-dependencies-worker.js +15 -4
  52. package/lib/typescript/worker/get-issues-worker.d.ts +1 -1
  53. package/lib/typescript/worker/get-issues-worker.js +52 -64
  54. package/lib/typescript/worker/lib/api.d.ts +13 -0
  55. package/lib/typescript/worker/lib/api.js +62 -0
  56. package/lib/typescript/worker/lib/config.d.ts +13 -9
  57. package/lib/typescript/worker/lib/config.js +93 -65
  58. package/lib/typescript/worker/lib/dependencies.d.ts +6 -1
  59. package/lib/typescript/worker/lib/dependencies.js +187 -53
  60. package/lib/typescript/worker/lib/diagnostics.d.ts +5 -4
  61. package/lib/typescript/worker/lib/diagnostics.js +67 -51
  62. package/lib/typescript/worker/lib/in-memory-file-system.d.ts +14 -0
  63. package/lib/typescript/worker/lib/in-memory-file-system.js +140 -0
  64. package/lib/typescript/worker/lib/performance.d.ts +1 -2
  65. package/lib/typescript/worker/lib/performance.js +13 -21
  66. package/lib/typescript/worker/lib/program/program.d.ts +6 -2
  67. package/lib/typescript/worker/lib/program/program.js +136 -26
  68. package/lib/typescript/worker/lib/program/solution-builder.d.ts +3 -1
  69. package/lib/typescript/worker/lib/program/solution-builder.js +43 -27
  70. package/lib/typescript/worker/lib/typescript.d.ts +4 -2
  71. package/lib/typescript/worker/lib/typescript.js +69 -3
  72. package/lib/utils/async/abort-error.d.ts +0 -1
  73. package/lib/utils/async/abort-error.js +1 -1
  74. package/lib/utils/async/controlled-promise.js +1 -2
  75. package/lib/utils/async/is-pending.js +1 -2
  76. package/lib/utils/async/pool.d.ts +0 -1
  77. package/lib/utils/async/pool.js +13 -25
  78. package/lib/utils/async/wait.js +1 -2
  79. package/lib/utils/deep-merge.d.ts +5 -0
  80. package/lib/utils/deep-merge.js +56 -0
  81. package/lib/utils/path/format-file-path.d.ts +3 -0
  82. package/lib/utils/path/format-file-path.js +15 -0
  83. package/lib/utils/path/forward-slash.js +1 -2
  84. package/lib/utils/path/is-inside-another-path.js +1 -2
  85. package/lib/utils/path/relative-to-context.js +1 -2
  86. package/lib/watch/inclusive-node-watch-file-system.d.ts +3 -0
  87. package/lib/watch/inclusive-node-watch-file-system.js +121 -113
  88. package/lib/watch/watch-file-system.d.ts +0 -1
  89. package/package.json +43 -53
  90. package/lib/formatter/types/babel__code-frame.d.ts +0 -21
  91. package/lib/formatter/types/babel__code-frame.js +0 -7
  92. package/lib/typescript/worker/lib/artifacts.d.ts +0 -4
  93. package/lib/typescript/worker/lib/artifacts.js +0 -94
  94. package/lib/typescript/worker/lib/emit.d.ts +0 -2
  95. package/lib/typescript/worker/lib/emit.js +0 -13
  96. package/lib/typescript/worker/lib/file-system/file-system.d.ts +0 -18
  97. package/lib/typescript/worker/lib/file-system/file-system.js +0 -2
  98. package/lib/typescript/worker/lib/file-system/mem-file-system.d.ts +0 -5
  99. package/lib/typescript/worker/lib/file-system/mem-file-system.js +0 -78
  100. package/lib/typescript/worker/lib/file-system/passive-file-system.d.ts +0 -5
  101. package/lib/typescript/worker/lib/file-system/passive-file-system.js +0 -65
  102. package/lib/typescript/worker/lib/file-system/real-file-system.d.ts +0 -5
  103. package/lib/typescript/worker/lib/file-system/real-file-system.js +0 -191
  104. package/lib/typescript/worker/lib/host/compiler-host.d.ts +0 -2
  105. package/lib/typescript/worker/lib/host/compiler-host.js +0 -10
  106. package/lib/typescript/worker/lib/host/watch-compiler-host.d.ts +0 -2
  107. package/lib/typescript/worker/lib/host/watch-compiler-host.js +0 -20
  108. package/lib/typescript/worker/lib/host/watch-solution-builder-host.d.ts +0 -2
  109. package/lib/typescript/worker/lib/host/watch-solution-builder-host.js +0 -47
  110. package/lib/typescript/worker/lib/program/watch-program.d.ts +0 -3
  111. package/lib/typescript/worker/lib/program/watch-program.js +0 -51
  112. package/lib/typescript/worker/lib/system.d.ts +0 -19
  113. package/lib/typescript/worker/lib/system.js +0 -232
  114. package/lib/typescript/worker/lib/tracing.d.ts +0 -4
  115. package/lib/typescript/worker/lib/tracing.js +0 -29
  116. package/lib/typescript/worker/lib/tsbuildinfo.d.ts +0 -4
  117. package/lib/typescript/worker/lib/tsbuildinfo.js +0 -96
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.interceptBuildOutputs = interceptBuildOutputs;
4
+ exports.invalidateRealDirectories = invalidateRealDirectories;
5
+ exports.getApi = getApi;
6
+ exports.createBuildOrchestrator = createBuildOrchestrator;
7
+ exports.closeApi = closeApi;
8
+ const in_memory_file_system_1 = require("./in-memory-file-system");
9
+ const typescript_1 = require("./typescript");
10
+ const worker_config_1 = require("./worker-config");
11
+ let api;
12
+ let invalidateRealDirectoriesOfApi;
13
+ let interceptsBuildOutputs = false;
14
+ /**
15
+ * Makes the API keep build-mode outputs in memory in the `in-memory` mode. Only
16
+ * the worker that builds needs it: the callbacks are round trips from the native
17
+ * compiler, which a worker that only parses tsconfig files would pay for nothing.
18
+ * Call it before the first `getApi()`.
19
+ */
20
+ function interceptBuildOutputs() {
21
+ interceptsBuildOutputs = true;
22
+ }
23
+ /** Forgets the resolved symlinks, in case packages were relinked between builds. */
24
+ function invalidateRealDirectories() {
25
+ invalidateRealDirectoriesOfApi?.();
26
+ }
27
+ function getApi() {
28
+ if (!api) {
29
+ // only `build` lets TypeScript decide what to write, and the `write` mode lets it;
30
+ // the outputs live in the callbacks' closure, so they go with the API
31
+ const fileSystem = interceptsBuildOutputs && worker_config_1.config.build && worker_config_1.config.mode === 'in-memory'
32
+ ? (0, in_memory_file_system_1.createInMemoryFileSystem)()
33
+ : undefined;
34
+ invalidateRealDirectoriesOfApi = fileSystem?.invalidateRealDirectories;
35
+ api = new typescript_1.typescriptSync.API({
36
+ cwd: worker_config_1.config.context,
37
+ fs: fileSystem?.callbacks,
38
+ collectTiming: worker_config_1.config.profile,
39
+ });
40
+ }
41
+ return api;
42
+ }
43
+ function createBuildOrchestrator(rootNames, options) {
44
+ const create = getApi()
45
+ .createBuildOrchestrator;
46
+ if (typeof create !== 'function') {
47
+ throw new Error('The installed TypeScript version does not support the `build` option (missing API#createBuildOrchestrator).');
48
+ }
49
+ return create.call(api, rootNames, options);
50
+ }
51
+ function closeApi() {
52
+ invalidateRealDirectoriesOfApi = undefined;
53
+ if (api) {
54
+ try {
55
+ api.close();
56
+ }
57
+ catch (error) {
58
+ // the compiler process may already be gone
59
+ }
60
+ api = undefined;
61
+ }
62
+ }
@@ -1,15 +1,19 @@
1
- import type * as ts from 'typescript';
1
+ import type { ParsedCommandLine } from 'typescript/sync';
2
2
  import type { FilesChange } from '../../../files-change';
3
3
  import type { FilesMatch } from '../../../files-match';
4
4
  import type { Issue } from '../../../issue';
5
- export declare function parseConfig(configFileName: string, configFileContext: string): ts.ParsedCommandLine;
5
+ /**
6
+ * The implicit overrides that apply both to a program and to the build
7
+ * orchestrator, which only accepts a small set of options.
8
+ */
9
+ export declare function getSharedImplicitCompilerOptions(): {
10
+ sourceMap: boolean;
11
+ inlineSourceMap: boolean;
12
+ };
13
+ export declare function parseConfig(configFileName: string, configFileContext: string): ParsedCommandLine;
6
14
  export declare function getParseConfigIssues(): Issue[];
7
- export declare function getParsedConfig(force?: boolean): ts.ParsedCommandLine;
8
- export declare function parseNextConfig(): readonly [ts.ParsedCommandLine | undefined, ts.ParsedCommandLine];
15
+ export declare function getParsedConfig(): ParsedCommandLine;
9
16
  export declare function invalidateConfig(): void;
10
- export declare function getConfigFilePathFromCompilerOptions(compilerOptions: ts.CompilerOptions): string;
11
- export declare function getConfigFilePathFromProgram(program: ts.Program): string;
12
- export declare function getConfigFilePathFromBuilderProgram(builderProgram: ts.BuilderProgram): string;
13
- export declare function didConfigFileChanged({ changedFiles, deletedFiles }: FilesChange): boolean;
17
+ export declare function didConfigFileChanged(configFiles: readonly string[], { changedFiles, deletedFiles }: FilesChange): boolean;
14
18
  export declare function didDependenciesProbablyChanged(dependencies: FilesMatch, { changedFiles, deletedFiles }: FilesChange): boolean;
15
- export declare function didRootFilesChanged(): boolean | undefined;
19
+ export declare function didRootFilesChanged(previousRootFiles: readonly string[]): boolean;
@@ -15,66 +15,117 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.didRootFilesChanged = exports.didDependenciesProbablyChanged = exports.didConfigFileChanged = exports.getConfigFilePathFromBuilderProgram = exports.getConfigFilePathFromProgram = exports.getConfigFilePathFromCompilerOptions = exports.invalidateConfig = exports.parseNextConfig = exports.getParsedConfig = exports.getParseConfigIssues = exports.parseConfig = void 0;
36
+ exports.getSharedImplicitCompilerOptions = getSharedImplicitCompilerOptions;
37
+ exports.parseConfig = parseConfig;
38
+ exports.getParseConfigIssues = getParseConfigIssues;
39
+ exports.getParsedConfig = getParsedConfig;
40
+ exports.invalidateConfig = invalidateConfig;
41
+ exports.didConfigFileChanged = didConfigFileChanged;
42
+ exports.didDependenciesProbablyChanged = didDependenciesProbablyChanged;
43
+ exports.didRootFilesChanged = didRootFilesChanged;
27
44
  const path = __importStar(require("path"));
28
- const forward_slash_1 = require("../../../utils/path/forward-slash");
45
+ const api_1 = require("./api");
29
46
  const diagnostics_1 = require("./diagnostics");
30
- const system_1 = require("./system");
31
- const typescript_1 = require("./typescript");
32
47
  const worker_config_1 = require("./worker-config");
33
48
  let parsedConfig;
34
49
  let parseConfigDiagnostics = [];
35
- // initialize ParseConfigFileHost
36
- const parseConfigFileHost = Object.assign(Object.assign({}, system_1.system), { onUnRecoverableConfigFileDiagnostic: (diagnostic) => {
37
- parseConfigDiagnostics.push(diagnostic);
38
- } });
39
50
  function getUserProvidedConfigOverwrite() {
40
51
  return worker_config_1.config.configOverwrite || {};
41
52
  }
53
+ /**
54
+ * The implicit overrides that apply both to a program and to the build
55
+ * orchestrator, which only accepts a small set of options.
56
+ */
57
+ function getSharedImplicitCompilerOptions() {
58
+ return {
59
+ sourceMap: false,
60
+ inlineSourceMap: false,
61
+ };
62
+ }
42
63
  function getImplicitConfigOverwrite() {
43
64
  const baseCompilerOptionsOverwrite = {
44
65
  skipLibCheck: true,
45
- sourceMap: false,
46
- inlineSourceMap: false,
66
+ ...getSharedImplicitCompilerOptions(),
47
67
  };
48
- switch (worker_config_1.config.mode) {
49
- case 'write-dts':
50
- return {
51
- compilerOptions: Object.assign(Object.assign({}, baseCompilerOptionsOverwrite), { declaration: true, emitDeclarationOnly: true, noEmit: false }),
52
- };
53
- case 'write-tsbuildinfo':
54
- case 'write-references':
55
- return {
56
- compilerOptions: Object.assign(Object.assign({}, baseCompilerOptionsOverwrite), { declaration: true, emitDeclarationOnly: false, noEmit: false }),
57
- };
68
+ if (worker_config_1.config.mode === 'write') {
69
+ return {
70
+ compilerOptions: {
71
+ ...baseCompilerOptionsOverwrite,
72
+ declaration: true,
73
+ // `build` writes everything, like `tsc --build` - a program only the declarations
74
+ emitDeclarationOnly: !worker_config_1.config.build,
75
+ noEmit: false,
76
+ },
77
+ };
58
78
  }
59
79
  return {
60
- compilerOptions: baseCompilerOptionsOverwrite,
80
+ compilerOptions: {
81
+ ...baseCompilerOptionsOverwrite,
82
+ // nothing is emitted, and without it emit-only option diagnostics
83
+ // (like TS5011 for a missing `rootDir`) are reported, unlike `tsc --noEmit`
84
+ noEmit: true,
85
+ },
61
86
  };
62
87
  }
63
88
  function applyConfigOverwrite(baseConfig, ...overwriteConfigs) {
64
89
  let config = baseConfig;
65
90
  for (const overwriteConfig of overwriteConfigs) {
66
- config = Object.assign(Object.assign(Object.assign({}, (config || {})), (overwriteConfig || {})), { compilerOptions: Object.assign(Object.assign({}, ((config === null || config === void 0 ? void 0 : config.compilerOptions) || {})), ((overwriteConfig === null || overwriteConfig === void 0 ? void 0 : overwriteConfig.compilerOptions) || {})) });
91
+ config = {
92
+ ...(config || {}),
93
+ ...(overwriteConfig || {}),
94
+ compilerOptions: {
95
+ ...(config?.compilerOptions || {}),
96
+ ...(overwriteConfig?.compilerOptions || {}),
97
+ },
98
+ };
67
99
  }
68
100
  return config;
69
101
  }
102
+ /**
103
+ * The plugin turns off the "sourceMap" and the "inlineSourceMap" options. Options that depend on
104
+ * them would become invalid, so we remove them as well.
105
+ */
106
+ function removeOrphanedSourceMapOptions(options) {
107
+ const { inlineSources, sourceRoot, mapRoot, ...otherOptions } = options;
108
+ return {
109
+ ...otherOptions,
110
+ ...(options.sourceMap || options.inlineSourceMap ? { inlineSources, sourceRoot } : {}),
111
+ ...(options.sourceMap || options.declarationMap ? { mapRoot } : {}),
112
+ };
113
+ }
70
114
  function parseConfig(configFileName, configFileContext) {
71
- const configFilePath = (0, forward_slash_1.forwardSlash)(configFileName);
72
- const { config: baseConfig, error: readConfigError } = typescript_1.typescript.readConfigFile(configFilePath, parseConfigFileHost.readFile);
115
+ const api = (0, api_1.getApi)();
116
+ const { config: baseConfig, error: readConfigError } = api.readConfigFile(configFileName);
73
117
  const overwrittenConfig = applyConfigOverwrite(baseConfig || {}, getImplicitConfigOverwrite(), getUserProvidedConfigOverwrite());
74
- const parsedConfigFile = typescript_1.typescript.parseJsonConfigFileContent(overwrittenConfig, parseConfigFileHost, configFileContext);
75
- return Object.assign(Object.assign({}, parsedConfigFile), { options: Object.assign(Object.assign({}, parsedConfigFile.options), { configFilePath: configFilePath }), errors: readConfigError ? [readConfigError] : parsedConfigFile.errors });
118
+ // the API resolves relative paths against the config file's directory unless
119
+ // we give it an explicit base directory - that's what the `context` option is for
120
+ const parsedConfigFile = api.parseJsonConfigFileContent(overwrittenConfig, path.normalize(configFileContext) === path.normalize(path.dirname(configFileName))
121
+ ? { configFileName }
122
+ : { configDirectory: configFileContext });
123
+ return {
124
+ ...parsedConfigFile,
125
+ options: removeOrphanedSourceMapOptions(parsedConfigFile.options),
126
+ errors: readConfigError ? [readConfigError] : parsedConfigFile.errors,
127
+ };
76
128
  }
77
- exports.parseConfig = parseConfig;
78
129
  function getParseConfigIssues() {
79
130
  const issues = (0, diagnostics_1.createIssuesFromDiagnostics)(parseConfigDiagnostics);
80
131
  issues.forEach((issue) => {
@@ -84,52 +135,29 @@ function getParseConfigIssues() {
84
135
  });
85
136
  return issues;
86
137
  }
87
- exports.getParseConfigIssues = getParseConfigIssues;
88
- function getParsedConfig(force = false) {
89
- if (!parsedConfig || force) {
138
+ function getParsedConfig() {
139
+ if (!parsedConfig) {
90
140
  parsedConfig = parseConfig(worker_config_1.config.configFile, worker_config_1.config.context);
91
141
  parseConfigDiagnostics = parsedConfig.errors || [];
92
142
  }
93
143
  return parsedConfig;
94
144
  }
95
- exports.getParsedConfig = getParsedConfig;
96
- function parseNextConfig() {
97
- const prevParsedConfig = parsedConfig;
98
- const nextParsedConfig = getParsedConfig(true);
99
- return [prevParsedConfig, nextParsedConfig];
100
- }
101
- exports.parseNextConfig = parseNextConfig;
102
145
  function invalidateConfig() {
103
146
  parsedConfig = undefined;
104
147
  parseConfigDiagnostics = [];
105
148
  }
106
- exports.invalidateConfig = invalidateConfig;
107
- function getConfigFilePathFromCompilerOptions(compilerOptions) {
108
- return compilerOptions.configFilePath;
109
- }
110
- exports.getConfigFilePathFromCompilerOptions = getConfigFilePathFromCompilerOptions;
111
- function getConfigFilePathFromProgram(program) {
112
- return getConfigFilePathFromCompilerOptions(program.getCompilerOptions());
113
- }
114
- exports.getConfigFilePathFromProgram = getConfigFilePathFromProgram;
115
- function getConfigFilePathFromBuilderProgram(builderProgram) {
116
- return getConfigFilePathFromCompilerOptions(builderProgram.getProgram().getCompilerOptions());
117
- }
118
- exports.getConfigFilePathFromBuilderProgram = getConfigFilePathFromBuilderProgram;
119
- function didConfigFileChanged({ changedFiles = [], deletedFiles = [] }) {
149
+ function didConfigFileChanged(configFiles, { changedFiles = [], deletedFiles = [] }) {
120
150
  return [...changedFiles, ...deletedFiles]
121
151
  .map((file) => path.normalize(file))
122
- .includes(path.normalize(worker_config_1.config.configFile));
152
+ .some((file) => configFiles.includes(file));
123
153
  }
124
- exports.didConfigFileChanged = didConfigFileChanged;
125
154
  function didDependenciesProbablyChanged(dependencies, { changedFiles = [], deletedFiles = [] }) {
126
155
  const didSomeDependencyHasBeenAdded = changedFiles.some((changeFile) => !dependencies.files.includes(changeFile));
127
156
  const didSomeDependencyHasBeenDeleted = deletedFiles.some((deletedFile) => dependencies.files.includes(deletedFile));
128
157
  return didSomeDependencyHasBeenAdded || didSomeDependencyHasBeenDeleted;
129
158
  }
130
- exports.didDependenciesProbablyChanged = didDependenciesProbablyChanged;
131
- function didRootFilesChanged() {
132
- const [prevConfig, nextConfig] = parseNextConfig();
133
- return (prevConfig && JSON.stringify(prevConfig.fileNames) !== JSON.stringify(nextConfig.fileNames));
159
+ function didRootFilesChanged(previousRootFiles) {
160
+ const previous = new Set(previousRootFiles);
161
+ const next = new Set(getParsedConfig().fileNames);
162
+ return previous.size !== next.size || [...next].some((fileName) => !previous.has(fileName));
134
163
  }
135
- exports.didRootFilesChanged = didRootFilesChanged;
@@ -1,3 +1,8 @@
1
1
  import type { FilesMatch } from '../../../files-match';
2
- export declare function getDependencies(force?: boolean): FilesMatch;
2
+ export declare function getDependencies(): FilesMatch;
3
+ /**
4
+ * The root config file, the config file of every referenced project, and every
5
+ * local config file they extend.
6
+ */
7
+ export declare function getConfigFiles(): string[];
3
8
  export declare function invalidateDependencies(): void;
@@ -15,71 +15,205 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.invalidateDependencies = exports.getDependencies = void 0;
36
+ exports.getDependencies = getDependencies;
37
+ exports.getConfigFiles = getConfigFiles;
38
+ exports.invalidateDependencies = invalidateDependencies;
39
+ const fs = __importStar(require("fs"));
40
+ const module_1 = require("module");
27
41
  const path = __importStar(require("path"));
42
+ const api_1 = require("./api");
28
43
  const config_1 = require("./config");
29
- const typescript_1 = require("./typescript");
30
44
  const worker_config_1 = require("./worker-config");
31
- let dependencies;
32
- function getDependencies(force = false) {
33
- if (!dependencies || force) {
34
- const parsedConfig = (0, config_1.getParsedConfig)();
35
- dependencies = getDependenciesWorker(parsedConfig, worker_config_1.config.context);
45
+ const EXTENSIONS = ['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs', '.tsbuildinfo'];
46
+ // both come from one walk over the project references, so they share a cache
47
+ let projectDependencies;
48
+ function getProjectDependencies() {
49
+ if (!projectDependencies) {
50
+ projectDependencies = createProjectDependencies();
36
51
  }
37
- return dependencies;
52
+ return projectDependencies;
53
+ }
54
+ function getDependencies() {
55
+ return getProjectDependencies().dependencies;
56
+ }
57
+ /**
58
+ * The root config file, the config file of every referenced project, and every
59
+ * local config file they extend.
60
+ */
61
+ function getConfigFiles() {
62
+ return getProjectDependencies().configFiles;
38
63
  }
39
- exports.getDependencies = getDependencies;
40
64
  function invalidateDependencies() {
41
- dependencies = undefined;
65
+ projectDependencies = undefined;
42
66
  }
43
- exports.invalidateDependencies = invalidateDependencies;
44
- function getDependenciesWorker(parsedConfig, configFileContext, processedConfigFiles = []) {
45
- var _a;
46
- const files = new Set(parsedConfig.fileNames);
47
- const configFilePath = parsedConfig.options.configFilePath;
48
- if (typeof configFilePath === 'string') {
49
- files.add(configFilePath);
67
+ /** A project reference's `path` can be either a tsconfig file or its directory. */
68
+ function resolveProjectReferencePath(referencePath) {
69
+ // a missing reference is reported by the compiler
70
+ return isDirectory(referencePath) ? path.join(referencePath, 'tsconfig.json') : referencePath;
71
+ }
72
+ /**
73
+ * Resolves an `include`/`exclude` entry. The parsed config keeps the
74
+ * `${configDir}` template as is. TypeScript replaces it with the directory the
75
+ * config is parsed against - the `context` option for the root config.
76
+ */
77
+ function resolveConfigPattern(pattern, configFileContext) {
78
+ return path.resolve(configFileContext, pattern.split('${configDir}').join(configFileContext));
79
+ }
80
+ function isDirectory(directory) {
81
+ try {
82
+ return fs.statSync(directory).isDirectory();
50
83
  }
51
- const dirs = new Set(Object.keys(parsedConfig.wildcardDirectories || {}));
52
- const excluded = new Set((((_a = parsedConfig.raw) === null || _a === void 0 ? void 0 : _a.exclude) || []).map((filePath) => path.resolve(configFileContext, filePath)));
53
- for (const projectReference of parsedConfig.projectReferences || []) {
54
- const childConfigFilePath = typescript_1.typescript.resolveProjectReferencePath(projectReference);
55
- const childConfigContext = path.dirname(childConfigFilePath);
56
- if (processedConfigFiles.includes(childConfigFilePath)) {
57
- // handle circular dependencies
84
+ catch (error) {
85
+ return false;
86
+ }
87
+ }
88
+ function isFile(file) {
89
+ try {
90
+ return fs.statSync(file).isFile();
91
+ }
92
+ catch (error) {
93
+ return false;
94
+ }
95
+ }
96
+ /**
97
+ * The native API doesn't expose `wildcardDirectories`, so derive the directories
98
+ * to watch from the static prefix of each `include` pattern.
99
+ */
100
+ function getIncludeDirectories(parsedConfig, configFileContext) {
101
+ const raw = (parsedConfig.raw || {});
102
+ const include = Array.isArray(raw.include)
103
+ ? raw.include.filter((pattern) => typeof pattern === 'string')
104
+ : Array.isArray(raw.files)
105
+ ? []
106
+ : ['**/*'];
107
+ return include.map((pattern) => {
108
+ const resolvedPattern = resolveConfigPattern(pattern, configFileContext);
109
+ const segments = resolvedPattern.split(/[\\/]/);
110
+ const firstWildcard = segments.findIndex((segment) => /[*?]/.test(segment));
111
+ const staticPart = (firstWildcard === -1 ? segments : segments.slice(0, firstWildcard)).join('/');
112
+ // `resolvedPattern` is absolute - resolve against its root to keep the drive on Windows
113
+ const directory = path.resolve(path.parse(resolvedPattern).root, staticPart);
114
+ // a pattern without a wildcard can point to a file
115
+ return firstWildcard === -1 && path.extname(directory) && !isDirectory(directory)
116
+ ? path.dirname(directory)
117
+ : directory;
118
+ });
119
+ }
120
+ /** Mirrors how TypeScript resolves a relative or absolute `extends` path. */
121
+ function resolveExtendsPath(extendsPath, baseDirectory) {
122
+ const resolved = path.resolve(baseDirectory, extendsPath);
123
+ // a directory with the same name doesn't count - TypeScript looks for a file
124
+ return isFile(resolved) || resolved.endsWith('.json') ? resolved : `${resolved}.json`;
125
+ }
126
+ /**
127
+ * Resolves an `extends` that names a package. Installed packages live in
128
+ * node_modules, which isn't watched, but a workspace package is a symlink to a
129
+ * directory that people edit - only those are returned, by their real path.
130
+ *
131
+ * This approximates TypeScript's own lookup. A specifier it gets wrong is left
132
+ * untracked, which only costs a restart after that config changes.
133
+ */
134
+ function resolveWorkspaceExtendsPath(extendsPath, baseDirectory) {
135
+ const { resolve } = (0, module_1.createRequire)(path.join(baseDirectory, 'tsconfig.json'));
136
+ const candidates = [extendsPath, `${extendsPath}.json`, `${extendsPath}/tsconfig.json`];
137
+ for (const candidate of candidates) {
138
+ let resolved;
139
+ try {
140
+ resolved = fs.realpathSync(resolve(candidate));
141
+ }
142
+ catch (error) {
143
+ continue;
144
+ }
145
+ if (!resolved.endsWith('.json')) {
146
+ // the package's code entry point, not a config file
147
+ continue;
148
+ }
149
+ return resolved.split(path.sep).includes('node_modules') ? undefined : resolved;
150
+ }
151
+ return undefined;
152
+ }
153
+ /**
154
+ * The chain of config files that `configFilePath` extends, without the file itself.
155
+ * `baseDirectory` is the directory the config was parsed against - the `context`
156
+ * option for the root config, which TypeScript also resolves `extends` against.
157
+ */
158
+ function getExtendedConfigFiles(raw, configFilePath, baseDirectory, visited = new Set([configFilePath])) {
159
+ const extendsValue = raw?.extends;
160
+ const extendsList = Array.isArray(extendsValue) ? extendsValue : [extendsValue];
161
+ const extendedConfigFiles = [];
162
+ for (const extendsPath of extendsList) {
163
+ if (typeof extendsPath !== 'string') {
164
+ continue;
165
+ }
166
+ const extendedConfigFile = extendsPath.startsWith('.') || path.isAbsolute(extendsPath)
167
+ ? resolveExtendsPath(extendsPath, baseDirectory)
168
+ : resolveWorkspaceExtendsPath(extendsPath, baseDirectory);
169
+ if (!extendedConfigFile || visited.has(extendedConfigFile)) {
58
170
  continue;
59
171
  }
60
- const childParsedConfig = (0, config_1.parseConfig)(childConfigFilePath, childConfigContext);
61
- const childDependencies = getDependenciesWorker(childParsedConfig, childConfigContext, [
62
- ...processedConfigFiles,
63
- childConfigFilePath,
64
- ]);
65
- childDependencies.files.forEach((file) => {
66
- files.add(file);
67
- });
68
- childDependencies.dirs.forEach((dir) => {
69
- dirs.add(dir);
70
- });
172
+ visited.add(extendedConfigFile);
173
+ extendedConfigFiles.push(extendedConfigFile);
174
+ // follow the chain - a missing or invalid file is reported by the compiler
175
+ const { config: extendedConfig } = (0, api_1.getApi)().readConfigFile(extendedConfigFile);
176
+ extendedConfigFiles.push(...getExtendedConfigFiles(extendedConfig, extendedConfigFile, path.dirname(extendedConfigFile), visited));
71
177
  }
72
- const extensions = [
73
- typescript_1.typescript.Extension.Ts,
74
- typescript_1.typescript.Extension.Tsx,
75
- typescript_1.typescript.Extension.Js,
76
- typescript_1.typescript.Extension.Jsx,
77
- typescript_1.typescript.Extension.TsBuildInfo,
78
- ];
178
+ return extendedConfigFiles;
179
+ }
180
+ function createProjectDependencies() {
181
+ const files = new Set();
182
+ const dirs = new Set();
183
+ const configFiles = new Set();
184
+ // a project can be referenced many times, or in a circle - parse each one once
185
+ const visited = new Set();
186
+ const visit = (parsedConfig, configFilePath, configFileContext) => {
187
+ configFiles.add(configFilePath);
188
+ getExtendedConfigFiles(parsedConfig.raw, configFilePath, configFileContext).forEach((file) => configFiles.add(file));
189
+ parsedConfig.fileNames.forEach((file) => files.add(file));
190
+ getIncludeDirectories(parsedConfig, configFileContext).forEach((dir) => dirs.add(dir));
191
+ for (const projectReference of parsedConfig.projectReferences || []) {
192
+ const childConfigFilePath = resolveProjectReferencePath(projectReference.path);
193
+ const childConfigKey = path.normalize(childConfigFilePath);
194
+ if (visited.has(childConfigKey)) {
195
+ continue;
196
+ }
197
+ visited.add(childConfigKey);
198
+ const childConfigContext = path.dirname(childConfigFilePath);
199
+ visit((0, config_1.parseConfig)(childConfigFilePath, childConfigContext), childConfigFilePath, childConfigContext);
200
+ }
201
+ };
202
+ const parsedConfig = (0, config_1.getParsedConfig)();
203
+ visited.add(path.normalize(worker_config_1.config.configFile));
204
+ visit(parsedConfig, worker_config_1.config.configFile, worker_config_1.config.context);
205
+ configFiles.forEach((file) => files.add(file));
206
+ const rawExclude = parsedConfig.raw?.exclude;
207
+ const excluded = (Array.isArray(rawExclude) ? rawExclude : [])
208
+ .filter((pattern) => typeof pattern === 'string')
209
+ .map((pattern) => resolveConfigPattern(pattern, worker_config_1.config.context));
79
210
  return {
80
- files: Array.from(files).map((file) => path.normalize(file)),
81
- dirs: Array.from(dirs).map((dir) => path.normalize(dir)),
82
- excluded: Array.from(excluded).map((aPath) => path.normalize(aPath)),
83
- extensions: extensions,
211
+ dependencies: {
212
+ files: Array.from(files, (file) => path.normalize(file)),
213
+ dirs: Array.from(dirs, (dir) => path.normalize(dir)),
214
+ excluded: Array.from(new Set(excluded), (aPath) => path.normalize(aPath)),
215
+ extensions: EXTENSIONS,
216
+ },
217
+ configFiles: Array.from(configFiles, (file) => path.normalize(file)),
84
218
  };
85
219
  }
@@ -1,7 +1,8 @@
1
- import type * as ts from 'typescript';
1
+ import type { Diagnostic, Program } from 'typescript/sync';
2
2
  import type { Issue } from '../../../issue';
3
- export declare function updateDiagnostics(configFile: string, diagnostics: ts.Diagnostic[]): void;
3
+ export declare function updateDiagnostics(configFile: string, diagnostics: Diagnostic[]): void;
4
4
  export declare function getIssues(): Issue[];
5
5
  export declare function invalidateDiagnostics(): void;
6
- export declare function getDiagnosticsOfProgram(program: ts.Program | ts.BuilderProgram): ts.Diagnostic[];
7
- export declare function createIssuesFromDiagnostics(diagnostics: ts.Diagnostic[]): Issue[];
6
+ export declare function createCrashDiagnostic(error: unknown): Diagnostic;
7
+ export declare function getDiagnosticsOfProgram(program: Program): Diagnostic[];
8
+ export declare function createIssuesFromDiagnostics(diagnostics: readonly Diagnostic[]): Issue[];