Abort npm build script from node.js script The 2019 Stack Overflow Developer Survey Results Are InHow 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?

Can you compress metal and what would be the consequences?

Does a dangling wire really electrocute me if I'm standing in water?

Right tool to dig six foot holes?

Is "plugging out" electronic devices an American expression?

The difference between dialogue marks

Is three citations per paragraph excessive for undergraduate research paper?

What to do when moving next to a bird sanctuary with a loosely-domesticated cat?

What tool would a Roman-age civilization have for the breaking of silver and other metals into dust?

Can a flute soloist sit?

Apparent duplicates between Haynes service instructions and MOT

Aging parents with no investments

What does ひと匙 mean in this manga and has it been used colloquially?

What is the meaning of Triage in Cybersec world?

Can one be advised by a professor who is very far away?

Why do UK politicians seemingly ignore opinion polls on Brexit?

Is bread bad for ducks?

Resizing object distorts it (Illustrator CC 2018)

How to support a colleague who finds meetings extremely tiring?

If a Druid sees an animal’s corpse, can they wild shape into that animal?

"as much details as you can remember"

Have you ever entered Singapore using a different passport or name?

Origin of "cooter" meaning "vagina"

Why did Acorn's A3000 have red function keys?

What did it mean to "align" a radio?



Abort npm build script from node.js script



The 2019 Stack Overflow Developer Survey Results Are InHow 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?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















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"


...









share|improve this question






















  • 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

















2















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"


...









share|improve this question






















  • 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













2












2








2








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"


...









share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 9:35









GabrielGabriel

1,57642749




1,57642749












  • 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

















  • 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
















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












1 Answer
1






active

oldest

votes


















1














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






share|improve this answer























    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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






    share|improve this answer



























      1














      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






      share|improve this answer

























        1












        1








        1







        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






        share|improve this answer













        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 9:46









        warl0ckwarl0ck

        1,74721732




        1,74721732





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко