From e7e2ecabe40d221ee187a72c3440f193cfb85e2d Mon Sep 17 00:00:00 2001 From: suhaotian Date: Tue, 2 Jan 2024 12:11:55 +1100 Subject: [PATCH] `nest-webpack.js` monorepoRoot use `config` from `tsdk.config.js` --- packages/tsdk/src/nest-webpack.ts | 4 +++- packages/tsdk/src/run-nest-command.ts | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/tsdk/src/nest-webpack.ts b/packages/tsdk/src/nest-webpack.ts index 792f559..e802e4e 100644 --- a/packages/tsdk/src/nest-webpack.ts +++ b/packages/tsdk/src/nest-webpack.ts @@ -7,6 +7,8 @@ import nodeExternals from 'webpack-node-externals'; import { getNpmCommand } from './get-pkg-manager'; +export const tsdkConfigFilePath = path.join(process.cwd(), 'tsdk.config.js'); + const defaultMainName = 'default'; const distProjects = 'dist-projects'; @@ -191,7 +193,7 @@ async function getNestProjectsConfig() { const cwd = process.cwd(); const nestjsFilepath = path.resolve( cwd, - process.env.MONOREPO_ROOT || './', + require(tsdkConfigFilePath).monorepoRoot || './', 'node_modules/@nestjs/cli/package.json' ); const nestjsFilepathExists = await fsExtra.pathExists(nestjsFilepath); diff --git a/packages/tsdk/src/run-nest-command.ts b/packages/tsdk/src/run-nest-command.ts index 703d517..3b2adb8 100644 --- a/packages/tsdk/src/run-nest-command.ts +++ b/packages/tsdk/src/run-nest-command.ts @@ -11,15 +11,18 @@ export async function runNestCommand() { if (command === 'build') { const cwd = process.cwd(); const webpackDistFile = path.resolve(cwd, 'node_modules', 'nest-webpack.js'); - const pkgManagerDistFile = path.resolve(cwd, 'node_modules', 'get-pkg-manager.js'); - await Promise.all([ - fsExtra.copy(path.resolve(__dirname, '../lib/nest-webpack.js'), webpackDistFile, { - overwrite: true, - }), - fsExtra.copy(path.resolve(__dirname, '../lib/get-pkg-manager.js'), pkgManagerDistFile, { - overwrite: true, - }), - ]); + const copyFiles = ['nest-webpack.js', 'get-pkg-manager.js']; + await Promise.all( + copyFiles.map((filename) => { + return fsExtra.copy( + path.resolve(__dirname, `../lib/${filename}`), + path.resolve(cwd, 'node_modules', filename), + { + overwrite: true, + } + ); + }) + ); const names = process.argv.filter((i, index) => index > idx + 1);