diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..a2482365 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,29 @@ +[alias] +xtask = "run --package xtask --" + + +[build] + +rustdocflags = [] + +[target.x86_64-unknown-linux-gnu] +rustflags = ["-C", "target-feature=+sse2"] + +[target.x86_64-unknown-linux-musl] +rustflags = ["-C", "target-feature=+sse2"] + +[target.x86_64-apple-darwin] +rustflags = ["-C", "target-feature=+sse2"] + +[target.x86_64-pc-windows-msvc] +rustflags = ["-C", "target-feature=+sse2"] + +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc" + +[target.aarch64-unknown-linux-musl] +linker = "aarch64-linux-gnu-gcc" +rustflags = ["-C", "target-feature=-crt-static", "-C", "link-arg=-lgcc"] + +[target.armv7-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc" diff --git a/.github/workflows/publish-swc-plugin-canyon.yml b/.github/workflows/publish-swc-plugin-canyon.yml index 0505eb75..d3c9bd9d 100644 --- a/.github/workflows/publish-swc-plugin-canyon.yml +++ b/.github/workflows/publish-swc-plugin-canyon.yml @@ -1,22 +1,39 @@ -name: Publish swc-plugin-canyon +name: Npm Publish swc-plugin-canyon on: push: - branches: [ "*" ] + branches: + - main + - ci + +env: + RUST_LOG: debug + CARGO_INCREMENTAL: 0 + MACOSX_DEPLOYMENT_TARGET: "10.13" jobs: - publish-npm: + build: + name: Build runs-on: ubuntu-latest steps: - - uses: pnpm/action-setup@v4 - with: - version: 9 - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 with: - node-version: 20 - registry-url: https://registry.npmjs.org/ - - run: pnpm install - - run: pnpm --filter=swc-plugin-canyon publish -f --no-git-checks --access=public --filter + submodules: true + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + + - name: Install wasm target + shell: bash + run: | + rustup target add wasm32-wasi + + - name: Setup node + uses: pnpm/action-setup@v4 + + - run: | + pnpm --filter=swc-plugin-canyon publish -f --no-git-checks --access=public env: NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}} diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000..216e233b --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,77 @@ +[workspace] +members = ["plugins/*"] + + +resolver = "2" + + +[workspace.package] +authors = ["Allen Zhang "] +edition = "2021" +homepage = "https://github.com/canyon-project/canyon" +license = "Apache-2.0" +repository = "https://github.com/canyon-project/canyon.git" +rust-version = "1.70" + +[workspace.dependencies] +Inflector = "0.11.4" +anyhow = "1.0.83" +base64 = "0.22" +byteorder = "1" +cargo_metadata = "0.18.1" +cipher = "0.4.4" +clap = "4.5.4" +convert_case = "0.6.0" +default-from-serde = "0.1" +fxhash = "0.2.1" +handlebars = "5.1.2" +hex = "0.4.3" +lightningcss = "1.0.0-alpha.59" +magic-crypt = "3.1.13" +once_cell = "1.19.0" +parcel_selectors = "0.27.0" +phf = "0.11.2" +preset_env_base = "1.0.0" +radix_fmt = "1" +regex = { version = "1.10.4", default-features = false } +serde = "1.0.203" +serde_json = "1.0.117" +sourcemap = "9.0.0" +swc_atoms = "2.0.0" +swc_cached = "1.0.0" +swc_common = "1.0.0" +swc_core = "1.0.0" +swc_css_ast = "1.0.0" +swc_css_codegen = "1.0.0" +swc_css_compat = "1.0.0" +swc_css_minifier = "1.0.0" +swc_css_parser = "1.0.0" +swc_css_prefixer = "1.0.0" +swc_css_visit = "1.0.0" +swc_ecma_ast = "1.0.0" +swc_ecma_codegen = "1.0.0" +swc_ecma_minifier = "1.0.0" +swc_ecma_parser = "1.0.0" +swc_ecma_transforms = "1.0.0" +swc_ecma_transforms_base = "1.0.0" +swc_ecma_transforms_react = "1.0.0" +swc_ecma_transforms_testing = "1.0.0" +swc_ecma_utils = "1.0.0" +swc_ecma_visit = "1.0.0" +swc_plugin_macro = "1.0.0" +swc_plugin_proxy = "1.0.0" +swc_trace_macro = "2.0.0" +testing = "1.0.0" +tracing = "0.1.40" + + +[profile.release] +codegen-units = 1 +# debug = true +lto = true + +# Optimize for size +opt-level = "s" + +# Strip debug symbols +strip = "symbols" diff --git a/plugins/swc-plugin-canyon/.editorconfig b/plugins/swc-plugin-canyon/.editorconfig deleted file mode 100755 index a1c0c006..00000000 --- a/plugins/swc-plugin-canyon/.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -# EditorConfig is awesome: https://EditorConfig.org - -root = true - -[*] -indent_style = space -indent_size = 2 -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true diff --git a/plugins/swc-plugin-canyon/.gitignore b/plugins/swc-plugin-canyon/.gitignore index 35060845..96ef6c0b 100644 --- a/plugins/swc-plugin-canyon/.gitignore +++ b/plugins/swc-plugin-canyon/.gitignore @@ -1,131 +1,2 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Snowpack dependency directory (https://snowpack.dev/) -web_modules/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next -out - -# Nuxt.js build / generate output -.nuxt -dist -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# yarn v2 -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz -.pnp.* - -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -*.code-workspace - -# Local History for Visual Studio Code -.history/ - -demo/ - -.idea/ - -pnpm-lock.yaml +/target +Cargo.lock diff --git a/plugins/swc-plugin-canyon/.npmignore b/plugins/swc-plugin-canyon/.npmignore new file mode 100644 index 00000000..1ed674f5 --- /dev/null +++ b/plugins/swc-plugin-canyon/.npmignore @@ -0,0 +1,2 @@ +transform/ +tests/ \ No newline at end of file diff --git a/plugins/swc-plugin-canyon/Cargo.toml b/plugins/swc-plugin-canyon/Cargo.toml new file mode 100644 index 00000000..4ec22d8c --- /dev/null +++ b/plugins/swc-plugin-canyon/Cargo.toml @@ -0,0 +1,27 @@ +[package] + +description = "Canyon plugin for debugging." + + +authors = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +name = "swc_plugin_canyon" +publish = false +repository = { workspace = true } +rust-version = { workspace = true } +version = "0.18.4" + + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +swc_common = { workspace = true, features = ["concurrent"] } +swc_core = { workspace = true, features = ["ecma_plugin_transform"] } +swc_ecma_ast = { workspace = true } +swc_ecma_utils = { workspace = true } +swc_ecma_visit = { workspace = true } +swc_plugin_macro = { workspace = true } +tracing = { workspace = true, features = ["release_max_level_off"] } diff --git a/plugins/swc-plugin-canyon/README.md b/plugins/swc-plugin-canyon/README.md deleted file mode 100644 index 1254483e..00000000 --- a/plugins/swc-plugin-canyon/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# swc-plugin-canyon - -To see how to use this plugin, please visit our [documentation](https://docs.canyonjs.org/zh/documentation/ecosystem/swc-plugin-canyon). - diff --git a/plugins/swc-plugin-canyon/build.config.ts b/plugins/swc-plugin-canyon/build.config.ts deleted file mode 100644 index cd9dfa8e..00000000 --- a/plugins/swc-plugin-canyon/build.config.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineBuildConfig } from 'unbuild'; - -export default defineBuildConfig({ - entries: [ - 'src/index', - ], - clean: true, - declaration: true, - rollup: { - emitCJS: true, - inlineDependencies: true, - }, -}); diff --git a/plugins/swc-plugin-canyon/package.json b/plugins/swc-plugin-canyon/package.json index 65541495..62478db1 100644 --- a/plugins/swc-plugin-canyon/package.json +++ b/plugins/swc-plugin-canyon/package.json @@ -1,42 +1,9 @@ { "name": "swc-plugin-canyon", - "version": "0.0.1-alpha.1", - "license": "MIT", - "files": [ - "dist/*" - ], - "main": "./dist/index.cjs", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "exports": { - ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.cjs" - } - }, + "version": "0.0.2", + "description": "Canyon SWC plugin, for debugging", + "main": "swc_plugin_canyon.wasm", "scripts": { - "dev": "unbuild --stub", - "build": "unbuild", - "prepublishOnly": "npm run build" - }, - "keywords": [ - "vite", - "babel", - "plugin", - "istanbul", - "nyc", - "canyon" - ], - "dependencies": { - "picocolors": "^1.0.0" - }, - "peerDependencies": { - "vite": ">=2.9.1" - }, - "devDependencies": { - "@types/node": "^20.10.6", - "typescript": "^5.3.3", - "unbuild": "^2.0.0" + "prepack": "cargo build --release -p swc_plugin_canyon --target wasm32-wasi && cp ../../target/wasm32-wasi/release/swc_plugin_canyon.wasm . && ls && cat package.json" } } diff --git a/plugins/swc-plugin-canyon/src/index.ts b/plugins/swc-plugin-canyon/src/index.ts deleted file mode 100644 index ed626fc7..00000000 --- a/plugins/swc-plugin-canyon/src/index.ts +++ /dev/null @@ -1,66 +0,0 @@ -import {Plugin, createLogger} from 'vite'; -import picocolors from 'picocolors'; - -const {green} = picocolors; - -export interface canyonPluginOptions { - commitSha?: string; - projectID?: string; - compareTarget?: string; - dsn?: string; - reporter?: string; - instrumentCwd?: string; - branch?: string; -} - -// Custom extensions to include .vue files -const DEFAULT_EXTENSION = ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx', '.vue']; -const PLUGIN_NAME = 'vite:canyon'; - -function resolveFilename(id: string): string { - // To remove the annoying query parameters from the filename - const [filename] = id.split('?vue'); - return filename; -} - -function shouldInstrument(filename: string) { - return DEFAULT_EXTENSION.some(ext => filename.endsWith(ext)); -} - -function instrumentedData(args: canyonPluginOptions): string { - const canyon = { - // gitlab流水线自带 - projectID: args.projectID || process.env['CI_PROJECT_ID'] || '', - commitSha: args.commitSha || process.env['CI_COMMIT_SHA'] || '', - sha: args.commitSha || process.env['CI_COMMIT_SHA'] || '', - branch: args.branch || process.env['CI_COMMIT_BRANCH'] || process.env['CI_COMMIT_REF_NAME'] ||'', - // 自己配置 - dsn: args.dsn || process.env['DSN'] || '', - reporter: args.reporter || process.env['REPORTER'] || '', - // 可选 - compareTarget: args.compareTarget, - // 自动获取 - instrumentCwd: args.instrumentCwd || process.cwd(), - } - return `(new Function("return this")()).__canyon__ = ${JSON.stringify(canyon)}`; -} - -export default function canyonPlugin(opts: canyonPluginOptions = {}): Plugin { - const logger = createLogger('info', {prefix: 'vite-plugin-canyon'}); - const canyonStr = instrumentedData(opts); - // logger.warn(`${PLUGIN_NAME}> ${green(`instrumented data: ${canyonStr}`)}`); - return { - name: PLUGIN_NAME, - enforce: 'post', - transform(srcCode, id, options) { - const newCode = `${canyonStr}\n${srcCode}` - const filename = resolveFilename(id); - if (shouldInstrument(filename)) { - return { - code: newCode, - map: null, - }; - } - }, - }; -} diff --git a/plugins/swc-plugin-canyon/src/lib.rs b/plugins/swc-plugin-canyon/src/lib.rs new file mode 100644 index 00000000..fdd69c5c --- /dev/null +++ b/plugins/swc-plugin-canyon/src/lib.rs @@ -0,0 +1,10 @@ +#![allow(clippy::not_unsafe_ptr_arg_deref)] + +use swc_core::plugin::proxies::TransformPluginProgramMetadata; +use swc_ecma_ast::Program; +use swc_plugin_macro::plugin_transform; + +#[plugin_transform] +fn plugin(program: Program, _: TransformPluginProgramMetadata) -> Program { + program +} diff --git a/plugins/swc-plugin-canyon/tsconfig.json b/plugins/swc-plugin-canyon/tsconfig.json deleted file mode 100644 index 2a6e0a70..00000000 --- a/plugins/swc-plugin-canyon/tsconfig.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "compilerOptions": { - "target": "es2018", - "module": "commonjs", - "moduleResolution": "node", - "lib": [ "dom" ], - "rootDir": "src", - "outDir": "dist", - "sourceMap": true, - "declaration": true, - "declarationMap": true, - "strict": true, - "allowSyntheticDefaultImports": true, - "esModuleInterop": true - }, - "include": [ "src/*" ], - "exclude": [ "**/node_modules" ] -} diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 00000000..c8dce96f --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly-2024-04-16 \ No newline at end of file