fork-ts-checker-webpack-plugin 9.2.0 → 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 (91) hide show
  1. package/README.md +23 -13
  2. package/lib/formatter/basic-formatter.js +2 -2
  3. package/lib/formatter/code-frame-formatter.d.ts +3 -2
  4. package/lib/formatter/code-frame-formatter.js +13 -3
  5. package/lib/formatter/formatter-config.js +2 -1
  6. package/lib/formatter/formatter-options.d.ts +1 -1
  7. package/lib/formatter/stats-formatter.js +3 -3
  8. package/lib/formatter/webpack-formatter.js +5 -9
  9. package/lib/hooks/report-issues.d.ts +8 -0
  10. package/lib/hooks/report-issues.js +22 -0
  11. package/lib/hooks/tap-after-compile-to-add-dependencies.js +3 -12
  12. package/lib/hooks/tap-after-compile-to-get-issues.js +6 -27
  13. package/lib/hooks/tap-done-to-async-get-issues.js +12 -32
  14. package/lib/hooks/tap-error-to-log-message.js +5 -7
  15. package/lib/hooks/tap-start-to-run-workers.js +12 -22
  16. package/lib/issue/issue-webpack-error.js +4 -11
  17. package/lib/plugin-options.json +4 -8
  18. package/lib/plugin-state.d.ts +0 -1
  19. package/lib/plugin.js +23 -23
  20. package/lib/rpc/expose-rpc.js +5 -14
  21. package/lib/rpc/rpc-error.js +2 -0
  22. package/lib/rpc/rpc-worker.d.ts +1 -1
  23. package/lib/rpc/rpc-worker.js +7 -7
  24. package/lib/rpc/wrap-rpc.js +3 -12
  25. package/lib/typescript/type-script-package.d.ts +4 -0
  26. package/lib/typescript/type-script-package.js +88 -0
  27. package/lib/typescript/type-script-support.js +8 -18
  28. package/lib/typescript/type-script-worker-config.d.ts +2 -3
  29. package/lib/typescript/type-script-worker-config.js +23 -2
  30. package/lib/typescript/type-script-worker-options.d.ts +4 -3
  31. package/lib/typescript/type-script-worker-options.js +4 -0
  32. package/lib/typescript/worker/get-dependencies-worker.js +15 -4
  33. package/lib/typescript/worker/get-issues-worker.d.ts +1 -1
  34. package/lib/typescript/worker/get-issues-worker.js +52 -64
  35. package/lib/typescript/worker/lib/api.d.ts +13 -0
  36. package/lib/typescript/worker/lib/api.js +62 -0
  37. package/lib/typescript/worker/lib/config.d.ts +13 -9
  38. package/lib/typescript/worker/lib/config.js +63 -63
  39. package/lib/typescript/worker/lib/dependencies.d.ts +6 -1
  40. package/lib/typescript/worker/lib/dependencies.js +168 -43
  41. package/lib/typescript/worker/lib/diagnostics.d.ts +5 -4
  42. package/lib/typescript/worker/lib/diagnostics.js +44 -50
  43. package/lib/typescript/worker/lib/in-memory-file-system.d.ts +14 -0
  44. package/lib/typescript/worker/lib/in-memory-file-system.js +140 -0
  45. package/lib/typescript/worker/lib/performance.d.ts +1 -2
  46. package/lib/typescript/worker/lib/performance.js +12 -19
  47. package/lib/typescript/worker/lib/program/program.d.ts +6 -2
  48. package/lib/typescript/worker/lib/program/program.js +135 -24
  49. package/lib/typescript/worker/lib/program/solution-builder.d.ts +3 -1
  50. package/lib/typescript/worker/lib/program/solution-builder.js +41 -24
  51. package/lib/typescript/worker/lib/typescript.d.ts +4 -2
  52. package/lib/typescript/worker/lib/typescript.js +69 -3
  53. package/lib/utils/async/abort-error.d.ts +0 -1
  54. package/lib/utils/async/abort-error.js +1 -1
  55. package/lib/utils/async/pool.d.ts +0 -1
  56. package/lib/utils/async/pool.js +12 -23
  57. package/lib/utils/deep-merge.d.ts +5 -0
  58. package/lib/utils/deep-merge.js +56 -0
  59. package/lib/utils/path/format-file-path.d.ts +3 -0
  60. package/lib/utils/path/format-file-path.js +15 -0
  61. package/lib/watch/inclusive-node-watch-file-system.d.ts +3 -0
  62. package/lib/watch/inclusive-node-watch-file-system.js +119 -111
  63. package/package.json +30 -38
  64. package/lib/formatter/types/babel__code-frame.d.ts +0 -21
  65. package/lib/formatter/types/babel__code-frame.js +0 -7
  66. package/lib/typescript/worker/lib/artifacts.d.ts +0 -4
  67. package/lib/typescript/worker/lib/artifacts.js +0 -103
  68. package/lib/typescript/worker/lib/emit.d.ts +0 -2
  69. package/lib/typescript/worker/lib/emit.js +0 -12
  70. package/lib/typescript/worker/lib/file-system/file-system.d.ts +0 -17
  71. package/lib/typescript/worker/lib/file-system/file-system.js +0 -2
  72. package/lib/typescript/worker/lib/file-system/mem-file-system.d.ts +0 -5
  73. package/lib/typescript/worker/lib/file-system/mem-file-system.js +0 -79
  74. package/lib/typescript/worker/lib/file-system/passive-file-system.d.ts +0 -5
  75. package/lib/typescript/worker/lib/file-system/passive-file-system.js +0 -65
  76. package/lib/typescript/worker/lib/file-system/real-file-system.d.ts +0 -5
  77. package/lib/typescript/worker/lib/file-system/real-file-system.js +0 -201
  78. package/lib/typescript/worker/lib/host/compiler-host.d.ts +0 -2
  79. package/lib/typescript/worker/lib/host/compiler-host.js +0 -9
  80. package/lib/typescript/worker/lib/host/watch-compiler-host.d.ts +0 -2
  81. package/lib/typescript/worker/lib/host/watch-compiler-host.js +0 -19
  82. package/lib/typescript/worker/lib/host/watch-solution-builder-host.d.ts +0 -2
  83. package/lib/typescript/worker/lib/host/watch-solution-builder-host.js +0 -46
  84. package/lib/typescript/worker/lib/program/watch-program.d.ts +0 -3
  85. package/lib/typescript/worker/lib/program/watch-program.js +0 -50
  86. package/lib/typescript/worker/lib/system.d.ts +0 -19
  87. package/lib/typescript/worker/lib/system.js +0 -232
  88. package/lib/typescript/worker/lib/tracing.d.ts +0 -4
  89. package/lib/typescript/worker/lib/tracing.js +0 -28
  90. package/lib/typescript/worker/lib/tsbuildinfo.d.ts +0 -4
  91. package/lib/typescript/worker/lib/tsbuildinfo.js +0 -105
