From d72062745a501e501219ae4a690b6f76aaa923e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Mon, 17 Jul 2023 12:34:58 +0900 Subject: [PATCH] fix: Include `binding.js` (#36) --- packages/css/.gitignore | 3 +- packages/css/binding.js | 260 +++++++++++++++++++++++++++++++++++ packages/css/package.json | 2 +- packages/html/.gitignore | 3 +- packages/html/binding.js | 260 +++++++++++++++++++++++++++++++++++ packages/html/package.json | 2 +- packages/linter/.gitignore | 3 +- packages/linter/binding.js | 258 ++++++++++++++++++++++++++++++++++ packages/linter/package.json | 2 +- 9 files changed, 787 insertions(+), 6 deletions(-) create mode 100644 packages/css/binding.js create mode 100644 packages/html/binding.js create mode 100644 packages/linter/binding.js diff --git a/packages/css/.gitignore b/packages/css/.gitignore index 343d521..e273a1f 100644 --- a/packages/css/.gitignore +++ b/packages/css/.gitignore @@ -1 +1,2 @@ -/*.js \ No newline at end of file +/*.js +!binding.js \ No newline at end of file diff --git a/packages/css/binding.js b/packages/css/binding.js new file mode 100644 index 0000000..41f3f1d --- /dev/null +++ b/packages/css/binding.js @@ -0,0 +1,260 @@ +/* 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, 'css.android-arm64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./css.android-arm64.node') + } else { + nativeBinding = require('@swc/css-android-arm64') + } + } catch (e) { + loadError = e + } + break + case 'arm': + localFileExisted = existsSync(join(__dirname, 'css.android-arm-eabi.node')) + try { + if (localFileExisted) { + nativeBinding = require('./css.android-arm-eabi.node') + } else { + nativeBinding = require('@swc/css-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, 'css.win32-x64-msvc.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./css.win32-x64-msvc.node') + } else { + nativeBinding = require('@swc/css-win32-x64-msvc') + } + } catch (e) { + loadError = e + } + break + case 'ia32': + localFileExisted = existsSync( + join(__dirname, 'css.win32-ia32-msvc.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./css.win32-ia32-msvc.node') + } else { + nativeBinding = require('@swc/css-win32-ia32-msvc') + } + } catch (e) { + loadError = e + } + break + case 'arm64': + localFileExisted = existsSync( + join(__dirname, 'css.win32-arm64-msvc.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./css.win32-arm64-msvc.node') + } else { + nativeBinding = require('@swc/css-win32-arm64-msvc') + } + } catch (e) { + loadError = e + } + break + default: + throw new Error(`Unsupported architecture on Windows: ${arch}`) + } + break + case 'darwin': + localFileExisted = existsSync(join(__dirname, 'css.darwin-universal.node')) + try { + if (localFileExisted) { + nativeBinding = require('./css.darwin-universal.node') + } else { + nativeBinding = require('@swc/css-darwin-universal') + } + break + } catch {} + switch (arch) { + case 'x64': + localFileExisted = existsSync(join(__dirname, 'css.darwin-x64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./css.darwin-x64.node') + } else { + nativeBinding = require('@swc/css-darwin-x64') + } + } catch (e) { + loadError = e + } + break + case 'arm64': + localFileExisted = existsSync( + join(__dirname, 'css.darwin-arm64.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./css.darwin-arm64.node') + } else { + nativeBinding = require('@swc/css-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, 'css.freebsd-x64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./css.freebsd-x64.node') + } else { + nativeBinding = require('@swc/css-freebsd-x64') + } + } catch (e) { + loadError = e + } + break + case 'linux': + switch (arch) { + case 'x64': + if (isMusl()) { + localFileExisted = existsSync( + join(__dirname, 'css.linux-x64-musl.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./css.linux-x64-musl.node') + } else { + nativeBinding = require('@swc/css-linux-x64-musl') + } + } catch (e) { + loadError = e + } + } else { + localFileExisted = existsSync( + join(__dirname, 'css.linux-x64-gnu.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./css.linux-x64-gnu.node') + } else { + nativeBinding = require('@swc/css-linux-x64-gnu') + } + } catch (e) { + loadError = e + } + } + break + case 'arm64': + if (isMusl()) { + localFileExisted = existsSync( + join(__dirname, 'css.linux-arm64-musl.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./css.linux-arm64-musl.node') + } else { + nativeBinding = require('@swc/css-linux-arm64-musl') + } + } catch (e) { + loadError = e + } + } else { + localFileExisted = existsSync( + join(__dirname, 'css.linux-arm64-gnu.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./css.linux-arm64-gnu.node') + } else { + nativeBinding = require('@swc/css-linux-arm64-gnu') + } + } catch (e) { + loadError = e + } + } + break + case 'arm': + localFileExisted = existsSync( + join(__dirname, 'css.linux-arm-gnueabihf.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./css.linux-arm-gnueabihf.node') + } else { + nativeBinding = require('@swc/css-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 { minify, minifySync, transform, transformSync } = nativeBinding + +module.exports.minify = minify +module.exports.minifySync = minifySync +module.exports.transform = transform +module.exports.transformSync = transformSync diff --git a/packages/css/package.json b/packages/css/package.json index bcee56a..3311ec3 100644 --- a/packages/css/package.json +++ b/packages/css/package.json @@ -1,7 +1,7 @@ { "name": "@swc/css", "packageManager": "yarn@3.2.3", - "version": "0.0.24", + "version": "0.0.25", "description": "Super-fast alternative for postcss", "homepage": "https://swc.rs", "main": "./index.js", diff --git a/packages/html/.gitignore b/packages/html/.gitignore index 343d521..e273a1f 100644 --- a/packages/html/.gitignore +++ b/packages/html/.gitignore @@ -1 +1,2 @@ -/*.js \ No newline at end of file +/*.js +!binding.js \ No newline at end of file diff --git a/packages/html/binding.js b/packages/html/binding.js new file mode 100644 index 0000000..cb0601b --- /dev/null +++ b/packages/html/binding.js @@ -0,0 +1,260 @@ +/* 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, 'html.android-arm64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./html.android-arm64.node') + } else { + nativeBinding = require('@swc/html-android-arm64') + } + } catch (e) { + loadError = e + } + break + case 'arm': + localFileExisted = existsSync(join(__dirname, 'html.android-arm-eabi.node')) + try { + if (localFileExisted) { + nativeBinding = require('./html.android-arm-eabi.node') + } else { + nativeBinding = require('@swc/html-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, 'html.win32-x64-msvc.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./html.win32-x64-msvc.node') + } else { + nativeBinding = require('@swc/html-win32-x64-msvc') + } + } catch (e) { + loadError = e + } + break + case 'ia32': + localFileExisted = existsSync( + join(__dirname, 'html.win32-ia32-msvc.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./html.win32-ia32-msvc.node') + } else { + nativeBinding = require('@swc/html-win32-ia32-msvc') + } + } catch (e) { + loadError = e + } + break + case 'arm64': + localFileExisted = existsSync( + join(__dirname, 'html.win32-arm64-msvc.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./html.win32-arm64-msvc.node') + } else { + nativeBinding = require('@swc/html-win32-arm64-msvc') + } + } catch (e) { + loadError = e + } + break + default: + throw new Error(`Unsupported architecture on Windows: ${arch}`) + } + break + case 'darwin': + localFileExisted = existsSync(join(__dirname, 'html.darwin-universal.node')) + try { + if (localFileExisted) { + nativeBinding = require('./html.darwin-universal.node') + } else { + nativeBinding = require('@swc/html-darwin-universal') + } + break + } catch {} + switch (arch) { + case 'x64': + localFileExisted = existsSync(join(__dirname, 'html.darwin-x64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./html.darwin-x64.node') + } else { + nativeBinding = require('@swc/html-darwin-x64') + } + } catch (e) { + loadError = e + } + break + case 'arm64': + localFileExisted = existsSync( + join(__dirname, 'html.darwin-arm64.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./html.darwin-arm64.node') + } else { + nativeBinding = require('@swc/html-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, 'html.freebsd-x64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./html.freebsd-x64.node') + } else { + nativeBinding = require('@swc/html-freebsd-x64') + } + } catch (e) { + loadError = e + } + break + case 'linux': + switch (arch) { + case 'x64': + if (isMusl()) { + localFileExisted = existsSync( + join(__dirname, 'html.linux-x64-musl.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./html.linux-x64-musl.node') + } else { + nativeBinding = require('@swc/html-linux-x64-musl') + } + } catch (e) { + loadError = e + } + } else { + localFileExisted = existsSync( + join(__dirname, 'html.linux-x64-gnu.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./html.linux-x64-gnu.node') + } else { + nativeBinding = require('@swc/html-linux-x64-gnu') + } + } catch (e) { + loadError = e + } + } + break + case 'arm64': + if (isMusl()) { + localFileExisted = existsSync( + join(__dirname, 'html.linux-arm64-musl.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./html.linux-arm64-musl.node') + } else { + nativeBinding = require('@swc/html-linux-arm64-musl') + } + } catch (e) { + loadError = e + } + } else { + localFileExisted = existsSync( + join(__dirname, 'html.linux-arm64-gnu.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./html.linux-arm64-gnu.node') + } else { + nativeBinding = require('@swc/html-linux-arm64-gnu') + } + } catch (e) { + loadError = e + } + } + break + case 'arm': + localFileExisted = existsSync( + join(__dirname, 'html.linux-arm-gnueabihf.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./html.linux-arm-gnueabihf.node') + } else { + nativeBinding = require('@swc/html-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 { minify, minifyFragment, minifySync, minifyFragmentSync } = nativeBinding + +module.exports.minify = minify +module.exports.minifyFragment = minifyFragment +module.exports.minifySync = minifySync +module.exports.minifyFragmentSync = minifyFragmentSync diff --git a/packages/html/package.json b/packages/html/package.json index 7c8038b..083a227 100644 --- a/packages/html/package.json +++ b/packages/html/package.json @@ -1,7 +1,7 @@ { "name": "@swc/html", "packageManager": "yarn@3.2.3", - "version": "0.0.24", + "version": "0.0.25", "description": "Super-fast alternative for posthtml", "homepage": "https://swc.rs", "main": "./index.js", diff --git a/packages/linter/.gitignore b/packages/linter/.gitignore index 343d521..e273a1f 100644 --- a/packages/linter/.gitignore +++ b/packages/linter/.gitignore @@ -1 +1,2 @@ -/*.js \ No newline at end of file +/*.js +!binding.js \ No newline at end of file diff --git a/packages/linter/binding.js b/packages/linter/binding.js new file mode 100644 index 0000000..424e202 --- /dev/null +++ b/packages/linter/binding.js @@ -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, 'lint.android-arm64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./lint.android-arm64.node') + } else { + nativeBinding = require('@swc/linter-android-arm64') + } + } catch (e) { + loadError = e + } + break + case 'arm': + localFileExisted = existsSync(join(__dirname, 'lint.android-arm-eabi.node')) + try { + if (localFileExisted) { + nativeBinding = require('./lint.android-arm-eabi.node') + } else { + nativeBinding = require('@swc/linter-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, 'lint.win32-x64-msvc.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./lint.win32-x64-msvc.node') + } else { + nativeBinding = require('@swc/linter-win32-x64-msvc') + } + } catch (e) { + loadError = e + } + break + case 'ia32': + localFileExisted = existsSync( + join(__dirname, 'lint.win32-ia32-msvc.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./lint.win32-ia32-msvc.node') + } else { + nativeBinding = require('@swc/linter-win32-ia32-msvc') + } + } catch (e) { + loadError = e + } + break + case 'arm64': + localFileExisted = existsSync( + join(__dirname, 'lint.win32-arm64-msvc.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./lint.win32-arm64-msvc.node') + } else { + nativeBinding = require('@swc/linter-win32-arm64-msvc') + } + } catch (e) { + loadError = e + } + break + default: + throw new Error(`Unsupported architecture on Windows: ${arch}`) + } + break + case 'darwin': + localFileExisted = existsSync(join(__dirname, 'lint.darwin-universal.node')) + try { + if (localFileExisted) { + nativeBinding = require('./lint.darwin-universal.node') + } else { + nativeBinding = require('@swc/linter-darwin-universal') + } + break + } catch {} + switch (arch) { + case 'x64': + localFileExisted = existsSync(join(__dirname, 'lint.darwin-x64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./lint.darwin-x64.node') + } else { + nativeBinding = require('@swc/linter-darwin-x64') + } + } catch (e) { + loadError = e + } + break + case 'arm64': + localFileExisted = existsSync( + join(__dirname, 'lint.darwin-arm64.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./lint.darwin-arm64.node') + } else { + nativeBinding = require('@swc/linter-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, 'lint.freebsd-x64.node')) + try { + if (localFileExisted) { + nativeBinding = require('./lint.freebsd-x64.node') + } else { + nativeBinding = require('@swc/linter-freebsd-x64') + } + } catch (e) { + loadError = e + } + break + case 'linux': + switch (arch) { + case 'x64': + if (isMusl()) { + localFileExisted = existsSync( + join(__dirname, 'lint.linux-x64-musl.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./lint.linux-x64-musl.node') + } else { + nativeBinding = require('@swc/linter-linux-x64-musl') + } + } catch (e) { + loadError = e + } + } else { + localFileExisted = existsSync( + join(__dirname, 'lint.linux-x64-gnu.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./lint.linux-x64-gnu.node') + } else { + nativeBinding = require('@swc/linter-linux-x64-gnu') + } + } catch (e) { + loadError = e + } + } + break + case 'arm64': + if (isMusl()) { + localFileExisted = existsSync( + join(__dirname, 'lint.linux-arm64-musl.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./lint.linux-arm64-musl.node') + } else { + nativeBinding = require('@swc/linter-linux-arm64-musl') + } + } catch (e) { + loadError = e + } + } else { + localFileExisted = existsSync( + join(__dirname, 'lint.linux-arm64-gnu.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./lint.linux-arm64-gnu.node') + } else { + nativeBinding = require('@swc/linter-linux-arm64-gnu') + } + } catch (e) { + loadError = e + } + } + break + case 'arm': + localFileExisted = existsSync( + join(__dirname, 'lint.linux-arm-gnueabihf.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./lint.linux-arm-gnueabihf.node') + } else { + nativeBinding = require('@swc/linter-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 { lint, lintSync } = nativeBinding + +module.exports.lint = lint +module.exports.lintSync = lintSync diff --git a/packages/linter/package.json b/packages/linter/package.json index d58e294..1c3ac3a 100644 --- a/packages/linter/package.json +++ b/packages/linter/package.json @@ -1,7 +1,7 @@ { "name": "@swc/linter", "packageManager": "yarn@3.2.3", - "version": "0.0.24", + "version": "0.0.25", "description": "Super-fast linter based on SWC", "homepage": "https://swc.rs", "main": "./binding.js",