Skip to content

Commit

Permalink
fix(nx): package manager detection in code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Aug 28, 2019
1 parent 74442e4 commit cfc1eaa
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/tao/src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ function createRecorder(record: any, logger: logging.Logger) {
};
}

function detectPackageManager(host: virtualFs.Host<any>): 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<fs.Stats>,
root: string,
Expand All @@ -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._;
Expand Down

0 comments on commit cfc1eaa

Please sign in to comment.