ptech-preset 1.1.3 → 1.1.4
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 +16 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import path3 from "path";
|
|
3
|
+
import fs3 from "fs";
|
|
3
4
|
|
|
4
5
|
// src/collectAutoExposes.ts
|
|
5
6
|
import path from "path";
|
|
@@ -103,6 +104,20 @@ async function collectAutoRemotes(opts = {}) {
|
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
// src/index.ts
|
|
107
|
+
function getPackageName(root) {
|
|
108
|
+
try {
|
|
109
|
+
const pkgPath = path3.resolve(root, "package.json");
|
|
110
|
+
if (fs3.existsSync(pkgPath)) {
|
|
111
|
+
const pkg = JSON.parse(fs3.readFileSync(pkgPath, "utf8"));
|
|
112
|
+
if (pkg.name && typeof pkg.name === "string") {
|
|
113
|
+
return pkg.name.replace(/\W+/g, "");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} catch (err) {
|
|
117
|
+
console.warn("[plugin-mf-auto] Cannot read package.json:", err);
|
|
118
|
+
}
|
|
119
|
+
return void 0;
|
|
120
|
+
}
|
|
106
121
|
function pluginMFAuto(opts) {
|
|
107
122
|
const {
|
|
108
123
|
baseDir = "src",
|
|
@@ -148,7 +163,7 @@ function pluginMFAuto(opts) {
|
|
|
148
163
|
}
|
|
149
164
|
}
|
|
150
165
|
if (!mfMerged.name) {
|
|
151
|
-
mfMerged.name = path3.basename(api.context.rootPath).replace(/\W+/g, "");
|
|
166
|
+
mfMerged.name = getPackageName(api.context.rootPath) || path3.basename(api.context.rootPath).replace(/\W+/g, "");
|
|
152
167
|
}
|
|
153
168
|
config.plugins ||= [];
|
|
154
169
|
config.plugins.push(pluginModuleFederation(mfMerged));
|