Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rebuild: include prefix when filtering with --only #850

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class Rebuilder {
}
this.realModulePaths.add(realPath);

if (this.prodDeps[`${prefix}${modulePath}`] && (!this.onlyModules || this.onlyModules.includes(modulePath))) {
if (this.prodDeps[`${prefix}${modulePath}`] && (!this.onlyModules || this.onlyModules.includes(modulePath) || this.onlyModules.includes(`${prefix}${modulePath}`))) {
this.rebuilds.push(() => this.rebuildModuleAt(realPath));
}

Expand Down
28 changes: 28 additions & 0 deletions test/fixture/native-app2/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "native-app",
"productName": "Native App",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"start": "electron-forge start"
},
"keywords": [],
"author": "",
"license": "MIT",
"config": {
"forge": "./forge.config.js"
},
"devDependencies": {
"@types/node": "^12.0.10",
"@scoped/native-addon": "1.2.3",
"ffi-napi": "2.4.5"
},
"dependencies": {
"@newrelic/native-metrics": "5.3.0",
"farmhash": "3.2.1",
"level": "6.0.0",
"native-hello-world": "2.0.0",
"ref-napi": "1"
}
}
8 changes: 8 additions & 0 deletions test/fixture/native-app2/native-addon/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "hello",
"sources": [ "hello.c" ]
}
]
}
23 changes: 23 additions & 0 deletions test/fixture/native-app2/native-addon/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <assert.h>
#include <node_api.h>

static napi_value Method(napi_env env, napi_callback_info info) {
napi_status status;
napi_value world;
status = napi_create_string_utf8(env, "world", 5, &world);
assert(status == napi_ok);
return world;
}

#define DECLARE_NAPI_METHOD(name, func) \
{ name, 0, func, 0, 0, 0, napi_default, 0 }

static napi_value Init(napi_env env, napi_value exports) {
napi_status status;
napi_property_descriptor desc = DECLARE_NAPI_METHOD("hello", Method);
status = napi_define_properties(env, exports, 1, &desc);
assert(status == napi_ok);
return exports;
}

NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
2 changes: 2 additions & 0 deletions test/fixture/native-app2/native-addon/hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const addon = require('./build/Release/hello.node');
console.log(addon.hello()); // 'world'
7 changes: 7 additions & 0 deletions test/fixture/native-app2/native-addon/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"private": true,
"name": "@scoped/native-addon",
"version": "1.2.3",
"main": "index.js",
"license": "MIT"
}
7 changes: 7 additions & 0 deletions test/fixture/native-app2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"private": true,
"workspaces": [
"native-addon",
"app"
]
}
18 changes: 13 additions & 5 deletions test/helpers/module-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ export function resetMSVSVersion(): void {
}
}

export async function resetTestModule(testModulePath: string): Promise<void> {
export interface ResetTestModuleOptions {
packageManager?: string
fixturePath?: string
}
export async function resetTestModule(testModulePath: string, options: ResetTestModuleOptions = {}): Promise<void> {
const {
packageManager = 'npm',
fixturePath = path.resolve(__dirname, '../../test/fixture/native-app1')
} = options;
await fs.remove(testModulePath);
await fs.mkdir(testModulePath, { recursive: true });
await fs.copyFile(
path.resolve(__dirname, '../../test/fixture/native-app1/package.json'),
path.resolve(testModulePath, 'package.json')
await fs.copy(
path.resolve(fixturePath),
path.resolve(testModulePath),
);
await spawn('npm', ['install'], { cwd: testModulePath });
await spawn(packageManager, ['install'], { cwd: testModulePath });
resetMSVSVersion();
}

Expand Down
40 changes: 39 additions & 1 deletion test/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('rebuilder', () => {
buildPath: testModulePath,
electronVersion: testElectronVersion,
arch: process.arch,
onlyModules: ['ffi-napi', 'ref-napi'], // TODO: check to see if there's a bug with scoped modules
onlyModules: ['ffi-napi', 'ref-napi'],
force: true
});
let built = 0;
Expand Down Expand Up @@ -194,4 +194,42 @@ describe('rebuilder', () => {
await expectNativeModuleToBeRebuilt(testModulePath, 'ffi-napi');
});
});

describe('only rebuild (with scoped module)', function() {
this.timeout(2 * MINUTES_IN_MILLISECONDS);

before(async () => await resetTestModule(testModulePath, {
packageManager: 'yarn',
fixturePath: path.resolve(__dirname, 'fixture/native-app2'),
}));
after(async () => await cleanupTestModule(testModulePath));

it('should rebuild multiple specified modules via --only option even when not prefixed with its scope', async () => {
const rebuilder = rebuild({
buildPath: path.resolve(testModulePath, 'app'),
electronVersion: testElectronVersion,
arch: process.arch,
onlyModules: ['ffi-napi', 'ref-napi', 'native-addon'],
force: true
});
let built = 0;
rebuilder.lifecycle.on('module-done', () => built++);
await rebuilder;
expect(built).to.equal(3);
});

it('should rebuild multiple specified modules via --only option when prefixed with its scope', async () => {
const rebuilder = rebuild({
buildPath: path.resolve(testModulePath, 'app'),
electronVersion: testElectronVersion,
arch: process.arch,
onlyModules: ['ffi-napi', 'ref-napi', '@scoped/native-addon'],
force: true
});
let built = 0;
rebuilder.lifecycle.on('module-done', () => built++);
await rebuilder;
expect(built).to.equal(3);
});
});
});