Skip to content

Commit

Permalink
fix(core): add dts option for napi executor
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Nov 14, 2024
1 parent 1f8a32b commit a76cb80
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
13 changes: 12 additions & 1 deletion e2e/rust-e2e/src/napi.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execSync } from 'child_process';
import { createTestProject, runNxCommand } from './utils';
import { rmSync } from 'fs';
import { listFiles } from '@nx/plugin/testing';
import { listFiles, readFile, updateFile } from '@nx/plugin/testing';

describe('napi', () => {
let projectDirectory: string;
Expand Down Expand Up @@ -31,6 +31,15 @@ describe('napi', () => {
projectDirectory
);

const projectConfigPath = `test-project-napi/napi_proj/project.json`;
const projectFile = JSON.parse(readFile(projectConfigPath));
projectFile['targets']['build']['options'] = {
...projectFile['targets']['build']['options'],
jsFile: 'native.js',
dts: 'native.d.ts',
};
updateFile(projectConfigPath, JSON.stringify(projectFile, null, 2));

expect(listFiles(`test-project-napi/napi_proj/npm`).length).toBeGreaterThan(
0
);
Expand All @@ -40,6 +49,8 @@ describe('napi', () => {
).not.toThrow();

const files = listFiles(`test-project-napi/napi_proj`);
expect(files.some((file) => file.endsWith('native.js'))).toBeTruthy();
expect(files.some((file) => file.endsWith('native.d.ts'))).toBeTruthy();
expect(files.some((file) => file.endsWith('.node'))).toBeTruthy();

expect(() =>
Expand Down
1 change: 1 addition & 0 deletions packages/rust/src/executors/napi/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default async function runExecutor(

buildOptions.platform = true;
buildOptions.jsBinding = options.jsFile;
buildOptions.dts = options.dts;
buildOptions.outputDir = options.dist;
buildOptions.manifestPath = join(projectRoot ?? '.', 'Cargo.toml');
buildOptions.packageJsonPath = packageJson;
Expand Down
1 change: 1 addition & 0 deletions packages/rust/src/executors/napi/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface NapiExecutorSchema {
dist: string;
jsFile: string;
dts?: string;
release?: boolean;
target?: string;
zig?: boolean;
Expand Down
4 changes: 4 additions & 0 deletions packages/rust/src/executors/napi/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"jsFile": {
"type": "string"
},
"dts": {
"type": "string",
"default": "index.d.ts"
},
"release": {
"type": "boolean",
"default": false
Expand Down
3 changes: 2 additions & 1 deletion project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"executor": "@nx/js:verdaccio",
"options": {
"config": ".verdaccio/config.yml",
"port": 3889
"port": 3889,
"clear": true
}
}
}
Expand Down

0 comments on commit a76cb80

Please sign in to comment.