@napi-rs/cli 3.0.0-alpha.4 → 3.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/cli.mjs +0 -0
  2. package/dist/api/build.js +26 -12
  3. package/dist/api/templates/ci-template.js +1 -3
  4. package/dist/api/templates/ci.yml.js +8 -2
  5. package/dist/api/templates/js-binding.d.ts +1 -1
  6. package/dist/api/templates/js-binding.js +4 -3
  7. package/dist/api/templates/package.json.js +29 -27
  8. package/dist/commands/artifacts.js +1 -2
  9. package/dist/commands/help.js +1 -2
  10. package/dist/commands/new.js +1 -4
  11. package/dist/def/artifacts.js +1 -2
  12. package/dist/def/build.js +1 -2
  13. package/dist/def/create-npm-dirs.js +1 -2
  14. package/dist/def/new.js +1 -2
  15. package/dist/def/pre-publish.js +1 -2
  16. package/dist/def/rename.js +1 -2
  17. package/dist/def/universalize.js +1 -2
  18. package/dist/def/version.js +1 -2
  19. package/dist/index.cjs +2400 -7660
  20. package/dist/utils/__tests__/typegen.spec.js +1 -1
  21. package/dist/utils/config.d.ts +9 -1
  22. package/dist/utils/typegen.d.ts +4 -1
  23. package/dist/utils/typegen.js +20 -1
  24. package/dist/utils/version.js +2 -2
  25. package/package.json +13 -13
  26. package/src/api/artifacts.ts +2 -2
  27. package/src/api/build.ts +34 -11
  28. package/src/api/pre-publish.ts +8 -5
  29. package/src/api/templates/ci-template.ts +1 -3
  30. package/src/api/templates/ci.yml.ts +8 -2
  31. package/src/api/templates/js-binding.ts +8 -3
  32. package/src/api/templates/package.json.ts +31 -26
  33. package/src/commands/new.ts +1 -5
  34. package/src/utils/__tests__/__snapshots__/version.spec.ts.md +7 -7
  35. package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
  36. package/src/utils/__tests__/typegen.spec.ts +1 -1
  37. package/src/utils/config.ts +12 -1
  38. package/src/utils/typegen.ts +20 -1
  39. package/src/utils/version.ts +1 -1
@@ -32,6 +32,6 @@ test('should ident string correctly', (t) => {
32
32
  t.snapshot(correctStringIdent(input, 2), 'original ident is 2');
33
33
  });
34
34
  test('should process type def correctly', async (t) => {
35
- const dts = await processTypeDef(join(fileURLToPath(import.meta.url), '../', '__fixtures__', 'napi_type_def'));
35
+ const { dts } = await processTypeDef(join(fileURLToPath(import.meta.url), '../', '__fixtures__', 'napi_type_def'));
36
36
  t.snapshot(dts);
37
37
  });
@@ -42,7 +42,7 @@ interface UserNapiConfig {
42
42
  additional?: string[];
43
43
  };
44
44
  }
