Skip to content

Commit

Permalink
fix(angular): incremental builds with mfes nrwl#6923
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Oct 6, 2021
1 parent 0d3601e commit 484b254
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
calculateProjectDependencies,
checkDependentProjectsHaveBeenBuilt,
createTmpTsConfig,
} from '@nrwl/workspace/src/utils/buildable-libs-utils';
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
import { joinPathFragments } from '@nrwl/devkit';
import { join } from 'path';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
Expand Down Expand Up @@ -94,7 +94,10 @@ function run(
): Observable<BuilderOutput> {
const { target, dependencies } = calculateProjectDependencies(
readCachedProjectGraph('4.0'),
context
context.workspaceRoot,
context.target.project,
context.target.target,
context.target.configuration
);

options.tsConfig = createTmpTsConfig(
Expand All @@ -103,8 +106,16 @@ function run(
target.data.root,
dependencies
);
process.env.NX_TSCONFIG_PATH = options.tsConfig;

return of(checkDependentProjectsHaveBeenBuilt(context, dependencies)).pipe(
return of(
checkDependentProjectsHaveBeenBuilt(
context.workspaceRoot,
context.target.project,
context.target.target,
dependencies
)
).pipe(
switchMap((result) => {
if (result) {
return buildApp(options, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@ exports[`app --mfe should add a remote application and add it to a specified hos
const mf = require(\\"@angular-architects/module-federation/webpack\\");
const path = require(\\"path\\");
/**
* We use the NX_TSCONFIG_PATH environment variable when using the @nrwl/angular:webpack-browser
* builder as it will generate a temporary tsconfig file which contains any required remappings of
* shared libraries.
* A remapping will occur when a library is buildable, as webpack needs to know the location of the
* built files for the buildable library.
* This NX_TSCONFIG_PATH environment variable is set by the @nrwl/angular:webpack-browser and it contains
* the location of the generated temporary tsconfig file.
*/
const tsConfigPath = process.env.NX_TSCONFIG_PATH ?? path.join(__dirname, '../../tsconfig.base.json');
const workspaceRootPath = path.join(__dirname, '../../');
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(path.join(__dirname, \\"../../tsconfig.base.json\\"), [
sharedMappings.register(tsConfigPath, [
/* mapped paths to share */
]);
], workspaceRootPath);
module.exports = {
output: {
Expand Down Expand Up @@ -50,10 +63,23 @@ exports[`app --mfe should add a remote application and add it to a specified hos
const mf = require(\\"@angular-architects/module-federation/webpack\\");
const path = require(\\"path\\");
/**
* We use the NX_TSCONFIG_PATH environment variable when using the @nrwl/angular:webpack-browser
* builder as it will generate a temporary tsconfig file which contains any required remappings of
* shared libraries.
* A remapping will occur when a library is buildable, as webpack needs to know the location of the
* built files for the buildable library.
* This NX_TSCONFIG_PATH environment variable is set by the @nrwl/angular:webpack-browser and it contains
* the location of the generated temporary tsconfig file.
*/
const tsConfigPath = process.env.NX_TSCONFIG_PATH ?? path.join(__dirname, '../../tsconfig.base.json');
const workspaceRootPath = path.join(__dirname, '../../');
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(path.join(__dirname, \\"../../tsconfig.base.json\\"), [
sharedMappings.register(tsConfigPath, [
/* mapped paths to share */
]);
], workspaceRootPath);
module.exports = {
output: {
Expand Down Expand Up @@ -94,10 +120,23 @@ exports[`app --mfe should generate a Module Federation correctly for a each app
const mf = require(\\"@angular-architects/module-federation/webpack\\");
const path = require(\\"path\\");
/**
* We use the NX_TSCONFIG_PATH environment variable when using the @nrwl/angular:webpack-browser
* builder as it will generate a temporary tsconfig file which contains any required remappings of
* shared libraries.
* A remapping will occur when a library is buildable, as webpack needs to know the location of the
* built files for the buildable library.
* This NX_TSCONFIG_PATH environment variable is set by the @nrwl/angular:webpack-browser and it contains
* the location of the generated temporary tsconfig file.
*/
const tsConfigPath = process.env.NX_TSCONFIG_PATH ?? path.join(__dirname, '../../tsconfig.base.json');
const workspaceRootPath = path.join(__dirname, '../../');
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(path.join(__dirname, \\"../../tsconfig.base.json\\"), [
sharedMappings.register(tsConfigPath, [
/* mapped paths to share */
]);
], workspaceRootPath);
module.exports = {
output: {
Expand Down Expand Up @@ -137,10 +176,23 @@ exports[`app --mfe should generate a Module Federation correctly for a each app
const mf = require(\\"@angular-architects/module-federation/webpack\\");
const path = require(\\"path\\");
/**
* We use the NX_TSCONFIG_PATH environment variable when using the @nrwl/angular:webpack-browser
* builder as it will generate a temporary tsconfig file which contains any required remappings of
* shared libraries.
* A remapping will occur when a library is buildable, as webpack needs to know the location of the
* built files for the buildable library.
* This NX_TSCONFIG_PATH environment variable is set by the @nrwl/angular:webpack-browser and it contains
* the location of the generated temporary tsconfig file.
*/
const tsConfigPath = process.env.NX_TSCONFIG_PATH ?? path.join(__dirname, '../../tsconfig.base.json');
const workspaceRootPath = path.join(__dirname, '../../');
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(path.join(__dirname, \\"../../tsconfig.base.json\\"), [
sharedMappings.register(tsConfigPath, [
/* mapped paths to share */
]);
], workspaceRootPath);
module.exports = {
output: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,23 @@ exports[`Init MFE should add a remote application and add it to a specified host
const mf = require(\\"@angular-architects/module-federation/webpack\\");
const path = require(\\"path\\");
/**
* We use the NX_TSCONFIG_PATH environment variable when using the @nrwl/angular:webpack-browser
* builder as it will generate a temporary tsconfig file which contains any required remappings of
* shared libraries.
* A remapping will occur when a library is buildable, as webpack needs to know the location of the
* built files for the buildable library.
* This NX_TSCONFIG_PATH environment variable is set by the @nrwl/angular:webpack-browser and it contains
* the location of the generated temporary tsconfig file.
*/
const tsConfigPath = process.env.NX_TSCONFIG_PATH ?? path.join(__dirname, '../../tsconfig.base.json');
const workspaceRootPath = path.join(__dirname, '../../');
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(path.join(__dirname, \\"../../tsconfig.base.json\\"), [
sharedMappings.register(tsConfigPath, [
/* mapped paths to share */
]);
], workspaceRootPath);
module.exports = {
output: {
Expand Down Expand Up @@ -78,10 +91,23 @@ exports[`Init MFE should add a remote application and add it to a specified host
const mf = require(\\"@angular-architects/module-federation/webpack\\");
const path = require(\\"path\\");
/**
* We use the NX_TSCONFIG_PATH environment variable when using the @nrwl/angular:webpack-browser
* builder as it will generate a temporary tsconfig file which contains any required remappings of
* shared libraries.
* A remapping will occur when a library is buildable, as webpack needs to know the location of the
* built files for the buildable library.
* This NX_TSCONFIG_PATH environment variable is set by the @nrwl/angular:webpack-browser and it contains
* the location of the generated temporary tsconfig file.
*/
const tsConfigPath = process.env.NX_TSCONFIG_PATH ?? path.join(__dirname, '../../tsconfig.base.json');
const workspaceRootPath = path.join(__dirname, '../../');
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(path.join(__dirname, \\"../../tsconfig.base.json\\"), [
sharedMappings.register(tsConfigPath, [
/* mapped paths to share */
]);
], workspaceRootPath);
module.exports = {
output: {
Expand Down Expand Up @@ -122,10 +148,23 @@ exports[`Init MFE should create webpack configs correctly 1`] = `
const mf = require(\\"@angular-architects/module-federation/webpack\\");
const path = require(\\"path\\");
/**
* We use the NX_TSCONFIG_PATH environment variable when using the @nrwl/angular:webpack-browser
* builder as it will generate a temporary tsconfig file which contains any required remappings of
* shared libraries.
* A remapping will occur when a library is buildable, as webpack needs to know the location of the
* built files for the buildable library.
* This NX_TSCONFIG_PATH environment variable is set by the @nrwl/angular:webpack-browser and it contains
* the location of the generated temporary tsconfig file.
*/
const tsConfigPath = process.env.NX_TSCONFIG_PATH ?? path.join(__dirname, '../../tsconfig.base.json');
const workspaceRootPath = path.join(__dirname, '../../');
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(path.join(__dirname, \\"../../tsconfig.base.json\\"), [
sharedMappings.register(tsConfigPath, [
/* mapped paths to share */
]);
], workspaceRootPath);
module.exports = {
output: {
Expand Down Expand Up @@ -165,10 +204,23 @@ exports[`Init MFE should create webpack configs correctly 2`] = `
const mf = require(\\"@angular-architects/module-federation/webpack\\");
const path = require(\\"path\\");
/**
* We use the NX_TSCONFIG_PATH environment variable when using the @nrwl/angular:webpack-browser
* builder as it will generate a temporary tsconfig file which contains any required remappings of
* shared libraries.
* A remapping will occur when a library is buildable, as webpack needs to know the location of the
* built files for the buildable library.
* This NX_TSCONFIG_PATH environment variable is set by the @nrwl/angular:webpack-browser and it contains
* the location of the generated temporary tsconfig file.
*/
const tsConfigPath = process.env.NX_TSCONFIG_PATH ?? path.join(__dirname, '../../tsconfig.base.json');
const workspaceRootPath = path.join(__dirname, '../../');
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(path.join(__dirname, \\"../../tsconfig.base.json\\"), [
sharedMappings.register(tsConfigPath, [
/* mapped paths to share */
]);
], workspaceRootPath);
module.exports = {
output: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@ const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPl
const mf = require("@angular-architects/module-federation/webpack");
const path = require("path");


/**
* We use the NX_TSCONFIG_PATH environment variable when using the @nrwl/angular:webpack-browser
* builder as it will generate a temporary tsconfig file which contains any required remappings of
* shared libraries.
* A remapping will occur when a library is buildable, as webpack needs to know the location of the
* built files for the buildable library.
* This NX_TSCONFIG_PATH environment variable is set by the @nrwl/angular:webpack-browser and it contains
* the location of the generated temporary tsconfig file.
*/
const tsConfigPath = process.env.NX_TSCONFIG_PATH ?? path.join(__dirname, '<%= offsetFromRoot %>tsconfig.base.json');

const workspaceRootPath = path.join(__dirname, '<%= offsetFromRoot %>');
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(path.join(__dirname, "../../tsconfig.base.json"), [
sharedMappings.register(tsConfigPath, [
/* mapped paths to share */
]);
], workspaceRootPath);

module.exports = {
output: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { Tree } from '@nrwl/devkit';
import type { Schema } from '../schema';
import { generateFiles, joinPathFragments, logger } from '@nrwl/devkit';
import {
generateFiles,
joinPathFragments,
logger,
offsetFromRoot,
} from '@nrwl/devkit';

const SHARED_SINGLETON_LIBRARIES = [
'@angular/core',
Expand Down Expand Up @@ -35,6 +40,7 @@ export function generateWebpackConfig(
remotes: remotesWithPorts ?? [],
sourceRoot: appRoot,
sharedLibraries: SHARED_SINGLETON_LIBRARIES,
offsetFromRoot: offsetFromRoot(appRoot),
}
);
}
2 changes: 1 addition & 1 deletion packages/angular/src/generators/setup-mfe/setup-mfe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function setupMfe(host: Tree, options: Schema) {
// add package to install
const installPackages = addDependenciesToPackageJson(
host,
{ '@angular-architects/module-federation': '^12.2.0' },
{ '@angular-architects/module-federation': '^12.5.3' },
{}
);

Expand Down

0 comments on commit 484b254

Please sign in to comment.