Skip to content

Commit

Permalink
fix(cli): packages设置npm包初始化报错
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Aug 29, 2023
1 parent 131ec6f commit 0865cf4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/cli/src/utils/resolveAppPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ const npmInstall = function (dependencies: Record<string, string>, cwd: string,
}[client];

const packages = Object.entries(dependencies)
.map(([name, version]) => `${name}@${version}`)
.map(([name, version]) => (version ? `${name}@${version}` : name))
.join(' ');

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

execInfo(cwd);
execInfo(command);
Expand Down Expand Up @@ -395,6 +395,14 @@ const splitNameVersion = function (str: string) {
if (typeof str !== 'string') {
return {};
}

if (fs.existsSync(str)) {
return {
name: str,
version: '',
};
}

const packStr = String.prototype.trim.call(str);
const ret = packStr.match(/((^|@).+)@(.+)/);
let name = packStr;
Expand Down Expand Up @@ -426,7 +434,7 @@ const setPackages = (packages: ModuleMainFilePath, app: App, packagePath: string

if (!moduleName) throw Error('packages中包含非法配置');

if (fs.lstatSync(moduleName).isDirectory()) {
if (isDirectory(moduleName)) {
if (!fs.existsSync(path.join(moduleName, './package.json'))) {
['index.js', 'index.ts'].forEach((index) => {
const indexFile = path.join(moduleName!, `./${index}`);
Expand Down

0 comments on commit 0865cf4

Please sign in to comment.