webpack-federation-types-plugin 1.0.0 → 1.1.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.
@@ -1,4 +1,4 @@
1
- const validate = require("schema-utils")
1
+ const validate = require("schema-utils").validate
2
2
  const ts = require("typescript")
3
3
  const axios = require("axios")
4
4
  const fs = require("fs-extra")
@@ -17,7 +17,7 @@ const tscOptions = {
17
17
  const optionsSchema = {
18
18
  type: "object",
19
19
  properties: {
20
- ignoreRemotes: {
20
+ excludeRemotes: {
21
21
  type: "array",
22
22
  },
23
23
  exposeTypes: {
@@ -39,7 +39,7 @@ const getAssetData = (content) => {
39
39
  }
40
40
 
41
41
  class FederationTypesPlugin {
42
- constructor(options) {
42
+ constructor(options = {}) {
43
43
  validate(optionsSchema, options)
44
44
  this._options = options
45
45
  }
@@ -109,8 +109,8 @@ class FederationTypesPlugin {
109
109
  const remotes = federationPlugin._options.remotes
110
110
  if (!remotes) return
111
111
 
112
- const ignoreRemotes = this._options.ignoreRemotes || []
113
- const wantedRemotes = Object.entries(remotes).filter((remote) => ignoreRemotes.find((c) => c !== remote[0]))
112
+ const excludeRemotes = this._options.excludeRemotes || []
113
+ const wantedRemotes = Object.entries(remotes).filter((remote) => !excludeRemotes.find((c) => c === remote[0]))
114
114
 
115
115
  for (const [remoteName, remoteEntryUri] of wantedRemotes) {
116
116
  const {origin, pathname} = new URL(remoteEntryUri.split("@")[1])
@@ -159,9 +159,10 @@ class FederationTypesPlugin {
159
159
  }
160
160
 
161
161
  compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
162
+ const pluginOptions = this._options || {}
162
163
  compilation.hooks.beforeCodeGeneration.tap(PLUGIN_NAME, () => {
163
- if (this._options.exposeTypes !== false) createTypesDefinitions(compilation)
164
- if (compilation.options.mode === "development" && this._options.importTypes !== false) {
164
+ if (pluginOptions.exposeTypes !== false) createTypesDefinitions(compilation)
165
+ if (compilation.options.mode === "development" && pluginOptions.importTypes !== false) {
165
166
  getTypesDefinitions()
166
167
  // TODO - call getTypesDefinitions using setInterval
167
168
  }
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,7 +36,7 @@ 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
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.0",
4
+ "version": "1.1.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",
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