@@ -34,61 +34,186 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.getDependencies = getDependencies;
37
+ exports.getConfigFiles = getConfigFiles;
37
38
  exports.invalidateDependencies = invalidateDependencies;
39
+ const fs = __importStar(require("fs"));
40
+ const module_1 = require("module");
38
41
  const path = __importStar(require("path"));
42
+ const api_1 = require("./api");
39
43
  const config_1 = require("./config");
40
- const typescript_1 = require("./typescript");
41
44
  const worker_config_1 = require("./worker-config");
42
- let dependencies;
43
- function getDependencies(force = false) {
44
- if (!dependencies || force) {
45
- const parsedConfig = (0, config_1.getParsedConfig)();
46
- 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();
47
51
  }
48
- 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;
49
63
  }
50
64
  function invalidateDependencies() {
51
- dependencies = undefined;
65
+ projectDependencies = undefined;
66
+ }
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();
83
+ }
84
+ catch (error) {
85
+ return false;
86
+ }
52
87
  }
53
- function getDependenciesWorker(parsedConfig, configFileContext, processedConfigFiles = []) {
54
- var _a;
55
- const files = new Set(parsedConfig.fileNames);
56
- const configFilePath = parsedConfig.options.configFilePath;
57
- if (typeof configFilePath === 'string') {
58
- files.add(configFilePath);
88
+ function isFile(file) {
89
+ try {
90
+ return fs.statSync(file).isFile();
91
+ }
92
+ catch (error) {
93
+ return false;
59
94
  }
60
- const dirs = new Set(Object.keys(parsedConfig.wildcardDirectories || {}));
61
- const excluded = new Set((((_a = parsedConfig.raw) === null || _a === void 0 ? void 0 : _a.exclude) || []).map((filePath) => path.resolve(configFileContext, filePath)));
62
- for (const projectReference of parsedConfig.projectReferences || []) {
63
- const childConfigFilePath = typescript_1.typescript.resolveProjectReferencePath(projectReference);
64
- const childConfigContext = path.dirname(childConfigFilePath);
65
- if (processedConfigFiles.includes(childConfigFilePath)) {
66
- // handle circular dependencies
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) {
67
143
  continue;
68
144
  }
69
- const childParsedConfig = (0, config_1.parseConfig)(childConfigFilePath, childConfigContext);
70
- const childDependencies = getDependenciesWorker(childParsedConfig, childConfigContext, [
71
- ...processedConfigFiles,
72
- childConfigFilePath,
73
- ]);
74
- childDependencies.files.forEach((file) => {
75
- files.add(file);
76
- });
77
- childDependencies.dirs.forEach((dir) => {
78
- dirs.add(dir);
79
- });
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;
80
150
  }
81
- const extensions = [
82
- typescript_1.typescript.Extension.Ts,
83
- typescript_1.typescript.Extension.Tsx,
84
- typescript_1.typescript.Extension.Js,
85
- typescript_1.typescript.Extension.Jsx,
86
- typescript_1.typescript.Extension.TsBuildInfo,
87
- ];
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)) {
170
+ continue;
171
+ }
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));
177
+ }
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));
88
210
  return {
89
- files: Array.from(files).map((file) => path.normalize(file)),
90
- dirs: Array.from(dirs).map((dir) => path.normalize(dir)),
91
- excluded: Array.from(excluded).map((aPath) => path.normalize(aPath)),
92
- 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)),
93
218
  };
