Skip to content

Commit

Permalink
feat(node): Support global file replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
imaustink committed Nov 20, 2020
1 parent 58e99b0 commit cbf0411
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 11 deletions.
Empty file added .yarnrc
Empty file.
1 change: 0 additions & 1 deletion .yarnrc.yml

This file was deleted.

11 changes: 7 additions & 4 deletions packages/node/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@nrwl/node",
"version": "0.0.1",
"name": "@bafsllc/node",
"version": "0.0.3",
"description": "Node Plugin for Nx",
"repository": {
"type": "git",
"url": "git+https://github.com/nrwl/nx.git"
"url": "git+https://github.com/bafsllc/nx.git"
},
"keywords": [
"Monorepo",
Expand All @@ -19,7 +19,7 @@
"author": "Victor Savkin",
"license": "MIT",
"bugs": {
"url": "https://github.com/nrwl/nx/issues"
"url": "https://github.com/bafsllc/nx/issues"
},
"homepage": "https://nx.dev",
"schematics": "./collection.json",
Expand Down Expand Up @@ -51,5 +51,8 @@
"webpack-merge": "4.2.1",
"webpack-dev-server": "3.11.0",
"webpack-node-externals": "1.7.2"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
}
}
45 changes: 41 additions & 4 deletions packages/node/src/builders/build/build.impl.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { BuilderContext, createBuilder } from '@angular-devkit/architect';
import { JsonObject, workspaces } from '@angular-devkit/core';
import { runWebpack, BuildResult } from '@angular-devkit/build-webpack';

import { Observable, from } from 'rxjs';
import { join, resolve } from 'path';
import { map, concatMap } from 'rxjs/operators';
import { getNodeWebpackConfig } from '../../utils/node.config';
import { OUT_FILENAME } from '../../utils/config';
import { BuildBuilderOptions } from '../../utils/types';
import { normalizeBuildOptions } from '../../utils/normalize';
import {
normalizeBuildOptions,
normalizeFileReplacements,
} from '../../utils/normalize';
import { NodeJsSyncHost } from '@angular-devkit/core/node';
import { createProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import {
createProjectGraph,
ProjectGraph,
} from '@nrwl/workspace/src/core/project-graph';
import {
calculateProjectDependencies,
createTmpTsConfig,
Expand All @@ -37,6 +42,20 @@ function run(
options: JsonObject & BuildNodeBuilderOptions,
context: BuilderContext
): Observable<NodeBuildEvent> {
const { configuration } = context.target;

if (options.useGlobalFileReplacements) {
const projGraph = createProjectGraph();
const fileReplacements = resolveAllProjectFileReplacements(
projGraph,
configuration
);
options.fileReplacements = normalizeFileReplacements(
context.workspaceRoot,
fileReplacements
);
}

if (!options.buildLibsFromSource) {
const projGraph = createProjectGraph();
const { target, dependencies } = calculateProjectDependencies(
Expand All @@ -60,7 +79,7 @@ function run(
if (options.webpackConfig) {
config = require(options.webpackConfig)(config, {
options,
configuration: context.target.configuration,
configuration,
});
}
return config;
Expand Down Expand Up @@ -99,3 +118,21 @@ async function getSourceRoot(context: BuilderContext) {
throw new Error(message);
}
}

export function resolveAllProjectFileReplacements(
projGraph: ProjectGraph,
configuration: string
) {
const projects = Object.values(projGraph.nodes);
const fileReplacements = projects.reduce((allReplacements, project) => {
const projectReplacements =
project?.data?.architect?.build?.configurations?.[configuration]
?.fileReplacements;
if (projectReplacements) {
allReplacements.push(...projectReplacements);
}
return allReplacements;
}, []);

return fileReplacements;
}
2 changes: 1 addition & 1 deletion packages/node/src/utils/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function normalizeAssets(
});
}

function normalizeFileReplacements(
export function normalizeFileReplacements(
root: string,
fileReplacements: FileReplacement[]
): FileReplacement[] {
Expand Down
3 changes: 3 additions & 0 deletions packages/workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,8 @@
"inquirer": "^6.3.1",
"resolve": "1.17.0",
"tslib": "^2.0.0"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
}
}
2 changes: 1 addition & 1 deletion workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
}
},
"lint": {
"builder": "@nrwl/linter:eslint",
"builder": "@bafsllc/linter:eslint",
"options": {
"lintFilePatterns": [
"packages/nx/**/*.ts",
Expand Down

0 comments on commit cbf0411

Please sign in to comment.