@napi-rs/cli 3.0.0-alpha.89 → 3.0.0-alpha.90
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/api/__tests__/new.spec.d.ts +1 -0
- package/dist/api/__tests__/new.spec.js +283 -0
- package/dist/api/__tests__/new.spec.js.map +1 -0
- package/dist/api/new.js +280 -112
- package/dist/api/new.js.map +1 -1
- package/dist/api/rename.js +66 -12
- package/dist/api/rename.js.map +1 -1
- package/dist/index.cjs +1869 -1669
- package/dist/utils/config.d.ts +1 -1
- package/dist/utils/config.js +1 -1
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/read-config.d.ts +7 -0
- package/dist/utils/read-config.js +8 -0
- package/dist/utils/read-config.js.map +1 -0
- package/package.json +11 -10
- package/src/api/__tests__/new.spec.ts +429 -0
- package/src/api/new.ts +353 -144
- package/src/api/rename.ts +94 -17
- package/src/utils/config.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/read-config.ts +20 -0
package/dist/utils/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Target } from './target.js';
|
|
2
2
|
export type ValueOfConstArray<T> = T[Exclude<keyof T, keyof Array<any>>];
|
|
3
|
-
export declare const SupportedPackageManagers: readonly ["yarn"];
|
|
3
|
+
export declare const SupportedPackageManagers: readonly ["yarn", "pnpm"];
|
|
4
4
|
export declare const SupportedTestFrameworks: readonly ["ava"];
|
|
5
5
|
export type SupportedPackageManager = ValueOfConstArray<typeof SupportedPackageManagers>;
|
|
6
6
|
export type SupportedTestFramework = ValueOfConstArray<typeof SupportedTestFrameworks>;
|
package/dist/utils/config.js
CHANGED
|
@@ -2,7 +2,7 @@ import { underline, yellow } from 'colorette';
|
|
|
2
2
|
import { merge, omit } from 'lodash-es';
|
|
3
3
|
import { fileExists, readFileAsync } from './misc.js';
|
|
4
4
|
import { DEFAULT_TARGETS, parseTriple } from './target.js';
|
|
5
|
-
export const SupportedPackageManagers = ['yarn'];
|
|
5
|
+
export const SupportedPackageManagers = ['yarn', 'pnpm'];
|
|
6
6
|
export const SupportedTestFrameworks = ['ava'];
|
|
7
7
|
export async function readNapiConfig(path, configPath) {
|
|
8
8
|
if (configPath && !(await fileExists(configPath))) {
|
package/dist/utils/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEvC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAU,MAAM,aAAa,CAAA;AAIlE,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,MAAM,CAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEvC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAU,MAAM,aAAa,CAAA;AAIlE,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAU,CAAA;AACjE,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAK,CAAU,CAAA;AA6IvD,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,IAAY,EACZ,UAAmB;IAEnB,IAAI,UAAU,IAAI,CAAC,CAAC,MAAM,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AED,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;IAE7C,OAAO,UAAU,CAAA;AACnB,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { readNapiConfig } from './config.js';
|
|
3
|
+
export async function readConfig(options) {
|
|
4
|
+
const resolvePath = (...paths) => resolve(options.cwd, ...paths);
|
|
5
|
+
const config = await readNapiConfig(resolvePath(options.configPath ?? options.packageJsonPath ?? 'package.json'), options.configPath ? resolvePath(options.configPath) : undefined);
|
|
6
|
+
return config;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=read-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-config.js","sourceRoot":"","sources":["../../src/utils/read-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAQ5C,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAA2B;IAC1D,MAAM,WAAW,GAAG,CAAC,GAAG,KAAe,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAA;IAC1E,MAAM,MAAM,GAAG,MAAM,cAAc,CACjC,WAAW,CACT,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,eAAe,IAAI,cAAc,CAChE,EACD,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CACjE,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/cli",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.90",
|
|
4
4
|
"description": "Cli tools for napi-rs",
|
|
5
5
|
"author": "LongYinan <lynweklm@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/napi-rs/napi-rs",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"import": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
23
|
},
|
|
24
24
|
"require": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.cjs"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"./package.json": {
|
|
@@ -70,22 +70,22 @@
|
|
|
70
70
|
"@inquirer/prompts": "^7.4.0",
|
|
71
71
|
"@napi-rs/cross-toolchain": "^0.0.19",
|
|
72
72
|
"@napi-rs/wasm-tools": "^0.0.3",
|
|
73
|
-
"@octokit/rest": "^22.0.0",
|
|
74
73
|
"clipanion": "^4.0.0-rc.4",
|
|
75
74
|
"colorette": "^2.0.20",
|
|
76
75
|
"debug": "^4.4.0",
|
|
77
76
|
"emnapi": "^1.4.0",
|
|
77
|
+
"find-up": "^7.0.0",
|
|
78
78
|
"js-yaml": "^4.1.0",
|
|
79
|
-
"lodash-es": "^4.17.21",
|
|
80
79
|
"semver": "^7.7.1",
|
|
81
|
-
"toml": "^3.0.0",
|
|
82
80
|
"typanion": "^3.14.0",
|
|
83
81
|
"wasm-sjlj": "^1.0.6"
|
|
84
82
|
},
|
|
85
83
|
"devDependencies": {
|
|
86
84
|
"@emnapi/core": "^1.4.0",
|
|
87
85
|
"@emnapi/runtime": "^1.4.0",
|
|
88
|
-
"@
|
|
86
|
+
"@octokit/rest": "^22.0.0",
|
|
87
|
+
"@oxc-node/core": "^0.0.29",
|
|
88
|
+
"@std/toml": "npm:@jsr/std__toml@^1.0.8",
|
|
89
89
|
"@types/debug": "^4.1.12",
|
|
90
90
|
"@types/inquirer": "^9.0.7",
|
|
91
91
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -95,6 +95,7 @@
|
|
|
95
95
|
"ava": "^6.2.0",
|
|
96
96
|
"env-paths": "^3.0.0",
|
|
97
97
|
"esbuild": "^0.25.2",
|
|
98
|
+
"lodash-es": "^4.17.21",
|
|
98
99
|
"prettier": "^3.5.3",
|
|
99
100
|
"tslib": "^2.8.1",
|
|
100
101
|
"typescript": "^5.8.2"
|
|
@@ -129,5 +130,5 @@
|
|
|
129
130
|
"**/__tests__/**/*.spec.ts"
|
|
130
131
|
]
|
|
131
132
|
},
|
|
132
|
-
"gitHead": "
|
|
133
|
+
"gitHead": "aeefd091b10e59e6eee8cae01337d19daee679f1"
|
|
133
134
|
}
|
|
@@ -0,0 +1,429 @@
|
|
|
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
|
+
})
|