fix(init): cd to correct path when installing (#6468)

* [bug] ensure we use the correct cd path

* Update index.ts

* refactor

* add ignore

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
Gabriel Csapo 2022-01-25 18:01:11 -08:00 committed by GitHub
parent dd539dd23f
commit d73b4f8674
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 13 deletions

View file

@ -1,6 +1,7 @@
copyUntypedFiles.mjs
.tsbuildinfo
__tests__
node_modules
# Files in the templates need to stay
/tsconfig*

View file

@ -270,23 +270,18 @@ export default async function init(
const pkgManager = useYarn ? 'yarn' : 'npm';
// Display the most elegant way to cd.
const cdpath =
path.join(process.cwd(), name) === dest
? name
: path.relative(process.cwd(), name);
const cdpath = path.relative('.', dest);
if (!cliOptions.skipInstall) {
shell.cd(dest);
logger.info`Installing dependencies with name=${pkgManager}...`;
if (
shell.exec(
`cd "${name}" && ${useYarn ? 'yarn' : 'npm install --color always'}`,
{
shell.exec(useYarn ? 'yarn' : 'npm install --color always', {
env: {
...process.env,
// Force coloring the output, since the command is invoked by shelljs, which is not the interactive shell
...(supportsColor.stdout ? {FORCE_COLOR: '1'} : {}),
},
},
).code !== 0
}).code !== 0
) {
logger.error('Dependency installation failed.');
logger.info`The site directory has already been created, and you can retry by typing: