Skip to content

Commit

Permalink
fix(node): support for typescript webpack plugins (nrwl#8171)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Dec 16, 2021
1 parent 1172fb6 commit 5b95b4c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"webpack": "^5.58.1",
"webpack-merge": "^5.8.0",
"webpack-node-externals": "^3.0.0",
"rxjs-for-await": "0.0.2"
"rxjs-for-await": "0.0.2",
"ts-node": "~9.1.1"
}
}
18 changes: 17 additions & 1 deletion packages/node/src/executors/build/build.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ import {

import { map, tap } from 'rxjs/operators';
import { eachValueFrom } from 'rxjs-for-await';
import { resolve } from 'path';
import { join, resolve } from 'path';
import { register } from 'ts-node';

import { getNodeWebpackConfig } from '../../utils/node.config';
import { BuildNodeBuilderOptions } from '../../utils/types';
import { normalizeBuildOptions } from '../../utils/normalize';
import { generatePackageJson } from '../../utils/generate-package-json';
import { runWebpack } from '../../utils/run-webpack';

import { existsSync } from 'fs';
import { appRootPath } from '@nrwl/tao/src/utils/app-root';

export type NodeBuildEvent = {
outfile: string;
success: boolean;
Expand All @@ -43,6 +47,11 @@ export async function* buildExecutor(
sourceRoot,
root
);

if (options.webpackConfig.some((x) => x.endsWith('.ts'))) {
registerTsNode();
}

const projGraph = readCachedProjectGraph();
if (!options.buildLibsFromSource) {
const { target, dependencies } = calculateProjectDependencies(
Expand Down Expand Up @@ -100,4 +109,11 @@ export async function* buildExecutor(
);
}

function registerTsNode() {
const rootTsConfig = join(appRootPath, 'tsconfig.base.json');
register({
...(existsSync(rootTsConfig) ? { project: rootTsConfig } : null),
});
}

export default buildExecutor;

0 comments on commit 5b95b4c

Please sign in to comment.