From b1f35060c034fcdc9dea94f88b29496be5a5f978 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Tue, 5 Sep 2023 10:23:35 +0100 Subject: [PATCH] feat(webpack): move module federation utils to webpack --- CODEOWNERS | 2 +- .../devkit/AdditionalSharedConfig.md | 3 - .../devkit/ModuleFederationConfig.md | 48 --- .../devkit/ModuleFederationLibrary.md | 10 - docs/generated/devkit/README.md | 18 - docs/generated/devkit/Remotes.md | 3 - docs/generated/devkit/SharedFunction.md | 18 - docs/generated/devkit/SharedLibraryConfig.md | 34 -- .../devkit/SharedWorkspaceLibraryConfig.md | 11 - docs/generated/devkit/WorkspaceLibrary.md | 11 - .../WorkspaceLibrarySecondaryEntryPoint.md | 10 - .../generated/devkit/applyAdditionalShared.md | 22 -- docs/generated/devkit/applySharedFunction.md | 17 - .../devkit/getDependentPackagesForProject.md | 19 - .../devkit/getNpmPackageSharedConfig.md | 17 - docs/generated/devkit/mapRemotes.md | 18 - docs/generated/devkit/mapRemotesForSSR.md | 18 - docs/generated/devkit/readRootPackageJson.md | 12 - docs/generated/devkit/sharePackages.md | 19 - .../devkit/shareWorkspaceLibraries.md | 17 - .../packages/devkit/documents/nx_devkit.md | 18 - .../src/react-module-federation.test.ts | 3 +- .../src/generators/setup-mf/setup-mf.ts | 7 +- packages/angular/src/utils/mf/utils.ts | 2 +- .../utils/mf/with-module-federation-ssr.ts | 2 +- .../src/utils/mf/with-module-federation.ts | 2 +- packages/devkit/migrations.json | 6 + packages/devkit/public-api.ts | 25 -- .../migrate-mf-util-usage.spec.ts | 231 +++++++++++++ .../update-17-0-0/migrate-mf-util-usage.ts | 324 ++++++++++++++++++ .../src/utils/module-federation/public-api.ts | 100 ------ ...module-federation.server.config.js__tmpl__ | 2 +- packages/react/src/module-federation/utils.ts | 2 +- .../with-module-federation-ssr.ts | 2 +- .../with-module-federation.ts | 2 +- packages/webpack/index.ts | 2 + .../module-federation/dependencies.spec.ts | 0 .../utils/module-federation/dependencies.ts | 2 +- .../src/utils/module-federation/index.ts | 0 .../utils/module-federation/models/index.ts | 0 .../utils/module-federation/package-json.ts | 4 +- .../src/utils/module-federation/public-api.ts | 46 +++ .../src/utils/module-federation/remotes.ts | 0 .../secondary-entry-points.ts | 7 +- .../src/utils/module-federation/share.spec.ts | 0 .../src/utils/module-federation/share.ts | 5 +- .../module-federation/typescript.spec.ts | 0 .../src/utils/module-federation/typescript.ts | 5 +- 48 files changed, 632 insertions(+), 494 deletions(-) delete mode 100644 docs/generated/devkit/AdditionalSharedConfig.md delete mode 100644 docs/generated/devkit/ModuleFederationConfig.md delete mode 100644 docs/generated/devkit/ModuleFederationLibrary.md delete mode 100644 docs/generated/devkit/Remotes.md delete mode 100644 docs/generated/devkit/SharedFunction.md delete mode 100644 docs/generated/devkit/SharedLibraryConfig.md delete mode 100644 docs/generated/devkit/SharedWorkspaceLibraryConfig.md delete mode 100644 docs/generated/devkit/WorkspaceLibrary.md delete mode 100644 docs/generated/devkit/WorkspaceLibrarySecondaryEntryPoint.md delete mode 100644 docs/generated/devkit/applyAdditionalShared.md delete mode 100644 docs/generated/devkit/applySharedFunction.md delete mode 100644 docs/generated/devkit/getDependentPackagesForProject.md delete mode 100644 docs/generated/devkit/getNpmPackageSharedConfig.md delete mode 100644 docs/generated/devkit/mapRemotes.md delete mode 100644 docs/generated/devkit/mapRemotesForSSR.md delete mode 100644 docs/generated/devkit/readRootPackageJson.md delete mode 100644 docs/generated/devkit/sharePackages.md delete mode 100644 docs/generated/devkit/shareWorkspaceLibraries.md create mode 100644 packages/devkit/src/migrations/update-17-0-0/migrate-mf-util-usage.spec.ts create mode 100644 packages/devkit/src/migrations/update-17-0-0/migrate-mf-util-usage.ts delete mode 100644 packages/devkit/src/utils/module-federation/public-api.ts rename packages/{devkit => webpack}/src/utils/module-federation/dependencies.spec.ts (100%) rename packages/{devkit => webpack}/src/utils/module-federation/dependencies.ts (96%) rename packages/{devkit => webpack}/src/utils/module-federation/index.ts (100%) rename packages/{devkit => webpack}/src/utils/module-federation/models/index.ts (100%) rename packages/{devkit => webpack}/src/utils/module-federation/package-json.ts (79%) create mode 100644 packages/webpack/src/utils/module-federation/public-api.ts rename packages/{devkit => webpack}/src/utils/module-federation/remotes.ts (100%) rename packages/{devkit => webpack}/src/utils/module-federation/secondary-entry-points.ts (96%) rename packages/{devkit => webpack}/src/utils/module-federation/share.spec.ts (100%) rename packages/{devkit => webpack}/src/utils/module-federation/share.ts (98%) rename packages/{devkit => webpack}/src/utils/module-federation/typescript.spec.ts (100%) rename packages/{devkit => webpack}/src/utils/module-federation/typescript.ts (95%) diff --git a/CODEOWNERS b/CODEOWNERS index 2b25dc570f7132..4551eb72a664d0 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -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 diff --git a/docs/generated/devkit/AdditionalSharedConfig.md b/docs/generated/devkit/AdditionalSharedConfig.md deleted file mode 100644 index 1667118dd409ef..00000000000000 --- a/docs/generated/devkit/AdditionalSharedConfig.md +++ /dev/null @@ -1,3 +0,0 @@ -# Type alias: AdditionalSharedConfig - -Ƭ **AdditionalSharedConfig**: (`string` \| [libraryName: string, sharedConfig: SharedLibraryConfig] \| { `libraryName`: `string` ; `sharedConfig`: [`SharedLibraryConfig`](../../devkit/documents/SharedLibraryConfig) })[] diff --git a/docs/generated/devkit/ModuleFederationConfig.md b/docs/generated/devkit/ModuleFederationConfig.md deleted file mode 100644 index 3d34dd6072454b..00000000000000 --- a/docs/generated/devkit/ModuleFederationConfig.md +++ /dev/null @@ -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) diff --git a/docs/generated/devkit/ModuleFederationLibrary.md b/docs/generated/devkit/ModuleFederationLibrary.md deleted file mode 100644 index d329d65cf927d8..00000000000000 --- a/docs/generated/devkit/ModuleFederationLibrary.md +++ /dev/null @@ -1,10 +0,0 @@ -# Type alias: ModuleFederationLibrary - -Ƭ **ModuleFederationLibrary**: `Object` - -#### Type declaration - -| Name | Type | -| :----- | :------- | -| `name` | `string` | -| `type` | `string` | diff --git a/docs/generated/devkit/README.md b/docs/generated/devkit/README.md index d773492142d909..a527f441b9ed54 100644 --- a/docs/generated/devkit/README.md +++ b/docs/generated/devkit/README.md @@ -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) diff --git a/docs/generated/devkit/Remotes.md b/docs/generated/devkit/Remotes.md deleted file mode 100644 index c7a8185e0552df..00000000000000 --- a/docs/generated/devkit/Remotes.md +++ /dev/null @@ -1,3 +0,0 @@ -# Type alias: Remotes - -Ƭ **Remotes**: `string`[] \| [remoteName: string, remoteUrl: string][] diff --git a/docs/generated/devkit/SharedFunction.md b/docs/generated/devkit/SharedFunction.md deleted file mode 100644 index 559050d602f526..00000000000000 --- a/docs/generated/devkit/SharedFunction.md +++ /dev/null @@ -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) diff --git a/docs/generated/devkit/SharedLibraryConfig.md b/docs/generated/devkit/SharedLibraryConfig.md deleted file mode 100644 index 1b5d81e8299dee..00000000000000 --- a/docs/generated/devkit/SharedLibraryConfig.md +++ /dev/null @@ -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` diff --git a/docs/generated/devkit/SharedWorkspaceLibraryConfig.md b/docs/generated/devkit/SharedWorkspaceLibraryConfig.md deleted file mode 100644 index d9dd46e281640f..00000000000000 --- a/docs/generated/devkit/SharedWorkspaceLibraryConfig.md +++ /dev/null @@ -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` | diff --git a/docs/generated/devkit/WorkspaceLibrary.md b/docs/generated/devkit/WorkspaceLibrary.md deleted file mode 100644 index 26db2c88728233..00000000000000 --- a/docs/generated/devkit/WorkspaceLibrary.md +++ /dev/null @@ -1,11 +0,0 @@ -# Type alias: WorkspaceLibrary - -Ƭ **WorkspaceLibrary**: `Object` - -#### Type declaration - -| Name | Type | -| :---------- | :---------------------- | -| `importKey` | `string` \| `undefined` | -| `name` | `string` | -| `root` | `string` | diff --git a/docs/generated/devkit/WorkspaceLibrarySecondaryEntryPoint.md b/docs/generated/devkit/WorkspaceLibrarySecondaryEntryPoint.md deleted file mode 100644 index 94c70a49d44077..00000000000000 --- a/docs/generated/devkit/WorkspaceLibrarySecondaryEntryPoint.md +++ /dev/null @@ -1,10 +0,0 @@ -# Type alias: WorkspaceLibrarySecondaryEntryPoint - -Ƭ **WorkspaceLibrarySecondaryEntryPoint**: `Object` - -#### Type declaration - -| Name | Type | -| :----- | :------- | -| `name` | `string` | -| `path` | `string` | diff --git a/docs/generated/devkit/applyAdditionalShared.md b/docs/generated/devkit/applyAdditionalShared.md deleted file mode 100644 index 55340a7602d062..00000000000000 --- a/docs/generated/devkit/applyAdditionalShared.md +++ /dev/null @@ -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` diff --git a/docs/generated/devkit/applySharedFunction.md b/docs/generated/devkit/applySharedFunction.md deleted file mode 100644 index 55c9517277383a..00000000000000 --- a/docs/generated/devkit/applySharedFunction.md +++ /dev/null @@ -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` diff --git a/docs/generated/devkit/getDependentPackagesForProject.md b/docs/generated/devkit/getDependentPackagesForProject.md deleted file mode 100644 index 50f871e4649fcf..00000000000000 --- a/docs/generated/devkit/getDependentPackagesForProject.md +++ /dev/null @@ -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)[] | diff --git a/docs/generated/devkit/getNpmPackageSharedConfig.md b/docs/generated/devkit/getNpmPackageSharedConfig.md deleted file mode 100644 index 4bf755bfc53e1a..00000000000000 --- a/docs/generated/devkit/getNpmPackageSharedConfig.md +++ /dev/null @@ -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` diff --git a/docs/generated/devkit/mapRemotes.md b/docs/generated/devkit/mapRemotes.md deleted file mode 100644 index 0c5e7df238f775..00000000000000 --- a/docs/generated/devkit/mapRemotes.md +++ /dev/null @@ -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`\> diff --git a/docs/generated/devkit/mapRemotesForSSR.md b/docs/generated/devkit/mapRemotesForSSR.md deleted file mode 100644 index 451da98d00ca7e..00000000000000 --- a/docs/generated/devkit/mapRemotesForSSR.md +++ /dev/null @@ -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`\> diff --git a/docs/generated/devkit/readRootPackageJson.md b/docs/generated/devkit/readRootPackageJson.md deleted file mode 100644 index 281627472e6cc2..00000000000000 --- a/docs/generated/devkit/readRootPackageJson.md +++ /dev/null @@ -1,12 +0,0 @@ -# Function: readRootPackageJson - -▸ **readRootPackageJson**(): `Object` - -#### Returns - -`Object` - -| Name | Type | -| :----------------- | :----------------------------- | -| `dependencies?` | { `[key: string]`: `string`; } | -| `devDependencies?` | { `[key: string]`: `string`; } | diff --git a/docs/generated/devkit/sharePackages.md b/docs/generated/devkit/sharePackages.md deleted file mode 100644 index aea4acc2d74128..00000000000000 --- a/docs/generated/devkit/sharePackages.md +++ /dev/null @@ -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)\> diff --git a/docs/generated/devkit/shareWorkspaceLibraries.md b/docs/generated/devkit/shareWorkspaceLibraries.md deleted file mode 100644 index 54f256f749aaf7..00000000000000 --- a/docs/generated/devkit/shareWorkspaceLibraries.md +++ /dev/null @@ -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) diff --git a/docs/generated/packages/devkit/documents/nx_devkit.md b/docs/generated/packages/devkit/documents/nx_devkit.md index d773492142d909..a527f441b9ed54 100644 --- a/docs/generated/packages/devkit/documents/nx_devkit.md +++ b/docs/generated/packages/devkit/documents/nx_devkit.md @@ -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) diff --git a/e2e/react-core/src/react-module-federation.test.ts b/e2e/react-core/src/react-module-federation.test.ts index b0b2709f7864ae..2030c256fcae98 100644 --- a/e2e/react-core/src/react-module-federation.test.ts +++ b/e2e/react-core/src/react-module-federation.test.ts @@ -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'); diff --git a/packages/angular/src/generators/setup-mf/setup-mf.ts b/packages/angular/src/generators/setup-mf/setup-mf.ts index 99387f70e52f66..aba7153aa270d6 100644 --- a/packages/angular/src/generators/setup-mf/setup-mf.ts +++ b/packages/angular/src/generators/setup-mf/setup-mf.ts @@ -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) { diff --git a/packages/angular/src/utils/mf/utils.ts b/packages/angular/src/utils/mf/utils.ts index db264241bd87ce..101142ad5796e9 100644 --- a/packages/angular/src/utils/mf/utils.ts +++ b/packages/angular/src/utils/mf/utils.ts @@ -8,7 +8,7 @@ import { SharedLibraryConfig, sharePackages, shareWorkspaceLibraries, -} from '@nx/devkit/src/utils/module-federation'; +} from '@nx/webpack/src/utils/module-federation'; import { createProjectGraphAsync, diff --git a/packages/angular/src/utils/mf/with-module-federation-ssr.ts b/packages/angular/src/utils/mf/with-module-federation-ssr.ts index 81d8ced86c65d1..1d4b88140feabb 100644 --- a/packages/angular/src/utils/mf/with-module-federation-ssr.ts +++ b/packages/angular/src/utils/mf/with-module-federation-ssr.ts @@ -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( diff --git a/packages/angular/src/utils/mf/with-module-federation.ts b/packages/angular/src/utils/mf/with-module-federation.ts index 71f615118add7e..93e13b95d5e0e8 100644 --- a/packages/angular/src/utils/mf/with-module-federation.ts +++ b/packages/angular/src/utils/mf/with-module-federation.ts @@ -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'); diff --git a/packages/devkit/migrations.json b/packages/devkit/migrations.json index 7db5ad4104821a..26cb1371e8a332 100644 --- a/packages/devkit/migrations.json +++ b/packages/devkit/migrations.json @@ -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-17-0-0-migrate-mf-usage-to-webpack": { + "cli": "nx", + "version": "17.0.0-beta.1", + "description": "Replace imports of Module Federation utils frm @nx/devkit to @nx/webpack", + "implementation": "./src/migrations/update-17-0-0/migrate-mf-util-usage" } }, "packageJsonUpdates": {}, diff --git a/packages/devkit/public-api.ts b/packages/devkit/public-api.ts index c0b77406849e15..e98b7ed326a89a 100644 --- a/packages/devkit/public-api.ts +++ b/packages/devkit/public-api.ts @@ -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'; diff --git a/packages/devkit/src/migrations/update-17-0-0/migrate-mf-util-usage.spec.ts b/packages/devkit/src/migrations/update-17-0-0/migrate-mf-util-usage.spec.ts new file mode 100644 index 00000000000000..7342e281af0065 --- /dev/null +++ b/packages/devkit/src/migrations/update-17-0-0/migrate-mf-util-usage.spec.ts @@ -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(); + }); +}); diff --git a/packages/devkit/src/migrations/update-17-0-0/migrate-mf-util-usage.ts b/packages/devkit/src/migrations/update-17-0-0/migrate-mf-util-usage.ts new file mode 100644 index 00000000000000..3a0db4656a7589 --- /dev/null +++ b/packages/devkit/src/migrations/update-17-0-0/migrate-mf-util-usage.ts @@ -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 => { + 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; +} diff --git a/packages/devkit/src/utils/module-federation/public-api.ts b/packages/devkit/src/utils/module-federation/public-api.ts deleted file mode 100644 index 0704d6afe9b47e..00000000000000 --- a/packages/devkit/src/utils/module-federation/public-api.ts +++ /dev/null @@ -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, -}; diff --git a/packages/react/src/generators/host/files/module-federation-ssr/module-federation.server.config.js__tmpl__ b/packages/react/src/generators/host/files/module-federation-ssr/module-federation.server.config.js__tmpl__ index 36eacd1efd9d8a..7cdaf87171f0bc 100644 --- a/packages/react/src/generators/host/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +++ b/packages/react/src/generators/host/files/module-federation-ssr/module-federation.server.config.js__tmpl__ @@ -1,7 +1,7 @@ // @ts-check /** - * @type {import('@nx/devkit').ModuleFederationConfig} + * @type {import('@nx/webpack').ModuleFederationConfig} **/ const moduleFederationConfig = { name: '<%= projectName %>', diff --git a/packages/react/src/module-federation/utils.ts b/packages/react/src/module-federation/utils.ts index a5c8a9ae8314f0..ce46bb2f8a05a0 100644 --- a/packages/react/src/module-federation/utils.ts +++ b/packages/react/src/module-federation/utils.ts @@ -7,7 +7,7 @@ import { ModuleFederationConfig, sharePackages, shareWorkspaceLibraries, -} from '@nx/devkit/src/utils/module-federation'; +} from '@nx/webpack/src/utils/module-federation'; import { createProjectGraphAsync, diff --git a/packages/react/src/module-federation/with-module-federation-ssr.ts b/packages/react/src/module-federation/with-module-federation-ssr.ts index e9d1b470d7364c..8776542fc197bd 100644 --- a/packages/react/src/module-federation/with-module-federation-ssr.ts +++ b/packages/react/src/module-federation/with-module-federation-ssr.ts @@ -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( diff --git a/packages/react/src/module-federation/with-module-federation.ts b/packages/react/src/module-federation/with-module-federation.ts index e57dc7d6ae5f94..8e30f947ed049c 100644 --- a/packages/react/src/module-federation/with-module-federation.ts +++ b/packages/react/src/module-federation/with-module-federation.ts @@ -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'); diff --git a/packages/webpack/index.ts b/packages/webpack/index.ts index 7b77994105e2ca..0084902d60d675 100644 --- a/packages/webpack/index.ts +++ b/packages/webpack/index.ts @@ -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'; diff --git a/packages/devkit/src/utils/module-federation/dependencies.spec.ts b/packages/webpack/src/utils/module-federation/dependencies.spec.ts similarity index 100% rename from packages/devkit/src/utils/module-federation/dependencies.spec.ts rename to packages/webpack/src/utils/module-federation/dependencies.spec.ts diff --git a/packages/devkit/src/utils/module-federation/dependencies.ts b/packages/webpack/src/utils/module-federation/dependencies.ts similarity index 96% rename from packages/devkit/src/utils/module-federation/dependencies.ts rename to packages/webpack/src/utils/module-federation/dependencies.ts index 05d70eec021330..6ac108d68066f9 100644 --- a/packages/devkit/src/utils/module-federation/dependencies.ts +++ b/packages/webpack/src/utils/module-federation/dependencies.ts @@ -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'; diff --git a/packages/devkit/src/utils/module-federation/index.ts b/packages/webpack/src/utils/module-federation/index.ts similarity index 100% rename from packages/devkit/src/utils/module-federation/index.ts rename to packages/webpack/src/utils/module-federation/index.ts diff --git a/packages/devkit/src/utils/module-federation/models/index.ts b/packages/webpack/src/utils/module-federation/models/index.ts similarity index 100% rename from packages/devkit/src/utils/module-federation/models/index.ts rename to packages/webpack/src/utils/module-federation/models/index.ts diff --git a/packages/devkit/src/utils/module-federation/package-json.ts b/packages/webpack/src/utils/module-federation/package-json.ts similarity index 79% rename from packages/devkit/src/utils/module-federation/package-json.ts rename to packages/webpack/src/utils/module-federation/package-json.ts index ce68761fcfd2fe..52e64b7fb983cb 100644 --- a/packages/devkit/src/utils/module-federation/package-json.ts +++ b/packages/webpack/src/utils/module-federation/package-json.ts @@ -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 }; diff --git a/packages/webpack/src/utils/module-federation/public-api.ts b/packages/webpack/src/utils/module-federation/public-api.ts new file mode 100644 index 00000000000000..7ac57f4fd3c919 --- /dev/null +++ b/packages/webpack/src/utils/module-federation/public-api.ts @@ -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, +}; diff --git a/packages/devkit/src/utils/module-federation/remotes.ts b/packages/webpack/src/utils/module-federation/remotes.ts similarity index 100% rename from packages/devkit/src/utils/module-federation/remotes.ts rename to packages/webpack/src/utils/module-federation/remotes.ts diff --git a/packages/devkit/src/utils/module-federation/secondary-entry-points.ts b/packages/webpack/src/utils/module-federation/secondary-entry-points.ts similarity index 96% rename from packages/devkit/src/utils/module-federation/secondary-entry-points.ts rename to packages/webpack/src/utils/module-federation/secondary-entry-points.ts index 3f9911e146a9c4..0cb16e24f24302 100644 --- a/packages/devkit/src/utils/module-federation/secondary-entry-points.ts +++ b/packages/webpack/src/utils/module-federation/secondary-entry-points.ts @@ -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 = diff --git a/packages/devkit/src/utils/module-federation/share.spec.ts b/packages/webpack/src/utils/module-federation/share.spec.ts similarity index 100% rename from packages/devkit/src/utils/module-federation/share.spec.ts rename to packages/webpack/src/utils/module-federation/share.spec.ts diff --git a/packages/devkit/src/utils/module-federation/share.ts b/packages/webpack/src/utils/module-federation/share.ts similarity index 98% rename from packages/devkit/src/utils/module-federation/share.ts rename to packages/webpack/src/utils/module-federation/share.ts index 24dae72218cd55..ceeba7cc55238f 100644 --- a/packages/devkit/src/utils/module-federation/share.ts +++ b/packages/webpack/src/utils/module-federation/share.ts @@ -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 diff --git a/packages/devkit/src/utils/module-federation/typescript.spec.ts b/packages/webpack/src/utils/module-federation/typescript.spec.ts similarity index 100% rename from packages/devkit/src/utils/module-federation/typescript.spec.ts rename to packages/webpack/src/utils/module-federation/typescript.spec.ts diff --git a/packages/devkit/src/utils/module-federation/typescript.ts b/packages/webpack/src/utils/module-federation/typescript.ts similarity index 95% rename from packages/devkit/src/utils/module-federation/typescript.ts rename to packages/webpack/src/utils/module-federation/typescript.ts index ca2c4573c6dd80..866169f5ed02da 100644 --- a/packages/devkit/src/utils/module-federation/typescript.ts +++ b/packages/webpack/src/utils/module-federation/typescript.ts @@ -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');