arcvision 0.1.12 → 0.1.13
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/index.js +51 -68
- package/package.json +1 -1
- package/src/core/path-resolver.js +84 -101
package/dist/index.js
CHANGED
|
@@ -56442,92 +56442,75 @@ var require_path_resolver = __commonJS({
|
|
|
56442
56442
|
"src/core/path-resolver.js"(exports2, module2) {
|
|
56443
56443
|
var fs2 = require("fs");
|
|
56444
56444
|
var path2 = require("path");
|
|
56445
|
-
function resolveImport(importPath,
|
|
56446
|
-
if (importPath.startsWith("
|
|
56445
|
+
function resolveImport(importPath, importerPath, projectRoot, tsconfig) {
|
|
56446
|
+
if (importPath.startsWith("http://") || importPath.startsWith("https://") || importPath.startsWith("data:")) {
|
|
56447
56447
|
return null;
|
|
56448
56448
|
}
|
|
56449
|
-
if (
|
|
56450
|
-
|
|
56451
|
-
|
|
56452
|
-
|
|
56453
|
-
|
|
56454
|
-
|
|
56449
|
+
if (importPath.startsWith(".")) {
|
|
56450
|
+
let resolvedPath = path2.resolve(path2.dirname(importerPath), importPath);
|
|
56451
|
+
const extensions = [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
56452
|
+
for (const ext of extensions) {
|
|
56453
|
+
if (fs2.existsSync(resolvedPath + ext)) {
|
|
56454
|
+
return resolvedPath + ext;
|
|
56455
|
+
}
|
|
56456
|
+
}
|
|
56457
|
+
const indexFiles = ["index.js", "index.jsx", "index.ts", "index.tsx"];
|
|
56458
|
+
for (const idxFile of indexFiles) {
|
|
56459
|
+
const indexPath = path2.join(resolvedPath, idxFile);
|
|
56460
|
+
if (fs2.existsSync(indexPath)) {
|
|
56461
|
+
return indexPath;
|
|
56462
|
+
}
|
|
56463
|
+
}
|
|
56464
|
+
if (fs2.existsSync(resolvedPath)) {
|
|
56465
|
+
return resolvedPath;
|
|
56455
56466
|
}
|
|
56467
|
+
return null;
|
|
56456
56468
|
}
|
|
56457
56469
|
if (tsconfig && tsconfig.paths) {
|
|
56458
|
-
const
|
|
56459
|
-
for (const
|
|
56460
|
-
|
|
56461
|
-
|
|
56462
|
-
|
|
56463
|
-
|
|
56464
|
-
const
|
|
56465
|
-
|
|
56466
|
-
|
|
56467
|
-
|
|
56468
|
-
|
|
56469
|
-
|
|
56470
|
-
|
|
56470
|
+
const paths = tsconfig.paths;
|
|
56471
|
+
for (const [aliasPattern, aliasTargets] of Object.entries(paths)) {
|
|
56472
|
+
const aliasBase = aliasPattern.replace(/\/\*$/, "");
|
|
56473
|
+
if (importPath.startsWith(aliasBase + "/")) {
|
|
56474
|
+
const relativePart = importPath.substring(aliasBase.length);
|
|
56475
|
+
for (const target of aliasTargets) {
|
|
56476
|
+
const targetPath = target.replace(/\/\*$/, "") + relativePart;
|
|
56477
|
+
let resolvedPath = path2.resolve(projectRoot, targetPath);
|
|
56478
|
+
const extensions = [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
56479
|
+
for (const ext of extensions) {
|
|
56480
|
+
if (fs2.existsSync(resolvedPath + ext)) {
|
|
56481
|
+
return resolvedPath + ext;
|
|
56482
|
+
}
|
|
56483
|
+
}
|
|
56484
|
+
const indexFiles = ["index.js", "index.jsx", "index.ts", "index.tsx"];
|
|
56485
|
+
for (const idxFile of indexFiles) {
|
|
56486
|
+
const indexPath = path2.join(resolvedPath, idxFile);
|
|
56487
|
+
if (fs2.existsSync(indexPath)) {
|
|
56488
|
+
return indexPath;
|
|
56489
|
+
}
|
|
56471
56490
|
}
|
|
56472
56491
|
}
|
|
56473
56492
|
}
|
|
56474
56493
|
}
|
|
56475
56494
|
}
|
|
56476
56495
|
if (tsconfig && tsconfig.baseUrl && !importPath.startsWith(".")) {
|
|
56477
|
-
|
|
56478
|
-
const
|
|
56479
|
-
|
|
56480
|
-
|
|
56481
|
-
|
|
56482
|
-
if (importPath.startsWith("@") && tsconfig && tsconfig.baseUrl) {
|
|
56483
|
-
const relativePath = importPath.substring(1);
|
|
56484
|
-
const realPath = path2.resolve(projectRoot, tsconfig.baseUrl, relativePath);
|
|
56485
|
-
const resolved = resolveFile(realPath);
|
|
56486
|
-
if (resolved)
|
|
56487
|
-
return resolved;
|
|
56488
|
-
const wildcardPath = importPath + "/*";
|
|
56489
|
-
if (tsconfig.paths && tsconfig.paths[wildcardPath]) {
|
|
56490
|
-
const pathMappings = tsconfig.paths[wildcardPath];
|
|
56491
|
-
if (Array.isArray(pathMappings) && pathMappings.length > 0) {
|
|
56492
|
-
const mappedPath = pathMappings[0].replace("*", "");
|
|
56493
|
-
const realPath2 = path2.resolve(projectRoot, tsconfig.baseUrl || ".", mappedPath);
|
|
56494
|
-
return resolveFile(realPath2);
|
|
56496
|
+
let resolvedPath = path2.resolve(projectRoot, tsconfig.baseUrl, importPath);
|
|
56497
|
+
const extensions = [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
56498
|
+
for (const ext of extensions) {
|
|
56499
|
+
if (fs2.existsSync(resolvedPath + ext)) {
|
|
56500
|
+
return resolvedPath + ext;
|
|
56495
56501
|
}
|
|
56496
56502
|
}
|
|
56497
|
-
|
|
56498
|
-
|
|
56499
|
-
|
|
56500
|
-
|
|
56501
|
-
|
|
56502
|
-
if (!importPath.startsWith(".")) {
|
|
56503
|
-
const realPath = path2.resolve(projectRoot, importPath);
|
|
56504
|
-
return resolveFile(realPath);
|
|
56505
|
-
}
|
|
56506
|
-
return null;
|
|
56507
|
-
}
|
|
56508
|
-
function resolveFile(basePath) {
|
|
56509
|
-
const extensions = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
|
|
56510
|
-
const barrelFiles = ["index.ts", "index.tsx", "index.js", "index.jsx"];
|
|
56511
|
-
if (fs2.existsSync(basePath) && fs2.statSync(basePath).isFile()) {
|
|
56512
|
-
return basePath;
|
|
56513
|
-
}
|
|
56514
|
-
for (const ext of extensions) {
|
|
56515
|
-
const pathWithExt = basePath + ext;
|
|
56516
|
-
if (fs2.existsSync(pathWithExt) && fs2.statSync(pathWithExt).isFile()) {
|
|
56517
|
-
return pathWithExt;
|
|
56518
|
-
}
|
|
56519
|
-
}
|
|
56520
|
-
if (fs2.existsSync(basePath) && fs2.statSync(basePath).isDirectory()) {
|
|
56521
|
-
for (const barrelFile of barrelFiles) {
|
|
56522
|
-
const barrelPath = path2.join(basePath, barrelFile);
|
|
56523
|
-
if (fs2.existsSync(barrelPath)) {
|
|
56524
|
-
return barrelPath;
|
|
56503
|
+
const indexFiles = ["index.js", "index.jsx", "index.ts", "index.tsx"];
|
|
56504
|
+
for (const idxFile of indexFiles) {
|
|
56505
|
+
const indexPath = path2.join(resolvedPath, idxFile);
|
|
56506
|
+
if (fs2.existsSync(indexPath)) {
|
|
56507
|
+
return indexPath;
|
|
56525
56508
|
}
|
|
56526
56509
|
}
|
|
56527
56510
|
}
|
|
56528
56511
|
return null;
|
|
56529
56512
|
}
|
|
56530
|
-
module2.exports = { resolveImport
|
|
56513
|
+
module2.exports = { resolveImport };
|
|
56531
56514
|
}
|
|
56532
56515
|
});
|
|
56533
56516
|
|
package/package.json
CHANGED
|
@@ -2,126 +2,109 @@ const fs = require('fs');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Resolve an import path to
|
|
6
|
-
*
|
|
7
|
-
* @param {string}
|
|
5
|
+
* Resolve an import path to its actual file location
|
|
6
|
+
* Handles relative paths, path aliases, barrel files, and implicit extensions
|
|
7
|
+
* @param {string} importPath - The import path from the source code
|
|
8
|
+
* @param {string} importerPath - The path of the file doing the import
|
|
8
9
|
* @param {string} projectRoot - The root directory of the project
|
|
9
|
-
* @param {Object|null} tsconfig -
|
|
10
|
+
* @param {Object|null} tsconfig - Loaded tsconfig with compilerOptions
|
|
10
11
|
* @returns {string|null} The resolved absolute file path or null if not found
|
|
11
12
|
*/
|
|
12
|
-
function resolveImport(importPath,
|
|
13
|
-
//
|
|
14
|
-
if (importPath.startsWith('
|
|
15
|
-
importPath.includes('node_modules/') ||
|
|
16
|
-
importPath.startsWith('http') ||
|
|
17
|
-
importPath.startsWith('//')) {
|
|
13
|
+
function resolveImport(importPath, importerPath, projectRoot, tsconfig) {
|
|
14
|
+
// If it's an absolute path or URL, skip resolution
|
|
15
|
+
if (importPath.startsWith('http://') || importPath.startsWith('https://') || importPath.startsWith('data:')) {
|
|
18
16
|
return null;
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
// Handle
|
|
22
|
-
if (
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
// Handle relative imports
|
|
20
|
+
if (importPath.startsWith('.')) {
|
|
21
|
+
// Resolve relative to importer
|
|
22
|
+
let resolvedPath = path.resolve(path.dirname(importerPath), importPath);
|
|
23
|
+
|
|
24
|
+
// Try with various extensions
|
|
25
|
+
const extensions = ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs'];
|
|
26
|
+
for (const ext of extensions) {
|
|
27
|
+
if (fs.existsSync(resolvedPath + ext)) {
|
|
28
|
+
return resolvedPath + ext;
|
|
29
|
+
}
|
|
29
30
|
}
|
|
31
|
+
|
|
32
|
+
// Try as directory with index files
|
|
33
|
+
const indexFiles = ['index.js', 'index.jsx', 'index.ts', 'index.tsx'];
|
|
34
|
+
for (const idxFile of indexFiles) {
|
|
35
|
+
const indexPath = path.join(resolvedPath, idxFile);
|
|
36
|
+
if (fs.existsSync(indexPath)) {
|
|
37
|
+
return indexPath;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// If original path exists as-is
|
|
42
|
+
if (fs.existsSync(resolvedPath)) {
|
|
43
|
+
return resolvedPath;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return null;
|
|
30
47
|
}
|
|
31
48
|
|
|
32
|
-
// Handle
|
|
49
|
+
// Handle path aliases (like @/components/, ~/utils/, etc.)
|
|
33
50
|
if (tsconfig && tsconfig.paths) {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
const paths = tsconfig.paths;
|
|
52
|
+
|
|
53
|
+
// Find matching path alias
|
|
54
|
+
for (const [aliasPattern, aliasTargets] of Object.entries(paths)) {
|
|
55
|
+
// Remove trailing * from pattern
|
|
56
|
+
const aliasBase = aliasPattern.replace(/\/\*$/, '');
|
|
57
|
+
|
|
58
|
+
// If import starts with this alias
|
|
59
|
+
if (importPath.startsWith(aliasBase + '/')) {
|
|
60
|
+
// Get the part after the alias
|
|
61
|
+
const relativePart = importPath.substring(aliasBase.length);
|
|
62
|
+
|
|
63
|
+
// Use the first target path
|
|
64
|
+
for (const target of aliasTargets) {
|
|
65
|
+
// Replace * in target with relative part
|
|
66
|
+
const targetPath = target.replace(/\/\*$/, '') + relativePart;
|
|
67
|
+
let resolvedPath = path.resolve(projectRoot, targetPath);
|
|
68
|
+
|
|
69
|
+
// Try with extensions
|
|
70
|
+
const extensions = ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs'];
|
|
71
|
+
for (const ext of extensions) {
|
|
72
|
+
if (fs.existsSync(resolvedPath + ext)) {
|
|
73
|
+
return resolvedPath + ext;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Try as directory with index files
|
|
78
|
+
const indexFiles = ['index.js', 'index.jsx', 'index.ts', 'index.tsx'];
|
|
79
|
+
for (const idxFile of indexFiles) {
|
|
80
|
+
const indexPath = path.join(resolvedPath, idxFile);
|
|
81
|
+
if (fs.existsSync(indexPath)) {
|
|
82
|
+
return indexPath;
|
|
83
|
+
}
|
|
46
84
|
}
|
|
47
85
|
}
|
|
48
86
|
}
|
|
49
87
|
}
|
|
50
88
|
}
|
|
51
89
|
|
|
52
|
-
// Handle baseUrl
|
|
90
|
+
// Handle baseUrl if configured
|
|
53
91
|
if (tsconfig && tsconfig.baseUrl && !importPath.startsWith('.')) {
|
|
54
|
-
|
|
55
|
-
const resolved = resolveFile(baseUrlPath);
|
|
56
|
-
if (resolved) return resolved;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Handle @ imports that don't match specific paths mappings
|
|
60
|
-
if (importPath.startsWith('@') && tsconfig && tsconfig.baseUrl) {
|
|
61
|
-
// Remove @ and resolve relative to baseUrl
|
|
62
|
-
const relativePath = importPath.substring(1); // Remove @
|
|
63
|
-
const realPath = path.resolve(projectRoot, tsconfig.baseUrl, relativePath);
|
|
64
|
-
const resolved = resolveFile(realPath);
|
|
65
|
-
if (resolved) return resolved;
|
|
92
|
+
let resolvedPath = path.resolve(projectRoot, tsconfig.baseUrl, importPath);
|
|
66
93
|
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (Array.isArray(pathMappings) && pathMappings.length > 0) {
|
|
73
|
-
const mappedPath = pathMappings[0].replace('*', '');
|
|
74
|
-
const realPath = path.resolve(projectRoot, tsconfig.baseUrl || '.', mappedPath);
|
|
75
|
-
return resolveFile(realPath);
|
|
94
|
+
// Try with extensions
|
|
95
|
+
const extensions = ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs'];
|
|
96
|
+
for (const ext of extensions) {
|
|
97
|
+
if (fs.existsSync(resolvedPath + ext)) {
|
|
98
|
+
return resolvedPath + ext;
|
|
76
99
|
}
|
|
77
100
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// For absolute paths within the project that don't match tsconfig paths
|
|
87
|
-
if (!importPath.startsWith('.')) {
|
|
88
|
-
// Try resolving relative to project root
|
|
89
|
-
const realPath = path.resolve(projectRoot, importPath);
|
|
90
|
-
return resolveFile(realPath);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Resolve a potential file path to an actual existing file
|
|
98
|
-
* Handles implicit extensions and barrel files (index files)
|
|
99
|
-
* @param {string} basePath - The base path to resolve
|
|
100
|
-
* @returns {string|null} The resolved file path or null if no file exists
|
|
101
|
-
*/
|
|
102
|
-
function resolveFile(basePath) {
|
|
103
|
-
const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'];
|
|
104
|
-
const barrelFiles = ['index.ts', 'index.tsx', 'index.js', 'index.jsx'];
|
|
105
|
-
|
|
106
|
-
// First, try the exact path
|
|
107
|
-
if (fs.existsSync(basePath) && fs.statSync(basePath).isFile()) {
|
|
108
|
-
return basePath;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Try with extensions
|
|
112
|
-
for (const ext of extensions) {
|
|
113
|
-
const pathWithExt = basePath + ext;
|
|
114
|
-
if (fs.existsSync(pathWithExt) && fs.statSync(pathWithExt).isFile()) {
|
|
115
|
-
return pathWithExt;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Try as a directory with barrel files
|
|
120
|
-
if (fs.existsSync(basePath) && fs.statSync(basePath).isDirectory()) {
|
|
121
|
-
for (const barrelFile of barrelFiles) {
|
|
122
|
-
const barrelPath = path.join(basePath, barrelFile);
|
|
123
|
-
if (fs.existsSync(barrelPath)) {
|
|
124
|
-
return barrelPath;
|
|
101
|
+
|
|
102
|
+
// Try as directory with index files
|
|
103
|
+
const indexFiles = ['index.js', 'index.jsx', 'index.ts', 'index.tsx'];
|
|
104
|
+
for (const idxFile of indexFiles) {
|
|
105
|
+
const indexPath = path.join(resolvedPath, idxFile);
|
|
106
|
+
if (fs.existsSync(indexPath)) {
|
|
107
|
+
return indexPath;
|
|
125
108
|
}
|
|
126
109
|
}
|
|
127
110
|
}
|
|
@@ -129,4 +112,4 @@ function resolveFile(basePath) {
|
|
|
129
112
|
return null;
|
|
130
113
|
}
|
|
131
114
|
|
|
132
|
-
module.exports = { resolveImport
|
|
115
|
+
module.exports = { resolveImport };
|