@travetto/compiler 4.0.4 → 4.0.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/package.json +1 -1
- package/src/state.ts +2 -2
- package/support/entry.trvc.ts +9 -2
- package/support/setup.ts +2 -1
- package/support/ts-util.ts +38 -0
- package/support/util.ts +1 -50
package/package.json
CHANGED
package/src/state.ts
CHANGED
|
@@ -4,7 +4,7 @@ import timers from 'node:timers/promises';
|
|
|
4
4
|
import { path, ManifestModuleUtil, ManifestModule, ManifestRoot, ManifestIndex } from '@travetto/manifest';
|
|
5
5
|
import { TransformerManager } from '@travetto/transformer';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { TypescriptUtil } from '../support/ts-util';
|
|
8
8
|
|
|
9
9
|
import { CompilerUtil } from './util';
|
|
10
10
|
import { CompileEmitError, CompileStateEntry } from './types';
|
|
@@ -82,7 +82,7 @@ export class CompilerState implements ts.CompilerHost {
|
|
|
82
82
|
this.#transformerManager = await TransformerManager.create(this.#manifestIndex);
|
|
83
83
|
|
|
84
84
|
this.#compilerOptions = {
|
|
85
|
-
...await
|
|
85
|
+
...await TypescriptUtil.getCompilerOptions(this.#manifest),
|
|
86
86
|
rootDir: this.#rootDir,
|
|
87
87
|
outDir: this.#outputPath
|
|
88
88
|
};
|
package/support/entry.trvc.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type { ManifestContext } from '@travetto/manifest';
|
|
|
6
6
|
|
|
7
7
|
import type { CompilerMode, CompilerServerInfo } from './types';
|
|
8
8
|
import { Log } from './log';
|
|
9
|
-
import { CommonUtil } from './util';
|
|
10
9
|
import { CompilerSetup } from './setup';
|
|
11
10
|
import { CompilerServer } from './server/server';
|
|
12
11
|
import { CompilerRunner } from './server/runner';
|
|
@@ -97,7 +96,15 @@ export const main = (ctx: ManifestContext) => {
|
|
|
97
96
|
Log.initLevel('error');
|
|
98
97
|
await compile('build');
|
|
99
98
|
}
|
|
100
|
-
|
|
99
|
+
|
|
100
|
+
return (mod, args) => {
|
|
101
|
+
const outputRoot = path.resolve(ctx.workspace.path, ctx.build.outputFolder);
|
|
102
|
+
process.env.TRV_MANIFEST = path.resolve(outputRoot, 'node_modules', ctx.main.name); // Setup for running
|
|
103
|
+
if (args) {
|
|
104
|
+
process.argv = [process.argv0, mod, ...args];
|
|
105
|
+
}
|
|
106
|
+
return import(path.join(outputRoot, 'node_modules', mod)); // Return function to run import on a module
|
|
107
|
+
};
|
|
101
108
|
},
|
|
102
109
|
|
|
103
110
|
/** Manifest entry point */
|
package/support/setup.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { type DeltaEvent, type ManifestContext, type Package } from '@travetto/m
|
|
|
6
6
|
|
|
7
7
|
import { Log } from './log';
|
|
8
8
|
import { CommonUtil } from './util';
|
|
9
|
+
import { TypescriptUtil } from './ts-util';
|
|
9
10
|
|
|
10
11
|
type ModFile = { input: string, output: string, stale: boolean };
|
|
11
12
|
|
|
@@ -57,7 +58,7 @@ export class CompilerSetup {
|
|
|
57
58
|
|
|
58
59
|
const ts = (await import('typescript')).default;
|
|
59
60
|
const content = ts.transpile(text, {
|
|
60
|
-
...await
|
|
61
|
+
...await TypescriptUtil.getCompilerOptions(ctx),
|
|
61
62
|
sourceMap: false,
|
|
62
63
|
inlineSourceMap: true,
|
|
63
64
|
}, inputFile);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { ManifestContext } from '@travetto/manifest';
|
|
5
|
+
|
|
6
|
+
const OPT_CACHE: Record<string, import('typescript').CompilerOptions> = {};
|
|
7
|
+
|
|
8
|
+
export class TypescriptUtil {
|
|
9
|
+
/**
|
|
10
|
+
* Returns the compiler options
|
|
11
|
+
*/
|
|
12
|
+
static async getCompilerOptions(ctx: ManifestContext): Promise<{}> {
|
|
13
|
+
if (!(ctx.workspace.path in OPT_CACHE)) {
|
|
14
|
+
let tsconfig = path.resolve(ctx.workspace.path, 'tsconfig.json');
|
|
15
|
+
|
|
16
|
+
if (!await fs.stat(tsconfig).then(_ => true, _ => false)) {
|
|
17
|
+
tsconfig = path.resolve(ctx.workspace.path, ctx.build.compilerModuleFolder, 'tsconfig.trv.json');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ts = (await import('typescript')).default;
|
|
21
|
+
|
|
22
|
+
const { options } = ts.parseJsonSourceFileConfigFileContent(
|
|
23
|
+
ts.readJsonConfigFile(tsconfig, ts.sys.readFile), ts.sys, ctx.workspace.path
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
OPT_CACHE[ctx.workspace.path] = {
|
|
27
|
+
...options,
|
|
28
|
+
allowJs: true,
|
|
29
|
+
resolveJsonModule: true,
|
|
30
|
+
sourceRoot: ctx.workspace.path,
|
|
31
|
+
rootDir: ctx.workspace.path,
|
|
32
|
+
outDir: path.resolve(ctx.workspace.path),
|
|
33
|
+
module: ctx.workspace.type === 'commonjs' ? ts.ModuleKind.CommonJS : ts.ModuleKind.ESNext,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return OPT_CACHE[ctx.workspace.path];
|
|
37
|
+
}
|
|
38
|
+
}
|
package/support/util.ts
CHANGED
|
@@ -1,45 +1,11 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import timers from 'node:timers/promises';
|
|
4
3
|
import { setMaxListeners } from 'node:events';
|
|
5
|
-
|
|
6
|
-
import type { ManifestContext } from '@travetto/manifest';
|
|
4
|
+
import timers from 'node:timers/promises';
|
|
7
5
|
|
|
8
6
|
import { Log } from './log';
|
|
9
7
|
|
|
10
|
-
const OPT_CACHE: Record<string, import('typescript').CompilerOptions> = {};
|
|
11
|
-
|
|
12
8
|
export class CommonUtil {
|
|
13
|
-
/**
|
|
14
|
-
* Returns the compiler options
|
|
15
|
-
*/
|
|
16
|
-
static async getCompilerOptions(ctx: ManifestContext): Promise<{}> {
|
|
17
|
-
if (!(ctx.workspace.path in OPT_CACHE)) {
|
|
18
|
-
let tsconfig = path.resolve(ctx.workspace.path, 'tsconfig.json');
|
|
19
|
-
|
|
20
|
-
if (!await fs.stat(tsconfig).then(_ => true, _ => false)) {
|
|
21
|
-
tsconfig = path.resolve(ctx.workspace.path, ctx.build.compilerModuleFolder, 'tsconfig.trv.json');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const ts = (await import('typescript')).default;
|
|
25
|
-
|
|
26
|
-
const { options } = ts.parseJsonSourceFileConfigFileContent(
|
|
27
|
-
ts.readJsonConfigFile(tsconfig, ts.sys.readFile), ts.sys, ctx.workspace.path
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
OPT_CACHE[ctx.workspace.path] = {
|
|
31
|
-
...options,
|
|
32
|
-
allowJs: true,
|
|
33
|
-
resolveJsonModule: true,
|
|
34
|
-
sourceRoot: ctx.workspace.path,
|
|
35
|
-
rootDir: ctx.workspace.path,
|
|
36
|
-
outDir: path.resolve(ctx.workspace.path),
|
|
37
|
-
module: ctx.workspace.type === 'commonjs' ? ts.ModuleKind.CommonJS : ts.ModuleKind.ESNext,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
return OPT_CACHE[ctx.workspace.path];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
9
|
/**
|
|
44
10
|
* Determine file type
|
|
45
11
|
*/
|
|
@@ -92,21 +58,6 @@ export class CommonUtil {
|
|
|
92
58
|
}
|
|
93
59
|
}
|
|
94
60
|
|
|
95
|
-
/**
|
|
96
|
-
* Create a module loader given a context, and assuming build is complete
|
|
97
|
-
* @param ctx
|
|
98
|
-
*/
|
|
99
|
-
static moduleLoader(ctx: ManifestContext): (mod: string, args?: string[]) => Promise<unknown> {
|
|
100
|
-
return (mod, args) => {
|
|
101
|
-
const outputRoot = path.resolve(ctx.workspace.path, ctx.build.outputFolder);
|
|
102
|
-
process.env.TRV_MANIFEST = path.resolve(outputRoot, 'node_modules', ctx.main.name); // Setup for running
|
|
103
|
-
if (args) {
|
|
104
|
-
process.argv = [process.argv0, mod, ...args];
|
|
105
|
-
}
|
|
106
|
-
return import(path.join(outputRoot, 'node_modules', mod)); // Return function to run import on a module
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
61
|
/**
|
|
111
62
|
* Non-blocking timeout, that is cancellable
|
|
112
63
|
*/
|