Skip to content

Commit

Permalink
refactor: node version check
Browse files Browse the repository at this point in the history
PR-URL: hyj1991#45
  • Loading branch information
hyj1991 authored May 23, 2022
1 parent 973ae8b commit 34fb892
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
5 changes: 2 additions & 3 deletions lib/binding.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

const nodeVersion = process.versions.node;
const tags = nodeVersion.split('.');
const nodeVersionLessThan = require('./utils').nodeVersionLessThan;

let binding;

if (tags[0] < 12) {
if (nodeVersionLessThan(12)) {
binding = require('../build/Release/profiler.node');
} else {
const path = require('path');
Expand Down
7 changes: 7 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

exports.nodeVersionLessThan = function (version) {
const nodeVersion = process.versions.node;
const tags = nodeVersion.split('.');
return Number(tags[0]) < Number(version);
};
2 changes: 1 addition & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ exports = module.exports = versions => {
change = `nvm use ${nvmNodeVersion}`;
}

const install = 'npm install';
const install = 'npm install --no-audit';
const build = `${npmBin} run dep`;
const pack = 'npx node-pre-gyp package && npx node-pre-gyp testpackage';
const copy = `${npmBin} run copy`;
Expand Down
5 changes: 2 additions & 3 deletions scripts/gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const path = require('path');
const fs = require('fs');
const execCmd = require('./build').execCmd;
const nodeVersion = process.versions.node;
const nodeVersionLessThan = require('../lib/utils').nodeVersionLessThan;

function writeConfig(config) {
const options = JSON.stringify(config, null, 2);
Expand All @@ -13,14 +13,13 @@ function writeConfig(config) {
}

module.exports = function (oldCmd, newCmd) {
const tags = nodeVersion.split('.');
const options = {
variables: {
action_after_build: 'false'
}
};

if (tags[0] < 12) {
if (nodeVersionLessThan(12)) {
writeConfig(options);
execCmd(oldCmd);
} else {
Expand Down
5 changes: 2 additions & 3 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const cp = require('child_process');
const path = require('path');
const nodeVersion = process.versions.node;
const nodeVersionLessThan = require('../lib/utils').nodeVersionLessThan;

function exec(cmd) {
cp.execSync(cmd, {
Expand All @@ -11,8 +11,7 @@ function exec(cmd) {
});
}

const tags = nodeVersion.split('.');
if (tags[0] < 8) {
if (nodeVersionLessThan(8)) {
exec('npm run test-old');
} else {
exec('npm run test-new');
Expand Down

0 comments on commit 34fb892

Please sign in to comment.