-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): exit with code 1 when remix build fails #1822
Conversation
accidentally closed this by force pushing to my remix dev branch #1527 |
packages/remix-dev/cli/commands.ts
Outdated
@@ -61,7 +61,11 @@ export async function build( | |||
|
|||
let start = Date.now(); | |||
let config = await readConfig(remixRoot); | |||
await compiler.build(config, { mode: mode, sourcemap }); | |||
try { | |||
await compiler.build(config, { mode: mode, sourcemap }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like we intended to have this code pass onBuildFailure
, and then we can process.exit(1)
there instead of a try catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, also we use a defaultOnBuildFailure handler, I think the process.exit(1) needs to go there.
@mjackson can you help us understand the intent here? Right now it just does console.error
in the default build failure handler, seems like that's also the spot we'd want to process.exit(1)
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the default on build error is a great place to exit with an error code.
Would you like me to change?
When builds fail remix does not exit with an error code which makes it hard to catch build failures in CI environments Example: ```sh ❯ yarn create remix ❯ cd ./my-remix-app ❯ echo -e "import doesntExists from \"doesnt-exists\";\ndoesntExists();\n$(cat app/routes/index.tsx)" > app/routes/index.tsx ❯ npx remix build npx remix build Building Remix app in production mode... The path "doesnt-exists" is imported in app/routes/index.tsx but doesnt-exists is not listed in your package.json dependencies. Did you forget to install it? > node_modules/@web-std/file/tsconfig.json:6:24: warning: Non-relative path "packages/file/src/lib.js" is not allowed when "baseUrl" is not set (did you forget a leading "./"?) 6 │ "@web-std/file": ["packages/file/src/lib.js"] ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~ > app/routes/index.tsx:1:25: error: Could not resolve "doesnt-exists" (mark it as external to exclude it from the bundle) 1 │ import doesntExists from "doesnt-exists"; ╵ ~~~~~~~~~~~~~~~ Build failed with 1 error: app/routes/index.tsx:1:25: error: Could not resolve "doesnt-exists" (mark it as external to exclude it from the bundle) Built in 571ms ❯ echo $? 0 ```
7ba7d5b
to
af2c821
Compare
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
@ryanflorence we actually got it wrong. remix/packages/remix-dev/cli.ts Line 66 in f1eef65
The only problem with it, is that the Now there's another thing we got wrong, the default build failure handler is also used in watch, if it would Instead, I've created a different |
6464c2b
to
4dcafab
Compare
@ryanflorence @mjackson can we get this merged? |
@mjackson @kentcdodds @ryanflorence this has been ready for a while, can we get this merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. I'll ping Michael and Ryan about it.
When builds fail remix does not exit with an error code which makes it hard to catch build failures in CI environments
remix/packages/remix-dev/compiler.ts
Lines 307 to 314 in 197f570
Example: