@napi-rs/cli 3.2.0 → 3.3.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.
Files changed (36) hide show
  1. package/cli.mjs +3 -3
  2. package/dist/cli.js +793 -864
  3. package/dist/index.cjs +920 -754
  4. package/dist/index.d.cts +31 -2
  5. package/dist/index.d.ts +30 -3
  6. package/dist/index.js +891 -751
  7. package/package.json +7 -7
  8. package/src/api/artifacts.ts +1 -1
  9. package/src/api/build.ts +175 -108
  10. package/src/api/create-npm-dirs.ts +2 -2
  11. package/src/api/new.ts +4 -3
  12. package/src/api/pre-publish.ts +1 -1
  13. package/src/api/rename.ts +3 -4
  14. package/src/api/templates/js-binding.ts +5 -1
  15. package/src/api/universalize.ts +1 -1
  16. package/src/api/version.ts +4 -1
  17. package/src/cli.ts +1 -27
  18. package/src/commands/new.ts +1 -1
  19. package/src/index.ts +33 -0
  20. package/src/utils/config.ts +1 -1
  21. package/src/utils/target.ts +1 -0
  22. package/src/api/__tests__/create-npm-dirs.spec.ts +0 -210
  23. package/src/api/__tests__/new.spec.ts +0 -429
  24. package/src/utils/__tests__/__fixtures__/napi_type_def +0 -201
  25. package/src/utils/__tests__/__snapshots__/config.spec.ts.md +0 -97
  26. package/src/utils/__tests__/__snapshots__/config.spec.ts.snap +0 -0
  27. package/src/utils/__tests__/__snapshots__/target.spec.ts.md +0 -173
  28. package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
  29. package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +0 -1157
  30. package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
  31. package/src/utils/__tests__/__snapshots__/version.spec.ts.md +0 -21
  32. package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
  33. package/src/utils/__tests__/config.spec.ts +0 -81
  34. package/src/utils/__tests__/target.spec.ts +0 -19
  35. package/src/utils/__tests__/typegen.spec.ts +0 -64
  36. package/src/utils/__tests__/version.spec.ts +0 -13
@@ -1,21 +0,0 @@
1
- # Snapshot report for `src/utils/__tests__/version.spec.ts`
2
-
3
- The actual snapshot is saved in `version.spec.ts.snap`.
4
-
5
- Generated by [AVA](https://avajs.dev).
6
-
7
- ## should generate correct napi engine requirement
8
-
9
- > Snapshot 1
10
-
11
- [
12
- '>= 8.6.0 < 9 || >= 9.0.0 < 10 || >= 10.0.0',
13
- '>= 8.10.0 < 9 || >= 9.3.0 < 10 || >= 10.0.0',
14
- '>= 6.14.2 < 7 || >= 8.11.2 < 9 || >= 9.11.0 < 10 || >= 10.0.0',
15
- '>= 10.16.0 < 11 || >= 11.8.0 < 12 || >= 12.0.0',
16
- '>= 10.17.0 < 11 || >= 12.11.0 < 13 || >= 13.0.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 < 15 || >= 15.0.0',
19
- '>= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0',
20
- '>= 18.17.0 < 19 || >= 20.3.0 < 21 || >= 21.1.0',
21
- ]
@@ -1,81 +0,0 @@
1
- import { unlink, writeFile } from 'node:fs/promises'
2
- import { tmpdir } from 'node:os'
3
- import { join } from 'node:path'
4
-
5
- import ava, { TestFn } from 'ava'
6
-
7
- import {
8
- CommonPackageJsonFields,
9
- UserNapiConfig,
10
- readNapiConfig,
11
- } from '../config.js'
12
-
13
- const NON_EXISTENT_FILE = 'non-existent-file'
14
-
15
- const test = ava as TestFn<{
16
- configPath: string
17
- packageJson: string
18
- pkgJson: CommonPackageJsonFields
19
- config: UserNapiConfig
20
- }>
21
-
22
- test.before(async (t) => {
23
- const tmp = tmpdir()
24
- const configPath = join(tmp, 'napi.json')
25
- const packageJson = join(tmp, 'package.json')
26
- const pkgJson = {
27
- name: '@napi-rs/testing',
28
- version: '0.0.0',
29
- napi: {
30
- binaryName: 'testing',
31
- packageName: '@napi-rs/testing',
32
- targets: [
33
- 'x86_64-unknown-linux-gnu',
34
- 'x86_64-pc-windows-msvc',
35
- 'x86_64-apple-darwin',
36
- ],
37
- },
38
- }
39
- await writeFile(packageJson, JSON.stringify(pkgJson, null, 2))
40
- const config = {
41
- binaryName: 'testing',
42
- packageName: '@node-rs/testing',
43
- targets: [
44
- 'x86_64-unknown-linux-gnu',
45
- 'x86_64-apple-darwin',
46
- 'aarch64-apple-darwin',
47
- ],
48
- }
49
- await writeFile(configPath, JSON.stringify(config, null, 2))
50
- t.context = { configPath, config, packageJson, pkgJson }
51
- })
52
-
53
- test.after(async (t) => {
54
- await unlink(t.context.configPath)
55
- await unlink(t.context.packageJson)
56
- })
57
-
58
- test('should throw if package.json not found', async (t) => {
59
- await t.throwsAsync(() => readNapiConfig(NON_EXISTENT_FILE), {
60
- message: `package.json not found at ${NON_EXISTENT_FILE}`,
61
- })
62
- })
63
-
64
- test('should throw if napi.json not found', async (t) => {
65
- const { packageJson } = t.context
66
- await t.throwsAsync(() => readNapiConfig(packageJson, NON_EXISTENT_FILE), {
67
- message: `NAPI-RS config not found at ${NON_EXISTENT_FILE}`,
68
- })
69
- })
70
-
71
- test('should be able to read config from package.json', async (t) => {
72
- const { packageJson } = t.context
73
- const config = await readNapiConfig(packageJson)
74
- t.snapshot(config)
75
- })
76
-
77
- test('should be able to read config from napi.json', async (t) => {
78
- const { packageJson, configPath } = t.context
79
- const config = await readNapiConfig(packageJson, configPath)
80
- t.snapshot(config)
81
- })
@@ -1,19 +0,0 @@
1
- import os from 'os'
2
-
3
- import test from 'ava'
4
-
5
- import {
6
- parseTriple,
7
- getSystemDefaultTarget,
8
- AVAILABLE_TARGETS,
9
- } from '../target.js'
10
-
11
- test('should parse triple correctly', (t) => {
12
- t.snapshot(AVAILABLE_TARGETS.map(parseTriple))
13
- })
14
-
15
- test('should get system default target correctly', (t) => {
16
- const target = getSystemDefaultTarget()
17
-
18
- t.is(target.platform, os.platform())
19
- })
@@ -1,64 +0,0 @@
1
- import { join } from 'path'
2
- import { fileURLToPath } from 'url'
3
-
4
- import test from 'ava'
5
-
6
- import { correctStringIdent, processTypeDef } from '../typegen.js'
7
-
8
- test('should ident string correctly', (t) => {
9
- const input = `
10
- /**
11
- * should keep
12
- * class A {
13
- * foo = () => {}
14
- * bar = () => {}
15
- * }
16
- */
17
- class A {
18
- foo() {
19
- a = b
20
- }
21
-
22
- bar = () => {
23
-
24
- }
25
- boz = 1
26
- }
27
-
28
- namespace B {
29
- namespace C {
30
- type D = A
31
- }
32
- }
33
- `
34
- t.snapshot(correctStringIdent(input, 0), 'original ident is 0')
35
- t.snapshot(correctStringIdent(input, 2), 'original ident is 2')
36
- })
37
-
38
- test('should process type def correctly', async (t) => {
39
- const { dts } = await processTypeDef(
40
- join(
41
- fileURLToPath(import.meta.url),
42
- '../',
43
- '__fixtures__',
44
- 'napi_type_def',
45
- ),
46
- true,
47
- )
48
-
49
- t.snapshot(dts)
50
- })
51
-
52
- test('should process type def with noConstEnum correctly', async (t) => {
53
- const { dts } = await processTypeDef(
54
- join(
55
- fileURLToPath(import.meta.url),
56
- '../',
57
- '__fixtures__',
58
- 'napi_type_def',
59
- ),
60
- false,
61
- )
62
-
63
- t.snapshot(dts)
64
- })
@@ -1,13 +0,0 @@
1
- import test from 'ava'
2
-
3
- import { napiEngineRequirement, NapiVersion } from '../version.js'
4
-
5
- test('should generate correct napi engine requirement', (t) => {
6
- t.snapshot(
7
- (
8
- Object.values(NapiVersion).filter(
9
- (v) => typeof v === 'number',
10
- ) as NapiVersion[]
11
- ).map(napiEngineRequirement),
12
- )
13
- })