fix(auto-imports): windows issue with parsing query from path (#3700)

Co-authored-by: Daniel Roe <daniel@roe.dev>
This commit is contained in:
pooya parsa 2022-03-16 14:41:37 +01:00 committed by GitHub
parent 452a7730e0
commit cb6a4e97c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 9 deletions

View File

@ -65,8 +65,7 @@ jobs:
strategy: strategy:
matrix: matrix:
# os: [ubuntu-latest, windows-latest] os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
node: [14] node: [14]
steps: steps:
@ -93,8 +92,7 @@ jobs:
strategy: strategy:
matrix: matrix:
# os: [ubuntu-latest, windows-latest] os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
node: [14] node: [14]
steps: steps:

View File

@ -1,4 +1,5 @@
import crypto from 'crypto' import crypto from 'crypto'
import { pathToFileURL } from 'url'
import { createUnplugin } from 'unplugin' import { createUnplugin } from 'unplugin'
import { parse } from 'acorn' import { parse } from 'acorn'
import MagicString from 'magic-string' import MagicString from 'magic-string'
@ -22,7 +23,7 @@ export const KeyPlugin = createUnplugin(() => {
name: 'nuxt-legacy-capi-key-transform', name: 'nuxt-legacy-capi-key-transform',
enforce: 'pre', enforce: 'pre',
transformInclude (id) { transformInclude (id) {
const { pathname, search } = parseURL(id) const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href))
const query = parseQuery(search) const query = parseQuery(search)
if (id.includes('node_modules')) { if (id.includes('node_modules')) {

View File

@ -1,3 +1,4 @@
import { pathToFileURL } from 'url'
import { createUnplugin } from 'unplugin' import { createUnplugin } from 'unplugin'
import { parseQuery, parseURL } from 'ufo' import { parseQuery, parseURL } from 'ufo'
import { Unimport } from 'unimport' import { Unimport } from 'unimport'
@ -8,7 +9,7 @@ export const TransformPlugin = createUnplugin(({ ctx, options }: {ctx: Unimport,
name: 'nuxt:auto-imports-transform', name: 'nuxt:auto-imports-transform',
enforce: 'post', enforce: 'post',
transformInclude (id) { transformInclude (id) {
const { pathname, search } = parseURL(id) const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href))
const { type, macro } = parseQuery(search) const { type, macro } = parseQuery(search)
const exclude = options.transform?.exclude || [/[\\/]node_modules[\\/]/] const exclude = options.transform?.exclude || [/[\\/]node_modules[\\/]/]

View File

@ -1,3 +1,4 @@
import { pathToFileURL } from 'url'
import { createUnplugin } from 'unplugin' import { createUnplugin } from 'unplugin'
import { parseQuery, parseURL } from 'ufo' import { parseQuery, parseURL } from 'ufo'
import { Component } from '@nuxt/schema' import { Component } from '@nuxt/schema'
@ -12,7 +13,7 @@ export const loaderPlugin = createUnplugin((options: LoaderOptions) => ({
name: 'nuxt:components-loader', name: 'nuxt:components-loader',
enforce: 'post', enforce: 'post',
transformInclude (id) { transformInclude (id) {
const { pathname, search } = parseURL(id) const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href))
const query = parseQuery(search) const query = parseQuery(search)
// we only transform render functions // we only transform render functions
// from `type=template` (in Webpack) and bare `.vue` file (in Vite) // from `type=template` (in Webpack) and bare `.vue` file (in Vite)

View File

@ -1,3 +1,4 @@
import { pathToFileURL } from 'url'
import { createUnplugin } from 'unplugin' import { createUnplugin } from 'unplugin'
import { parseQuery, parseURL, withQuery } from 'ufo' import { parseQuery, parseURL, withQuery } from 'ufo'
import { findStaticImports, findExports } from 'mlly' import { findStaticImports, findExports } from 'mlly'
@ -14,12 +15,12 @@ export const TransformMacroPlugin = createUnplugin((options: TransformMacroPlugi
enforce: 'post', enforce: 'post',
transformInclude (id) { transformInclude (id) {
if (!id || id.startsWith('\x00')) { return } if (!id || id.startsWith('\x00')) { return }
const { search, pathname } = parseURL(id) const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href))
return pathname.endsWith('.vue') || !!parseQuery(search).macro return pathname.endsWith('.vue') || !!parseQuery(search).macro
}, },
transform (code, id) { transform (code, id) {
const s = new MagicString(code) const s = new MagicString(code)
const { search } = parseURL(id) const { search } = parseURL(decodeURIComponent(pathToFileURL(id).href))
function result () { function result () {
if (s.hasChanged()) { if (s.hasChanged()) {