Skip to content

Commit f52293b

Browse files
committed
chore: added namespaces during build
1 parent 5b25b43 commit f52293b

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ npm-debug.log*
1010
yarn-debug.log*
1111
yarn-error.log*
1212
lerna-debug.log*
13+
.vscode/
1314

1415
# Diagnostic reports (https://nodejs.org/api/report.html)
1516
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ function requireNative() {
373373
}
374374
try {
375375
const binding = require('@antoniomuso/lz4-napi-linux-riscv64-gnu')
376-
const bindingPackageVersion = require('lz4-napi-linux-riscv64-gnu/package.json').version
376+
const bindingPackageVersion = require('@antoniomuso/lz4-napi-linux-riscv64-gnu/package.json').version
377377
if (bindingPackageVersion !== '2.9.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
378378
throw new Error(`Native binding package version mismatch, expected 2.9.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
379379
}

namespace.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { readFileSync, writeFileSync } from 'fs'
2+
import { join } from 'path'
3+
import { fileURLToPath } from 'url'
4+
5+
const file = await readFileSync(fileURLToPath(join(import.meta.url, '..', 'index.js')), 'utf-8');
6+
const newFile = file.replaceAll(/require\(('|")(?!\.)([.\/a-zA-Z-0-9]+)('|")\)/g, "require('@antoniomuso/$2')");
7+
writeFileSync(fileURLToPath(join(import.meta.url, '..', 'index.js')), newFile);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"scripts": {
5858
"artifacts": "napi artifacts --output-dir artifacts --npm-dir ./npm",
5959
"bench": "node --import @oxc-node/core/register benchmark/bench.ts",
60-
"build": "napi build --platform --release",
60+
"build": "napi build --platform --release && yarn addNamespaces:index",
6161
"build:debug": "napi build --platform",
6262
"format": "run-p format:source format:rs format:toml",
6363
"format:toml": "taplo format",
@@ -66,6 +66,7 @@
6666
"lint": "eslint -c ./.eslintrc.yml .",
6767
"prepublishOnly": "napi prepublish -t npm && esbuild --minify --outfile=index.js --allow-overwrite index.js && yarn addNamespaces",
6868
"addNamespaces": "cat package.json | jq '.optionalDependencies |= with_entries(.key |= \"@antoniomuso/\" + .)' > package.json",
69+
"addNamespaces:index": "node --import @oxc-node/core/register namespace.ts",
6970
"test": "ava",
7071
"test:mem": "node ./memory-leak-detect.mjs",
7172
"version": "napi version && conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"

0 commit comments

Comments
 (0)