Skip to content

Commit

Permalink
fix: webpack windows path
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyinws committed Jul 17, 2024
1 parent 778e50b commit 726422e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/core/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cwd } from 'node:process'
import { extname, relative, sep } from 'pathe'
import { extname, relative } from 'pathe'
import { createFilter } from '@rollup/pluginutils'
import type { Comment, Node } from '@babel/types'
import type { Compiler, GenContext, Options } from '../types'
Expand Down Expand Up @@ -43,6 +43,7 @@ export function getFileNameWithoutExtension(fileName: string) {
}

export function getExtendedPath(filePath: string, extendedPathFileNames?: string[]) {
const sep = filePath.includes('\\') ? '\\' : '/'
const arr = filePath.split(sep)
let basename = arr.pop() || ''
const basenameWithoutExt = getFileNameWithoutExtension(basename).toLowerCase()
Expand Down
34 changes: 34 additions & 0 deletions test/__snapshots__/transform.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,40 @@ exports[`edge case > includes highlight 1`] = `
}
`;

exports[`edge case > win path 1`] = `
{
"code": "<template>
Hello World
</template>
<script setup lang="ts">
const msg: string = "Hello World"
console.log("%c🚀 App.vue·7 ~ msg%c🔦 http://localhost:3070#appvue,7,3","padding:2px 5px; border-radius:3px 0 0 3px;margin-bottom:5px;color: #fff; background: #4FC08D","background: #00DC8250;padding:2px 5px;border-radius:0 3px 3px 0;margin-bottom:5px","\\n",msg)
</script>
",
"map": SourceMap {
"file": "App.vue",
"mappings": "AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACV,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACb,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACX;AACA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,sPAAC,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;",
"names": [],
"sources": [
"App.vue",
],
"sourcesContent": [
"<template>
Hello World
</template>
<script setup lang="ts">
const msg: string = "Hello World"
console.log(msg)
</script>
",
],
"version": 3,
},
}
`;

exports[`svelte transform > svelte 1`] = `
{
"code": "<script lang="ts">
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,17 @@ export const INCLUDES_HIGHLIGHT: Context = {
code: `console.log('%cLog Message', 'color: orange');`,
id: '/home/runner/main.js',
}

export const WIN_PATH = {
options: {},
code: `<template>
Hello World
</template>
<script setup lang="ts">
const msg: string = "Hello World"
console.log(msg)
</script>
`,
id: '\\home\\runner\\App.vue',
}
7 changes: 6 additions & 1 deletion test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { join } from 'pathe'
import { describe, expect, it, vi } from 'vitest'
import { transform } from '../src/core/transform'
import { resolveOptions } from '../src/core/options'
import { INCLUDES_HIGHLIGHT, SVELTE, TSX, TYPESCRIPT, VUE_OPTIONS, VUE_SCRIPT_SETUP } from './fixtures/transform'
import { INCLUDES_HIGHLIGHT, SVELTE, TSX, TYPESCRIPT, VUE_OPTIONS, VUE_SCRIPT_SETUP, WIN_PATH } from './fixtures/transform'

vi.mock('node:process', () => {
return {
Expand Down Expand Up @@ -58,4 +58,9 @@ describe('edge case', () => {
INCLUDES_HIGHLIGHT.options = resolveOptions(INCLUDES_HIGHLIGHT.options)
expect(await transform(INCLUDES_HIGHLIGHT)).matchSnapshot()
})

it('win path', async () => {
WIN_PATH.options = resolveOptions(WIN_PATH.options)
expect(await transform(WIN_PATH)).matchSnapshot()
})
})

0 comments on commit 726422e

Please sign in to comment.