@napi-rs/cli 3.2.0 → 3.3.0
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/cli.mjs +3 -3
- package/dist/cli.js +791 -863
- package/dist/index.cjs +918 -753
- package/dist/index.d.cts +31 -2
- package/dist/index.d.ts +30 -3
- package/dist/index.js +889 -750
- package/package.json +5 -6
- package/src/api/artifacts.ts +1 -1
- package/src/api/build.ts +175 -108
- package/src/api/create-npm-dirs.ts +2 -2
- package/src/api/new.ts +4 -3
- package/src/api/pre-publish.ts +1 -1
- package/src/api/rename.ts +3 -4
- package/src/api/templates/js-binding.ts +5 -1
- package/src/api/universalize.ts +1 -1
- package/src/api/version.ts +4 -1
- package/src/cli.ts +1 -27
- package/src/commands/new.ts +1 -1
- package/src/index.ts +33 -0
- package/src/utils/config.ts +1 -1
- package/src/utils/target.ts +1 -0
- package/src/api/__tests__/create-npm-dirs.spec.ts +0 -210
- package/src/api/__tests__/new.spec.ts +0 -429
- package/src/utils/__tests__/__fixtures__/napi_type_def +0 -201
- package/src/utils/__tests__/__snapshots__/config.spec.ts.md +0 -97
- package/src/utils/__tests__/__snapshots__/config.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.md +0 -173
- package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +0 -1157
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/version.spec.ts.md +0 -21
- package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
- package/src/utils/__tests__/config.spec.ts +0 -81
- package/src/utils/__tests__/target.spec.ts +0 -19
- package/src/utils/__tests__/typegen.spec.ts +0 -64
- package/src/utils/__tests__/version.spec.ts +0 -13
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs'
|
|
2
|
-
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises'
|
|
3
|
-
import { tmpdir } from 'node:os'
|
|
4
|
-
import { join } from 'node:path'
|
|
5
|
-
|
|
6
|
-
import ava, { TestFn } from 'ava'
|
|
7
|
-
|
|
8
|
-
import { createNpmDirs } from '../create-npm-dirs.js'
|
|
9
|
-
|
|
10
|
-
const test = ava as TestFn<{
|
|
11
|
-
tmpDir: string
|
|
12
|
-
packageJsonPath: string
|
|
13
|
-
}>
|
|
14
|
-
|
|
15
|
-
test.beforeEach(async (t) => {
|
|
16
|
-
// Create a unique temp directory for tests
|
|
17
|
-
const timestamp = Date.now()
|
|
18
|
-
const random = Math.random().toString(36).substring(7)
|
|
19
|
-
const tmpDir = join(
|
|
20
|
-
tmpdir(),
|
|
21
|
-
'napi-rs-test',
|
|
22
|
-
`create-npm-dirs-${timestamp}-${random}`,
|
|
23
|
-
)
|
|
24
|
-
const packageJsonPath = join(tmpDir, 'package.json')
|
|
25
|
-
|
|
26
|
-
// Create the directory
|
|
27
|
-
await mkdir(tmpDir, { recursive: true })
|
|
28
|
-
|
|
29
|
-
t.context = { tmpDir, packageJsonPath }
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test.afterEach.always(async (t) => {
|
|
33
|
-
// Clean up any created directories
|
|
34
|
-
if (existsSync(t.context.tmpDir)) {
|
|
35
|
-
await rm(t.context.tmpDir, { recursive: true, force: true })
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
test('should omit exports fields from publishConfig in scoped packages', async (t) => {
|
|
40
|
-
const { tmpDir, packageJsonPath } = t.context
|
|
41
|
-
|
|
42
|
-
// Create a package.json with publishConfig that includes exports field
|
|
43
|
-
const packageJson = {
|
|
44
|
-
name: 'test-package',
|
|
45
|
-
version: '1.0.0',
|
|
46
|
-
publishConfig: {
|
|
47
|
-
registry: 'https://custom-registry.com',
|
|
48
|
-
access: 'public',
|
|
49
|
-
exports: {
|
|
50
|
-
'.': './dist/index.js',
|
|
51
|
-
'./package.json': './package.json',
|
|
52
|
-
},
|
|
53
|
-
tag: 'beta',
|
|
54
|
-
},
|
|
55
|
-
napi: {
|
|
56
|
-
binaryName: 'test-package',
|
|
57
|
-
targets: ['x86_64-unknown-linux-gnu'],
|
|
58
|
-
},
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
62
|
-
|
|
63
|
-
await createNpmDirs({
|
|
64
|
-
cwd: tmpDir,
|
|
65
|
-
packageJsonPath: 'package.json',
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
// Check that the scoped package directory was created
|
|
69
|
-
const scopedDir = join(tmpDir, 'npm', 'linux-x64-gnu')
|
|
70
|
-
t.true(existsSync(scopedDir))
|
|
71
|
-
|
|
72
|
-
// Read the generated package.json for the scoped package
|
|
73
|
-
const scopedPackageJsonPath = join(scopedDir, 'package.json')
|
|
74
|
-
t.true(existsSync(scopedPackageJsonPath))
|
|
75
|
-
|
|
76
|
-
const scopedPackageJson = JSON.parse(
|
|
77
|
-
await readFile(scopedPackageJsonPath, 'utf-8'),
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
// Verify that publishConfig only contains registry and access, not exports
|
|
81
|
-
t.truthy(scopedPackageJson.publishConfig)
|
|
82
|
-
t.is(scopedPackageJson.publishConfig.registry, 'https://custom-registry.com')
|
|
83
|
-
t.is(scopedPackageJson.publishConfig.access, 'public')
|
|
84
|
-
t.is(scopedPackageJson.publishConfig.exports, undefined)
|
|
85
|
-
t.is(scopedPackageJson.publishConfig.tag, undefined)
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
test('should handle package without publishConfig', async (t) => {
|
|
89
|
-
const { tmpDir, packageJsonPath } = t.context
|
|
90
|
-
|
|
91
|
-
// Create a package.json without publishConfig
|
|
92
|
-
const packageJson = {
|
|
93
|
-
name: 'test-package-no-config',
|
|
94
|
-
version: '1.0.0',
|
|
95
|
-
napi: {
|
|
96
|
-
binaryName: 'test-package-no-config',
|
|
97
|
-
targets: ['x86_64-unknown-linux-gnu'],
|
|
98
|
-
},
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
102
|
-
|
|
103
|
-
await createNpmDirs({
|
|
104
|
-
cwd: tmpDir,
|
|
105
|
-
packageJsonPath: 'package.json',
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
// Check that the scoped package directory was created
|
|
109
|
-
const scopedDir = join(tmpDir, 'npm', 'linux-x64-gnu')
|
|
110
|
-
t.true(existsSync(scopedDir))
|
|
111
|
-
|
|
112
|
-
// Read the generated package.json for the scoped package
|
|
113
|
-
const scopedPackageJsonPath = join(scopedDir, 'package.json')
|
|
114
|
-
const scopedPackageJson = JSON.parse(
|
|
115
|
-
await readFile(scopedPackageJsonPath, 'utf-8'),
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
// Verify that publishConfig is not present when not in source
|
|
119
|
-
t.is(scopedPackageJson.publishConfig, undefined)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
test('should preserve only registry and access in publishConfig', async (t) => {
|
|
123
|
-
const { tmpDir, packageJsonPath } = t.context
|
|
124
|
-
|
|
125
|
-
// Create a package.json with minimal publishConfig
|
|
126
|
-
const packageJson = {
|
|
127
|
-
name: 'test-package-minimal',
|
|
128
|
-
version: '1.0.0',
|
|
129
|
-
publishConfig: {
|
|
130
|
-
registry: 'https://npm.company.com',
|
|
131
|
-
access: 'restricted',
|
|
132
|
-
},
|
|
133
|
-
napi: {
|
|
134
|
-
binaryName: 'test-package-minimal',
|
|
135
|
-
targets: ['aarch64-apple-darwin'],
|
|
136
|
-
},
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
140
|
-
|
|
141
|
-
await createNpmDirs({
|
|
142
|
-
cwd: tmpDir,
|
|
143
|
-
packageJsonPath: 'package.json',
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
// Check that the scoped package directory was created
|
|
147
|
-
const scopedDir = join(tmpDir, 'npm', 'darwin-arm64')
|
|
148
|
-
t.true(existsSync(scopedDir))
|
|
149
|
-
|
|
150
|
-
// Read the generated package.json for the scoped package
|
|
151
|
-
const scopedPackageJsonPath = join(scopedDir, 'package.json')
|
|
152
|
-
const scopedPackageJson = JSON.parse(
|
|
153
|
-
await readFile(scopedPackageJsonPath, 'utf-8'),
|
|
154
|
-
)
|
|
155
|
-
|
|
156
|
-
// Verify that publishConfig contains exactly registry and access
|
|
157
|
-
t.truthy(scopedPackageJson.publishConfig)
|
|
158
|
-
t.is(scopedPackageJson.publishConfig.registry, 'https://npm.company.com')
|
|
159
|
-
t.is(scopedPackageJson.publishConfig.access, 'restricted')
|
|
160
|
-
t.is(Object.keys(scopedPackageJson.publishConfig).length, 2)
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
test('should handle WASM targets correctly with publishConfig', async (t) => {
|
|
164
|
-
const { tmpDir, packageJsonPath } = t.context
|
|
165
|
-
|
|
166
|
-
// Create a package.json for WASM target
|
|
167
|
-
const packageJson = {
|
|
168
|
-
name: 'test-wasm-package',
|
|
169
|
-
version: '1.0.0',
|
|
170
|
-
publishConfig: {
|
|
171
|
-
registry: 'https://wasm-registry.com',
|
|
172
|
-
access: 'public',
|
|
173
|
-
exports: './wasm.js',
|
|
174
|
-
browser: './browser.js',
|
|
175
|
-
},
|
|
176
|
-
napi: {
|
|
177
|
-
binaryName: 'test-wasm-package',
|
|
178
|
-
targets: ['wasm32-wasi-preview1-threads'],
|
|
179
|
-
},
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
183
|
-
|
|
184
|
-
await createNpmDirs({
|
|
185
|
-
cwd: tmpDir,
|
|
186
|
-
packageJsonPath: 'package.json',
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
// Check that the scoped package directory was created
|
|
190
|
-
const scopedDir = join(tmpDir, 'npm', 'wasm32-wasi')
|
|
191
|
-
t.true(existsSync(scopedDir))
|
|
192
|
-
|
|
193
|
-
// Read the generated package.json for the scoped package
|
|
194
|
-
const scopedPackageJsonPath = join(scopedDir, 'package.json')
|
|
195
|
-
const scopedPackageJson = JSON.parse(
|
|
196
|
-
await readFile(scopedPackageJsonPath, 'utf-8'),
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
// Verify that publishConfig is correctly filtered for WASM too
|
|
200
|
-
t.truthy(scopedPackageJson.publishConfig)
|
|
201
|
-
t.is(scopedPackageJson.publishConfig.registry, 'https://wasm-registry.com')
|
|
202
|
-
t.is(scopedPackageJson.publishConfig.access, 'public')
|
|
203
|
-
t.is(scopedPackageJson.publishConfig.exports, undefined)
|
|
204
|
-
t.is(scopedPackageJson.publishConfig.browser, undefined)
|
|
205
|
-
|
|
206
|
-
// Verify WASM-specific fields are set correctly
|
|
207
|
-
t.truthy(scopedPackageJson.main)
|
|
208
|
-
t.truthy(scopedPackageJson.browser)
|
|
209
|
-
t.truthy(scopedPackageJson.dependencies)
|
|
210
|
-
})
|
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs'
|
|
2
|
-
import { readFile, rm } from 'node:fs/promises'
|
|
3
|
-
import { tmpdir } from 'node:os'
|
|
4
|
-
import { join } from 'node:path'
|
|
5
|
-
|
|
6
|
-
import ava, { TestFn } from 'ava'
|
|
7
|
-
import { load as yamlLoad } from 'js-yaml'
|
|
8
|
-
|
|
9
|
-
import { newProject } from '../new.js'
|
|
10
|
-
|
|
11
|
-
const test = ava as TestFn<{
|
|
12
|
-
tmpDir: string
|
|
13
|
-
}>
|
|
14
|
-
|
|
15
|
-
test.beforeEach(async (t) => {
|
|
16
|
-
// Create a unique temp directory for tests
|
|
17
|
-
const timestamp = Date.now()
|
|
18
|
-
const random = Math.random().toString(36).substring(7)
|
|
19
|
-
const tmpDir = join(
|
|
20
|
-
tmpdir(),
|
|
21
|
-
'napi-rs-test',
|
|
22
|
-
`new-project-${timestamp}-${random}`,
|
|
23
|
-
)
|
|
24
|
-
t.context = { tmpDir }
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
test.afterEach.always(async (t) => {
|
|
28
|
-
// Clean up any created directories
|
|
29
|
-
if (existsSync(t.context.tmpDir)) {
|
|
30
|
-
await rm(t.context.tmpDir, { recursive: true, force: true })
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test('create a new project with default options', async (t) => {
|
|
35
|
-
const projectPath = join(t.context.tmpDir, 'default-project')
|
|
36
|
-
|
|
37
|
-
await newProject({
|
|
38
|
-
path: projectPath,
|
|
39
|
-
enableDefaultTargets: true,
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
t.true(existsSync(projectPath))
|
|
43
|
-
t.true(existsSync(join(projectPath, 'package.json')))
|
|
44
|
-
t.true(existsSync(join(projectPath, 'Cargo.toml')))
|
|
45
|
-
t.true(existsSync(join(projectPath, 'src')))
|
|
46
|
-
t.true(existsSync(join(projectPath, '.github', 'workflows', 'CI.yml')))
|
|
47
|
-
|
|
48
|
-
// Check package.json
|
|
49
|
-
const pkgJson = JSON.parse(
|
|
50
|
-
await readFile(join(projectPath, 'package.json'), 'utf-8'),
|
|
51
|
-
)
|
|
52
|
-
t.is(pkgJson.name, 'default-project')
|
|
53
|
-
t.is(pkgJson.napi.binaryName, 'default-project')
|
|
54
|
-
t.is(pkgJson.license, 'MIT')
|
|
55
|
-
t.truthy(pkgJson.engines.node)
|
|
56
|
-
t.falsy(existsSync(join(projectPath, 'default-project.wasi-browser.js')))
|
|
57
|
-
const gitAttributes = await readFile(
|
|
58
|
-
join(projectPath, '.gitattributes'),
|
|
59
|
-
'utf-8',
|
|
60
|
-
)
|
|
61
|
-
t.truthy(gitAttributes.includes('default-project.wasi-browser.js'))
|
|
62
|
-
t.truthy(gitAttributes.includes('default-project.wasi.cjs'))
|
|
63
|
-
t.truthy(gitAttributes.includes('wasi-worker-browser.mjs'))
|
|
64
|
-
t.truthy(gitAttributes.includes('wasi-worker.mjs'))
|
|
65
|
-
const ciYaml = await readFile(
|
|
66
|
-
join(projectPath, '.github', 'workflows', 'CI.yml'),
|
|
67
|
-
'utf-8',
|
|
68
|
-
)
|
|
69
|
-
const yamlObject = yamlLoad(ciYaml) as any
|
|
70
|
-
t.is(yamlObject.env.APP_NAME, 'default-project')
|
|
71
|
-
t.falsy(yamlObject.jobs.publish.needs.includes('wasm32-wasip1-threads'))
|
|
72
|
-
t.falsy(
|
|
73
|
-
yamlObject.jobs['test-linux-binding'].strategy.matrix.target.includes(
|
|
74
|
-
'aarch64-unknown-linux-musl',
|
|
75
|
-
),
|
|
76
|
-
)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test('create a new project with custom name', async (t) => {
|
|
80
|
-
const projectPath = join(t.context.tmpDir, 'custom-name-dir')
|
|
81
|
-
|
|
82
|
-
await newProject({
|
|
83
|
-
path: projectPath,
|
|
84
|
-
name: '@my-scope/custom-package',
|
|
85
|
-
enableDefaultTargets: true,
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
t.true(existsSync(projectPath))
|
|
89
|
-
|
|
90
|
-
const pkgJson = JSON.parse(
|
|
91
|
-
await readFile(join(projectPath, 'package.json'), 'utf-8'),
|
|
92
|
-
)
|
|
93
|
-
t.is(pkgJson.name, '@my-scope/custom-package')
|
|
94
|
-
t.is(pkgJson.napi.binaryName, 'custom-package')
|
|
95
|
-
|
|
96
|
-
const cargoToml = await readFile(join(projectPath, 'Cargo.toml'), 'utf-8')
|
|
97
|
-
// Verify that the package name was properly renamed to follow Rust naming conventions
|
|
98
|
-
t.true(cargoToml.includes('name = "custom_package"'))
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
test('create a new project with custom path', async (t) => {
|
|
102
|
-
const customPath = join(t.context.tmpDir, 'nested', 'folders', 'my-project')
|
|
103
|
-
|
|
104
|
-
await newProject({
|
|
105
|
-
path: customPath,
|
|
106
|
-
enableDefaultTargets: true,
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
t.true(existsSync(customPath))
|
|
110
|
-
t.true(existsSync(join(customPath, 'package.json')))
|
|
111
|
-
|
|
112
|
-
const pkgJson = JSON.parse(
|
|
113
|
-
await readFile(join(customPath, 'package.json'), 'utf-8'),
|
|
114
|
-
)
|
|
115
|
-
t.is(pkgJson.name, 'my-project')
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
test('create a new project with custom path and name', async (t) => {
|
|
119
|
-
const projectPath = join(t.context.tmpDir, 'custom-dir')
|
|
120
|
-
|
|
121
|
-
await newProject({
|
|
122
|
-
path: projectPath,
|
|
123
|
-
name: 'custom-project-name',
|
|
124
|
-
enableDefaultTargets: true,
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
t.true(existsSync(projectPath))
|
|
128
|
-
|
|
129
|
-
const pkgJson = JSON.parse(
|
|
130
|
-
await readFile(join(projectPath, 'package.json'), 'utf-8'),
|
|
131
|
-
)
|
|
132
|
-
t.is(pkgJson.name, 'custom-project-name')
|
|
133
|
-
t.is(pkgJson.napi.binaryName, 'custom-project-name')
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
test('create a new project with custom path, name, and targets', async (t) => {
|
|
137
|
-
const projectPath = join(t.context.tmpDir, 'full-custom')
|
|
138
|
-
const customTargets = [
|
|
139
|
-
'x86_64-unknown-linux-gnu',
|
|
140
|
-
'x86_64-apple-darwin',
|
|
141
|
-
'aarch64-apple-darwin',
|
|
142
|
-
'wasm32-wasip1-threads',
|
|
143
|
-
'x86_64-unknown-freebsd',
|
|
144
|
-
]
|
|
145
|
-
|
|
146
|
-
await newProject({
|
|
147
|
-
path: projectPath,
|
|
148
|
-
name: '@custom/full-project',
|
|
149
|
-
targets: customTargets,
|
|
150
|
-
enableDefaultTargets: false,
|
|
151
|
-
license: 'Apache-2.0',
|
|
152
|
-
minNodeApiVersion: 6,
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
t.true(existsSync(projectPath))
|
|
156
|
-
|
|
157
|
-
const pkgJson = JSON.parse(
|
|
158
|
-
await readFile(join(projectPath, 'package.json'), 'utf-8'),
|
|
159
|
-
)
|
|
160
|
-
t.is(pkgJson.name, '@custom/full-project')
|
|
161
|
-
t.is(pkgJson.napi.binaryName, 'full-project')
|
|
162
|
-
t.is(pkgJson.license, 'Apache-2.0')
|
|
163
|
-
t.true(pkgJson.engines.node.includes('>= 14.0.0'))
|
|
164
|
-
|
|
165
|
-
// Check that CI workflow only includes the specified targets
|
|
166
|
-
const ciYaml = await readFile(
|
|
167
|
-
join(projectPath, '.github', 'workflows', 'CI.yml'),
|
|
168
|
-
'utf-8',
|
|
169
|
-
)
|
|
170
|
-
const yamlObject = yamlLoad(ciYaml) as any
|
|
171
|
-
t.true(
|
|
172
|
-
yamlObject.jobs.build.strategy.matrix.settings.some(
|
|
173
|
-
(setting: any) => setting.target === 'x86_64-unknown-linux-gnu',
|
|
174
|
-
),
|
|
175
|
-
)
|
|
176
|
-
t.true(
|
|
177
|
-
yamlObject.jobs.build.strategy.matrix.settings.some(
|
|
178
|
-
(setting: any) => setting.target === 'x86_64-apple-darwin',
|
|
179
|
-
),
|
|
180
|
-
)
|
|
181
|
-
t.true(
|
|
182
|
-
yamlObject.jobs.build.strategy.matrix.settings.some(
|
|
183
|
-
(setting: any) => setting.target === 'aarch64-apple-darwin',
|
|
184
|
-
),
|
|
185
|
-
)
|
|
186
|
-
t.false(
|
|
187
|
-
yamlObject.jobs.build.strategy.matrix.settings.some(
|
|
188
|
-
(setting: any) => setting.target === 'x86_64-pc-windows-msvc',
|
|
189
|
-
),
|
|
190
|
-
)
|
|
191
|
-
t.true(
|
|
192
|
-
yamlObject.jobs.build.strategy.matrix.settings.some(
|
|
193
|
-
(setting: any) => setting.target === 'wasm32-wasip1-threads',
|
|
194
|
-
),
|
|
195
|
-
)
|
|
196
|
-
t.truthy(yamlObject.jobs['build-freebsd'])
|
|
197
|
-
t.truthy(yamlObject.jobs['test-wasi'])
|
|
198
|
-
t.falsy(
|
|
199
|
-
yamlObject.jobs['test-macOS-windows-binding'].strategy.matrix.settings.some(
|
|
200
|
-
(setting: any) => setting.target === 'x86_64-pc-windows-msvc',
|
|
201
|
-
),
|
|
202
|
-
)
|
|
203
|
-
t.truthy(
|
|
204
|
-
yamlObject.jobs['test-macOS-windows-binding'].strategy.matrix.settings.some(
|
|
205
|
-
(setting: any) => setting.target === 'aarch64-apple-darwin',
|
|
206
|
-
),
|
|
207
|
-
)
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
test('non Windows and macOS targets should remove test-macOS-windows-binding job', async (t) => {
|
|
211
|
-
const projectPath = join(t.context.tmpDir, 'no-windows-macos')
|
|
212
|
-
const targets = [
|
|
213
|
-
'x86_64-unknown-linux-gnu',
|
|
214
|
-
'aarch64-unknown-linux-gnu',
|
|
215
|
-
'wasm32-wasip1-threads',
|
|
216
|
-
'x86_64-unknown-freebsd',
|
|
217
|
-
]
|
|
218
|
-
|
|
219
|
-
await newProject({
|
|
220
|
-
path: projectPath,
|
|
221
|
-
targets,
|
|
222
|
-
enableDefaultTargets: false,
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
t.true(existsSync(projectPath))
|
|
226
|
-
|
|
227
|
-
const ciYaml = await readFile(
|
|
228
|
-
join(projectPath, '.github', 'workflows', 'CI.yml'),
|
|
229
|
-
'utf-8',
|
|
230
|
-
)
|
|
231
|
-
const yamlObject = yamlLoad(ciYaml) as any
|
|
232
|
-
t.falsy(yamlObject.jobs['test-macOS-windows-binding'])
|
|
233
|
-
t.falsy(yamlObject.jobs.publish.needs.includes('test-macOS-windows-binding'))
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
test('should remove test-linux-binding job if no Linux targets are enabled', async (t) => {
|
|
237
|
-
const projectPath = join(t.context.tmpDir, 'no-linux')
|
|
238
|
-
const targets = ['x86_64-apple-darwin', 'aarch64-apple-darwin']
|
|
239
|
-
|
|
240
|
-
await newProject({
|
|
241
|
-
path: projectPath,
|
|
242
|
-
targets,
|
|
243
|
-
enableDefaultTargets: false,
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
t.true(existsSync(projectPath))
|
|
247
|
-
|
|
248
|
-
const ciYaml = await readFile(
|
|
249
|
-
join(projectPath, '.github', 'workflows', 'CI.yml'),
|
|
250
|
-
'utf-8',
|
|
251
|
-
)
|
|
252
|
-
const yamlObject = yamlLoad(ciYaml) as any
|
|
253
|
-
t.falsy(yamlObject.jobs['test-linux-binding'])
|
|
254
|
-
t.falsy(yamlObject.jobs.publish.needs.includes('test-linux-binding'))
|
|
255
|
-
})
|
|
256
|
-
|
|
257
|
-
test('should fail when no path is provided', async (t) => {
|
|
258
|
-
await t.throwsAsync(
|
|
259
|
-
async () => {
|
|
260
|
-
await newProject({
|
|
261
|
-
enableDefaultTargets: true,
|
|
262
|
-
})
|
|
263
|
-
},
|
|
264
|
-
{ message: /Please provide the path as the argument/ },
|
|
265
|
-
)
|
|
266
|
-
})
|
|
267
|
-
|
|
268
|
-
test('should fail when path already exists and is not empty', async (t) => {
|
|
269
|
-
const projectPath = join(t.context.tmpDir, 'existing-project')
|
|
270
|
-
|
|
271
|
-
// Create directory with a file
|
|
272
|
-
await rm(projectPath, { recursive: true, force: true }).catch(() => {})
|
|
273
|
-
const { mkdirSync, writeFileSync } = await import('node:fs')
|
|
274
|
-
mkdirSync(projectPath, { recursive: true })
|
|
275
|
-
writeFileSync(join(projectPath, 'existing-file.txt'), 'content')
|
|
276
|
-
|
|
277
|
-
await t.throwsAsync(
|
|
278
|
-
async () => {
|
|
279
|
-
await newProject({
|
|
280
|
-
path: projectPath,
|
|
281
|
-
enableDefaultTargets: true,
|
|
282
|
-
})
|
|
283
|
-
},
|
|
284
|
-
{ message: /already exists and it's not empty/ },
|
|
285
|
-
)
|
|
286
|
-
})
|
|
287
|
-
|
|
288
|
-
test('should fail when path is a file', async (t) => {
|
|
289
|
-
const filePath = join(t.context.tmpDir, 'file.txt')
|
|
290
|
-
|
|
291
|
-
// Create a file
|
|
292
|
-
const { writeFileSync } = await import('node:fs')
|
|
293
|
-
const { mkdirSync } = await import('node:fs')
|
|
294
|
-
mkdirSync(t.context.tmpDir, { recursive: true })
|
|
295
|
-
writeFileSync(filePath, 'content')
|
|
296
|
-
|
|
297
|
-
await t.throwsAsync(
|
|
298
|
-
async () => {
|
|
299
|
-
await newProject({
|
|
300
|
-
path: filePath,
|
|
301
|
-
enableDefaultTargets: true,
|
|
302
|
-
})
|
|
303
|
-
},
|
|
304
|
-
{ message: /already exists and it's not a directory/ },
|
|
305
|
-
)
|
|
306
|
-
})
|
|
307
|
-
|
|
308
|
-
test('dry run should not create any files', async (t) => {
|
|
309
|
-
const projectPath = join(t.context.tmpDir, 'dry-run-project')
|
|
310
|
-
|
|
311
|
-
await newProject({
|
|
312
|
-
path: projectPath,
|
|
313
|
-
name: 'dry-run-test',
|
|
314
|
-
enableDefaultTargets: true,
|
|
315
|
-
dryRun: true,
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
t.false(existsSync(projectPath))
|
|
319
|
-
})
|
|
320
|
-
|
|
321
|
-
test('create project without GitHub Actions', async (t) => {
|
|
322
|
-
const projectPath = join(t.context.tmpDir, 'no-github-actions')
|
|
323
|
-
|
|
324
|
-
await newProject({
|
|
325
|
-
path: projectPath,
|
|
326
|
-
enableDefaultTargets: true,
|
|
327
|
-
enableGithubActions: false,
|
|
328
|
-
})
|
|
329
|
-
|
|
330
|
-
t.true(existsSync(projectPath))
|
|
331
|
-
t.true(existsSync(join(projectPath, 'package.json')))
|
|
332
|
-
t.false(existsSync(join(projectPath, '.github')))
|
|
333
|
-
})
|
|
334
|
-
|
|
335
|
-
test('create a new project with pnpm package manager', async (t) => {
|
|
336
|
-
const projectPath = join(t.context.tmpDir, 'pnpm-project')
|
|
337
|
-
|
|
338
|
-
await newProject({
|
|
339
|
-
path: projectPath,
|
|
340
|
-
name: 'pnpm-test-project',
|
|
341
|
-
packageManager: 'pnpm',
|
|
342
|
-
enableDefaultTargets: true,
|
|
343
|
-
})
|
|
344
|
-
|
|
345
|
-
t.true(existsSync(projectPath))
|
|
346
|
-
t.true(existsSync(join(projectPath, 'package.json')))
|
|
347
|
-
t.true(existsSync(join(projectPath, 'Cargo.toml')))
|
|
348
|
-
|
|
349
|
-
// Check package.json
|
|
350
|
-
const pkgJson = JSON.parse(
|
|
351
|
-
await readFile(join(projectPath, 'package.json'), 'utf-8'),
|
|
352
|
-
)
|
|
353
|
-
t.is(pkgJson.name, 'pnpm-test-project')
|
|
354
|
-
t.is(pkgJson.napi.binaryName, 'pnpm-test-project')
|
|
355
|
-
|
|
356
|
-
// Verify that the Cargo.toml has the correct sanitized name
|
|
357
|
-
const cargoToml = await readFile(join(projectPath, 'Cargo.toml'), 'utf-8')
|
|
358
|
-
t.true(cargoToml.includes('name = "pnpm_test_project"'))
|
|
359
|
-
|
|
360
|
-
// Check for pnpm-specific files or configurations if any
|
|
361
|
-
// The template might have different structure for pnpm
|
|
362
|
-
})
|
|
363
|
-
|
|
364
|
-
test('create a new project with pnpm and custom name', async (t) => {
|
|
365
|
-
const projectPath = join(t.context.tmpDir, 'pnpm-custom-name')
|
|
366
|
-
|
|
367
|
-
await newProject({
|
|
368
|
-
path: projectPath,
|
|
369
|
-
name: '@my-org/custom-pnpm-package',
|
|
370
|
-
packageManager: 'pnpm',
|
|
371
|
-
enableDefaultTargets: true,
|
|
372
|
-
})
|
|
373
|
-
|
|
374
|
-
t.true(existsSync(projectPath))
|
|
375
|
-
t.true(existsSync(join(projectPath, 'package.json')))
|
|
376
|
-
|
|
377
|
-
const pkgJson = JSON.parse(
|
|
378
|
-
await readFile(join(projectPath, 'package.json'), 'utf-8'),
|
|
379
|
-
)
|
|
380
|
-
t.is(pkgJson.name, '@my-org/custom-pnpm-package')
|
|
381
|
-
t.is(pkgJson.napi.binaryName, 'custom-pnpm-package')
|
|
382
|
-
|
|
383
|
-
const cargoToml = await readFile(join(projectPath, 'Cargo.toml'), 'utf-8')
|
|
384
|
-
t.true(cargoToml.includes('name = "custom_pnpm_package"'))
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
test('create a new project with pnpm and custom path/name combination', async (t) => {
|
|
388
|
-
const projectPath = join(t.context.tmpDir, 'deep', 'nested', 'pnpm-dir')
|
|
389
|
-
|
|
390
|
-
await newProject({
|
|
391
|
-
path: projectPath,
|
|
392
|
-
name: '@scoped/pnpm-custom-name',
|
|
393
|
-
packageManager: 'pnpm',
|
|
394
|
-
enableDefaultTargets: true,
|
|
395
|
-
license: 'Apache-2.0',
|
|
396
|
-
})
|
|
397
|
-
|
|
398
|
-
t.true(existsSync(projectPath))
|
|
399
|
-
t.true(existsSync(join(projectPath, 'package.json')))
|
|
400
|
-
t.true(existsSync(join(projectPath, 'Cargo.toml')))
|
|
401
|
-
|
|
402
|
-
// Check package.json
|
|
403
|
-
const pkgJson = JSON.parse(
|
|
404
|
-
await readFile(join(projectPath, 'package.json'), 'utf-8'),
|
|
405
|
-
)
|
|
406
|
-
t.is(pkgJson.name, '@scoped/pnpm-custom-name')
|
|
407
|
-
t.is(pkgJson.napi.binaryName, 'pnpm-custom-name')
|
|
408
|
-
t.is(pkgJson.license, 'Apache-2.0')
|
|
409
|
-
|
|
410
|
-
// Check Cargo.toml has sanitized name
|
|
411
|
-
const cargoToml = await readFile(join(projectPath, 'Cargo.toml'), 'utf-8')
|
|
412
|
-
t.true(cargoToml.includes('name = "pnpm_custom_name"'))
|
|
413
|
-
})
|
|
414
|
-
|
|
415
|
-
test('should fail when no targets are enabled', async (t) => {
|
|
416
|
-
const projectPath = join(t.context.tmpDir, 'no-targets')
|
|
417
|
-
|
|
418
|
-
await t.throwsAsync(
|
|
419
|
-
async () => {
|
|
420
|
-
await newProject({
|
|
421
|
-
path: projectPath,
|
|
422
|
-
enableDefaultTargets: false,
|
|
423
|
-
enableAllTargets: false,
|
|
424
|
-
targets: [],
|
|
425
|
-
})
|
|
426
|
-
},
|
|
427
|
-
{ message: /At least one target must be enabled/ },
|
|
428
|
-
)
|
|
429
|
-
})
|