diff --git a/integration/fixtures/gyp/package.json b/integration/fixtures/gyp/package.json new file mode 100644 index 0000000..2879b28 --- /dev/null +++ b/integration/fixtures/gyp/package.json @@ -0,0 +1,6 @@ +{ + "repository": "git@github.com:cnpm/rapid.git", + "dependencies": { + "fsevents": "^1.2.13" + } +} diff --git a/integration/index.2.test.js b/integration/index.2.test.js index f041d6c..a8e3523 100644 --- a/integration/index.2.test.js +++ b/integration/index.2.test.js @@ -57,6 +57,32 @@ describe('test/index.v2.test.js', () => { } }); + describe('node gyp', async () => { + it('should support node-gyp for npminstall', async () => { + cwd = path.join(__dirname, './fixtures/gyp'); + await coffee + .fork(rapid, [ 'install', '--by=npminstall' ], { + cwd, + }) + .debug() + .expect('code', 0) + .expect('stdout', /CXX\(target\) Release\/obj.target\/fse\/fsevents\.o/) + .end(); + }); + + it('should support node-gyp for npm mode', async () => { + cwd = path.join(__dirname, './fixtures/gyp'); + await coffee + .fork(rapid, [ 'install', '--by=npm' ], { + cwd, + }) + .debug() + .expect('code', 0) + .expect('stdout', /CXX\(target\) Release\/obj.target\/fse\/fsevents\.o/) + .end(); + }); + }); + describe('INIT_CWD', async () => { it('should set INIT_CWD', async () => { cwd = path.join(__dirname, './fixtures/init-cwd'); @@ -171,7 +197,6 @@ describe('test/index.v2.test.js', () => { it('should auto clean when reinstall', async () => { cwd = path.join(__dirname, './fixtures/esbuild'); - await coffee .fork(rapid, [ 'install', @@ -203,4 +228,6 @@ describe('test/index.v2.test.js', () => { const res = await execa.command('mount', { stdio: 'pipe' }); assert(res.stdout.indexOf('integration/fixtures/esbuild/node_modules') === res.stdout.lastIndexOf('integration/fixtures/esbuild/node_modules')); }); + + }); diff --git a/packages/cli/lib/node-gyp-bin/node-gyp b/packages/cli/lib/node-gyp-bin/node-gyp new file mode 100755 index 0000000..381931c --- /dev/null +++ b/packages/cli/lib/node-gyp-bin/node-gyp @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +node "`dirname "$0"`/node-gyp.js" "$@" diff --git a/packages/cli/lib/node-gyp-bin/node-gyp.cmd b/packages/cli/lib/node-gyp-bin/node-gyp.cmd new file mode 100755 index 0000000..48fe570 --- /dev/null +++ b/packages/cli/lib/node-gyp-bin/node-gyp.cmd @@ -0,0 +1 @@ +node "%~dp0\node-gyp.js" %* diff --git a/packages/cli/lib/node-gyp-bin/node-gyp.js b/packages/cli/lib/node-gyp-bin/node-gyp.js new file mode 100644 index 0000000..839ef32 --- /dev/null +++ b/packages/cli/lib/node-gyp-bin/node-gyp.js @@ -0,0 +1,3 @@ +'use strict'; + +return require('node-gyp/bin/node-gyp.js'); diff --git a/packages/cli/lib/util.js b/packages/cli/lib/util.js index f475ec4..96cde63 100644 --- a/packages/cli/lib/util.js +++ b/packages/cli/lib/util.js @@ -534,7 +534,7 @@ exports.runScript = async (pkgDir, script, options) => { // ignore error } env.PATH = [ - path.join(__dirname, '../node-gyp-bin'), + path.join(__dirname, './node-gyp-bin'), path.join(options.cwd, 'node_modules', '.bin'), path.join(pkgDir, 'node_modules', '.bin'), process.env.PATH, diff --git a/packages/cli/package.json b/packages/cli/package.json index 0a5ab4e..58804ba 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -31,7 +31,8 @@ "semver": "^7.3.8", "urllib": "^3.16.1", "yargs": "^17.7.2", - "yargs-parser": "^9.0.2" + "yargs-parser": "^9.0.2", + "node-gyp": "^9.0.0" }, "homepage": "https://github.com/cnpm/rapid", "repository": { diff --git a/packages/cli/test/fixtures/gyp/package.json b/packages/cli/test/fixtures/gyp/package.json new file mode 100644 index 0000000..e69de29