feat(nx): detect package manager in workspace-schematic
workspace-schematic now tries to detect the right package manager using Angular CLI config and can identify pnpm from lock file.
This commit is contained in:
parent
26903c04e2
commit
9e15f4a7f5
@ -17,11 +17,12 @@ import {
|
|||||||
import * as appRoot from 'app-root-path';
|
import * as appRoot from 'app-root-path';
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { readFileSync, statSync, writeFileSync } from 'fs';
|
import { readFileSync, writeFileSync } from 'fs';
|
||||||
import { copySync, removeSync } from 'fs-extra';
|
import { copySync, removeSync } from 'fs-extra';
|
||||||
import * as inquirer from 'inquirer';
|
import * as inquirer from 'inquirer';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as yargsParser from 'yargs-parser';
|
import * as yargsParser from 'yargs-parser';
|
||||||
|
import { fileExists } from '../utils/fileutils';
|
||||||
|
|
||||||
const rootDirectory = appRoot.path;
|
const rootDirectory = appRoot.path;
|
||||||
|
|
||||||
@ -115,12 +116,29 @@ function createWorkflow(dryRun: boolean) {
|
|||||||
const root = normalize(rootDirectory);
|
const root = normalize(rootDirectory);
|
||||||
const host = new virtualFs.ScopedHost(new NodeJsSyncHost(), root);
|
const host = new virtualFs.ScopedHost(new NodeJsSyncHost(), root);
|
||||||
return new NodeWorkflow(host, {
|
return new NodeWorkflow(host, {
|
||||||
packageManager: fileExists('yarn.lock') ? 'yarn' : 'npm',
|
packageManager: detectPackageManager(),
|
||||||
root,
|
root,
|
||||||
dryRun
|
dryRun
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function detectPackageManager(): string {
|
||||||
|
try {
|
||||||
|
const packageManager = execSync(`ng config cli.packageManager`, {
|
||||||
|
stdio: ['ignore', 'pipe', 'ignore']
|
||||||
|
})
|
||||||
|
.toString()
|
||||||
|
.trim();
|
||||||
|
return packageManager;
|
||||||
|
} catch (e) {
|
||||||
|
return fileExists('yarn.lock')
|
||||||
|
? 'yarn'
|
||||||
|
: fileExists('pnpm-lock.yaml')
|
||||||
|
? 'pnpm'
|
||||||
|
: 'npm';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function listSchematics(collectionName: string, logger: logging.Logger) {
|
function listSchematics(collectionName: string, logger: logging.Logger) {
|
||||||
try {
|
try {
|
||||||
const engineHost = new NodeModulesEngineHost();
|
const engineHost = new NodeModulesEngineHost();
|
||||||
@ -276,11 +294,3 @@ function exists(file: string): boolean {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fileExists(filePath: string): boolean {
|
|
||||||
try {
|
|
||||||
return statSync(filePath).isFile();
|
|
||||||
} catch (err) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user