* 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:
Yulong Wang 2017-08-17 17:10:20 -07:00 коммит произвёл GitHub
Родитель 5b1aa4fd78
Коммит f0786f7386
9 изменённых файлов: 115 добавлений и 22 удалений

Просмотреть файл

@ -65,7 +65,7 @@ before_install:
fi
install:
- npm install cmake-js -g
- npm install
- npm install --no-fetch
script:
- npm test
- npm run unittest

Просмотреть файл

@ -25,4 +25,5 @@ add_subdirectory(src)
if (CMAKE_JS_VERSION)
# Build napa addon for node.
add_subdirectory(node)
add_subdirectory(test/module/addon)
endif()

Просмотреть файл

@ -16,7 +16,7 @@ platform:
install:
- ps: Install-Product node $env:nodejs_version $env:platform
- npm install cmake-js -g
- npm install
- npm install --no-fetch
# Skip MSBuild stage
build: off

Просмотреть файл

@ -9,18 +9,28 @@
"type": "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": {
"mocha": ">= 3.4.2",
"typescript": ">= 2.2.1",
"@types/node": ">= 7.0.8",
"@types/mocha": ">= 2.2.0",
"markdown-table": "1.1.0"
"node-pre-gyp-github": "^1.3.1",
"mocha": "^3.5.0",
"typescript": "^2.4.2",
"@types/node": "^8.0.22",
"@types/mocha": "^2.2.41",
"markdown-table": "^1.1.1"
},
"scripts": {
"benchmark": "node benchmark/bench.js",
"install": "cmake-js compile",
"install": "node scripts/install.js",
"prepare": "tsc -p lib && tsc -p test && tsc -p benchmark",
"pretest": "cmake-js compile -d test/module/addon",
"test": "mocha test --recursive",
"rebuild": "cmake-js rebuild && tsc -p lib",
"rebuildd": "cmake-js rebuild --debug && tsc -p lib",

82
scripts/install.js Normal file
Просмотреть файл

@ -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(() => {
var assert = require("assert");
var jsonModule = require('./module/test.json');
assert.notEqual(jsonModule, undefined);
assert.equal(jsonModule.prop1, "val1");
assert.equal(jsonModule.prop2, "val2");
@ -50,8 +50,8 @@ describe('napajs/module', function () {
it('napa module', () => {
return napaZone.execute(() => {
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.equal(napaModule.getModuleName(), "simple-napa-addon");
});
@ -60,8 +60,8 @@ describe('napajs/module', function () {
it('object wrap module', () => {
return napaZone.execute(() => {
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();
assert.notEqual(obj, undefined);
obj.setValue(3);
@ -411,7 +411,7 @@ describe('napajs/module', function () {
it('post async work', () => {
return napaZone.execute(() => {
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();
obj.setValue(3);
@ -434,7 +434,7 @@ describe('napajs/module', function () {
it('do async work', () => {
return napaZone.execute(() => {
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();
obj.setValue(8);

Просмотреть файл

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project("simple-napa-addon")
project("simple-addon")
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_target_properties(${TARGET_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/build
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/build
LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/build
LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/build
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${NAPA_ROOT}/bin
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${NAPA_ROOT}/bin
LIBRARY_OUTPUT_DIRECTORY_DEBUG ${NAPA_ROOT}/bin
LIBRARY_OUTPUT_DIRECTORY_RELEASE ${NAPA_ROOT}/bin
)
# Include directories

Просмотреть файл

@ -23,7 +23,7 @@ function run() {
assert(require.resolve('./sub-folder/.././sub-folder/file.js'), __dirname + '/sub-folder/file.js');
// 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
assert(require.resolve('file.js'), __dirname + '/node_modules/file.js');

Просмотреть файл