From 7905b0dcf5afaf9a465e54b6dbae211627a48ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Sat, 19 Sep 2020 02:07:28 +0900 Subject: [PATCH] wasm: Automatic deployment (#1084) wasm: - Add auto deployment. --- .github/workflows/integration.yml | 6 +-- .../{publish.yml => publish-node.yml} | 12 ++--- .github/workflows/publish-wasm.yml | 47 +++++++++++++++++++ ecmascript/ast/src/lib.rs | 2 +- wasm/Cargo.toml | 25 +++++----- wasm/src/lib.rs | 30 ++++++------ 6 files changed, 83 insertions(+), 39 deletions(-) rename .github/workflows/{publish.yml => publish-node.yml} (96%) create mode 100644 .github/workflows/publish-wasm.yml diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index ecc42cd5daf..6770cf4324c 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -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 @@ -37,7 +37,7 @@ jobs: npm i export PATH="$PATH:$HOME/npm/bin" - npm run build + npm run build:dev npm i -g @swc/cli npm link diff --git a/.github/workflows/publish.yml b/.github/workflows/publish-node.yml similarity index 96% rename from .github/workflows/publish.yml rename to .github/workflows/publish-node.yml index 6a97045eef9..54c8b922b61 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish-node.yml @@ -1,4 +1,4 @@ -name: Publish +name: Publish (node) on: create: @@ -7,8 +7,8 @@ on: env: CARGO_INCREMENTAL: 0 - CI: '1' - DEBUG: 'napi:*' + CI: "1" + DEBUG: "napi:*" jobs: build: @@ -63,7 +63,7 @@ jobs: shell: bash run: npm run build env: - MACOSX_DEPLOYMENT_TARGET: '10.13' + MACOSX_DEPLOYMENT_TARGET: "10.13" - name: Upload artifact uses: actions/upload-artifact@v2 @@ -97,10 +97,10 @@ jobs: run: | docker pull docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts docker tag docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts builder - - name: 'Install dependencies' + - name: "Install dependencies" run: yarn install --frozen-lockfile --registry https://registry.npmjs.org - - name: 'Build' + - name: "Build" run: | docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/node-rs -w /node-rs builder sh -c "cargo build -p node --release" docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/node-rs -w /node-rs builder sh -c "./node_modules/.bin/napi build --platform --cargo-name node --musl --release -c ./package.json ./scripts/npm" diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml new file mode 100644 index 00000000000..ab5ca9e6926 --- /dev/null +++ b/.github/workflows/publish-wasm.yml @@ -0,0 +1,47 @@ +name: Publish (wasm) + +env: + CARGO_INCREMENTAL: 0 + CI: "1" + +on: + create: + tags: + - v* + +jobs: + build: + name: Build - wasm + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup node + uses: actions/setup-node@v1 + with: + node-version: 12 + + - name: Cache + uses: actions/cache@v2 + with: + path: | + ~/.cargo/ + **/target/ + key: ${{ runner.os }}-publish-integration + + - name: Install node dependencies + run: npm i + + - name: Install wasm-pack + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + + - name: Build + run: (cd wasm && wasm-pack build --release --scope=swc --target nodejs) + + - name: Publish + run: | + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc + (cd wasm/pkg && npm publish) + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/ecmascript/ast/src/lib.rs b/ecmascript/ast/src/lib.rs index 562663cabb9..58ba91d3aea 100644 --- a/ecmascript/ast/src/lib.rs +++ b/ecmascript/ast/src/lib.rs @@ -4,7 +4,7 @@ #![deny(trivial_casts)] #![deny(trivial_numeric_casts)] #![deny(unreachable_pub)] -#![deny(variant_size_differences)] +// #![deny(variant_size_differences)] pub use self::{ class::{ diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index f6917e1424b..bdcf9e6a5da 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -1,26 +1,23 @@ [package] -name = "wasm" -version = "0.2.0" authors = ["강동윤 "] -license = "Apache-2.0/MIT" -repository = "https://github.com/swc-project/swc.git" description = "wasm module for swc" edition = "2018" +license = "Apache-2.0/MIT" +name = "wasm" +repository = "https://github.com/swc-project/swc.git" +version = "1.2.30" [lib] crate-type = ["cdylib"] [dependencies] -swc = { path = "../" } -swc_common = { path = "../common" } -swc_ecmascript = { path = "../ecmascript" } -serde_json = "1" +console_error_panic_hook = "0.1.6" once_cell = "1.3.1" path-clean = "0.1" -serde = { version = "1", features = ["derive"] } +serde = {version = "1", features = ["derive"]} +serde_json = "1" +swc = {path = "../"} +swc_common = {path = "../common"} +swc_ecmascript = {path = "../ecmascript"} +wasm-bindgen = {version = "0.2", features = ["serde-serialize"]} wasm-bindgen-futures = "0.4.8" -console_error_panic_hook = "0.1.6" - -[dependencies.wasm-bindgen] -version = "0.2" -features = ["serde-serialize"] \ No newline at end of file diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 6c3734c1918..c27536a438d 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -9,7 +9,7 @@ use swc::{ Compiler, }; use swc_common::{ - errors::{EmitterWriter, Handler, HandlerFlags, SourceMapperDyn}, + errors::{DiagnosticBuilder, Emitter, Handler, SourceMapperDyn}, FileName, FilePathMapping, SourceMap, }; use swc_ecmascript::ast::Program; @@ -98,26 +98,26 @@ fn codemap() -> Arc { } /// Creates a new handler which emits to returned buffer. -fn new_handler(cm: Arc) -> (Arc, BufferedError) { +fn new_handler(_cm: Arc) -> (Arc, BufferedError) { let e = BufferedError::default(); - let handler = Handler::with_emitter_and_flags( - Box::new(EmitterWriter::new( - Box::new(e.clone()), - Some(cm.clone()), - false, - false, - )), - HandlerFlags { - treat_err_as_bug: false, - can_emit_warnings: true, - ..Default::default() - }, - ); + let handler = Handler::with_emitter(true, false, Box::new(MyEmiter::default())); (Arc::new(handler), e) } +#[derive(Clone, Default)] +struct MyEmiter(BufferedError); + +impl Emitter for MyEmiter { + fn emit(&mut self, db: &DiagnosticBuilder<'_>) { + let z = &(self.0).0; + for msg in &db.message { + z.write().unwrap().push_str(&msg.0); + } + } +} + #[derive(Clone, Default)] pub(crate) struct BufferedError(Arc>);