@napi-rs/cli 3.0.0-alpha.91 → 3.0.0-alpha.92

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/cli",
3
- "version": "3.0.0-alpha.91",
3
+ "version": "3.0.0-alpha.92",
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",
@@ -96,7 +96,7 @@
96
96
  "ava": "^6.2.0",
97
97
  "env-paths": "^3.0.0",
98
98
  "prettier": "^3.5.3",
99
- "rolldown": "^1.0.0-beta.19",
99
+ "rolldown": "^1.0.0-beta.23",
100
100
  "tslib": "^2.8.1",
101
101
  "typescript": "^5.8.2"
102
102
  },
@@ -132,5 +132,5 @@
132
132
  "e2e/**/*.spec.ts"
133
133
  ]
134
134
  },
135
- "gitHead": "71da5b6dc17064e478e5beb0ffa71f73d6238f7d"
135
+ "gitHead": "e9e806e92092e05bb5ed0c7fb9a30705bd09760e"
136
136
  }
package/src/api/build.ts CHANGED
@@ -270,16 +270,14 @@ class Builder {
270
270
  'include/',
271
271
  )
272
272
  }
273
- if (!process.env.CC && !process.env.TARGET_CC) {
274
- this.envs[`CC`] = join(toolchainPath, 'bin', `${crossTargetName}-gcc`)
273
+ if (!process.env.TARGET_CC) {
275
274
  this.envs[`TARGET_CC`] = join(
276
275
  toolchainPath,
277
276
  'bin',
278
277
  `${crossTargetName}-gcc`,
279
278
  )
280
279
  }
281
- if (!process.env.CXX && !process.env.TARGET_CXX) {
282
- this.envs[`CXX`] = join(toolchainPath, 'bin', `${crossTargetName}-g++`)
280
+ if (!process.env.TARGET_CXX) {
283
281
  this.envs[`TARGET_CXX`] = join(
284
282
  toolchainPath,
285
283
  'bin',
@@ -287,22 +285,18 @@ class Builder {
287
285
  )
288
286
  }
289
287
  if (
290
- (process.env.CC?.startsWith('clang') &&
291
- (process.env.TARGET_CC?.startsWith('clang') ||
292
- !process.env.TARGET_CC)) ||
293
- process.env.TARGET_CC?.startsWith('clang')
288
+ process.env.TARGET_CC?.startsWith('clang') ||
289
+ (process.env.CC?.startsWith('clang') && !process.env.TARGET_CC)
294
290
  ) {
295
- const CFLAGS = process.env.CFLAGS ?? ''
296
- this.envs.CFLAGS = `--sysroot=${this.envs.TARGET_SYSROOT} --gcc-toolchain=${toolchainPath} ${CFLAGS}`
291
+ const TARGET_CFLAGS = process.env.TARGET_CFLAGS ?? ''
292
+ this.envs.TARGET_CFLAGS = `--sysroot=${this.envs.TARGET_SYSROOT} --gcc-toolchain=${toolchainPath} ${TARGET_CFLAGS}`
297
293
  }
298
294
  if (
299
- (process.env.CXX?.startsWith('clang++') &&
300
- (process.env.TARGET_CXX?.startsWith('clang++') ||
301
- !process.env.TARGET_CXX)) ||
295
+ (process.env.CXX?.startsWith('clang++') && !process.env.TARGET_CXX) ||
302
296
  process.env.TARGET_CXX?.startsWith('clang++')
303
297
  ) {
304
- const CXXFLAGS = process.env.CXXFLAGS ?? ''
305
- this.envs.CXXFLAGS = `--sysroot=${this.envs.TARGET_SYSROOT} --gcc-toolchain=${toolchainPath} ${CXXFLAGS} ${CXXFLAGS}`
298
+ const TARGET_CXXFLAGS = process.env.TARGET_CXXFLAGS ?? ''
299
+ this.envs.TARGET_CXXFLAGS = `--sysroot=${this.envs.TARGET_SYSROOT} --gcc-toolchain=${toolchainPath} ${TARGET_CXXFLAGS}`
306
300
  }
307
301
  this.envs.PATH = this.envs.PATH
308
302
  ? `${toolchainPath}/bin:${this.envs.PATH}:${process.env.PATH}`
@@ -905,6 +899,12 @@ export declare class ExternalObject<T> {
905
899
  `
906
900
  }
907
901
 
902
+ if (dts.indexOf('TypedArray') > -1) {
903
+ header += `
904
+ export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array
905
+ `
906
+ }
907
+
908
908
  dts = header + dts
909
909
 
910
910
  try {
@@ -15,10 +15,12 @@ import {
15
15
  Target,
16
16
  } from '../utils/index.js'
17
17
 
18
- import type { PackageMeta } from './templates/package.json.js'
19
-
20
18
  const debug = debugFactory('create-npm-dirs')
21
19
 
20
+ export interface PackageMeta {
21
+ 'dist-tags': { [index: string]: string }
22
+ }
23
+
22
24
  export async function createNpmDirs(userOptions: CreateNpmDirsOptions) {
23
25
  const options = applyDefaultCreateNpmDirsOptions(userOptions)
24
26
 
@@ -1,8 +1 @@
1
- export * from './.gitignore.js'
2
- export * from './.npmignore.js'
3
- export * from './build.rs.js'
4
- export * from './cargo.toml.js'
5
- export * from './ci.yml.js'
6
- export * from './lib.rs.js'
7
- export * from './package.json.js'
8
1
  export * from './js-binding.js'
@@ -160,6 +160,29 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
160
160
  worker.onmessage = ({ data }) => {
161
161
  __wasmCreateOnMessageForFsProxy(__nodeFs)(data)
162
162
  }
163
+
164
+ // The main thread of Node.js waits for all the active handles before exiting.
165
+ // But Rust threads are never waited without \`thread::join\`.
166
+ // So here we hack the code of Node.js to prevent the workers from being referenced (active).
167
+ // According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
168
+ // a worker is consist of two handles: kPublicPort and kHandle.
169
+ {
170
+ const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
171
+ s.toString().includes("kPublicPort")
172
+ );
173
+ if (kPublicPort) {
174
+ worker[kPublicPort].ref = () => {};
175
+ }
176
+
177
+ const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
178
+ s.toString().includes("kHandle")
179
+ );
180
+ if (kPublicPort) {
181
+ worker[kHandle].ref = () => {};
182
+ }
183
+
184
+ worker.unref();
185
+ }
163
186
  return worker
164
187
  },
165
188
  overwriteImports(importObject) {
@@ -234,6 +234,15 @@ export async function readNapiConfig(
234
234
  }
235
235
  }
236
236
 
237
+ // find duplicate targets
238
+ const uniqueTargets = new Set(targets)
239
+ if (uniqueTargets.size !== targets.length) {
240
+ const duplicateTarget = targets.find(
241
+ (target, index) => targets.indexOf(target) !== index,
242
+ )
243
+ throw new Error(`Duplicate targets are not allowed: ${duplicateTarget}`)
244
+ }
245
+
237
246
  napiConfig.targets = targets.map(parseTriple)
238
247
 
239
248
  return napiConfig
@@ -1 +0,0 @@
1
- export declare const gitIgnore = "# Created by https://www.toptal.com/developers/gitignore/api/node\n# Edit at https://www.toptal.com/developers/gitignore?templates=node\n\n### Node ###\n# Logs\nlogs\n*.log\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\nlerna-debug.log*\n\n# Diagnostic reports (https://nodejs.org/api/report.html)\nreport.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json\n\n# Runtime data\npids\n*.pid\n*.seed\n*.pid.lock\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n*.lcov\n\n# nyc test coverage\n.nyc_output\n\n# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)\n.grunt\n\n# Bower dependency directory (https://bower.io/)\nbower_components\n\n# node-waf configuration\n.lock-wscript\n\n# Compiled binary addons (https://nodejs.org/api/addons.html)\nbuild/Release\n\n# Dependency directories\nnode_modules/\njspm_packages/\n\n# TypeScript v1 declaration files\ntypings/\n\n# TypeScript cache\n*.tsbuildinfo\n\n# Optional npm cache directory\n.npm\n\n# Optional eslint cache\n.eslintcache\n\n# Microbundle cache\n.rpt2_cache/\n.rts2_cache_cjs/\n.rts2_cache_es/\n.rts2_cache_umd/\n\n# Optional REPL history\n.node_repl_history\n\n# Output of 'npm pack'\n*.tgz\n\n# Yarn Integrity file\n.yarn-integrity\n\n# dotenv environment variables file\n.env\n.env.test\n\n# parcel-bundler cache (https://parceljs.org/)\n.cache\n\n# Next.js build output\n.next\n\n# Nuxt.js build / generate output\n.nuxt\ndist\n\n# Gatsby files\n.cache/\n# Comment in the public line in if your project uses Gatsby and not Next.js\n# https://nextjs.org/blog/next-9-1#public-directory-support\n# public\n\n# vuepress build output\n.vuepress/dist\n\n# Serverless directories\n.serverless/\n\n# FuseBox cache\n.fusebox/\n\n# DynamoDB Local files\n.dynamodb/\n\n# TernJS port file\n.tern-port\n\n# Stores VSCode versions used for testing VSCode extensions\n.vscode-test\n\n# End of https://www.toptal.com/developers/gitignore/api/node\n\n# Created by https://www.toptal.com/developers/gitignore/api/macos\n# Edit at https://www.toptal.com/developers/gitignore?templates=macos\n\n### macOS ###\n# General\n.DS_Store\n.AppleDouble\n.LSOverride\n\n# Icon must end with two \r\nIcon\n\n\n# Thumbnails\n._*\n\n# Files that might appear in the root of a volume\n.DocumentRevisions-V100\n.fseventsd\n.Spotlight-V100\n.TemporaryItems\n.Trashes\n.VolumeIcon.icns\n.com.apple.timemachine.donotpresent\n\n# Directories potentially created on remote AFP share\n.AppleDB\n.AppleDesktop\nNetwork Trash Folder\nTemporary Items\n.apdisk\n\n### macOS Patch ###\n# iCloud generated files\n*.icloud\n\n# End of https://www.toptal.com/developers/gitignore/api/macos\n\n# Created by https://www.toptal.com/developers/gitignore/api/windows\n# Edit at https://www.toptal.com/developers/gitignore?templates=windows\n\n### Windows ###\n# Windows thumbnail cache files\nThumbs.db\nThumbs.db:encryptable\nehthumbs.db\nehthumbs_vista.db\n\n# Dump file\n*.stackdump\n\n# Folder config file\n[Dd]esktop.ini\n\n# Recycle Bin used on file shares\n$RECYCLE.BIN/\n\n# Windows Installer files\n*.cab\n*.msi\n*.msix\n*.msm\n*.msp\n\n# Windows shortcuts\n*.lnk\n\n# End of https://www.toptal.com/developers/gitignore/api/windows\n\n#Added by cargo\n\n/target\nCargo.lock\n\n.pnp.*\n.yarn/*\n!.yarn/patches\n!.yarn/plugins\n!.yarn/releases\n!.yarn/sdks\n!.yarn/versions\n\n*.node\n*.wasm\n";
@@ -1 +0,0 @@
1
- export declare const npmIgnore = "target\nCargo.lock\n.cargo\n.github\nnpm\n.eslintrc\n.prettierignore\nrustfmt.toml\nyarn.lock\n*.node\n.yarn\n__test__\nrenovate.json\n";
@@ -1 +0,0 @@
1
- export declare const createBuildRs: () => string;
@@ -1,6 +0,0 @@
1
- export declare const createCargoToml: ({ name, license, features, deriveFeatures, }: {
2
- name: string;
3
- license: string;
4
- features: string[];
5
- deriveFeatures: string[];
6
- }) => string;
@@ -1,3 +0,0 @@
1
- import type { SupportedPackageManager } from '../../utils/config.js';
2
- export type WasiTargetName = 'wasm32-wasi-preview1-threads' | 'wasm32-wasip1-threads' | 'wasm32-wasip2';
3
- export declare const YAML: (packageManager: SupportedPackageManager, wasiTargetName: WasiTargetName) => string;
@@ -1,3 +0,0 @@
1
- import { type SupportedPackageManager } from '../../utils/index.js';
2
- import { type WasiTargetName } from './ci-template.js';
3
- export declare const createGithubActionsCIYml: (targets: string[], packageManager: SupportedPackageManager, wasiTargetName: WasiTargetName) => string;
@@ -1 +0,0 @@
1
- export declare const createLibRs: () => string;
@@ -1,15 +0,0 @@
1
- import type { SupportedTestFramework } from '../../utils/config.js';
2
- export interface PackageMeta {
3
- 'dist-tags': {
4
- [index: string]: string;
5
- };
6
- }
7
- export declare const createPackageJson: ({ name, binaryName, targets, license, engineRequirement, cliVersion, testFramework, }: {
8
- name: string;
9
- binaryName: string;
10
- targets: string[];
11
- license: string;
12
- engineRequirement: string;
13
- cliVersion: string;
14
- testFramework: SupportedTestFramework;
15
- }) => Promise<string>;
@@ -1,199 +0,0 @@
1
- export const gitIgnore = `# Created by https://www.toptal.com/developers/gitignore/api/node
2
- # Edit at https://www.toptal.com/developers/gitignore?templates=node
3
-
4
- ### Node ###
5
- # Logs
6
- logs
7
- *.log
8
- npm-debug.log*
9
- yarn-debug.log*
10
- yarn-error.log*
11
- lerna-debug.log*
12
-
13
- # Diagnostic reports (https://nodejs.org/api/report.html)
14
- report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
15
-
16
- # Runtime data
17
- pids
18
- *.pid
19
- *.seed
20
- *.pid.lock
21
-
22
- # Directory for instrumented libs generated by jscoverage/JSCover
23
- lib-cov
24
-
25
- # Coverage directory used by tools like istanbul
26
- coverage
27
- *.lcov
28
-
29
- # nyc test coverage
30
- .nyc_output
31
-
32
- # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
33
- .grunt
34
-
35
- # Bower dependency directory (https://bower.io/)
36
- bower_components
37
-
38
- # node-waf configuration
39
- .lock-wscript
40
-
41
- # Compiled binary addons (https://nodejs.org/api/addons.html)
42
- build/Release
43
-
44
- # Dependency directories
45
- node_modules/
46
- jspm_packages/
47
-
48
- # TypeScript v1 declaration files
49
- typings/
50
-
51
- # TypeScript cache
52
- *.tsbuildinfo
53
-
54
- # Optional npm cache directory
55
- .npm
56
-
57
- # Optional eslint cache
58
- .eslintcache
59
-
60
- # Microbundle cache
61
- .rpt2_cache/
62
- .rts2_cache_cjs/
63
- .rts2_cache_es/
64
- .rts2_cache_umd/
65
-
66
- # Optional REPL history
67
- .node_repl_history
68
-
69
- # Output of 'npm pack'
70
- *.tgz
71
-
72
- # Yarn Integrity file
73
- .yarn-integrity
74
-
75
- # dotenv environment variables file
76
- .env
77
- .env.test
78
-
79
- # parcel-bundler cache (https://parceljs.org/)
80
- .cache
81
-
82
- # Next.js build output
83
- .next
84
-
85
- # Nuxt.js build / generate output
86
- .nuxt
87
- dist
88
-
89
- # Gatsby files
90
- .cache/
91
- # Comment in the public line in if your project uses Gatsby and not Next.js
92
- # https://nextjs.org/blog/next-9-1#public-directory-support
93
- # public
94
-
95
- # vuepress build output
96
- .vuepress/dist
97
-
98
- # Serverless directories
99
- .serverless/
100
-
101
- # FuseBox cache
102
- .fusebox/
103
-
104
- # DynamoDB Local files
105
- .dynamodb/
106
-
107
- # TernJS port file
108
- .tern-port
109
-
110
- # Stores VSCode versions used for testing VSCode extensions
111
- .vscode-test
112
-
113
- # End of https://www.toptal.com/developers/gitignore/api/node
114
-
115
- # Created by https://www.toptal.com/developers/gitignore/api/macos
116
- # Edit at https://www.toptal.com/developers/gitignore?templates=macos
117
-
118
- ### macOS ###
119
- # General
120
- .DS_Store
121
- .AppleDouble
122
- .LSOverride
123
-
124
- # Icon must end with two \r
125
- Icon
126
-
127
-
128
- # Thumbnails
129
- ._*
130
-
131
- # Files that might appear in the root of a volume
132
- .DocumentRevisions-V100
133
- .fseventsd
134
- .Spotlight-V100
135
- .TemporaryItems
136
- .Trashes
137
- .VolumeIcon.icns
138
- .com.apple.timemachine.donotpresent
139
-
140
- # Directories potentially created on remote AFP share
141
- .AppleDB
142
- .AppleDesktop
143
- Network Trash Folder
144
- Temporary Items
145
- .apdisk
146
-
147
- ### macOS Patch ###
148
- # iCloud generated files
149
- *.icloud
150
-
151
- # End of https://www.toptal.com/developers/gitignore/api/macos
152
-
153
- # Created by https://www.toptal.com/developers/gitignore/api/windows
154
- # Edit at https://www.toptal.com/developers/gitignore?templates=windows
155
-
156
- ### Windows ###
157
- # Windows thumbnail cache files
158
- Thumbs.db
159
- Thumbs.db:encryptable
160
- ehthumbs.db
161
- ehthumbs_vista.db
162
-
163
- # Dump file
164
- *.stackdump
165
-
166
- # Folder config file
167
- [Dd]esktop.ini
168
-
169
- # Recycle Bin used on file shares
170
- $RECYCLE.BIN/
171
-
172
- # Windows Installer files
173
- *.cab
174
- *.msi
175
- *.msix
176
- *.msm
177
- *.msp
178
-
179
- # Windows shortcuts
180
- *.lnk
181
-
182
- # End of https://www.toptal.com/developers/gitignore/api/windows
183
-
184
- #Added by cargo
185
-
186
- /target
187
- Cargo.lock
188
-
189
- .pnp.*
190
- .yarn/*
191
- !.yarn/patches
192
- !.yarn/plugins
193
- !.yarn/releases
194
- !.yarn/sdks
195
- !.yarn/versions
196
-
197
- *.node
198
- *.wasm
199
- `
@@ -1,14 +0,0 @@
1
- export const npmIgnore = `target
2
- Cargo.lock
3
- .cargo
4
- .github
5
- npm
6
- .eslintrc
7
- .prettierignore
8
- rustfmt.toml
9
- yarn.lock
10
- *.node
11
- .yarn
12
- __test__
13
- renovate.json
14
- `
@@ -1,4 +0,0 @@
1
- export const createBuildRs = () => `fn main() {
2
- napi_build::setup();
3
- }
4
- `
@@ -1,36 +0,0 @@
1
- export const createCargoToml = ({
2
- name,
3
- license,
4
- features,
5
- deriveFeatures,
6
- }: {
7
- name: string
8
- license: string
9
- features: string[]
10
- deriveFeatures: string[]
11
- }) => `[package]
12
- name = "${name.replace('@', '').replace('/', '_').toLowerCase()}"
13
- version = "1.0.0"
14
- edition = "2021"
15
- license = "${license}"
16
-
17
- [lib]
18
- crate-type = ["cdylib"]
19
-
20
- [dependencies.napi]
21
- version = "2"
22
- default-features = false
23
- # see https://nodejs.org/api/n-api.html#node-api-version-matrix
24
- features = ${JSON.stringify(features)}
25
-
26
- [dependencies.napi-derive]
27
- version = "2"
28
- features = ${JSON.stringify(deriveFeatures)}
29
-
30
- [build-dependencies]
31
- napi-build = "2"
32
-
33
- [profile.release]
34
- lto = true
35
- strip = "symbols"
36
- `