* build(ci): test against Node 14

* refactor: replace Object.assign with object spread

* test: replace @nlv8/signun with @newrelic/native-metrics for Node 14 support

* test: re-enable workspace tests

* test(workspaces): use snappy instead of ref-napi

* test(workspaces): use sleep instead of ffi-napi

* test: derive test electron version/range from package.json

* test: handle Electron version location on macOS

* build(deps-dev): upgrade electron to ^10.0.0

* build: run npm audit fix

* test: emit stderr when npm/yarn fail

* chore: enable GitHub Dependabot on the repo
This commit is contained in:
Mark Lee 2020-08-27 11:33:25 -07:00 коммит произвёл GitHub
Родитель 2e19f76904
Коммит 108762b25e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 693 добавлений и 720 удалений

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

@ -74,15 +74,14 @@ workflows:
jobs:
- test-linux-10
- test-linux-12
# FIXME: figure out why this fails
# - test-linux-14
- test-linux-14
- test-mac
- test-windows
- release:
requires:
- test-linux-10
- test-linux-12
# - test-linux-14
- test-linux-14
- test-mac
- test-windows
filters:

6
.github/dependabot.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily" # weekdays

1316
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -56,7 +56,7 @@
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.2",
"electron": "^5.0.13",
"electron": "^10.0.0",
"eslint": "^7.7.0",
"eslint-plugin-mocha": "^8.0.0",
"mocha": "^8.1.1",

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

