@travetto/compiler 8.0.0-alpha.4 → 8.0.0-alpha.6
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/bin/hook.js +5 -14
- package/bin/trvc-target.js +1 -0
- package/bin/trvc.js +1 -0
- package/package.json +4 -4
- package/src/state.ts +44 -22
package/bin/hook.js
CHANGED
|
@@ -1,26 +1,17 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import module from 'node:module';
|
|
2
3
|
import { readFileSync } from 'node:fs';
|
|
3
4
|
import { fileURLToPath } from 'node:url';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
process.setSourceMapsEnabled(true); // Ensure source map during compilation/development
|
|
8
|
-
process.env.NODE_OPTIONS = `${process.env.NODE_OPTIONS ?? ''} --enable-source-maps`; // Ensure it passes to children
|
|
9
|
-
const ogEmitWarning = process.emitWarning;
|
|
10
|
-
Error.stackTraceLimit = 50;
|
|
6
|
+
globalThis.devProcessWarningExclusions?.push((message) => message.startsWith('stripTypeScriptTypes'));
|
|
11
7
|
|
|
12
8
|
module.registerHooks({
|
|
13
9
|
load: (url, context, nextLoad) => {
|
|
14
10
|
if (/[.]tsx?$/.test(url)) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const source = readFileSync(fileURLToPath(url), 'utf8');
|
|
18
|
-
return { format: 'module', source: module.stripTypeScriptTypes(source), shortCircuit: true };
|
|
19
|
-
} finally {
|
|
20
|
-
process.emitWarning = ogEmitWarning;
|
|
21
|
-
}
|
|
11
|
+
const source = readFileSync(fileURLToPath(url), 'utf8');
|
|
12
|
+
return { format: 'module', source: module.stripTypeScriptTypes(source), shortCircuit: true };
|
|
22
13
|
} else {
|
|
23
14
|
return nextLoad(url, context);
|
|
24
15
|
}
|
|
25
16
|
}
|
|
26
|
-
});
|
|
17
|
+
});
|
package/bin/trvc-target.js
CHANGED
package/bin/trvc.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/compiler",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The compiler infrastructure for the Travetto framework",
|
|
6
6
|
"keywords": [
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@parcel/watcher": "^2.5.6",
|
|
34
|
-
"@travetto/manifest": "^8.0.0-alpha.
|
|
35
|
-
"@travetto/transformer": "^8.0.0-alpha.
|
|
34
|
+
"@travetto/manifest": "^8.0.0-alpha.4",
|
|
35
|
+
"@travetto/transformer": "^8.0.0-alpha.4"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@travetto/cli": "^8.0.0-alpha.
|
|
38
|
+
"@travetto/cli": "^8.0.0-alpha.9"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
41
|
"@travetto/cli": {
|
package/src/state.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
1
2
|
import type { CompilerHost, SourceFile, CompilerOptions, Program, ScriptTarget } from 'typescript';
|
|
2
3
|
|
|
3
4
|
import { path, ManifestModuleUtil, type ManifestModule, type ManifestRoot, type ManifestIndex, type ManifestModuleFolderType } from '@travetto/manifest';
|
|
@@ -39,10 +40,37 @@ export class CompilerState implements CompilerHost {
|
|
|
39
40
|
#program: Program;
|
|
40
41
|
|
|
41
42
|
#readFile(sourceFile: string): string | undefined {
|
|
42
|
-
|
|
43
|
+
const location = this.#sourceToEntry.get(sourceFile)?.sourceFile ?? sourceFile;
|
|
44
|
+
try {
|
|
45
|
+
return ts.sys.readFile(location, 'utf8');
|
|
46
|
+
} catch {
|
|
47
|
+
try { return fs.readFileSync(location, 'utf8'); } catch { }
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#writeFile(location: string, text: string, bom?: boolean): void {
|
|
53
|
+
try {
|
|
54
|
+
ts.sys.writeFile(location, text, bom);
|
|
55
|
+
} catch {
|
|
56
|
+
fs.mkdirSync(path.dirname(location), { recursive: true });
|
|
57
|
+
fs.writeFileSync(location, text, 'utf8');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#fileExists(location: string): boolean {
|
|
62
|
+
try {
|
|
63
|
+
return ts.sys.fileExists(location);
|
|
64
|
+
} catch { return fs.existsSync(location); }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#directoryExists(location: string): boolean {
|
|
68
|
+
try {
|
|
69
|
+
return ts.sys.directoryExists(location);
|
|
70
|
+
} catch { return fs.existsSync(location); }
|
|
43
71
|
}
|
|
44
72
|
|
|
45
|
-
#writeExternalTypings(location: string, text: string, bom
|
|
73
|
+
#writeExternalTypings(location: string, text: string, bom?: boolean): void {
|
|
46
74
|
let core = location.replace('.map', '');
|
|
47
75
|
if (!this.#outputToEntry.has(core)) {
|
|
48
76
|
core = core.replace(ManifestModuleUtil.TYPINGS_EXT_REGEX, ManifestModuleUtil.OUTPUT_EXT);
|
|
@@ -51,7 +79,7 @@ export class CompilerState implements CompilerHost {
|
|
|
51
79
|
if (entry) {
|
|
52
80
|
const relative = this.#manifestIndex.getFromSource(entry.sourceFile)?.relativeFile;
|
|
53
81
|
if (relative && TYPINGS_FOLDER_KEYS.has(ManifestModuleUtil.getFolderKey(relative))) {
|
|
54
|
-
|
|
82
|
+
this.#writeFile(location.replace(this.#outputPath, this.#typingsPath), text, bom);
|
|
55
83
|
}
|
|
56
84
|
}
|
|
57
85
|
}
|
|
@@ -59,7 +87,7 @@ export class CompilerState implements CompilerHost {
|
|
|
59
87
|
async #initCompilerOptions(): Promise<CompilerOptions> {
|
|
60
88
|
const tsconfigFile = CommonUtil.resolveWorkspace(this.#manifest, 'tsconfig.json');
|
|
61
89
|
if (!ts.sys.fileExists(tsconfigFile)) {
|
|
62
|
-
|
|
90
|
+
this.#writeFile(tsconfigFile, JSON.stringify({ extends: '@travetto/compiler/tsconfig.trv.json' }, null, 2));
|
|
63
91
|
}
|
|
64
92
|
|
|
65
93
|
const { options } = ts.parseJsonSourceFileConfigFileContent(
|
|
@@ -153,16 +181,18 @@ export class CompilerState implements CompilerHost {
|
|
|
153
181
|
return;
|
|
154
182
|
}
|
|
155
183
|
|
|
156
|
-
const program = await this.getProgram(needsNewProgram);
|
|
157
184
|
switch (ManifestModuleUtil.getFileType(sourceFile)) {
|
|
158
|
-
case 'typings':
|
|
159
|
-
case 'package-json':
|
|
160
|
-
this.writeFile(output, this.readFile(sourceFile)!, false), undefined;
|
|
161
|
-
break;
|
|
162
185
|
case 'js':
|
|
163
|
-
|
|
186
|
+
case 'typings':
|
|
187
|
+
case 'package-json': {
|
|
188
|
+
const text = this.readFile(sourceFile)!;
|
|
189
|
+
const finalText = sourceFile.endsWith('package.json') ? CompilerUtil.rewritePackageJSON(this.#manifest, text) : text;
|
|
190
|
+
const location = this.#tscOutputFileToOuptut.get(output) ?? output;
|
|
191
|
+
this.#writeFile(location, finalText, false);
|
|
164
192
|
break;
|
|
193
|
+
}
|
|
165
194
|
case 'ts': {
|
|
195
|
+
const program = await this.getProgram(needsNewProgram);
|
|
166
196
|
const tsSourceFile = program.getSourceFile(sourceFile)!;
|
|
167
197
|
program.emit(
|
|
168
198
|
tsSourceFile,
|
|
@@ -286,22 +316,14 @@ export class CompilerState implements CompilerHost {
|
|
|
286
316
|
getDefaultLibLocation(): string { return path.dirname(ts.getDefaultLibFilePath(this.#compilerOptions)); }
|
|
287
317
|
|
|
288
318
|
fileExists(sourceFile: string): boolean {
|
|
289
|
-
return this.#sourceToEntry.has(sourceFile) ||
|
|
319
|
+
return this.#sourceToEntry.has(sourceFile) || this.#fileExists(sourceFile);
|
|
290
320
|
}
|
|
291
321
|
|
|
292
322
|
directoryExists(sourceDirectory: string): boolean {
|
|
293
|
-
return this.#sourceDirectory.has(sourceDirectory) ||
|
|
323
|
+
return this.#sourceDirectory.has(sourceDirectory) || this.#directoryExists(sourceDirectory);
|
|
294
324
|
}
|
|
295
325
|
|
|
296
|
-
writeFile(
|
|
297
|
-
outputFile: string,
|
|
298
|
-
text: string,
|
|
299
|
-
bom: boolean
|
|
300
|
-
): void {
|
|
301
|
-
if (outputFile.endsWith('package.json')) {
|
|
302
|
-
text = CompilerUtil.rewritePackageJSON(this.#manifest, text);
|
|
303
|
-
}
|
|
304
|
-
|
|
326
|
+
writeFile(outputFile: string, text: string, bom?: boolean): void {
|
|
305
327
|
// JSX runtime shenanigans
|
|
306
328
|
text = text.replace(/support\/jsx-runtime"/g, 'support/jsx-runtime.js"');
|
|
307
329
|
|
|
@@ -311,7 +333,7 @@ export class CompilerState implements CompilerHost {
|
|
|
311
333
|
this.#writeExternalTypings(location, text, bom);
|
|
312
334
|
}
|
|
313
335
|
|
|
314
|
-
|
|
336
|
+
return this.#writeFile(location, text, bom);
|
|
315
337
|
}
|
|
316
338
|
|
|
317
339
|
readFile(sourceFile: string): string | undefined {
|