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

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.
@@ -1,140 +0,0 @@
1
- import { load, dump } from 'js-yaml'
2
-
3
- import {
4
- NodeArchToCpu,
5
- type SupportedPackageManager,
6
- UniArchsByPlatform,
7
- parseTriple,
8
- } from '../../utils/index.js'
9
-
10
- import { type WasiTargetName, YAML } from './ci-template.js'
11
-
12
- const BUILD_FREEBSD = 'build-freebsd'
13
- const TEST_MACOS_WINDOWS = 'test-macOS-windows-binding'
14
- const TEST_LINUX_X64_GNU = 'test-linux-x64-gnu-binding'
15
- const TEST_LINUX_X64_MUSL = 'test-linux-x64-musl-binding'
16
- const TEST_LINUX_AARCH64_GNU = 'test-linux-aarch64-gnu-binding'
17
- const TEST_LINUX_AARCH64_MUSL = 'test-linux-aarch64-musl-binding'
18
- const TEST_LINUX_ARM_GNUEABIHF = 'test-linux-arm-gnueabihf-binding'
19
- const TEST_WASI = 'test-wasi-nodejs'
20
- const UNIVERSAL_MACOS = 'universal-macOS'
21
-
22
- export const createGithubActionsCIYml = (
23
- targets: string[],
24
- packageManager: SupportedPackageManager,
25
- wasiTargetName: WasiTargetName,
26
- ) => {
27
- const allTargets = new Set(
28
- targets.flatMap((t) => {
29
- const platform = parseTriple(t)
30
- if (platform.arch === 'universal') {
31
- const srcTriples = UniArchsByPlatform[platform.platform]?.map((arch) =>
32
- t.replace('universal', NodeArchToCpu[arch]),
33
- )
34
- return [t, ...(srcTriples ?? [])]
35
- }
36
- return [t]
37
- }),
38
- )
39
-
40
- const fullTemplate = load(YAML(packageManager, wasiTargetName)) as any
41
-
42
- const requiredSteps = []
43
- const enableWindowsX86 = allTargets.has('x86_64-pc-windows-msvc')
44
- const enableMacOSX86 = allTargets.has('x86_64-apple-darwin')
45
- const enableLinuxX86Gnu = allTargets.has('x86_64-unknown-linux-gnu')
46
- const enableLinuxX86Musl = allTargets.has('x86_64-unknown-linux-musl')
47
- const enableLinuxArm8Gnu = allTargets.has('aarch64-unknown-linux-gnu')
48
- const enableLinuxArm8Musl = allTargets.has('aarch64-unknown-linux-musl')
49
- const enableLinuxArm7 = allTargets.has('armv7-unknown-linux-gnueabihf')
50
- const enableFreeBSD = allTargets.has('x86_64-unknown-freebsd')
51
- const enableMacOSUni = allTargets.has('universal-apple-darwin')
52
- const enableWasi =
53
- allTargets.has('wasm32-wasi-preview1-threads') ||
54
- allTargets.has('wasm32-wasip1-threads') ||
55
- allTargets.has('wasm32-wasip2')
56
- fullTemplate.jobs.build.strategy.matrix.settings =
57
- fullTemplate.jobs.build.strategy.matrix.settings.filter(
58
- ({ target }: { target: string }) => allTargets.has(target),
59
- )
60
- if (!fullTemplate.jobs.build.strategy.matrix.settings.length) {
61
- delete fullTemplate.jobs.build.strategy.matrix
62
- }
63
-
64
- if (!enableFreeBSD) {
65
- delete fullTemplate.jobs[BUILD_FREEBSD]
66
- } else {
67
- requiredSteps.push(BUILD_FREEBSD)
68
- }
69
-
70
- if (!enableWindowsX86 && !enableMacOSX86) {
71
- delete fullTemplate.jobs[TEST_MACOS_WINDOWS]
72
- } else {
73
- const filterTargets = new Set<string>()
74
- if (enableWindowsX86) {
75
- filterTargets.add('windows-latest')
76
- }
77
- if (enableMacOSUni || enableMacOSX86) {
78
- filterTargets.add('macos-latest')
79
- }
80
- fullTemplate.jobs[TEST_MACOS_WINDOWS].strategy.matrix.settings =
81
- fullTemplate.jobs[TEST_MACOS_WINDOWS].strategy.matrix.settings.filter(
82
- ({ host }: { host: string; target: string }) => filterTargets.has(host),
83
- )
84
-
85
- requiredSteps.push(TEST_MACOS_WINDOWS)
86
- }
87
-
88
- if (!enableLinuxX86Gnu) {
89
- delete fullTemplate.jobs[TEST_LINUX_X64_GNU]
90
- } else {
91
- requiredSteps.push(TEST_LINUX_X64_GNU)
92
- }
93
-
94
- if (!enableLinuxX86Musl) {
95
- delete fullTemplate.jobs[TEST_LINUX_X64_MUSL]
96
- } else {
97
- requiredSteps.push(TEST_LINUX_X64_MUSL)
98
- }
99
-
100
- if (!enableLinuxArm8Gnu) {
101
- delete fullTemplate.jobs[TEST_LINUX_AARCH64_GNU]
102
- } else {
103
- requiredSteps.push(TEST_LINUX_AARCH64_GNU)
104
- }
105
-
106
- if (!enableLinuxArm8Musl) {
107
- delete fullTemplate.jobs[TEST_LINUX_AARCH64_MUSL]
108
- } else {
109
- requiredSteps.push(TEST_LINUX_AARCH64_MUSL)
110
- }
111
-
112
- if (!enableLinuxArm7) {
113
- delete fullTemplate.jobs[TEST_LINUX_ARM_GNUEABIHF]
114
- } else {
115
- requiredSteps.push(TEST_LINUX_ARM_GNUEABIHF)
116
- }
117
-
118
- if (!enableMacOSUni) {
119
- delete fullTemplate.jobs[UNIVERSAL_MACOS]
120
- } else {
121
- requiredSteps.push(UNIVERSAL_MACOS)
122
- }
123
-
124
- if (!enableWasi) {
125
- delete fullTemplate.jobs[TEST_WASI]
126
- } else {
127
- requiredSteps.push(TEST_WASI)
128
- }
129
-
130
- fullTemplate.jobs.publish.needs = requiredSteps
131
-
132
- try {
133
- return dump(fullTemplate, {
134
- lineWidth: 1000,
135
- })
136
- } catch (err) {
137
- console.info(fullTemplate)
138
- throw err
139
- }
140
- }
@@ -1,7 +0,0 @@
1
- export const createLibRs = () => `use napi_derive::napi;
2
-
3
- #[napi]
4
- pub fn sum(a: i32, b: i32) -> i32 {
5
- a + b
6
- }
7
- `
@@ -1,90 +0,0 @@
1
- import type {
2
- CommonPackageJsonFields,
3
- SupportedTestFramework,
4
- } from '../../utils/config.js'
5
- import { UNIVERSAL_TARGETS } from '../../utils/target.js'
6
-
7
- export interface PackageMeta {
8
- 'dist-tags': { [index: string]: string }
9
- }
10
-
11
- export const createPackageJson = async ({
12
- name,
13
- binaryName,
14
- targets,
15
- license,
16
- engineRequirement,
17
- cliVersion,
18
- testFramework,
19
- }: {
20
- name: string
21
- binaryName: string
22
- targets: string[]
23
- license: string
24
- engineRequirement: string
25
- cliVersion: string
26
- testFramework: SupportedTestFramework
27
- }) => {
28
- const hasWasmTarget = targets.some((t) => t.includes('wasm'))
29
- const universalTargets = targets.filter(
30
- (t) => t in UNIVERSAL_TARGETS,
31
- ) as (keyof typeof UNIVERSAL_TARGETS)[]
32
- const unifiedtargets = universalTargets.length
33
- ? targets.filter(
34
- (target) =>
35
- !universalTargets.some((t) => {
36
- // @ts-expect-error
37
- return UNIVERSAL_TARGETS[t].includes(target)
38
- }),
39
- )
40
- : targets
41
- const content: CommonPackageJsonFields = {
42
- name,
43
- version: '0.0.0',
44
- license,
45
- engines: {
46
- node: engineRequirement,
47
- },
48
- type: 'commonjs',
49
- main: 'index.js',
50
- types: 'index.d.ts',
51
- browser: 'browser.js',
52
- module: undefined,
53
- exports: undefined,
54
- napi: {
55
- binaryName,
56
- targets: unifiedtargets,
57
- },
58
- scripts: {
59
- test: testFramework,
60
- build: 'napi build --release --platform --strip',
61
- 'build:debug': 'napi build',
62
- prepublishOnly: 'napi prepublish -t npm',
63
- artifacts: 'napi artifacts',
64
- version: 'napi version',
65
- },
66
- devDependencies: {
67
- '@napi-rs/cli': `^${cliVersion}`,
68
- },
69
- }
70
-
71
- if (testFramework === 'ava') {
72
- const avaMeta = await fetch(`https://registry.npmjs.org/ava`).then(
73
- (res) => res.json() as Promise<PackageMeta>,
74
- )
75
- content.devDependencies!['ava'] = `^${avaMeta['dist-tags'].latest}`
76
- content.ava = {
77
- timeout: '1m',
78
- }
79
- }
80
-
81
- if (hasWasmTarget) {
82
- const wasmRuntime = await fetch(
83
- `https://registry.npmjs.org/@napi-rs/wasm-runtime`,
84
- ).then((res) => res.json() as Promise<PackageMeta>)
85
- const latest = wasmRuntime['dist-tags'].latest
86
- content.devDependencies!['@napi-rs/wasm-runtime'] = `^${latest}`
87
- }
88
-
89
- return JSON.stringify(content, null, 2)
90
- }