diff --git a/e2e/rust-e2e/src/napi.spec.ts b/e2e/rust-e2e/src/napi.spec.ts index 2b7e3b7..0825972 100644 --- a/e2e/rust-e2e/src/napi.spec.ts +++ b/e2e/rust-e2e/src/napi.spec.ts @@ -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; @@ -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 ); @@ -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(() => diff --git a/packages/rust/src/executors/napi/executor.ts b/packages/rust/src/executors/napi/executor.ts index e961ea4..cb4c28b 100644 --- a/packages/rust/src/executors/napi/executor.ts +++ b/packages/rust/src/executors/napi/executor.ts @@ -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; diff --git a/packages/rust/src/executors/napi/schema.d.ts b/packages/rust/src/executors/napi/schema.d.ts index 61a6108..024281d 100644 --- a/packages/rust/src/executors/napi/schema.d.ts +++ b/packages/rust/src/executors/napi/schema.d.ts @@ -1,6 +1,7 @@ export interface NapiExecutorSchema { dist: string; jsFile: string; + dts?: string; release?: boolean; target?: string; zig?: boolean; diff --git a/packages/rust/src/executors/napi/schema.json b/packages/rust/src/executors/napi/schema.json index ba61755..b82517c 100644 --- a/packages/rust/src/executors/napi/schema.json +++ b/packages/rust/src/executors/napi/schema.json @@ -11,6 +11,10 @@ "jsFile": { "type": "string" }, + "dts": { + "type": "string", + "default": "index.d.ts" + }, "release": { "type": "boolean", "default": false diff --git a/project.json b/project.json index d47f979..ad8c30c 100644 --- a/project.json +++ b/project.json @@ -6,7 +6,8 @@ "executor": "@nx/js:verdaccio", "options": { "config": ".verdaccio/config.yml", - "port": 3889 + "port": 3889, + "clear": true } } }