Skip to content

Commit

Permalink
feat: multiple line console
Browse files Browse the repository at this point in the history
  • Loading branch information
yugang.cao committed Dec 1, 2023
1 parent 21b5b93 commit 3810316
Show file tree
Hide file tree
Showing 10 changed files with 571 additions and 314 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "unplugin-remove",
"type": "module",
"version": "0.1.5",
"packageManager": "pnpm@8.6.12",
"packageManager": "pnpm@8.11.0",
"description": "Register global imports on demand for Vite and Webpack",
"license": "MIT",
"type": "module",
"homepage": "https://github.com/Talljack/unplugin-remove#readme",
"repository": {
"type": "git",
Expand All @@ -23,32 +23,32 @@
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
"import": "./dist/index.js"
},
"./vite": {
"require": "./dist/vite.js",
"import": "./dist/vite.mjs"
"import": "./dist/vite.js"
},
"./webpack": {
"require": "./dist/webpack.js",
"import": "./dist/webpack.mjs"
"import": "./dist/webpack.js"
},
"./rollup": {
"require": "./dist/rollup.js",
"import": "./dist/rollup.mjs"
"import": "./dist/rollup.js"
},
"./esbuild": {
"require": "./dist/esbuild.js",
"import": "./dist/esbuild.mjs"
"import": "./dist/esbuild.js"
},
"./types": {
"require": "./dist/types.js",
"import": "./dist/types.mjs"
"import": "./dist/types.js"
},
"./*": "./*"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"module": "dist/index.js",
"types": "index.d.ts",
"typesVersions": {
"*": {
Expand Down
13 changes: 12 additions & 1 deletion playground/vite/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { count } from './test'
debugger
console.log('hello world')
// eslint-disable-next-line prettier/prettier
console.log(
'hello world',
'world hello',
123
)
document.getElementById('app')!.innerHTML = `__UNPLUGIN__${count}`

console.log('hello world')

const test = () => console.log(123)

test()
5 changes: 3 additions & 2 deletions playground/vite/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"type": "module",
"private": true,
"scripts": {
"dev": "nodemon -w '../src/**/*.ts' -e .ts -x vite"
},
"devDependencies": {
"unplugin-remove": "workspace:*",
"vite": "^2.9.13",
"vite-plugin-inspect": "^0.5.1"
"vite": "^5.0.0",
"vite-plugin-inspect": "^0.8.0"
}
}
3 changes: 3 additions & 0 deletions playground/vite/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ import unpluginRemoveVite from 'unplugin-remove/vite'

export default defineConfig({
plugins: [Inspect(), unpluginRemoveVite()],
build: {
sourcemap: true,
},
})
828 changes: 534 additions & 294 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- packages
- playground
packages:
- 'playground/*'
6 changes: 3 additions & 3 deletions scripts/postbuild.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { basename, resolve, dirname } from 'path'
import { basename, dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import { promises as fs } from 'fs'
import fg from 'fast-glob'
import chalk from 'chalk'

const __filename = fileURLToPath(import.meta.url);
const __filename = fileURLToPath(import.meta.url)

const __dirname = dirname(__filename);
const __dirname = dirname(__filename)

async function run() {
const files = await fg('*.js', {
Expand Down
2 changes: 1 addition & 1 deletion src/core/unplugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default createUnplugin<Options>(options => {
const ctx = createUnpluginContext(options ?? defaultOptions)
return {
name: 'unplugin-remove-console-debugger',
enforce: 'post',
enforce: 'post' as const,
apply: 'build',
transformInclude(id) {
return ctx.filter(id)
Expand Down
5 changes: 4 additions & 1 deletion src/core/unpluginContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const createUnpluginContext = (options: Options = {}) => {
map: null,
}
}
const reg = new RegExp(`console\\.(${options.consoleType?.join('|') || 'log'})(.*);?`, 'g')
const reg = new RegExp(
`console\\.(${options.consoleType?.join('|') || 'log'})\\s*\\([\\s\\S]*?\\)(?:\\s*;)?\\s*\\)?;?`,
'g',
)
s.replace(reg, '')
s.replace(/debugger;?/g, '')
return {
Expand Down
1 change: 0 additions & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ export default <Options>{
clean: true,
format: ['cjs', 'esm'],
dts: true,
onSuccess: 'npm run build:fix',
}

0 comments on commit 3810316

Please sign in to comment.