Skip to content
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

RFC: Add ability to skip script hooks #185

Closed
wants to merge 1 commit into from
Closed

Conversation

lumaxis
Copy link
Contributor

@lumaxis lumaxis commented Jul 20, 2020

See content.

@isaacs isaacs added Agenda will be discussed at the Open RFC call Release 7.x semver:major backwards-incompatible breaking changes labels Jul 20, 2020
@isaacs
Copy link
Contributor

isaacs commented Jul 20, 2020

It turns out we're already running the specified script for npm run-script (and thus for test, start, etc.) when --ignore-scripts is set. (v6 does not do this, so this is an overlooked breaking change, now turned into a feature by this RFC ;)

The whole diff to do this in v7 is:

diff --git a/lib/run-script.js b/lib/run-script.js
index 270a91ab7..733534421 100644
--- a/lib/run-script.js
+++ b/lib/run-script.js
@@ -80,11 +80,13 @@ const runScript = async (args) => {
 
   // positional args only added to the main event, not pre/post
   const events = [[event, args]]
-  if (scripts[`pre${event}`]) {
-    events.unshift([`pre${event}`, []])
-  }
-  if (scripts[`post${event}`]) {
-    events.push([`post${event}`, []])
+  if (!npm.flatOptions.ignoreScripts) {
+    if (scripts[`pre${event}`]) {
+      events.unshift([`pre${event}`, []])
+    }
+    if (scripts[`post${event}`]) {
+      events.push([`post${event}`, []])
+    }
   }
 
   const opts = {

@ljharb
Copy link
Contributor

ljharb commented Jul 20, 2020

ooh, so to confirm, npm test --ignore-scripts in npm 7 will no longer run nothing, but instead will run test without pretest/posttest??

@isaacs
Copy link
Contributor

isaacs commented Jul 21, 2020

Well... in the current implementation on the beta branch, it'll run test with pretest/posttest. If we accept this RFC, it'll run without pretest/posttest. If we do a different thing, it'll do a different thing :)

Whether the current implementation is a feature or a bug is something we'll discuss wednesday in the call.

@isaacs
Copy link
Contributor

isaacs commented Jul 21, 2020

Personally, I'm of the opinion that npm test should always run your test, even if you have --ignore-scripts set. Because that's the command you're running, it's a bit silly to have a flag that says "don't do the thing I'm telling you specifically to do". But I think it's reasonable to assume in that case that it should not run other scripts that ride along with that command, sort of in the spirit of --ignore-scripts, which is what this RFC proposes.

@ljharb
Copy link
Contributor

ljharb commented Jul 21, 2020

I agree - but it shouldnt run the pre and post scripts, ie, I’m strongly in favor of this rfc.

The behavior in npm <= 6 is bizarre in that it runs nothing :-)

@ruyadorno
Copy link
Contributor

ruyadorno commented Jul 21, 2020

Related: #158

@askirmas
Copy link

askirmas commented Jul 31, 2020

npm run $script --ignore-scripts looks too weird. It should be based on word hooks or lifecycle like --without-hooks or --no-lifecycle. Also can be leading --omit-, --skip-, --dry-.

--ignore-scripts omits dependency's(1) package(2) lifecycle but discussed option skips lifecycle of self(1) script(2). It will be puzzling name coincide and not option reusage.

Besides, is it ok that install and install {package} looks like completely different scripts? Considering

/* ./package.json */
{
  "scripts": {
    "preinstall": "echo 'main preinstall'",
    "postinstall": "echo 'main postinstall'"
  },
  "dependencies": {
    "sub": "file:sub"
  }
}

/* ./sub/package.json */
  "name": "sub",
  "version": "1.0.0",
  "scripts": {
    "preinstall": "echo 'sub preinstall'",
    "postinstall": "echo 'sub postinstall'"
  },

Output:

$ npm install
# main preinstall
# main postinstall
$ npm install ./sub
# sub preinstall
# sub postinstall

@isaacs
Copy link
Contributor

isaacs commented Aug 19, 2020

We discussed this on the call last week and consensus was that adding another term for this (even the term lifecycle which is used internally) is not ideal for UX.

Going to ratify this proposal as-is, and get the implementation in one of the next few v7 beta releases for play-testing.

@ruyadorno ruyadorno removed the Agenda will be discussed at the Open RFC call label Aug 19, 2020
@lumaxis
Copy link
Contributor Author

lumaxis commented Aug 20, 2020

@isaacs Do we merge this or what's the process for the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver:major backwards-incompatible breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants