sliftutils 0.49.0 → 0.50.0
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/bundler/bundleWrapper.ts +13 -5
- package/package.json +1 -1
package/bundler/bundleWrapper.ts
CHANGED
|
@@ -15,9 +15,16 @@ const getPackageJsonPath = cache((directory: string): string | undefined => {
|
|
|
15
15
|
const getMainPath = cache((directory: string): string | undefined => {
|
|
16
16
|
let packageJsonPath = getPackageJsonPath(directory);
|
|
17
17
|
if (!packageJsonPath) return undefined;
|
|
18
|
-
let packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"))
|
|
18
|
+
let packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")) as {
|
|
19
|
+
main?: string;
|
|
20
|
+
exports?: {
|
|
21
|
+
"."?: {
|
|
22
|
+
require?: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
19
26
|
let dir = path.dirname(packageJsonPath);
|
|
20
|
-
let mainName = packageJson.main;
|
|
27
|
+
let mainName = packageJson.exports?.["."]?.require || packageJson.main;
|
|
21
28
|
if (!mainName) {
|
|
22
29
|
if (fs.existsSync(path.resolve(dir, "index.js"))) {
|
|
23
30
|
mainName = "index.js";
|
|
@@ -29,6 +36,7 @@ const getMainPath = cache((directory: string): string | undefined => {
|
|
|
29
36
|
mainName = "index.js";
|
|
30
37
|
}
|
|
31
38
|
}
|
|
39
|
+
// Handle the negative value ESM exports thing.
|
|
32
40
|
let mainPath = path.resolve(dir, mainName);
|
|
33
41
|
return mainPath;
|
|
34
42
|
});
|
|
@@ -62,14 +70,14 @@ export function wrapModule(module: NodeJS.Module): string {
|
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
|
|
65
|
-
let
|
|
73
|
+
let moduleMain: string | undefined;
|
|
66
74
|
let dirname = path.dirname(module.filename);
|
|
67
75
|
let packageJsonPath = getPackageJsonPath(dirname);
|
|
68
76
|
if (packageJsonPath) {
|
|
69
77
|
let mainPath = getMainPath(dirname);
|
|
70
78
|
if (mainPath?.replaceAll("\\", "/") === module.filename.replaceAll("\\", "/")) {
|
|
71
79
|
// Then we are the main of the module
|
|
72
|
-
|
|
80
|
+
moduleMain = path.dirname(packageJsonPath).replaceAll("\\", "/");
|
|
73
81
|
}
|
|
74
82
|
}
|
|
75
83
|
|
|
@@ -77,7 +85,7 @@ export function wrapModule(module: NodeJS.Module): string {
|
|
|
77
85
|
let objWrapped = `{`
|
|
78
86
|
+ ` id: ${JSON.stringify(module.id.replaceAll("\\", "/"))},`
|
|
79
87
|
+ ` filename: ${JSON.stringify(module.filename.replaceAll("\\", "/"))},`
|
|
80
|
-
+ ` isModuleMain: ${JSON.stringify(
|
|
88
|
+
+ ` isModuleMain: ${JSON.stringify(moduleMain)},`
|
|
81
89
|
+ ` paths: ${JSON.stringify(module.paths.map(p => p.replaceAll("\\", "/")))},`
|
|
82
90
|
+ ` moduleFields: ${JSON.stringify(moduleFields)},`
|
|
83
91
|
+ ` moduleFnc: ${wrapped}`
|