Abort npm build script from node.js scriptHow do I remove a property from a JavaScript object?How do I pass command line arguments to a Node.js program?How to decide when to use Node.js?How to exit in Node.jsHow do I remove a particular element from an array in JavaScript?How can I update NodeJS and NPM to the next versions?Find the version of an installed npm packageWhat is the difference between Bower and npm?What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?What is the --save option for npm install?
Increase performance creating Mandelbrot set in python
Valid Badminton Score?
Go Pregnant or Go Home
How do I rename a LINUX host without needing to reboot for the rename to take effect?
Can criminal fraud exist without damages?
How can a jailer prevent the Forge Cleric's Artisan's Blessing from being used?
Do I need a multiple entry visa for a trip UK -> Sweden -> UK?
There is only s̶i̶x̶t̶y one place he can be
Print name if parameter passed to function
Why are on-board computers allowed to change controls without notifying the pilots?
Will it be accepted, if there is no ''Main Character" stereotype?
Is exact Kanji stroke length important?
How does it work when somebody invests in my business?
Finding all intervals that match predicate in vector
Coordinate position not precise
Cynical novel that describes an America ruled by the media, arms manufacturers, and ethnic figureheads
Is the destination of a commercial flight important for the pilot?
Why did Kant, Hegel, and Adorno leave some words and phrases in the Greek alphabet?
Is there a good way to store credentials outside of a password manager?
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
What would be the benefits of having both a state and local currencies?
when is out of tune ok?
Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?
What defines a dissertation?
Abort npm build script from node.js script
How do I remove a property from a JavaScript object?How do I pass command line arguments to a Node.js program?How to decide when to use Node.js?How to exit in Node.jsHow do I remove a particular element from an array in JavaScript?How can I update NodeJS and NPM to the next versions?Find the version of an installed npm packageWhat is the difference between Bower and npm?What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?What is the --save option for npm install?
I created a node
script which checks if my project contains lock
file or not. If it doesn't then I want to abort my npm
build. Any idea how to do that?
lock-check.js
const path = require('path');
const fs = require("fs");
const lockFiles = ["package-lock.json", "npm-shrinkwrap.json", "yarn.lock"];
let exists = 0;
function checkIfExists()
lockFiles.forEach(
(lf) =>
if (fs.existsSync(lf))
exists++;
);
return exists > 0;
package.json
...
"scripts":
"prestart": "node ./lock-check.js" // Abort the task
"start": "webpack-dev-server --config config/webpack.dev.js --hot --inline"
...
javascript node.js npm
add a comment |
I created a node
script which checks if my project contains lock
file or not. If it doesn't then I want to abort my npm
build. Any idea how to do that?
lock-check.js
const path = require('path');
const fs = require("fs");
const lockFiles = ["package-lock.json", "npm-shrinkwrap.json", "yarn.lock"];
let exists = 0;
function checkIfExists()
lockFiles.forEach(
(lf) =>
if (fs.existsSync(lf))
exists++;
);
return exists > 0;
package.json
...
"scripts":
"prestart": "node ./lock-check.js" // Abort the task
"start": "webpack-dev-server --config config/webpack.dev.js --hot --inline"
...
javascript node.js npm
to abort you can doprocess.exit(1)
with 1 or any non zero exit code to tell it was not completed successfully
– warl0ck
Mar 8 at 9:40
I suspect that would work. npm is a different process so it will resume execution.
– Neptune
Mar 8 at 9:41
it works fine in webpack configs i have been using it for some custom tests before building it. just exit code should be non-zero
– warl0ck
Mar 8 at 9:43
1
Yes you are right about Exit codes. If any step of the scripts exits with a non-zero exit code the whole process will terminate. See docs.npmjs.com/misc/scripts#exiting I just read that
– Neptune
Mar 8 at 9:46
It's working. Thanks
– Gabriel
Mar 8 at 9:47
add a comment |
I created a node
script which checks if my project contains lock
file or not. If it doesn't then I want to abort my npm
build. Any idea how to do that?
lock-check.js
const path = require('path');
const fs = require("fs");
const lockFiles = ["package-lock.json", "npm-shrinkwrap.json", "yarn.lock"];
let exists = 0;
function checkIfExists()
lockFiles.forEach(
(lf) =>
if (fs.existsSync(lf))
exists++;
);
return exists > 0;
package.json
...
"scripts":
"prestart": "node ./lock-check.js" // Abort the task
"start": "webpack-dev-server --config config/webpack.dev.js --hot --inline"
...
javascript node.js npm
I created a node
script which checks if my project contains lock
file or not. If it doesn't then I want to abort my npm
build. Any idea how to do that?
lock-check.js
const path = require('path');
const fs = require("fs");
const lockFiles = ["package-lock.json", "npm-shrinkwrap.json", "yarn.lock"];
let exists = 0;
function checkIfExists()
lockFiles.forEach(
(lf) =>
if (fs.existsSync(lf))
exists++;
);
return exists > 0;
package.json
...
"scripts":
"prestart": "node ./lock-check.js" // Abort the task
"start": "webpack-dev-server --config config/webpack.dev.js --hot --inline"
...
javascript node.js npm
javascript node.js npm
asked Mar 8 at 9:35
GabrielGabriel
1,56142749
1,56142749
to abort you can doprocess.exit(1)
with 1 or any non zero exit code to tell it was not completed successfully
– warl0ck
Mar 8 at 9:40
I suspect that would work. npm is a different process so it will resume execution.
– Neptune
Mar 8 at 9:41
it works fine in webpack configs i have been using it for some custom tests before building it. just exit code should be non-zero
– warl0ck
Mar 8 at 9:43
1
Yes you are right about Exit codes. If any step of the scripts exits with a non-zero exit code the whole process will terminate. See docs.npmjs.com/misc/scripts#exiting I just read that
– Neptune
Mar 8 at 9:46
It's working. Thanks
– Gabriel
Mar 8 at 9:47
add a comment |
to abort you can doprocess.exit(1)
with 1 or any non zero exit code to tell it was not completed successfully
– warl0ck
Mar 8 at 9:40
I suspect that would work. npm is a different process so it will resume execution.
– Neptune
Mar 8 at 9:41
it works fine in webpack configs i have been using it for some custom tests before building it. just exit code should be non-zero
– warl0ck
Mar 8 at 9:43
1
Yes you are right about Exit codes. If any step of the scripts exits with a non-zero exit code the whole process will terminate. See docs.npmjs.com/misc/scripts#exiting I just read that
– Neptune
Mar 8 at 9:46
It's working. Thanks
– Gabriel
Mar 8 at 9:47
to abort you can do
process.exit(1)
with 1 or any non zero exit code to tell it was not completed successfully– warl0ck
Mar 8 at 9:40
to abort you can do
process.exit(1)
with 1 or any non zero exit code to tell it was not completed successfully– warl0ck
Mar 8 at 9:40
I suspect that would work. npm is a different process so it will resume execution.
– Neptune
Mar 8 at 9:41
I suspect that would work. npm is a different process so it will resume execution.
– Neptune
Mar 8 at 9:41
it works fine in webpack configs i have been using it for some custom tests before building it. just exit code should be non-zero
– warl0ck
Mar 8 at 9:43
it works fine in webpack configs i have been using it for some custom tests before building it. just exit code should be non-zero
– warl0ck
Mar 8 at 9:43
1
1
Yes you are right about Exit codes. If any step of the scripts exits with a non-zero exit code the whole process will terminate. See docs.npmjs.com/misc/scripts#exiting I just read that
– Neptune
Mar 8 at 9:46
Yes you are right about Exit codes. If any step of the scripts exits with a non-zero exit code the whole process will terminate. See docs.npmjs.com/misc/scripts#exiting I just read that
– Neptune
Mar 8 at 9:46
It's working. Thanks
– Gabriel
Mar 8 at 9:47
It's working. Thanks
– Gabriel
Mar 8 at 9:47
add a comment |
1 Answer
1
active
oldest
votes
To abort the build process you just have to call process.exit(1)
,
Here I have used 1 but you can use any non-zero exit code to tell it wasn't a successful build as 0 means successful.
You can read more on official nodejs docs
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060371%2fabort-npm-build-script-from-node-js-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
To abort the build process you just have to call process.exit(1)
,
Here I have used 1 but you can use any non-zero exit code to tell it wasn't a successful build as 0 means successful.
You can read more on official nodejs docs
add a comment |
To abort the build process you just have to call process.exit(1)
,
Here I have used 1 but you can use any non-zero exit code to tell it wasn't a successful build as 0 means successful.
You can read more on official nodejs docs
add a comment |
To abort the build process you just have to call process.exit(1)
,
Here I have used 1 but you can use any non-zero exit code to tell it wasn't a successful build as 0 means successful.
You can read more on official nodejs docs
To abort the build process you just have to call process.exit(1)
,
Here I have used 1 but you can use any non-zero exit code to tell it wasn't a successful build as 0 means successful.
You can read more on official nodejs docs
answered Mar 8 at 9:46
warl0ckwarl0ck
1,72011632
1,72011632
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060371%2fabort-npm-build-script-from-node-js-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
to abort you can do
process.exit(1)
with 1 or any non zero exit code to tell it was not completed successfully– warl0ck
Mar 8 at 9:40
I suspect that would work. npm is a different process so it will resume execution.
– Neptune
Mar 8 at 9:41
it works fine in webpack configs i have been using it for some custom tests before building it. just exit code should be non-zero
– warl0ck
Mar 8 at 9:43
1
Yes you are right about Exit codes. If any step of the scripts exits with a non-zero exit code the whole process will terminate. See docs.npmjs.com/misc/scripts#exiting I just read that
– Neptune
Mar 8 at 9:46
It's working. Thanks
– Gabriel
Mar 8 at 9:47