@decohere/workspace 0.0.1-dev.20261123.408 → 0.0.1-dev.20261125.414
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/es6/src/factories/workspace.factory.js +3 -1
- package/es6/src/models/has-tsconfig.mixin.js +6 -2
- package/es6/src/models/jsonc.js +16 -6
- package/es6/src/models/package-aliases.js +26 -10
- package/es6/src/models/project-scripts.js +3 -1
- package/es6/src/models/project.model.js +24 -8
- package/es6/src/models/source-extensions.js +17 -9
- package/es6/src/models/workspace.model.js +3 -1
- package/package.json +4 -4
|
@@ -46,7 +46,9 @@ class Factory {
|
|
|
46
46
|
}
|
|
47
47
|
async getPackageJson(rootDir) {
|
|
48
48
|
const packageJsonPath = path.join(rootDir, PACKAGE_JSON);
|
|
49
|
-
if (!await io.fileExists(packageJsonPath))
|
|
49
|
+
if (!await io.fileExists(packageJsonPath)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
50
52
|
const data = await io.readJsonFile(packageJsonPath);
|
|
51
53
|
return new PackageJson(data);
|
|
52
54
|
}
|
|
@@ -16,13 +16,17 @@ import { Tsconfig } from "./tsconfig.model.js";
|
|
|
16
16
|
export class HasTsConfig {
|
|
17
17
|
async getTsConfig() {
|
|
18
18
|
for (const configPath of this.tsConfigPaths){
|
|
19
|
-
if (await io.fileExists(configPath))
|
|
19
|
+
if (await io.fileExists(configPath)) {
|
|
20
|
+
return Tsconfig.parse(configPath);
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
return Tsconfig.default();
|
|
22
24
|
}
|
|
23
25
|
getTsConfigSync() {
|
|
24
26
|
const configPath = this.findTsConfigPath();
|
|
25
|
-
if (configPath != null)
|
|
27
|
+
if (configPath != null) {
|
|
28
|
+
return Tsconfig.parseSync(configPath);
|
|
29
|
+
}
|
|
26
30
|
return Tsconfig.default();
|
|
27
31
|
}
|
|
28
32
|
/** First existing `tsconfig.json` on this object, if any. */ findTsConfigPath() {
|
package/es6/src/models/jsonc.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* Parses JSON with comments and trailing commas, as `tsconfig.json` allows. An empty file is
|
|
3
3
|
* `{}`, as tsc reads it. Throws a `SyntaxError` on anything else that isn't valid JSON.
|
|
4
4
|
*/ export function parseJsonc(text) {
|
|
5
|
-
if (text.trim() === "")
|
|
5
|
+
if (text.trim() === "") {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
6
8
|
return JSON.parse(stripJsonc(text));
|
|
7
9
|
}
|
|
8
10
|
function stripJsonc(text) {
|
|
@@ -20,13 +22,17 @@ function stripJsonc(text) {
|
|
|
20
22
|
i = end === -1 ? text.length : end;
|
|
21
23
|
} else if (char === "/" && next === "*") {
|
|
22
24
|
const end = text.indexOf("*/", i + 2);
|
|
23
|
-
if (end === -1)
|
|
25
|
+
if (end === -1) {
|
|
26
|
+
throw new SyntaxError("Unterminated comment in JSON");
|
|
27
|
+
}
|
|
24
28
|
out += " ";
|
|
25
29
|
i = end + 2;
|
|
26
30
|
} else if (char === "}" || char === "]") {
|
|
27
31
|
// Drop a trailing comma before the closing bracket.
|
|
28
32
|
out = out.trimEnd();
|
|
29
|
-
if (out.endsWith(","))
|
|
33
|
+
if (out.endsWith(",")) {
|
|
34
|
+
out = out.slice(0, -1);
|
|
35
|
+
}
|
|
30
36
|
out += char;
|
|
31
37
|
i++;
|
|
32
38
|
} else {
|
|
@@ -39,9 +45,13 @@ function stripJsonc(text) {
|
|
|
39
45
|
/** Index just past the string starting at `start` (a `"`); an unclosed string runs to the end. */ function stringEnd(text, start) {
|
|
40
46
|
let i = start + 1;
|
|
41
47
|
while(i < text.length){
|
|
42
|
-
if (text[i] === "\\")
|
|
43
|
-
|
|
44
|
-
else i
|
|
48
|
+
if (text[i] === "\\") {
|
|
49
|
+
i += 2;
|
|
50
|
+
} else if (text[i] === '"') {
|
|
51
|
+
return i + 1;
|
|
52
|
+
} else {
|
|
53
|
+
i++;
|
|
54
|
+
}
|
|
45
55
|
}
|
|
46
56
|
return text.length;
|
|
47
57
|
}
|
|
@@ -22,15 +22,21 @@ import { sourceExtensions } from "./source-extensions.js";
|
|
|
22
22
|
* Resolve a bare specifier through package aliases (SWC-style `paths`
|
|
23
23
|
* relative to `baseUrl`) to an absolute `.ts` path. Longest key wins.
|
|
24
24
|
*/ function resolvePath(specifier, paths, baseUrl) {
|
|
25
|
-
if (!isBareSpecifier(specifier))
|
|
25
|
+
if (!isBareSpecifier(specifier)) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
26
28
|
const resolvedBase = path.resolve(baseUrl);
|
|
27
29
|
const keys = Object.keys(paths).sort((a, b)=>b.length - a.length);
|
|
28
30
|
for (const key of keys){
|
|
29
31
|
const target = paths[key]?.[0];
|
|
30
|
-
if (target == null)
|
|
32
|
+
if (target == null) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
31
35
|
if (key.endsWith("/*")) {
|
|
32
36
|
const prefix = key.slice(0, -1);
|
|
33
|
-
if (!specifier.startsWith(prefix))
|
|
37
|
+
if (!specifier.startsWith(prefix)) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
34
40
|
const mappedRoot = target.endsWith("/*") ? target.slice(0, -2) : target;
|
|
35
41
|
const subpath = specifier.slice(prefix.length);
|
|
36
42
|
return subpathSource(path.resolve(resolvedBase, mappedRoot, subpath));
|
|
@@ -45,14 +51,18 @@ function conventionAliasPaths(projects, baseUrl) {
|
|
|
45
51
|
const aliases = {};
|
|
46
52
|
for (const project of projects){
|
|
47
53
|
const name = project.name;
|
|
48
|
-
if (name.length === 0)
|
|
54
|
+
if (name.length === 0) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
49
57
|
const entry = path.resolve(project.getSourceEntryPath());
|
|
50
58
|
// A package with no root entry (only subpaths, like core) gets no bare alias, and its
|
|
51
59
|
// subpaths resolve under `src/`.
|
|
52
60
|
const hasEntry = existsSync(entry);
|
|
53
|
-
if (hasEntry)
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
if (hasEntry) {
|
|
62
|
+
aliases[name] = [
|
|
63
|
+
toPosixRelative(baseUrl, entry)
|
|
64
|
+
];
|
|
65
|
+
}
|
|
56
66
|
const subpathRoot = hasEntry ? path.dirname(entry) : path.resolve(project.rootDir, project.projectDirectory, "src");
|
|
57
67
|
if (existsSync(subpathRoot)) {
|
|
58
68
|
aliases[`${name}/*`] = [
|
|
@@ -71,7 +81,9 @@ function conventionAliasPaths(projects, baseUrl) {
|
|
|
71
81
|
}
|
|
72
82
|
function toPosixRelative(from, to) {
|
|
73
83
|
const relative = path.relative(from, to);
|
|
74
|
-
if (relative === "")
|
|
84
|
+
if (relative === "") {
|
|
85
|
+
return ".";
|
|
86
|
+
}
|
|
75
87
|
return relative.split(path.sep).join("/");
|
|
76
88
|
}
|
|
77
89
|
/**
|
|
@@ -87,8 +99,12 @@ function toPosixRelative(from, to) {
|
|
|
87
99
|
...files,
|
|
88
100
|
...indexes
|
|
89
101
|
].find((file)=>existsSync(file));
|
|
90
|
-
if (found != null)
|
|
91
|
-
|
|
102
|
+
if (found != null) {
|
|
103
|
+
return found;
|
|
104
|
+
}
|
|
105
|
+
if (existsSync(candidate) && statSync(candidate).isFile()) {
|
|
106
|
+
return candidate;
|
|
107
|
+
}
|
|
92
108
|
return toTsSourcePath(candidate);
|
|
93
109
|
}
|
|
94
110
|
/** A target as a source path: itself when it is one, else its first source candidate. */ function toTsSourcePath(candidate) {
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
* `forge`, `flux` or `decohere` doesn't count: running it would only call the tool again.
|
|
7
7
|
*/ function getOwn(scripts, name) {
|
|
8
8
|
const command = scripts?.[name];
|
|
9
|
-
if (command == null || command.trim() === "" || DECOHERE_TOOL.test(command))
|
|
9
|
+
if (command == null || command.trim() === "" || DECOHERE_TOOL.test(command)) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
10
12
|
return command;
|
|
11
13
|
}
|
|
12
14
|
export const projectScripts = {
|
|
@@ -200,10 +200,14 @@ export class Project extends mixwith(HasPackageJson, HasTsConfig) {
|
|
|
200
200
|
]){
|
|
201
201
|
const fromSrc = built?.match(/(?:^|\/)(src\/.+)$/)?.[1];
|
|
202
202
|
const source = fromSrc == null ? undefined : sourceFileFor(path.join(projectRoot, fromSrc));
|
|
203
|
-
if (source != null)
|
|
203
|
+
if (source != null) {
|
|
204
|
+
return source;
|
|
205
|
+
}
|
|
204
206
|
}
|
|
205
207
|
const conventional = path.join(projectRoot, "src/index.ts");
|
|
206
|
-
if (main == null || existsSync(conventional))
|
|
208
|
+
if (main == null || existsSync(conventional)) {
|
|
209
|
+
return conventional;
|
|
210
|
+
}
|
|
207
211
|
return path.join(projectRoot, main);
|
|
208
212
|
}
|
|
209
213
|
/**
|
|
@@ -213,16 +217,24 @@ export class Project extends mixwith(HasPackageJson, HasTsConfig) {
|
|
|
213
217
|
* TypeScript extension. Wildcard subpaths, and targets with no such source file, are left out.
|
|
214
218
|
*/ getSourceExports() {
|
|
215
219
|
const exports = this.packageJson?.exports;
|
|
216
|
-
if (exports == null || typeof exports === "string")
|
|
220
|
+
if (exports == null || typeof exports === "string") {
|
|
221
|
+
return {};
|
|
222
|
+
}
|
|
217
223
|
const projectRoot = path.join(this.rootDir, this.projectDirectory);
|
|
218
224
|
const sources = {};
|
|
219
225
|
for (const [subpath, target] of Object.entries(exports)){
|
|
220
|
-
if (!subpath.startsWith("./") || subpath.includes("*"))
|
|
226
|
+
if (!subpath.startsWith("./") || subpath.includes("*")) {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
221
229
|
const built = firstExportTarget(target);
|
|
222
230
|
const fromSrc = built?.match(/(?:^|\/)(src\/.+)$/)?.[1];
|
|
223
|
-
if (fromSrc == null)
|
|
231
|
+
if (fromSrc == null) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
224
234
|
const source = sourceFileFor(path.join(projectRoot, fromSrc));
|
|
225
|
-
if (source != null)
|
|
235
|
+
if (source != null) {
|
|
236
|
+
sources[subpath] = source;
|
|
237
|
+
}
|
|
226
238
|
}
|
|
227
239
|
return sources;
|
|
228
240
|
}
|
|
@@ -287,7 +299,9 @@ _ts_decorate([
|
|
|
287
299
|
_ts_metadata("design:returntype", void 0)
|
|
288
300
|
], Project.prototype, "getOutDir", null);
|
|
289
301
|
/** The first path an exports value gives, preferring the conditions that name runtime code. */ function firstExportTarget(value) {
|
|
290
|
-
if (typeof value === "string")
|
|
302
|
+
if (typeof value === "string") {
|
|
303
|
+
return value;
|
|
304
|
+
}
|
|
291
305
|
for (const condition of [
|
|
292
306
|
"import",
|
|
293
307
|
"default",
|
|
@@ -296,7 +310,9 @@ _ts_decorate([
|
|
|
296
310
|
"types"
|
|
297
311
|
]){
|
|
298
312
|
const nested = value[condition];
|
|
299
|
-
if (nested != null)
|
|
313
|
+
if (nested != null) {
|
|
314
|
+
return firstExportTarget(nested);
|
|
315
|
+
}
|
|
300
316
|
}
|
|
301
317
|
return undefined;
|
|
302
318
|
}
|
|
@@ -31,21 +31,29 @@ import path from "node:path";
|
|
|
31
31
|
* The source files a path written in an import (or a built path) could name, most likely first:
|
|
32
32
|
* itself when it is already a source, else the same stem with each matching source extension.
|
|
33
33
|
*/ function candidates(file) {
|
|
34
|
-
if (isSource(file))
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
if (isSource(file)) {
|
|
35
|
+
return [
|
|
36
|
+
file
|
|
37
|
+
];
|
|
38
|
+
}
|
|
37
39
|
const ext = path.extname(file);
|
|
38
40
|
const known = SOURCES_FOR[ext];
|
|
39
|
-
if (known == null)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
if (known == null) {
|
|
42
|
+
return [
|
|
43
|
+
`${file}.ts`,
|
|
44
|
+
`${file}.tsx`
|
|
45
|
+
];
|
|
46
|
+
}
|
|
43
47
|
const stem = ext === "" ? file : file.slice(0, -ext.length);
|
|
44
48
|
return known.map((sourceExt)=>`${stem}${sourceExt}`);
|
|
45
49
|
}
|
|
46
50
|
/** The extension a source builds to: `.mts` to `.mjs`, `.cts` to `.cjs`, the rest to `.js`. */ function outputExtension(file) {
|
|
47
|
-
if (file.endsWith(".mts"))
|
|
48
|
-
|
|
51
|
+
if (file.endsWith(".mts")) {
|
|
52
|
+
return ".mjs";
|
|
53
|
+
}
|
|
54
|
+
if (file.endsWith(".cts")) {
|
|
55
|
+
return ".cjs";
|
|
56
|
+
}
|
|
49
57
|
return ".js";
|
|
50
58
|
}
|
|
51
59
|
/** The path a source builds to: `a.mts` to `a.mjs`, `a.cts` to `a.cjs`, `a.ts` and `a.tsx` to `a.js`. */ function outputPath(file) {
|
|
@@ -123,7 +123,9 @@ export class Workspace extends mixwith(HasPackageJson, HasTsConfig) {
|
|
|
123
123
|
async sourcePathsOf(project) {
|
|
124
124
|
const files = await project.getAllFiles();
|
|
125
125
|
const cached = this.#sourcePaths.get(files);
|
|
126
|
-
if (cached != null)
|
|
126
|
+
if (cached != null) {
|
|
127
|
+
return cached;
|
|
128
|
+
}
|
|
127
129
|
const paths = new Set(files.map((file)=>file.fullPath));
|
|
128
130
|
this.#sourcePaths.set(files, paths);
|
|
129
131
|
return paths;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decohere/workspace",
|
|
3
|
-
"version": "0.0.1-dev.
|
|
3
|
+
"version": "0.0.1-dev.20261125.414",
|
|
4
4
|
"description": "Workspace and project model primitives for monorepo tooling",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@decohere/core": "0.0.1-dev.
|
|
36
|
-
"@decohere/crucible": "0.0.1-dev.
|
|
37
|
-
"@decohere/devkit": "0.0.1-dev.
|
|
35
|
+
"@decohere/core": "0.0.1-dev.20261125.414",
|
|
36
|
+
"@decohere/crucible": "0.0.1-dev.20261125.414",
|
|
37
|
+
"@decohere/devkit": "0.0.1-dev.20261125.414",
|
|
38
38
|
"get-tsconfig": "^4.14.3",
|
|
39
39
|
"picomatch": "^4.0.4"
|
|
40
40
|
},
|