Repository navigation
fix: put node-gyp on PATH for dependency build scripts #10554
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
894e0be
fix: put node-gyp on PATH for dependency build scripts
zkochan ea9f3b9
test: cover node-gyp on PATH end to end
zkochan 40f74a4
fix: keep node-gyp setup out of dry runs, key the wrapper by its paths
zkochan aaf8797
fix: harden the node-gyp wrapper read and the spec's PATH restore
zkochan e0b54ee
test: override PATH under the casing the platform already uses
zkochan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import chai, { expect } from 'chai'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import { Helper, NpmCiRegistry, supportNpmCiRegistryTesting } from '@teambit/legacy.e2e-helper'; | ||
| import chaiFs from 'chai-fs'; | ||
| chai.use(chaiFs); | ||
|
|
||
| /** The env keys naming PATH, as this platform spells them — `Path` on Windows. */ | ||
| function pathEnvKeys(): string[] { | ||
| const keys = Object.keys(process.env).filter((key) => key.toUpperCase() === 'PATH'); | ||
| return keys.length ? keys : ['PATH']; | ||
| } | ||
|
|
||
| /** | ||
| * A PATH override holding this process's PATH minus every directory with a | ||
| * `node-gyp` in it, so the installed Bit has to supply its own. Without it the | ||
| * test would pass either way: `npm run` puts the repo's `node_modules/.bin` — | ||
| * which carries a `node-gyp` bin link — on PATH, and dependency build scripts | ||
| * inherit it. | ||
| * | ||
| * Keyed by the casing already in `process.env`, because the command helper | ||
| * spreads it into a plain object: an override under a casing of its own would | ||
| * sit alongside the original rather than replacing it. | ||
| */ | ||
| function pathWithoutNodeGyp(): Record<string, string> { | ||
| const keys = pathEnvKeys(); | ||
| const filtered = (process.env[keys[0]] ?? '') | ||
| .split(path.delimiter) | ||
| .filter((dir) => !['node-gyp', 'node-gyp.cmd'].some((bin) => fs.existsSync(path.join(dir, bin)))) | ||
| .join(path.delimiter); | ||
| return Object.fromEntries(keys.map((key) => [key, filtered])); | ||
| } | ||
|
|
||
| // The pnpm engine ships no node-gyp and spawns dependency build scripts with | ||
| // Bit's own PATH, so without the node-gyp Bit puts there, `node-gyp rebuild` | ||
| // dies with "node-gyp: command not found". | ||
| (supportNpmCiRegistryTesting ? describe : describe.skip)('a dependency built by node-gyp', function () { | ||
| this.timeout(0); | ||
| let helper: Helper; | ||
| let npmCiRegistry: NpmCiRegistry; | ||
| before(async () => { | ||
| helper = new Helper({ scopesOptions: { remoteScopeWithDot: true } }); | ||
| helper.scopeHelper.setWorkspaceWithRemoteScope(); | ||
| helper.workspaceJsonc.setPackageManager(`teambit.dependencies/pnpm`); | ||
| npmCiRegistry = new NpmCiRegistry(helper); | ||
| await npmCiRegistry.init(); | ||
|
|
||
| npmCiRegistry.setRegistry(); | ||
| // A store of its own, so the package is built by this install rather than | ||
| // restored from the side-effects cache of an earlier one — which would | ||
| // reproduce the build output without ever running node-gyp. | ||
| fs.writeFileSync( | ||
| path.join(helper.fixtures.scopes.localPath, 'pnpm-workspace.yaml'), | ||
| `storeDir: ${path.join(helper.fixtures.scopes.localPath, '.pnpm-store')}\n` | ||
| ); | ||
| helper.extensions.workspaceJsonc.addKeyValToDependencyResolver('allowScripts', { | ||
| '@pnpm.e2e/has-binding-gyp': true, | ||
| }); | ||
| helper.command.install('@pnpm.e2e/has-binding-gyp', undefined, undefined, { | ||
| envVariables: pathWithoutNodeGyp(), | ||
| }); | ||
| }); | ||
| after(() => { | ||
| npmCiRegistry.destroy(); | ||
| helper.scopeHelper.destroy(); | ||
| }); | ||
| it('should run its install script through node-gyp', () => { | ||
| // Written by the gyp action in the package's binding.gyp, so it only exists | ||
| // if `node-gyp rebuild` was found and ran. | ||
| expect( | ||
| path.join(helper.fixtures.scopes.localPath, 'node_modules/@pnpm.e2e/has-binding-gyp/generated.js') | ||
| ).to.be.a.path(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
1. Path override not portable
🐞 Bug☼ ReliabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools