Skip to content

Commit

Permalink
feat(cli): 新增npm install 参数配置
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen authored and jia000 committed Dec 9, 2024
1 parent e6909dc commit 3cae4fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface NpmConfig {
autoInstall?: boolean;
/** 安装组件后,npm默认会将依赖写入package.json中,将该值设置为true,则不会写入,默认为true */
keepPackageJsonClean?: boolean;
installArgs?: string;
}

export interface ModuleMainFilePath {
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/utils/resolveAppPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const getRelativePath = (str: string, base: string) => (path.isAbsolute(str) ? p

const npmInstall = function (dependencies: Record<string, string>, cwd: string, npmConfig: NpmConfig = {}) {
try {
const { client = 'npm', registry } = npmConfig;
const { client = 'npm', registry, installArgs = '' } = npmConfig;
const install = {
npm: 'install',
yarn: 'add',
Expand All @@ -49,7 +49,9 @@ const npmInstall = function (dependencies: Record<string, string>, cwd: string,
.map(([name, version]) => (version ? `${name}@${version}` : name))
.join(' ');

const command = `${client} ${install} ${packages}${registry ? ` --registry ${registry}` : ''}`;
const installArgsString = `${installArgs ? ` ${installArgs}` : ''}`;
const registryString = `${registry ? ` --registry ${registry}` : ''}`;
const command = `${client} ${install}${installArgsString} ${packages}${registryString}`;

execInfo(cwd);
execInfo(command);
Expand Down

0 comments on commit 3cae4fb

Please sign in to comment.