-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
430 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules/ | ||
*.node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "oxc_napi_resolver" | ||
version = "0.0.0" | ||
publish = false | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
test = false | ||
doctest = false | ||
|
||
[dependencies] | ||
oxc_resolver = { workspace = true } | ||
napi = { version = "2", features = ["serde-json", "async"] } | ||
napi-derive = { version = "2" } | ||
|
||
[build-dependencies] | ||
napi-build = "2" | ||
|
||
[package.metadata.cargo-machete] | ||
ignored = ["napi"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Installation | ||
|
||
```bash | ||
corepack enable | ||
``` | ||
|
||
# Build | ||
|
||
```bash | ||
pnpm install | ||
pnpm run build | ||
``` | ||
|
||
# Test | ||
|
||
```bash | ||
pnpm test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
napi_build::setup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
|
||
/* auto-generated by NAPI-RS */ | ||
|
||
export interface ResolveResult { | ||
path?: string | ||
error?: string | ||
} | ||
export function sync(path: string, request: string): ResolveResult | ||
export class ResolverFactory { | ||
constructor() | ||
sync(path: string, request: string): ResolveResult | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, 'resolver.android-arm64.node')) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.android-arm64.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-android-arm64') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
case 'arm': | ||
localFileExisted = existsSync(join(__dirname, 'resolver.android-arm-eabi.node')) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.android-arm-eabi.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-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, 'resolver.win32-x64-msvc.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.win32-x64-msvc.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-win32-x64-msvc') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
case 'ia32': | ||
localFileExisted = existsSync( | ||
join(__dirname, 'resolver.win32-ia32-msvc.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.win32-ia32-msvc.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-win32-ia32-msvc') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
case 'arm64': | ||
localFileExisted = existsSync( | ||
join(__dirname, 'resolver.win32-arm64-msvc.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.win32-arm64-msvc.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-win32-arm64-msvc') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
default: | ||
throw new Error(`Unsupported architecture on Windows: ${arch}`) | ||
} | ||
break | ||
case 'darwin': | ||
localFileExisted = existsSync(join(__dirname, 'resolver.darwin-universal.node')) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.darwin-universal.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-darwin-universal') | ||
} | ||
break | ||
} catch {} | ||
switch (arch) { | ||
case 'x64': | ||
localFileExisted = existsSync(join(__dirname, 'resolver.darwin-x64.node')) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.darwin-x64.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-darwin-x64') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
case 'arm64': | ||
localFileExisted = existsSync( | ||
join(__dirname, 'resolver.darwin-arm64.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.darwin-arm64.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-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, 'resolver.freebsd-x64.node')) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.freebsd-x64.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-freebsd-x64') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
break | ||
case 'linux': | ||
switch (arch) { | ||
case 'x64': | ||
if (isMusl()) { | ||
localFileExisted = existsSync( | ||
join(__dirname, 'resolver.linux-x64-musl.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.linux-x64-musl.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-linux-x64-musl') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
} else { | ||
localFileExisted = existsSync( | ||
join(__dirname, 'resolver.linux-x64-gnu.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.linux-x64-gnu.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-linux-x64-gnu') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
} | ||
break | ||
case 'arm64': | ||
if (isMusl()) { | ||
localFileExisted = existsSync( | ||
join(__dirname, 'resolver.linux-arm64-musl.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.linux-arm64-musl.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-linux-arm64-musl') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
} else { | ||
localFileExisted = existsSync( | ||
join(__dirname, 'resolver.linux-arm64-gnu.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.linux-arm64-gnu.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-linux-arm64-gnu') | ||
} | ||
} catch (e) { | ||
loadError = e | ||
} | ||
} | ||
break | ||
case 'arm': | ||
localFileExisted = existsSync( | ||
join(__dirname, 'resolver.linux-arm-gnueabihf.node') | ||
) | ||
try { | ||
if (localFileExisted) { | ||
nativeBinding = require('./resolver.linux-arm-gnueabihf.node') | ||
} else { | ||
nativeBinding = require('@oxc-resolver/binding-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 { ResolverFactory, sync } = nativeBinding | ||
|
||
module.exports.ResolverFactory = ResolverFactory | ||
module.exports.sync = sync |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@oxc-resolver/binding", | ||
"private": true, | ||
"scripts": { | ||
"build": "napi build --platform --release", | ||
"test": "node test.mjs" | ||
}, | ||
"devDependencies": { | ||
"@napi-rs/cli": "^2.15.2" | ||
}, | ||
"engines": { | ||
"node": ">=14.*" | ||
}, | ||
"packageManager": "pnpm@8.2.0", | ||
"napi": { | ||
"name": "resolver", | ||
"triples": { | ||
"defaults": false, | ||
"additional": [ | ||
"x86_64-pc-windows-msvc", | ||
"aarch64-pc-windows-msvc", | ||
"x86_64-unknown-linux-gnu", | ||
"aarch64-unknown-linux-gnu", | ||
"x86_64-apple-darwin", | ||
"aarch64-apple-darwin" | ||
] | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.