Upgrade to napi-rs@0.3 cli (#1033)

This commit is contained in:
LongYinan 2020-09-05 16:48:22 +08:00 committed by GitHub
parent 468abb9832
commit c0cb9e4401
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 146 additions and 176 deletions

View File

@ -4,7 +4,7 @@ on: [push, pull_request]
env:
CARGO_INCREMENTAL: 0
CI: "1"
CI: '1'
jobs:
integration-test:
@ -15,7 +15,7 @@ jobs:
- uses: actions/setup-node@v2-beta
with:
node-version: "12"
node-version: '12'
- name: Cache
uses: actions/cache@v2
@ -38,10 +38,6 @@ jobs:
export PATH="$PATH:$HOME/npm/bin"
npm run build
cp native/node.$PLATFORM_NAME.node swc.$PLATFORM_NAME.node
cp native/node.$PLATFORM_NAME.node scripts/npm/core-$PLATFORM_NAME/swc.node
(cd scripts/npm/core-$PLATFORM_NAME && npm link)
npm i -g @swc/cli
npm link

View File

@ -8,7 +8,8 @@ on:
env:
CARGO_INCREMENTAL: 0
CI: "1"
CI: '1'
DEBUG: 'napi:*'
jobs:
build:
@ -51,32 +52,24 @@ jobs:
LIBCLANG_PATH: 'C:\\Program Files\\LLVM\\bin'
- name: Install node dependencies
run: |
npm i
run: npm i
- name: Build
shell: bash
run: |
npm run build
cp native/node.$PLATFORM_NAME.node swc.$PLATFORM_NAME.node
cp native/node.$PLATFORM_NAME.node node.$PLATFORM_NAME.node
cp native/node.$PLATFORM_NAME.node scripts/npm/core-$PLATFORM_NAME/swc.node
(cd scripts/npm/core-$PLATFORM_NAME && npm link)
run: npm run build
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: bindings
path: node.${{ env.PLATFORM_NAME }}.node
path: swc.${{ env.PLATFORM_NAME }}.node
- name: List packages
run: ls -R ./scripts/npm/
shell: bash
- name: Test bindings
run: |
npm link @swc/core-$PLATFORM_NAME
npm test
run: npm test
publish:
name: npm
@ -98,17 +91,17 @@ jobs:
- name: Download all artifacts
uses: actions/download-artifact@v2
with:
path: ./native
path: artifacts
- name: List binaries
run: ls -R ./native/
run: ls -R artifacts
shell: bash
- name: Move binaries
shell: bash
run: |
cp ./native/bindings/*.node ./native
run: npm run artifacts
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -9,44 +9,9 @@ import {
} from "./types";
export * from "./types";
import { BundleInput, compileBundleOptions } from "./spack";
import { loadBinding } from '@node-rs/helper';
import { platform } from 'os';
import { loadBinding } from "@node-rs/helper";
let bindings: any
let linuxError = null
try {
bindings = loadBinding(__dirname, 'swc')
} catch (e) {
const platformName = platform()
try {
bindings = require(`@swc/core-${platformName}`)
} catch (e) {
if (platformName !== 'linux') {
throw new TypeError('Not compatible with your platform. Error message: ' + e.message)
} else {
linuxError = e
}
}
}
if (!bindings) {
try {
require.resolve('@swc/core-linux-musl')
} catch (e) {
throw new TypeError(
`Could not load @swc/core-linux, You may need add @swc/core-linux-musl to optionalDependencies of your project`,
)
}
try {
bindings = require('@swc/core-linux-musl')
} catch (e) {
throw new TypeError(
`Linux glibc version load error: ${linuxError.message}; Linux musl version load error: Error message: ${e.message}`,
)
}
}
const bindings = loadBinding(__dirname, "swc", "@swc/core")
/**
* Version of the swc binding.

View File

@ -33,15 +33,20 @@
"cpu": [
"x64"
],
"napi": {
"name": "swc"
},
"dependencies": {
"@node-rs/helper": "^0.3.1"
"@node-rs/helper": "^0.4.0"
},
"types": "./lib/index.d.ts",
"scripts": {
"prepublishOnly": "tsc -d && node ./scripts/npm/prepublish.js",
"build": "tsc -d && cargo build -p node --release && cd ./native && napi build --platform --release .",
"build:dev": "tsc -d && cargo build -p node && cd ./native && napi build --platform .",
"test": "jest node-swc/__tests__"
"artifacts": "napi artifacts -t scripts/npm",
"prepublishOnly": "tsc -d && napi prepublish -p scripts/npm --tagstyle npm",
"build": "tsc -d && cargo build -p node --release && napi build --platform --release --cargo-name node",
"build:dev": "tsc -d && cargo build -p node && napi build --platform --cargo-name node",
"test": "jest node-swc/__tests__",
"version": "napi version -p scripts/npm"
},
"devDependencies": {
"@babel/core": "^7.2.2",
@ -58,7 +63,7 @@
"browserslist": "^4.12.0",
"jest": "^23.6.0",
"lodash": "^4.17.11",
"napi-rs": "^0.2.6",
"napi-rs": "^0.3.1",
"progress": "^2.0.3",
"source-map": "^0.7.3",
"sourcemap-validator": "^1.1.1",
@ -67,10 +72,5 @@
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/swc"
},
"optionalDependencies": {
"@swc/core-darwin": "^1.2.22",
"@swc/core-linux": "^1.2.22",
"@swc/core-win32": "^1.2.22"
}
}
}

View File

@ -1,21 +0,0 @@
{
"name": "@swc/core-darwin",
"description": "The macOS 64-bit binary for @swc/core.",
"repository": "https://github.com/swc-project/swc",
"license": "MIT",
"version": "0.0.0",
"main": "swc.node",
"files": [
"swc.node"
],
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"os": [
"darwin"
],
"cpu": [
"x64"
]
}

View File

@ -1,21 +0,0 @@
{
"name": "@swc/core-linux",
"description": "The Linux 64-bit binary for @swc/core.",
"repository": "https://github.com/swc-project/swc",
"license": "MIT",
"version": "0.0.0",
"main": "swc.node",
"files": [
"swc.node"
],
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"os": [
"linux"
],
"cpu": [
"x64"
]
}

View File

@ -1,21 +0,0 @@
{
"name": "@swc/core-win32",
"description": "The Windows 64-bit binary for @swc-node/core.",
"repository": "https://github.com/swc-project/swc",
"license": "MIT",
"version": "0.0.0",
"main": "swc.node",
"files": [
"swc.node"
],
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"os": [
"win32"
],
"cpu": [
"x64"
]
}

View File

@ -0,0 +1,3 @@
`#@swc/core-darwin`
this is the **darwin** 64-bit binary for `@swc/core`

View File

@ -0,0 +1,37 @@
{
"name": "@swc/core-darwin",
"version": "1.2.23",
"os": [
"darwin"
],
"main": "swc.darwin.node",
"files": [
"swc.darwin.node"
],
"description": "Super-fast alternative for babel",
"keywords": [
"swc",
"spack",
"babel",
"typescript",
"rust",
"webpack",
"tsc"
],
"author": "강동윤 <kdy1997.dev@gmail.com>",
"homepage": "https://swc-project.github.io",
"license": "MIT",
"cpu": [
"x64"
],
"engines": {
"node": ">=8.9.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/swc-project/swc.git"
},
"bugs": {
"url": "https://github.com/swc-project/swc/issues"
}
}

View File

@ -0,0 +1,3 @@
`#@swc/core-linux`
this is the **linux** 64-bit binary for `@swc/core`

View File

@ -0,0 +1,37 @@
{
"name": "@swc/core-linux",
"version": "1.2.23",
"os": [
"linux"
],
"main": "swc.linux.node",
"files": [
"swc.linux.node"
],
"description": "Super-fast alternative for babel",
"keywords": [
"swc",
"spack",
"babel",
"typescript",
"rust",
"webpack",
"tsc"
],
"author": "강동윤 <kdy1997.dev@gmail.com>",
"homepage": "https://swc-project.github.io",
"license": "MIT",
"cpu": [
"x64"
],
"engines": {
"node": ">=8.9.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/swc-project/swc.git"
},
"bugs": {
"url": "https://github.com/swc-project/swc/issues"
}
}

View File

@ -1 +0,0 @@
module.exports = ['darwin', 'linux', 'win32']

View File

@ -1,34 +0,0 @@
const { execSync } = require('child_process')
const fs = require('fs')
const path = require('path')
const { version } = require('../../package.json')
const platforms = require('./platforms')
const updatePackageJson = require('./update-package')
updatePackageJson(path.join(__dirname, '..', '..', 'package.json'), {
optionalDependencies: platforms.reduce((acc, cur) => {
acc[`@swc/core-${cur}`] = `^${version}`
return acc
}, {}),
})
for (const name of platforms) {
const pkgDir = path.join(__dirname, `core-${name}`)
updatePackageJson(path.join(pkgDir, 'package.json'), {
version: `${version}`,
})
}
for (const name of platforms) {
const pkgDir = path.join(__dirname, `core-${name}`)
const bindingFile = fs.readFileSync(path.join(__dirname, '..', '..', 'native', `node.${name}.node`))
fs.writeFileSync(path.join(pkgDir, `swc.node`), bindingFile);
execSync('npm publish', {
cwd: pkgDir,
env: process.env,
stdio: 'inherit',
})
}

View File

@ -1,6 +0,0 @@
const fs = require('fs')
module.exports = function updatePackageJson(path, partial) {
const old = require(path)
fs.writeFileSync(path, JSON.stringify({ ...old, ...partial }, null, 2))
}

View File

@ -0,0 +1,3 @@
`#@swc/core-win32`
this is the **win32** 64-bit binary for `@swc/core`

View File

@ -0,0 +1,37 @@
{
"name": "@swc/core-win32",
"version": "1.2.23",
"os": [
"win32"
],
"main": "swc.win32.node",
"files": [
"swc.win32.node"
],
"description": "Super-fast alternative for babel",
"keywords": [
"swc",
"spack",
"babel",
"typescript",
"rust",
"webpack",
"tsc"
],
"author": "강동윤 <kdy1997.dev@gmail.com>",
"homepage": "https://swc-project.github.io",
"license": "MIT",
"cpu": [
"x64"
],
"engines": {
"node": ">=8.9.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/swc-project/swc.git"
},
"bugs": {
"url": "https://github.com/swc-project/swc/issues"
}
}