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 copyUntypedFiles.mjs
.tsbuildinfo .tsbuildinfo
__tests__ __tests__
node_modules
# Files in the templates need to stay # Files in the templates need to stay
/tsconfig* /tsconfig*

View file

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