webpack-federation-types-plugin 1.2.0 → 1.2.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/FederationTypesPlugin.js +21 -7
- package/package.json +1 -1
- package/TODO +0 -5
package/FederationTypesPlugin.js
CHANGED
|
@@ -5,6 +5,7 @@ const fs = require("fs-extra")
|
|
|
5
5
|
const path = require("path")
|
|
6
6
|
const ms = require("ms")
|
|
7
7
|
|
|
8
|
+
let isFirstCompilation = true
|
|
8
9
|
const PLUGIN_NAME = "FederationTypesPlugin"
|
|
9
10
|
const MF_TYPES_DIR = "federation-types"
|
|
10
11
|
const DECLARATION_FILE_EXT = ".d.ts"
|
|
@@ -58,13 +59,25 @@ class FederationTypesPlugin {
|
|
|
58
59
|
if (!federationPlugin) throw new Error("No ModuleFederationPlugin found.")
|
|
59
60
|
const logger = compiler.getInfrastructureLogger(PLUGIN_NAME)
|
|
60
61
|
|
|
61
|
-
const exposes = Object.fromEntries(Object.entries(federationPlugin._options.exposes || {}).map(([
|
|
62
|
+
const exposes = Object.fromEntries(Object.entries(federationPlugin._options.exposes || {}).map(([moduleName, currentPath]) => {
|
|
63
|
+
let isIndexFile = false
|
|
64
|
+
const absPath = path.resolve(process.cwd(), currentPath)
|
|
65
|
+
const hasExtension = !!path.extname(currentPath)
|
|
66
|
+
const extension = hasExtension ? "" : fs.existsSync(absPath + ".jsx") ? ".jsx" : fs.existsSync(absPath + ".js") ? ".js" : ""
|
|
67
|
+
if (!hasExtension && extension === "") {
|
|
68
|
+
if ( fs.existsSync(path.resolve(absPath, "index.js"))) {
|
|
69
|
+
isIndexFile = true
|
|
70
|
+
}
|
|
71
|
+
else logger.error(`Couldn't find ${currentPath}`)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return [moduleName.replace("./", ""), currentPath + (isIndexFile ? "/index.js" : "") + extension]
|
|
75
|
+
}
|
|
76
|
+
))
|
|
62
77
|
|
|
63
78
|
const modulesPathsMap = Object.fromEntries(
|
|
64
79
|
Object.entries(exposes).map(([name, currentPath]) => {
|
|
65
|
-
|
|
66
|
-
const extension = path.extname(currentPath) ? "" : fs.existsSync(absPath + ".jsx") ? ".jsx" : ".js"
|
|
67
|
-
return [name, path.join(process.cwd(), currentPath + extension).replace(/\\/g, "/")]
|
|
80
|
+
return [name, path.join(process.cwd(), currentPath).replace(/\\/g, "/")]
|
|
68
81
|
})
|
|
69
82
|
)
|
|
70
83
|
|
|
@@ -127,8 +140,8 @@ class FederationTypesPlugin {
|
|
|
127
140
|
// get types index from the current remote
|
|
128
141
|
.get(federationTypesUrl + "index.json")
|
|
129
142
|
.catch((error) => {
|
|
130
|
-
if (error.response?.status === 404) logger.warn(`WARNING: remote ${remoteName} has no types`)
|
|
131
|
-
else logger.error(
|
|
143
|
+
if (error.response?.status === 404) logger.warn(`WARNING: The remote ${remoteName} has no types`)
|
|
144
|
+
else logger.error(`Failed to get remote types from ${remotePublicUrl}.`, error.message)
|
|
132
145
|
})
|
|
133
146
|
.then((response) => response?.data)
|
|
134
147
|
.then((modulesNames) => {
|
|
@@ -145,7 +158,6 @@ class FederationTypesPlugin {
|
|
|
145
158
|
if (!declarationFileResponse) return
|
|
146
159
|
const declarationFileContent = declarationFileResponse.data
|
|
147
160
|
const decFilePath = path.join(remoteDeclareDirPath, moduleName)
|
|
148
|
-
fs.writeFile(decFilePath, declarationFileContent, {recursive: true})
|
|
149
161
|
fs.promises
|
|
150
162
|
.mkdir(path.dirname(decFilePath), {recursive: true})
|
|
151
163
|
.catch((error) => logger.error(`Failed to write dir: ${decFilePath}`, error))
|
|
@@ -166,6 +178,8 @@ class FederationTypesPlugin {
|
|
|
166
178
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
167
179
|
const pluginOptions = this._options || {}
|
|
168
180
|
compilation.hooks.beforeCodeGeneration.tap(PLUGIN_NAME, () => {
|
|
181
|
+
if (!isFirstCompilation) return
|
|
182
|
+
isFirstCompilation = false
|
|
169
183
|
if (pluginOptions.exposeTypes !== false) createTypesDefinitions(compilation)
|
|
170
184
|
if (compilation.options.mode === "development" && pluginOptions.importTypes !== false) {
|
|
171
185
|
getTypesDefinitions()
|
package/package.json
CHANGED
package/TODO
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
cts\wedding\node_modules\@types\appJAMain\getJAData.d.ts'
|
|
2
|
-
(Use `node --trace-warnings ...` to show where the warning was created)
|
|
3
|
-
(node:10492) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 15)
|
|
4
|
-
(node:10492) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
|
|
5
|
-
|