45
- interface CommonPackageJsonFields {
45
+ export interface CommonPackageJsonFields {
46
46
  name: string;
47
47
  version: string;
48
48
  description?: string;
@@ -56,6 +56,14 @@ interface CommonPackageJsonFields {
56
56
  publishConfig?: any;
57
57
  bugs?: any;
58
58
  napi?: UserNapiConfig;
59
+ type?: 'module' | 'commonjs';
60
+ scripts?: Record<string, string>;
61
+ main?: string;
62
+ module?: string;
63
+ types?: string;
64
+ exports?: any;
65
+ dependencies?: Record<string, string>;
66
+ devDependencies?: Record<string, string>;
59
67
  }
60
68
  export type NapiConfig = Required<Pick<UserNapiConfig, 'binaryName' | 'packageName' | 'npmClient'>> & {
61
69
  targets: Target[];
@@ -1,3 +1,6 @@
1
1
  export declare const DEFAULT_TYPE_DEF_HEADER = "/* auto-generated by NAPI-RS */\n/* eslint-disable */\n";
2
- export declare function processTypeDef(intermediateTypeFile: string, header?: string): Promise<string>;
2
+ export declare function processTypeDef(intermediateTypeFile: string, header?: string): Promise<{
3
+ dts: string;
4
+ exports: string[];
5
+ }>;
3
6
  export declare function correctStringIdent(src: string, ident: number): string;
@@ -34,6 +34,7 @@ function prettyPrint(line, ident) {
34
34
  return correctStringIdent(s, ident);
35
35
  }
36
36
  export async function processTypeDef(intermediateTypeFile, header) {
37
+ const exports = [];
37
38
  const defs = await readIntermediateTypeFile(intermediateTypeFile);
38
39
  const groupedDefs = preprocessTypeDef(defs);
39
40
  header = header ? header + '\n' : '';
@@ -42,9 +43,24 @@ export async function processTypeDef(intermediateTypeFile, header) {
42
43
  if (namespace === TOP_LEVEL_NAMESPACE) {
43
44
  for (const def of defs) {
44
45
  dts += prettyPrint(def, 0) + '\n\n';
46
+ switch (def.kind) {
47
+ case TypeDefKind.Const:
48
+ case TypeDefKind.Enum:
49
+ case TypeDefKind.Fn:
50
+ case TypeDefKind.Struct: {
51
+ exports.push(def.name);
52
+ if (def.original_name && def.original_name !== def.name) {
53
+ exports.push(def.original_name);
54
+ }
55
+ break;
56
+ }
57
+ default:
58
+ break;
59
+ }
45
60
  }
46
61
  }
47
62
  else {
63
+ exports.push(namespace);
48
64
  dts += `export namespace ${namespace} {\n`;
49
65
  for (const def of defs) {
50
66
  dts += prettyPrint(def, 2) + '\n';
@@ -62,7 +78,10 @@ export class ExternalObject<T> {
62
78
  }
63
79
  `;
64
80
  }
65
- return header + dts;
81
+ return {
82
+ dts: header + dts,
83
+ exports,
84
+ };
66
85
  }
67
86
  async function readIntermediateTypeFile(file) {
68
87
  const content = await readFileAsync(file, 'utf8');
@@ -8,7 +8,7 @@ export var NapiVersion;
8
8
  NapiVersion[NapiVersion["Napi6"] = 6] = "Napi6";
9
9
  NapiVersion[NapiVersion["Napi7"] = 7] = "Napi7";
10
10
  NapiVersion[NapiVersion["Napi8"] = 8] = "Napi8";
11
- })(NapiVersion = NapiVersion || (NapiVersion = {}));
11
+ })(NapiVersion || (NapiVersion = {}));
12
12
  /// because node support new napi version in some minor version updates, so we might meet such situation:
13
13
  /// `node v10.20.0` supports `napi5` and `napi6`, but `node v12.0.0` only support `napi4`,
14
14
  /// by which, we can not tell directly napi version supportness from node version directly.
@@ -52,7 +52,7 @@ function toEngineRequirement(versions) {
52
52
  req += `${i === 0 ? '' : ' || '}>= ${v.major}.${v.minor}.${v.patch}`;
53
53
  requirements.push(req);
54
54
  });
55
- return requirements.join(' && ');
55
+ return requirements.join(' ');
56
56
  }
57
57
  export function napiEngineRequirement(napiVersion) {
58
58
  return toEngineRequirement(requiredNodeVersions(napiVersion));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/cli",
3
- "version": "3.0.0-alpha.4",
3
+ "version": "3.0.0-alpha.5",
4
4
  "description": "Cli tools for napi-rs",
5
5
  "author": "LongYinan <lynweklm@gmail.com>",
6
6
  "homepage": "https://github.com/napi-rs/napi-rs",
@@ -67,24 +67,24 @@
67
67
  "url": "https://github.com/napi-rs/napi-rs/issues"
68
68
  },
69
69
  "dependencies": {
70
- "@octokit/rest": "^19.0.7",
71
- "clipanion": "^3.2.0",
72
- "colorette": "^2.0.19",
70
+ "@octokit/rest": "^20.0.1",
71
+ "clipanion": "^3.2.1",
72
+ "colorette": "^2.0.20",
73
73
  "debug": "^4.3.4",
74
- "inquirer": "^9.1.5",
74
+ "inquirer": "^9.2.8",
75
75
  "js-yaml": "^4.1.0",
76
76
  "lodash-es": "^4.17.21",
77
- "typanion": "^3.12.1"
77
+ "typanion": "^3.13.0"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@types/inquirer": "^9.0.3",
81
81
  "@types/js-yaml": "^4.0.5",
82
- "@types/lodash-es": "^4.17.7",
83
- "ava": "^5.2.0",
84
- "esbuild": "^0.17.16",
85
- "prettier": "^2.8.7",
82
+ "@types/lodash-es": "^4.17.8",
83
+ "ava": "^5.3.1",
84
+ "esbuild": "^0.18.13",
85
+ "prettier": "^3.0.0",
86
86
  "ts-node": "^10.9.1",
87
- "typescript": "^5.0.4"
87
+ "typescript": "^5.1.6"
88
88
  },
89
89
  "funding": {
90
90
  "type": "github",
@@ -94,7 +94,7 @@
94
94
  "codegen": "node --loader ts-node/esm/transpile-only ./codegen/index.ts",
95
95
  "build": "tsc && yarn build:cjs",
96
96
  "build:cjs": "node ./esbuild.mjs",
97
- "test": "ava"
97
+ "test": "node --loader ts-node/esm/transpile-only ../node_modules/ava/entrypoints/cli.mjs"
98
98
  },
99
- "gitHead": "0302e564faad54dcfe6c91c9a7f26749a6a0d8e8"
99
+ "gitHead": "cbed8fceb2996af195085aa13a94ff779879b999"
100
100
  }
@@ -30,8 +30,8 @@ export async function collectArtifacts(userOptions: ArtifactsOptions) {
30
30
  const universalSourceBins = new Set(
31
31
  targets
32
32
  .filter((platform) => platform.arch === 'universal')
33
- .flatMap((p) =>
34
- UniArchsByPlatform[p.platform]?.map((a) => `${p.platform}-${a}`),
33
+ .flatMap(
34
+ (p) => UniArchsByPlatform[p.platform]?.map((a) => `${p.platform}-${a}`),
35
35
  )
36
36
  .filter(Boolean) as string[],
37
37
  )
package/src/api/build.ts CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  writeFileAsync,
29
29
  } from '../utils/index.js'
30
30
 
31
- import { createJsBinding } from './templates/index.js'
31
+ import { createCjsBinding } from './templates/index.js'
32
32
 
33
33
  const debug = debugFactory('build')
34
34
 
@@ -149,6 +149,7 @@ class Builder {
149
149
 
150
150
  const controller = new AbortController()
151
151
 
152
+ const watch = this.options.watch
152
153
  const buildTask = new Promise<void>((resolve, reject) => {
153
154
  const command =
154
155
  process.env.CARGO ?? (this.options.useCross ? 'cross' : 'cargo')
@@ -157,7 +158,7 @@ class Builder {
157
158
  ...process.env,
158
159
  ...this.envs,
159
160
  },
160
- stdio: 'inherit',
161
+ stdio: watch ? ['inherit', 'inherit', 'pipe'] : 'inherit',
161
162
  cwd: this.cwd,
162
163
  signal: controller.signal,
163
164
  })
@@ -178,6 +179,15 @@ class Builder {
178
179
  }),
179
180
  )
180
181
  })
182
+
183
+ // watch mode only, they are piped through stderr
184
+ buildProcess.stderr?.on('data', (data) => {
185
+ const output = data.toString()
186
+ console.error(output)
187
+ if (/Finished\s(dev|release)/.test(output)) {
188
+ this.postBuild().catch(() => {})
189
+ }
190
+ })
181
191
  })
182
192
 
183
193
  return {
@@ -207,6 +217,7 @@ class Builder {
207
217
  this.crateDir,
208
218
  '--',
209
219
  'cargo',
220
+ 'build',
210
221
  )
211
222
  set = true
212
223
  }
@@ -452,8 +463,8 @@ class Builder {
452
463
 
453
464
  // only for cdylib
454
465
  if (this.cdyLibName) {
455
- await this.generateTypeDef()
456
- await this.writeJsBinding()
466
+ const idents = await this.generateTypeDef()
467
+ await this.writeJsBinding(idents)
457
468
  }
458
469
 
459
470
  return this.outputs
@@ -523,12 +534,12 @@ class Builder {
523
534
 
524
535
  private async generateTypeDef() {
525
536
  if (!(await fileExists(this.envs.TYPE_DEF_TMP_PATH))) {
526
- return
537
+ return []
527
538
  }
528
539
 
529
540
  const dest = join(this.outputDir, this.options.dts ?? 'index.d.ts')
530
541
 
531
- const dts = await processTypeDef(
542
+ const { dts, exports } = await processTypeDef(
532
543
  this.envs.TYPE_DEF_TMP_PATH,
533
544
  !this.options.noDtsHeader
534
545
  ? this.options.dtsHeader ?? DEFAULT_TYPE_DEF_HEADER
@@ -547,21 +558,33 @@ class Builder {
547
558
  debug.error('Failed to write type def file')
548
559
  debug.error(e as Error)
549
560
  }
561
+
562
+ return exports
550
563
  }
551
564
 
552
- private async writeJsBinding() {
553
- if (!this.options.platform || this.options.noJsBinding) {
565
+ private async writeJsBinding(idents: string[]) {
566
+ if (
567
+ !this.options.platform ||
568
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
569
+ this.options.noJsBinding ||
570
+ idents.length === 0
571
+ ) {
554
572
  return
555
573
  }
556
574
 
557
- const dest = join(this.outputDir, this.options.jsBinding ?? 'index.js')
575
+ const name = parse(this.options.jsBinding ?? 'index.js').name
558
576
 
559
- const js = createJsBinding(this.config.binaryName, this.config.packageName)
577
+ const cjs = createCjsBinding(
578
+ this.config.binaryName,
579
+ this.config.packageName,
580
+ idents,
581
+ )
560
582
 
561
583
  try {
584
+ const dest = join(this.outputDir, `${name}.js`)
562
585
  debug('Writing js binding to:')
563
586
  debug(' %i', dest)
564
- await writeFileAsync(dest, js, 'utf-8')
587
+ await writeFileAsync(dest, cjs, 'utf-8')
565
588
  this.outputs.push({
566
589
  kind: 'js',
567
590
  path: dest,
@@ -129,11 +129,14 @@ export async function prePublish(userOptions: PrePublishOptions) {
129
129
  if (!options.dryRun) {
130
130
  await version(userOptions)
131
131
  await updatePackageJson(packageJsonPath, {
132
- optionalDependencies: targets.reduce((deps, target) => {
133
- deps[`${packageName}-${target.platformArchABI}`] = packageJson.version
134
-
135
- return deps
136
- }, {} as Record<string, string>),
132
+ optionalDependencies: targets.reduce(
133
+ (deps, target) => {
134
+ deps[`${packageName}-${target.platformArchABI}`] = packageJson.version
135
+
136
+ return deps
137
+ },
138
+ {} as Record<string, string>,
139
+ ),
137
140
  })
138
141
  }
139
142
 
@@ -198,9 +198,7 @@ jobs:
198
198
  usesh: true
199
199
  mem: 3000
200
200
  prepare: |
201
- pkg install -y -f curl node libnghttp2
202
- curl -qL https://www.npmjs.com/install.sh | sh
203
- npm install --location=global --ignore-scripts yarn
201
+ pkg install -y -f curl node libnghttp2 npm yarn
204
202
  curl https://sh.rustup.rs -sSf --output rustup.sh
205
203
  sh rustup.sh -y --profile minimal --default-toolchain beta
206
204
  export PATH="/usr/local/cargo/bin:$PATH"
@@ -63,10 +63,16 @@ export const createGithubActionsCIYml = (
63
63
  if (!enableWindowsX86 && !enableMacOSX86) {
64
64
  delete fullTemplate.jobs[TEST_MACOS_WINDOWS]
65
65
  } else {
66
- const filterTarget = enableWindowsX86 ? 'macos-latest' : 'windows-latest'
66
+ const filterTargets = new Set<string>()
67
+ if (enableWindowsX86) {
68
+ filterTargets.add('windows-latest')
69
+ }
70
+ if (enableMacOSUni || enableMacOSX86) {
71
+ filterTargets.add('macos-latest')
72
+ }
67
73
  fullTemplate.jobs[TEST_MACOS_WINDOWS].strategy.matrix.settings =
68
74
  fullTemplate.jobs[TEST_MACOS_WINDOWS].strategy.matrix.settings.filter(
69
- ({ host }: { host: string; target: string }) => host !== filterTarget,
75
+ ({ host }: { host: string; target: string }) => filterTargets.has(host),
70
76
  )
71
77
 
72
78
  requiredSteps.push(TEST_MACOS_WINDOWS)
@@ -1,8 +1,10 @@
1
- export function createJsBinding(localName: string, pkgName: string): string {
1
+ export function createCjsBinding(
2
+ localName: string,
3
+ pkgName: string,
4
+ idents: string[],
5
+ ): string {
2
6
  return `// prettier-ignore
3
- /* tslint:disable */
4
7
  /* eslint-disable */
5
-
6
8
  /* auto-generated by NAPI-RS */
7
9
 
8
10
  const { existsSync, readFileSync } = require('fs')
@@ -253,5 +255,8 @@ if (!nativeBinding) {
253
255
  throw new Error(\`Failed to load native binding\`)
254
256
  }
255
257
 
258
+ ${idents
259
+ .map((ident) => `module.exports.${ident} = binding.${ident}`)
260
+ .join('\n')}
256
261
  `
257
262
  }
@@ -1,3 +1,5 @@
1
+ import { CommonPackageJsonFields } from '../../utils/config.js'
2
+
1
3
  export const createPackageJson = ({
2
4
  name,
3
5
  binaryName,
@@ -13,31 +15,34 @@ export const createPackageJson = ({
13
15
  engineRequirement: string
14
16
  cliVersion: string
15
17
  }) => {
16
- return `{
17
- "name": "${name}",
18
- "version": "1.0.0",
19
- "main": "index.js",
20
- "types": "index.d.ts",
21
- "license": "${license}",
22
- "engines": {
23
- "node": "${engineRequirement}"
24
- },
25
- "napi": {
26
- "binaryName": "${binaryName}",
27
- "targets": [
28
- ${targets.map((t) => `"${t}"`).join(',\n ')}
29
- ]
30
- },
31
- "scripts": {
32
- "test": "node -e \\"assert(require('.').sum(1, 2) === 3)\\"",
33
- "build": "napi build --release --platform --strip",
34
- "build:debug": "napi build",
35
- "prepublishOnly": "napi prepublish -t npm",
36
- "artifacts": "napi artifacts",
37
- "version": "napi version"
38
- },
39
- "devDependencies": {
40
- "@napi-rs/cli": "^${cliVersion}"
18
+ const content: CommonPackageJsonFields = {
19
+ name,
20
+ version: '1.0.0',
21
+ license,
22
+ engines: {
23
+ node: engineRequirement,
24
+ },
25
+ type: 'commonjs',
26
+ main: 'index.js',
27
+ types: 'index.d.ts',
28
+ module: undefined,
29
+ exports: undefined,
30
+ napi: {
31
+ binaryName,
32
+ targets,
33
+ },
34
+ scripts: {
35
+ test: 'node -e "assert(require(\'.\').sum(1, 2) === 3)"',
36
+ build: 'napi build --release --platform --strip',
37
+ 'build:debug': 'napi build',
38
+ prepublishOnly: 'napi prepublish -t npm',
39
+ artifacts: 'napi artifacts',
40
+ version: 'napi version',
41
+ },
42
+ devDependencies: {
43
+ '@napi-rs/cli': `^${cliVersion}`,
44
+ },
41
45
  }
42
- }`
46
+
47
+ return JSON.stringify(content, null, 2)
43
48
  }
@@ -94,10 +94,6 @@ export class NewCommand extends BaseNewCommand {
94
94
  }
95
95
 
96
96
  private async fetchTargets(): Promise<TargetTriple[]> {
97
- if (this.enableDefaultTargets) {
98
- return DEFAULT_TARGETS.concat()
99
- }
100
-
101
97
  if (this.enableAllTargets) {
102
98
  return AVAILABLE_TARGETS.concat()
103
99
  }
@@ -107,7 +103,7 @@ export class NewCommand extends BaseNewCommand {
107
103
  type: 'checkbox',
108
104
  loop: false,
109
105
  message: 'Choose target(s) your crate will be compiled to',
110
- default: DEFAULT_TARGETS,
106
+ default: this.enableDefaultTargets ? DEFAULT_TARGETS : [],
111
107
  choices: AVAILABLE_TARGETS,
112
108
  })
113
109
 
@@ -10,11 +10,11 @@ Generated by [AVA](https://avajs.dev).
10
10
 
11
11
  [
12
12
  '>= 8.6.0',
13
- '>= 8.10.0 && < 9 || >= 9.3.0',
14
- '>= 6.14.2 && < 7 || >= 8.11.2 && < 9 || >= 9.11.0',
15
- '>= 10.16.0 && < 11 || >= 11.8.0',
16
- '>= 10.17.0 && < 11 || >= 12.11.0',
17
- '>= 10.20.0 && < 11 || >= 12.17.0 && < 13 || >= 14.0.0',
18
- '>= 10.23.0 && < 11 || >= 12.19.0 && < 13 || >= 14.12.0',
19
- '>= 12.22.0 && < 13 || >= 14.17.0 && < 15 || >= 15.12.0',
13
+ '>= 8.10.0 < 9 || >= 9.3.0',
14
+ '>= 6.14.2 < 7 || >= 8.11.2 < 9 || >= 9.11.0',
15
+ '>= 10.16.0 < 11 || >= 11.8.0',
16
+ '>= 10.17.0 < 11 || >= 12.11.0',
17
+ '>= 10.20.0 < 11 || >= 12.17.0 < 13 || >= 14.0.0',
18
+ '>= 10.23.0 < 11 || >= 12.19.0 < 13 || >= 14.12.0',
19
+ '>= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0',
20
20
  ]
@@ -36,7 +36,7 @@ test('should ident string correctly', (t) => {
36
36
  })
37
37
 
38
38
  test('should process type def correctly', async (t) => {
39
- const dts = await processTypeDef(
39
+ const { dts } = await processTypeDef(
40
40
  join(
41
41
  fileURLToPath(import.meta.url),
42
42
  '../',
@@ -49,7 +49,7 @@ interface UserNapiConfig {
49
49
  }
50
50
  }
51
51
 
52
- interface CommonPackageJsonFields {
52
+ export interface CommonPackageJsonFields {
53
53
  name: string
54
54
  version: string
55
55
  description?: string
@@ -64,6 +64,17 @@ interface CommonPackageJsonFields {
64
64
  bugs?: any
65
65
  // eslint-disable-next-line no-use-before-define
66
66
  napi?: UserNapiConfig
67
+ type?: 'module' | 'commonjs'
68
+ scripts?: Record<string, string>
69
+
70
+ // modules
71
+ main?: string
72
+ module?: string
73
+ types?: string
74
+ exports?: any
75
+
76
+ dependencies?: Record<string, string>
77
+ devDependencies?: Record<string, string>
67
78
  }
68
79
 
69
80
  export type NapiConfig = Required<
@@ -54,6 +54,7 @@ export async function processTypeDef(
54
54
  intermediateTypeFile: string,
55
55
  header?: string,
56
56
  ) {
57
+ const exports: string[] = []
57
58
  const defs = await readIntermediateTypeFile(intermediateTypeFile)
58
59
  const groupedDefs = preprocessTypeDef(defs)
59
60
 
@@ -65,8 +66,23 @@ export async function processTypeDef(
65
66
  if (namespace === TOP_LEVEL_NAMESPACE) {
66
67
  for (const def of defs) {
67
68
  dts += prettyPrint(def, 0) + '\n\n'
69
+ switch (def.kind) {
70
+ case TypeDefKind.Const:
71
+ case TypeDefKind.Enum:
72
+ case TypeDefKind.Fn:
73
+ case TypeDefKind.Struct: {
74
+ exports.push(def.name)
75
+ if (def.original_name && def.original_name !== def.name) {
76
+ exports.push(def.original_name)
77
+ }
78
+ break
79
+ }
80
+ default:
81
+ break
82
+ }
68
83
  }
69
84
  } else {
85
+ exports.push(namespace)
70
86
  dts += `export namespace ${namespace} {\n`
71
87
  for (const def of defs) {
72
88
  dts += prettyPrint(def, 2) + '\n'
@@ -87,7 +103,10 @@ export class ExternalObject<T> {
87
103
  `
88
104
  }
89
105
 
90
- return header + dts
106
+ return {
107
+ dts: header + dts,
108
+ exports,
109
+ }
91
110
  }
92
111
 
93
112
  async function readIntermediateTypeFile(file: string) {
@@ -68,7 +68,7 @@ function toEngineRequirement(versions: NodeVersion[]): string {
68
68
  requirements.push(req)
69
69
  })
70
70
 
71
- return requirements.join(' && ')
71
+ return requirements.join(' ')
72
72
  }
73
73
 
74
74
  export function napiEngineRequirement(napiVersion: NapiVersion): string {