зеркало из https://github.com/microsoft/napajs.git
Enable pre-build for napa.js (#41)
* Onboard node-pre-gyp * Add missing dependencies * Remove node-pre-gyp from bundledDependencies * run prepare scripts under NPM<4.x * fix string template * Update version of package dependencies * re-organize installation logs * Add build logs for fallback logic * Rename the test module name from 'simple-napa-addon' to 'simple-addon' * Fix auto-resolve error * Fix error in install.js
This commit is contained in:
Родитель
5b1aa4fd78
Коммит
f0786f7386
|
@ -65,7 +65,7 @@ before_install:
|
||||||
fi
|
fi
|
||||||
install:
|
install:
|
||||||
- npm install cmake-js -g
|
- npm install cmake-js -g
|
||||||
- npm install
|
- npm install --no-fetch
|
||||||
script:
|
script:
|
||||||
- npm test
|
- npm test
|
||||||
- npm run unittest
|
- npm run unittest
|
||||||
|
|
|
@ -25,4 +25,5 @@ add_subdirectory(src)
|
||||||
if (CMAKE_JS_VERSION)
|
if (CMAKE_JS_VERSION)
|
||||||
# Build napa addon for node.
|
# Build napa addon for node.
|
||||||
add_subdirectory(node)
|
add_subdirectory(node)
|
||||||
|
add_subdirectory(test/module/addon)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -16,7 +16,7 @@ platform:
|
||||||
install:
|
install:
|
||||||
- ps: Install-Product node $env:nodejs_version $env:platform
|
- ps: Install-Product node $env:nodejs_version $env:platform
|
||||||
- npm install cmake-js -g
|
- npm install cmake-js -g
|
||||||
- npm install
|
- npm install --no-fetch
|
||||||
|
|
||||||
# Skip MSBuild stage
|
# Skip MSBuild stage
|
||||||
build: off
|
build: off
|
||||||
|
|
24
package.json
24
package.json
|
@ -9,18 +9,28 @@
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/Microsoft/napajs.git"
|
"url": "https://github.com/Microsoft/napajs.git"
|
||||||
},
|
},
|
||||||
|
"binary": {
|
||||||
|
"module_name": "napa-binding",
|
||||||
|
"module_path": "./bin/",
|
||||||
|
"host": "https://github.com/Microsoft/napajs/releases/download/",
|
||||||
|
"remote_path": "{version}"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"node-pre-gyp": "^0.6.36",
|
||||||
|
"npmlog": "^4.1.2"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": ">= 3.4.2",
|
"node-pre-gyp-github": "^1.3.1",
|
||||||
"typescript": ">= 2.2.1",
|
"mocha": "^3.5.0",
|
||||||
"@types/node": ">= 7.0.8",
|
"typescript": "^2.4.2",
|
||||||
"@types/mocha": ">= 2.2.0",
|
"@types/node": "^8.0.22",
|
||||||
"markdown-table": "1.1.0"
|
"@types/mocha": "^2.2.41",
|
||||||
|
"markdown-table": "^1.1.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"benchmark": "node benchmark/bench.js",
|
"benchmark": "node benchmark/bench.js",
|
||||||
"install": "cmake-js compile",
|
"install": "node scripts/install.js",
|
||||||
"prepare": "tsc -p lib && tsc -p test && tsc -p benchmark",
|
"prepare": "tsc -p lib && tsc -p test && tsc -p benchmark",
|
||||||
"pretest": "cmake-js compile -d test/module/addon",
|
|
||||||
"test": "mocha test --recursive",
|
"test": "mocha test --recursive",
|
||||||
"rebuild": "cmake-js rebuild && tsc -p lib",
|
"rebuild": "cmake-js rebuild && tsc -p lib",
|
||||||
"rebuildd": "cmake-js rebuild --debug && tsc -p lib",
|
"rebuildd": "cmake-js rebuild --debug && tsc -p lib",
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
var log = require('npmlog');
|
||||||
|
var execSync = require('child_process').execSync;
|
||||||
|
|
||||||
|
// Default command
|
||||||
|
var fetchCommand = 'node-pre-gyp install --fallback-to-build=false';
|
||||||
|
var buildCommand = 'cmake-js compile';
|
||||||
|
|
||||||
|
// ==== Determine install options ====
|
||||||
|
// Skip the fetch stage. '--no-fetch', or '--fetch=false'
|
||||||
|
var skipFetch = process.env.hasOwnProperty('npm_config_fetch') && !process.env['npm_config_fetch'];
|
||||||
|
// Skip the build stage. '--no-build', or '--build=false'
|
||||||
|
var skipBuild = process.env.hasOwnProperty('npm_config_build') && !process.env['npm_config_build'];
|
||||||
|
|
||||||
|
// Use debug build
|
||||||
|
if (process.env.hasOwnProperty('npm_config_debug') && process.env['npm_config_debug']) {
|
||||||
|
buildCommand += " --debug";
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info('NAPA_INSTALL', 'installing napajs...');
|
||||||
|
|
||||||
|
var errorCode = 0;
|
||||||
|
|
||||||
|
// ==== Try to fetch the pre-build binaries ====
|
||||||
|
if (!skipFetch) {
|
||||||
|
try {
|
||||||
|
log.info('NAPA_INSTALL', 'downloading the pre-build binaries...');
|
||||||
|
execSync(fetchCommand, { 'stdio': 'inherit' });
|
||||||
|
|
||||||
|
log.info('NAPA_INSTALL', 'completed successfully by download.');
|
||||||
|
skipBuild = true;
|
||||||
|
} catch (e) {
|
||||||
|
errorCode = e.status;
|
||||||
|
|
||||||
|
log.warn('NAPA_INSTALL', 'failed to download the pre-build binaries.');
|
||||||
|
if (!skipBuild) {
|
||||||
|
log.warn('NAPA_INSTALL', 'will fallback to build stage.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==== Try to build from sources ====
|
||||||
|
if (!skipBuild) {
|
||||||
|
try {
|
||||||
|
log.info('NAPA_INSTALL', 'building from sources...');
|
||||||
|
execSync(buildCommand, { 'stdio': 'inherit' });
|
||||||
|
|
||||||
|
log.info('NAPA_INSTALL', 'completed successfully by build.');
|
||||||
|
} catch (e) {
|
||||||
|
errorCode = e.status;
|
||||||
|
|
||||||
|
log.warning('NAPA_INSTALL', 'failed to build from sources.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==== Compile Typescript files ====
|
||||||
|
if (errorCode == 0) {
|
||||||
|
var npmVersion = execSync('npm --version').toString().trim();
|
||||||
|
log.info('NAPA_INSTALL', `current NPM version=${npmVersion}.`);
|
||||||
|
|
||||||
|
var npmMajorVersion = npmVersion.split('.')[0];
|
||||||
|
var npmMajorVersionNumber = parseInt(npmMajorVersion);
|
||||||
|
if (npmMajorVersionNumber < 4) {
|
||||||
|
// Before npm 4.x, the 'prepare' script will not run automatically by npm.
|
||||||
|
// We have to run it explicitly in this script.
|
||||||
|
log.info('NAPA_INSTALL', 'NPM below 4.x does not recognize script "prepare". We need to run it explicitly.');
|
||||||
|
log.info('NAPA_INSTALL', 'running "npm run prepare"...');
|
||||||
|
|
||||||
|
try {
|
||||||
|
execSync('npm run prepare', { 'stdio': 'inherit' });
|
||||||
|
} catch (e) {
|
||||||
|
errorCode = e.status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorCode != 0) {
|
||||||
|
log.error('NAPA_INSTALL', 'failed to install napajs.');
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(errorCode);
|
|
@ -40,7 +40,7 @@ describe('napajs/module', function () {
|
||||||
return napaZone.execute(() => {
|
return napaZone.execute(() => {
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var jsonModule = require('./module/test.json');
|
var jsonModule = require('./module/test.json');
|
||||||
|
|
||||||
assert.notEqual(jsonModule, undefined);
|
assert.notEqual(jsonModule, undefined);
|
||||||
assert.equal(jsonModule.prop1, "val1");
|
assert.equal(jsonModule.prop1, "val1");
|
||||||
assert.equal(jsonModule.prop2, "val2");
|
assert.equal(jsonModule.prop2, "val2");
|
||||||
|
@ -50,8 +50,8 @@ describe('napajs/module', function () {
|
||||||
it('napa module', () => {
|
it('napa module', () => {
|
||||||
return napaZone.execute(() => {
|
return napaZone.execute(() => {
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var napaModule = require('./module/addon/build/simple-napa-addon.napa');
|
var napaModule = require('../bin/simple-addon.napa');
|
||||||
|
|
||||||
assert.notEqual(napaModule, undefined);
|
assert.notEqual(napaModule, undefined);
|
||||||
assert.equal(napaModule.getModuleName(), "simple-napa-addon");
|
assert.equal(napaModule.getModuleName(), "simple-napa-addon");
|
||||||
});
|
});
|
||||||
|
@ -60,8 +60,8 @@ describe('napajs/module', function () {
|
||||||
it('object wrap module', () => {
|
it('object wrap module', () => {
|
||||||
return napaZone.execute(() => {
|
return napaZone.execute(() => {
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var napaModule = require('./module/addon/build/simple-napa-addon.napa');
|
var napaModule = require('../bin/simple-addon.napa');
|
||||||
|
|
||||||
var obj = napaModule.createSimpleObjectWrap();
|
var obj = napaModule.createSimpleObjectWrap();
|
||||||
assert.notEqual(obj, undefined);
|
assert.notEqual(obj, undefined);
|
||||||
obj.setValue(3);
|
obj.setValue(3);
|
||||||
|
@ -411,7 +411,7 @@ describe('napajs/module', function () {
|
||||||
it('post async work', () => {
|
it('post async work', () => {
|
||||||
return napaZone.execute(() => {
|
return napaZone.execute(() => {
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var napaModule = require('./module/addon/build/simple-napa-addon.napa');
|
var napaModule = require('../bin/simple-addon.napa');
|
||||||
|
|
||||||
var obj = napaModule.createSimpleObjectWrap();
|
var obj = napaModule.createSimpleObjectWrap();
|
||||||
obj.setValue(3);
|
obj.setValue(3);
|
||||||
|
@ -434,7 +434,7 @@ describe('napajs/module', function () {
|
||||||
it('do async work', () => {
|
it('do async work', () => {
|
||||||
return napaZone.execute(() => {
|
return napaZone.execute(() => {
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var napaModule = require('./module/addon/build/simple-napa-addon.napa');
|
var napaModule = require('../bin/simple-addon.napa');
|
||||||
|
|
||||||
var obj = napaModule.createSimpleObjectWrap();
|
var obj = napaModule.createSimpleObjectWrap();
|
||||||
obj.setValue(8);
|
obj.setValue(8);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
|
||||||
|
|
||||||
project("simple-napa-addon")
|
project("simple-addon")
|
||||||
|
|
||||||
set(NAPA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
set(NAPA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
||||||
|
|
||||||
|
@ -21,10 +21,10 @@ set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "" SUFFIX ".napa")
|
||||||
|
|
||||||
# Set output directory for the addon
|
# Set output directory for the addon
|
||||||
set_target_properties(${TARGET_NAME} PROPERTIES
|
set_target_properties(${TARGET_NAME} PROPERTIES
|
||||||
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/build
|
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${NAPA_ROOT}/bin
|
||||||
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/build
|
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${NAPA_ROOT}/bin
|
||||||
LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/build
|
LIBRARY_OUTPUT_DIRECTORY_DEBUG ${NAPA_ROOT}/bin
|
||||||
LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/build
|
LIBRARY_OUTPUT_DIRECTORY_RELEASE ${NAPA_ROOT}/bin
|
||||||
)
|
)
|
||||||
|
|
||||||
# Include directories
|
# Include directories
|
||||||
|
|
|
@ -23,7 +23,7 @@ function run() {
|
||||||
assert(require.resolve('./sub-folder/.././sub-folder/file.js'), __dirname + '/sub-folder/file.js');
|
assert(require.resolve('./sub-folder/.././sub-folder/file.js'), __dirname + '/sub-folder/file.js');
|
||||||
|
|
||||||
// Relative path without extension to napa addon
|
// Relative path without extension to napa addon
|
||||||
assert(require.resolve('./addon/build/simple-napa-addon'), __dirname + '/addon/build/simple-napa-addon.napa');
|
assert(require.resolve('./sub-folder/addon/mock-addon'), __dirname + '/sub-folder/addon/mock-addon.napa');
|
||||||
|
|
||||||
// From node_modules with extension
|
// From node_modules with extension
|
||||||
assert(require.resolve('file.js'), __dirname + '/node_modules/file.js');
|
assert(require.resolve('file.js'), __dirname + '/node_modules/file.js');
|
||||||
|
|
Загрузка…
Ссылка в новой задаче