Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit a3894d7

Browse files
kunalspathakxzyfer
authored andcommitted
Enable building for node-chakracore
When building node-sass and libsass using `npm build .` or `node scripts/build -f`, script uses `node-gyp` version installed as part of `npm install` step inside `node_modules` folder. However this version of `node-gyp` is not compatible with [node-chakracore](https://github.com/nodejs/node-chakracore). It will become partially compatible with node-chakracore once nodejs/node-gyp#873 is merged. However in order to fully work with node-chakracore build need to use the `node-gyp` version that is installed with node-chakracore. This change detects if `npm build` was ran from `Node.js chakracore command prompt` and if yes, use the `node-gyp` that comes with node-chakracore instead of using from `node_modules`.
1 parent 3ad08e7 commit a3894d7

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

scripts/build.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,31 @@ function build(options) {
132132
process.exit(1);
133133
}
134134

135-
var args = [require.resolve(path.join('node-gyp', 'bin', 'node-gyp.js')), 'rebuild', '--verbose'].concat(
136-
['libsass_ext', 'libsass_cflags', 'libsass_ldflags', 'libsass_library'].map(function(subject) {
135+
var args = ['rebuild', '--verbose'].concat(
136+
['libsass_ext', 'libsass_cflags', 'libsass_ldflags', 'libsass_library'].map(function (subject) {
137137
return ['--', subject, '=', process.env[subject.toUpperCase()] || ''].join('');
138138
})).concat(options.args);
139139

140-
console.log(['Building:', process.execPath].concat(args).join(' '));
140+
// To make node-chakracore work, check if node-gyp is in the path.
141+
// If yes, use it instead of using node-gyp directly from node_modules because it might not be
142+
// compatible with node-chakracore.
143+
var nodePath = path.dirname(process.execPath);
144+
var useInstalledNodeGyp = process.jsEngine && process.jsEngine === 'chakracore' &&
145+
process.env.Path.split(';').find(function (path) {
146+
return path.startsWith(nodePath) &&
147+
path.endsWith('node-gyp-bin');
148+
}) != undefined;
149+
150+
var exeName = process.execPath;
151+
if (useInstalledNodeGyp) {
152+
exeName = 'node-gyp';
153+
} else {
154+
args.unshift(require.resolve(path.join('node-gyp', 'bin', 'node-gyp.js')));
155+
}
156+
157+
console.log(['Building:', exeName].concat(args).join(' '));
141158

142-
var proc = spawn(process.execPath, args, {
159+
var proc = spawn(exeName, args, {
143160
stdio: [0, 1, 2]
144161
});
145162

0 commit comments

Comments
 (0)