@napi-rs/cli 3.8.6 → 3.9.1
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/dist/cli.js +9085 -8737
- package/dist/index.cjs +9092 -8744
- package/dist/index.d.cts +37 -17
- package/dist/index.d.ts +37 -17
- package/dist/index.js +9085 -8737
- package/docs/build.md +36 -34
- package/package.json +4 -5
- package/src/api/__tests__/__snapshots__/templates.spec.ts.md +9 -13
- package/src/api/__tests__/__snapshots__/templates.spec.ts.snap +0 -0
- package/src/api/__tests__/build.spec.ts +284 -0
- package/src/api/__tests__/create-npm-dirs.spec.ts +4 -3
- package/src/api/__tests__/templates.spec.ts +84 -1
- package/src/api/build.ts +181 -7
- package/src/api/create-npm-dirs.ts +2 -1
- package/src/api/new.ts +13 -18
- package/src/api/pre-publish.ts +5 -10
- package/src/api/rename.ts +10 -21
- package/src/api/templates/js-binding.ts +7 -9
- package/src/api/templates/load-wasi-template.ts +20 -17
- package/src/api/templates/wasi-worker-template.ts +36 -31
- package/src/commands/__tests__/build.spec.ts +24 -0
- package/src/commands/build.ts +1 -1
- package/src/def/build.ts +30 -4
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +18 -28
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
- package/src/utils/__tests__/misc.spec.ts +4 -0
- package/src/utils/__tests__/serialize.spec.ts +55 -0
- package/src/utils/__tests__/target.spec.ts +221 -0
- package/src/utils/__tests__/typegen.spec.ts +115 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/misc.ts +4 -5
- package/src/utils/serialize.ts +47 -0
- package/src/utils/target.ts +150 -1
- package/src/utils/typegen.ts +241 -30
|
@@ -13,11 +13,11 @@ let __emnapiWasmEnvCleanupDrained = false
|
|
|
13
13
|
let __emnapiWasmEnvCleanupDrainPromise
|
|
14
14
|
let __wasiDisposed = false
|
|
15
15
|
let __wasiDisposePromise
|
|
16
|
-
let __completeWasiDisposal = function() {}
|
|
16
|
+
let __completeWasiDisposal = function () {}
|
|
17
17
|
// Overridden by loader flavors that have a last-resort reclaim for a rollback
|
|
18
18
|
// that stopped short of destroying the context. See
|
|
19
19
|
// \`__rollbackWasiInitialization\`.
|
|
20
|
-
let __retainWasiRollbackForRetry = function() {}
|
|
20
|
+
let __retainWasiRollbackForRetry = function () {}
|
|
21
21
|
|
|
22
22
|
function __isThenable(value) {
|
|
23
23
|
return (
|
|
@@ -1923,6 +1923,7 @@ function __createWasiWorker(filename) {
|
|
|
1923
1923
|
return new Worker(filename, {
|
|
1924
1924
|
env: process.env,
|
|
1925
1925
|
execArgv: __workerExecArgv,
|
|
1926
|
+
workerData: { hostRoot: __hostRoot, rootDir: __rootDir },
|
|
1926
1927
|
})
|
|
1927
1928
|
} catch (error) {
|
|
1928
1929
|
if (!error || error.code !== 'ERR_WORKER_INVALID_EXEC_ARGV') {
|
|
@@ -1944,7 +1945,7 @@ function __createWasiWorker(filename) {
|
|
|
1944
1945
|
: ''
|
|
1945
1946
|
const memoryName = threads ? '__sharedMemory' : '__wasmMemory'
|
|
1946
1947
|
const asyncWorkOptions = threads
|
|
1947
|
-
? ` asyncWorkPoolSize: (function() {
|
|
1948
|
+
? ` asyncWorkPoolSize: (function () {
|
|
1948
1949
|
const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
|
|
1949
1950
|
// NaN > 0 is false
|
|
1950
1951
|
if (threadsSizeFromEnv > 0) {
|
|
@@ -1980,21 +1981,21 @@ function __createWasiWorker(filename) {
|
|
|
1980
1981
|
// According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
|
|
1981
1982
|
// a worker is consist of two handles: kPublicPort and kHandle.
|
|
1982
1983
|
{
|
|
1983
|
-
const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
|
|
1984
|
-
s.toString().includes(
|
|
1985
|
-
)
|
|
1984
|
+
const kPublicPort = Object.getOwnPropertySymbols(worker).find((s) =>
|
|
1985
|
+
s.toString().includes('kPublicPort'),
|
|
1986
|
+
)
|
|
1986
1987
|
if (kPublicPort) {
|
|
1987
|
-
worker[kPublicPort].ref = () => {}
|
|
1988
|
+
worker[kPublicPort].ref = () => {}
|
|
1988
1989
|
}
|
|
1989
1990
|
|
|
1990
|
-
const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
|
|
1991
|
-
s.toString().includes(
|
|
1992
|
-
)
|
|
1991
|
+
const kHandle = Object.getOwnPropertySymbols(worker).find((s) =>
|
|
1992
|
+
s.toString().includes('kHandle'),
|
|
1993
|
+
)
|
|
1993
1994
|
if (kHandle) {
|
|
1994
|
-
worker[kHandle].ref = () => {}
|
|
1995
|
+
worker[kHandle].ref = () => {}
|
|
1995
1996
|
}
|
|
1996
1997
|
|
|
1997
|
-
worker.unref()
|
|
1998
|
+
worker.unref()
|
|
1998
1999
|
}
|
|
1999
2000
|
return worker
|
|
2000
2001
|
},
|
|
@@ -2002,8 +2003,6 @@ function __createWasiWorker(filename) {
|
|
|
2002
2003
|
: ''
|
|
2003
2004
|
|
|
2004
2005
|
return `/* eslint-disable */
|
|
2005
|
-
/* prettier-ignore */
|
|
2006
|
-
|
|
2007
2006
|
/* auto-generated by NAPI-RS */
|
|
2008
2007
|
|
|
2009
2008
|
const __nodeFs = require('node:fs')
|
|
@@ -2019,14 +2018,18 @@ ${workerRuntimeImport}\
|
|
|
2019
2018
|
const { createContext: __emnapiCreateContext } = require('@emnapi/runtime')
|
|
2020
2019
|
${workerExecArgv}\
|
|
2021
2020
|
|
|
2022
|
-
const
|
|
2021
|
+
const __cwd = process.cwd()
|
|
2022
|
+
const __rootDir = __nodePath.parse(__cwd).root
|
|
2023
|
+
const __hostRoot =
|
|
2024
|
+
process.platform === 'android' ? __cwd : __rootDir
|
|
2023
2025
|
|
|
2024
2026
|
const __wasi = new __nodeWASI({
|
|
2025
2027
|
version: 'preview1',
|
|
2026
2028
|
env: process.env,
|
|
2027
2029
|
preopens: {
|
|
2028
|
-
[__rootDir]:
|
|
2029
|
-
|
|
2030
|
+
[__rootDir]: __hostRoot,
|
|
2031
|
+
[__hostRoot]: __hostRoot,
|
|
2032
|
+
},
|
|
2030
2033
|
})
|
|
2031
2034
|
|
|
2032
2035
|
const ${memoryName} = new WebAssembly.Memory({
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export const WASI_WORKER_TEMPLATE = `import fs from
|
|
2
|
-
import { createRequire } from
|
|
3
|
-
import { parse } from
|
|
4
|
-
import { WASI } from
|
|
5
|
-
import { parentPort, Worker } from
|
|
1
|
+
export const WASI_WORKER_TEMPLATE = `import fs from 'node:fs'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { parse } from 'node:path'
|
|
4
|
+
import { WASI } from 'node:wasi'
|
|
5
|
+
import { parentPort, Worker, workerData } from 'node:worker_threads'
|
|
6
6
|
|
|
7
|
-
const require = createRequire(import.meta.url)
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
8
|
|
|
9
9
|
const {
|
|
10
10
|
instantiateNapiModuleSync,
|
|
@@ -12,12 +12,12 @@ const {
|
|
|
12
12
|
getDefaultContext,
|
|
13
13
|
emnapiAsyncWorkPlugin,
|
|
14
14
|
emnapiTSFNPlugin,
|
|
15
|
-
} = require(
|
|
15
|
+
} = require('@napi-rs/wasm-runtime')
|
|
16
16
|
|
|
17
17
|
if (parentPort) {
|
|
18
|
-
parentPort.on(
|
|
19
|
-
globalThis.onmessage({ data })
|
|
20
|
-
})
|
|
18
|
+
parentPort.on('message', (data) => {
|
|
19
|
+
globalThis.onmessage({ data })
|
|
20
|
+
})
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
Object.assign(globalThis, {
|
|
@@ -25,18 +25,25 @@ Object.assign(globalThis, {
|
|
|
25
25
|
require,
|
|
26
26
|
Worker,
|
|
27
27
|
importScripts: function (f) {
|
|
28
|
-
|
|
28
|
+
// oxlint-disable-next-line no-eval -- WASI importScripts polyfill
|
|
29
|
+
;(0, eval)(fs.readFileSync(f, 'utf8') + '//# sourceURL=' + f)
|
|
29
30
|
},
|
|
30
31
|
postMessage: function (msg) {
|
|
31
32
|
if (parentPort) {
|
|
32
|
-
parentPort.postMessage(msg)
|
|
33
|
+
parentPort.postMessage(msg)
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
|
-
})
|
|
36
|
+
})
|
|
36
37
|
|
|
37
|
-
const emnapiContext = getDefaultContext()
|
|
38
|
+
const emnapiContext = getDefaultContext()
|
|
38
39
|
|
|
39
|
-
const
|
|
40
|
+
const __cwd = process.cwd()
|
|
41
|
+
const __rootDir =
|
|
42
|
+
(workerData && typeof workerData.rootDir === 'string' && workerData.rootDir) ||
|
|
43
|
+
parse(__cwd).root
|
|
44
|
+
const __hostRoot =
|
|
45
|
+
(workerData && typeof workerData.hostRoot === 'string' && workerData.hostRoot) ||
|
|
46
|
+
(process.platform === 'android' ? __cwd : __rootDir)
|
|
40
47
|
|
|
41
48
|
const handler = new MessageHandler({
|
|
42
49
|
onLoad({ wasmModule, wasmMemory }) {
|
|
@@ -44,9 +51,10 @@ const handler = new MessageHandler({
|
|
|
44
51
|
version: 'preview1',
|
|
45
52
|
env: process.env,
|
|
46
53
|
preopens: {
|
|
47
|
-
[__rootDir]:
|
|
54
|
+
[__rootDir]: __hostRoot,
|
|
55
|
+
[__hostRoot]: __hostRoot,
|
|
48
56
|
},
|
|
49
|
-
})
|
|
57
|
+
})
|
|
50
58
|
|
|
51
59
|
return instantiateNapiModuleSync(wasmModule, {
|
|
52
60
|
childThread: true,
|
|
@@ -62,16 +70,16 @@ const handler = new MessageHandler({
|
|
|
62
70
|
...importObject.env,
|
|
63
71
|
...importObject.napi,
|
|
64
72
|
...importObject.emnapi,
|
|
65
|
-
memory: wasmMemory
|
|
66
|
-
}
|
|
73
|
+
memory: wasmMemory,
|
|
74
|
+
}
|
|
67
75
|
},
|
|
68
|
-
})
|
|
76
|
+
})
|
|
69
77
|
},
|
|
70
|
-
})
|
|
78
|
+
})
|
|
71
79
|
|
|
72
80
|
globalThis.onmessage = function (e) {
|
|
73
|
-
handler.handle(e)
|
|
74
|
-
}
|
|
81
|
+
handler.handle(e)
|
|
82
|
+
}
|
|
75
83
|
`
|
|
76
84
|
|
|
77
85
|
export const createWasiBrowserWorkerBinding = (
|
|
@@ -110,10 +118,9 @@ const fs = createFsProxy(__memfsExported)`
|
|
|
110
118
|
// eslint-disable-next-line no-console
|
|
111
119
|
console.log.apply(console, arguments)
|
|
112
120
|
},
|
|
113
|
-
printErr: function() {
|
|
121
|
+
printErr: function () {
|
|
114
122
|
// eslint-disable-next-line no-console
|
|
115
|
-
console.error.apply(console, arguments)
|
|
116
|
-
${errorOutputsAppend}
|
|
123
|
+
console.error.apply(console, arguments)${errorOutputsAppend}
|
|
117
124
|
},
|
|
118
125
|
})`
|
|
119
126
|
: `const wasi = new WASI({
|
|
@@ -121,10 +128,9 @@ const fs = createFsProxy(__memfsExported)`
|
|
|
121
128
|
// eslint-disable-next-line no-console
|
|
122
129
|
console.log.apply(console, arguments)
|
|
123
130
|
},
|
|
124
|
-
printErr: function() {
|
|
131
|
+
printErr: function () {
|
|
125
132
|
// eslint-disable-next-line no-console
|
|
126
|
-
console.error.apply(console, arguments)
|
|
127
|
-
${errorOutputsAppend}
|
|
133
|
+
console.error.apply(console, arguments)${errorOutputsAppend}
|
|
128
134
|
},
|
|
129
135
|
})`
|
|
130
136
|
const errorHandler = errorEvent
|
|
@@ -156,8 +162,7 @@ const handler = new MessageHandler({
|
|
|
156
162
|
}
|
|
157
163
|
},
|
|
158
164
|
})
|
|
159
|
-
}
|
|
160
|
-
${errorHandler}
|
|
165
|
+
},${errorHandler ? `\n ${errorHandler}` : ''}
|
|
161
166
|
})
|
|
162
167
|
|
|
163
168
|
globalThis.onmessage = function (e) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
|
|
3
|
+
import { createBuildCommand } from '../../index.js'
|
|
4
|
+
|
|
5
|
+
test('build supports explicit format and compatibility aliases', (t) => {
|
|
6
|
+
const explicit = createBuildCommand([
|
|
7
|
+
'--format',
|
|
8
|
+
'esm',
|
|
9
|
+
'--js-binding',
|
|
10
|
+
'index.mjs',
|
|
11
|
+
])
|
|
12
|
+
|
|
13
|
+
t.is(explicit.format, 'esm')
|
|
14
|
+
t.is(explicit.jsBinding, 'index.mjs')
|
|
15
|
+
|
|
16
|
+
t.true(createBuildCommand(['--esm']).esm)
|
|
17
|
+
t.true(createBuildCommand(['--commonjs']).commonjs)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('build rejects unsupported formats', (t) => {
|
|
21
|
+
t.throws(() => createBuildCommand(['--format', 'umd']), {
|
|
22
|
+
message: /Invalid value for --format/,
|
|
23
|
+
})
|
|
24
|
+
})
|
package/src/commands/build.ts
CHANGED
|
@@ -11,7 +11,7 @@ const debug = debugFactory('build')
|
|
|
11
11
|
export class BuildCommand extends BaseBuildCommand {
|
|
12
12
|
pipe = Option.String('--pipe', {
|
|
13
13
|
description:
|
|
14
|
-
'Pipe all outputs file to given command. e.g. `napi build --pipe "npx
|
|
14
|
+
'Pipe all outputs file to given command. e.g. `napi build --pipe "npx oxfmt"`',
|
|
15
15
|
})
|
|
16
16
|
|
|
17
17
|
cargoOptions = Option.Rest()
|
package/src/def/build.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// This file is generated by codegen/index.ts
|
|
2
2
|
// Do not edit this file manually
|
|
3
3
|
import { Command, Option } from 'clipanion'
|
|
4
|
+
import * as typanion from 'typanion'
|
|
4
5
|
|
|
5
6
|
export abstract class BaseBuildCommand extends Command {
|
|
6
7
|
static paths = [['build']]
|
|
@@ -60,7 +61,7 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
60
61
|
'Emit `#[napi(string_enum)]` enums as runtime enums (`export declare enum`) under `--no-const-enum`. Default: type-only union.',
|
|
61
62
|
})
|
|
62
63
|
|
|
63
|
-
jsBinding?: string = Option.String('--js', {
|
|
64
|
+
jsBinding?: string = Option.String('--js,--js-binding', {
|
|
64
65
|
description:
|
|
65
66
|
'Path and filename of generated JS binding file. Only works with `--platform` flag. Relative to `--output-dir`.',
|
|
66
67
|
})
|
|
@@ -89,9 +90,21 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
89
90
|
description: 'Whether to enable the dts cache, default to true',
|
|
90
91
|
})
|
|
91
92
|
|
|
92
|
-
|
|
93
|
+
format?: 'esm' | 'commonjs' = Option.String('--format', {
|
|
94
|
+
validator: typanion.isOneOf([
|
|
95
|
+
typanion.isLiteral('esm'),
|
|
96
|
+
typanion.isLiteral('commonjs'),
|
|
97
|
+
]),
|
|
93
98
|
description:
|
|
94
|
-
'
|
|
99
|
+
'The module format of the generated JS binding file. Only works with `--platform` flag. Defaults to `commonjs`.',
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
esm?: boolean = Option.Boolean('--esm', {
|
|
103
|
+
description: 'Alias for `--format esm`.',
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
commonjs?: boolean = Option.Boolean('--commonjs', {
|
|
107
|
+
description: 'Alias for `--format commonjs`.',
|
|
95
108
|
})
|
|
96
109
|
|
|
97
110
|
strip?: boolean = Option.Boolean('--strip,-s', {
|
|
@@ -150,6 +163,9 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
150
163
|
description: 'Do not activate the `default` feature',
|
|
151
164
|
})
|
|
152
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Return the parsed build options.
|
|
168
|
+
*/
|
|
153
169
|
getOptions() {
|
|
154
170
|
return {
|
|
155
171
|
target: this.target,
|
|
@@ -169,7 +185,9 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
169
185
|
dtsHeader: this.dtsHeader,
|
|
170
186
|
noDtsHeader: this.noDtsHeader,
|
|
171
187
|
dtsCache: this.dtsCache,
|
|
188
|
+
format: this.format,
|
|
172
189
|
esm: this.esm,
|
|
190
|
+
commonjs: this.commonjs,
|
|
173
191
|
strip: this.strip,
|
|
174
192
|
release: this.release,
|
|
175
193
|
verbose: this.verbose,
|
|
@@ -262,9 +280,17 @@ export interface BuildOptions {
|
|
|
262
280
|
*/
|
|
263
281
|
dtsCache?: boolean
|
|
264
282
|
/**
|
|
265
|
-
*
|
|
283
|
+
* The module format of the generated JS binding file. Only works with `--platform` flag. Defaults to `commonjs`.
|
|
284
|
+
*/
|
|
285
|
+
format?: 'esm' | 'commonjs'
|
|
286
|
+
/**
|
|
287
|
+
* Alias for `--format esm`.
|
|
266
288
|
*/
|
|
267
289
|
esm?: boolean
|
|
290
|
+
/**
|
|
291
|
+
* Alias for `--format commonjs`.
|
|
292
|
+
*/
|
|
293
|
+
commonjs?: boolean
|
|
268
294
|
/**
|
|
269
295
|
* Whether strip the library to achieve the minimum file size
|
|
270
296
|
*/
|
|
@@ -142,9 +142,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
142
142
|
}␊
|
|
143
143
|
export type Blake2bHasher = Blake2BHasher␊
|
|
144
144
|
␊
|
|
145
|
-
export declare class Blake2BKey {␊
|
|
146
|
-
␊
|
|
147
|
-
}␊
|
|
145
|
+
export declare class Blake2BKey {}␊
|
|
148
146
|
export type Blake2bKey = Blake2BKey␊
|
|
149
147
|
␊
|
|
150
148
|
export declare class ClassWithFactory {␊
|
|
@@ -257,7 +255,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
257
255
|
␊
|
|
258
256
|
export declare const enum ALIAS {␊
|
|
259
257
|
A = 0,␊
|
|
260
|
-
B = 1
|
|
258
|
+
B = 1,␊
|
|
261
259
|
}␊
|
|
262
260
|
␊
|
|
263
261
|
export interface AliasedStruct {␊
|
|
@@ -345,7 +343,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
345
343
|
Six = 6,␊
|
|
346
344
|
Eight = 8,␊
|
|
347
345
|
Nine = 9,␊
|
|
348
|
-
Ten = 10
|
|
346
|
+
Ten = 10,␊
|
|
349
347
|
}␊
|
|
350
348
|
␊
|
|
351
349
|
export declare function customStatusCode(): void␊
|
|
@@ -358,7 +356,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
358
356
|
export declare function dateToNumber(input: Date): number␊
|
|
359
357
|
␊
|
|
360
358
|
/** This is a const */␊
|
|
361
|
-
export const DEFAULT_COST: number␊
|
|
359
|
+
export declare const DEFAULT_COST: number␊
|
|
362
360
|
␊
|
|
363
361
|
export declare function derefUint8Array(a: Uint8Array, b: Uint8ClampedArray): number␊
|
|
364
362
|
␊
|
|
@@ -374,9 +372,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
374
372
|
␊
|
|
375
373
|
export declare function eitherStringOrNumber(input: string | number): number␊
|
|
376
374
|
␊
|
|
377
|
-
export declare const enum Empty {␊
|
|
378
|
-
␊
|
|
379
|
-
}␊
|
|
375
|
+
export declare const enum Empty {}␊
|
|
380
376
|
␊
|
|
381
377
|
export declare function enumToI32(e: CustomNumEnum): number␊
|
|
382
378
|
␊
|
|
@@ -422,7 +418,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
422
418
|
/** Kills birds */␊
|
|
423
419
|
Cat = 1,␊
|
|
424
420
|
/** Tasty */␊
|
|
425
|
-
Duck = 2
|
|
421
|
+
Duck = 2,␊
|
|
426
422
|
}␊
|
|
427
423
|
␊
|
|
428
424
|
export declare function listObjKeys(obj: object): Array<string>␊
|
|
@@ -519,7 +515,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
519
515
|
export declare const enum Status {␊
|
|
520
516
|
Pristine = 'Pristine',␊
|
|
521
517
|
Loading = 'Loading',␊
|
|
522
|
-
Ready = 'Ready'
|
|
518
|
+
Ready = 'Ready',␊
|
|
523
519
|
}␊
|
|
524
520
|
␊
|
|
525
521
|
export interface StrictObject {␊
|
|
@@ -695,9 +691,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
695
691
|
}␊
|
|
696
692
|
export type Blake2bHasher = Blake2BHasher␊
|
|
697
693
|
␊
|
|
698
|
-
export declare class Blake2BKey {␊
|
|
699
|
-
␊
|
|
700
|
-
}␊
|
|
694
|
+
export declare class Blake2BKey {}␊
|
|
701
695
|
export type Blake2bKey = Blake2BKey␊
|
|
702
696
|
␊
|
|
703
697
|
export declare class ClassWithFactory {␊
|
|
@@ -810,7 +804,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
810
804
|
␊
|
|
811
805
|
export declare enum ALIAS {␊
|
|
812
806
|
A = 0,␊
|
|
813
|
-
B = 1
|
|
807
|
+
B = 1,␊
|
|
814
808
|
}␊
|
|
815
809
|
␊
|
|
816
810
|
export interface AliasedStruct {␊
|
|
@@ -898,7 +892,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
898
892
|
Six = 6,␊
|
|
899
893
|
Eight = 8,␊
|
|
900
894
|
Nine = 9,␊
|
|
901
|
-
Ten = 10
|
|
895
|
+
Ten = 10,␊
|
|
902
896
|
}␊
|
|
903
897
|
␊
|
|
904
898
|
export declare function customStatusCode(): void␊
|
|
@@ -911,7 +905,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
911
905
|
export declare function dateToNumber(input: Date): number␊
|
|
912
906
|
␊
|
|
913
907
|
/** This is a const */␊
|
|
914
|
-
export const DEFAULT_COST: number␊
|
|
908
|
+
export declare const DEFAULT_COST: number␊
|
|
915
909
|
␊
|
|
916
910
|
export declare function derefUint8Array(a: Uint8Array, b: Uint8ClampedArray): number␊
|
|
917
911
|
␊
|
|
@@ -927,9 +921,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
927
921
|
␊
|
|
928
922
|
export declare function eitherStringOrNumber(input: string | number): number␊
|
|
929
923
|
␊
|
|
930
|
-
export declare enum Empty {␊
|
|
931
|
-
␊
|
|
932
|
-
}␊
|
|
924
|
+
export declare enum Empty {}␊
|
|
933
925
|
␊
|
|
934
926
|
export declare function enumToI32(e: CustomNumEnum): number␊
|
|
935
927
|
␊
|
|
@@ -975,7 +967,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
975
967
|
/** Kills birds */␊
|
|
976
968
|
Cat = 1,␊
|
|
977
969
|
/** Tasty */␊
|
|
978
|
-
Duck = 2
|
|
970
|
+
Duck = 2,␊
|
|
979
971
|
}␊
|
|
980
972
|
␊
|
|
981
973
|
export declare function listObjKeys(obj: object): Array<string>␊
|
|
@@ -1069,9 +1061,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
1069
1061
|
␊
|
|
1070
1062
|
export declare function setSymbolInObj(symbol: symbol): object␊
|
|
1071
1063
|
␊
|
|
1072
|
-
export type Status =
|
|
1073
|
-
'Loading'|␊
|
|
1074
|
-
'Ready';␊
|
|
1064
|
+
export type Status = 'Pristine' | 'Loading' | 'Ready'␊
|
|
1075
1065
|
␊
|
|
1076
1066
|
export interface StrictObject {␊
|
|
1077
1067
|
name: string␊
|
|
@@ -1172,12 +1162,12 @@ Generated by [AVA](https://avajs.dev).
|
|
|
1172
1162
|
|
|
1173
1163
|
`export declare enum Priority {␊
|
|
1174
1164
|
Low = 0,␊
|
|
1175
|
-
High = 1
|
|
1165
|
+
High = 1,␊
|
|
1176
1166
|
}␊
|
|
1177
1167
|
␊
|
|
1178
1168
|
export declare enum Status {␊
|
|
1179
1169
|
Active = 'Active',␊
|
|
1180
|
-
Inactive = 'Inactive'
|
|
1170
|
+
Inactive = 'Inactive',␊
|
|
1181
1171
|
}␊
|
|
1182
1172
|
`
|
|
1183
1173
|
|
|
@@ -1187,11 +1177,11 @@ Generated by [AVA](https://avajs.dev).
|
|
|
1187
1177
|
|
|
1188
1178
|
`export declare const enum Priority {␊
|
|
1189
1179
|
Low = 0,␊
|
|
1190
|
-
High = 1
|
|
1180
|
+
High = 1,␊
|
|
1191
1181
|
}␊
|
|
1192
1182
|
␊
|
|
1193
1183
|
export declare const enum Status {␊
|
|
1194
1184
|
Active = 'Active',␊
|
|
1195
|
-
Inactive = 'Inactive'
|
|
1185
|
+
Inactive = 'Inactive',␊
|
|
1196
1186
|
}␊
|
|
1197
1187
|
`
|
|
Binary file
|
|
@@ -71,6 +71,10 @@ test('updatePackageJson merges nested objects instead of overwriting them', asyn
|
|
|
71
71
|
fsevents: '^2.3.3',
|
|
72
72
|
'@napi-rs/fixture-darwin-arm64': '1.0.1',
|
|
73
73
|
})
|
|
74
|
+
|
|
75
|
+
const written = await readFile(packageJsonPath, 'utf8')
|
|
76
|
+
t.true(written.endsWith('\n'))
|
|
77
|
+
t.false(written.endsWith('\n\n'))
|
|
74
78
|
})
|
|
75
79
|
|
|
76
80
|
test('statIdentitiesMatch distinguishes inodes that collide as lossy Numbers', (t) => {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
|
|
3
|
+
import { serializeJson, serializeToml, serializeYaml } from '../serialize.js'
|
|
4
|
+
|
|
5
|
+
test('serializeJson uses 2-space indent and a trailing newline', (t) => {
|
|
6
|
+
t.is(
|
|
7
|
+
serializeJson({ name: 'pkg', files: ['a.node'] }),
|
|
8
|
+
`{
|
|
9
|
+
"name": "pkg",
|
|
10
|
+
"files": [
|
|
11
|
+
"a.node"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
`,
|
|
15
|
+
)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('serializeJson always ends with exactly one newline', (t) => {
|
|
19
|
+
const serialized = serializeJson({ ok: true })
|
|
20
|
+
t.true(serialized.endsWith('\n'))
|
|
21
|
+
t.false(serialized.endsWith('\n\n'))
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('serializeToml strips the leading blank line @std/toml inserts', (t) => {
|
|
25
|
+
const serialized = serializeToml({
|
|
26
|
+
package: { name: 'demo', version: '0.1.0' },
|
|
27
|
+
dependencies: {
|
|
28
|
+
napi: { version: '3.0.0', features: ['napi4'] },
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
t.false(serialized.startsWith('\n'))
|
|
32
|
+
t.true(serialized.startsWith('[package]\n'))
|
|
33
|
+
t.true(serialized.endsWith('\n'))
|
|
34
|
+
t.false(serialized.endsWith('\n\n'))
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('serializeYaml always ends with a trailing newline', (t) => {
|
|
38
|
+
const serialized = serializeYaml({ on: { push: null } })
|
|
39
|
+
t.true(serialized.endsWith('\n'))
|
|
40
|
+
t.false(serialized.endsWith('\n\n'))
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('serializeToml does not rewrite commas inside quoted strings', (t) => {
|
|
44
|
+
const serialized = serializeToml({
|
|
45
|
+
lib: { include: ['src/a,b.rs'] },
|
|
46
|
+
package: {
|
|
47
|
+
name: 'demo',
|
|
48
|
+
description: 'uses = [a,b] in a scalar',
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
t.true(serialized.includes('include = ["src/a,b.rs"]'))
|
|
52
|
+
t.true(serialized.includes('description = "uses = [a,b] in a scalar"'))
|
|
53
|
+
t.false(serialized.includes('src/a, b.rs'))
|
|
54
|
+
t.false(serialized.includes('= [a, b]'))
|
|
55
|
+
})
|