Skip to content

Commit

Permalink
Merge pull request #1 from carbonteq/add-dummy-methods-to-test-release
Browse files Browse the repository at this point in the history
Add dummy methods to test release
  • Loading branch information
volf52 committed Jun 10, 2023
2 parents 75a2da6 + 193e185 commit 033197a
Show file tree
Hide file tree
Showing 13 changed files with 762 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-gifts-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@carbonteq/jwt": patch
---

Add mul
68 changes: 34 additions & 34 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Test CI
env:
DEBUG: napi:*
APP_NAME: jwt
Expand Down Expand Up @@ -173,39 +173,39 @@ jobs:
shell: bash
- name: Test bindings
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test
universal-macOS:
name: Build universal macOS binary
needs:
- build
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
check-latest: true
cache: yarn
- name: Install dependencies
run: yarn install
- name: Download macOS x64 artifact
uses: actions/download-artifact@v3
with:
name: bindings-x86_64-apple-darwin
path: artifacts
- name: Download macOS arm64 artifact
uses: actions/download-artifact@v3
with:
name: bindings-aarch64-apple-darwin
path: artifacts
- name: Combine binaries
run: yarn universal
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: bindings-universal-apple-darwin
path: ${{ env.APP_NAME }}.*.node
if-no-files-found: error
# universal-macOS:
# name: Build universal macOS binary
# needs:
# - build
# runs-on: macos-latest
# steps:
# - uses: actions/checkout@v3
# - name: Setup node
# uses: actions/setup-node@v3
# with:
# node-version: 18
# check-latest: true
# cache: yarn
# - name: Install dependencies
# run: yarn install
# - name: Download macOS x64 artifact
# uses: actions/download-artifact@v3
# with:
# name: bindings-x86_64-apple-darwin
# path: artifacts
# - name: Download macOS arm64 artifact
# uses: actions/download-artifact@v3
# with:
# name: bindings-aarch64-apple-darwin
# path: artifacts
# - name: Combine binaries
# run: yarn universal
# - name: Upload artifact
# uses: actions/upload-artifact@v3
# with:
# name: bindings-universal-apple-darwin
# path: ${{ env.APP_NAME }}.*.node
# if-no-files-found: error
# publish:
# name: Publish
# runs-on: ubuntu-latest
Expand Down
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ yarn.lock
.yarn
__test__
renovate.json
bench
examples
bacon.toml
esbuild-runner.config.js
rome.json
rustfmt.toml
tsconfig.json
7 changes: 0 additions & 7 deletions __test__/index.spec.mjs

This file was deleted.

6 changes: 6 additions & 0 deletions __test__/mul.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import test from 'ava';
import { mul } from '../index';

test('mul native', (t) => {
t.is(mul(20, 23), 20 * 23);
});
6 changes: 6 additions & 0 deletions __test__/sum.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import test from 'ava';
import { sum } from '../index';

test('sum native ts', (t) => {
t.is(sum(1, 2), 3);
});
10 changes: 10 additions & 0 deletions esbuild-runner.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const config = {
type: 'transform',
esbuild: {
loader: {
'.node': 'file',
},
},
};

module.exports = config;
7 changes: 7 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* tslint:disable */
/* eslint-disable */

/* auto-generated by NAPI-RS */

export function sum(a: number, b: number): number
export function mul(a: number, b: number): number
258 changes: 258 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
/* 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, 'jwt.android-arm64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./jwt.android-arm64.node')
} else {
nativeBinding = require('@carbonteq/jwt-android-arm64')
}
} catch (e) {
loadError = e
}
break
case 'arm':
localFileExisted = existsSync(join(__dirname, 'jwt.android-arm-eabi.node'))
try {
if (localFileExisted) {
nativeBinding = require('./jwt.android-arm-eabi.node')
} else {
nativeBinding = require('@carbonteq/jwt-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, 'jwt.win32-x64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./jwt.win32-x64-msvc.node')
} else {
nativeBinding = require('@carbonteq/jwt-win32-x64-msvc')
}
} catch (e) {
loadError = e
}
break
case 'ia32':
localFileExisted = existsSync(
join(__dirname, 'jwt.win32-ia32-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./jwt.win32-ia32-msvc.node')
} else {
nativeBinding = require('@carbonteq/jwt-win32-ia32-msvc')
}
} catch (e) {
loadError = e
}
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'jwt.win32-arm64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./jwt.win32-arm64-msvc.node')
} else {
nativeBinding = require('@carbonteq/jwt-win32-arm64-msvc')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Windows: ${arch}`)
}
break
case 'darwin':
localFileExisted = existsSync(join(__dirname, 'jwt.darwin-universal.node'))
try {
if (localFileExisted) {
nativeBinding = require('./jwt.darwin-universal.node')
} else {
nativeBinding = require('@carbonteq/jwt-darwin-universal')
}
break
} catch {}
switch (arch) {
case 'x64':
localFileExisted = existsSync(join(__dirname, 'jwt.darwin-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./jwt.darwin-x64.node')
} else {
nativeBinding = require('@carbonteq/jwt-darwin-x64')
}
} catch (e) {
loadError = e
}
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'jwt.darwin-arm64.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./jwt.darwin-arm64.node')
} else {
nativeBinding = require('@carbonteq/jwt-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, 'jwt.freebsd-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./jwt.freebsd-x64.node')
} else {
nativeBinding = require('@carbonteq/jwt-freebsd-x64')
}
} catch (e) {
loadError = e
}
break
case 'linux':
switch (arch) {
case 'x64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'jwt.linux-x64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./jwt.linux-x64-musl.node')
} else {
nativeBinding = require('@carbonteq/jwt-linux-x64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'jwt.linux-x64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./jwt.linux-x64-gnu.node')
} else {
nativeBinding = require('@carbonteq/jwt-linux-x64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 'arm64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'jwt.linux-arm64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./jwt.linux-arm64-musl.node')
} else {
nativeBinding = require('@carbonteq/jwt-linux-arm64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'jwt.linux-arm64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./jwt.linux-arm64-gnu.node')
} else {
nativeBinding = require('@carbonteq/jwt-linux-arm64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 'arm':
localFileExisted = existsSync(
join(__dirname, 'jwt.linux-arm-gnueabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./jwt.linux-arm-gnueabihf.node')
} else {
nativeBinding = require('@carbonteq/jwt-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, mul } = nativeBinding

module.exports.sum = sum
module.exports.mul = mul
Loading

0 comments on commit 033197a

Please sign in to comment.