94
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[];
@@ -36,12 +36,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.updateDiagnostics = updateDiagnostics;
37
37
  exports.getIssues = getIssues;
38
38
  exports.invalidateDiagnostics = invalidateDiagnostics;
39
+ exports.createCrashDiagnostic = createCrashDiagnostic;
39
40
  exports.getDiagnosticsOfProgram = getDiagnosticsOfProgram;
40
41
  exports.createIssuesFromDiagnostics = createIssuesFromDiagnostics;
41
42
  const os = __importStar(require("os"));
43
+ const path = __importStar(require("path"));
42
44
  const issue_1 = require("../../../issue");
43
- const typescript_1 = require("./typescript");
44
45
  const worker_config_1 = require("./worker-config");
46
+ // matches TypeScript's DiagnosticCategory
47
+ const DIAGNOSTIC_CATEGORY_WARNING = 0;
45
48
  const diagnosticsPerConfigFile = new Map();
46
49
  function updateDiagnostics(configFile, diagnostics) {
47
50
  diagnosticsPerConfigFile.set(configFile, diagnostics);
@@ -56,79 +59,70 @@ function getIssues() {
56
59
  function invalidateDiagnostics() {
57
60
  diagnosticsPerConfigFile.clear();
58
61
  }
59
- /**
60
- * Options diagnostics contain errors that the user did not cause, so we skip them.
61
- */
62
- function isReportableOptionsDiagnostic(diagnostic) {
63
- if (diagnostic.code === 6053) {
64
- // File '{0}' not found.
65
- // A deleted file stays in the list of root files of a watch program until the next update.
66
- return false;
67
- }
68
- return true;
62
+ function createCrashDiagnostic(error) {
63
+ return {
64
+ pos: -1,
65
+ end: -1,
66
+ code: 1,
67
+ category: 1,
68
+ text: `TSC compiler crashed: ${error instanceof Error ? `${error.message}\n${error.stack}` : String(error)}`,
69
+ };
69
70
  }
70
71
  function getDiagnosticsOfProgram(program) {
72
+ // errors aren't caught here: the worker reports them and resets the compiler
71
73
  const programDiagnostics = [];
72
- try {
73
- // compiler options errors, for example a deprecated or an invalid option, are always reported
74
- programDiagnostics.push(...program.getOptionsDiagnostics().filter(isReportableOptionsDiagnostic));
75
- if (worker_config_1.config.diagnosticOptions.syntactic) {
76
- programDiagnostics.push(...program.getSyntacticDiagnostics());
77
- }
78
- if (worker_config_1.config.diagnosticOptions.global) {
79
- programDiagnostics.push(...program.getGlobalDiagnostics());
80
- }
81
- if (worker_config_1.config.diagnosticOptions.semantic) {
82
- programDiagnostics.push(...program.getSemanticDiagnostics());
83
- }
84
- if (worker_config_1.config.diagnosticOptions.declaration) {
85
- programDiagnostics.push(...program.getDeclarationDiagnostics());
86
- }
74
+ // compiler options diagnostics (e.g. a removed `target`)
75
+ programDiagnostics.push(...program.getProgramDiagnostics());
76
+ if (worker_config_1.config.diagnosticOptions.syntactic) {
77
+ programDiagnostics.push(...program.getSyntacticDiagnostics());
87
78
  }
88
- catch (e) {
89
- if (e instanceof Error) {
90
- programDiagnostics.push({
91
- code: 1,
92
- category: 1,
93
- messageText: `TSC compiler crashed: ${e.message}
94
- ${e.stack}`,
95
- file: undefined,
96
- start: undefined,
97
- length: undefined,
98
- });
99
- }
79
+ if (worker_config_1.config.diagnosticOptions.global) {
80
+ programDiagnostics.push(...program.getGlobalDiagnostics());
81
+ }
82
+ if (worker_config_1.config.diagnosticOptions.semantic) {
83
+ programDiagnostics.push(...program.getSemanticDiagnostics());
84
+ }
85
+ if (worker_config_1.config.diagnosticOptions.declaration) {
86
+ programDiagnostics.push(...program.getDeclarationDiagnostics());
100
87
  }
101
88
  return programDiagnostics;
102
89
  }
103
90
  function createIssueFromDiagnostic(diagnostic) {
104
91
  let file;
105
92
  let location;
106
- if (diagnostic.file) {
107
- file = diagnostic.file.fileName;
108
- if (diagnostic.start && diagnostic.length) {
109
- const { line: startLine, character: startCharacter } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
110
- const { line: endLine, character: endCharacter } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start + diagnostic.length);
93
+ if (diagnostic.fileName) {
94
+ // the API always returns forward-slashed paths
95
+ file = path.normalize(diagnostic.fileName);
96
+ if (diagnostic.startPosition && diagnostic.endPosition) {
111
97
  location = {
112
98
  start: {
113
- line: startLine + 1,
114
- column: startCharacter + 1,
99
+ line: diagnostic.startPosition.line + 1,
100
+ column: diagnostic.startPosition.character + 1,
115
101
  },
116
102
  end: {
117
- line: endLine + 1,
118
- column: endCharacter + 1,
103
+ line: diagnostic.endPosition.line + 1,
104
+ column: diagnostic.endPosition.character + 1,
119
105
  },
120
106
  };
121
107
  }
122
108
  }
123
109
  return {
124
- code: 'TS' + String(diagnostic.code),
110
+ code: (diagnostic.source || 'TS') + String(diagnostic.code),
125
111
  // we don't handle Suggestion and Message diagnostics
126
- severity: diagnostic.category === 0 ? 'warning' : 'error',
127
- message: typescript_1.typescript.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL),
112
+ severity: diagnostic.category === DIAGNOSTIC_CATEGORY_WARNING ? 'warning' : 'error',
113
+ message: flattenDiagnosticMessageText(diagnostic),
128
114
  file,
129
115
  location,
130
116
  };
131
117
  }
118
+ // same output as TypeScript's classic `flattenDiagnosticMessageText`
119
+ function flattenDiagnosticMessageText(diagnostic, indent = 0) {
120
+ let result = indent ? os.EOL + ' '.repeat(indent) + diagnostic.text : diagnostic.text;
121
+ for (const chained of diagnostic.messageChain ?? []) {
122
+ result += flattenDiagnosticMessageText(chained, indent + 1);
123
+ }
124
+ return result;
125
+ }
132
126
  function createIssuesFromDiagnostics(diagnostics) {
133
127
  return (0, issue_1.deduplicateAndSortIssues)(diagnostics.map((diagnostic) => createIssueFromDiagnostic(diagnostic)));
134
128
  }
@@ -0,0 +1,14 @@
1
+ import type { FileSystemCallbacks } from 'typescript/fs';
2
+ export interface InMemoryFileSystem {
3
+ callbacks: FileSystemCallbacks;
4
+ /** Forgets the resolved symlinks, in case packages were relinked between builds. */
5
+ invalidateRealDirectories(): void;
6
+ }
7
+ /**
8
+ * File system callbacks that keep everything the build orchestrator writes in
9
+ * memory, for `build: true` in the `in-memory` mode. Later projects read what
10
+ * earlier ones "wrote", and nothing reaches the user's disk. The callbacks are
11
+ * round trips from the native compiler, so reads of anything not written here
12
+ * are left to the compiler's own file system.
13
+ */
14
+ export declare function createInMemoryFileSystem(): InMemoryFileSystem;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
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
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.createInMemoryFileSystem = createInMemoryFileSystem;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const forward_slash_1 = require("../../../utils/path/forward-slash");
40
+ const typescript_1 = require("./typescript");
41
+ /**
42
+ * File system callbacks that keep everything the build orchestrator writes in
43
+ * memory, for `build: true` in the `in-memory` mode. Later projects read what
44
+ * earlier ones "wrote", and nothing reaches the user's disk. The callbacks are
45
+ * round trips from the native compiler, so reads of anything not written here
46
+ * are left to the compiler's own file system.
47
+ */
48
+ function createInMemoryFileSystem() {
49
+ const { serverFS } = typescript_1.typescriptFs;
50
+ // The compiler always gives the callbacks forward-slashed paths, on Windows too
51
+ // (`C:/project/lib/index.d.ts`), so paths are handled with `path.posix`.
52
+ // file content, by path
53
+ const outputs = new Map();
54
+ // file mtime, by path: the up-to-date check compares inputs with the .tsbuildinfo
55
+ // mtime, so reporting "now" would make every input look older
56
+ const outputTimes = new Map();
57
+ // the directories that contain the files
58
+ const outputDirectories = new Set();
59
+ // A cache of resolved symlinks (symlinked directory -> real directory), cleared
60
+ // before each build in case of relinks.
61
+ const realDirectories = new Map();
62
+ // The up-to-date check only compares inputs with .tsbuildinfo, never with the
63
+ // other outputs. A .tsbuildinfo left on disk by an earlier run in the `write` mode
64
+ // (or by `tsc --build`) could mark projects as built while their .d.ts files are
65
+ // missing from memory - so hide any .tsbuildinfo that wasn't written here.
66
+ const isHidden = (fileName) => fileName.endsWith('.tsbuildinfo') && !outputs.has(fileName);
67
+ // Outputs are keyed by their real path, but the compiler can also look them up
68
+ // through a symlink - typically a workspace package in node_modules whose
69
+ // `types` point at another project's in-memory .d.ts files.
70
+ const toOutputPath = (fileName) => {
71
+ if (outputs.has(fileName) || outputDirectories.has(fileName)) {
72
+ return fileName;
73
+ }
74
+ if (outputs.size === 0 || !fileName.includes('/node_modules/')) {
75
+ return fileName;
76
+ }
77
+ let directory = path.posix.dirname(fileName);
78
+ const rest = [path.posix.basename(fileName)];
79
+ while (!realDirectories.has(directory) && !fs.existsSync(directory)) {
80
+ const parent = path.posix.dirname(directory);
81
+ if (parent === directory) {
82
+ return fileName;
83
+ }
84
+ rest.unshift(path.posix.basename(directory));
85
+ directory = parent;
86
+ }
87
+ let realDirectory = realDirectories.get(directory);
88
+ if (realDirectory === undefined) {
89
+ realDirectory = (0, forward_slash_1.forwardSlash)(fs.realpathSync(directory));
90
+ realDirectories.set(directory, realDirectory);
91
+ }
92
+ return path.posix.join(realDirectory, ...rest);
93
+ };
94
+ // The API throws unless every callback is a function or a `serverFS` sentinel.
95
+ const callbacks = {
96
+ writeFile(fileName, content) {
97
+ outputs.set(fileName, content);
98
+ outputTimes.set(fileName, new Date());
99
+ for (let dir = path.posix.dirname(fileName); !outputDirectories.has(dir);) {
100
+ outputDirectories.add(dir);
101
+ const parent = path.posix.dirname(dir);
102
+ if (parent === dir)
103
+ break;
104
+ dir = parent;
105
+ }
106
+ return serverFS.noop;
107
+ },
108
+ readFile: (fileName) => isHidden(fileName) ? undefined : (outputs.get(toOutputPath(fileName)) ?? serverFS.useOS),
109
+ fileExists: (fileName) => isHidden(fileName) ? false : outputs.has(toOutputPath(fileName)) || serverFS.useOS,
110
+ directoryExists: (directoryName) => outputDirectories.has(toOutputPath(directoryName)) || serverFS.useOS,
111
+ stat: (fileName) => {
112
+ if (isHidden(fileName)) {
113
+ return undefined;
114
+ }
115
+ const outputPath = toOutputPath(fileName);
116
+ const content = outputs.get(outputPath);
117
+ return content === undefined
118
+ ? serverFS.useOS
119
+ : {
120
+ mode: 0o100644,
121
+ size: Buffer.byteLength(content),
122
+ mtime: outputTimes.get(outputPath) ?? new Date(),
123
+ };
124
+ },
125
+ // never delete from the disk, where the user's real build output may be
126
+ removeFile: (fileName) => {
127
+ outputs.delete(fileName);
128
+ outputTimes.delete(fileName);
129
+ return serverFS.noop;
130
+ },
131
+ getAccessibleEntries: serverFS.useOS,
132
+ realpath: (fileName) => {
133
+ const outputPath = toOutputPath(fileName);
134
+ return outputs.has(outputPath) || outputDirectories.has(outputPath)
135
+ ? outputPath
136
+ : serverFS.useOS;
137
+ },
138
+ };
139
+ return { callbacks, invalidateRealDirectories: () => realDirectories.clear() };
140
+ }
@@ -1,3 +1,2 @@
1
- export declare function enablePerformanceIfNeeded(): void;
2
- export declare function disablePerformanceIfNeeded(): void;
1
+ export declare function resetPerformanceIfNeeded(): void;
3
2
  export declare function printPerformanceMeasuresIfNeeded(): void;
@@ -1,31 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.enablePerformanceIfNeeded = enablePerformanceIfNeeded;
4
- exports.disablePerformanceIfNeeded = disablePerformanceIfNeeded;
3
+ exports.resetPerformanceIfNeeded = resetPerformanceIfNeeded;
5
4
  exports.printPerformanceMeasuresIfNeeded = printPerformanceMeasuresIfNeeded;
6
- const typescript_1 = require("./typescript");
5
+ const api_1 = require("./api");
7
6
  const worker_config_1 = require("./worker-config");
8
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
- const performance = typescript_1.typescript.performance;
10
- function enablePerformanceIfNeeded() {
11
- var _a;
7
+ function resetPerformanceIfNeeded() {
12
8
  if (worker_config_1.config.profile) {
13
- (_a = performance === null || performance === void 0 ? void 0 : performance.enable) === null || _a === void 0 ? void 0 : _a.call(performance);
14
- }
15
- }
16
- function disablePerformanceIfNeeded() {
17
- var _a;
18
- if (worker_config_1.config.profile) {
19
- (_a = performance === null || performance === void 0 ? void 0 : performance.disable) === null || _a === void 0 ? void 0 : _a.call(performance);
9
+ (0, api_1.getApi)().resetTimingInfo();
20
10
  }
21
11
  }
22
12
  function printPerformanceMeasuresIfNeeded() {
23
- var _a;
24
13
  if (worker_config_1.config.profile) {
25
- const measures = {};
26
- (_a = performance === null || performance === void 0 ? void 0 : performance.forEachMeasure) === null || _a === void 0 ? void 0 : _a.call(performance, (measureName, duration) => {
27
- measures[measureName] = duration;
14
+ const { totals } = (0, api_1.getApi)().getTimingInfo();
15
+ console.table({
16
+ Requests: totals.requestCount,
17
+ 'Round trip (ms)': Math.round(totals.roundTripMs),
18
+ 'Compiler (ms)': Math.round(totals.serverTimeMs),
19
+ 'Transport (ms)': Math.round(totals.roundTripMs - totals.serverTimeMs),
20
+ 'Sent (bytes)': totals.bytesSent,
21
+ 'Received (bytes)': totals.bytesReceived,
28
22
  });
29
- console.table(measures);
30
23
  }
31
24
  }
@@ -1,2 +1,6 @@
1
- export declare function useProgram(): void;
2
- export declare function invalidateProgram(withHost?: boolean): void;
1
+ import type { FilesChange } from '../../../../files-change';
2
+ export declare function useProgram(change: FilesChange): void;
3
+ export declare function invalidateProgramConfig(): void;
4
+ export declare function invalidateProgramRootFileNames(): void;
5
+ /** Forgets the program without talking to the compiler, which may be gone. */
6
+ export declare function resetProgram(): void;