-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module-federation): move withModuleFederation for webpack to new…
… package
- Loading branch information
Showing
22 changed files
with
249 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...-federation/with-module-federation-ssr.ts → ...ion/webpack/with-module-federation-ssr.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
...dule-federation/with-module-federation.ts → ...eration/webpack/with-module-federation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './src/with-module-federation/webpack/with-module-federation'; | ||
export * from './src/with-module-federation/webpack/with-module-federation-ssr'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import { withModuleFederation } from './src/module-federation/with-module-federation'; | ||
import { withModuleFederationForSSR } from './src/module-federation/with-module-federation-ssr'; | ||
import { withModuleFederation } from '@nx/module-federation/webpack'; | ||
import { withModuleFederationForSSR } from '@nx/module-federation/webpack'; | ||
|
||
export { withModuleFederation }; | ||
export { withModuleFederationForSSR }; | ||
/** | ||
* @deprecated Use `@nx/module-federation/webpack` instead. This will be removed in Nx v22. | ||
*/ | ||
export { withModuleFederation, withModuleFederationForSSR }; | ||
|
||
// Support for older generated code: `const withModuleFederation = require('@nx/react/module-federation')` | ||
/** | ||
* @deprecated Use `@nx/module-federation/webpack` instead. This will be removed in Nx v22. | ||
*/ | ||
module.exports = withModuleFederation; | ||
|
||
// Allow newer generated code to work: `const { withModuleFederation } = require(...)`; | ||
/** | ||
* @deprecated Use `@nx/module-federation/webpack` instead. This will be removed in Nx v22. | ||
*/ | ||
module.exports.withModuleFederation = withModuleFederation; | ||
/** | ||
* @deprecated Use `@nx/module-federation/webpack` instead. This will be removed in Nx v22. | ||
*/ | ||
module.exports.withModuleFederationForSSR = withModuleFederationForSSR; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...c/generators/host/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../src/generators/host/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...act/src/generators/host/files/webpack-module-federation-ts/webpack.config.prod.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...es/react/src/generators/host/files/webpack-module-federation-ts/webpack.config.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/react/src/generators/host/files/webpack-module-federation/webpack.config.js__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../react/src/generators/host/files/webpack-module-federation/webpack.config.prod.js__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...generators/remote/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rc/generators/remote/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../react/src/generators/remote/files/webpack-module-federation-ts/webpack.config.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ges/react/src/generators/remote/files/webpack-module-federation/webpack.config.js__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
packages/react/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { type Tree } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import migrateWithMfImport from './migrate-with-mf-import-to-new-package'; | ||
|
||
describe('migrate-with-mf-import-to-new-package', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
tree.write( | ||
'apps/shell/project.json', | ||
JSON.stringify({ | ||
name: 'shell', | ||
root: 'apps/shell', | ||
sourceRoot: 'apps/shell/src', | ||
projectType: 'application', | ||
targets: { | ||
serve: { | ||
executor: '@nx/react:module-federation-dev-server', | ||
options: {}, | ||
}, | ||
}, | ||
}) | ||
); | ||
}); | ||
|
||
it('should migrate the import correctly for withMf', async () => { | ||
// ARRANGE | ||
tree.write( | ||
'apps/shell/webpack.config.ts', | ||
`import { withModuleFederation } from '@nx/react/module-federation';` | ||
); | ||
|
||
// ACT | ||
await migrateWithMfImport(tree); | ||
|
||
// ASSERT | ||
expect(tree.read('apps/shell/webpack.config.ts', 'utf-8')) | ||
.toMatchInlineSnapshot(` | ||
"import { withModuleFederation } from '@nx/module-federation/webpack'; | ||
" | ||
`); | ||
}); | ||
|
||
it('should migrate the require correctly for withMf', async () => { | ||
// ARRANGE | ||
tree.write( | ||
'apps/shell/webpack.config.js', | ||
`const { withModuleFederation } = require('@nx/react/module-federation');` | ||
); | ||
|
||
// ACT | ||
await migrateWithMfImport(tree); | ||
|
||
// ASSERT | ||
expect(tree.read('apps/shell/webpack.config.js', 'utf-8')) | ||
.toMatchInlineSnapshot(` | ||
"const { withModuleFederation } = require('@nx/module-federation/webpack'); | ||
" | ||
`); | ||
}); | ||
|
||
it('should migrate the import correctly for withMfSSR', async () => { | ||
// ARRANGE | ||
tree.write( | ||
'apps/shell/webpack.config.ts', | ||
`import { withModuleFederationForSSR } from '@nx/react/module-federation';` | ||
); | ||
|
||
// ACT | ||
await migrateWithMfImport(tree); | ||
|
||
// ASSERT | ||
expect(tree.read('apps/shell/webpack.config.ts', 'utf-8')) | ||
.toMatchInlineSnapshot(` | ||
"import { withModuleFederationForSSR } from '@nx/module-federation/webpack'; | ||
" | ||
`); | ||
}); | ||
|
||
it('should migrate the require correctly for withMfSSR', async () => { | ||
// ARRANGE | ||
tree.write( | ||
'apps/shell/webpack.config.js', | ||
`const { withModuleFederationForSSR } = require('@nx/react/module-federation');` | ||
); | ||
|
||
// ACT | ||
await migrateWithMfImport(tree); | ||
|
||
// ASSERT | ||
expect(tree.read('apps/shell/webpack.config.js', 'utf-8')) | ||
.toMatchInlineSnapshot(` | ||
"const { withModuleFederationForSSR } = require('@nx/module-federation/webpack'); | ||
" | ||
`); | ||
}); | ||
|
||
describe('idempotent', () => { | ||
it('should migrate the import correctly for withMf even when run twice', async () => { | ||
// ARRANGE | ||
tree.write( | ||
'apps/shell/webpack.config.ts', | ||
`import { withModuleFederation } from '@nx/react/module-federation';` | ||
); | ||
|
||
// ACT | ||
await migrateWithMfImport(tree); | ||
await migrateWithMfImport(tree); | ||
|
||
// ASSERT | ||
expect(tree.read('apps/shell/webpack.config.ts', 'utf-8')) | ||
.toMatchInlineSnapshot(` | ||
"import { withModuleFederation } from '@nx/module-federation/webpack'; | ||
" | ||
`); | ||
}); | ||
|
||
it('should migrate the require correctly for withMfSSR even when run twice', async () => { | ||
// ARRANGE | ||
tree.write( | ||
'apps/shell/webpack.config.js', | ||
`const { withModuleFederationForSSR } = require('@nx/react/module-federation');` | ||
); | ||
|
||
// ACT | ||
await migrateWithMfImport(tree); | ||
await migrateWithMfImport(tree); | ||
|
||
// ASSERT | ||
expect(tree.read('apps/shell/webpack.config.js', 'utf-8')) | ||
.toMatchInlineSnapshot(` | ||
"const { withModuleFederationForSSR } = require('@nx/module-federation/webpack'); | ||
" | ||
`); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.