From 2bdbf0cc5155d12bf6fa8c9cf9303efe5da110bd Mon Sep 17 00:00:00 2001 From: Shigma Date: Thu, 18 Jul 2024 15:01:14 +0800 Subject: [PATCH] feat(create): write `packageManager` --- packages/create/package.json | 2 +- packages/create/src/index.ts | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/create/package.json b/packages/create/package.json index f46692f..1ad8df6 100644 --- a/packages/create/package.json +++ b/packages/create/package.json @@ -1,7 +1,7 @@ { "name": "create-cordis", "description": "Setup a Cordis application", - "version": "0.2.1", + "version": "0.2.2", "type": "module", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/packages/create/src/index.ts b/packages/create/src/index.ts index 2c2e559..f4bb9c2 100644 --- a/packages/create/src/index.ts +++ b/packages/create/src/index.ts @@ -121,12 +121,14 @@ class Scaffold { const targetFile = join(targetDir, `yarn-${version}.cjs`) await mkdir(targetDir, { recursive: true }) await copyFile(targetFile, cacheFile) + return version } async scaffold() { - console.log(kleur.dim(' Scaffolding project in ') + project + kleur.dim(' ...')) - this.registry = (await getRegistry()).replace(/\/$/, '') + console.log(kleur.dim(' Registry server: ') + this.registry) + + console.log(kleur.dim(' Scaffolding project in ') + project + kleur.dim(' ...')) const template = argv.template || this.options.template const resp1 = await fetch(`${this.registry}/${template}`) @@ -149,17 +151,17 @@ class Scaffold { stream.on('error', reject) }) - await Promise.all([ - this.downloadYarn(), - this.writePackageJson(), - ]) + const yarnVersion = await this.downloadYarn() + const packageManager = yarnVersion ? `yarn@${yarnVersion}` : undefined + await this.writePackageJson(packageManager) console.log(kleur.green(' Done.\n')) } - async writePackageJson() { + async writePackageJson(packageManager?: string) { const filename = join(rootDir, 'package.json') const meta = JSON.parse(await readFile(filename, 'utf8')) meta.name = project + meta.packageManager = packageManager if (argv.prod) { // https://github.com/koishijs/koishi/issues/994 // Do not use `NODE_ENV` or `--production` flag.