Skip to content

Commit 029be44

Browse files
authored
chore: release 0.1.2 (#65)
1 parent d0af319 commit 029be44

File tree

7 files changed

+117
-26
lines changed

7 files changed

+117
-26
lines changed

.github/workflows/release-npm.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ jobs:
130130
git status
131131
cp napi/{index,browser}.js npm
132132
cp napi/index.d.ts npm
133-
pnpm node scripts/x.mjs publish --otp --tag ${{inputs.tag}} ${{inputs.dry_run && '--dry-run' || '--no-dry-run'}} ${{inputs.push_tags && '--push-tags' || '--no-push-tags'}}
133+
pnpm node scripts/x.mjs prepublish
134+
pnpm node scripts/x.mjs publish --otp --tag ${{inputs.tag}} ${{inputs.dry_run && '--dry-run' || '--no-dry-run'}} ${{inputs.push_tags && '--push-tags' || '--no-push-tags'}}
134135
env:
135136
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
136137
REPOSITORY: ${{ github.repository }}

npm/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Oxc Resolver Napi Binding
1+
# Rspack Resolver Napi Binding
22

33
See
44

55
* `index.d.ts` for `resolveSync` and `ResolverFactory` API.
6-
* [README.md](https://github.com/oxc-project/oxc-resolver?tab=readme-ov-file#oxc-resolver) for options.
6+
* [README.md](https://github.com/web-infra-dev/rspack-resolver?tab=readme-ov-file#rspack-resolver) for options.
77

88
## API
99

npm/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rspack/resolver",
3-
"version": "1.12.0",
3+
"version": "0.1.2",
44
"description": "Rspack Resolver Node API",
55
"main": "index.js",
66
"browser": "browser.js",
@@ -39,6 +39,5 @@
3939
"aarch64-apple-darwin"
4040
]
4141
},
42-
"optionalDependencies": {
43-
}
42+
"optionalDependencies": {}
4443
}

pnpm-lock.yaml

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/prepublish.mjs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import * as path from "node:path";
2+
import fs from "node:fs/promises";
3+
import {getPackageJson} from "./version.mjs";
4+
5+
const CpuToNodeArch = {
6+
x86_64: "x64",
7+
aarch64: "arm64",
8+
i686: "ia32",
9+
armv7: "arm"
10+
};
11+
12+
const NodeArchToCpu = {
13+
x64: "x86_64",
14+
arm64: "aarch64",
15+
ia32: "i686",
16+
arm: "armv7"
17+
};
18+
19+
const SysToNodePlatform = {
20+
linux: "linux",
21+
freebsd: "freebsd",
22+
darwin: "darwin",
23+
windows: "win32"
24+
};
25+
26+
const AbiToNodeLibc = {
27+
gnu: "glibc",
28+
musl: "musl"
29+
};
30+
31+
const UniArchsByPlatform = {
32+
darwin: ["x64", "arm64"]
33+
};
34+
35+
/**
36+
* A triple is a specific format for specifying a target architecture.
37+
* 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.
38+
* The general format of the triple is `<arch><sub>-<vendor>-<sys>-<abi>` where:
39+
* - `arch` = The base CPU architecture, for example `x86_64`, `i686`, `arm`, `thumb`, `mips`, etc.
40+
* - `sub` = The CPU sub-architecture, for example `arm` has `v7`, `v7s`, `v5te`, etc.
41+
* - `vendor` = The vendor, for example `unknown`, `apple`, `pc`, `nvidia`, etc.
42+
* - `sys` = The system name, for example `linux`, `windows`, `darwin`, etc. none is typically used for bare-metal without an OS.
43+
* - `abi` = The ABI, for example `gnu`, `android`, `eabi`, etc.
44+
*/
45+
function parseTriple(rawTriple) {
46+
const triple = rawTriple.endsWith("eabi")
47+
? `${rawTriple.slice(0, -4)}-eabi`
48+
: rawTriple;
49+
const triples = triple.split("-");
50+
let cpu;
51+
let sys;
52+
let abi = null;
53+
if (triples.length === 4) {
54+
[cpu, , sys, abi = null] = triples;
55+
} else if (triples.length === 3) {
56+
[cpu, , sys] = triples;
57+
} else {
58+
[cpu, sys] = triples;
59+
}
60+
const platformName = SysToNodePlatform[sys] ?? sys;
61+
const arch = CpuToNodeArch[cpu] ?? cpu;
62+
return {
63+
platform: platformName,
64+
arch,
65+
abi,
66+
platformArchABI: abi
67+
? `${platformName}-${arch}-${abi}`
68+
: `${platformName}-${arch}`,
69+
raw: rawTriple
70+
};
71+
}
72+
73+
74+
export async function prepublish_handler(options) {
75+
let root = process.cwd();
76+
let json = await getPackageJson(root)
77+
78+
let {napi, version} = json;
79+
80+
let optionalDependencies = {};
81+
for (let rawTarget of napi.targets) {
82+
let target = parseTriple(rawTarget);
83+
optionalDependencies[`${napi.packageName}-${target.platformArchABI}`] = version;
84+
}
85+
86+
const packageFile = path.resolve(process.cwd(), "npm/package.json")
87+
let newPackageJson = {
88+
...json,
89+
optionalDependencies
90+
}
91+
92+
await fs.writeFile(
93+
packageFile,
94+
`${JSON.stringify(newPackageJson, null, 2)}\n`,
95+
"utf-8"
96+
);
97+
98+
}

scripts/version.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ async function getCommitId() {
77
}
88

99
export async function getLastVersion(root) {
10+
let pkg = await getPackageJson(root);
11+
return pkg.version
12+
}
13+
14+
export async function getPackageJson(root) {
1015
const pkgPath = path.resolve(root, "./npm/package.json");
1116

1217
try {
@@ -16,15 +21,15 @@ export async function getLastVersion(root) {
1621
type: "json"
1722
}
1823
});
19-
return result.default.version;
24+
return result.default;
2025
} catch (e) {
2126
// Node < 20
2227
const result = await import(pkgPath, {
2328
assert: {
2429
type: "json"
2530
}
2631
});
27-
return result.default.version;
32+
return result.default;
2833
}
2934
}
3035

scripts/x.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Command } from "commander";
66

77
import { publish_handler } from "./publish.mjs";
88
import { version_handler } from "./version.mjs";
9+
import {prepublish_handler} from "./prepublish.mjs";
910

1011
process.env.CARGO_TERM_COLOR = "always"; // Assume every terminal that using zx supports color
1112
process.env.FORCE_COLOR = 3; // Fix zx losing color output in subprocesses
@@ -39,6 +40,11 @@ program
3940
.description("bump version")
4041
.action(version_handler);
4142

43+
program
44+
.command("prepublish")
45+
.description("prepublishOnly")
46+
.action(prepublish_handler);
47+
4248
let argv = process.argv.slice(2); // remove the `node` and script call
4349
if (argv[0] && /x.mjs/.test(argv[0])) {
4450
// Called from `zx x.mjs`

0 commit comments

Comments
 (0)