Skip to content

Commit 7e18dcc

Browse files
carlhoerbergclaudebaelter
authored
chore: Make npm scripts cross-platform compatible (#179)
* chore: Make npm scripts cross-platform compatible Replace Unix-specific shell commands with Node.js scripts to ensure compatibility across Windows, macOS, and Linux: - Replace `rm -rf` with fs.rmSync() in prebuild script - Replace `echo` redirect with fs.writeFileSync() in postbuild script - Replace macOS-specific `sed` command with Node.js file operations in version script All scripts use Node.js built-in APIs (fs, path) with no additional dependencies. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fixup! chore: Make npm scripts cross-platform compatible * format --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Anders Bälter <anders@84codes.com>
1 parent 73d7b8f commit 7e18dcc

4 files changed

Lines changed: 25 additions & 3 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
"test-browser": "vitest --config ./vitest.config.browser.ts",
3939
"update-changelog": "node scripts/update-changelog.js",
4040
"create-tag": "node scripts/release-tag.js",
41-
"prebuild": "rm -rf dist lib types",
41+
"prebuild": "node scripts/clean.js",
4242
"build": "tsc && tsc --module commonjs --outDir lib/cjs && tsc --emitDeclarationOnly --removeComments false && rollup -c",
43-
"postbuild": "echo '{\"type\": \"commonjs\"}' > lib/cjs/package.json",
43+
"postbuild": "node scripts/write-cjs-package.js",
4444
"prepare": "npm run build",
4545
"preversion": "npm run test:local",
46-
"version": "sed -i '' \"s/VERSION = .*/VERSION = \\\"$npm_package_version\\\"/\" src/amqp-base-client.ts && npm run update-changelog && npm run format && git add -A",
46+
"version": "node scripts/update-version.js && npm run update-changelog && npm run format && git add -A",
4747
"postversion": "npm run create-tag && git push && git push --tags",
4848
"release": "npm version patch --no-git-tag-version",
4949
"release:minor": "npm version minor --no-git-tag-version",

scripts/clean.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { rmSync } from "fs"
2+
;["dist", "lib", "types"].forEach((dir) => {
3+
rmSync(dir, { recursive: true, force: true })
4+
})

scripts/update-version.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { readFileSync, writeFileSync } from "fs"
2+
3+
const version = process.env.npm_package_version
4+
if (!version) {
5+
console.error("Error: npm_package_version not found")
6+
process.exit(1)
7+
}
8+
9+
const file = "src/amqp-base-client.ts"
10+
const content = readFileSync(file, "utf8")
11+
const updated = content.replace(/VERSION = ".*"/, `VERSION = "${version}"`)
12+
writeFileSync(file, updated)

scripts/write-cjs-package.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { writeFileSync, mkdirSync } from "fs"
2+
import { dirname } from "path"
3+
4+
const path = "lib/cjs/package.json"
5+
mkdirSync(dirname(path), { recursive: true })
6+
writeFileSync(path, JSON.stringify({ type: "commonjs" }, null, 2) + "\n")

0 commit comments

Comments
 (0)