@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
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { join } from 'path';
|
|
2
|
-
import { fileURLToPath } from 'url';
|
|
3
|
-
import test from 'ava';
|
|
4
|
-
import { correctStringIdent, processTypeDef } from '../typegen.js';
|
|
5
|
-
test('should ident string correctly', (t) => {
|
|
6
|
-
const input = `
|
|
7
|
-
/**
|
|
8
|
-
* should keep
|
|
9
|
-
* class A {
|
|
10
|
-
* foo = () => {}
|
|
11
|
-
* bar = () => {}
|
|
12
|
-
* }
|
|
13
|
-
*/
|
|
14
|
-
class A {
|
|
15
|
-
foo() {
|
|
16
|
-
a = b
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
bar = () => {
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
boz = 1
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
namespace B {
|
|
26
|
-
namespace C {
|
|
27
|
-
type D = A
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
`;
|
|
31
|
-
t.snapshot(correctStringIdent(input, 0), 'original ident is 0');
|
|
32
|
-
t.snapshot(correctStringIdent(input, 2), 'original ident is 2');
|
|
33
|
-
});
|
|
34
|
-
test('should process type def correctly', async (t) => {
|
|
35
|
-
const dts = await processTypeDef(join(fileURLToPath(import.meta.url), '../', '__fixtures__', 'napi_type_def'));
|
|
36
|
-
t.snapshot(dts);
|
|
37
|
-
});
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import { napiEngineRequirement, NapiVersion } from '../version.js';
|
|
3
|
-
test('should generate correct napi engine requirement', (t) => {
|
|
4
|
-
t.snapshot(Object.values(NapiVersion).filter((v) => typeof v === 'number').map(napiEngineRequirement));
|
|
5
|
-
});
|
package/dist/utils/cargo.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
2
|
-
import { debug } from './log.js';
|
|
3
|
-
export function tryInstallCargoBinary(name, bin) {
|
|
4
|
-
if (detectCargoBinary(bin)) {
|
|
5
|
-
debug('Cargo binary already installed: %s', name);
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
try {
|
|
9
|
-
debug('Installing cargo binary: %s', name);
|
|
10
|
-
execSync(`cargo install ${name}`, {
|
|
11
|
-
stdio: 'inherit',
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
catch (e) {
|
|
15
|
-
throw new Error(`Failed to install cargo binary: ${name}`, {
|
|
16
|
-
cause: e,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function detectCargoBinary(bin) {
|
|
21
|
-
debug('Detecting cargo binary: %s', bin);
|
|
22
|
-
try {
|
|
23
|
-
execSync(`cargo help ${bin}`, {
|
|
24
|
-
stdio: 'ignore',
|
|
25
|
-
});
|
|
26
|
-
debug('Cargo binary detected: %s', bin);
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
debug('Cargo binary not detected: %s', bin);
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
}
|
package/dist/utils/ci.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TargetTriple } from './target.js';
|
|
2
|
-
export declare const CIConfig: Partial<Record<TargetTriple, {
|
|
3
|
-
host: string;
|
|
4
|
-
build_image?: string;
|
|
5
|
-
build_setup?: string[];
|
|
6
|
-
test?: boolean;
|
|
7
|
-
test_image?: string;
|
|
8
|
-
test_setup?: string[];
|
|
9
|
-
yarn_cpu?: string;
|
|
10
|
-
yarn_libc?: string;
|
|
11
|
-
}>>;
|
package/dist/utils/ci.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
export const CIConfig = {
|
|
2
|
-
'x86_64-apple-darwin': {
|
|
3
|
-
host: 'macos-latest',
|
|
4
|
-
},
|
|
5
|
-
'x86_64-pc-windows-msvc': {
|
|
6
|
-
host: 'windows-latest',
|
|
7
|
-
},
|
|
8
|
-
'i686-pc-windows-msvc': {
|
|
9
|
-
host: 'windows-latest',
|
|
10
|
-
test: false,
|
|
11
|
-
},
|
|
12
|
-
'x86_64-unknown-linux-gnu': {
|
|
13
|
-
host: 'ubuntu-latest',
|
|
14
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian',
|
|
15
|
-
},
|
|
16
|
-
'x86_64-unknown-linux-musl': {
|
|
17
|
-
host: 'ubuntu-latest',
|
|
18
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine',
|
|
19
|
-
test_image: 'node:${{ matrix.node }}-alpine',
|
|
20
|
-
yarn_libc: 'musl',
|
|
21
|
-
},
|
|
22
|
-
'aarch64-apple-darwin': {
|
|
23
|
-
host: 'macos-latest',
|
|
24
|
-
build_setup: [
|
|
25
|
-
'sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*',
|
|
26
|
-
'export CC=$(xcrun -f clang)',
|
|
27
|
-
'export CXX=$(xcrun -f clang++)',
|
|
28
|
-
'export SDK_ROOT=$(xcrun --sdk macosx --show-sdk-path)',
|
|
29
|
-
'export CFLAGS="-isysroot $SDK_ROOT -isystem $SDK_ROOT"',
|
|
30
|
-
],
|
|
31
|
-
test: false,
|
|
32
|
-
},
|
|
33
|
-
'aarch64-unknown-linux-gnu': {
|
|
34
|
-
host: 'ubuntu-latest',
|
|
35
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64',
|
|
36
|
-
build_setup: [
|
|
37
|
-
'sudo apt-get update',
|
|
38
|
-
'sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y',
|
|
39
|
-
'export CARGO_BUILD_TARGET=x86_64-unknown-linux-gnu',
|
|
40
|
-
],
|
|
41
|
-
test_image: 'ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.node }}',
|
|
42
|
-
yarn_cpu: 'arm64',
|
|
43
|
-
},
|
|
44
|
-
'aarch64-unknown-linux-musl': {
|
|
45
|
-
host: 'ubuntu-latest',
|
|
46
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine',
|
|
47
|
-
build_setup: ['rustup target add aarch64-unknown-linux-musl'],
|
|
48
|
-
test_image: 'multiarch/alpine:aarch64-latest-stable',
|
|
49
|
-
test_setup: ['apk add nodejs npm yarn'],
|
|
50
|
-
yarn_cpu: 'arm64',
|
|
51
|
-
yarn_libc: 'musl',
|
|
52
|
-
},
|
|
53
|
-
'aarch64-pc-windows-msvc': {
|
|
54
|
-
host: 'windows-latest',
|
|
55
|
-
test: false,
|
|
56
|
-
},
|
|
57
|
-
'armv7-unknown-linux-gnueabihf': {
|
|
58
|
-
host: 'ubuntu-latest',
|
|
59
|
-
build_setup: [
|
|
60
|
-
'sudo apt-get update',
|
|
61
|
-
'sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y',
|
|
62
|
-
],
|
|
63
|
-
yarn_cpu: 'arm',
|
|
64
|
-
test_image: 'ghcr.io/napi-rs/napi-rs/nodejs:armhf-${{ matrix.node }}',
|
|
65
|
-
},
|
|
66
|
-
'aarch64-linux-android': {
|
|
67
|
-
host: 'ubuntu-latest',
|
|
68
|
-
build_setup: [
|
|
69
|
-
'export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"',
|
|
70
|
-
'export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"',
|
|
71
|
-
'export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++"',
|
|
72
|
-
'export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"',
|
|
73
|
-
],
|
|
74
|
-
test: false,
|
|
75
|
-
},
|
|
76
|
-
'armv7-linux-androideabi': {
|
|
77
|
-
host: 'ubuntu-latest',
|
|
78
|
-
build_setup: [
|
|
79
|
-
'export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"',
|
|
80
|
-
'export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"',
|
|
81
|
-
'export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang++"',
|
|
82
|
-
'export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"',
|
|
83
|
-
],
|
|
84
|
-
test: false,
|
|
85
|
-
},
|
|
86
|
-
};
|
package/dist/utils/config.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { merge, omit } from 'lodash-es';
|
|
2
|
-
import { fileExists, readFileAsync } from './misc.js';
|
|
3
|
-
import { DEFAULT_TARGETS, parseTriple } from './target.js';
|
|
4
|
-
export async function readNapiConfig(path) {
|
|
5
|
-
if (!(await fileExists(path))) {
|
|
6
|
-
throw new Error(`napi-rs config not found at ${path}`);
|
|
7
|
-
}
|
|
8
|
-
// May support multiple config sources later on.
|
|
9
|
-
const content = await readFileAsync(path, 'utf8');
|
|
10
|
-
let pkgJson;
|
|
11
|
-
try {
|
|
12
|
-
pkgJson = JSON.parse(content);
|
|
13
|
-
}
|
|
14
|
-
catch (e) {
|
|
15
|
-
throw new Error('Failed to parse napi-rs config', {
|
|
16
|
-
cause: e,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
const userNapiConfig = pkgJson.napi ?? {};
|
|
20
|
-
const napiConfig = merge({
|
|
21
|
-
binaryName: 'index',
|
|
22
|
-
packageName: pkgJson.name,
|
|
23
|
-
targets: [],
|
|
24
|
-
packageJson: pkgJson,
|
|
25
|
-
npmClient: 'npm',
|
|
26
|
-
}, omit(userNapiConfig, 'targets'));
|
|
27
|
-
let targets = userNapiConfig.targets ?? [];
|
|
28
|
-
// compatible with old config
|
|
29
|
-
if (userNapiConfig.package?.name) {
|
|
30
|
-
napiConfig.packageName = userNapiConfig.package.name;
|
|
31
|
-
}
|
|
32
|
-
if (!targets.length) {
|
|
33
|
-
if (userNapiConfig.triples?.default) {
|
|
34
|
-
targets = targets.concat(DEFAULT_TARGETS);
|
|
35
|
-
}
|
|
36
|
-
if (userNapiConfig.triples?.additional?.length) {
|
|
37
|
-
targets = targets.concat(userNapiConfig.triples.additional);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
napiConfig.targets = targets.map(parseTriple);
|
|
41
|
-
return napiConfig;
|
|
42
|
-
}
|
package/dist/utils/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './ci.js';
|
|
2
|
-
export * from './log.js';
|
|
3
|
-
export * from './misc.js';
|
|
4
|
-
export * from './target.js';
|
|
5
|
-
export * from './version.js';
|
|
6
|
-
export * from './metadata.js';
|
|
7
|
-
export * from './config.js';
|
|
8
|
-
export * from './cargo.js';
|
|
9
|
-
export * from './typegen.js';
|
package/dist/utils/log.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as colors from 'colorette';
|
|
2
|
-
import rawDebug from 'debug';
|
|
3
|
-
// debug('%i', 'This is an info')
|
|
4
|
-
rawDebug.formatters.i = (v) => {
|
|
5
|
-
return colors.green(v);
|
|
6
|
-
};
|
|
7
|
-
export const debugFactory = (namespace) => {
|
|
8
|
-
const debug = rawDebug(`napi:${namespace}`);
|
|
9
|
-
debug.info = (...args) => console.error(colors.black(colors.bgGreen(' INFO ')), ...args);
|
|
10
|
-
debug.warn = (...args) => console.error(colors.black(colors.bgYellow(' WARNING ')), ...args);
|
|
11
|
-
debug.error = (...args) => console.error(colors.white(colors.bgRed(' ERROR ')), ...args.map((arg) => arg instanceof Error ? arg.stack ?? arg.message : arg));
|
|
12
|
-
return debug;
|
|
13
|
-
};
|
|
14
|
-
export const debug = debugFactory('utils');
|
package/dist/utils/metadata.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
export function parseMetadata(manifestPath) {
|
|
4
|
-
if (!fs.existsSync(manifestPath)) {
|
|
5
|
-
throw new Error(`No crate found in manifest: ${manifestPath}`);
|
|
6
|
-
}
|
|
7
|
-
const cmd = `cargo metadata --manifest-path ${manifestPath} --format-version 1 --no-deps`;
|
|
8
|
-
try {
|
|
9
|
-
const output = execSync(cmd, {
|
|
10
|
-
encoding: 'utf-8',
|
|
11
|
-
});
|
|
12
|
-
return JSON.parse(output);
|
|
13
|
-
}
|
|
14
|
-
catch (e) {
|
|
15
|
-
throw new Error(`Failed to parse cargo metadata output by command: ${cmd}`, {
|
|
16
|
-
cause: e,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
package/dist/utils/misc.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { readFile, writeFile, copyFile, mkdir, unlink, stat, readdir } from 'fs';
|
|
2
|
-
import { createRequire } from 'module';
|
|
3
|
-
import { promisify } from 'util';
|
|
4
|
-
import { debug } from './log.js';
|
|
5
|
-
const require = createRequire(import.meta.url);
|
|
6
|
-
const pkgJson = require('../../package.json');
|
|
7
|
-
export const readFileAsync = promisify(readFile);
|
|
8
|
-
export const writeFileAsync = promisify(writeFile);
|
|
9
|
-
export const unlinkAsync = promisify(unlink);
|
|
10
|
-
export const copyFileAsync = promisify(copyFile);
|
|
11
|
-
export const mkdirAsync = promisify(mkdir);
|
|
12
|
-
export const statAsync = promisify(stat);
|
|
13
|
-
export const readdirAsync = promisify(readdir);
|
|
14
|
-
export async function fileExists(path) {
|
|
15
|
-
const exists = await statAsync(path)
|
|
16
|
-
.then(() => true)
|
|
17
|
-
.catch(() => false);
|
|
18
|
-
return exists;
|
|
19
|
-
}
|
|
20
|
-
export function pick(o, ...keys) {
|
|
21
|
-
return keys.reduce((acc, key) => {
|
|
22
|
-
acc[key] = o[key];
|
|
23
|
-
return acc;
|
|
24
|
-
}, {});
|
|
25
|
-
}
|
|
26
|
-
export async function updatePackageJson(path, partial) {
|
|
27
|
-
const exists = await fileExists(path);
|
|
28
|
-
if (!exists) {
|
|
29
|
-
debug(`File not exists ${path}`);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const old = require(path);
|
|
33
|
-
await writeFileAsync(path, JSON.stringify({ ...old, ...partial }, null, 2));
|
|
34
|
-
}
|
|
35
|
-
export const CLI_VERSION = pkgJson.version;
|
package/dist/utils/target.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
2
|
-
export const AVAILABLE_TARGETS = [
|
|
3
|
-
'aarch64-apple-darwin',
|
|
4
|
-
'aarch64-linux-android',
|
|
5
|
-
'aarch64-unknown-linux-gnu',
|
|
6
|
-
'aarch64-unknown-linux-musl',
|
|
7
|
-
'aarch64-pc-windows-msvc',
|
|
8
|
-
'x86_64-apple-darwin',
|
|
9
|
-
'x86_64-pc-windows-msvc',
|
|
10
|
-
'x86_64-unknown-linux-gnu',
|
|
11
|
-
'x86_64-unknown-linux-musl',
|
|
12
|
-
'x86_64-unknown-freebsd',
|
|
13
|
-
'i686-pc-windows-msvc',
|
|
14
|
-
'armv7-unknown-linux-gnueabihf',
|
|
15
|
-
'armv7-linux-androideabi',
|
|
16
|
-
'universal-apple-darwin',
|
|
17
|
-
];
|
|
18
|
-
export const DEFAULT_TARGETS = [
|
|
19
|
-
'x86_64-apple-darwin',
|
|
20
|
-
'x86_64-pc-windows-msvc',
|
|
21
|
-
'x86_64-unknown-linux-gnu',
|
|
22
|
-
];
|
|
23
|
-
export const TARGET_LINKER = {
|
|
24
|
-
'aarch64-unknown-linux-gnu': 'aarch64-linux-gnu-gcc',
|
|
25
|
-
'armv7-unknown-linux-gnueabihf': 'arm-linux-gnueabihf-gcc',
|
|
26
|
-
'aarch64-unknown-linux-musl': 'aarch64-linux-musl-gcc',
|
|
27
|
-
};
|
|
28
|
-
const CpuToNodeArch = {
|
|
29
|
-
x86_64: 'x64',
|
|
30
|
-
aarch64: 'arm64',
|
|
31
|
-
i686: 'ia32',
|
|
32
|
-
armv7: 'arm',
|
|
33
|
-
};
|
|
34
|
-
export const NodeArchToCpu = {
|
|
35
|
-
x64: 'x86_64',
|
|
36
|
-
arm64: 'aarch64',
|
|
37
|
-
ia32: 'i686',
|
|
38
|
-
arm: 'armv7',
|
|
39
|
-
};
|
|
40
|
-
const SysToNodePlatform = {
|
|
41
|
-
linux: 'linux',
|
|
42
|
-
freebsd: 'freebsd',
|
|
43
|
-
darwin: 'darwin',
|
|
44
|
-
windows: 'win32',
|
|
45
|
-
};
|
|
46
|
-
export const UniArchsByPlatform = {
|
|
47
|
-
darwin: ['x64', 'arm64'],
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* A triple is a specific format for specifying a target architecture.
|
|
51
|
-
* Triples may be referred to as a target triple which is the architecture for the artifact produced, and the host triple which is the architecture that the compiler is running on.
|
|
52
|
-
* The general format of the triple is `<arch><sub>-<vendor>-<sys>-<abi>` where:
|
|
53
|
-
* - `arch` = The base CPU architecture, for example `x86_64`, `i686`, `arm`, `thumb`, `mips`, etc.
|
|
54
|
-
* - `sub` = The CPU sub-architecture, for example `arm` has `v7`, `v7s`, `v5te`, etc.
|
|
55
|
-
* - `vendor` = The vendor, for example `unknown`, `apple`, `pc`, `nvidia`, etc.
|
|
56
|
-
* - `sys` = The system name, for example `linux`, `windows`, `darwin`, etc. none is typically used for bare-metal without an OS.
|
|
57
|
-
* - `abi` = The ABI, for example `gnu`, `android`, `eabi`, etc.
|
|
58
|
-
*/
|
|
59
|
-
export function parseTriple(rawTriple) {
|
|
60
|
-
const triple = rawTriple.endsWith('eabi')
|
|
61
|
-
? `${rawTriple.slice(0, -4)}-eabi`
|
|
62
|
-
: rawTriple;
|
|
63
|
-
const triples = triple.split('-');
|
|
64
|
-
let cpu;
|
|
65
|
-
let sys;
|
|
66
|
-
let abi = null;
|
|
67
|
-
if (triples.length === 2) {
|
|
68
|
-
// aarch64-fuchsia
|
|
69
|
-
// ^ cpu ^ sys
|
|
70
|
-
;
|
|
71
|
-
[cpu, sys] = triples;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// aarch64-unknown-linux-musl
|
|
75
|
-
// ^ cpu ^ sys ^ abi
|
|
76
|
-
// aarch64-apple-darwin
|
|
77
|
-
// ^ cpu ^ sys (abi is None)
|
|
78
|
-
;
|
|
79
|
-
[cpu, , sys, abi = null] = triples;
|
|
80
|
-
}
|
|
81
|
-
const platform = SysToNodePlatform[sys] ?? sys;
|
|
82
|
-
const arch = CpuToNodeArch[cpu] ?? cpu;
|
|
83
|
-
return {
|
|
84
|
-
triple: rawTriple,
|
|
85
|
-
platformArchABI: abi ? `${platform}-${arch}-${abi}` : `${platform}-${arch}`,
|
|
86
|
-
platform,
|
|
87
|
-
arch,
|
|
88
|
-
abi,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
export function getSystemDefaultTarget() {
|
|
92
|
-
const host = execSync(`rustc -vV`, {
|
|
93
|
-
env: process.env,
|
|
94
|
-
})
|
|
95
|
-
.toString('utf8')
|
|
96
|
-
.split('\n')
|
|
97
|
-
.find((line) => line.startsWith('host: '));
|
|
98
|
-
const triple = host?.slice('host: '.length);
|
|
99
|
-
if (!triple) {
|
|
100
|
-
throw new TypeError(`Can not parse target triple from host`);
|
|
101
|
-
}
|
|
102
|
-
return parseTriple(triple);
|
|
103
|
-
}
|
|
104
|
-
export function getTargetLinker(target) {
|
|
105
|
-
return TARGET_LINKER[target];
|
|
106
|
-
}
|
|
107
|
-
export function targetToEnvVar(target) {
|
|
108
|
-
return target.replace(/-/g, '_').toUpperCase();
|
|
109
|
-
}
|
package/dist/utils/typegen.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { sortBy } from 'lodash-es';
|
|
2
|
-
import { readFileAsync } from './misc.js';
|
|
3
|
-
const TOP_LEVEL_NAMESPACE = '__TOP_LEVEL_MODULE__';
|
|
4
|
-
export const DEFAULT_TYPE_DEF_HEADER = `/* auto-generated by NAPI-RS */
|
|
5
|
-
/* eslint-disable */
|
|
6
|
-
`;
|
|
7
|
-
var TypeDefKind;
|
|
8
|
-
(function (TypeDefKind) {
|
|
9
|
-
TypeDefKind["Const"] = "const";
|
|
10
|
-
TypeDefKind["Enum"] = "enum";
|
|
11
|
-
TypeDefKind["Interface"] = "interface";
|
|
12
|
-
TypeDefKind["Fn"] = "fn";
|
|
13
|
-
TypeDefKind["Struct"] = "struct";
|
|
14
|
-
TypeDefKind["Impl"] = "impl";
|
|
15
|
-
})(TypeDefKind || (TypeDefKind = {}));
|
|
16
|
-
function prettyPrint(line, ident) {
|
|
17
|
-
let s = line.js_doc ?? '';
|
|
18
|
-
switch (line.kind) {
|
|
19
|
-
case TypeDefKind.Interface:
|
|
20
|
-
s += `export interface ${line.name} {\n${line.def}\n}`;
|
|
21
|
-
break;
|
|
22
|
-
case TypeDefKind.Enum:
|
|
23
|
-
s += `export const enum ${line.name} {\n${line.def}\n}`;
|
|
24
|
-
break;
|
|
25
|
-
case TypeDefKind.Struct:
|
|
26
|
-
s += `export class ${line.name} {\n${line.def}\n}`;
|
|
27
|
-
if (line.original_name && line.original_name !== line.name) {
|
|
28
|
-
s += `\nexport type ${line.original_name} = ${line.name}`;
|
|
29
|
-
}
|
|
30
|
-
break;
|
|
31
|
-
default:
|
|
32
|
-
s += line.def;
|
|
33
|
-
}
|
|
34
|
-
return correctStringIdent(s, ident);
|
|
35
|
-
}
|
|
36
|
-
export async function processTypeDef(intermediateTypeFile, header) {
|
|
37
|
-
const defs = await readIntermediateTypeFile(intermediateTypeFile);
|
|
38
|
-
const groupedDefs = preprocessTypeDef(defs);
|
|
39
|
-
header = header ? header + '\n' : '';
|
|
40
|
-
let dts = '';
|
|
41
|
-
sortBy(Array.from(groupedDefs), ([namespace]) => namespace).forEach(([namespace, defs]) => {
|
|
42
|
-
if (namespace === TOP_LEVEL_NAMESPACE) {
|
|
43
|
-
for (const def of defs) {
|
|
44
|
-
dts += prettyPrint(def, 0) + '\n\n';
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
dts += `export namespace ${namespace} {\n`;
|
|
49
|
-
for (const def of defs) {
|
|
50
|
-
dts += prettyPrint(def, 2) + '\n';
|
|
51
|
-
}
|
|
52
|
-
dts += '}\n\n';
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
if (dts.indexOf('ExternalObject<') > -1) {
|
|
56
|
-
header += `
|
|
57
|
-
export class ExternalObject<T> {
|
|
58
|
-
readonly '': {
|
|
59
|
-
readonly '': unique symbol
|
|
60
|
-
[K: symbol]: T
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
`;
|
|
64
|
-
}
|
|
65
|
-
return header + dts;
|
|
66
|
-
}
|
|
67
|
-
async function readIntermediateTypeFile(file) {
|
|
68
|
-
const content = await readFileAsync(file, 'utf8');
|
|
69
|
-
const defs = content
|
|
70
|
-
.split('\n')
|
|
71
|
-
.filter(Boolean)
|
|
72
|
-
.map((line) => {
|
|
73
|
-
line = line.trim();
|
|
74
|
-
if (!line.startsWith('{')) {
|
|
75
|
-
// crateName:{ "def": "", ... }
|
|
76
|
-
const start = line.indexOf(':') + 1;
|
|
77
|
-
line = line.slice(start);
|
|
78
|
-
}
|
|
79
|
-
return JSON.parse(line);
|
|
80
|
-
});
|
|
81
|
-
// move all `struct` def to the very top
|
|
82
|
-
// and order the rest alphabetically.
|
|
83
|
-
return defs.sort((a, b) => {
|
|
84
|
-
if (a.kind === TypeDefKind.Struct) {
|
|
85
|
-
if (b.kind === TypeDefKind.Struct) {
|
|
86
|
-
return a.name.localeCompare(b.name);
|
|
87
|
-
}
|
|
88
|
-
return -1;
|
|
89
|
-
}
|
|
90
|
-
else if (b.kind === TypeDefKind.Struct) {
|
|
91
|
-
return 1;
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
return a.name.localeCompare(b.name);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
function preprocessTypeDef(defs) {
|
|
99
|
-
const namespaceGrouped = new Map();
|
|
100
|
-
const classDefs = new Map();
|
|
101
|
-
for (const def of defs) {
|
|
102
|
-
const namespace = def.js_mod ?? TOP_LEVEL_NAMESPACE;
|
|
103
|
-
if (!namespaceGrouped.has(namespace)) {
|
|
104
|
-
namespaceGrouped.set(namespace, []);
|
|
105
|
-
}
|
|
106
|
-
const group = namespaceGrouped.get(namespace);
|
|
107
|
-
if (def.kind === TypeDefKind.Struct) {
|
|
108
|
-
group.push(def);
|
|
109
|
-
classDefs.set(def.name, def);
|
|
110
|
-
}
|
|
111
|
-
else if (def.kind === TypeDefKind.Impl) {
|
|
112
|
-
// merge `impl` into class definition
|
|
113
|
-
const classDef = classDefs.get(def.name);
|
|
114
|
-
if (classDef) {
|
|
115
|
-
if (classDef.def) {
|
|
116
|
-
classDef.def += '\n';
|
|
117
|
-
}
|
|
118
|
-
classDef.def += def.def;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
group.push(def);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return namespaceGrouped;
|
|
126
|
-
}
|
|
127
|
-
export function correctStringIdent(src, ident) {
|
|
128
|
-
let bracketDepth = 0;
|
|
129
|
-
const result = src
|
|
130
|
-
.split('\n')
|
|
131
|
-
.map((line) => {
|
|
132
|
-
line = line.trim();
|
|
133
|
-
if (line === '') {
|
|
134
|
-
return '';
|
|
135
|
-
}
|
|
136
|
-
const isInMultilineComment = line.startsWith('*');
|
|
137
|
-
const isClosingBracket = line.endsWith('}');
|
|
138
|
-
const isOpeningBracket = line.endsWith('{');
|
|
139
|
-
let rightIndent = ident;
|
|
140
|
-
if (isOpeningBracket && !isInMultilineComment) {
|
|
141
|
-
bracketDepth += 1;
|
|
142
|
-
rightIndent += (bracketDepth - 1) * 2;
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
if (isClosingBracket && bracketDepth > 0 && !isInMultilineComment) {
|
|
146
|
-
bracketDepth -= 1;
|
|
147
|
-
}
|
|
148
|
-
rightIndent += bracketDepth * 2;
|
|
149
|
-
}
|
|
150
|
-
if (isInMultilineComment) {
|
|
151
|
-
rightIndent += 1;
|
|
152
|
-
}
|
|
153
|
-
const s = `${' '.repeat(rightIndent)}${line}`;
|
|
154
|
-
return s;
|
|
155
|
-
})
|
|
156
|
-
.join('\n');
|
|
157
|
-
return result;
|
|
158
|
-
}
|
package/dist/utils/version.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export var NapiVersion;
|
|
2
|
-
(function (NapiVersion) {
|
|
3
|
-
NapiVersion[NapiVersion["Napi1"] = 1] = "Napi1";
|
|
4
|
-
NapiVersion[NapiVersion["Napi2"] = 2] = "Napi2";
|
|
5
|
-
NapiVersion[NapiVersion["Napi3"] = 3] = "Napi3";
|
|
6
|
-
NapiVersion[NapiVersion["Napi4"] = 4] = "Napi4";
|
|
7
|
-
NapiVersion[NapiVersion["Napi5"] = 5] = "Napi5";
|
|
8
|
-
NapiVersion[NapiVersion["Napi6"] = 6] = "Napi6";
|
|
9
|
-
NapiVersion[NapiVersion["Napi7"] = 7] = "Napi7";
|
|
10
|
-
NapiVersion[NapiVersion["Napi8"] = 8] = "Napi8";
|
|
11
|
-
})(NapiVersion = NapiVersion || (NapiVersion = {}));
|
|
12
|
-
/// because node support new napi version in some minor version updates, so we might meet such situation:
|
|
13
|
-
/// `node v10.20.0` supports `napi5` and `napi6`, but `node v12.0.0` only support `napi4`,
|
|
14
|
-
/// by which, we can not tell directly napi version supportness from node version directly.
|
|
15
|
-
const NAPI_VERSION_MATRIX = new Map([
|
|
16
|
-
[NapiVersion.Napi1, '8.6.0'],
|
|
17
|
-
[NapiVersion.Napi2, '8.10.0 | 9.3.0'],
|
|
18
|
-
[NapiVersion.Napi3, '6.14.2 | 8.11.2 | 9.11.0'],
|
|
19
|
-
[NapiVersion.Napi4, '10.16.0 | 11.8.0'],
|
|
20
|
-
[NapiVersion.Napi5, '10.17.0 | 12.11.0'],
|
|
21
|
-
[NapiVersion.Napi6, '10.20.0 | 12.17.0 | 14.0.0'],
|
|
22
|
-
[NapiVersion.Napi7, '10.23.0 | 12.19.0 | 14.12.0'],
|
|
23
|
-
[NapiVersion.Napi8, '12.22.0 | 14.17.0 | 15.12.0'],
|
|
24
|
-
]);
|
|
25
|
-
function parseNodeVersion(v) {
|
|
26
|
-
const matches = v.match(/v?([0-9]+)\.([0-9]+)\.([0-9]+)/i);
|
|
27
|
-
if (!matches) {
|
|
28
|
-
throw new Error('Unknown node version number: ' + v);
|
|
29
|
-
}
|
|
30
|
-
const [, major, minor, patch] = matches;
|
|
31
|
-
return {
|
|
32
|
-
major: parseInt(major),
|
|
33
|
-
minor: parseInt(minor),
|
|
34
|
-
patch: parseInt(patch),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function requiredNodeVersions(napiVersion) {
|
|
38
|
-
const requirement = NAPI_VERSION_MATRIX.get(napiVersion);
|
|
39
|
-
if (!requirement) {
|
|
40
|
-
return [parseNodeVersion('10.0.0')];
|
|
41
|
-
}
|
|
42
|
-
return requirement.split('|').map(parseNodeVersion);
|
|
43
|
-
}
|
|
44
|
-
function toEngineRequirement(versions) {
|
|
45
|
-
const requirements = [];
|
|
46
|
-
versions.forEach((v, i) => {
|
|
47
|
-
let req = '';
|
|
48
|
-
if (i !== 0) {
|
|
49
|
-
const lastVersion = versions[i - 1];
|
|
50
|
-
req += `< ${lastVersion.major + 1}`;
|
|
51
|
-
}
|
|
52
|
-
req += `${i === 0 ? '' : ' || '}>= ${v.major}.${v.minor}.${v.patch}`;
|
|
53
|
-
requirements.push(req);
|
|
54
|
-
});
|
|
55
|
-
return requirements.join(' && ');
|
|
56
|
-
}
|
|
57
|
-
export function napiEngineRequirement(napiVersion) {
|
|
58
|
-
return toEngineRequirement(requiredNodeVersions(napiVersion));
|
|
59
|
-
}
|