@travetto/compiler 5.0.11 → 5.0.12
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/common.js +2 -1
- package/bin/manifest-context.mjs +32 -97
- package/package.json +4 -4
- package/src/watch.ts +1 -0
package/bin/common.js
CHANGED
|
@@ -57,10 +57,11 @@ async function getEntry() {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// Load module on demand
|
|
60
|
+
/** @type {import('@travetto/manifest/src/context')} */
|
|
60
61
|
const { getManifestContext } = await import(manifestJs);
|
|
61
62
|
|
|
62
63
|
/** @type {Ctx} */
|
|
63
|
-
const ctx = getManifestContext();
|
|
64
|
+
const ctx = getManifestContext(process.cwd(), process.env.TRV_MODULE);
|
|
64
65
|
const target = getTarget.bind(null, ctx);
|
|
65
66
|
|
|
66
67
|
// Setup Tsconfig
|
package/bin/manifest-context.mjs
CHANGED
|
@@ -1,121 +1,56 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function readPackage(dir) {
|
|
10
|
-
dir = dir.endsWith('.json') ? path.dirname(dir) : dir;
|
|
11
|
-
try {
|
|
12
|
-
const v = readFileSync(path.resolve(dir, 'package.json'), 'utf8');
|
|
13
|
-
return ({ ...JSON.parse(v), path: path.resolve(dir) });
|
|
14
|
-
}
|
|
15
|
-
catch { }
|
|
16
|
-
}
|
|
17
|
-
function findPackage(dir) {
|
|
18
|
-
let prev;
|
|
19
|
-
let pkg, curr = path.resolve(dir);
|
|
20
|
-
while (!pkg && curr !== prev) {
|
|
21
|
-
pkg = readPackage(curr);
|
|
22
|
-
[prev, curr] = [curr, path.dirname(curr)];
|
|
23
|
-
}
|
|
24
|
-
if (!pkg) {
|
|
25
|
-
throw new Error('Could not find a package.json');
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return pkg;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function resolveWorkspace(base = process.cwd()) {
|
|
32
|
-
if (base in WS_ROOT) {
|
|
33
|
-
return WS_ROOT[base];
|
|
34
|
-
}
|
|
35
|
-
let folder = base;
|
|
4
|
+
const toPort = (pth) => (Math.abs([...pth].reduce((a, b) => (a * 33) ^ b.charCodeAt(0), 5381)) % 29000) + 20000;
|
|
5
|
+
const toPosix = (pth) => pth.replaceAll('\\', '/');
|
|
6
|
+
const readPackage = (file) => ({ ...JSON.parse(readFileSync(file, 'utf8')), path: toPosix(path.dirname(file)) });
|
|
7
|
+
function findPackage(base, pred) {
|
|
8
|
+
let folder = `${base}/.`;
|
|
36
9
|
let prev;
|
|
37
10
|
let pkg;
|
|
38
|
-
|
|
11
|
+
do {
|
|
39
12
|
prev = folder;
|
|
40
|
-
pkg = readPackage(folder) ?? pkg;
|
|
41
|
-
if ((pkg && (!!pkg.workspaces || !!pkg.travetto?.build?.isolated)) ||
|
|
42
|
-
existsSync(path.resolve(folder, '.git'))) {
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
13
|
folder = path.dirname(folder);
|
|
46
|
-
|
|
14
|
+
const folderPkg = path.resolve(folder, 'package.json');
|
|
15
|
+
pkg = existsSync(folderPkg) ? readPackage(folderPkg) : pkg;
|
|
16
|
+
} while (prev !== folder &&
|
|
17
|
+
!pred(pkg) &&
|
|
18
|
+
!existsSync(path.resolve(folder, '.git')));
|
|
47
19
|
if (!pkg) {
|
|
48
20
|
throw new Error('Could not find a package.json');
|
|
49
21
|
}
|
|
50
|
-
return
|
|
51
|
-
...pkg,
|
|
52
|
-
name: pkg.name ?? 'untitled',
|
|
53
|
-
type: pkg.type,
|
|
54
|
-
manager: existsSync(path.resolve(pkg.path, 'yarn.lock')) ? 'yarn' : 'npm',
|
|
55
|
-
resolve: createRequire(`${pkg.path}/node_modules`).resolve.bind(null),
|
|
56
|
-
stripRoot: (full) => full === pkg.path ? '' : full.replace(`${pkg.path}/`, ''),
|
|
57
|
-
mono: !!pkg.workspaces
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
function getCompilerUrl(ws) {
|
|
61
|
-
const port = (Math.abs([...ws.path].reduce((a, b) => (a * 33) ^ b.charCodeAt(0), 5381)) % 29000) + 20000;
|
|
62
|
-
return `http://localhost:${port}`;
|
|
63
|
-
}
|
|
64
|
-
function resolveModule(workspace, folder) {
|
|
65
|
-
let mod;
|
|
66
|
-
if (!folder && process.env.TRV_MODULE) {
|
|
67
|
-
mod = process.env.TRV_MODULE;
|
|
68
|
-
if (/[.][cm]?(t|j)sx?$/.test(mod)) {
|
|
69
|
-
try {
|
|
70
|
-
process.env.TRV_MODULE = mod = findPackage(path.dirname(mod)).name;
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
process.env.TRV_MODULE = mod = '';
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (mod) {
|
|
78
|
-
try {
|
|
79
|
-
folder = path.dirname(workspace.resolve(`${mod}/package.json`));
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
const workspacePkg = readPackage(workspace.path);
|
|
83
|
-
if (workspacePkg?.name === mod) {
|
|
84
|
-
folder = workspace.path;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
throw new Error(`Unable to resolve location for ${folder}`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return findPackage(folder ?? '.');
|
|
22
|
+
return pkg;
|
|
92
23
|
}
|
|
93
|
-
export function getManifestContext(
|
|
94
|
-
const workspace =
|
|
95
|
-
const mod = resolveModule(workspace, folder);
|
|
24
|
+
export function getManifestContext(root, mod) {
|
|
25
|
+
const workspace = findPackage(root, pkg => !!pkg?.workspaces || !!pkg?.travetto?.build?.isolated);
|
|
96
26
|
const build = workspace.travetto?.build ?? {};
|
|
27
|
+
const resolve = createRequire(path.resolve(workspace.path, 'node_modules')).resolve.bind(null);
|
|
28
|
+
const wsPrefix = `${workspace.path}/`;
|
|
29
|
+
const modPkg = mod ?
|
|
30
|
+
readPackage(resolve(`${mod}/package.json`)) :
|
|
31
|
+
findPackage(root, pkg => !!pkg) ?? workspace;
|
|
97
32
|
return {
|
|
98
33
|
workspace: {
|
|
99
|
-
name: workspace.name,
|
|
34
|
+
name: workspace.name ?? 'untitled',
|
|
100
35
|
path: workspace.path,
|
|
101
|
-
mono: workspace.
|
|
102
|
-
manager: workspace.
|
|
36
|
+
mono: !!workspace.workspaces,
|
|
37
|
+
manager: existsSync(path.resolve(workspace.path, 'yarn.lock')) ? 'yarn' : 'npm',
|
|
103
38
|
type: workspace.type ?? 'commonjs',
|
|
104
39
|
defaultEnv: workspace.travetto?.defaultEnv ?? 'local'
|
|
105
40
|
},
|
|
106
41
|
build: {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
outputFolder: build.outputFolder ??
|
|
111
|
-
toolFolder: build.toolFolder ??
|
|
112
|
-
typesFolder: build.typesFolder ??
|
|
42
|
+
compilerUrl: build.compilerUrl ?? `http://localhost:${toPort(wsPrefix)}`,
|
|
43
|
+
compilerModuleFolder: toPosix(path.dirname(resolve('@travetto/compiler/package.json'))).replace(wsPrefix, ''),
|
|
44
|
+
compilerFolder: toPosix(build.compilerFolder ?? '.trv/compiler'),
|
|
45
|
+
outputFolder: toPosix(build.outputFolder ?? '.trv/output'),
|
|
46
|
+
toolFolder: toPosix(build.toolFolder ?? '.trv/tool'),
|
|
47
|
+
typesFolder: toPosix(build.typesFolder ?? '.trv/types')
|
|
113
48
|
},
|
|
114
49
|
main: {
|
|
115
|
-
name:
|
|
116
|
-
folder:
|
|
117
|
-
version:
|
|
118
|
-
description:
|
|
50
|
+
name: modPkg.name ?? 'untitled',
|
|
51
|
+
folder: modPkg.path.replace(wsPrefix, ''),
|
|
52
|
+
version: modPkg.version,
|
|
53
|
+
description: modPkg.description
|
|
119
54
|
}
|
|
120
55
|
};
|
|
121
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/compiler",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.12",
|
|
4
4
|
"description": "The compiler infrastructure for the Travetto framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@parcel/watcher": "^2.4.1",
|
|
36
|
-
"@travetto/manifest": "^5.0.
|
|
37
|
-
"@travetto/transformer": "^5.0.
|
|
36
|
+
"@travetto/manifest": "^5.0.6",
|
|
37
|
+
"@travetto/transformer": "^5.0.7",
|
|
38
38
|
"@types/node": "^22.7.4"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@travetto/cli": "^5.0.
|
|
41
|
+
"@travetto/cli": "^5.0.9"
|
|
42
42
|
},
|
|
43
43
|
"peerDependenciesMeta": {
|
|
44
44
|
"@travetto/cli": {
|
package/src/watch.ts
CHANGED
|
@@ -141,6 +141,7 @@ export class CompilerWatcher {
|
|
|
141
141
|
const packageFiles = new Set(['package-lock.json', 'yarn.lock', 'package.json'].map(x => path.resolve(this.#root, x)));
|
|
142
142
|
|
|
143
143
|
log.debug('Ignore Globs', ignore);
|
|
144
|
+
log.debug('Watching', this.#root);
|
|
144
145
|
|
|
145
146
|
await this.#cleanup.workspace?.();
|
|
146
147
|
|