@mui/internal-docs-infra 0.13.1-canary.22 → 0.13.1-canary.23

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-docs-infra",
3
- "version": "0.13.1-canary.22",
3
+ "version": "0.13.1-canary.23",
4
4
  "author": "MUI Team",
5
5
  "description": "MUI Infra - internal documentation creation tools.",
6
6
  "license": "MIT",
@@ -813,5 +813,5 @@
813
813
  "bin": {
814
814
  "docs-infra": "./cli/index.mjs"
815
815
  },
816
- "gitSha": "80d3ec0d49901ddda4af788aeb3b1b51e21c07cc"
816
+ "gitSha": "0572f77091d6b3c01daa7626ab0b8a261735a136"
817
817
  }
@@ -303,7 +303,6 @@ function getOrCreateLanguageService(projectPath, compilerOptions) {
303
303
  // Create optimized compiler options
304
304
  const optimizedOptions = {
305
305
  ...compilerOptions,
306
- baseUrl: compilerOptions.baseUrl || projectPath,
307
306
  rootDir: compilerOptions.rootDir || projectPath,
308
307
  types: compilerOptions.types || [],
309
308
  skipLibCheck: true
@@ -1,4 +1,8 @@
1
1
  import ts from 'typescript';
2
+ /**
3
+ * Loads a tsconfig and caches the result until the tsconfig or any file it extends changes.
4
+ * Failed loads are not cached, so a fixed tsconfig is picked up on the next call.
5
+ */
2
6
  export declare function loadTypescriptConfig(configPath: string): Promise<{
3
7
  projectPath: string;
4
8
  options: ts.CompilerOptions;
@@ -23,113 +23,70 @@ function getTsConfigWatchers() {
23
23
  }
24
24
  return processObj[TSCONFIG_WATCHERS_KEY];
25
25
  }
26
- function setupFileWatcher(configPath) {
26
+ function setupFileWatcher(filePath) {
27
27
  const cache = getTsConfigCache();
28
28
  const watchers = getTsConfigWatchers();
29
29
 
30
30
  // Skip if already watching this file
31
- if (watchers.has(configPath)) {
31
+ if (watchers.has(filePath)) {
32
32
  return;
33
33
  }
34
34
 
35
35
  // Mark as watching
36
- watchers.add(configPath);
36
+ watchers.add(filePath);
37
37
 
38
38
  // Set up file watcher
39
- const watcher = fs.watch(configPath);
39
+ const watcher = fs.watch(filePath);
40
40
 
41
41
  // Handle file changes
42
42
  (async () => {
43
43
  try {
44
44
  for await (const event of watcher) {
45
45
  if (event.eventType === 'change') {
46
- // Purge this config and any configs that might extend it
47
- const cachedPaths = Array.from(cache.keys());
48
- const toPurge = cachedPaths.filter(cachedPath => cachedPath === configPath || cachedPath.includes(configPath));
49
- toPurge.forEach(pathToPurge => {
50
- cache.delete(pathToPurge);
51
- });
46
+ // Any cached config may extend the changed file, purge them all
47
+ cache.clear();
52
48
  }
53
49
  }
54
50
  } catch (error) {
55
51
  // Watcher was closed or file was deleted
56
- watchers.delete(configPath);
52
+ watchers.delete(filePath);
57
53
  }
58
54
  })();
59
55
  }
60
- function mergeConfig(target, source) {
61
- for (const key in source) {
62
- if (Object.prototype.hasOwnProperty.call(source, key)) {
63
- if (typeof target[key] === 'object' && target[key] !== null && typeof source[key] === 'object' && source[key] !== null && !Array.isArray(target[key]) && !Array.isArray(source[key])) {
64
- mergeConfig(target[key], source[key]);
65
- } else {
66
- target[key] = source[key];
67
- }
68
- }
69
- }
70
- return target;
71
- }
56
+ const FORMAT_DIAGNOSTICS_HOST = {
57
+ getCanonicalFileName: fileName => fileName,
58
+ getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
59
+ getNewLine: () => ts.sys.newLine
60
+ };
61
+
62
+ /**
63
+ * Reads and parses a tsconfig, letting TypeScript resolve `extends` with the same
64
+ * semantics as `tsc`. Throws the first configuration error as an `Error`.
65
+ */
72
66
  async function loadTypescriptConfigUncached(configPath) {
73
- const dependencies = [configPath];
74
67
  const projectPath = path.dirname(configPath);
75
68
  const data = await fs.readFile(configPath, 'utf-8');
76
- const {
77
- config,
78
- error
79
- } = ts.readConfigFile(configPath, filePath => {
80
- if (filePath !== configPath) {
81
- throw new Error(`Unexpected file path: ${filePath}`);
82
- }
83
- return data.toString();
84
- });
85
- if (error) {
86
- throw error;
69
+ const sourceFile = ts.readJsonConfigFile(configPath, () => data);
70
+ const parsed = ts.parseJsonSourceFileConfigFileContent(sourceFile, ts.sys, projectPath, undefined, configPath);
71
+ const [diagnostic] = ts.getConfigFileParsingDiagnostics(parsed);
72
+ if (diagnostic) {
73
+ throw new Error(ts.formatDiagnostic(diagnostic, FORMAT_DIAGNOSTICS_HOST).trim());
87
74
  }
88
- const {
89
- options,
90
- errors,
91
- raw
92
- } = ts.parseJsonConfigFileContent(config, ts.sys, projectPath);
93
- options.configFilePath = configPath;
94
- let mergedConfig = options;
95
- if (raw.extends) {
96
- const extendedConfigPath = path.resolve(projectPath, raw.extends);
97
- const {
98
- options: parentOptions,
99
- projectPath: parentPath,
100
- dependencies: parentDependencies
101
- } = await loadTypescriptConfig(extendedConfigPath);
102
- dependencies.push(...parentDependencies);
103
75
 
104
- // scope compilerOptions.paths relative to the tsconfig location
105
- if (parentOptions.paths) {
106
- Object.keys(parentOptions.paths).forEach(key => {
107
- if (!parentOptions.paths) {
108
- return;
109
- }
110
- const paths = [];
111
- parentOptions.paths[key].forEach(relativePath => {
112
- const absolutePath = path.resolve(parentPath, relativePath);
113
- let scopedPath = path.relative(projectPath, absolutePath);
114
- if (!scopedPath.startsWith('.')) {
115
- scopedPath = `./${scopedPath}`;
116
- }
117
- paths.push(scopedPath);
118
- });
119
- parentOptions.paths[key] = paths;
120
- });
121
- }
122
- mergedConfig = mergeConfig(parentOptions, mergedConfig);
123
- }
124
- if (errors.length > 0) {
125
- throw errors[0];
126
- }
76
+ // TypeScript reports extended files with forward slashes
77
+ const extendedFiles = (sourceFile.extendedSourceFiles ?? []).map(file => path.normalize(file));
78
+ extendedFiles.forEach(setupFileWatcher);
127
79
  return {
128
80
  projectPath,
129
- options: mergedConfig,
130
- dependencies
81
+ options: parsed.options,
82
+ dependencies: [configPath, ...extendedFiles]
131
83
  };
132
84
  }
85
+
86
+ /**
87
+ * Loads a tsconfig and caches the result until the tsconfig or any file it extends changes.
88
+ * Failed loads are not cached, so a fixed tsconfig is picked up on the next call.
89
+ */
133
90
  export async function loadTypescriptConfig(configPath) {
134
91
  const cache = getTsConfigCache();
135
92
 
@@ -145,5 +102,13 @@ export async function loadTypescriptConfig(configPath) {
145
102
  // Create and cache the promise
146
103
  const promise = loadTypescriptConfigUncached(configPath);
147
104
  cache.set(configPath, promise);
148
- return promise;
105
+ try {
106
+ return await promise;
107
+ } catch (error) {
108
+ // Leave a newer load alone if the cache was purged while this one ran
109
+ if (cache.get(configPath) === promise) {
110
+ cache.delete(configPath);
111
+ }
112
+ throw error;
113
+ }
149
114
  }