Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
wip: try normalizing specifier
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jul 8, 2022
1 parent e45a67d commit 85f6860
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/nuxt/src/pages/macros.ts
Expand Up @@ -3,6 +3,7 @@ import { createUnplugin } from 'unplugin'
import { parseQuery, parseURL, withQuery } from 'ufo'
import { findStaticImports, findExports } from 'mlly'
import MagicString from 'magic-string'
import { normalize } from 'pathe'

export interface TransformMacroPluginOptions {
macros: Record<string, string>
Expand All @@ -25,6 +26,8 @@ export const TransformMacroPlugin = createUnplugin((options: TransformMacroPlugi

function result () {
if (s.hasChanged()) {
// Testing CI
console.log({ id, code: s.toString() })
return { code: s.toString(), map: options.sourcemap && s.generateMap({ source: id, includeContent: true }) }
}
}
Expand All @@ -48,7 +51,7 @@ export const TransformMacroPlugin = createUnplugin((options: TransformMacroPlugi
if (scriptImport) {
// https://github.com/vuejs/vue-loader/pull/1911
// https://github.com/vitejs/vite/issues/8473
const parsed = parseURL(scriptImport.specifier.replace('?macro=true', ''))
const parsed = parseURL(normalize(scriptImport.specifier).replace('?macro=true', ''))
const specifier = withQuery(parsed.pathname, { macro: 'true', ...parseQuery(parsed.search) })
s.overwrite(0, code.length, `export { meta } from "${specifier}"`)
return result()
Expand Down

0 comments on commit 85f6860

Please sign in to comment.