@baseplate-dev/tools 0.1.2 → 0.1.3
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/package.json +1 -1
- package/src-subpath-import-plugin.js +28 -25
package/package.json
CHANGED
|
@@ -28,38 +28,41 @@ export function srcSubpathImportPlugin(dirname) {
|
|
|
28
28
|
|
|
29
29
|
return {
|
|
30
30
|
name: 'custom-src-resolve',
|
|
31
|
-
resolveId
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
resolveId: {
|
|
32
|
+
order: 'pre',
|
|
33
|
+
handler(id, importer) {
|
|
34
|
+
// Only handle #src imports
|
|
35
|
+
if (!id.startsWith('#src')) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
// Skip if no importer (entry point) or importer is in node_modules
|
|
40
|
+
if (!importer || importer.includes('node_modules')) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
// Check if importer is within the project directory
|
|
45
|
+
const resolvedImporter = path.resolve(importer);
|
|
46
|
+
const projectRoot = path.resolve(dirname);
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
if (!resolvedImporter.startsWith(projectRoot)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
// Replace #src with the actual src path
|
|
53
|
+
const basePath = id.replace(/^#src/, srcPath).replace(/\.js$/, '');
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
// Try each extension
|
|
56
|
+
for (const ext of EXTENSIONS) {
|
|
57
|
+
const resolvedPath = basePath + ext;
|
|
58
|
+
if (fs.existsSync(resolvedPath)) {
|
|
59
|
+
return resolvedPath;
|
|
60
|
+
}
|
|
58
61
|
}
|
|
59
|
-
}
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
// If no extension matches, return the base path
|
|
64
|
+
return basePath;
|
|
65
|
+
},
|
|
63
66
|
},
|
|
64
67
|
};
|
|
65
68
|
}
|