feat(webpack): move module federation utils to webpack (#18996)
This commit is contained in:
parent
e507ff02e2
commit
dd5ea7a244
@ -87,6 +87,7 @@ pnpm-lock.yaml @nrwl/nx-core-reviewers
|
||||
/packages/web/** @nrwl/nx-js-reviewers
|
||||
/e2e/web/** @nrwl/nx-js-reviewers
|
||||
/packages/webpack/** @nrwl/nx-js-reviewers
|
||||
/packages/webpack/src/utils/module-federation @jaysoo @Coly010
|
||||
/e2e/webpack/** @nrwl/nx-js-reviewers
|
||||
/packages/esbuild/** @nrwl/nx-js-reviewers
|
||||
/e2e/esbuild/** @nrwl/nx-js-reviewers
|
||||
@ -131,7 +132,6 @@ pnpm-lock.yaml @nrwl/nx-core-reviewers
|
||||
/packages/devkit/index.d.ts @FrozenPandaz @vsavkin
|
||||
/packages/devkit/public-api.ts @FrozenPandaz @vsavkin
|
||||
/packages/devkit/nx.ts @FrozenPandaz @vsavkin
|
||||
/packages/devkit/src/utils/module-federation @jaysoo @Coly010
|
||||
|
||||
# Nx-Plugin
|
||||
/docs/generated/packages/plugin/** @nrwl/nx-devkit-reviewers @nrwl/nx-docs-reviewers
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
# Type alias: AdditionalSharedConfig
|
||||
|
||||
Ƭ **AdditionalSharedConfig**: (`string` \| [libraryName: string, sharedConfig: SharedLibraryConfig] \| { `libraryName`: `string` ; `sharedConfig`: [`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig) })[]
|
||||
@ -1,48 +0,0 @@
|
||||
# Interface: ModuleFederationConfig
|
||||
|
||||
## Table of contents
|
||||
|
||||
### Properties
|
||||
|
||||
- [additionalShared](../../devkit/documents/ModuleFederationConfig#additionalshared): AdditionalSharedConfig
|
||||
- [exposes](../../devkit/documents/ModuleFederationConfig#exposes): Record<string, string>
|
||||
- [library](../../devkit/documents/ModuleFederationConfig#library): ModuleFederationLibrary
|
||||
- [name](../../devkit/documents/ModuleFederationConfig#name): string
|
||||
- [remotes](../../devkit/documents/ModuleFederationConfig#remotes): Remotes
|
||||
- [shared](../../devkit/documents/ModuleFederationConfig#shared): SharedFunction
|
||||
|
||||
## Properties
|
||||
|
||||
### additionalShared
|
||||
|
||||
• `Optional` **additionalShared**: [`AdditionalSharedConfig`](../../devkit/documents/AdditionalSharedConfig)
|
||||
|
||||
---
|
||||
|
||||
### exposes
|
||||
|
||||
• `Optional` **exposes**: `Record`<`string`, `string`\>
|
||||
|
||||
---
|
||||
|
||||
### library
|
||||
|
||||
• `Optional` **library**: [`ModuleFederationLibrary`](../../devkit/documents/ModuleFederationLibrary)
|
||||
|
||||
---
|
||||
|
||||
### name
|
||||
|
||||
• **name**: `string`
|
||||
|
||||
---
|
||||
|
||||
### remotes
|
||||
|
||||
• `Optional` **remotes**: [`Remotes`](../../devkit/documents/Remotes)
|
||||
|
||||
---
|
||||
|
||||
### shared
|
||||
|
||||
• `Optional` **shared**: [`SharedFunction`](../../devkit/documents/SharedFunction)
|
||||
@ -1,10 +0,0 @@
|
||||
# Type alias: ModuleFederationLibrary
|
||||
|
||||
Ƭ **ModuleFederationLibrary**: `Object`
|
||||
|
||||
#### Type declaration
|
||||
|
||||
| Name | Type |
|
||||
| :----- | :------- |
|
||||
| `name` | `string` |
|
||||
| `type` | `string` |
|
||||
@ -37,7 +37,6 @@ It only uses language primitives and immutable objects
|
||||
- [JsonParseOptions](../../devkit/documents/JsonParseOptions)
|
||||
- [JsonSerializeOptions](../../devkit/documents/JsonSerializeOptions)
|
||||
- [MigrationsJson](../../devkit/documents/MigrationsJson)
|
||||
- [ModuleFederationConfig](../../devkit/documents/ModuleFederationConfig)
|
||||
- [NxAffectedConfig](../../devkit/documents/NxAffectedConfig)
|
||||
- [NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration)
|
||||
- [ProjectConfiguration](../../devkit/documents/ProjectConfiguration)
|
||||
@ -50,7 +49,6 @@ It only uses language primitives and immutable objects
|
||||
- [ProjectGraphProjectNode](../../devkit/documents/ProjectGraphProjectNode)
|
||||
- [ProjectsConfigurations](../../devkit/documents/ProjectsConfigurations)
|
||||
- [RemoteCache](../../devkit/documents/RemoteCache)
|
||||
- [SharedLibraryConfig](../../devkit/documents/SharedLibraryConfig)
|
||||
- [StringDeletion](../../devkit/documents/StringDeletion)
|
||||
- [StringInsertion](../../devkit/documents/StringInsertion)
|
||||
- [Target](../../devkit/documents/Target)
|
||||
@ -64,7 +62,6 @@ It only uses language primitives and immutable objects
|
||||
|
||||
### Type Aliases
|
||||
|
||||
- [AdditionalSharedConfig](../../devkit/documents/AdditionalSharedConfig)
|
||||
- [CreateDependencies](../../devkit/documents/CreateDependencies)
|
||||
- [CreateNodes](../../devkit/documents/CreateNodes)
|
||||
- [CreateNodesFunction](../../devkit/documents/CreateNodesFunction)
|
||||
@ -74,7 +71,6 @@ It only uses language primitives and immutable objects
|
||||
- [GeneratorCallback](../../devkit/documents/GeneratorCallback)
|
||||
- [Hasher](../../devkit/documents/Hasher)
|
||||
- [ImplicitDependencyEntry](../../devkit/documents/ImplicitDependencyEntry)
|
||||
- [ModuleFederationLibrary](../../devkit/documents/ModuleFederationLibrary)
|
||||
- [NxPlugin](../../devkit/documents/NxPlugin)
|
||||
- [NxPluginV1](../../devkit/documents/NxPluginV1)
|
||||
- [NxPluginV2](../../devkit/documents/NxPluginV2)
|
||||
@ -82,15 +78,10 @@ It only uses language primitives and immutable objects
|
||||
- [ProjectGraphNode](../../devkit/documents/ProjectGraphNode)
|
||||
- [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator)
|
||||
- [ProjectType](../../devkit/documents/ProjectType)
|
||||
- [Remotes](../../devkit/documents/Remotes)
|
||||
- [SharedFunction](../../devkit/documents/SharedFunction)
|
||||
- [SharedWorkspaceLibraryConfig](../../devkit/documents/SharedWorkspaceLibraryConfig)
|
||||
- [StringChange](../../devkit/documents/StringChange)
|
||||
- [TaskGraphExecutor](../../devkit/documents/TaskGraphExecutor)
|
||||
- [WorkspaceConfiguration](../../devkit/documents/WorkspaceConfiguration)
|
||||
- [WorkspaceJsonConfiguration](../../devkit/documents/WorkspaceJsonConfiguration)
|
||||
- [WorkspaceLibrary](../../devkit/documents/WorkspaceLibrary)
|
||||
- [WorkspaceLibrarySecondaryEntryPoint](../../devkit/documents/WorkspaceLibrarySecondaryEntryPoint)
|
||||
|
||||
### Variables
|
||||
|
||||
@ -105,9 +96,7 @@ It only uses language primitives and immutable objects
|
||||
|
||||
- [addDependenciesToPackageJson](../../devkit/documents/addDependenciesToPackageJson)
|
||||
- [addProjectConfiguration](../../devkit/documents/addProjectConfiguration)
|
||||
- [applyAdditionalShared](../../devkit/documents/applyAdditionalShared)
|
||||
- [applyChangesToString](../../devkit/documents/applyChangesToString)
|
||||
- [applySharedFunction](../../devkit/documents/applySharedFunction)
|
||||
- [convertNxExecutor](../../devkit/documents/convertNxExecutor)
|
||||
- [convertNxGenerator](../../devkit/documents/convertNxGenerator)
|
||||
- [createProjectFileMapUsingProjectGraph](../../devkit/documents/createProjectFileMapUsingProjectGraph)
|
||||
@ -118,8 +107,6 @@ It only uses language primitives and immutable objects
|
||||
- [extractLayoutDirectory](../../devkit/documents/extractLayoutDirectory)
|
||||
- [formatFiles](../../devkit/documents/formatFiles)
|
||||
- [generateFiles](../../devkit/documents/generateFiles)
|
||||
- [getDependentPackagesForProject](../../devkit/documents/getDependentPackagesForProject)
|
||||
- [getNpmPackageSharedConfig](../../devkit/documents/getNpmPackageSharedConfig)
|
||||
- [getOutputsForTargetAndConfiguration](../../devkit/documents/getOutputsForTargetAndConfiguration)
|
||||
- [getPackageManagerCommand](../../devkit/documents/getPackageManagerCommand)
|
||||
- [getPackageManagerVersion](../../devkit/documents/getPackageManagerVersion)
|
||||
@ -130,8 +117,6 @@ It only uses language primitives and immutable objects
|
||||
- [installPackagesTask](../../devkit/documents/installPackagesTask)
|
||||
- [isStandaloneProject](../../devkit/documents/isStandaloneProject)
|
||||
- [joinPathFragments](../../devkit/documents/joinPathFragments)
|
||||
- [mapRemotes](../../devkit/documents/mapRemotes)
|
||||
- [mapRemotesForSSR](../../devkit/documents/mapRemotesForSSR)
|
||||
- [moveFilesToNewDirectory](../../devkit/documents/moveFilesToNewDirectory)
|
||||
- [names](../../devkit/documents/names)
|
||||
- [normalizePath](../../devkit/documents/normalizePath)
|
||||
@ -144,7 +129,6 @@ It only uses language primitives and immutable objects
|
||||
- [readNxJson](../../devkit/documents/readNxJson)
|
||||
- [readProjectConfiguration](../../devkit/documents/readProjectConfiguration)
|
||||
- [readProjectsConfigurationFromProjectGraph](../../devkit/documents/readProjectsConfigurationFromProjectGraph)
|
||||
- [readRootPackageJson](../../devkit/documents/readRootPackageJson)
|
||||
- [readTargetOptions](../../devkit/documents/readTargetOptions)
|
||||
- [readWorkspaceConfiguration](../../devkit/documents/readWorkspaceConfiguration)
|
||||
- [removeDependenciesFromPackageJson](../../devkit/documents/removeDependenciesFromPackageJson)
|
||||
@ -153,8 +137,6 @@ It only uses language primitives and immutable objects
|
||||
- [runExecutor](../../devkit/documents/runExecutor)
|
||||
- [runTasksInSerial](../../devkit/documents/runTasksInSerial)
|
||||
- [serializeJson](../../devkit/documents/serializeJson)
|
||||
- [sharePackages](../../devkit/documents/sharePackages)
|
||||
- [shareWorkspaceLibraries](../../devkit/documents/shareWorkspaceLibraries)
|
||||
- [stripIndents](../../devkit/documents/stripIndents)
|
||||
- [stripJsonComments](../../devkit/documents/stripJsonComments)
|
||||
- [targetToTargetString](../../devkit/documents/targetToTargetString)
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
# Type alias: Remotes
|
||||
|
||||
Ƭ **Remotes**: `string`[] \| [remoteName: string, remoteUrl: string][]
|
||||
@ -1,18 +0,0 @@
|
||||
# Type alias: SharedFunction
|
||||
|
||||
Ƭ **SharedFunction**: (`libraryName`: `string`, `sharedConfig`: [`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig)) => `undefined` \| `false` \| [`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig)
|
||||
|
||||
#### Type declaration
|
||||
|
||||
▸ (`libraryName`, `sharedConfig`): `undefined` \| `false` \| [`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig)
|
||||
|
||||
##### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------------- | :------------------------------------------------------------------ |
|
||||
| `libraryName` | `string` |
|
||||
| `sharedConfig` | [`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig) |
|
||||
|
||||
##### Returns
|
||||
|
||||
`undefined` \| `false` \| [`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig)
|
||||
@ -1,34 +0,0 @@
|
||||
# Interface: SharedLibraryConfig
|
||||
|
||||
## Table of contents
|
||||
|
||||
### Properties
|
||||
|
||||
- [eager](../../devkit/documents/SharedLibraryConfig#eager): boolean
|
||||
- [requiredVersion](../../devkit/documents/SharedLibraryConfig#requiredversion): string | false
|
||||
- [singleton](../../devkit/documents/SharedLibraryConfig#singleton): boolean
|
||||
- [strictVersion](../../devkit/documents/SharedLibraryConfig#strictversion): boolean
|
||||
|
||||
## Properties
|
||||
|
||||
### eager
|
||||
|
||||
• `Optional` **eager**: `boolean`
|
||||
|
||||
---
|
||||
|
||||
### requiredVersion
|
||||
|
||||
• `Optional` **requiredVersion**: `string` \| `false`
|
||||
|
||||
---
|
||||
|
||||
### singleton
|
||||
|
||||
• `Optional` **singleton**: `boolean`
|
||||
|
||||
---
|
||||
|
||||
### strictVersion
|
||||
|
||||
• `Optional` **strictVersion**: `boolean`
|
||||
@ -1,11 +0,0 @@
|
||||
# Type alias: SharedWorkspaceLibraryConfig
|
||||
|
||||
Ƭ **SharedWorkspaceLibraryConfig**: `Object`
|
||||
|
||||
#### Type declaration
|
||||
|
||||
| Name | Type |
|
||||
| :--------------------- | :---------------------------------------------------------------------------------------------------------------- |
|
||||
| `getAliases` | () => `Record`<`string`, `string`\> |
|
||||
| `getLibraries` | (`eager?`: `boolean`) => `Record`<`string`, [`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig)\> |
|
||||
| `getReplacementPlugin` | () => `NormalModuleReplacementPlugin` |
|
||||
@ -1,11 +0,0 @@
|
||||
# Type alias: WorkspaceLibrary
|
||||
|
||||
Ƭ **WorkspaceLibrary**: `Object`
|
||||
|
||||
#### Type declaration
|
||||
|
||||
| Name | Type |
|
||||
| :---------- | :---------------------- |
|
||||
| `importKey` | `string` \| `undefined` |
|
||||
| `name` | `string` |
|
||||
| `root` | `string` |
|
||||
@ -1,10 +0,0 @@
|
||||
# Type alias: WorkspaceLibrarySecondaryEntryPoint
|
||||
|
||||
Ƭ **WorkspaceLibrarySecondaryEntryPoint**: `Object`
|
||||
|
||||
#### Type declaration
|
||||
|
||||
| Name | Type |
|
||||
| :----- | :------- |
|
||||
| `name` | `string` |
|
||||
| `path` | `string` |
|
||||
@ -1,22 +0,0 @@
|
||||
# Function: applyAdditionalShared
|
||||
|
||||
▸ **applyAdditionalShared**(`sharedConfig`, `additionalShared`, `projectGraph`): `void`
|
||||
|
||||
Add additional dependencies to the shared package that may not have been
|
||||
discovered by the project graph.
|
||||
|
||||
This can be useful for applications that use a Dependency Injection system
|
||||
that expects certain Singleton values to be present in the shared injection
|
||||
hierarchy.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :----------------- | :--------------------------------------------------------------------------------------- | :--------------------------------- |
|
||||
| `sharedConfig` | `Record`<`string`, [`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig)\> | The original Shared Config |
|
||||
| `additionalShared` | [`AdditionalSharedConfig`](../../devkit/documents/AdditionalSharedConfig) | The additional dependencies to add |
|
||||
| `projectGraph` | [`ProjectGraph`](../../devkit/documents/ProjectGraph) | The Nx project graph |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
@ -1,17 +0,0 @@
|
||||
# Function: applySharedFunction
|
||||
|
||||
▸ **applySharedFunction**(`sharedConfig`, `sharedFn`): `void`
|
||||
|
||||
Apply a custom function provided by the user that will modify the Shared Config
|
||||
of the dependencies for the Module Federation build.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------------- | :--------------------------------------------------------------------------------------- | :---------------------------------------- |
|
||||
| `sharedConfig` | `Record`<`string`, [`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig)\> | The original Shared Config to be modified |
|
||||
| `sharedFn` | [`SharedFunction`](../../devkit/documents/SharedFunction) | The custom function to run |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
@ -1,19 +0,0 @@
|
||||
# Function: getDependentPackagesForProject
|
||||
|
||||
▸ **getDependentPackagesForProject**(`projectGraph`, `name`): `Object`
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------------- | :---------------------------------------------------- |
|
||||
| `projectGraph` | [`ProjectGraph`](../../devkit/documents/ProjectGraph) |
|
||||
| `name` | `string` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Object`
|
||||
|
||||
| Name | Type |
|
||||
| :------------------- | :-------------------------------------------------------------- |
|
||||
| `npmPackages` | `string`[] |
|
||||
| `workspaceLibraries` | [`WorkspaceLibrary`](../../devkit/documents/WorkspaceLibrary)[] |
|
||||
@ -1,17 +0,0 @@
|
||||
# Function: getNpmPackageSharedConfig
|
||||
|
||||
▸ **getNpmPackageSharedConfig**(`pkgName`, `version`): [`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig) \| `undefined`
|
||||
|
||||
Build the Module Federation Share Config for a specific package and the
|
||||
specified version of that package.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :-------- | :------- | :----------------------------------------------------------------------------- |
|
||||
| `pkgName` | `string` | Name of the package to share |
|
||||
| `version` | `string` | Version of the package to require by other apps in the Module Federation setup |
|
||||
|
||||
#### Returns
|
||||
|
||||
[`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig) \| `undefined`
|
||||
@ -1,18 +0,0 @@
|
||||
# Function: mapRemotes
|
||||
|
||||
▸ **mapRemotes**(`remotes`, `remoteEntryExt`, `determineRemoteUrl`): `Record`<`string`, `string`\>
|
||||
|
||||
Map remote names to a format that can be understood and used by Module
|
||||
Federation.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------------------- | :------------------------------------------ | :------------------------------------------------------- |
|
||||
| `remotes` | [`Remotes`](../../devkit/documents/Remotes) | The remotes to map |
|
||||
| `remoteEntryExt` | `"js"` \| `"mjs"` | The file extension of the remoteEntry file |
|
||||
| `determineRemoteUrl` | (`remote`: `string`) => `string` | The function used to lookup the URL of the served remote |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Record`<`string`, `string`\>
|
||||
@ -1,18 +0,0 @@
|
||||
# Function: mapRemotesForSSR
|
||||
|
||||
▸ **mapRemotesForSSR**(`remotes`, `remoteEntryExt`, `determineRemoteUrl`): `Record`<`string`, `string`\>
|
||||
|
||||
Map remote names to a format that can be understood and used by Module
|
||||
Federation.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------------------- | :------------------------------------------ | :------------------------------------------------------- |
|
||||
| `remotes` | [`Remotes`](../../devkit/documents/Remotes) | The remotes to map |
|
||||
| `remoteEntryExt` | `"js"` \| `"mjs"` | The file extension of the remoteEntry file |
|
||||
| `determineRemoteUrl` | (`remote`: `string`) => `string` | The function used to lookup the URL of the served remote |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Record`<`string`, `string`\>
|
||||
@ -1,12 +0,0 @@
|
||||
# Function: readRootPackageJson
|
||||
|
||||
▸ **readRootPackageJson**(): `Object`
|
||||
|
||||
#### Returns
|
||||
|
||||
`Object`
|
||||
|
||||
| Name | Type |
|
||||
| :----------------- | :----------------------------- |
|
||||
| `dependencies?` | { `[key: string]`: `string`; } |
|
||||
| `devDependencies?` | { `[key: string]`: `string`; } |
|
||||
@ -1,19 +0,0 @@
|
||||
# Function: sharePackages
|
||||
|
||||
▸ **sharePackages**(`packages`): `Record`<`string`, [`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig)\>
|
||||
|
||||
Create a dictionary of packages and their Module Federation Shared Config
|
||||
from an array of package names.
|
||||
|
||||
Lookup the versions of the packages from the root package.json file in the
|
||||
workspace.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :--------- | :--------- | :-------------------------------- |
|
||||
| `packages` | `string`[] | Array of package names as strings |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Record`<`string`, [`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig)\>
|
||||
@ -1,17 +0,0 @@
|
||||
# Function: shareWorkspaceLibraries
|
||||
|
||||
▸ **shareWorkspaceLibraries**(`libraries`, `tsConfigPath?`): [`SharedWorkspaceLibraryConfig`](../../devkit/documents/SharedWorkspaceLibraryConfig)
|
||||
|
||||
Build an object of functions to be used with the ModuleFederationPlugin to
|
||||
share Nx Workspace Libraries between Hosts and Remotes.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :-------------- | :-------------------------------------------------------------- | :--------------------------------------------------------------------------- |
|
||||
| `libraries` | [`WorkspaceLibrary`](../../devkit/documents/WorkspaceLibrary)[] | The Nx Workspace Libraries to share |
|
||||
| `tsConfigPath?` | `string` | The path to TS Config File that contains the Path Mappings for the Libraries |
|
||||
|
||||
#### Returns
|
||||
|
||||
[`SharedWorkspaceLibraryConfig`](../../devkit/documents/SharedWorkspaceLibraryConfig)
|
||||
@ -37,7 +37,6 @@ It only uses language primitives and immutable objects
|
||||
- [JsonParseOptions](../../devkit/documents/JsonParseOptions)
|
||||
- [JsonSerializeOptions](../../devkit/documents/JsonSerializeOptions)
|
||||
- [MigrationsJson](../../devkit/documents/MigrationsJson)
|
||||
- [ModuleFederationConfig](../../devkit/documents/ModuleFederationConfig)
|
||||
- [NxAffectedConfig](../../devkit/documents/NxAffectedConfig)
|
||||
- [NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration)
|
||||
- [ProjectConfiguration](../../devkit/documents/ProjectConfiguration)
|
||||
@ -50,7 +49,6 @@ It only uses language primitives and immutable objects
|
||||
- [ProjectGraphProjectNode](../../devkit/documents/ProjectGraphProjectNode)
|
||||
- [ProjectsConfigurations](../../devkit/documents/ProjectsConfigurations)
|
||||
- [RemoteCache](../../devkit/documents/RemoteCache)
|
||||
- [SharedLibraryConfig](../../devkit/documents/SharedLibraryConfig)
|
||||
- [StringDeletion](../../devkit/documents/StringDeletion)
|
||||
- [StringInsertion](../../devkit/documents/StringInsertion)
|
||||
- [Target](../../devkit/documents/Target)
|
||||
@ -64,7 +62,6 @@ It only uses language primitives and immutable objects
|
||||
|
||||
### Type Aliases
|
||||
|
||||
- [AdditionalSharedConfig](../../devkit/documents/AdditionalSharedConfig)
|
||||
- [CreateDependencies](../../devkit/documents/CreateDependencies)
|
||||
- [CreateNodes](../../devkit/documents/CreateNodes)
|
||||
- [CreateNodesFunction](../../devkit/documents/CreateNodesFunction)
|
||||
@ -74,7 +71,6 @@ It only uses language primitives and immutable objects
|
||||
- [GeneratorCallback](../../devkit/documents/GeneratorCallback)
|
||||
- [Hasher](../../devkit/documents/Hasher)
|
||||
- [ImplicitDependencyEntry](../../devkit/documents/ImplicitDependencyEntry)
|
||||
- [ModuleFederationLibrary](../../devkit/documents/ModuleFederationLibrary)
|
||||
- [NxPlugin](../../devkit/documents/NxPlugin)
|
||||
- [NxPluginV1](../../devkit/documents/NxPluginV1)
|
||||
- [NxPluginV2](../../devkit/documents/NxPluginV2)
|
||||
@ -82,15 +78,10 @@ It only uses language primitives and immutable objects
|
||||
- [ProjectGraphNode](../../devkit/documents/ProjectGraphNode)
|
||||
- [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator)
|
||||
- [ProjectType](../../devkit/documents/ProjectType)
|
||||
- [Remotes](../../devkit/documents/Remotes)
|
||||
- [SharedFunction](../../devkit/documents/SharedFunction)
|
||||
- [SharedWorkspaceLibraryConfig](../../devkit/documents/SharedWorkspaceLibraryConfig)
|
||||
- [StringChange](../../devkit/documents/StringChange)
|
||||
- [TaskGraphExecutor](../../devkit/documents/TaskGraphExecutor)
|
||||
- [WorkspaceConfiguration](../../devkit/documents/WorkspaceConfiguration)
|
||||
- [WorkspaceJsonConfiguration](../../devkit/documents/WorkspaceJsonConfiguration)
|
||||
- [WorkspaceLibrary](../../devkit/documents/WorkspaceLibrary)
|
||||
- [WorkspaceLibrarySecondaryEntryPoint](../../devkit/documents/WorkspaceLibrarySecondaryEntryPoint)
|
||||
|
||||
### Variables
|
||||
|
||||
@ -105,9 +96,7 @@ It only uses language primitives and immutable objects
|
||||
|
||||
- [addDependenciesToPackageJson](../../devkit/documents/addDependenciesToPackageJson)
|
||||
- [addProjectConfiguration](../../devkit/documents/addProjectConfiguration)
|
||||
- [applyAdditionalShared](../../devkit/documents/applyAdditionalShared)
|
||||
- [applyChangesToString](../../devkit/documents/applyChangesToString)
|
||||
- [applySharedFunction](../../devkit/documents/applySharedFunction)
|
||||
- [convertNxExecutor](../../devkit/documents/convertNxExecutor)
|
||||
- [convertNxGenerator](../../devkit/documents/convertNxGenerator)
|
||||
- [createProjectFileMapUsingProjectGraph](../../devkit/documents/createProjectFileMapUsingProjectGraph)
|
||||
@ -118,8 +107,6 @@ It only uses language primitives and immutable objects
|
||||
- [extractLayoutDirectory](../../devkit/documents/extractLayoutDirectory)
|
||||
- [formatFiles](../../devkit/documents/formatFiles)
|
||||
- [generateFiles](../../devkit/documents/generateFiles)
|
||||
- [getDependentPackagesForProject](../../devkit/documents/getDependentPackagesForProject)
|
||||
- [getNpmPackageSharedConfig](../../devkit/documents/getNpmPackageSharedConfig)
|
||||
- [getOutputsForTargetAndConfiguration](../../devkit/documents/getOutputsForTargetAndConfiguration)
|
||||
- [getPackageManagerCommand](../../devkit/documents/getPackageManagerCommand)
|
||||
- [getPackageManagerVersion](../../devkit/documents/getPackageManagerVersion)
|
||||
@ -130,8 +117,6 @@ It only uses language primitives and immutable objects
|
||||
- [installPackagesTask](../../devkit/documents/installPackagesTask)
|
||||
- [isStandaloneProject](../../devkit/documents/isStandaloneProject)
|
||||
- [joinPathFragments](../../devkit/documents/joinPathFragments)
|
||||
- [mapRemotes](../../devkit/documents/mapRemotes)
|
||||
- [mapRemotesForSSR](../../devkit/documents/mapRemotesForSSR)
|
||||
- [moveFilesToNewDirectory](../../devkit/documents/moveFilesToNewDirectory)
|
||||
- [names](../../devkit/documents/names)
|
||||
- [normalizePath](../../devkit/documents/normalizePath)
|
||||
@ -144,7 +129,6 @@ It only uses language primitives and immutable objects
|
||||
- [readNxJson](../../devkit/documents/readNxJson)
|
||||
- [readProjectConfiguration](../../devkit/documents/readProjectConfiguration)
|
||||
- [readProjectsConfigurationFromProjectGraph](../../devkit/documents/readProjectsConfigurationFromProjectGraph)
|
||||
- [readRootPackageJson](../../devkit/documents/readRootPackageJson)
|
||||
- [readTargetOptions](../../devkit/documents/readTargetOptions)
|
||||
- [readWorkspaceConfiguration](../../devkit/documents/readWorkspaceConfiguration)
|
||||
- [removeDependenciesFromPackageJson](../../devkit/documents/removeDependenciesFromPackageJson)
|
||||
@ -153,8 +137,6 @@ It only uses language primitives and immutable objects
|
||||
- [runExecutor](../../devkit/documents/runExecutor)
|
||||
- [runTasksInSerial](../../devkit/documents/runTasksInSerial)
|
||||
- [serializeJson](../../devkit/documents/serializeJson)
|
||||
- [sharePackages](../../devkit/documents/sharePackages)
|
||||
- [shareWorkspaceLibraries](../../devkit/documents/shareWorkspaceLibraries)
|
||||
- [stripIndents](../../devkit/documents/stripIndents)
|
||||
- [stripJsonComments](../../devkit/documents/stripJsonComments)
|
||||
- [targetToTargetString](../../devkit/documents/targetToTargetString)
|
||||
|
||||
@ -51,8 +51,7 @@ describe('React Module Federation', () => {
|
||||
updateFile(
|
||||
`apps/${shell}/webpack.config.js`,
|
||||
stripIndents`
|
||||
import { ModuleFederationConfig } from '@nx/devkit';
|
||||
import { composePlugins, withNx } from '@nx/webpack';
|
||||
import { composePlugins, withNx, ModuleFederationConfig } from '@nx/webpack';
|
||||
import { withReact } from '@nx/react';
|
||||
import { withModuleFederation } from '@nx/react/module-federation');
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ export async function setupMf(tree: Tree, rawOptions: Schema) {
|
||||
installTask = addDependenciesToPackageJson(
|
||||
tree,
|
||||
{},
|
||||
{ '@nx/web': nxVersion }
|
||||
{ '@nx/web': nxVersion, '@nx/webpack': nxVersion }
|
||||
);
|
||||
}
|
||||
|
||||
@ -61,6 +61,11 @@ export async function setupMf(tree: Tree, rawOptions: Schema) {
|
||||
if (options.mfType === 'host') {
|
||||
setupHostIfDynamic(tree, options);
|
||||
updateHostAppRoutes(tree, options);
|
||||
installTask = addDependenciesToPackageJson(
|
||||
tree,
|
||||
{},
|
||||
{ '@nx/webpack': nxVersion }
|
||||
);
|
||||
}
|
||||
|
||||
if (!options.skipE2E) {
|
||||
|
||||
@ -8,7 +8,7 @@ import {
|
||||
SharedLibraryConfig,
|
||||
sharePackages,
|
||||
shareWorkspaceLibraries,
|
||||
} from '@nx/devkit/src/utils/module-federation';
|
||||
} from '@nx/webpack/src/utils/module-federation';
|
||||
|
||||
import {
|
||||
createProjectGraphAsync,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { ModuleFederationConfig } from '@nx/devkit/src/utils/module-federation';
|
||||
import { ModuleFederationConfig } from '@nx/webpack/src/utils/module-federation';
|
||||
import { getModuleFederationConfig } from './utils';
|
||||
|
||||
export async function withModuleFederationForSSR(
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { ModuleFederationConfig } from '@nx/devkit/src/utils/module-federation';
|
||||
import { ModuleFederationConfig } from '@nx/webpack/src/utils/module-federation';
|
||||
import { getModuleFederationConfig } from './utils';
|
||||
import ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
|
||||
|
||||
|
||||
@ -5,6 +5,12 @@
|
||||
"version": "16.0.0-beta.1",
|
||||
"description": "Replace @nrwl/devkit with @nx/devkit",
|
||||
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
|
||||
},
|
||||
"update-16-9-0-migrate-mf-usage-to-webpack": {
|
||||
"cli": "nx",
|
||||
"version": "16.9.0-beta.1",
|
||||
"description": "Replace imports of Module Federation utils frm @nx/devkit to @nx/webpack",
|
||||
"implementation": "./src/migrations/update-16-9-0/migrate-mf-util-usage"
|
||||
}
|
||||
},
|
||||
"packageJsonUpdates": {},
|
||||
|
||||
@ -109,28 +109,3 @@ export { convertNxExecutor } from './src/utils/convert-nx-executor';
|
||||
* @category Utils
|
||||
*/
|
||||
export { moveFilesToNewDirectory } from './src/utils/move-dir';
|
||||
|
||||
/**
|
||||
* @category Utils
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
export {
|
||||
AdditionalSharedConfig,
|
||||
ModuleFederationConfig,
|
||||
SharedLibraryConfig,
|
||||
SharedWorkspaceLibraryConfig,
|
||||
WorkspaceLibrary,
|
||||
SharedFunction,
|
||||
WorkspaceLibrarySecondaryEntryPoint,
|
||||
Remotes,
|
||||
ModuleFederationLibrary,
|
||||
applySharedFunction,
|
||||
applyAdditionalShared,
|
||||
getNpmPackageSharedConfig,
|
||||
shareWorkspaceLibraries,
|
||||
sharePackages,
|
||||
mapRemotes,
|
||||
mapRemotesForSSR,
|
||||
getDependentPackagesForProject,
|
||||
readRootPackageJson,
|
||||
} from './src/utils/module-federation/public-api';
|
||||
|
||||
@ -0,0 +1,231 @@
|
||||
import { createTreeWithEmptyWorkspace } from 'nx/src/generators/testing-utils/create-tree-with-empty-workspace';
|
||||
import { stripIndents } from 'nx/src/utils/strip-indents';
|
||||
import { readJson } from 'nx/src/generators/utils/json';
|
||||
|
||||
import migrateMfUtilUsage from './migrate-mf-util-usage';
|
||||
|
||||
describe('migrate-mf-util-usage', () => {
|
||||
it('should do nothing if it does not find files using the mf public api', async () => {
|
||||
// ARRANGE
|
||||
const testFileContents = `${stripIndents`import { readFileSync } from 'fs';
|
||||
const file = readFileSync('test.ts');`}\n`;
|
||||
|
||||
const tree = createTreeWithEmptyWorkspace();
|
||||
tree.write('test.ts', testFileContents);
|
||||
|
||||
// ACT
|
||||
await migrateMfUtilUsage(tree);
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('test.ts', 'utf-8')).toEqual(testFileContents);
|
||||
});
|
||||
|
||||
it('should do nothing if it does not find files using the mf public api even if they use devkit', async () => {
|
||||
// ARRANGE
|
||||
const testFileContents = `${stripIndents`import { readJson } from '@nx/devkit';
|
||||
const file = readJson('test.json');`}\n`;
|
||||
|
||||
const tree = createTreeWithEmptyWorkspace();
|
||||
tree.write('test.ts', testFileContents);
|
||||
|
||||
// ACT
|
||||
await migrateMfUtilUsage(tree);
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('test.ts', 'utf-8')).toEqual(testFileContents);
|
||||
});
|
||||
|
||||
it('should replace imports to utils from devkit with webpack', async () => {
|
||||
// ARRANGE
|
||||
const testFileContents = stripIndents`import {ModuleFederationConfig} from '@nx/devkit';
|
||||
const config: ModuleFederationConfig = {};
|
||||
`;
|
||||
const expectedTestFileContents = `${stripIndents`import { ModuleFederationConfig } from '@nx/webpack';
|
||||
const config: ModuleFederationConfig = {};`}\n`;
|
||||
|
||||
const tree = createTreeWithEmptyWorkspace();
|
||||
tree.write('test.ts', testFileContents);
|
||||
|
||||
// ACT
|
||||
await migrateMfUtilUsage(tree);
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('test.ts', 'utf-8')).toEqual(expectedTestFileContents);
|
||||
expect(
|
||||
readJson(tree, 'package.json').devDependencies['@nx/webpack']
|
||||
).toBeDefined();
|
||||
});
|
||||
|
||||
it('should extract imports to utils from devkit and replace with imports from webpack', async () => {
|
||||
// ARRANGE
|
||||
const testFileContents = stripIndents`import {joinPathFragments, ModuleFederationConfig} from '@nx/devkit';
|
||||
const config: ModuleFederationConfig = {};
|
||||
`;
|
||||
const expectedTestFileContents = `${stripIndents`import { joinPathFragments } from '@nx/devkit';
|
||||
import { ModuleFederationConfig } from '@nx/webpack';
|
||||
const config: ModuleFederationConfig = {};`}\n`;
|
||||
|
||||
const tree = createTreeWithEmptyWorkspace();
|
||||
tree.write('test.ts', testFileContents);
|
||||
|
||||
// ACT
|
||||
await migrateMfUtilUsage(tree);
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('test.ts', 'utf-8')).toEqual(expectedTestFileContents);
|
||||
expect(
|
||||
readJson(tree, 'package.json').devDependencies['@nx/webpack']
|
||||
).toBeDefined();
|
||||
});
|
||||
|
||||
it('should extract imports to utils from devkit and replace with imports from webpack, even with multiple devkit imports', async () => {
|
||||
// ARRANGE
|
||||
const testFileContents = stripIndents`import {joinPathFragments, ModuleFederationConfig} from '@nx/devkit';
|
||||
import {readJson, WorkspaceLibrary} from '@nx/devkit';
|
||||
const config: ModuleFederationConfig = {};
|
||||
`;
|
||||
const expectedTestFileContents = `${stripIndents`import { joinPathFragments } from '@nx/devkit';
|
||||
import { readJson } from '@nx/devkit';
|
||||
import { ModuleFederationConfig, WorkspaceLibrary } from '@nx/webpack';
|
||||
const config: ModuleFederationConfig = {};`}\n`;
|
||||
|
||||
const tree = createTreeWithEmptyWorkspace();
|
||||
tree.write('test.ts', testFileContents);
|
||||
|
||||
// ACT
|
||||
await migrateMfUtilUsage(tree);
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('test.ts', 'utf-8')).toEqual(expectedTestFileContents);
|
||||
expect(
|
||||
readJson(tree, 'package.json').devDependencies['@nx/webpack']
|
||||
).toBeDefined();
|
||||
});
|
||||
|
||||
describe('require()', () => {
|
||||
it('should do nothing if it does not find files using the mf public api', async () => {
|
||||
// ARRANGE
|
||||
const testFileContents = `${stripIndents`const { readFileSync } = require('fs');
|
||||
const file = readFileSync('test.ts');`}\n`;
|
||||
|
||||
const tree = createTreeWithEmptyWorkspace();
|
||||
tree.write('test.ts', testFileContents);
|
||||
|
||||
// ACT
|
||||
await migrateMfUtilUsage(tree);
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('test.ts', 'utf-8')).toEqual(testFileContents);
|
||||
});
|
||||
|
||||
it('should do nothing if it does not find files using the mf public api even if they use devkit', async () => {
|
||||
// ARRANGE
|
||||
const testFileContents = `${stripIndents`const { readJson } = require('@nx/devkit');
|
||||
const file = readJson('test.json');`}\n`;
|
||||
|
||||
const tree = createTreeWithEmptyWorkspace();
|
||||
tree.write('test.ts', testFileContents);
|
||||
|
||||
// ACT
|
||||
await migrateMfUtilUsage(tree);
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('test.ts', 'utf-8')).toEqual(testFileContents);
|
||||
});
|
||||
|
||||
it('should replace imports to utils from devkit with webpack', async () => {
|
||||
// ARRANGE
|
||||
const testFileContents = stripIndents`const {ModuleFederationConfig} = require('@nx/devkit');
|
||||
const config: ModuleFederationConfig = {};
|
||||
`;
|
||||
const expectedTestFileContents = `${stripIndents`const { ModuleFederationConfig } = require('@nx/webpack');
|
||||
const config: ModuleFederationConfig = {};`}\n`;
|
||||
|
||||
const tree = createTreeWithEmptyWorkspace();
|
||||
tree.write('test.ts', testFileContents);
|
||||
|
||||
// ACT
|
||||
await migrateMfUtilUsage(tree);
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('test.ts', 'utf-8')).toEqual(expectedTestFileContents);
|
||||
expect(
|
||||
readJson(tree, 'package.json').devDependencies['@nx/webpack']
|
||||
).toBeDefined();
|
||||
});
|
||||
|
||||
it('should extract imports to utils from devkit and replace with imports from webpack', async () => {
|
||||
// ARRANGE
|
||||
const testFileContents = stripIndents`const {joinPathFragments, ModuleFederationConfig} = require("@nx/devkit");
|
||||
const config: ModuleFederationConfig = {};
|
||||
`;
|
||||
const expectedTestFileContents = `${stripIndents`const { joinPathFragments } = require('@nx/devkit');
|
||||
const { ModuleFederationConfig } = require('@nx/webpack');
|
||||
const config: ModuleFederationConfig = {};`}\n`;
|
||||
|
||||
const tree = createTreeWithEmptyWorkspace();
|
||||
tree.write('test.ts', testFileContents);
|
||||
|
||||
// ACT
|
||||
await migrateMfUtilUsage(tree);
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('test.ts', 'utf-8')).toEqual(expectedTestFileContents);
|
||||
expect(
|
||||
readJson(tree, 'package.json').devDependencies['@nx/webpack']
|
||||
).toBeDefined();
|
||||
});
|
||||
|
||||
it('should extract imports to utils from devkit and replace with imports from webpack, even with multiple devkit imports', async () => {
|
||||
// ARRANGE
|
||||
const testFileContents = stripIndents`const {joinPathFragments, ModuleFederationConfig} = require('@nx/devkit');
|
||||
const {readJson, WorkspaceLibrary} = require('@nx/devkit');
|
||||
const config: ModuleFederationConfig = {};
|
||||
`;
|
||||
const expectedTestFileContents = `${stripIndents`const { joinPathFragments } = require('@nx/devkit');
|
||||
const { readJson } = require('@nx/devkit');
|
||||
const { ModuleFederationConfig, WorkspaceLibrary } = require('@nx/webpack');
|
||||
const config: ModuleFederationConfig = {};`}\n`;
|
||||
|
||||
const tree = createTreeWithEmptyWorkspace();
|
||||
tree.write('test.ts', testFileContents);
|
||||
|
||||
// ACT
|
||||
await migrateMfUtilUsage(tree);
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('test.ts', 'utf-8')).toEqual(expectedTestFileContents);
|
||||
expect(
|
||||
readJson(tree, 'package.json').devDependencies['@nx/webpack']
|
||||
).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should replace imports to utils from devkit with webpack in JSDoc comments', async () => {
|
||||
// ARRANGE
|
||||
const testFileContents = stripIndents`
|
||||
/**
|
||||
* @type {import('@nx/devkit').ModuleFederationConfig}
|
||||
**/
|
||||
const config = {};
|
||||
`;
|
||||
|
||||
const tree = createTreeWithEmptyWorkspace();
|
||||
tree.write('test.js', testFileContents);
|
||||
|
||||
// ACT
|
||||
await migrateMfUtilUsage(tree);
|
||||
|
||||
// ASSERT
|
||||
expect(tree.read('test.js', 'utf-8')).toMatchInlineSnapshot(`
|
||||
"/**
|
||||
* @type {import('@nx/webpack').ModuleFederationConfig}
|
||||
**/
|
||||
const config = {};
|
||||
"
|
||||
`);
|
||||
expect(
|
||||
readJson(tree, 'package.json').devDependencies['@nx/webpack']
|
||||
).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,324 @@
|
||||
import type { Tree } from 'nx/src/generators/tree';
|
||||
import type { GeneratorCallback } from 'nx/src/config/misc-interfaces';
|
||||
import type { Node, SyntaxKind } from 'typescript';
|
||||
import { visitNotIgnoredFiles } from '../../generators/visit-not-ignored-files';
|
||||
import { formatFiles } from '../../generators/format-files';
|
||||
import { requireNx } from '../../../nx';
|
||||
import {
|
||||
addDependenciesToPackageJson,
|
||||
ensurePackage,
|
||||
} from '../../utils/package-json';
|
||||
import { typescriptVersion } from '../../utils/versions';
|
||||
|
||||
const { readJson } = requireNx();
|
||||
|
||||
let tsModule: typeof import('typescript');
|
||||
|
||||
const MODULE_FEDERATION_PUBLIC_TOKENS = [
|
||||
'AdditionalSharedConfig',
|
||||
'ModuleFederationConfig',
|
||||
'SharedLibraryConfig',
|
||||
'SharedWorkspaceLibraryConfig',
|
||||
'WorkspaceLibrary',
|
||||
'SharedFunction',
|
||||
'WorkspaceLibrarySecondaryEntryPoint',
|
||||
'Remotes',
|
||||
'ModuleFederationLibrary',
|
||||
'applySharedFunction',
|
||||
'applyAdditionalShared',
|
||||
'getNpmPackageSharedConfig',
|
||||
'shareWorkspaceLibraries',
|
||||
'sharePackages',
|
||||
'mapRemotes',
|
||||
'mapRemotesForSSR',
|
||||
'getDependentPackagesForProject',
|
||||
'readRootPackageJson',
|
||||
];
|
||||
|
||||
export default async (tree: Tree): Promise<GeneratorCallback | void> => {
|
||||
let hasFileToMigrate = false;
|
||||
visitNotIgnoredFiles(tree, '/', (path) => {
|
||||
if (!path.endsWith('.ts') && !path.endsWith('.js')) {
|
||||
return;
|
||||
}
|
||||
|
||||
let fileContents = tree.read(path, 'utf-8');
|
||||
if (
|
||||
MODULE_FEDERATION_PUBLIC_TOKENS.every(
|
||||
(token) => !fileContents.includes(token)
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
hasFileToMigrate = true;
|
||||
|
||||
fileContents = replaceTSImports(tree, path, fileContents);
|
||||
fileContents = replaceRequireCalls(tree, path, fileContents);
|
||||
fileContents = replaceJSDoc(tree, path, fileContents);
|
||||
tree.write(path, fileContents);
|
||||
});
|
||||
|
||||
if (hasFileToMigrate) {
|
||||
await formatFiles(tree);
|
||||
|
||||
const pkgJson = readJson(tree, 'package.json');
|
||||
const nxVersion =
|
||||
pkgJson.devDependencies?.['nx'] ??
|
||||
pkgJson.dependencies?.['nx'] ??
|
||||
'17.0.0';
|
||||
return addDependenciesToPackageJson(tree, {}, { '@nx/webpack': nxVersion });
|
||||
}
|
||||
};
|
||||
|
||||
function replaceJSDoc(tree: Tree, path: string, fileContents: string) {
|
||||
let newFileContents = fileContents;
|
||||
for (const token of MODULE_FEDERATION_PUBLIC_TOKENS) {
|
||||
newFileContents = newFileContents.replaceAll(
|
||||
new RegExp(
|
||||
`(@type)+\\s({)+(\\s)*(import\\(('|")+@nx\/devkit('|")+\\)\.)+(${token})+\\s*(})+`,
|
||||
'g'
|
||||
),
|
||||
`@type {import('@nx/webpack').${token}}`
|
||||
);
|
||||
}
|
||||
|
||||
return newFileContents;
|
||||
}
|
||||
|
||||
function replaceRequireCalls(
|
||||
tree: Tree,
|
||||
path: string,
|
||||
fileContents: string
|
||||
): string {
|
||||
if (!tsModule) {
|
||||
tsModule = ensurePackage('typescript', typescriptVersion);
|
||||
}
|
||||
|
||||
const sourceFile = tsModule.createSourceFile(
|
||||
path,
|
||||
fileContents,
|
||||
tsModule.ScriptTarget.Latest,
|
||||
true
|
||||
);
|
||||
|
||||
const allDevkitRequires = findNodes(
|
||||
sourceFile,
|
||||
tsModule.SyntaxKind.VariableStatement
|
||||
)
|
||||
.filter((node) =>
|
||||
[`require("@nx/devkit")`, `require('@nx/devkit')`].some((r) =>
|
||||
node.getText().includes(r)
|
||||
)
|
||||
)
|
||||
.filter(
|
||||
(node) => findNodes(node, tsModule.SyntaxKind.ObjectBindingPattern).length
|
||||
);
|
||||
|
||||
const mfUtilRequires = allDevkitRequires.filter((node) =>
|
||||
MODULE_FEDERATION_PUBLIC_TOKENS.some((token) =>
|
||||
node.getText().includes(token)
|
||||
)
|
||||
);
|
||||
|
||||
if (!mfUtilRequires.length) {
|
||||
return fileContents;
|
||||
}
|
||||
|
||||
const mfUtilTokens = mfUtilRequires.map((node) => {
|
||||
const allTokens = findNodes(node, tsModule.SyntaxKind.BindingElement);
|
||||
const mfTokens = allTokens.filter((node) =>
|
||||
MODULE_FEDERATION_PUBLIC_TOKENS.some((token) => node.getText() === token)
|
||||
);
|
||||
|
||||
return {
|
||||
requireNode: node,
|
||||
onlyMf: allTokens.length === mfTokens.length,
|
||||
mfTokens,
|
||||
};
|
||||
});
|
||||
|
||||
const changes: {
|
||||
startPosition: number;
|
||||
endPosition?: number;
|
||||
content: string;
|
||||
}[] = [];
|
||||
for (const mfUtilRequireData of mfUtilTokens) {
|
||||
if (mfUtilRequireData.onlyMf) {
|
||||
changes.push({
|
||||
startPosition: mfUtilRequireData.requireNode.getStart(),
|
||||
endPosition: mfUtilRequireData.requireNode.getEnd(),
|
||||
content: '',
|
||||
});
|
||||
} else {
|
||||
for (const mfToken of mfUtilRequireData.mfTokens) {
|
||||
const replaceTrailingComma =
|
||||
mfToken.getText().charAt(mfToken.getEnd() + 1) === ',';
|
||||
changes.push({
|
||||
startPosition: mfToken.getStart(),
|
||||
endPosition: replaceTrailingComma
|
||||
? mfToken.getEnd() + 1
|
||||
: mfToken.getEnd(),
|
||||
content: '',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
changes.push({
|
||||
startPosition: mfUtilTokens[mfUtilTokens.length - 1].requireNode.getEnd(),
|
||||
content: `\nconst { ${mfUtilTokens
|
||||
.map((mfUtilToken) => mfUtilToken.mfTokens.map((node) => node.getText()))
|
||||
.join(', ')} } = require('@nx/webpack');`,
|
||||
});
|
||||
|
||||
let newFileContents = fileContents;
|
||||
while (changes.length) {
|
||||
const change = changes.pop();
|
||||
newFileContents = `${newFileContents.substring(0, change.startPosition)}${
|
||||
change.content
|
||||
}${newFileContents.substring(
|
||||
change.endPosition ? change.endPosition : change.startPosition
|
||||
)}`;
|
||||
}
|
||||
|
||||
return newFileContents;
|
||||
}
|
||||
|
||||
function replaceTSImports(
|
||||
tree: Tree,
|
||||
path: string,
|
||||
fileContents: string
|
||||
): string {
|
||||
if (!tsModule) {
|
||||
tsModule = ensurePackage('typescript', typescriptVersion);
|
||||
}
|
||||
|
||||
const sourceFile = tsModule.createSourceFile(
|
||||
path,
|
||||
fileContents,
|
||||
tsModule.ScriptTarget.Latest,
|
||||
true
|
||||
);
|
||||
|
||||
const allImports = findNodes(
|
||||
sourceFile,
|
||||
tsModule.SyntaxKind.ImportDeclaration
|
||||
);
|
||||
const devkitImports = allImports.filter((i) =>
|
||||
i.getText().includes(`'@nx/devkit';`)
|
||||
);
|
||||
const mfUtilsImports = devkitImports.filter((i) =>
|
||||
MODULE_FEDERATION_PUBLIC_TOKENS.some((token) => i.getText().includes(token))
|
||||
);
|
||||
|
||||
if (!mfUtilsImports.length) {
|
||||
return fileContents;
|
||||
}
|
||||
|
||||
const mfUtilsWithMultipleImports = mfUtilsImports.map((i) => {
|
||||
const importSpecifierNodes = findNodes(
|
||||
i,
|
||||
tsModule.SyntaxKind.ImportSpecifier
|
||||
);
|
||||
const mfImportSpecifierNodes = importSpecifierNodes.filter((node) =>
|
||||
MODULE_FEDERATION_PUBLIC_TOKENS.some((token) =>
|
||||
node.getText().includes(token)
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
importDeclarationNode: i,
|
||||
onlyMf: mfImportSpecifierNodes.length === importSpecifierNodes.length,
|
||||
mfImportSpecifierNodes,
|
||||
};
|
||||
});
|
||||
|
||||
const changes: {
|
||||
startPosition: number;
|
||||
endPosition?: number;
|
||||
content: string;
|
||||
}[] = [];
|
||||
for (const importDeclaration of mfUtilsWithMultipleImports) {
|
||||
if (importDeclaration.onlyMf) {
|
||||
changes.push({
|
||||
startPosition: importDeclaration.importDeclarationNode.getStart(),
|
||||
endPosition: importDeclaration.importDeclarationNode.getEnd(),
|
||||
content: '',
|
||||
});
|
||||
} else {
|
||||
for (const mfImportSpecifierNodes of importDeclaration.mfImportSpecifierNodes) {
|
||||
const replaceTrailingComma =
|
||||
importDeclaration.importDeclarationNode
|
||||
.getText()
|
||||
.charAt(mfImportSpecifierNodes.getEnd() + 1) === ',';
|
||||
changes.push({
|
||||
startPosition: mfImportSpecifierNodes.getStart(),
|
||||
endPosition: replaceTrailingComma
|
||||
? mfImportSpecifierNodes.getEnd() + 1
|
||||
: mfImportSpecifierNodes.getEnd(),
|
||||
content: '',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
changes.push({
|
||||
startPosition:
|
||||
mfUtilsWithMultipleImports[
|
||||
mfUtilsWithMultipleImports.length - 1
|
||||
].importDeclarationNode.getEnd(),
|
||||
content: `\nimport { ${mfUtilsWithMultipleImports
|
||||
.map((importDeclaration) =>
|
||||
importDeclaration.mfImportSpecifierNodes.map((node) => node.getText())
|
||||
)
|
||||
.join(', ')} } from '@nx/webpack';`,
|
||||
});
|
||||
|
||||
let newFileContents = fileContents;
|
||||
while (changes.length) {
|
||||
const change = changes.pop();
|
||||
newFileContents = `${newFileContents.substring(0, change.startPosition)}${
|
||||
change.content
|
||||
}${newFileContents.substring(
|
||||
change.endPosition ? change.endPosition : change.startPosition
|
||||
)}`;
|
||||
}
|
||||
|
||||
return newFileContents;
|
||||
}
|
||||
|
||||
function findNodes(
|
||||
node: Node,
|
||||
kind: SyntaxKind | SyntaxKind[],
|
||||
max = Infinity
|
||||
): Node[] {
|
||||
if (!node || max == 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const arr: Node[] = [];
|
||||
const hasMatch = Array.isArray(kind)
|
||||
? kind.includes(node.kind)
|
||||
: node.kind === kind;
|
||||
if (hasMatch) {
|
||||
arr.push(node);
|
||||
max--;
|
||||
}
|
||||
if (max > 0) {
|
||||
for (const child of node.getChildren()) {
|
||||
findNodes(child, kind, max).forEach((node) => {
|
||||
if (max > 0) {
|
||||
arr.push(node);
|
||||
}
|
||||
max--;
|
||||
});
|
||||
|
||||
if (max <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
@ -1,100 +0,0 @@
|
||||
import {
|
||||
AdditionalSharedConfig,
|
||||
ModuleFederationConfig,
|
||||
ModuleFederationLibrary,
|
||||
Remotes,
|
||||
SharedFunction,
|
||||
SharedLibraryConfig,
|
||||
SharedWorkspaceLibraryConfig,
|
||||
WorkspaceLibrary,
|
||||
WorkspaceLibrarySecondaryEntryPoint,
|
||||
} from './models';
|
||||
|
||||
import {
|
||||
applyAdditionalShared,
|
||||
applySharedFunction,
|
||||
getNpmPackageSharedConfig,
|
||||
sharePackages,
|
||||
shareWorkspaceLibraries,
|
||||
} from './share';
|
||||
|
||||
import { mapRemotes, mapRemotesForSSR } from './remotes';
|
||||
|
||||
import { getDependentPackagesForProject } from './dependencies';
|
||||
|
||||
import { readRootPackageJson } from './package-json';
|
||||
|
||||
export {
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
ModuleFederationConfig,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
SharedLibraryConfig,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
SharedWorkspaceLibraryConfig,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
AdditionalSharedConfig,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
WorkspaceLibrary,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
SharedFunction,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
WorkspaceLibrarySecondaryEntryPoint,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
Remotes,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
ModuleFederationLibrary,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
applySharedFunction,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
applyAdditionalShared,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
getNpmPackageSharedConfig,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
shareWorkspaceLibraries,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
sharePackages,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
mapRemotes,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
mapRemotesForSSR,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
getDependentPackagesForProject,
|
||||
/**
|
||||
* @deprecated Accessing the Module Federation Utils from the Public API of @nx/devkit is deprecated and they will be removed from the Public API in v17.
|
||||
*/
|
||||
readRootPackageJson,
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* @type {import('@nx/devkit').ModuleFederationConfig}
|
||||
* @type {import('@nx/webpack').ModuleFederationConfig}
|
||||
**/
|
||||
const moduleFederationConfig = {
|
||||
name: '<%= projectName %>',
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
ModuleFederationConfig,
|
||||
sharePackages,
|
||||
shareWorkspaceLibraries,
|
||||
} from '@nx/devkit/src/utils/module-federation';
|
||||
} from '@nx/webpack/src/utils/module-federation';
|
||||
|
||||
import {
|
||||
createProjectGraphAsync,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { ModuleFederationConfig } from '@nx/devkit/src/utils/module-federation';
|
||||
import { ModuleFederationConfig } from '@nx/webpack/src/utils/module-federation';
|
||||
import { getModuleFederationConfig } from './utils';
|
||||
|
||||
export async function withModuleFederationForSSR(
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { ModuleFederationConfig } from '@nx/devkit/src/utils/module-federation';
|
||||
import { ModuleFederationConfig } from '@nx/webpack/src/utils/module-federation';
|
||||
import { getModuleFederationConfig } from './utils';
|
||||
import type { AsyncNxWebpackPlugin } from '@nx/webpack';
|
||||
import ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { configurationGenerator } from './src/generators/configuration/configuration';
|
||||
|
||||
export { configurationGenerator };
|
||||
|
||||
// Exported for backwards compatibility in case a plugin is using the old name.
|
||||
@ -21,3 +22,4 @@ export * from './src/executors/webpack/webpack.impl';
|
||||
export * from './src/utils/get-css-module-local-ident';
|
||||
export * from './src/utils/with-nx';
|
||||
export * from './src/utils/with-web';
|
||||
export * from './src/utils/module-federation/public-api';
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
||||
import type { ProjectGraph } from '@nx/devkit';
|
||||
import type { WorkspaceLibrary } from './models';
|
||||
import { readTsPathMappings } from './typescript';
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import { existsSync } from 'fs';
|
||||
import { requireNx } from '../../../nx';
|
||||
|
||||
const { workspaceRoot, readJsonFile, joinPathFragments } = requireNx();
|
||||
import { workspaceRoot, readJsonFile, joinPathFragments } from '@nx/devkit';
|
||||
|
||||
export function readRootPackageJson(): {
|
||||
dependencies?: { [key: string]: string };
|
||||
46
packages/webpack/src/utils/module-federation/public-api.ts
Normal file
46
packages/webpack/src/utils/module-federation/public-api.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import {
|
||||
AdditionalSharedConfig,
|
||||
ModuleFederationConfig,
|
||||
ModuleFederationLibrary,
|
||||
Remotes,
|
||||
SharedFunction,
|
||||
SharedLibraryConfig,
|
||||
SharedWorkspaceLibraryConfig,
|
||||
WorkspaceLibrary,
|
||||
WorkspaceLibrarySecondaryEntryPoint,
|
||||
} from './models';
|
||||
|
||||
import {
|
||||
applyAdditionalShared,
|
||||
applySharedFunction,
|
||||
getNpmPackageSharedConfig,
|
||||
sharePackages,
|
||||
shareWorkspaceLibraries,
|
||||
} from './share';
|
||||
|
||||
import { mapRemotes, mapRemotesForSSR } from './remotes';
|
||||
|
||||
import { getDependentPackagesForProject } from './dependencies';
|
||||
|
||||
import { readRootPackageJson } from './package-json';
|
||||
|
||||
export {
|
||||
ModuleFederationConfig,
|
||||
SharedLibraryConfig,
|
||||
SharedWorkspaceLibraryConfig,
|
||||
AdditionalSharedConfig,
|
||||
WorkspaceLibrary,
|
||||
SharedFunction,
|
||||
WorkspaceLibrarySecondaryEntryPoint,
|
||||
Remotes,
|
||||
ModuleFederationLibrary,
|
||||
applySharedFunction,
|
||||
applyAdditionalShared,
|
||||
getNpmPackageSharedConfig,
|
||||
shareWorkspaceLibraries,
|
||||
sharePackages,
|
||||
mapRemotes,
|
||||
mapRemotesForSSR,
|
||||
getDependentPackagesForProject,
|
||||
readRootPackageJson,
|
||||
};
|
||||
@ -2,12 +2,11 @@ import type { WorkspaceLibrary } from './models';
|
||||
import { WorkspaceLibrarySecondaryEntryPoint } from './models';
|
||||
import { dirname, join, relative } from 'path';
|
||||
import { existsSync, lstatSync, readdirSync } from 'fs';
|
||||
|
||||
import { readJsonFile, joinPathFragments, workspaceRoot } from '@nx/devkit';
|
||||
import type { PackageJson } from 'nx/src/utils/package-json';
|
||||
import { requireNx } from '../../../nx';
|
||||
import { requireNx } from '@nx/devkit/nx';
|
||||
|
||||
let { readJsonFile, joinPathFragments, workspaceRoot, readModulePackageJson } =
|
||||
requireNx();
|
||||
let { readModulePackageJson } = requireNx();
|
||||
|
||||
// TODO: Remove this in Nx 18 when Nx 16.7.0 is no longer supported
|
||||
readModulePackageJson =
|
||||
@ -11,10 +11,7 @@ import {
|
||||
collectPackageSecondaryEntryPoints,
|
||||
collectWorkspaceLibrarySecondaryEntryPoints,
|
||||
} from './secondary-entry-points';
|
||||
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
||||
import { requireNx } from '../../../nx';
|
||||
|
||||
const { workspaceRoot, logger } = requireNx();
|
||||
import { type ProjectGraph, workspaceRoot, logger } from '@nx/devkit';
|
||||
|
||||
/**
|
||||
* Build an object of functions to be used with the ModuleFederationPlugin to
|
||||
@ -1,9 +1,7 @@
|
||||
import { existsSync } from 'fs';
|
||||
import { ParsedCommandLine } from 'typescript';
|
||||
import { dirname, join } from 'path';
|
||||
import { requireNx } from '../../../nx';
|
||||
|
||||
const { workspaceRoot } = requireNx();
|
||||
import { workspaceRoot } from '@nx/devkit';
|
||||
|
||||
let tsConfig: ParsedCommandLine;
|
||||
let tsPathMappings: ParsedCommandLine['options']['paths'];
|
||||
@ -35,6 +33,7 @@ function readTsConfiguration(tsConfigPath: string): ParsedCommandLine {
|
||||
}
|
||||
|
||||
let tsModule: typeof import('typescript');
|
||||
|
||||
export function readTsConfig(tsConfigPath: string): ParsedCommandLine {
|
||||
if (!tsModule) {
|
||||
tsModule = require('typescript');
|
||||
Loading…
x
Reference in New Issue
Block a user