@richapps/ong 0.1.4 → 0.1.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/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,48 +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
- let configPath = tsconfig;
13
- let paths;
14
- let baseUrl = '.';
15
- // Walk the extends chain to find paths
16
- // Collect baseUrl from each level; paths from the first config that defines them
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
17
28
  const configChain = [];
18
- while (configPath) {
19
- if (!existsSync(configPath))
20
- break;
21
- const raw = readFileSync(configPath, 'utf-8');
22
- // Strip comments (single-line // and multi-line /* */)
23
- const stripped = raw.replace(/\/\/.*$/gm, '').replace(/\/\*[\s\S]*?\*\//g, '');
24
- const config = JSON.parse(stripped);
25
- configChain.push(config);
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)
26
38
  if (config.extends) {
27
- configPath = resolve(configPath, '..', config.extends);
28
- if (!configPath.endsWith('.json'))
29
- configPath += '.json';
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
+ }
30
46
  }
31
- else {
32
- break;
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;
33
62
  }
34
- }
35
- // Resolve inherited values: child overrides parent
36
- for (let i = configChain.length - 1; i >= 0; i--) {
37
- const compilerOptions = configChain[i].compilerOptions ?? {};
38
- if (compilerOptions.baseUrl !== undefined)
39
- baseUrl = compilerOptions.baseUrl;
40
- if (compilerOptions.paths !== undefined)
41
- paths = compilerOptions.paths;
42
63
  }
43
64
  if (!paths)
44
65
  return aliases;
45
- const baseDir = resolve(workspaceRoot, baseUrl);
66
+ const baseDir = baseUrl !== undefined ? resolve(baseUrlDir, baseUrl) : workspaceRoot;
46
67
  for (const [pattern, targets] of Object.entries(paths)) {
47
68
  if (!targets.length)
48
69
  continue;
@@ -55,12 +76,14 @@ export function resolveTsconfigPaths(tsconfig, workspaceRoot) {
55
76
  }
56
77
  else {
57
78
  // Exact mapping: "@scope/lib" -> "libs/lib/src/index.ts"
58
- aliases.push({ find: pattern, replacement: resolve(baseDir, target) });
79
+ // Use RegExp with $ anchor so "@scope/lib" doesn't prefix-match "@scope/lib/sub"
80
+ // (Vite string aliases do prefix matching, but tsconfig exact paths should only match exactly)
81
+ aliases.push({ find: new RegExp(`^${escapeRegex(pattern)}$`), replacement: resolve(baseDir, target) });
59
82
  }
60
83
  }
61
84
  }
62
- catch {
63
- // Ignore tsconfig parse errors fall back to no aliases
85
+ catch (err) {
86
+ console.warn(` Warning: failed to resolve tsconfig paths: ${err.message}`);
64
87
  }
65
88
  return aliases;
66
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@richapps/ong",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Angular CLI powered by Vite + OXC — blazing fast drop-in replacement for ng serve/build",
5
5
  "keywords": [
6
6
  "angular",