@idomatic/core 1.0.0 โ 1.0.2
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/lib/core.js +11 -1
- package/package.json +1 -1
package/lib/core.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
+
import { createRequire } from "module";
|
|
2
3
|
|
|
3
4
|
const parserMap = {
|
|
4
5
|
".js": "@idomatic/parser-js",
|
|
@@ -10,6 +11,9 @@ const parserMap = {
|
|
|
10
11
|
".ng.html": "@idomatic/parser-html",
|
|
11
12
|
};
|
|
12
13
|
|
|
14
|
+
// Create a require function relative to the user's project root
|
|
15
|
+
const requireFromUserProject = createRequire(process.cwd());
|
|
16
|
+
|
|
13
17
|
export async function processFile(filePath, config) {
|
|
14
18
|
const ext = path.extname(filePath).toLowerCase();
|
|
15
19
|
const parserPackage = parserMap[ext];
|
|
@@ -20,8 +24,14 @@ export async function processFile(filePath, config) {
|
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
try {
|
|
23
|
-
|
|
27
|
+
console.log("Process CWD:", process.cwd());
|
|
28
|
+
// Resolve the package path using the user's project root
|
|
29
|
+
const resolvedPath = requireFromUserProject.resolve(parserPackage);
|
|
30
|
+
console.log(`๐งช Resolved "${parserPackage}" to:`, resolvedPath);
|
|
31
|
+
|
|
32
|
+
const parser = await import(resolvedPath);
|
|
24
33
|
await parser.default(filePath, config);
|
|
34
|
+
console.log(`โ
Updated: ${filePath}`);
|
|
25
35
|
} catch (err) {
|
|
26
36
|
console.error(
|
|
27
37
|
`โ Failed to load parser "${parserPackage}" for ${filePath}`
|