Skip to content
This repository has been archived by the owner on Aug 17, 2019. It is now read-only.

fix(lifecycle): platform check for default install scripts #50

Open
wants to merge 5 commits into
base: latest
Choose a base branch
from

Conversation

reyronald
Copy link

Would be nice if @caleblloyd could jump in and test this again in his environment, just in case.

Naturally, I'm not familiar with the rest of the code base and npm's internals, so I can't be certain if there are no other side-effects that should be considered. I'm all ears.

Fixes #49
Related to #45, #46

This is a continuation of zkat#45, a side-effect of the provided fix for it
in zkat#46 and was introduced in `[email protected]`.

For the case where a default `install` script is used and a
`binding.gyp` file is present in  the package root, `npm ci` will fail
with packages that target a different platform that the one currently
running.

Fixes zkat#49
index.js Outdated
})
.then(pkg)
.catch(() => 'ignore')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the buildTree() method, you'll notice a if (!checkDepEnv(...)) {...}. What that does is filter out the dependency altogether while building the tree we're going to extract. If you add the necessary checks to checkDepEnv(), you should be good.

Interesting to note that checkPlatform() is actually synchronous, even though it takes a callback: https://github.com/npm/npm-install-checks/blob/master/index.js#L27-L54 so I'd just rather you write a wrapper that treats it as sync so you don't have to refactor all the checkDepEnv calls into async calls.

t.ok(fs.statSync(path.join(prefix, 'node_modules', 'a', 'build', 'Release', 'hello' + binarySuffix)), 'dep a binary is built')
t.throws(() => {
fs.statSync(path.join(prefix, 'node_modules', 'b', 'build', 'Release', 'hello' + binarySuffix))
}, 'dep b binary is not built')
t.throws(() => {
fs.statSync(path.join(prefix, 'node_modules', 'c', 'build', 'Release', 'hello' + binarySuffix))
}, 'dep c binary is not built')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hooray for tests! v. v. happy about this 💯

- Sync wrapper for `checkPlatform`
- Move `checkPlatform` check from `updateInstallScript` to `checkDepEnv`
@reyronald
Copy link
Author

@zkat I had to add pkg parameter to checkDepEnv to be able to perform the platform check inside it. It is optional though because the only place where it is readily available before the call is in buildTree. In all the other places (extractTree and updateJson) the package.json is not read yet at that point and I didn't wanna go ahead and do such a drastic change. So it feels kind of ugly to me this way, did you consider this?

Perhaps it would be best to call checkPlatformSync directly in buildTree right next tocheckDepEnv, instead of having it inside it and having to do that null/undefined check and bypass it like it is now ? Honestly I don't mind much either way so if you think it's fine then 👍 , unless you have another suggestion, just wanted to mention it just in case.

P.S.: Should we include that checkPlatformSync function in the npm-install-checks package itself ?

@@ -657,7 +658,7 @@ test('skips lifecycle scripts with ignoreScripts is set', t => {
})
})

test('adds install script when binding.gyp is present', t => {
only('adds install script when binding.gyp is present', t => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would imagine this only() needs to be a test() again before this PR can be merged...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing platform check for packages with default install script when binding.gyp is present
3 participants