@travetto/compiler 3.0.0-rc.8 → 3.0.0
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/README.md +68 -14
- package/__index__.ts +4 -1
- package/bin/trv.js +57 -63
- package/package.json +8 -6
- package/src/compiler.ts +74 -113
- package/src/log.ts +18 -0
- package/src/state.ts +160 -166
- package/src/types.ts +14 -0
- package/src/util.ts +32 -87
- package/src/watch.ts +142 -0
- package/support/compiler-entry.ts +2 -0
- package/support/launcher.ts +152 -0
- package/support/lock-pinger.ts +25 -0
- package/support/lock.ts +234 -0
- package/support/log.ts +51 -0
- package/support/transpile.ts +210 -0
- package/tsconfig.trv.json +1 -0
- package/bin/transpile.d.ts +0 -32
- package/bin/transpile.js +0 -227
- package/support/bin/compiler-bootstrap.ts +0 -151
- package/support/bin/utils.ts +0 -116
- package/support/main.output.ts +0 -11
package/support/bin/utils.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { type Stats } from 'fs';
|
|
5
|
-
import { createRequire } from 'module';
|
|
6
|
-
|
|
7
|
-
import type { ManifestContext, ManifestUtil } from '@travetto/manifest';
|
|
8
|
-
|
|
9
|
-
import { transpileFile, writePackageJson } from '../../bin/transpile';
|
|
10
|
-
|
|
11
|
-
const req = createRequire(`${process.cwd()}/node_modules`);
|
|
12
|
-
|
|
13
|
-
type ModFile = { input: string, output: string, stale: boolean };
|
|
14
|
-
|
|
15
|
-
const SOURCE_SEED = ['package.json', 'index.ts', '__index__.ts', 'src', 'support', 'bin'];
|
|
16
|
-
|
|
17
|
-
export const IS_DEBUG = /\b([*]|build)\b/.test(process.env.DEBUG ?? '');
|
|
18
|
-
|
|
19
|
-
const resolveImport = (lib: string): string => req.resolve(lib);
|
|
20
|
-
const recentStat = (stat: Stats): number => Math.max(stat.ctimeMs, stat.mtimeMs);
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Common logging support
|
|
24
|
-
*/
|
|
25
|
-
export const log = IS_DEBUG ?
|
|
26
|
-
(...args: unknown[]): void => console.debug(new Date().toISOString(), ...args) :
|
|
27
|
-
(): void => { };
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Scan directory to find all project sources for comparison
|
|
31
|
-
*/
|
|
32
|
-
export async function getProjectSources(
|
|
33
|
-
ctx: ManifestContext, module: string, seed: string[] = SOURCE_SEED
|
|
34
|
-
): Promise<ModFile[]> {
|
|
35
|
-
const inputFolder = (ctx.mainModule === module) ?
|
|
36
|
-
process.cwd() :
|
|
37
|
-
path.dirname(resolveImport(`${module}/package.json`));
|
|
38
|
-
|
|
39
|
-
const folders = seed.filter(x => !/[.]/.test(x)).map(x => path.resolve(inputFolder, x));
|
|
40
|
-
const files = seed.filter(x => /[.]/.test(x)).map(x => path.resolve(inputFolder, x));
|
|
41
|
-
|
|
42
|
-
while (folders.length) {
|
|
43
|
-
const sub = folders.pop();
|
|
44
|
-
if (!sub) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
for (const file of await fs.readdir(sub).catch(() => [])) {
|
|
49
|
-
if (file.startsWith('.')) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
const resolvedInput = path.resolve(sub, file);
|
|
53
|
-
const stat = await fs.stat(resolvedInput);
|
|
54
|
-
|
|
55
|
-
if (stat.isDirectory()) {
|
|
56
|
-
folders.push(resolvedInput);
|
|
57
|
-
} else if (file.endsWith('.d.ts')) {
|
|
58
|
-
// Do nothing
|
|
59
|
-
} else if (file.endsWith('.ts') || file.endsWith('.js')) {
|
|
60
|
-
files.push(resolvedInput);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const outputFolder = path.resolve(ctx.workspacePath, ctx.compilerFolder, 'node_modules', module);
|
|
66
|
-
const out: ModFile[] = [];
|
|
67
|
-
for (const input of files) {
|
|
68
|
-
const output = input.replace(inputFolder, outputFolder).replace(/[.]ts$/, '.js');
|
|
69
|
-
const inputTs = await fs.stat(input).then(recentStat, () => 0);
|
|
70
|
-
if (inputTs) {
|
|
71
|
-
const outputTs = await fs.stat(output).then(recentStat, () => 0);
|
|
72
|
-
await fs.mkdir(path.dirname(output), { recursive: true, });
|
|
73
|
-
out.push({ input, output, stale: inputTs > outputTs });
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return out;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Recompile folder if stale
|
|
82
|
-
*/
|
|
83
|
-
export async function compileIfStale(ctx: ManifestContext, prefix: string, files: ModFile[]): Promise<void> {
|
|
84
|
-
try {
|
|
85
|
-
if (files.some(f => f.stale)) {
|
|
86
|
-
log(`${prefix} Starting`);
|
|
87
|
-
for (const file of files.filter(x => x.stale)) {
|
|
88
|
-
if (file.input.endsWith('package.json')) {
|
|
89
|
-
await writePackageJson(ctx, file.input, file.output);
|
|
90
|
-
} else {
|
|
91
|
-
await transpileFile(ctx, file.input, file.output);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
log(`${prefix} Skipped`);
|
|
96
|
-
}
|
|
97
|
-
} catch (err) {
|
|
98
|
-
console.error(err);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Add node path at runtime
|
|
104
|
-
*/
|
|
105
|
-
export async function addNodePath(folder: string): Promise<void> {
|
|
106
|
-
process.env.NODE_PATH = [`${folder}/node_modules`, process.env.NODE_PATH].join(path.delimiter);
|
|
107
|
-
const { Module } = await import('module');
|
|
108
|
-
// @ts-expect-error
|
|
109
|
-
Module._initPaths();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Import the manifest utils once compiled
|
|
114
|
-
*/
|
|
115
|
-
export const importManifest = (ctx: ManifestContext): Promise<{ ManifestUtil: typeof ManifestUtil }> =>
|
|
116
|
-
import(path.resolve(ctx.workspacePath, ctx.compilerFolder, 'node_modules', '@travetto', 'manifest', '__index__.js'));
|
package/support/main.output.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import { install } from 'source-map-support';
|
|
3
|
-
|
|
4
|
-
import { ManifestState } from '@travetto/manifest';
|
|
5
|
-
|
|
6
|
-
import { Compiler } from '../src/compiler';
|
|
7
|
-
|
|
8
|
-
install();
|
|
9
|
-
const [manifestState, watch] = process.argv.slice(2);
|
|
10
|
-
const state: ManifestState = JSON.parse(readFileSync(manifestState, 'utf8'));
|
|
11
|
-
new Compiler().init(state).run(watch === 'true');
|