@ -389,7 +389,8 @@ class Rebuilder {
await fs.mkdirp(devDir)
await spawn(nodeGypPath, rebuildArgs, {
cwd: modulePath,
env: Object.assign({}, process.env, {
env: {
...process.env,
USERPROFILE: devDir,
npm_config_disturl: 'https://www.electronjs.org/headers',
npm_config_runtime: 'electron',
@ -398,7 +399,7 @@ class Rebuilder {
npm_config_build_from_source: 'true',
npm_config_debug: this.debug ? 'true' : '',
npm_config_devdir: devDir,
}),
},
});
d('built:', path.basename(modulePath));
@ -512,7 +513,7 @@ function rebuildWithOptions(options: RebuildOptions): Promise<void> {
// eslint-disable-next-line prefer-rest-params
d('rebuilding with args:', arguments);
const lifecycle = new EventEmitter();
const rebuilderOptions: RebuilderOptions = Object.assign({}, options, { lifecycle });
const rebuilderOptions: RebuilderOptions = { ...options, lifecycle };
const rebuilder = new Rebuilder(rebuilderOptions);
const ret = rebuilder.rebuild() as Promise<void> & { lifecycle: EventEmitter };

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

@ -5,6 +5,9 @@ import { spawn } from '@malept/cross-spawn-promise';
import { locateElectronModule } from '../src/electron-locator';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const testElectronRange = require(path.resolve(__dirname, '..', 'package.json')).devDependencies.electron;
function packageCommand(command: string, packageName: string): Promise<string> {
return spawn('npm', [command, '--no-save', packageName], {
cwd: path.resolve(__dirname, '..'),
@ -43,12 +46,12 @@ describe('locateElectronModule', function() {
});
describe('with electron installed', async () => {
before(() => install('electron@^5.0.13'));
before(() => install(`electron@${testElectronRange}`));
testElectronCanBeFound();
after(() => uninstall('electron'));
});
after(() => install('electron@^5.0.13'));
after(() => install(`electron@${testElectronRange}`));
});

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

@ -18,7 +18,7 @@
"ffi-napi": "2.4.5"
},
"dependencies": {
"@nlv8/signun": "1.3.4",
"@newrelic/native-metrics": "5.3.0",
"farmhash": "3.0.0",
"level": "6.0.0",
"ref-napi": "1.4.2"

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

@ -8,9 +8,9 @@
"author": "",
"license": "MIT",
"devDependencies": {
"ffi-napi": "2.4.5"
"sleep": "6.3.0"
},
"dependencies": {
"ref-napi": "1.4.2"
"snappy": "6.3.4"
}
}

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

@ -0,0 +1,16 @@
import * as fs from 'fs-extra';
import * as path from 'path';
function electronVersionPath() {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const electronPath = require('electron');
if (process.platform === 'darwin') {
return path.resolve(path.dirname(electronPath), '..', '..', '..', 'version');
} else {
return path.join(path.dirname(electronPath), 'version');
}
}
export function getExactElectronVersionSync(): string {
return fs.readFileSync(electronVersionPath()).toString().trim();
}

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

@ -4,10 +4,13 @@ import * as os from 'os';
import { spawn } from '@malept/cross-spawn-promise';
import { expectNativeModuleToBeRebuilt, expectNativeModuleToNotBeRebuilt } from './helpers/rebuild';
import { rebuild } from '../src/rebuild';
import { getExactElectronVersionSync } from './helpers/electron-version';
import { getProjectRootPath } from '../src/search-module';
import { rebuild } from '../src/rebuild';
describe.skip('rebuild for yarn workspace', function() {
const testElectronVersion = getExactElectronVersionSync();
describe('rebuild for yarn workspace', function() {
this.timeout(2 * 60 * 1000);
const testModulePath = path.resolve(os.tmpdir(), 'electron-rebuild-test');
@ -16,27 +19,24 @@ describe.skip('rebuild for yarn workspace', function() {
await fs.remove(testModulePath);
await fs.copy(path.resolve(__dirname, 'fixture/workspace-test'), testModulePath);
await spawn('yarn', [], {
cwd: testModulePath,
stdio: 'ignore'
});
await spawn('yarn', [], { cwd: testModulePath });
const projectRootPath = await getProjectRootPath(path.join(testModulePath, 'workspace-test', 'child-workspace'));
await rebuild({
buildPath: path.resolve(testModulePath, 'child-workspace'),
electronVersion: '5.0.13',
electronVersion: testElectronVersion,
arch: process.arch,
projectRootPath
});
});
it('should have rebuilt top level prod dependencies', async () => {
await expectNativeModuleToBeRebuilt(testModulePath, 'ref-napi');
await expectNativeModuleToBeRebuilt(testModulePath, 'snappy');
});
it('should not have rebuilt top level devDependencies', async () => {
await expectNativeModuleToNotBeRebuilt(testModulePath, 'ffi-napi');
await expectNativeModuleToNotBeRebuilt(testModulePath, 'sleep');
});
after(async () => {

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

@ -5,8 +5,11 @@ import * as os from 'os';
import { spawn } from '@malept/cross-spawn-promise';
import { expectNativeModuleToBeRebuilt, expectNativeModuleToNotBeRebuilt } from './helpers/rebuild';
import { getExactElectronVersionSync } from './helpers/electron-version';
import { rebuild, RebuildOptions } from '../src/rebuild';
const testElectronVersion = getExactElectronVersionSync();
describe('rebuilder', () => {
const testModulePath = path.resolve(os.tmpdir(), 'electron-rebuild-test');
const timeoutSeconds = process.platform === 'win32' ? 5 : 2;
@ -18,20 +21,17 @@ describe('rebuilder', () => {
path.resolve(__dirname, '../test/fixture/native-app1/package.json'),
path.resolve(testModulePath, 'package.json')
);
await spawn('npm', ['install'], {
cwd: testModulePath,
stdio: 'ignore',
});
await spawn('npm', ['install'], { cwd: testModulePath });
};
const optionSets: {
name: string;
args: RebuildOptions | string[];
}[] = [
{ args: [testModulePath, '5.0.13', process.arch], name: 'sequential args' },
{ args: [testModulePath, testElectronVersion, process.arch], name: 'sequential args' },
{ args: {
buildPath: testModulePath,
electronVersion: '5.0.13',
electronVersion: testElectronVersion,
arch: process.arch
}, name: 'options object' }
];
@ -68,7 +68,7 @@ describe('rebuilder', () => {
});
it('should have rebuilt children of scoped top level prod dependencies', async () => {
await expectNativeModuleToBeRebuilt(testModulePath, '@nlv8/signun');
await expectNativeModuleToBeRebuilt(testModulePath, '@newrelic/native-metrics');
});
it('should have rebuilt top level optional dependencies', async () => {
@ -92,8 +92,8 @@ describe('rebuilder', () => {
before(resetTestModule);
it('should skip the rebuild step when disabled', async () => {
await rebuild(testModulePath, '5.0.13', process.arch);
const rebuilder = rebuild(testModulePath, '5.0.13', process.arch, [], false);
await rebuild(testModulePath, testElectronVersion, process.arch);
const rebuilder = rebuild(testModulePath, testElectronVersion, process.arch, [], false);
let skipped = 0;
rebuilder.lifecycle.on('module-skip', () => {
skipped++;
@ -103,7 +103,7 @@ describe('rebuilder', () => {
});
it('should rebuild all modules again when disabled but the electron ABI bumped', async () => {
await rebuild(testModulePath, '5.0.13', process.arch);
await rebuild(testModulePath, testElectronVersion, process.arch);
const rebuilder = rebuild(testModulePath, '3.0.0', process.arch, [], false);
let skipped = 0;
rebuilder.lifecycle.on('module-skip', () => {
@ -114,8 +114,8 @@ describe('rebuilder', () => {
});
it('should rebuild all modules again when enabled', async () => {
await rebuild(testModulePath, '5.0.13', process.arch);
const rebuilder = rebuild(testModulePath, '5.0.13', process.arch, [], true);
await rebuild(testModulePath, testElectronVersion, process.arch);
const rebuilder = rebuild(testModulePath, testElectronVersion, process.arch, [], true);
let skipped = 0;
rebuilder.lifecycle.on('module-skip', () => {
skipped++;
@ -134,7 +134,7 @@ describe('rebuilder', () => {
it('should rebuild only specified modules', async () => {
const rebuilder = rebuild({
buildPath: testModulePath,
electronVersion: '5.0.13',
electronVersion: testElectronVersion,
arch: process.arch,
onlyModules: ['ffi-napi'],
force: true
@ -148,7 +148,7 @@ describe('rebuilder', () => {
it('should rebuild multiple specified modules via --only option', async () => {
const rebuilder = rebuild({
buildPath: testModulePath,
electronVersion: '5.0.13',
electronVersion: testElectronVersion,
arch: process.arch,
onlyModules: ['ffi-napi', 'ref-napi'], // TODO: check to see if there's a bug with scoped modules
force: true
@ -169,7 +169,7 @@ describe('rebuilder', () => {
it('should have rebuilt ffi-napi module in Debug mode', async () => {
await rebuild({
buildPath: testModulePath,
electronVersion: '5.0.13',
electronVersion: testElectronVersion,
arch: process.arch,
onlyModules: ['ffi-napi'],
force: true,