Skip to content

Commit

Permalink
chore: ci publish
Browse files Browse the repository at this point in the history
  • Loading branch information
callqh committed Apr 9, 2024
1 parent 808a1bb commit d560ed4
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/three-dogs-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farmfe/magic-string": patch
---

fix: ci publish
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* tslint:disable */
/* eslint-disable */

/* auto-generated by NAPI-RS */

export function sum(a: number, b: number): number
257 changes: 257 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
/* tslint:disable */
/* eslint-disable */
/* prettier-ignore */

/* auto-generated by NAPI-RS */

const { existsSync, readFileSync } = require('fs')
const { join } = require('path')

const { platform, arch } = process

let nativeBinding = null
let localFileExisted = false
let loadError = null

function isMusl() {
// For Node 10
if (!process.report || typeof process.report.getReport !== 'function') {
try {
const lddPath = require('child_process').execSync('which ldd').toString().trim()
return readFileSync(lddPath, 'utf8').includes('musl')
} catch (e) {
return true
}
} else {
const { glibcVersionRuntime } = process.report.getReport().header
return !glibcVersionRuntime
}
}

switch (platform) {
case 'android':
switch (arch) {
case 'arm64':
localFileExisted = existsSync(join(__dirname, 'magic-string.android-arm64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.android-arm64.node')
} else {
nativeBinding = require('@farmfe/magic-string-android-arm64')
}
} catch (e) {
loadError = e
}
break
case 'arm':
localFileExisted = existsSync(join(__dirname, 'magic-string.android-arm-eabi.node'))
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.android-arm-eabi.node')
} else {
nativeBinding = require('@farmfe/magic-string-android-arm-eabi')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Android ${arch}`)
}
break
case 'win32':
switch (arch) {
case 'x64':
localFileExisted = existsSync(
join(__dirname, 'magic-string.win32-x64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.win32-x64-msvc.node')
} else {
nativeBinding = require('@farmfe/magic-string-win32-x64-msvc')
}
} catch (e) {
loadError = e
}
break
case 'ia32':
localFileExisted = existsSync(
join(__dirname, 'magic-string.win32-ia32-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.win32-ia32-msvc.node')
} else {
nativeBinding = require('@farmfe/magic-string-win32-ia32-msvc')
}
} catch (e) {
loadError = e
}
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'magic-string.win32-arm64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.win32-arm64-msvc.node')
} else {
nativeBinding = require('@farmfe/magic-string-win32-arm64-msvc')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Windows: ${arch}`)
}
break
case 'darwin':
localFileExisted = existsSync(join(__dirname, 'magic-string.darwin-universal.node'))
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.darwin-universal.node')
} else {
nativeBinding = require('@farmfe/magic-string-darwin-universal')
}
break
} catch {}
switch (arch) {
case 'x64':
localFileExisted = existsSync(join(__dirname, 'magic-string.darwin-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.darwin-x64.node')
} else {
nativeBinding = require('@farmfe/magic-string-darwin-x64')
}
} catch (e) {
loadError = e
}
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'magic-string.darwin-arm64.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.darwin-arm64.node')
} else {
nativeBinding = require('@farmfe/magic-string-darwin-arm64')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on macOS: ${arch}`)
}
break
case 'freebsd':
if (arch !== 'x64') {
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
}
localFileExisted = existsSync(join(__dirname, 'magic-string.freebsd-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.freebsd-x64.node')
} else {
nativeBinding = require('@farmfe/magic-string-freebsd-x64')
}
} catch (e) {
loadError = e
}
break
case 'linux':
switch (arch) {
case 'x64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'magic-string.linux-x64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.linux-x64-musl.node')
} else {
nativeBinding = require('@farmfe/magic-string-linux-x64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'magic-string.linux-x64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.linux-x64-gnu.node')
} else {
nativeBinding = require('@farmfe/magic-string-linux-x64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 'arm64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'magic-string.linux-arm64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.linux-arm64-musl.node')
} else {
nativeBinding = require('@farmfe/magic-string-linux-arm64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'magic-string.linux-arm64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.linux-arm64-gnu.node')
} else {
nativeBinding = require('@farmfe/magic-string-linux-arm64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 'arm':
localFileExisted = existsSync(
join(__dirname, 'magic-string.linux-arm-gnueabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./magic-string.linux-arm-gnueabihf.node')
} else {
nativeBinding = require('@farmfe/magic-string-linux-arm-gnueabihf')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`)
}
break
default:
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
}

if (!nativeBinding) {
if (loadError) {
throw loadError
}
throw new Error(`Failed to load native binding`)
}

const { sum } = nativeBinding

module.exports.sum = sum
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,28 @@
"build:debug": "napi build --platform",
"prepublishOnly": "napi prepublish -t npm",
"test": "ava",
"bump": "node ./scripts/bump.mjs",
"release": "node ./scripts/release.mjs",
"universal": "napi universal",
"version": "napi version"
},
"dependencies": {
"@changesets/cli": "^2.27.1"
},
"optionalDependencies": {
"@farmfe/magic-string-win32-x64-msvc": "0.0.0",
"@farmfe/magic-string-darwin-x64": "0.0.0",
"@farmfe/magic-string-linux-x64-gnu": "0.0.0",
"@farmfe/magic-string-darwin-arm64": "0.0.0",
"@farmfe/magic-string-android-arm64": "0.0.0",
"@farmfe/magic-string-linux-arm64-gnu": "0.0.0",
"@farmfe/magic-string-linux-arm64-musl": "0.0.0",
"@farmfe/magic-string-win32-arm64-msvc": "0.0.0",
"@farmfe/magic-string-linux-arm-gnueabihf": "0.0.0",
"@farmfe/magic-string-linux-x64-musl": "0.0.0",
"@farmfe/magic-string-freebsd-x64": "0.0.0",
"@farmfe/magic-string-win32-ia32-msvc": "0.0.0",
"@farmfe/magic-string-android-arm-eabi": "0.0.0",
"@farmfe/magic-string-darwin-universal": "0.0.0"
}
}
3 changes: 2 additions & 1 deletion scripts/bump.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { execSync } from "child_process";

execSync('pnpm run build', { stdio: 'inherit' });
execSync('npx changeset version', { stdio: 'inherit' });
execSync('pnpm install --no-frozen-lockfile', { stdio: 'inherit' });
execSync('pnpm install --no-frozen-lockfile', { stdio: 'inherit' });

0 comments on commit d560ed4

Please sign in to comment.