webpack-federation-types-plugin 1.0.1 → 1.2.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.
@@ -3,6 +3,7 @@ const ts = require("typescript")
3
3
  const axios = require("axios")
4
4
  const fs = require("fs-extra")
5
5
  const path = require("path")
6
+ const ms = require("ms")
6
7
 
7
8
  const PLUGIN_NAME = "FederationTypesPlugin"
8
9
  const MF_TYPES_DIR = "federation-types"
@@ -17,7 +18,7 @@ const tscOptions = {
17
18
  const optionsSchema = {
18
19
  type: "object",
19
20
  properties: {
20
- ignoreRemotes: {
21
+ excludeRemotes: {
21
22
  type: "array",
22
23
  },
23
24
  exposeTypes: {
@@ -26,6 +27,9 @@ const optionsSchema = {
26
27
  importTypes: {
27
28
  type: "boolean",
28
29
  },
30
+ getTypesInterval: {
31
+ type: "string",
32
+ },
29
33
  },
30
34
  }
31
35
 
@@ -48,6 +52,7 @@ class FederationTypesPlugin {
48
52
  * @param {import("webpack").Compiler} compiler
49
53
  */
50
54
  apply(compiler) {
55
+ let getTypesInterval
51
56
  const federationPlugin =
52
57
  compiler.options.plugins && compiler.options.plugins.find((plugin) => plugin.constructor.name === "ModuleFederationPlugin")
53
58
  if (!federationPlugin) throw new Error("No ModuleFederationPlugin found.")
@@ -109,8 +114,8 @@ class FederationTypesPlugin {
109
114
  const remotes = federationPlugin._options.remotes
110
115
  if (!remotes) return
111
116
 
112
- const ignoreRemotes = this._options.ignoreRemotes || []
113
- const wantedRemotes = Object.entries(remotes).filter((remote) => ignoreRemotes.find((c) => c !== remote[0]))
117
+ const excludeRemotes = this._options.excludeRemotes || []
118
+ const wantedRemotes = Object.entries(remotes).filter((remote) => !excludeRemotes.find((c) => c === remote[0]))
114
119
 
115
120
  for (const [remoteName, remoteEntryUri] of wantedRemotes) {
116
121
  const {origin, pathname} = new URL(remoteEntryUri.split("@")[1])
@@ -164,7 +169,10 @@ class FederationTypesPlugin {
164
169
  if (pluginOptions.exposeTypes !== false) createTypesDefinitions(compilation)
165
170
  if (compilation.options.mode === "development" && pluginOptions.importTypes !== false) {
166
171
  getTypesDefinitions()
167
- // TODO - call getTypesDefinitions using setInterval
172
+ if (pluginOptions.getTypesInterval) {
173
+ clearInterval(getTypesInterval)
174
+ getTypesInterval = setInterval(() => getTypesDefinitions(compilation), ms(pluginOptions.getTypesInterval))
175
+ }
168
176
  }
169
177
  })
170
178
  })
package/README.md CHANGED
@@ -17,7 +17,7 @@ const FederationTypesPlugin = require("webpack-federation-types-plugin")
17
17
 
18
18
  module.exports = {
19
19
  // ...
20
- plugins: [new FederationTypesPlugin({ignoreRemotes: ["remoteName"], importTypes: true, exposeTypes: true})],
20
+ plugins: [new FederationTypesPlugin({excludeRemotes: ["remoteName"], importTypes: true, exposeTypes: true})],
21
21
  }
22
22
  ```
23
23
 
@@ -36,9 +36,15 @@ Type: boolean
36
36
  Default: true
37
37
  Description: fetch the remotes declaration files and add them to the @types directory
38
38
 
39
- ##### ignoreRemotes
39
+ ##### excludeRemotes
40
40
 
41
41
  Type: string[]
42
42
  Default: undefined
43
43
  Description: remotes to ignore
44
44
 
45
+ ##### getTypesInterval
46
+
47
+ Type: string
48
+ Default: undefined
49
+ Description: the interval between types requests
50
+ Example: "5 minutes", "30 seconds"
package/TODO ADDED
@@ -0,0 +1,5 @@
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
+
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "webpack-federation-types-plugin",
3
3
  "description": "This plugin adds type definitions for remote modules",
4
- "version": "1.0.1",
4
+ "version": "1.2.0",
5
5
  "main": "FederationTypesPlugin.js",
6
+ "types": "types.d.ts",
6
7
  "scripts": {
7
8
  "publish:patch": "npm version patch -m \"patch version - %s\" && npm publish",
8
9
  "publish:minor": "npm version minor -m \"minor version - %s\" && npm publish",
@@ -25,6 +26,7 @@
25
26
  "dependencies": {
26
27
  "axios": "^1.2.2",
27
28
  "fs-extra": "^11.1.0",
29
+ "ms": "^2.1.3",
28
30
  "schema-utils": "^4.0.0",
29
31
  "typescript": "^4.9.4"
30
32
  }
package/types.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ declare interface FederationTypesPluginOptions {
2
+ exposeTypes?: boolean
3
+ importTypes?: boolean
4
+ excludeRemotes?: string[]
5
+ }
6
+
7
+ declare class FederationTypesPlugin {
8
+ constructor(options?: FederationTypesPluginOptions)
9
+ apply(compiler: any): void
10
+ }
11
+
12
+ export default FederationTypesPlugin