fix: windows path issues (#408)

This commit is contained in:
Daniel Roe 2021-08-09 19:24:52 +01:00 committed by GitHub
parent a5dfe69850
commit 25e96bb896
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 9 deletions

View File

@ -35,7 +35,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest] # TODO: add windows-latest by #408
os: [ubuntu-latest, windows-latest]
node: [14]
steps:
@ -59,7 +59,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest] # TODO: add windows-latest by #408
os: [ubuntu-latest, windows-latest]
node: [14]
steps:

View File

@ -24,6 +24,14 @@ export default function nuxt2CompatModule () {
const nitroContext = getNitroContext(nuxt.options, nitroOptions)
const nitroDevContext = getNitroContext(nuxt.options, { ...nitroOptions, preset: 'dev' })
// Normalize Nuxt directories
for (const context of [nitroContext, nitroDevContext]) {
context._nuxt.rootDir = resolve(context._nuxt.rootDir)
context._nuxt.srcDir = resolve(context._nuxt.srcDir)
context._nuxt.buildDir = resolve(context._nuxt.buildDir)
context._nuxt.generateDir = resolve(context._nuxt.generateDir)
}
// Connect hooks
nuxt.addHooks(nitroContext.nuxtHooks)
nuxt.hook('close', () => nitroContext._internal.hooks.callHook('close'))

View File

@ -23,8 +23,14 @@ export function externals (opts: NodeExternalsOptions): Plugin {
return null
}
const originalId = id
// Normalize path on windows
if (process.platform === 'win32') {
if (id.startsWith('/')) {
// Add back C: prefix on Windows
id = resolve(id)
}
id = id.replace(/\\/g, '/')
}
@ -46,7 +52,7 @@ export function externals (opts: NodeExternalsOptions): Plugin {
// Track externals
if (opts.trace !== false) {
const resolved = await this.resolve(id, importer, { ...options, skipSelf: true }).then(r => r.id)
const resolved = await this.resolve(originalId, importer, { ...options, skipSelf: true }).then(r => r.id)
trackedExternals.add(resolved)
}

View File

@ -45,6 +45,11 @@ export async function generateApp (nuxt: Nuxt, app: NuxtApp) {
const aliasPath = '#build/' + template.filename.replace(/\.\w+$/, '')
nuxt.vfs[aliasPath] = contents
// In case a non-normalized absolute path is called for on Windows
if (process.platform === 'win32') {
nuxt.vfs[fullPath.replace(/\//g, '\\')] = contents
}
}))
await nuxt.callHook('app:templatesGenerated', app)

View File

@ -1,4 +1,4 @@
import { dirname, join } from 'upath'
import { dirname, isAbsolute, join, resolve } from 'upath'
import type { Plugin } from 'rollup'
const PREFIX = '\0virtual:'
@ -19,9 +19,13 @@ export default function virtual (vfs: Record<string, string>): Plugin {
name: 'virtual',
resolveId (id, importer) {
if (process.platform === 'win32' && isAbsolute(id)) {
// Add back C: prefix on Windows
id = resolve(id)
}
const resolvedId = resolveWithExt(id)
if (resolvedId) { return PREFIX + resolvedId }
if (importer && id[0] !== '/') {
if (importer && !isAbsolute(id)) {
const importerNoPrefix = importer.startsWith(PREFIX) ? importer.slice(PREFIX.length) : importer
const importedDir = dirname(importerNoPrefix)
const resolved = resolveWithExt(join(importedDir, id))

View File

@ -1,3 +1,4 @@
import { isAbsolute } from 'upath'
import { ProvidePlugin } from 'webpack'
import { WebpackConfigContext, applyPresets, getWebpackConfig } from '../utils/config'
import { nuxt } from '../presets/nuxt'
@ -48,7 +49,7 @@ function serverStandalone (ctx: WebpackConfigContext) {
ctx.config.externals.push(({ request }, cb) => {
if (
request[0] === '.' ||
request[0] === '/' ||
isAbsolute(request) ||
inline.find(prefix => request.startsWith(prefix))
) {
// console.log('Inline', request)

View File

@ -11693,8 +11693,8 @@ typescript@^4.3.5:
linkType: hard
"unbuild@npm:^0.4.1":
version: 0.4.1
resolution: "unbuild@npm:0.4.1"
version: 0.4.2
resolution: "unbuild@npm:0.4.2"
dependencies:
"@rollup/plugin-alias": ^3.1.4
"@rollup/plugin-commonjs": ^19.0.1
@ -11719,7 +11719,7 @@ typescript@^4.3.5:
upath: ^2.0.1
bin:
unbuild: bin/unbuild.js
checksum: ad99d5db62eef0f9b812f58dea4ff09df9d41d43f028b626faf7cae138cd83b0bee20f2cca1750b8fcce4a6a58d434757698a6c626b0543d3fa57266d7dea47a
checksum: c21e40225b73ded9ccd5893e4af9d7c5ce984d025b2732cbfd95a8c2969ae33a9e1a0351fd84d0e24fe1b4206bc0fbebab83b938afe90cafae0abf197f5250b4
languageName: node
linkType: hard