@napi-rs/cli 3.7.2 → 3.7.4
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 +240 -64
- package/dist/index.cjs +239 -63
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +240 -64
- package/package.json +3 -3
- package/src/api/__tests__/__snapshots__/templates.spec.ts.md +353 -0
- package/src/api/__tests__/__snapshots__/templates.spec.ts.snap +0 -0
- package/src/api/__tests__/android-build.spec.ts +113 -0
- package/src/api/__tests__/artifacts.spec.ts +95 -0
- package/src/api/__tests__/build-regressions.spec.ts +128 -0
- package/src/api/__tests__/build.spec.ts +1020 -0
- package/src/api/__tests__/create-npm-dirs.spec.ts +561 -0
- package/src/api/__tests__/new-node-api-version.spec.ts +87 -0
- package/src/api/__tests__/new.spec.ts +527 -0
- package/src/api/__tests__/rename.spec.ts +181 -0
- package/src/api/__tests__/templates.spec.ts +164 -0
- package/src/api/__tests__/universalize.spec.ts +128 -0
- package/src/api/artifacts.ts +7 -16
- package/src/api/build.ts +354 -111
- package/src/api/new.ts +65 -1
- package/src/commands/__tests__/new.spec.ts +13 -0
- package/src/def/build.ts +6 -6
- package/src/utils/__tests__/__fixtures__/napi_type_def +202 -0
- package/src/utils/__tests__/__fixtures__/optional-napi-derive/Cargo.toml +3 -0
- package/src/utils/__tests__/__fixtures__/optional-napi-derive/main-crate/Cargo.toml +8 -0
- package/src/utils/__tests__/__fixtures__/optional-napi-derive/main-crate/src/lib.rs +1 -0
- package/src/utils/__tests__/__fixtures__/optional-napi-derive/napi-derive/Cargo.toml +5 -0
- package/src/utils/__tests__/__fixtures__/optional-napi-derive/napi-derive/src/lib.rs +1 -0
- package/src/utils/__tests__/__fixtures__/optional-napi-derive/with-optional-derive/Cargo.toml +11 -0
- package/src/utils/__tests__/__fixtures__/optional-napi-derive/with-optional-derive/src/lib.rs +1 -0
- package/src/utils/__tests__/__fixtures__/runtime_string_enum_flag +2 -0
- package/src/utils/__tests__/__snapshots__/config.spec.ts.md +97 -0
- package/src/utils/__tests__/__snapshots__/config.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.md +180 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +1197 -0
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/version.spec.ts.md +22 -0
- package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
- package/src/utils/__tests__/config.spec.ts +81 -0
- package/src/utils/__tests__/metadata.spec.ts +69 -0
- package/src/utils/__tests__/misc.spec.ts +56 -0
- package/src/utils/__tests__/target.spec.ts +19 -0
- package/src/utils/__tests__/typegen.spec.ts +85 -0
- package/src/utils/__tests__/version.spec.ts +7 -0
- package/src/utils/metadata.ts +94 -3
- package/src/utils/version.ts +2 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
2
|
+
import { mkdir, rm, writeFile } from 'node:fs/promises'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
|
|
6
|
+
import ava, { type TestFn } from 'ava'
|
|
7
|
+
|
|
8
|
+
import { buildProject, generateTypeDef } from '../build.js'
|
|
9
|
+
|
|
10
|
+
const test = ava as TestFn<{
|
|
11
|
+
tmpDir: string
|
|
12
|
+
projectDir: string
|
|
13
|
+
typeDefDir: string
|
|
14
|
+
}>
|
|
15
|
+
|
|
16
|
+
test.beforeEach(async (t) => {
|
|
17
|
+
const tmpDir = join(
|
|
18
|
+
tmpdir(),
|
|
19
|
+
'napi-rs-test',
|
|
20
|
+
`build-regressions-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
21
|
+
)
|
|
22
|
+
const projectDir = join(tmpDir, 'project')
|
|
23
|
+
const typeDefDir = join(projectDir, 'type-def')
|
|
24
|
+
|
|
25
|
+
await mkdir(typeDefDir, { recursive: true })
|
|
26
|
+
t.context = { tmpDir, projectDir, typeDefDir }
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test.afterEach.always(async (t) => {
|
|
30
|
+
if (existsSync(t.context.tmpDir)) {
|
|
31
|
+
await rm(t.context.tmpDir, { recursive: true, force: true })
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
async function writeMixedTargetProject(projectDir: string) {
|
|
36
|
+
await mkdir(join(projectDir, 'src'), { recursive: true })
|
|
37
|
+
await writeFile(
|
|
38
|
+
join(projectDir, 'Cargo.toml'),
|
|
39
|
+
`[package]
|
|
40
|
+
name = "build_regression"
|
|
41
|
+
version = "0.1.0"
|
|
42
|
+
edition = "2021"
|
|
43
|
+
|
|
44
|
+
[lib]
|
|
45
|
+
crate-type = ["cdylib"]
|
|
46
|
+
|
|
47
|
+
[[bin]]
|
|
48
|
+
name = "selected-bin"
|
|
49
|
+
path = "src/main.rs"
|
|
50
|
+
`,
|
|
51
|
+
)
|
|
52
|
+
await writeFile(join(projectDir, 'src', 'lib.rs'), 'pub fn library() {}\n')
|
|
53
|
+
await writeFile(join(projectDir, 'src', 'main.rs'), 'fn main() {}\n')
|
|
54
|
+
await writeFile(
|
|
55
|
+
join(projectDir, 'package.json'),
|
|
56
|
+
JSON.stringify({
|
|
57
|
+
name: 'build-regression',
|
|
58
|
+
version: '0.1.0',
|
|
59
|
+
napi: { binaryName: 'build-regression' },
|
|
60
|
+
}),
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
test.serial(
|
|
65
|
+
'`--bin` copies the selected executable from a mixed cdylib/bin crate',
|
|
66
|
+
async (t) => {
|
|
67
|
+
const { projectDir } = t.context
|
|
68
|
+
await writeMixedTargetProject(projectDir)
|
|
69
|
+
|
|
70
|
+
const outputs = await (async () => {
|
|
71
|
+
const originalCargo = process.env.CARGO
|
|
72
|
+
delete process.env.CARGO
|
|
73
|
+
try {
|
|
74
|
+
return await (
|
|
75
|
+
await buildProject({
|
|
76
|
+
cwd: projectDir,
|
|
77
|
+
bin: 'selected-bin',
|
|
78
|
+
outputDir: 'dist',
|
|
79
|
+
})
|
|
80
|
+
).task
|
|
81
|
+
} finally {
|
|
82
|
+
if (originalCargo === undefined) {
|
|
83
|
+
delete process.env.CARGO
|
|
84
|
+
} else {
|
|
85
|
+
process.env.CARGO = originalCargo
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
})()
|
|
89
|
+
|
|
90
|
+
const executableName =
|
|
91
|
+
process.platform === 'win32' ? 'selected-bin.exe' : 'selected-bin'
|
|
92
|
+
const executablePath = join(projectDir, 'dist', executableName)
|
|
93
|
+
|
|
94
|
+
t.deepEqual(outputs, [{ kind: 'exe', path: executablePath }])
|
|
95
|
+
t.true(existsSync(executablePath))
|
|
96
|
+
t.false(existsSync(join(projectDir, 'dist', 'build-regression.node')))
|
|
97
|
+
},
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
test.serial(
|
|
101
|
+
'an explicit dtsHeaderFile takes precedence over config and inline headers',
|
|
102
|
+
async (t) => {
|
|
103
|
+
const { projectDir, typeDefDir } = t.context
|
|
104
|
+
await Promise.all([
|
|
105
|
+
writeFile(join(projectDir, 'explicit-header.d.ts'), '// explicit\n'),
|
|
106
|
+
writeFile(join(projectDir, 'config-header.d.ts'), '// config file\n'),
|
|
107
|
+
writeFile(
|
|
108
|
+
join(typeDefDir, 'value.type'),
|
|
109
|
+
'{"kind":"fn","name":"value","def":"function value(): void"}\n',
|
|
110
|
+
),
|
|
111
|
+
])
|
|
112
|
+
|
|
113
|
+
const { dts } = await generateTypeDef({
|
|
114
|
+
cwd: projectDir,
|
|
115
|
+
typeDefDir,
|
|
116
|
+
dtsHeaderFile: 'explicit-header.d.ts',
|
|
117
|
+
configDtsHeaderFile: 'config-header.d.ts',
|
|
118
|
+
dtsHeader: '// explicit inline\n',
|
|
119
|
+
configDtsHeader: '// config inline\n',
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
t.true(dts.startsWith('// explicit\n'))
|
|
123
|
+
t.false(dts.includes('// config file'))
|
|
124
|
+
t.false(dts.includes('// explicit inline'))
|
|
125
|
+
t.false(dts.includes('// config inline'))
|
|
126
|
+
t.true(dts.includes('function value(): void'))
|
|
127
|
+
},
|
|
128
|
+
)
|