@napi-rs/cli 3.0.0-alpha.1 → 3.0.0-alpha.100
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 +1 -1
- package/dist/api/__tests__/create-npm-dirs.spec.d.ts +1 -0
- package/dist/api/__tests__/new.spec.d.ts +1 -0
- package/dist/api/build.d.ts +2 -2
- package/dist/api/create-npm-dirs.d.ts +5 -0
- package/dist/api/templates/index.d.ts +0 -7
- package/dist/api/templates/js-binding.d.ts +2 -1
- package/dist/api/templates/load-wasi-template.d.ts +2 -0
- package/dist/api/templates/wasi-worker-template.d.ts +2 -0
- package/dist/cli.js +3961 -14
- package/dist/def/artifacts.d.ts +21 -1
- package/dist/def/build.d.ts +167 -4
- package/dist/def/create-npm-dirs.d.ts +10 -0
- package/dist/def/new.d.ts +25 -7
- package/dist/def/pre-publish.d.ts +21 -2
- package/dist/def/rename.d.ts +16 -6
- package/dist/def/universalize.d.ts +10 -0
- package/dist/def/version.d.ts +10 -0
- package/dist/index.cjs +10142 -20524
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3711 -29
- package/dist/utils/__tests__/config.spec.d.ts +1 -0
- package/dist/utils/config.d.ts +70 -6
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/metadata.d.ts +13 -1
- package/dist/utils/misc.d.ts +3 -3
- package/dist/utils/read-config.d.ts +7 -0
- package/dist/utils/target.d.ts +9 -6
- package/dist/utils/typegen.d.ts +4 -1
- package/dist/utils/version.d.ts +2 -1
- package/package.json +60 -24
- package/src/api/__tests__/create-npm-dirs.spec.ts +210 -0
- package/src/api/__tests__/new.spec.ts +429 -0
- package/src/api/artifacts.ts +83 -8
- package/src/api/build.ts +682 -134
- package/src/api/create-npm-dirs.ts +64 -13
- package/src/api/new.ts +389 -125
- package/src/api/pre-publish.ts +27 -16
- package/src/api/rename.ts +103 -17
- package/src/api/templates/index.ts +0 -7
- package/src/api/templates/js-binding.ts +212 -107
- package/src/api/templates/load-wasi-template.ts +216 -0
- package/src/api/templates/wasi-worker-template.ts +122 -0
- package/src/api/universalize.ts +13 -8
- package/src/api/version.ts +5 -2
- package/src/commands/artifacts.ts +2 -2
- package/src/commands/build.ts +1 -1
- package/src/commands/new.ts +46 -49
- package/src/def/artifacts.ts +22 -3
- package/src/def/build.ts +83 -8
- package/src/def/create-npm-dirs.ts +9 -0
- package/src/def/new.ts +28 -3
- package/src/def/pre-publish.ts +24 -3
- package/src/def/rename.ts +11 -2
- package/src/def/universalize.ts +9 -0
- package/src/def/version.ts +9 -0
- package/src/index.ts +2 -0
- package/src/utils/__tests__/__fixtures__/napi_type_def +130 -130
- 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 +56 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +703 -164
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/version.spec.ts.md +9 -8
- package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
- package/src/utils/__tests__/config.spec.ts +81 -0
- package/src/utils/__tests__/typegen.spec.ts +19 -4
- package/src/utils/cargo.ts +2 -2
- package/src/utils/config.ts +147 -13
- package/src/utils/index.ts +1 -1
- package/src/utils/log.ts +1 -1
- package/src/utils/metadata.ts +52 -14
- package/src/utils/misc.ts +21 -7
- package/src/utils/read-config.ts +20 -0
- package/src/utils/target.ts +53 -9
- package/src/utils/typegen.ts +100 -40
- package/src/utils/version.ts +11 -9
- package/dist/api/artifacts.js +0 -50
- package/dist/api/build.js +0 -404
- package/dist/api/create-npm-dirs.js +0 -63
- package/dist/api/new.js +0 -154
- package/dist/api/pre-publish.js +0 -157
- package/dist/api/rename.js +0 -28
- package/dist/api/templates/.gitignore.d.ts +0 -1
- package/dist/api/templates/.gitignore.js +0 -198
- package/dist/api/templates/.npmignore.d.ts +0 -1
- package/dist/api/templates/.npmignore.js +0 -14
- package/dist/api/templates/build.rs.d.ts +0 -1
- package/dist/api/templates/build.rs.js +0 -4
- package/dist/api/templates/cargo.toml.d.ts +0 -6
- package/dist/api/templates/cargo.toml.js +0 -25
- package/dist/api/templates/ci-template.d.ts +0 -1
- package/dist/api/templates/ci-template.js +0 -566
- package/dist/api/templates/ci.yml.d.ts +0 -1
- package/dist/api/templates/ci.yml.js +0 -92
- package/dist/api/templates/index.js +0 -8
- package/dist/api/templates/js-binding.js +0 -124
- package/dist/api/templates/lib.rs.d.ts +0 -1
- package/dist/api/templates/lib.rs.js +0 -10
- package/dist/api/templates/package.json.d.ts +0 -8
- package/dist/api/templates/package.json.js +0 -30
- package/dist/api/universalize.js +0 -38
- package/dist/api/version.js +0 -16
- package/dist/commands/artifacts.js +0 -19
- package/dist/commands/build.js +0 -34
- package/dist/commands/create-npm-dirs.js +0 -7
- package/dist/commands/help.js +0 -12
- package/dist/commands/new.js +0 -112
- package/dist/commands/pre-publish.js +0 -8
- package/dist/commands/rename.js +0 -7
- package/dist/commands/universalize.js +0 -7
- package/dist/commands/version.js +0 -7
- package/dist/def/artifacts.js +0 -38
- package/dist/def/build.js +0 -105
- package/dist/def/commands/artifacts.d.ts +0 -15
- package/dist/def/commands/artifacts.js +0 -29
- package/dist/def/commands/build.d.ts +0 -53
- package/dist/def/commands/build.js +0 -105
- package/dist/def/commands/create-npm-dirs.d.ts +0 -15
- package/dist/def/commands/create-npm-dirs.js +0 -29
- package/dist/def/commands/new.d.ts +0 -27
- package/dist/def/commands/new.js +0 -53
- package/dist/def/commands/pre-publish.d.ts +0 -23
- package/dist/def/commands/pre-publish.js +0 -45
- package/dist/def/commands/rename.d.ts +0 -25
- package/dist/def/commands/rename.js +0 -49
- package/dist/def/commands/universalize.d.ts +0 -13
- package/dist/def/commands/universalize.js +0 -25
- package/dist/def/commands/version.d.ts +0 -13
- package/dist/def/commands/version.js +0 -25
- package/dist/def/create-npm-dirs.js +0 -38
- package/dist/def/new.js +0 -66
- package/dist/def/options/artifacts.d.ts +0 -35
- package/dist/def/options/artifacts.js +0 -11
- package/dist/def/options/build.d.ts +0 -97
- package/dist/def/options/build.js +0 -3
- package/dist/def/options/create-npm-dirs.d.ts +0 -35
- package/dist/def/options/create-npm-dirs.js +0 -11
- package/dist/def/options/new.d.ts +0 -79
- package/dist/def/options/new.js +0 -15
- package/dist/def/options/pre-publish.d.ts +0 -65
- package/dist/def/options/pre-publish.js +0 -13
- package/dist/def/options/rename.d.ts +0 -75
- package/dist/def/options/rename.js +0 -11
- package/dist/def/options/universalize.d.ts +0 -28
- package/dist/def/options/universalize.js +0 -10
- package/dist/def/options/version.d.ts +0 -28
- package/dist/def/options/version.js +0 -10
- package/dist/def/pre-publish.js +0 -56
- package/dist/def/rename.js +0 -58
- package/dist/def/universalize.js +0 -33
- package/dist/def/version.js +0 -33
- package/dist/utils/__tests__/target.spec.js +0 -10
- package/dist/utils/__tests__/typegen.spec.js +0 -37
- package/dist/utils/__tests__/version.spec.js +0 -5
- package/dist/utils/cargo.js +0 -33
- package/dist/utils/ci.d.ts +0 -11
- package/dist/utils/ci.js +0 -86
- package/dist/utils/config.js +0 -42
- package/dist/utils/index.js +0 -9
- package/dist/utils/log.js +0 -14
- package/dist/utils/metadata.js +0 -19
- package/dist/utils/misc.js +0 -35
- package/dist/utils/target.js +0 -109
- package/dist/utils/typegen.js +0 -158
- package/dist/utils/version.js +0 -59
- package/src/api/templates/.gitignore.ts +0 -198
- package/src/api/templates/.npmignore.ts +0 -14
- package/src/api/templates/build.rs.ts +0 -4
- package/src/api/templates/cargo.toml.ts +0 -35
- package/src/api/templates/ci-template.ts +0 -566
- package/src/api/templates/ci.yml.ts +0 -116
- package/src/api/templates/lib.rs.ts +0 -10
- package/src/api/templates/package.json.ts +0 -44
- package/src/utils/ci.ts +0 -102
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils/config.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
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", "pnpm"];
|
|
4
|
+
export declare const SupportedTestFrameworks: readonly ["ava"];
|
|
5
|
+
export type SupportedPackageManager = ValueOfConstArray<typeof SupportedPackageManagers>;
|
|
6
|
+
export type SupportedTestFramework = ValueOfConstArray<typeof SupportedTestFrameworks>;
|
|
7
|
+
export interface UserNapiConfig {
|
|
3
8
|
/**
|
|
4
9
|
* Name of the binary to be generated, default to `index`
|
|
5
10
|
*/
|
|
@@ -18,6 +23,50 @@ interface UserNapiConfig {
|
|
|
18
23
|
* The npm client project uses.
|
|
19
24
|
*/
|
|
20
25
|
npmClient?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Whether generate const enum for typescript bindings
|
|
28
|
+
*/
|
|
29
|
+
constEnum?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* dts header prepend to the generated dts file
|
|
32
|
+
*/
|
|
33
|
+
dtsHeader?: string;
|
|
34
|
+
/**
|
|
35
|
+
* dts header file path to be prepended to the generated dts file
|
|
36
|
+
* if both dtsHeader and dtsHeaderFile are provided, dtsHeaderFile will be used
|
|
37
|
+
*/
|
|
38
|
+
dtsHeaderFile?: string;
|
|
39
|
+
/**
|
|
40
|
+
* wasm compilation options
|
|
41
|
+
*/
|
|
42
|
+
wasm?: {
|
|
43
|
+
/**
|
|
44
|
+
* https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Memory
|
|
45
|
+
* @default 4000 pages (256MiB)
|
|
46
|
+
*/
|
|
47
|
+
initialMemory?: number;
|
|
48
|
+
/**
|
|
49
|
+
* @default 65536 pages (4GiB)
|
|
50
|
+
*/
|
|
51
|
+
maximumMemory?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Browser wasm binding configuration
|
|
54
|
+
*/
|
|
55
|
+
browser: {
|
|
56
|
+
/**
|
|
57
|
+
* Whether to use fs module in browser
|
|
58
|
+
*/
|
|
59
|
+
fs?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Whether to initialize wasm asynchronously
|
|
62
|
+
*/
|
|
63
|
+
asyncInit?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Whether to inject `buffer` to emnapi context
|
|
66
|
+
*/
|
|
67
|
+
buffer?: boolean;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
21
70
|
/**
|
|
22
71
|
* @deprecated binaryName instead
|
|
23
72
|
*/
|
|
@@ -35,14 +84,14 @@ interface UserNapiConfig {
|
|
|
35
84
|
/**
|
|
36
85
|
* Whether enable default targets
|
|
37
86
|
*/
|
|
38
|
-
|
|
87
|
+
defaults: boolean;
|
|
39
88
|
/**
|
|
40
89
|
* Additional targets to be compiled for
|
|
41
90
|
*/
|
|
42
91
|
additional?: string[];
|
|
43
92
|
};
|
|
44
93
|
}
|
|
45
|
-
interface CommonPackageJsonFields {
|
|
94
|
+
export interface CommonPackageJsonFields {
|
|
46
95
|
name: string;
|
|
47
96
|
version: string;
|
|
48
97
|
description?: string;
|
|
@@ -50,16 +99,31 @@ interface CommonPackageJsonFields {
|
|
|
50
99
|
author?: string;
|
|
51
100
|
authors?: string[];
|
|
52
101
|
license?: string;
|
|
102
|
+
cpu?: string[];
|
|
103
|
+
os?: string[];
|
|
104
|
+
libc?: string[];
|
|
105
|
+
files?: string[];
|
|
53
106
|
repository?: any;
|
|
54
107
|
homepage?: any;
|
|
55
108
|
engines?: Record<string, string>;
|
|
56
109
|
publishConfig?: any;
|
|
57
110
|
bugs?: any;
|
|
58
111
|
napi?: UserNapiConfig;
|
|
112
|
+
type?: 'module' | 'commonjs';
|
|
113
|
+
scripts?: Record<string, string>;
|
|
114
|
+
main?: string;
|
|
115
|
+
module?: string;
|
|
116
|
+
types?: string;
|
|
117
|
+
browser?: string;
|
|
118
|
+
exports?: any;
|
|
119
|
+
dependencies?: Record<string, string>;
|
|
120
|
+
devDependencies?: Record<string, string>;
|
|
121
|
+
ava?: {
|
|
122
|
+
timeout?: string;
|
|
123
|
+
};
|
|
59
124
|
}
|
|
60
|
-
export type NapiConfig = Required<Pick<UserNapiConfig, 'binaryName' | 'packageName' | 'npmClient'>> & {
|
|
125
|
+
export type NapiConfig = Required<Pick<UserNapiConfig, 'binaryName' | 'packageName' | 'npmClient'>> & Pick<UserNapiConfig, 'wasm' | 'dtsHeader' | 'dtsHeaderFile' | 'constEnum'> & {
|
|
61
126
|
targets: Target[];
|
|
62
127
|
packageJson: CommonPackageJsonFields;
|
|
63
128
|
};
|
|
64
|
-
export declare function readNapiConfig(path: string): Promise<NapiConfig>;
|
|
65
|
-
export {};
|
|
129
|
+
export declare function readNapiConfig(path: string, configPath?: string): Promise<NapiConfig>;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from './ci.js';
|
|
2
1
|
export * from './log.js';
|
|
3
2
|
export * from './misc.js';
|
|
4
3
|
export * from './target.js';
|
|
@@ -7,3 +6,4 @@ export * from './metadata.js';
|
|
|
7
6
|
export * from './config.js';
|
|
8
7
|
export * from './cargo.js';
|
|
9
8
|
export * from './typegen.js';
|
|
9
|
+
export * from './read-config.js';
|
package/dist/utils/metadata.d.ts
CHANGED
|
@@ -13,6 +13,18 @@ export interface Crate {
|
|
|
13
13
|
targets: CrateTarget[];
|
|
14
14
|
features: Record<string, string[]>;
|
|
15
15
|
manifest_path: string;
|
|
16
|
+
dependencies: Array<{
|
|
17
|
+
name: string;
|
|
18
|
+
source: string;
|
|
19
|
+
req: string;
|
|
20
|
+
kind: string | null;
|
|
21
|
+
rename: string | null;
|
|
22
|
+
optional: boolean;
|
|
23
|
+
uses_default_features: boolean;
|
|
24
|
+
features: string[];
|
|
25
|
+
target: string | null;
|
|
26
|
+
registry: string | null;
|
|
27
|
+
}>;
|
|
16
28
|
}
|
|
17
29
|
export interface CargoWorkspaceMetadata {
|
|
18
30
|
version: number;
|
|
@@ -21,4 +33,4 @@ export interface CargoWorkspaceMetadata {
|
|
|
21
33
|
target_directory: string;
|
|
22
34
|
workspace_root: string;
|
|
23
35
|
}
|
|
24
|
-
export declare function parseMetadata(manifestPath: string): CargoWorkspaceMetadata
|
|
36
|
+
export declare function parseMetadata(manifestPath: string): Promise<CargoWorkspaceMetadata>;
|
package/dist/utils/misc.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { readFile, writeFile, copyFile, mkdir, unlink, stat, readdir } from 'fs';
|
|
1
|
+
import { readFile, writeFile, copyFile, mkdir, unlink, stat, readdir } from 'node:fs';
|
|
3
2
|
export declare const readFileAsync: typeof readFile.__promisify__;
|
|
4
3
|
export declare const writeFileAsync: typeof writeFile.__promisify__;
|
|
5
4
|
export declare const unlinkAsync: typeof unlink.__promisify__;
|
|
@@ -8,6 +7,7 @@ export declare const mkdirAsync: typeof mkdir.__promisify__;
|
|
|
8
7
|
export declare const statAsync: typeof stat.__promisify__;
|
|
9
8
|
export declare const readdirAsync: typeof readdir.__promisify__;
|
|
10
9
|
export declare function fileExists(path: string): Promise<boolean>;
|
|
10
|
+
export declare function dirExistsAsync(path: string): Promise<boolean>;
|
|
11
11
|
export declare function pick<O, K extends keyof O>(o: O, ...keys: K[]): Pick<O, K>;
|
|
12
12
|
export declare function updatePackageJson(path: string, partial: Record<string, any>): Promise<void>;
|
|
13
|
-
export declare const CLI_VERSION:
|
|
13
|
+
export declare const CLI_VERSION: string;
|
package/dist/utils/target.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
1
|
+
export type Platform = NodeJS.Platform | 'wasm' | 'wasi' | 'openharmony';
|
|
2
|
+
export declare const UNIVERSAL_TARGETS: {
|
|
3
|
+
readonly 'universal-apple-darwin': readonly ["aarch64-apple-darwin", "x86_64-apple-darwin"];
|
|
4
|
+
};
|
|
5
|
+
export declare const AVAILABLE_TARGETS: readonly ["aarch64-apple-darwin", "aarch64-linux-android", "aarch64-unknown-linux-gnu", "aarch64-unknown-linux-musl", "aarch64-unknown-linux-ohos", "aarch64-pc-windows-msvc", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-unknown-linux-ohos", "x86_64-unknown-freebsd", "i686-pc-windows-msvc", "armv7-unknown-linux-gnueabihf", "armv7-unknown-linux-musleabihf", "armv7-linux-androideabi", "universal-apple-darwin", "riscv64gc-unknown-linux-gnu", "powerpc64le-unknown-linux-gnu", "s390x-unknown-linux-gnu", "wasm32-wasi-preview1-threads", "wasm32-wasip1-threads"];
|
|
3
6
|
export type TargetTriple = (typeof AVAILABLE_TARGETS)[number];
|
|
4
|
-
export declare const DEFAULT_TARGETS: readonly ["x86_64-apple-darwin", "x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu"];
|
|
7
|
+
export declare const DEFAULT_TARGETS: readonly ["x86_64-apple-darwin", "aarch64-apple-darwin", "x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu"];
|
|
5
8
|
export declare const TARGET_LINKER: Record<string, string>;
|
|
6
|
-
type NodeJSArch = 'arm' | 'arm64' | 'ia32' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64' | 'universal';
|
|
9
|
+
type NodeJSArch = 'arm' | 'arm64' | 'ia32' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 'riscv64' | 's390' | 's390x' | 'x32' | 'x64' | 'universal' | 'wasm32';
|
|
7
10
|
export declare const NodeArchToCpu: Record<string, string>;
|
|
8
|
-
export declare const UniArchsByPlatform: Partial<Record<
|
|
11
|
+
export declare const UniArchsByPlatform: Partial<Record<Platform, NodeJSArch[]>>;
|
|
9
12
|
export interface Target {
|
|
10
13
|
triple: string;
|
|
11
14
|
platformArchABI: string;
|
|
12
|
-
platform:
|
|
15
|
+
platform: Platform;
|
|
13
16
|
arch: NodeJSArch;
|
|
14
17
|
abi: string | null;
|
|
15
18
|
}
|
package/dist/utils/typegen.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export declare const DEFAULT_TYPE_DEF_HEADER = "/* auto-generated by NAPI-RS */\n/* eslint-disable */\n";
|
|
2
|
-
export declare function processTypeDef(intermediateTypeFile: string,
|
|
2
|
+
export declare function processTypeDef(intermediateTypeFile: string, constEnum: boolean): Promise<{
|
|
3
|
+
dts: string;
|
|
4
|
+
exports: string[];
|
|
5
|
+
}>;
|
|
3
6
|
export declare function correctStringIdent(src: string, ident: number): string;
|
package/dist/utils/version.d.ts
CHANGED
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.100",
|
|
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": {
|
|
@@ -67,34 +67,70 @@
|
|
|
67
67
|
"url": "https://github.com/napi-rs/napi-rs/issues"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
70
|
+
"@inquirer/prompts": "^7.4.0",
|
|
71
|
+
"@napi-rs/cross-toolchain": "^0.0.19",
|
|
72
|
+
"@napi-rs/wasm-tools": "^0.0.3",
|
|
73
|
+
"@octokit/rest": "^22.0.0",
|
|
74
|
+
"clipanion": "^4.0.0-rc.4",
|
|
75
|
+
"colorette": "^2.0.20",
|
|
76
|
+
"debug": "^4.4.0",
|
|
77
|
+
"emnapi": "^1.4.0",
|
|
78
|
+
"find-up": "^7.0.0",
|
|
75
79
|
"js-yaml": "^4.1.0",
|
|
76
80
|
"lodash-es": "^4.17.21",
|
|
77
|
-
"
|
|
81
|
+
"semver": "^7.7.1",
|
|
82
|
+
"typanion": "^3.14.0",
|
|
83
|
+
"wasm-sjlj": "^1.0.6"
|
|
78
84
|
},
|
|
79
85
|
"devDependencies": {
|
|
80
|
-
"@
|
|
81
|
-
"@
|
|
82
|
-
"@
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
86
|
+
"@emnapi/core": "^1.4.0",
|
|
87
|
+
"@emnapi/runtime": "^1.4.0",
|
|
88
|
+
"@oxc-node/core": "^0.0.29",
|
|
89
|
+
"@std/toml": "npm:@jsr/std__toml@^1.0.8",
|
|
90
|
+
"@types/debug": "^4.1.12",
|
|
91
|
+
"@types/inquirer": "^9.0.7",
|
|
92
|
+
"@types/js-yaml": "^4.0.9",
|
|
93
|
+
"@types/lodash-es": "^4.17.12",
|
|
94
|
+
"@types/node": "^22.13.16",
|
|
95
|
+
"@types/semver": "^7.7.0",
|
|
96
|
+
"ava": "^6.2.0",
|
|
97
|
+
"env-paths": "^3.0.0",
|
|
98
|
+
"prettier": "^3.5.3",
|
|
99
|
+
"rolldown": "^1.0.0-beta.23",
|
|
100
|
+
"tslib": "^2.8.1",
|
|
101
|
+
"typescript": "^5.8.2"
|
|
102
|
+
},
|
|
103
|
+
"peerDependencies": {
|
|
104
|
+
"@emnapi/runtime": "^1.1.0",
|
|
105
|
+
"emnapi": "^1.1.0"
|
|
106
|
+
},
|
|
107
|
+
"peerDependenciesMeta": {
|
|
108
|
+
"@emnapi/runtime": {
|
|
109
|
+
"optional": true
|
|
110
|
+
},
|
|
111
|
+
"emnapi": {
|
|
112
|
+
"optional": true
|
|
113
|
+
}
|
|
88
114
|
},
|
|
89
115
|
"funding": {
|
|
90
116
|
"type": "github",
|
|
91
117
|
"url": "https://github.com/sponsors/Brooooooklyn"
|
|
92
118
|
},
|
|
93
119
|
"scripts": {
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"build
|
|
97
|
-
"test": "ava"
|
|
120
|
+
"clean": "node --import @oxc-node/core/register ./clean.ts",
|
|
121
|
+
"codegen": "node --import @oxc-node/core/register ./codegen/index.ts",
|
|
122
|
+
"build": "tsc && yarn clean && rolldown -c rolldown.config.js",
|
|
123
|
+
"test": "node --import @oxc-node/core/register ../node_modules/ava/entrypoints/cli.mjs"
|
|
124
|
+
},
|
|
125
|
+
"ava": {
|
|
126
|
+
"extensions": {
|
|
127
|
+
"ts": "module"
|
|
128
|
+
},
|
|
129
|
+
"timeout": "1m",
|
|
130
|
+
"files": [
|
|
131
|
+
"**/__tests__/**/*.spec.ts",
|
|
132
|
+
"e2e/**/*.spec.ts"
|
|
133
|
+
]
|
|
98
134
|
},
|
|
99
|
-
"gitHead": "
|
|
135
|
+
"gitHead": "40839a3a5e798bcbc59c5466d741f45a4794d1fd"
|
|
100
136
|
}
|
|
@@ -0,0 +1,210 @@
|
|
|
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
|
+
})
|