Skip to content

Commit

Permalink
Do not print execa stack traces when processes error (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebinsua authored Sep 21, 2020
1 parent 9503d2c commit 3616010
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 28 deletions.
11 changes: 11 additions & 0 deletions .changeset/smart-points-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'create-modular-react-app': patch
'modular-scripts': patch
---

Do not print `execa` stack traces when processes error.

Ensure that the `build/` directory does not get added into a Git repository.

Let the underlying commands handle any `--help` argument instead of `modular`'s
own argument parser.
14 changes: 7 additions & 7 deletions e2e-tests/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ describe('creating a new project', () => {
it('sets up the repo with the directory structure', () => {
expect(tree(repoDirectory)).toMatchInlineSnapshot(`
"test-repo
├─ .eslintignore #3wv9rw
├─ .gitignore #3wv9rw
├─ .eslintignore #1ugsijf
├─ .gitignore #1ugsijf
├─ README.md #1nksyzj
├─ package.json #3h17sm
├─ package.json #1a8xxo
├─ packages
│ ├─ README.md #14bthrh
│ ├─ app
Expand Down Expand Up @@ -322,7 +322,7 @@ describe('creating a new project', () => {
Object {
"dependencies": Object {
"eslint-config-modular-app": "^0.1.2",
"modular-scripts": "^0.1.3",
"modular-scripts": "^0.1.4",
"prettier": "^2.1.2",
},
"eslintConfig": Object {
Expand Down Expand Up @@ -462,10 +462,10 @@ describe('creating a new project', () => {
it('creates a widget, a package, and an app', async () => {
expect(tree(repoDirectory)).toMatchInlineSnapshot(`
"test-repo
├─ .eslintignore #3wv9rw
├─ .gitignore #3wv9rw
├─ .eslintignore #1ugsijf
├─ .gitignore #1ugsijf
├─ README.md #1nksyzj
├─ package.json #3h17sm
├─ package.json #1a8xxo
├─ packages
│ ├─ README.md #14bthrh
│ ├─ app
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/tree/__tests__/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ test('it can serialise a folder', () => {
"create-modular-react-app
├─ .npmignore #1rstiru
├─ CHANGELOG.md #1k5lnr5
├─ package.json #1l7jkzs
├─ package.json #qef6lj
├─ src
│ └─ cli.ts #78me31
│ └─ cli.ts #cd0fl6
└─ template
├─ README.md #1nksyzj
├─ gitignore #3wv9rw
├─ gitignore #1ugsijf
├─ packages
│ └─ README.md #14bthrh
├─ shared
Expand Down
3 changes: 2 additions & 1 deletion packages/create-modular-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
"chalk": "^4.1.0",
"execa": "^4.0.2",
"fs-extra": "^9.0.1",
"yargs": "^15.4.1"
"mri": "^1.1.6"
},
"devDependencies": {
"@schemastore/package": "^0.0.6",
"@types/fs-extra": "^5.0.2",
"@types/mri": "^1.1.0",
"@types/node": "*",
"rimraf": "^3.0.2"
}
Expand Down
4 changes: 3 additions & 1 deletion packages/create-modular-react-app/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import execa from 'execa';
import * as fs from 'fs-extra';
import * as path from 'path';
import chalk from 'chalk';
import { argv } from 'yargs';
import mri from 'mri';

// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
Expand Down Expand Up @@ -48,6 +48,8 @@ function createModularApp() {
process.exit(1);
}

const argv = mri(process.argv.slice(2));

const [name] = argv._;
if (!name) {
console.error(
Expand Down
2 changes: 1 addition & 1 deletion packages/create-modular-react-app/template/gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ node_modules
/coverage

# production
/app/build
/packages/*/build

# misc
.DS_Store
Expand Down
3 changes: 2 additions & 1 deletion packages/modular-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
"find-up": "^4.1.0",
"fs-extra": "^9.0.1",
"globby": "^11.0.1",
"mri": "^1.1.6",
"react-scripts": "^3.4.1",
"resolve-as-bin": "^2.1.0",
"yargs": "^15.4.1",
"rimraf": "^3.0.2",
"inquirer": "^7.3.3"
},
"devDependencies": {
"@types/find-up": "^4.0.0",
"@types/fs-extra": "^5.0.2",
"@types/mri": "^1.1.0",
"@types/node": "*",
"@types/inquirer": "^7.3.1",
"@schemastore/package": "^0.0.6"
Expand Down
41 changes: 28 additions & 13 deletions packages/modular-scripts/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { argv } from 'yargs';
import mri from 'mri';
import execa from 'execa';
import * as fs from 'fs-extra';
import * as path from 'path';
Expand Down Expand Up @@ -87,19 +87,34 @@ function run() {
process.exit(1);
}

const argv = mri(process.argv.slice(2));

const command = argv._[0];
switch (command) {
case 'add':
return addPackage(argv._[1], argv.unstableType as string | void);
case 'test':
return test(process.argv.slice(3));
case 'start':
return start(argv._[1]);
case 'build':
return build(argv._[1]);
default:
console.log(help);
process.exit(1);
try {
switch (command) {
case 'add':
return addPackage(argv._[1], argv['unstable-type'] as string | void);
case 'test':
return test(process.argv.slice(3));
case 'start':
return start(argv._[1]);
case 'build':
return build(argv._[1]);
default:
console.log(help);
process.exit(1);
}
} catch (err) {
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
// When there is an `execa` Error with an `.exitCode` the
// error message will already have been printed out by the
// process so we only need to bail with the exit code.
if (err.exitCode !== undefined) {
process.exit(err.exitCode);
}
/* eslint-enable @typescript-eslint/no-unsafe-member-access */

throw err;
}
}

Expand Down
12 changes: 11 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2516,6 +2516,11 @@
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==

"@types/mri@^1.1.0":
version "1.1.0"
resolved "https://registry.npmjs.org/@types/mri/-/mri-1.1.0.tgz#66555e4d797713789ea0fefdae0898d8170bf5af"
integrity sha512-fMl88ZoZXOB7VKazJ6wUMpZc9QIn+jcigSFRf2K/rrw4DcXn+/uGxlWX8DDlcE7JkwgIZ7BDH+JgxZPlc/Ap3g==

"@types/node@*":
version "14.6.3"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.6.3.tgz#cc4f979548ca4d8e7b90bc0180052ab99ee64224"
Expand Down Expand Up @@ -10964,6 +10969,11 @@ move-concurrently@^1.0.1:
rimraf "^2.5.4"
run-queue "^1.0.3"

mri@^1.1.6:
version "1.1.6"
resolved "https://registry.npmjs.org/mri/-/mri-1.1.6.tgz#49952e1044db21dbf90f6cd92bc9c9a777d415a6"
integrity sha512-oi1b3MfbyGa7FJMP9GmLTttni5JoICpYBRlq+x5V16fZbLsnL9N3wFqqIm/nIG43FjUFkFh9Epzp/kzUGUnJxQ==

ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
Expand Down Expand Up @@ -16799,7 +16809,7 @@ yargs@^13.3.0, yargs@^13.3.2:
y18n "^4.0.0"
yargs-parser "^13.1.2"

yargs@^15.1.0, yargs@^15.3.1, yargs@^15.4.1:
yargs@^15.1.0, yargs@^15.3.1:
version "15.4.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.4.1.tgz#0d87a16de01aee9d8bec2bfbf74f67851730f4f8"
integrity sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==
Expand Down

0 comments on commit 3616010

Please sign in to comment.