Skip to content

Commit

Permalink
fix: plugin options
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyinws committed Dec 5, 2023
1 parent 975a242 commit 32b9445
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/core/transform/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@ export function genConsoleString(genContext: GenContext) {
argsName = `${argsName.slice(0, 30)}...`

// not output when argtype is string or number
const lineInfo = `${_prefix}%c🚀 ${fileName}:${originalLine}${['StringLiteral', 'NumericLiteral'].includes(argType) ? '' : ` ~ ${argsName}`}`
const lineInfo = `%c🚀 ${fileName}:${originalLine}${['StringLiteral', 'NumericLiteral'].includes(argType) ? '' : ` ~ ${argsName}`}`
const codePosition = `${relative(cwd(), filePath)}:${originalLine}:${(originalColumn || 0) + 1}`

const launchEditorString = `%c🔦 http://localhost:${port}/client#${Buffer.from(codePosition, 'utf-8').toString('base64')}`

let consoleString = ''

if (!disableHighlight && !disableHighlight)
consoleString = `"${lineInfo}${launchEditorString}","${getConsoleStyle(fileType)}","${launchEditorStyle}","\\n",`
consoleString = `"${_prefix}${lineInfo}${launchEditorString}","${getConsoleStyle(fileType)}","${launchEditorStyle}","\\n",`

if (disableHighlight && !disableLaunchEditor)
consoleString = `"${launchEditorString}","${launchEditorStyle}","\\n",`
consoleString = `"${_prefix}${launchEditorString}","${launchEditorStyle}","\\n",`

if (!disableHighlight && disableLaunchEditor)
consoleString = `"${lineInfo}","${getConsoleStyle(fileType)}","\\n",`
consoleString = `"${_prefix}${lineInfo}","${getConsoleStyle(fileType)}","\\n",`

if (disableHighlight && disableLaunchEditor)
consoleString = `"${_prefix}",`

return {
consoleString,
Expand Down
8 changes: 4 additions & 4 deletions test/__snapshots__/options.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

exports[`options > disable all 1`] = `
{
"code": "console.log('hello javascript',\\"\\")",
"code": "console.log(\\"\\",'hello javascript',\\"\\")",
"map": SourceMap {
"file": undefined,
"mappings": "AAAA,YAAY,qBAAkB",
"mappings": "AAAA,eAAY,qBAAkB",
"names": [],
"sources": [
"/home/runner/work/unplugin-turbo-console/src/App.vue",
Expand Down Expand Up @@ -66,10 +66,10 @@ exports[`options > empty option 1`] = `

exports[`options > perfix suffix 1`] = `
{
"code": "console.log(\\"xxxx \\\\n%c🚀 App.vue:1%c🔦 http://localhost:undefined/client#Li4vLi4vaG9tZS9ydW5uZXIvd29yay91bnBsdWdpbi10dXJiby1jb25zb2xlL3NyYy9BcHAudnVlOjE6MQ==\\",\\"padding:2px 5px; border-radius:3px 0 0 3px;color: #fff; background: #4FC08D\\",\\"background: #00DC8250;padding:2px 5px;border-radius:0 3px 3px 0;margin-bottom:5px\\",\\"\\\\n\\",'hello javascript',\\"\\\\n yyy\\")",
"code": "console.log(\\"xxxx \\\\n\\",'hello javascript',\\"\\\\n yyy\\")",
"map": SourceMap {
"file": undefined,
"mappings": "AAAA,sUAAY,2BAAkB",
"mappings": "AAAA,sBAAY,2BAAkB",
"names": [],
"sources": [
"/home/runner/work/unplugin-turbo-console/src/App.vue",
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ export const optionWithPrefix = {
options: {
prefix: 'xxxx',
suffix: 'yyy',
disableLaunchEditor: false,
disableLaunchEditor: true,
disableHighlight: true,
},
code: `console.log('hello javascript')`,
id: '/home/runner/work/unplugin-turbo-console/src/App.vue',
Expand Down

0 comments on commit 32b9445

Please sign in to comment.