From cfc1eaa4740acd0b8d911286e18df1e8de22c5b7 Mon Sep 17 00:00:00 2001 From: victor savkin Date: Thu, 22 Aug 2019 19:35:14 -0400 Subject: [PATCH] fix(nx): package manager detection in code generation --- packages/tao/src/commands/generate.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/tao/src/commands/generate.ts b/packages/tao/src/commands/generate.ts index 31ec947e43ab0..77309d321de2a 100644 --- a/packages/tao/src/commands/generate.ts +++ b/packages/tao/src/commands/generate.ts @@ -139,6 +139,23 @@ function createRecorder(record: any, logger: logging.Logger) { }; } +function detectPackageManager(host: virtualFs.Host): string { + const hostTree = new HostTree(host); + if (hostTree.get('workspace.json')) { + const workspaceJson = JSON.parse( + hostTree.read('workspace.json')!.toString() + ); + if (workspaceJson.cli && workspaceJson.cli.packageManager) { + return workspaceJson.cli.packageManager; + } + } + return host.exists('yarn.lock' as any) + ? 'yarn' + : host.exists('pnpm-lock.yaml' as any) + ? 'pnpm' + : 'npm'; +} + function createWorkflow( fsHost: virtualFs.Host, root: string, @@ -147,7 +164,7 @@ function createWorkflow( const workflow = new NodeWorkflow(fsHost, { force: opts.force, dryRun: opts.dryRun, - packageManager: 'yarn', + packageManager: detectPackageManager(fsHost), root: normalize(root) }); const _params = opts.schematicOptions._;