mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 12:51:57 +00:00
refactor: change @oxidation-compiler/napi to oxc-parser (#1209)
This commit is contained in:
parent
8c624abf9c
commit
90ff0ddbe0
20 changed files with 102 additions and 381 deletions
|
|
@ -1,13 +1,11 @@
|
||||||
name: Release NAPI
|
name: Release NAPI Parser
|
||||||
|
|
||||||
# When main is pushed and npm/napi/package.json has been changed,
|
|
||||||
# trigger the jobs after the ci workflow has been passed.
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths:
|
paths:
|
||||||
- npm/napi/package.json # Please only commit this file, so we don't need to wait for test CI to pass.
|
- npm/oxc-parser/package.json # Please only commit this file, so we don't need to wait for test CI to pass.
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
|
@ -28,8 +26,8 @@ jobs:
|
||||||
id: version
|
id: version
|
||||||
with:
|
with:
|
||||||
static-checking: localIsNew
|
static-checking: localIsNew
|
||||||
file-url: https://unpkg.com/@oxidation-compiler/napi@latest/package.json
|
file-url: https://unpkg.com/oxc-parser@latest/package.json
|
||||||
file-name: npm/napi/package.json
|
file-name: npm/oxc-parser/package.json
|
||||||
|
|
||||||
- name: Set version name
|
- name: Set version name
|
||||||
if: steps.version.outputs.changed == 'true'
|
if: steps.version.outputs.changed == 'true'
|
||||||
|
|
@ -38,8 +36,6 @@ jobs:
|
||||||
echo "version=${{ steps.version.outputs.version }}" >> $GITHUB_ENV
|
echo "version=${{ steps.version.outputs.version }}" >> $GITHUB_ENV
|
||||||
|
|
||||||
build:
|
build:
|
||||||
needs: check
|
|
||||||
if: needs.check.outputs.version_changed == 'true'
|
|
||||||
env:
|
env:
|
||||||
version: ${{ needs.check.outputs.version }}
|
version: ${{ needs.check.outputs.version }}
|
||||||
outputs:
|
outputs:
|
||||||
|
|
@ -84,18 +80,18 @@ jobs:
|
||||||
run: rustup target add ${{ matrix.target }}
|
run: rustup target add ${{ matrix.target }}
|
||||||
|
|
||||||
- name: Build with cross
|
- name: Build with cross
|
||||||
run: cross build -p oxc_napi --release --target=${{ matrix.target }}
|
run: cross build -p oxc_napi_parser --release --target=${{ matrix.target }}
|
||||||
|
|
||||||
- name: Move file on ${{ matrix.os }}
|
- name: Move file on ${{ matrix.os }}
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
shopt -s extglob
|
shopt -s extglob
|
||||||
ls target/${{ matrix.target }}/release/*.@(so|dll|dylib)
|
ls target/${{ matrix.target }}/release/*.@(so|dll|dylib)
|
||||||
mv target/${{ matrix.target }}/release/*.@(so|dll|dylib) crates/oxc_napi/napi.${{ matrix.code-target }}.node
|
mv target/${{ matrix.target }}/release/*.@(so|dll|dylib) napi/parser/parser.${{ matrix.code-target }}.node
|
||||||
ls crates/oxc_napi
|
ls napi/parser
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
working-directory: crates/oxc_napi
|
working-directory: napi/parser
|
||||||
if: ${{ contains(matrix.target, 'x86') }} # Need docker for aarch64
|
if: ${{ contains(matrix.target, 'x86') }} # Need docker for aarch64
|
||||||
run: |
|
run: |
|
||||||
ls
|
ls
|
||||||
|
|
@ -105,13 +101,13 @@ jobs:
|
||||||
- name: Archive Binary
|
- name: Archive Binary
|
||||||
if: runner.os == 'Windows'
|
if: runner.os == 'Windows'
|
||||||
shell: bash
|
shell: bash
|
||||||
run: 7z a ${{ matrix.code-target }}.zip crates/oxc_napi/napi.${{ matrix.code-target }}.node
|
run: 7z a ${{ matrix.code-target }}.zip napi/parser/parser.${{ matrix.code-target }}.node
|
||||||
|
|
||||||
# The binary is zipped to fix permission loss https://github.com/actions/upload-artifact#permission-loss
|
# The binary is zipped to fix permission loss https://github.com/actions/upload-artifact#permission-loss
|
||||||
- name: Archive Binary
|
- name: Archive Binary
|
||||||
if: runner.os != 'Windows'
|
if: runner.os != 'Windows'
|
||||||
shell: bash
|
shell: bash
|
||||||
run: tar czf ${{ matrix.code-target }}.tar.gz crates/oxc_napi/napi.${{ matrix.code-target }}.node
|
run: tar czf ${{ matrix.code-target }}.tar.gz napi/parser/parser.${{ matrix.code-target }}.node
|
||||||
|
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
|
|
@ -157,10 +153,10 @@ jobs:
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
ls
|
ls
|
||||||
ls crates/oxc_napi
|
ls napi/parser
|
||||||
node npm/napi/scripts/generate-packages.mjs
|
node npm/oxc-parser/scripts/generate-packages.mjs
|
||||||
cat npm/napi/package.json
|
cat npm/oxc-parser/package.json
|
||||||
for package in npm/napi*
|
for package in npm/oxc-parser*
|
||||||
do
|
do
|
||||||
ls $package
|
ls $package
|
||||||
cat $package/package.json
|
cat $package/package.json
|
||||||
|
|
@ -170,11 +166,13 @@ jobs:
|
||||||
- name: Publish npm packages as latest
|
- name: Publish npm packages as latest
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
# NOTE: The trailing slash on $package/ changes it to publishing the directory
|
|
||||||
shell: bash
|
shell: bash
|
||||||
|
# NOTE: The trailing slash on $package/ changes it to publishing the directory
|
||||||
run: |
|
run: |
|
||||||
for package in npm/napi*
|
# publish subpackages first
|
||||||
|
for package in npm/oxc-parser-*
|
||||||
do
|
do
|
||||||
npm publish $package/ --tag latest --provenance --access public
|
npm publish $package/ --tag latest --provenance --access public
|
||||||
echo '----'
|
|
||||||
done
|
done
|
||||||
|
# publish root package last
|
||||||
|
npm publish npm/oxc-parser/ --tag latest --provenance --access public
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -3,7 +3,6 @@ target/
|
||||||
|
|
||||||
/node_modules/
|
/node_modules/
|
||||||
/website/node_modules/
|
/website/node_modules/
|
||||||
/crates/oxc_napi/node_modules/
|
|
||||||
/benchmark/node_modules/
|
/benchmark/node_modules/
|
||||||
/editors/vscode/node_modules/
|
/editors/vscode/node_modules/
|
||||||
/editors/vscode/icon.png
|
/editors/vscode/icon.png
|
||||||
|
|
@ -13,9 +12,6 @@ target/
|
||||||
|
|
||||||
npm/cli-*
|
npm/cli-*
|
||||||
|
|
||||||
# From napi build
|
|
||||||
crates/oxc_napi/*.node
|
|
||||||
|
|
||||||
# Ignore accidental files from the root
|
# Ignore accidental files from the root
|
||||||
/*.js
|
/*.js
|
||||||
/*.jsx
|
/*.jsx
|
||||||
|
|
|
||||||
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -1725,7 +1725,7 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oxc_napi"
|
name = "oxc_napi_parser"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"miette",
|
"miette",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = ["crates/*", "tasks/*", "editors/vscode/server"]
|
members = ["crates/*", "tasks/*", "editors/vscode/server", "napi/*"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
authors = ["Boshen <boshenc@gmail.com>", "Oxc contributors"]
|
authors = ["Boshen <boshenc@gmail.com>", "Oxc contributors"]
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ where warm runs complete in 5 minutes.
|
||||||
|
|
||||||
### Node.js
|
### Node.js
|
||||||
|
|
||||||
* You may use the parser via napi: [@oxidation-compiler/napi][npm-napi]
|
* You may use the parser via napi: [oxc-parser][npm-napi]
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
@ -321,7 +321,7 @@ Oxc partially copies code from the following projects, their licenses are listed
|
||||||
[ezno]: https://github.com/kaleidawave/ezno
|
[ezno]: https://github.com/kaleidawave/ezno
|
||||||
[google-closure-compiler]: https://github.com/google/closure-compiler
|
[google-closure-compiler]: https://github.com/google/closure-compiler
|
||||||
[minification-benchmarks]: https://github.com/privatenumber/minification-benchmarks
|
[minification-benchmarks]: https://github.com/privatenumber/minification-benchmarks
|
||||||
[npm-napi]: https://www.npmjs.com/package/@oxidation-compiler/napi
|
[npm-napi]: https://www.npmjs.com/package/oxc-parser
|
||||||
[npm-oxlint]: https://www.npmjs.com/package/oxlint
|
[npm-oxlint]: https://www.npmjs.com/package/oxlint
|
||||||
[parser-benchmark]: https://github.com/Boshen/bench-javascript-parser-written-in-rust
|
[parser-benchmark]: https://github.com/Boshen/bench-javascript-parser-written-in-rust
|
||||||
[prettier]: https://github.com/prettier/prettier
|
[prettier]: https://github.com/prettier/prettier
|
||||||
|
|
|
||||||
2
napi/parser/.gitignore
vendored
Normal file
2
napi/parser/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
/node_modules/
|
||||||
|
*.node
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "oxc_napi"
|
name = "oxc_napi_parser"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
publish = false
|
publish = false
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|
@ -18,7 +18,7 @@ export interface ParseResult {
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Parse without returning anything.
|
* Parse without returning anything.
|
||||||
* For benchmark purposes such as measuring the napi communication overhead.
|
* This is for benchmark purposes such as measuring napi communication overhead.
|
||||||
*
|
*
|
||||||
* # Panics
|
* # Panics
|
||||||
*
|
*
|
||||||
|
|
@ -35,6 +35,7 @@ export function parseWithoutReturn(sourceText: string, options?: ParserOptions |
|
||||||
export function parseSync(sourceText: string, options?: ParserOptions | undefined | null): ParseResult
|
export function parseSync(sourceText: string, options?: ParserOptions | undefined | null): ParseResult
|
||||||
/**
|
/**
|
||||||
* # Panics
|
* # Panics
|
||||||
|
*
|
||||||
* * Tokio crashes
|
* * Tokio crashes
|
||||||
*/
|
*/
|
||||||
export function parseAsync(sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>
|
export function parseAsync(sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>
|
||||||
|
|
@ -32,24 +32,24 @@ switch (platform) {
|
||||||
case 'android':
|
case 'android':
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
localFileExisted = existsSync(join(__dirname, 'napi.android-arm64.node'))
|
localFileExisted = existsSync(join(__dirname, 'parser.android-arm64.node'))
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.android-arm64.node')
|
nativeBinding = require('./parser.android-arm64.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-android-arm64')
|
nativeBinding = require('@oxc-parser/binding-android-arm64')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'arm':
|
case 'arm':
|
||||||
localFileExisted = existsSync(join(__dirname, 'napi.android-arm-eabi.node'))
|
localFileExisted = existsSync(join(__dirname, 'parser.android-arm-eabi.node'))
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.android-arm-eabi.node')
|
nativeBinding = require('./parser.android-arm-eabi.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-android-arm-eabi')
|
nativeBinding = require('@oxc-parser/binding-android-arm-eabi')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
|
|
@ -63,13 +63,13 @@ switch (platform) {
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case 'x64':
|
case 'x64':
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'napi.win32-x64-msvc.node')
|
join(__dirname, 'parser.win32-x64-msvc.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.win32-x64-msvc.node')
|
nativeBinding = require('./parser.win32-x64-msvc.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-win32-x64-msvc')
|
nativeBinding = require('@oxc-parser/binding-win32-x64-msvc')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
|
|
@ -77,13 +77,13 @@ switch (platform) {
|
||||||
break
|
break
|
||||||
case 'ia32':
|
case 'ia32':
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'napi.win32-ia32-msvc.node')
|
join(__dirname, 'parser.win32-ia32-msvc.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.win32-ia32-msvc.node')
|
nativeBinding = require('./parser.win32-ia32-msvc.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-win32-ia32-msvc')
|
nativeBinding = require('@oxc-parser/binding-win32-ia32-msvc')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
|
|
@ -91,13 +91,13 @@ switch (platform) {
|
||||||
break
|
break
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'napi.win32-arm64-msvc.node')
|
join(__dirname, 'parser.win32-arm64-msvc.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.win32-arm64-msvc.node')
|
nativeBinding = require('./parser.win32-arm64-msvc.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-win32-arm64-msvc')
|
nativeBinding = require('@oxc-parser/binding-win32-arm64-msvc')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
|
|
@ -108,23 +108,23 @@ switch (platform) {
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
localFileExisted = existsSync(join(__dirname, 'napi.darwin-universal.node'))
|
localFileExisted = existsSync(join(__dirname, 'parser.darwin-universal.node'))
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.darwin-universal.node')
|
nativeBinding = require('./parser.darwin-universal.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-darwin-universal')
|
nativeBinding = require('@oxc-parser/binding-darwin-universal')
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
} catch {}
|
} catch {}
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case 'x64':
|
case 'x64':
|
||||||
localFileExisted = existsSync(join(__dirname, 'napi.darwin-x64.node'))
|
localFileExisted = existsSync(join(__dirname, 'parser.darwin-x64.node'))
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.darwin-x64.node')
|
nativeBinding = require('./parser.darwin-x64.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-darwin-x64')
|
nativeBinding = require('@oxc-parser/binding-darwin-x64')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
|
|
@ -132,13 +132,13 @@ switch (platform) {
|
||||||
break
|
break
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'napi.darwin-arm64.node')
|
join(__dirname, 'parser.darwin-arm64.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.darwin-arm64.node')
|
nativeBinding = require('./parser.darwin-arm64.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-darwin-arm64')
|
nativeBinding = require('@oxc-parser/binding-darwin-arm64')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
|
|
@ -152,12 +152,12 @@ switch (platform) {
|
||||||
if (arch !== 'x64') {
|
if (arch !== 'x64') {
|
||||||
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
||||||
}
|
}
|
||||||
localFileExisted = existsSync(join(__dirname, 'napi.freebsd-x64.node'))
|
localFileExisted = existsSync(join(__dirname, 'parser.freebsd-x64.node'))
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.freebsd-x64.node')
|
nativeBinding = require('./parser.freebsd-x64.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-freebsd-x64')
|
nativeBinding = require('@oxc-parser/binding-freebsd-x64')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
|
|
@ -168,26 +168,26 @@ switch (platform) {
|
||||||
case 'x64':
|
case 'x64':
|
||||||
if (isMusl()) {
|
if (isMusl()) {
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'napi.linux-x64-musl.node')
|
join(__dirname, 'parser.linux-x64-musl.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.linux-x64-musl.node')
|
nativeBinding = require('./parser.linux-x64-musl.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-linux-x64-musl')
|
nativeBinding = require('@oxc-parser/binding-linux-x64-musl')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'napi.linux-x64-gnu.node')
|
join(__dirname, 'parser.linux-x64-gnu.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.linux-x64-gnu.node')
|
nativeBinding = require('./parser.linux-x64-gnu.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-linux-x64-gnu')
|
nativeBinding = require('@oxc-parser/binding-linux-x64-gnu')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
|
|
@ -197,26 +197,26 @@ switch (platform) {
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
if (isMusl()) {
|
if (isMusl()) {
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'napi.linux-arm64-musl.node')
|
join(__dirname, 'parser.linux-arm64-musl.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.linux-arm64-musl.node')
|
nativeBinding = require('./parser.linux-arm64-musl.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-linux-arm64-musl')
|
nativeBinding = require('@oxc-parser/binding-linux-arm64-musl')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'napi.linux-arm64-gnu.node')
|
join(__dirname, 'parser.linux-arm64-gnu.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.linux-arm64-gnu.node')
|
nativeBinding = require('./parser.linux-arm64-gnu.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-linux-arm64-gnu')
|
nativeBinding = require('@oxc-parser/binding-linux-arm64-gnu')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
|
|
@ -225,13 +225,13 @@ switch (platform) {
|
||||||
break
|
break
|
||||||
case 'arm':
|
case 'arm':
|
||||||
localFileExisted = existsSync(
|
localFileExisted = existsSync(
|
||||||
join(__dirname, 'napi.linux-arm-gnueabihf.node')
|
join(__dirname, 'parser.linux-arm-gnueabihf.node')
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (localFileExisted) {
|
if (localFileExisted) {
|
||||||
nativeBinding = require('./napi.linux-arm-gnueabihf.node')
|
nativeBinding = require('./parser.linux-arm-gnueabihf.node')
|
||||||
} else {
|
} else {
|
||||||
nativeBinding = require('@oxidation-compiler/napi-linux-arm-gnueabihf')
|
nativeBinding = require('@oxc-parser/binding-linux-arm-gnueabihf')
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadError = e
|
loadError = e
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@oxidation-compiler/napi",
|
"name": "@oxc-parser/binding",
|
||||||
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "napi build --platform --release"
|
"build": "napi build --platform --release"
|
||||||
},
|
},
|
||||||
|
|
@ -11,7 +12,7 @@
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@8.2.0",
|
"packageManager": "pnpm@8.2.0",
|
||||||
"napi": {
|
"napi": {
|
||||||
"name": "napi",
|
"name": "parser",
|
||||||
"triples": {
|
"triples": {
|
||||||
"defaults": false,
|
"defaults": false,
|
||||||
"additional": [
|
"additional": [
|
||||||
29
npm/napi/index.d.ts
vendored
29
npm/napi/index.d.ts
vendored
|
|
@ -1,29 +0,0 @@
|
||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
|
|
||||||
/* auto-generated by NAPI-RS */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Babel Parser Options
|
|
||||||
*
|
|
||||||
* <https://github.com/babel/babel/blob/main/packages/babel-parser/typings/babel-parser.d.ts>
|
|
||||||
*/
|
|
||||||
export interface ParserOptions {
|
|
||||||
sourceType?: string
|
|
||||||
sourceFilename?: string
|
|
||||||
}
|
|
||||||
export interface ParseResult {
|
|
||||||
program: any
|
|
||||||
errors: Array<string>
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* # Panics
|
|
||||||
* * File extension is invalid
|
|
||||||
* * Serde JSON serialization
|
|
||||||
*/
|
|
||||||
export function parseSync(sourceText: string, options?: ParserOptions | undefined | null): ParseResult
|
|
||||||
/**
|
|
||||||
* # Panics
|
|
||||||
* * Tokio crashes
|
|
||||||
*/
|
|
||||||
export function parseAsync(sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>
|
|
||||||
|
|
@ -1,258 +0,0 @@
|
||||||
/* 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, 'napi.android-arm64.node'))
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.android-arm64.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-android-arm64')
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
loadError = e
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'arm':
|
|
||||||
localFileExisted = existsSync(join(__dirname, 'napi.android-arm-eabi.node'))
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.android-arm-eabi.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-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, 'napi.win32-x64-msvc.node')
|
|
||||||
)
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.win32-x64-msvc.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-win32-x64-msvc')
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
loadError = e
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'ia32':
|
|
||||||
localFileExisted = existsSync(
|
|
||||||
join(__dirname, 'napi.win32-ia32-msvc.node')
|
|
||||||
)
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.win32-ia32-msvc.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-win32-ia32-msvc')
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
loadError = e
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'arm64':
|
|
||||||
localFileExisted = existsSync(
|
|
||||||
join(__dirname, 'napi.win32-arm64-msvc.node')
|
|
||||||
)
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.win32-arm64-msvc.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-win32-arm64-msvc')
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
loadError = e
|
|
||||||
}
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
throw new Error(`Unsupported architecture on Windows: ${arch}`)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'darwin':
|
|
||||||
localFileExisted = existsSync(join(__dirname, 'napi.darwin-universal.node'))
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.darwin-universal.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-darwin-universal')
|
|
||||||
}
|
|
||||||
break
|
|
||||||
} catch {}
|
|
||||||
switch (arch) {
|
|
||||||
case 'x64':
|
|
||||||
localFileExisted = existsSync(join(__dirname, 'napi.darwin-x64.node'))
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.darwin-x64.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-darwin-x64')
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
loadError = e
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'arm64':
|
|
||||||
localFileExisted = existsSync(
|
|
||||||
join(__dirname, 'napi.darwin-arm64.node')
|
|
||||||
)
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.darwin-arm64.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-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, 'napi.freebsd-x64.node'))
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.freebsd-x64.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-freebsd-x64')
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
loadError = e
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'linux':
|
|
||||||
switch (arch) {
|
|
||||||
case 'x64':
|
|
||||||
if (isMusl()) {
|
|
||||||
localFileExisted = existsSync(
|
|
||||||
join(__dirname, 'napi.linux-x64-musl.node')
|
|
||||||
)
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.linux-x64-musl.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-linux-x64-musl')
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
loadError = e
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
localFileExisted = existsSync(
|
|
||||||
join(__dirname, 'napi.linux-x64-gnu.node')
|
|
||||||
)
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.linux-x64-gnu.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-linux-x64-gnu')
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
loadError = e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'arm64':
|
|
||||||
if (isMusl()) {
|
|
||||||
localFileExisted = existsSync(
|
|
||||||
join(__dirname, 'napi.linux-arm64-musl.node')
|
|
||||||
)
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.linux-arm64-musl.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-linux-arm64-musl')
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
loadError = e
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
localFileExisted = existsSync(
|
|
||||||
join(__dirname, 'napi.linux-arm64-gnu.node')
|
|
||||||
)
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.linux-arm64-gnu.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-linux-arm64-gnu')
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
loadError = e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'arm':
|
|
||||||
localFileExisted = existsSync(
|
|
||||||
join(__dirname, 'napi.linux-arm-gnueabihf.node')
|
|
||||||
)
|
|
||||||
try {
|
|
||||||
if (localFileExisted) {
|
|
||||||
nativeBinding = require('./napi.linux-arm-gnueabihf.node')
|
|
||||||
} else {
|
|
||||||
nativeBinding = require('@oxidation-compiler/napi-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 { parseSync, parseAsync } = nativeBinding
|
|
||||||
|
|
||||||
module.exports.parseSync = parseSync
|
|
||||||
module.exports.parseAsync = parseAsync
|
|
||||||
|
|
@ -7,7 +7,7 @@ TypeScript typings for the AST is currently work in progress.
|
||||||
## cjs
|
## cjs
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const oxc = require("@oxidation-compiler/napi");
|
const oxc = require("oxc-parser");
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
function test(ret) {
|
function test(ret) {
|
||||||
|
|
@ -27,7 +27,7 @@ main()
|
||||||
## ESM
|
## ESM
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import oxc from '@oxidation-compiler/napi';
|
import oxc from 'oxc-parser';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
|
|
||||||
function test(ret) {
|
function test(ret) {
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
{
|
{
|
||||||
"name": "@oxidation-compiler/napi",
|
"name": "oxc-parser",
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"description": "The JavaScript Oxidation Compiler Node API",
|
"description": "Oxc Parser Node API",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "Boshen and oxc contributors",
|
|
||||||
"files": [
|
"files": [
|
||||||
"index.d.ts",
|
"index.d.ts",
|
||||||
"index.js"
|
"index.js"
|
||||||
|
|
@ -11,8 +10,8 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/web-infra-dev/oxc",
|
"url": "https://github.com/web-infra-dev/oxc.git",
|
||||||
"directory": "npm/napi"
|
"directory": "npm/oxc-parser"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/Boshen"
|
"url": "https://github.com/sponsors/Boshen"
|
||||||
|
|
@ -5,20 +5,27 @@ import { fileURLToPath } from "node:url";
|
||||||
import * as fs from "node:fs";
|
import * as fs from "node:fs";
|
||||||
|
|
||||||
const OXC_ROOT = resolve(fileURLToPath(import.meta.url), "../..");
|
const OXC_ROOT = resolve(fileURLToPath(import.meta.url), "../..");
|
||||||
console.log(OXC_ROOT);
|
|
||||||
const PACKAGES_ROOT = resolve(OXC_ROOT, "..");
|
const PACKAGES_ROOT = resolve(OXC_ROOT, "..");
|
||||||
const BINARY_ROOT = resolve(OXC_ROOT, "../../crates/oxc_napi");
|
const BINARY_ROOT = resolve(OXC_ROOT, "../../napi/parser");
|
||||||
const MANIFEST_PATH = resolve(OXC_ROOT, "package.json");
|
const MANIFEST_PATH = resolve(OXC_ROOT, "package.json");
|
||||||
|
|
||||||
|
console.log('OXC_ROOT', OXC_ROOT);
|
||||||
|
console.log('PACKAGES_ROOT', PACKAGES_ROOT);
|
||||||
|
console.log('BINARY_ROOT', BINARY_ROOT);
|
||||||
|
console.log('MANIFEST_PATH', MANIFEST_PATH);
|
||||||
|
|
||||||
const rootManifest = JSON.parse(
|
const rootManifest = JSON.parse(
|
||||||
fs.readFileSync(MANIFEST_PATH).toString("utf-8")
|
fs.readFileSync(MANIFEST_PATH).toString("utf-8")
|
||||||
);
|
);
|
||||||
|
|
||||||
function generateNativePackage(target) {
|
function package_name(target) {
|
||||||
const packageName = `@oxidation-compiler/napi-${target}`;
|
return `@oxc-parser/binding-${target}`
|
||||||
const binaryName = `napi.${target}.node`;
|
}
|
||||||
|
|
||||||
const packageRoot = resolve(PACKAGES_ROOT, `napi-${target}`);
|
function generateNativePackage(target) {
|
||||||
|
const binaryName = `parser.${target}.node`;
|
||||||
|
|
||||||
|
const packageRoot = resolve(PACKAGES_ROOT, `oxc-parser-${target}`);
|
||||||
const binarySource = resolve(BINARY_ROOT, binaryName);
|
const binarySource = resolve(BINARY_ROOT, binaryName);
|
||||||
const binaryTarget = resolve(packageRoot, binaryName);
|
const binaryTarget = resolve(packageRoot, binaryName);
|
||||||
|
|
||||||
|
|
@ -35,7 +42,7 @@ function generateNativePackage(target) {
|
||||||
|
|
||||||
const [os, cpu, third] = target.split("-");
|
const [os, cpu, third] = target.split("-");
|
||||||
const manifest = {
|
const manifest = {
|
||||||
name: packageName,
|
name: package_name(target),
|
||||||
version,
|
version,
|
||||||
main: binaryName,
|
main: binaryName,
|
||||||
files: [binaryName],
|
files: [binaryName],
|
||||||
|
|
@ -57,23 +64,27 @@ function generateNativePackage(target) {
|
||||||
fs.copyFileSync(binarySource, binaryTarget);
|
fs.copyFileSync(binarySource, binaryTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeManifest(packagePath) {
|
function writeManifest() {
|
||||||
const packageRoot = resolve(PACKAGES_ROOT, packagePath);
|
const packageRoot = resolve(PACKAGES_ROOT, 'oxc-parser');
|
||||||
const manifestPath = resolve(packageRoot, "package.json");
|
const manifestPath = resolve(packageRoot, "package.json");
|
||||||
|
|
||||||
|
console.log('packageRoot', packageRoot);
|
||||||
|
|
||||||
const manifestData = JSON.parse(
|
const manifestData = JSON.parse(
|
||||||
fs.readFileSync(manifestPath).toString("utf-8")
|
fs.readFileSync(manifestPath).toString("utf-8")
|
||||||
);
|
);
|
||||||
|
|
||||||
const nativePackages = TARGETS.map((target) => [
|
const nativePackages = TARGETS.map((target) => [
|
||||||
`@oxidation-compiler/napi-${target}`,
|
package_name(target),
|
||||||
rootManifest.version,
|
rootManifest.version,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
manifestData["version"] = rootManifest.version;
|
manifestData["version"] = rootManifest.version;
|
||||||
manifestData["optionalDependencies"] = Object.fromEntries(nativePackages);
|
manifestData["optionalDependencies"] = Object.fromEntries(nativePackages);
|
||||||
|
|
||||||
console.log(`Update manifest ${manifestPath}`);
|
console.log('manifestPath', manifestPath);
|
||||||
|
console.log('manifestData', manifestData);
|
||||||
|
|
||||||
const content = JSON.stringify(manifestData);
|
const content = JSON.stringify(manifestData);
|
||||||
fs.writeFileSync(manifestPath, content);
|
fs.writeFileSync(manifestPath, content);
|
||||||
|
|
||||||
|
|
@ -96,4 +107,4 @@ for (const target of TARGETS) {
|
||||||
generateNativePackage(target);
|
generateNativePackage(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
writeManifest("napi");
|
writeManifest();
|
||||||
Loading…
Reference in a new issue