-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ecbca8f
commit 1bb3a2e
Showing
7 changed files
with
303 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Publish swc-plugin-canyon | ||
|
||
on: | ||
push: | ||
branches: [ "*" ] | ||
|
||
jobs: | ||
publish-npm: | ||
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 | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { defineBuildConfig } from 'unbuild'; | ||
|
||
export default defineBuildConfig({ | ||
entries: [ | ||
'src/index', | ||
], | ||
clean: true, | ||
declaration: true, | ||
rollup: { | ||
emitCJS: true, | ||
inlineDependencies: true, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"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" | ||
} | ||
}, | ||
"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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
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, | ||
}; | ||
} | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"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" ] | ||
} |