Skip to content

Commit 4495b61

Browse files
committed
style: normalize indentation and quote style in npm scripts and install.js
- npm/scripts/build.sh: convert tab indentation to 2-space indentation - npm/unirtm/install.js: replace single quotes with double quotes for consistency - .goreleaser.yaml: minor cleanup - specs/2-pip-packaging/plan.md: add blank line for readability
1 parent 9da4034 commit 4495b61

4 files changed

Lines changed: 104 additions & 104 deletions

File tree

.goreleaser.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ changelog:
131131
sboms:
132132
- artifacts: archive
133133

134-
135134
# signs:
136135
# - artifacts: checksum
137136
# args:

npm/scripts/build.sh

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,36 @@ VERSION_FILE="${PROJECT_ROOT}/VERSION"
2727
# ---------------------------------------------------------------------------
2828
VERSION=""
2929
while [ $# -gt 0 ]; do
30-
case "$1" in
31-
--version)
32-
VERSION="$2"
33-
shift 2
34-
;;
35-
--dist-dir)
36-
DIST_DIR="$2"
37-
shift 2
38-
;;
39-
--npm-dir)
40-
NPM_DIR="$2"
41-
shift 2
42-
;;
43-
*)
44-
printf 'Unknown argument: %s\n' "$1" >&2
45-
exit 1
46-
;;
47-
esac
30+
case "$1" in
31+
--version)
32+
VERSION="$2"
33+
shift 2
34+
;;
35+
--dist-dir)
36+
DIST_DIR="$2"
37+
shift 2
38+
;;
39+
--npm-dir)
40+
NPM_DIR="$2"
41+
shift 2
42+
;;
43+
*)
44+
printf 'Unknown argument: %s\n' "$1" >&2
45+
exit 1
46+
;;
47+
esac
4848
done
4949

5050
# ---------------------------------------------------------------------------
5151
# Resolve version
5252
# ---------------------------------------------------------------------------
5353
if [ -z "${VERSION}" ]; then
54-
if [ -f "${VERSION_FILE}" ]; then
55-
VERSION="$(cat "${VERSION_FILE}" | tr -d '[:space:]')"
56-
else
57-
printf 'ERROR: VERSION file not found and --version not specified.\n' >&2
58-
exit 1
59-
fi
54+
if [ -f "${VERSION_FILE}" ]; then
55+
VERSION="$(cat "${VERSION_FILE}" | tr -d '[:space:]')"
56+
else
57+
printf 'ERROR: VERSION file not found and --version not specified.\n' >&2
58+
exit 1
59+
fi
6060
fi
6161

6262
# Strip leading 'v' for npm semver compatibility
@@ -92,32 +92,32 @@ unirtm-windows-ia32|unirtm_windows_386_sse2|unirtm.exe
9292
# Helper: generate package.json from .tpl file
9393
# ---------------------------------------------------------------------------
9494
generate_package_json() {
95-
local _pkg_dir="$1"
96-
local _version="$2"
97-
local _tpl="${_pkg_dir}/package.json.tpl"
98-
local _out="${_pkg_dir}/package.json"
99-
100-
if [ ! -f "${_tpl}" ]; then
101-
printf ' ⚠️ Template not found: %s (skipping package.json generation)\n' "${_tpl}"
102-
return 0
103-
fi
104-
105-
# Replace {{VERSION}} placeholder
106-
sed "s/{{VERSION}}/${_version}/g" "${_tpl}" >"${_out}"
107-
printf ' ✅ Generated: %s\n' "${_out#"${PROJECT_ROOT}"/}"
95+
local _pkg_dir="$1"
96+
local _version="$2"
97+
local _tpl="${_pkg_dir}/package.json.tpl"
98+
local _out="${_pkg_dir}/package.json"
99+
100+
if [ ! -f "${_tpl}" ]; then
101+
printf ' ⚠️ Template not found: %s (skipping package.json generation)\n' "${_tpl}"
102+
return 0
103+
fi
104+
105+
# Replace {{VERSION}} placeholder
106+
sed "s/{{VERSION}}/${_version}/g" "${_tpl}" >"${_out}"
107+
printf ' ✅ Generated: %s\n' "${_out#"${PROJECT_ROOT}"/}"
108108
}
109109

