@richapps/ong 0.1.3 → 0.1.5
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/dist/config.d.ts +1 -1
- package/dist/config.js +53 -27
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { InlineConfig, Alias } from 'vite';
|
|
|
2
2
|
import type { ResolvedBuildOptions } from './workspace.js';
|
|
3
3
|
/**
|
|
4
4
|
* Reads tsconfig paths and converts them to Vite resolve aliases.
|
|
5
|
-
* Follows tsconfig "extends" chain to find paths from base configs.
|
|
5
|
+
* Follows tsconfig "extends" chain (including array extends) to find paths from base configs.
|
|
6
6
|
*/
|
|
7
7
|
export declare function resolveTsconfigPaths(tsconfig: string, workspaceRoot: string): Alias[];
|
|
8
8
|
/**
|
package/dist/config.js
CHANGED
|
@@ -1,43 +1,69 @@
|
|
|
1
|
-
import { resolve } from 'node:path';
|
|
1
|
+
import { resolve, dirname } from 'node:path';
|
|
2
2
|
import { readFileSync, existsSync } from 'node:fs';
|
|
3
3
|
import { angular } from '@oxc-angular/vite';
|
|
4
4
|
import { htmlInjectPlugin, assetCopyPlugin } from './plugins.js';
|
|
5
|
+
/**
|
|
6
|
+
* Parse a tsconfig JSON file, stripping comments and trailing commas.
|
|
7
|
+
*/
|
|
8
|
+
function parseTsconfig(filePath) {
|
|
9
|
+
const raw = readFileSync(filePath, 'utf-8');
|
|
10
|
+
const stripped = raw
|
|
11
|
+
// Remove single-line comments
|
|
12
|
+
.replace(/\/\/.*$/gm, '')
|
|
13
|
+
// Remove multi-line comments
|
|
14
|
+
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
15
|
+
// Remove trailing commas before } or ]
|
|
16
|
+
.replace(/,\s*([\]}])/g, '$1');
|
|
17
|
+
return JSON.parse(stripped);
|
|
18
|
+
}
|
|
5
19
|
/**
|
|
6
20
|
* Reads tsconfig paths and converts them to Vite resolve aliases.
|
|
7
|
-
* Follows tsconfig "extends" chain to find paths from base configs.
|
|
21
|
+
* Follows tsconfig "extends" chain (including array extends) to find paths from base configs.
|
|
8
22
|
*/
|
|
9
23
|
export function resolveTsconfigPaths(tsconfig, workspaceRoot) {
|
|
10
24
|
const aliases = [];
|
|
11
25
|
try {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
if (compilerOptions.paths) {
|
|
25
|
-
paths = compilerOptions.paths;
|
|
26
|
-
baseUrl = compilerOptions.baseUrl ?? '.';
|
|
27
|
-
}
|
|
26
|
+
// Collect configs from root of extends chain to the leaf (tsconfig.app.json)
|
|
27
|
+
// Each entry stores the parsed config and the directory of the tsconfig file
|
|
28
|
+
const configChain = [];
|
|
29
|
+
const visited = new Set();
|
|
30
|
+
const walk = (configPath) => {
|
|
31
|
+
const resolved = resolve(configPath);
|
|
32
|
+
if (visited.has(resolved) || !existsSync(resolved))
|
|
33
|
+
return;
|
|
34
|
+
visited.add(resolved);
|
|
35
|
+
const config = parseTsconfig(resolved);
|
|
36
|
+
const dir = dirname(resolved);
|
|
37
|
+
// Recurse into extends first (parents before children in the chain)
|
|
28
38
|
if (config.extends) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
const extendsList = Array.isArray(config.extends) ? config.extends : [config.extends];
|
|
40
|
+
for (const ext of extendsList) {
|
|
41
|
+
let extPath = resolve(dir, ext);
|
|
42
|
+
if (!extPath.endsWith('.json'))
|
|
43
|
+
extPath += '.json';
|
|
44
|
+
walk(extPath);
|
|
45
|
+
}
|
|
33
46
|
}
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
configChain.push({ config, dir });
|
|
48
|
+
};
|
|
49
|
+
walk(tsconfig);
|
|
50
|
+
// Resolve inherited values: earlier entries (parents) are overridden by later (children)
|
|
51
|
+
let baseUrl;
|
|
52
|
+
let baseUrlDir = workspaceRoot;
|
|
53
|
+
let paths;
|
|
54
|
+
for (const { config, dir } of configChain) {
|
|
55
|
+
const co = config.compilerOptions ?? {};
|
|
56
|
+
if (co.baseUrl !== undefined) {
|
|
57
|
+
baseUrl = co.baseUrl;
|
|
58
|
+
baseUrlDir = dir; // baseUrl is relative to the tsconfig that defines it
|
|
59
|
+
}
|
|
60
|
+
if (co.paths !== undefined) {
|
|
61
|
+
paths = co.paths;
|
|
36
62
|
}
|
|
37
63
|
}
|
|
38
64
|
if (!paths)
|
|
39
65
|
return aliases;
|
|
40
|
-
const baseDir = resolve(
|
|
66
|
+
const baseDir = baseUrl !== undefined ? resolve(baseUrlDir, baseUrl) : workspaceRoot;
|
|
41
67
|
for (const [pattern, targets] of Object.entries(paths)) {
|
|
42
68
|
if (!targets.length)
|
|
43
69
|
continue;
|
|
@@ -54,8 +80,8 @@ export function resolveTsconfigPaths(tsconfig, workspaceRoot) {
|
|
|
54
80
|
}
|
|
55
81
|
}
|
|
56
82
|
}
|
|
57
|
-
catch {
|
|
58
|
-
|
|
83
|
+
catch (err) {
|
|
84
|
+
console.warn(` Warning: failed to resolve tsconfig paths: ${err.message}`);
|
|
59
85
|
}
|
|
60
86
|
return aliases;
|
|
61
87
|
}
|