@idomatic/core 1.0.0 → 1.0.1
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 +7 -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
|
+
// 🔥 require from the user 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,10 @@ export async function processFile(filePath, config) {
|
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
try {
|
|
23
|
-
const
|
|
27
|
+
const parserPath = requireFromUserProject.resolve(parserPackage);
|
|
28
|
+
const parser = await import(parserPath);
|
|
24
29
|
await parser.default(filePath, config);
|
|
30
|
+
console.log(`✅ Updated: ${filePath}`);
|
|
25
31
|
} catch (err) {
|
|
26
32
|
console.error(
|
|
27
33
|
`❌ Failed to load parser "${parserPackage}" for ${filePath}`
|