110110
# ---------------------------------------------------------------------------
111111
# Helper: copy documentation files
112112
# ---------------------------------------------------------------------------
113113
copy_docs() {
114-
local _pkg_dir="$1"
114+
local _pkg_dir="$1"
115115

116-
for _doc in LICENSE README.md README_zh-CN.md; do
117-
if [ -f "${PROJECT_ROOT}/${_doc}" ]; then
118-
cp "${PROJECT_ROOT}/${_doc}" "${_pkg_dir}/${_doc}"
119-
fi
120-
done
116+
for _doc in LICENSE README.md README_zh-CN.md; do
117+
if [ -f "${PROJECT_ROOT}/${_doc}" ]; then
118+
cp "${PROJECT_ROOT}/${_doc}" "${_pkg_dir}/${_doc}"
119+
fi
120+
done
121121
}
122122

123123
# ---------------------------------------------------------------------------
@@ -126,38 +126,38 @@ copy_docs() {
126126
printf '\n📦 Processing platform packages...\n'
127127

128128
printf '%s' "${PLATFORMS}" | grep -v '^$' | while IFS='|' read -r _npm_pkg _dist_subdir _binary; do
129-
_pkg_dir="${NPM_DIR}/${_npm_pkg}"
130-
_src_binary="${DIST_DIR}/${_dist_subdir}/${_binary}"
131-
_bin_dir="${_pkg_dir}/bin"
132-
_dst_binary="${_bin_dir}/${_binary}"
129+
_pkg_dir="${NPM_DIR}/${_npm_pkg}"
130+
_src_binary="${DIST_DIR}/${_dist_subdir}/${_binary}"
131+
_bin_dir="${_pkg_dir}/bin"
132+
_dst_binary="${_bin_dir}/${_binary}"
133133

134-
printf '\n🔧 %s\n' "${_npm_pkg}"
134+
printf '\n🔧 %s\n' "${_npm_pkg}"
135135

136-
# Verify source binary exists
137-
if [ ! -f "${_src_binary}" ]; then
138-
printf ' ❌ Source binary not found: %s\n' "${_src_binary}"
139-
printf ' Skipping (run GoReleaser build first)\n'
140-
continue
141-
fi
136+
# Verify source binary exists
137+
if [ ! -f "${_src_binary}" ]; then
138+
printf ' ❌ Source binary not found: %s\n' "${_src_binary}"
139+
printf ' Skipping (run GoReleaser build first)\n'
140+
continue
141+
fi
142142

143-
# Create bin directory
144-
mkdir -p "${_bin_dir}"
143+
# Create bin directory
144+
mkdir -p "${_bin_dir}"
145145

146-
# Copy binary
147-
cp "${_src_binary}" "${_dst_binary}"
146+
# Copy binary
147+
cp "${_src_binary}" "${_dst_binary}"
148148

149-
# Set executable permission (no-op on Windows binaries, harmless)
150-
chmod +x "${_dst_binary}"
149+
# Set executable permission (no-op on Windows binaries, harmless)
150+
chmod +x "${_dst_binary}"
151151

152-
printf ' ✅ Binary: %s -> %s\n' \
153-
"${_src_binary#"${PROJECT_ROOT}"/}" \
154-
"${_dst_binary#"${PROJECT_ROOT}"/}"
152+
printf ' ✅ Binary: %s -> %s\n' \
153+
"${_src_binary#"${PROJECT_ROOT}"/}" \
154+
"${_dst_binary#"${PROJECT_ROOT}"/}"
155155

156-
# Generate package.json from template
157-
generate_package_json "${_pkg_dir}" "${VERSION_NPM}"
156+
# Generate package.json from template
157+
generate_package_json "${_pkg_dir}" "${VERSION_NPM}"
158158

159-
# Copy documentation
160-
copy_docs "${_pkg_dir}"
159+
# Copy documentation
160+
copy_docs "${_pkg_dir}"
161161
done
162162

163163
# ---------------------------------------------------------------------------

npm/unirtm/install.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
// - Runs it (when invoked as CLI)
77
// - Validates the installation (when invoked via postinstall)
88

9-
'use strict';
9+
"use strict";
1010

11-
const { execFileSync, spawnSync } = require('child_process');
12-
const path = require('path');
13-
const fs = require('fs');
14-
const os = require('os');
11+
const { execFileSync, spawnSync } = require("child_process");
12+
const path = require("path");
13+
const fs = require("fs");
14+
const os = require("os");
1515

1616
// ---------------------------------------------------------------------------
1717
// Platform detection
@@ -23,41 +23,41 @@ const os = require('os');
2323
*/
2424
function getPlatformPackageSuffix() {
2525
const platform = process.platform; // 'darwin' | 'linux' | 'win32'
26-
const arch = process.arch; // 'x64' | 'arm64' | 'arm' | 'ia32'
26+
const arch = process.arch; // 'x64' | 'arm64' | 'arm' | 'ia32'
2727

2828
// ARM sub-arch detection (armv5/armv6/armv7)
2929
// process.config.variables.arm_version is available in some Node builds
30-
const armVersion = (process.config && process.config.variables && process.config.variables.arm_version) || '';
30+
const armVersion = (process.config && process.config.variables && process.config.variables.arm_version) || "";
3131

32-
if (platform === 'darwin') {
33-
if (arch === 'arm64') return 'darwin-arm64';
34-
if (arch === 'x64') return 'darwin-x64';
32+
if (platform === "darwin") {
33+
if (arch === "arm64") return "darwin-arm64";
34+
if (arch === "x64") return "darwin-x64";
3535
}
3636

37-
if (platform === 'linux') {
38-
if (arch === 'x64') return 'linux-x64';
39-
if (arch === 'arm64') return 'linux-arm64';
40-
if (arch === 'ia32') return 'linux-ia32';
41-
if (arch === 'arm') {
42-
if (armVersion === '5') return 'linux-arm-5';
43-
if (armVersion === '6') return 'linux-arm-6';
44-
return 'linux-arm'; // armv7 default
37+
if (platform === "linux") {
38+
if (arch === "x64") return "linux-x64";
39+
if (arch === "arm64") return "linux-arm64";
40+
if (arch === "ia32") return "linux-ia32";
41+
if (arch === "arm") {
42+
if (armVersion === "5") return "linux-arm-5";
43+
if (armVersion === "6") return "linux-arm-6";
44+
return "linux-arm"; // armv7 default
4545
}
46-
if (arch === 'loong64') return 'linux-loong64';
47-
if (arch === 'ppc64') return 'linux-ppc64le';
48-
if (arch === 'riscv64') return 'linux-riscv64';
49-
if (arch === 's390x') return 'linux-s390x';
46+
if (arch === "loong64") return "linux-loong64";
47+
if (arch === "ppc64") return "linux-ppc64le";
48+
if (arch === "riscv64") return "linux-riscv64";
49+
if (arch === "s390x") return "linux-s390x";
5050
}
5151

52-
if (platform === 'win32') {
53-
if (arch === 'x64') return 'windows-x64';
54-
if (arch === 'arm64') return 'windows-arm64';
55-
if (arch === 'ia32') return 'windows-ia32';
52+
if (platform === "win32") {
53+
if (arch === "x64") return "windows-x64";
54+
if (arch === "arm64") return "windows-arm64";
55+
if (arch === "ia32") return "windows-ia32";
5656
}
5757

5858
throw new Error(
5959
`Unsupported platform: ${platform}-${arch}\n` +
60-
'Please open an issue at https://github.com/snowdreamtech/unirtm/issues'
60+
"Please open an issue at https://github.com/snowdreamtech/unirtm/issues"
6161
);
6262
}
6363

@@ -72,13 +72,13 @@ function getPlatformPackageSuffix() {
7272
*/
7373
function resolveBinary(suffix) {
7474
const pkgName = `@snowdreamtech/unirtm-${suffix}`;
75-
const binaryName = process.platform === 'win32' ? 'unirtm.exe' : 'unirtm';
75+
const binaryName = process.platform === "win32" ? "unirtm.exe" : "unirtm";
7676

7777
// Strategy 1: resolve via require.resolve (works when package is installed)
7878
try {
7979
const pkgJsonPath = require.resolve(`${pkgName}/package.json`);
8080
const pkgDir = path.dirname(pkgJsonPath);
81-
const binPath = path.join(pkgDir, 'bin', binaryName);
81+
const binPath = path.join(pkgDir, "bin", binaryName);
8282
if (fs.existsSync(binPath)) {
8383
return binPath;
8484
}
@@ -89,7 +89,7 @@ function resolveBinary(suffix) {
8989
// Strategy 2: walk up node_modules hierarchy
9090
let dir = __dirname;
9191
for (let i = 0; i < 10; i++) {
92-
const candidate = path.join(dir, 'node_modules', pkgName, 'bin', binaryName);
92+
const candidate = path.join(dir, "node_modules", pkgName, "bin", binaryName);
9393
if (fs.existsSync(candidate)) {
9494
return candidate;
9595
}
@@ -100,24 +100,24 @@ function resolveBinary(suffix) {
100100

101101
throw new Error(
102102
`Could not find binary for ${pkgName}.\n` +
103-
'Try reinstalling @snowdreamtech/unirtm:\n' +
104-
' npm install @snowdreamtech/unirtm\n\n' +
105-
`Platform: ${process.platform}-${process.arch}`
103+
"Try reinstalling @snowdreamtech/unirtm:\n" +
104+
" npm install @snowdreamtech/unirtm\n\n" +
105+
`Platform: ${process.platform}-${process.arch}`
106106
);
107107
}
108108

109109
// ---------------------------------------------------------------------------
110110
// Entry point
111111
// ---------------------------------------------------------------------------
112112

113-
const isPostInstall = process.env.npm_lifecycle_event === 'postinstall';
113+
const isPostInstall = process.env.npm_lifecycle_event === "postinstall";
114114

115115
if (isPostInstall) {
116116
// Postinstall: just validate that the binary can be found
117117
try {
118118
const suffix = getPlatformPackageSuffix();
119119
const binPath = resolveBinary(suffix);
120-
const result = spawnSync(binPath, ['--version'], { encoding: 'utf8' });
120+
const result = spawnSync(binPath, ["--version"], { encoding: "utf8" });
121121
if (result.status === 0) {
122122
process.stdout.write(`✅ unirtm installed successfully (${binPath})\n`);
123123
}
@@ -133,7 +133,7 @@ if (isPostInstall) {
133133
const args = process.argv.slice(2);
134134

135135
const result = spawnSync(binPath, args, {
136-
stdio: 'inherit',
136+
stdio: "inherit",
137137
windowsHide: false,
138138
});
139139

specs/2-pip-packaging/plan.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
## Summary
77

88
为 UniRTM 建立 Python wheel 发布体系。pip 的分发机制与 npm 有本质差异:
9+
910
- **npm**:一个根包 + N 个平台子包,通过 `optionalDependencies` + `os/cpu` 字段筛选
1011
- **pip**:N 个平台专属 wheel 文件,通过 wheel **文件名中的 platform tag** 自动匹配
1112

0 commit comments

Comments
 (0)