From 1796a55803e81d8824e54ffa20fc3fee875c0b62 Mon Sep 17 00:00:00 2001 From: Ben Surgison Date: Fri, 18 Nov 2022 15:49:24 +0000 Subject: [PATCH] Retain original package name property --- bin/cli | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/cli b/bin/cli index bb3f999e2a..14eb301b74 100755 --- a/bin/cli +++ b/bin/cli @@ -43,8 +43,8 @@ const packageJson = { } } -async function updatePackageJson (packageJsonPath) { - let newPackageJson = Object.assign({}, packageJson) +async function updatePackageJson (packageJsonPath, data = {}) { + let newPackageJson = Object.assign(data, packageJson) newPackageJson = Object.assign(newPackageJson, await fs.readJson(packageJsonPath)) await fs.writeJson(packageJsonPath, newPackageJson, packageJsonFormat) } @@ -236,8 +236,13 @@ function warnIfNpmStart (argv, env) { const projectDirectory = process.argv[4] + // extract the name from the original package.json + const pkgJson = await fs.readJson(path.join(projectDirectory, 'package.json')) + // if the name doesn't exist, use the name of the project directory + const { name = projectDirectory.split('/').pop() } = pkgJson || {} + await Promise.all([ - updatePackageJson(path.join(projectDirectory, 'package.json')), + updatePackageJson(path.join(projectDirectory, 'package.json'), { name }), fs.writeFile(path.join(projectDirectory, '.npmrc'), npmrc, 'utf8'), fs.access(path.join(projectDirectory, '.gitignore')) .catch(() => fs.writeFile(path.join(projectDirectory, '.gitignore'), gitignore, 'utf8'))