Add/wasm build (#31470)

This commit is contained in:
Maia Teegarden 2021-11-17 11:01:02 -08:00 committed by GitHub
parent af6e9e2d87
commit b80c378975
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
248 changed files with 571 additions and 391 deletions

View file

@ -26,6 +26,6 @@ packages/create-next-app/templates/**
test/integration/eslint/**
test/development/basic/legacy-decorators/**/*
test-timings.json
packages/next/build/swc/tests/**
packages/next/build/swc/crates/**
bench/nested-deps/pages/**
bench/nested-deps/components/**

View file

@ -1129,3 +1129,73 @@ jobs:
with:
name: next-swc-binaries
path: packages/next/native/next-swc.android-arm64.node
build-wasm:
needs: build
strategy:
matrix:
target: [web, nodejs]
runs-on: ubuntu-latest
steps:
- uses: actions/cache@v2
id: restore-build
with:
path: ./*
key: ${{ github.sha }}
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 14
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2021-08-12
override: true
target: wasm32-unknown-unknown
- name: Cache
uses: actions/cache@v2
with:
path: |
~/.cargo/
**/target/
key: ${{ runner.os }}-publish-integration
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Build
run: (wasm-pack build packages/next/build/swc/crates/wasm --release --scope=next --target ${{ matrix.target }})
- name: Add target to folder name
run: mv packages/next/build/swc/crates/wasm/pkg packages/next/build/swc/crates/wasm/pkg-${{ matrix.target }}
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: wasm-binaries
path: packages/next/build/swc/crates/wasm/pkg-*
- run: ls packages/next/build/swc/crates/wasm
# - name: Publish
# run: |
# echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
# (cd crates/wasm/pkg && npm publish --access public)
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
practice:
needs: build-wasm
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v2
with:
name: wasm-binaries
path: packages/next/build/swc/crates/wasm
- run: ls packages/next/build/swc/crates/wasm

View file

@ -10,7 +10,7 @@ packages/react-dev-overlay/lib/**
**/__tmp__/**
lerna.json
.github/actions/next-stats-action/.work
packages/next/build/swc/tests/**/*
packages/next/build/swc/crates/**/*
packages/next-codemod/transforms/__testfixtures__/**/*
packages/next-codemod/transforms/__tests__/**/*
packages/next-codemod/**/*.js

View file

@ -1,7 +1,7 @@
**/.next/**
**/_next/**
**/dist/**
packages/next/build/swc/tests/**
packages/next/build/swc/crates/**
packages/next/compiled/**/*
packages/next/bundles/webpack/packages/*.runtime.js
lerna.json

View file

@ -177,6 +177,12 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7"
[[package]]
name = "bumpalo"
version = "3.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c"
[[package]]
name = "byteorder"
version = "1.4.3"
@ -223,6 +229,25 @@ dependencies = [
"bitflags",
]
[[package]]
name = "cloudabi"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467"
dependencies = [
"bitflags",
]
[[package]]
name = "console_error_panic_hook"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
dependencies = [
"cfg-if 1.0.0",
"wasm-bindgen",
]
[[package]]
name = "cpufeatures"
version = "0.2.1"
@ -571,6 +596,15 @@ version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "js-sys"
version = "0.3.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc15e39392125075f60c95ba416f5381ff6c3a948ff02ab12464715adf56c821"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -754,27 +788,16 @@ checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
name = "next-swc"
version = "0.0.0"
dependencies = [
"anyhow",
"backtrace",
"chrono",
"easy-error",
"either",
"fxhash",
"napi",
"napi-build",
"napi-derive",
"once_cell",
"path-clean",
"pathdiff",
"regex",
"retain_mut",
"rustc-hash",
"serde",
"serde_json",
"styled_components",
"swc",
"swc_atoms",
"swc_bundler",
"swc_common",
"swc_css",
"swc_ecma_loader",
@ -788,6 +811,29 @@ dependencies = [
"walkdir",
]
[[package]]
name = "next-swc-napi"
version = "0.0.0"
dependencies = [
"anyhow",
"backtrace",
"fxhash",
"napi",
"napi-build",
"napi-derive",
"next-swc",
"once_cell",
"serde",
"serde_json",
"swc",
"swc_atoms",
"swc_bundler",
"swc_common",
"swc_ecma_loader",
"swc_ecmascript",
"swc_node_base",
]
[[package]]
name = "normpath"
version = "0.2.0"
@ -898,13 +944,13 @@ dependencies = [
[[package]]
name = "parking_lot"
version = "0.11.2"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb"
dependencies = [
"instant",
"lock_api 0.4.5",
"parking_lot_core 0.8.5",
"parking_lot_core 0.8.0",
]
[[package]]
@ -922,14 +968,15 @@ dependencies = [
[[package]]
name = "parking_lot_core"
version = "0.8.5"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b"
dependencies = [
"cfg-if 1.0.0",
"cfg-if 0.1.10",
"cloudabi 0.1.0",
"instant",
"libc",
"redox_syscall",
"redox_syscall 0.1.57",
"smallvec 1.7.0",
"winapi",
]
@ -1262,7 +1309,7 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
dependencies = [
"cloudabi",
"cloudabi 0.0.3",
"fuchsia-cprng",
"libc",
"rand_core 0.4.2",
@ -1332,6 +1379,12 @@ dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "redox_syscall"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "redox_syscall"
version = "0.2.10"
@ -1600,7 +1653,7 @@ checksum = "923f0f39b6267d37d23ce71ae7235602134b250ace715dd2c90421998ddac0c6"
dependencies = [
"lazy_static",
"new_debug_unreachable",
"parking_lot 0.11.2",
"parking_lot 0.11.1",
"phf_shared",
"precomputed-hash",
"serde",
@ -1715,7 +1768,7 @@ dependencies = [
"indexmap",
"is-macro",
"once_cell",
"parking_lot 0.11.2",
"parking_lot 0.11.1",
"petgraph",
"radix_fmt",
"rayon",
@ -2393,7 +2446,7 @@ dependencies = [
"cfg-if 1.0.0",
"libc",
"rand 0.8.4",
"redox_syscall",
"redox_syscall 0.2.10",
"remove_dir_all",
"winapi",
]
@ -2629,6 +2682,104 @@ version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasm"
version = "0.0.0"
dependencies = [
"anyhow",
"console_error_panic_hook",
"next-swc",
"once_cell",
"parking_lot_core 0.8.0",
"path-clean",
"serde",
"serde_json",
"swc",
"swc_common",
"swc_ecmascript",
"tracing",
"wasm-bindgen",
"wasm-bindgen-futures",
]
[[package]]
name = "wasm-bindgen"
version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fe8f61dba8e5d645a4d8132dc7a0a66861ed5e1045d2c0ed940fab33bac0fbe"
dependencies = [
"cfg-if 1.0.0",
"serde",
"serde_json",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "046ceba58ff062da072c7cb4ba5b22a37f00a302483f7e2a6cdc18fedbdc1fd3"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73157efb9af26fb564bb59a009afd1c7c334a44db171d280690d0c3faaec3468"
dependencies = [
"cfg-if 1.0.0",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ef9aa01d36cda046f797c57959ff5f3c615c9cc63997a8d545831ec7976819b"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96eb45c1b2ee33545a813a92dbb53856418bf7eb54ab34f7f7ff1448a5b3735d"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7148f4696fb4960a346eaa60bbfb42a1ac4ebba21f750f75fc1375b098d5ffa"
[[package]]
name = "web-sys"
version = "0.3.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59fe19d70f5dacc03f6e46777213facae5ac3801575d56ca6cbd4c93dcd12310"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "winapi"
version = "0.3.9"

View file

@ -1,48 +1,10 @@
[package]
edition = "2018"
name = "next-swc"
version = "0.0.0"
[workspace]
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
anyhow = "1.0"
backtrace = "0.3"
chrono = "0.4"
easy-error = "1.0.0"
either = "1"
fxhash = "0.2.1"
napi = {version = "1", features = ["serde-json"]}
napi-derive = "1"
once_cell = "1.8.0"
path-clean = "0.1"
pathdiff = "0.2.0"
regex = "1.5"
retain_mut = "0.1.3"
rustc-hash = "1.1.0"
serde = "1"
serde_json = "1"
styled_components = "0.2.0"
swc = "0.85.0"
swc_atoms = "0.2.7"
swc_bundler = { version = "0.82.0", features = ["concurrent"] }
swc_common = {version = "0.14.2", features = ["concurrent", "sourcemap"]}
swc_css = "0.31.0"
swc_ecma_loader = { version = "0.24.2", features = ["node", "lru"] }
swc_ecma_preset_env = "0.66.0"
swc_ecmascript = { version = "0.87.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.1"
swc_stylis = "0.28.0"
tracing = {version = "0.1.28", features = ["release_max_level_off"]}
[build-dependencies]
napi-build = "1"
[dev-dependencies]
swc_ecma_transforms_testing = "0.45.0"
testing = "0.15.1"
walkdir = "2.3.2"
members = [
"crates/core",
"crates/napi",
"crates/wasm"
]
[profile.release]
lto = true
lto = true

View file

@ -0,0 +1,34 @@
[package]
edition = "2018"
name = "next-swc"
version = "0.0.0"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
chrono = "0.4"
easy-error = "1.0.0"
either = "1"
fxhash = "0.2.1"
pathdiff = "0.2.0"
serde = "1"
serde_json = "1"
styled_components = "0.2.0"
swc = "0.85.0"
swc_atoms = "0.2.7"
swc_common = {version = "0.14.2", features = ["concurrent", "sourcemap"]}
swc_css = "0.31.0"
swc_ecma_loader = { version = "0.24.2", features = ["node", "lru"] }
swc_ecma_preset_env = "0.66.0"
swc_ecmascript = { version = "0.87.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.1"
swc_stylis = "0.28.0"
tracing = {version = "0.1.28", features = ["release_max_level_off"]}
[dev-dependencies]
swc_ecma_transforms_testing = "0.45.0"
testing = "0.15.1"
walkdir = "2.3.2"

View file

@ -29,22 +29,15 @@ DEALINGS IN THE SOFTWARE.
#![recursion_limit = "2048"]
//#![deny(clippy::all)]
#[macro_use]
extern crate napi_derive;
/// Explicit extern crate to use allocator.
extern crate swc_node_base;
use auto_cjs::contains_cjs;
use backtrace::Backtrace;
use either::Either;
use napi::{CallContext, Env, JsObject, JsUndefined};
use serde::Deserialize;
use std::cell::RefCell;
use std::rc::Rc;
use std::{env, panic::set_hook, path::PathBuf, sync::Arc};
use swc::{config::ModuleConfig, Compiler, TransformOutput};
use std::{path::PathBuf, sync::Arc};
use swc::config::ModuleConfig;
use swc_common::SourceFile;
use swc_common::{self, chain, pass::Optional, sync::Lazy, FilePathMapping, SourceMap};
use swc_common::{self, chain, pass::Optional};
use swc_ecmascript::ast::EsVersion;
use swc_ecmascript::transforms::pass::noop;
use swc_ecmascript::{
@ -54,17 +47,13 @@ use swc_ecmascript::{
pub mod amp_attributes;
mod auto_cjs;
mod bundle;
pub mod hook_optimizer;
pub mod minify;
pub mod next_dynamic;
pub mod next_ssg;
pub mod page_config;
pub mod remove_console;
pub mod styled_jsx;
mod top_level_binding_collector;
mod transform;
mod util;
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
@ -127,46 +116,6 @@ pub fn custom_before_pass(file: Arc<SourceFile>, opts: &TransformOptions) -> imp
)
}
static COMPILER: Lazy<Arc<Compiler>> = Lazy::new(|| {
let cm = Arc::new(SourceMap::new(FilePathMapping::empty()));
Arc::new(Compiler::new(cm.clone()))
});
#[module_exports]
fn init(mut exports: JsObject) -> napi::Result<()> {
if cfg!(debug_assertions) || env::var("SWC_DEBUG").unwrap_or_default() == "1" {
set_hook(Box::new(|panic_info| {
let backtrace = Backtrace::new();
println!("Panic: {:?}\nBacktrace: {:?}", panic_info, backtrace);
}));
}
exports.create_named_method("bundle", bundle::bundle)?;
exports.create_named_method("transform", transform::transform)?;
exports.create_named_method("transformSync", transform::transform_sync)?;
exports.create_named_method("minify", minify::minify)?;
exports.create_named_method("minifySync", minify::minify_sync)?;
Ok(())
}
fn get_compiler(_ctx: &CallContext) -> Arc<Compiler> {
COMPILER.clone()
}
#[js_function]
fn construct_compiler(ctx: CallContext) -> napi::Result<JsUndefined> {
// TODO: Assign swc::Compiler
ctx.env.get_undefined()
}
pub fn complete_output(env: &Env, output: TransformOutput) -> napi::Result<JsObject> {
env.to_js_value(&output)?.coerce_to_object()
}
impl TransformOptions {
pub fn patch(mut self, fm: &SourceFile) -> Self {
self.swc.swcrc = false;
@ -189,5 +138,3 @@ impl TransformOptions {
self
}
}
pub type ArcCompiler = Arc<Compiler>;

Some files were not shown because too many files have changed in this diff Show more