fix: allow use of nuxt3 in non-wsl windows environment (#308)

This commit is contained in:
Daniel Roe 2021-07-12 11:54:24 +01:00 committed by GitHub
parent 4521580fc3
commit 0a3041cdf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 69 additions and 49 deletions

View File

@ -38,6 +38,7 @@
"lerna": "^4.0.0", "lerna": "^4.0.0",
"object-hash": "^2.2.0", "object-hash": "^2.2.0",
"typescript": "^4.3.5", "typescript": "^4.3.5",
"unbuild": "^0.3.1" "unbuild": "^0.3.1",
"upath": "^2.0.1"
} }
} }

View File

@ -1,4 +1,4 @@
const { resolve } = require('path') const { resolve } = require('upath')
module.exports = { module.exports = {
appDir: resolve(__dirname, 'dist') appDir: resolve(__dirname, 'dist')

View File

@ -23,6 +23,7 @@
"@vueuse/head": "^0.6.0", "@vueuse/head": "^0.6.0",
"hookable": "^4.4.1", "hookable": "^4.4.1",
"ohmyfetch": "^0.2.0", "ohmyfetch": "^0.2.0",
"upath": "^2.0.1",
"vue": "^3.1.4", "vue": "^3.1.4",
"vue-router": "^4.0.10", "vue-router": "^4.0.10",
"vuex5": "^0.5.0-testing.3" "vuex5": "^0.5.0-testing.3"

View File

@ -33,6 +33,7 @@
"listhen": "^0.2.4", "listhen": "^0.2.4",
"mri": "^1.1.6", "mri": "^1.1.6",
"unbuild": "^0.3.1", "unbuild": "^0.3.1",
"upath": "^2.0.1",
"v8-compile-cache": "^2.3.0" "v8-compile-cache": "^2.3.0"
} }
} }

View File

@ -1,5 +1,5 @@
import { resolve } from 'path' import { resolve } from 'upath'
import { requireModule } from '../utils/cjs' import { requireModule } from '../utils/cjs'
export async function invoke (args) { export async function invoke (args) {

View File

@ -1,4 +1,4 @@
import { resolve } from 'path' import { resolve } from 'upath'
import chokidar from 'chokidar' import chokidar from 'chokidar'
import debounce from 'debounce-promise' import debounce from 'debounce-promise'
import { createServer, createLoadingHandler } from '../utils/server' import { createServer, createLoadingHandler } from '../utils/server'

View File

@ -1,5 +1,7 @@
import { normalize } from 'upath'
export function resolveModule (id, paths?) { export function resolveModule (id, paths?) {
return require.resolve(id, { return normalize(require.resolve(id, {
paths: [].concat( paths: [].concat(
// @ts-ignore // @ts-ignore
global.__NUXT_PREPATHS__, global.__NUXT_PREPATHS__,
@ -8,7 +10,7 @@ export function resolveModule (id, paths?) {
// @ts-ignore // @ts-ignore
global.__NUXT_PATHS__ global.__NUXT_PATHS__
).filter(Boolean) ).filter(Boolean)
}) }))
} }
export function requireModule (id, paths?) { export function requireModule (id, paths?) {

View File

@ -1,5 +1,5 @@
import { resolve } from 'path'
import { existsSync, promises as fsp } from 'fs' import { existsSync, promises as fsp } from 'fs'
import { resolve } from 'upath'
import dotenv from 'dotenv' import dotenv from 'dotenv'
export interface LoadDotEnvOptions { export interface LoadDotEnvOptions {

View File

@ -1,5 +1,5 @@
import { resolve } from 'path'
import { existsSync } from 'fs' import { existsSync } from 'fs'
import { resolve } from 'upath'
import defu from 'defu' import defu from 'defu'
import { applyDefaults } from 'untyped' import { applyDefaults } from 'untyped'
import * as rc from 'rc9' import * as rc from 'rc9'

View File

@ -1,4 +1,4 @@
import { resolve, join } from 'path' import { resolve, join } from 'upath'
import { existsSync, readdirSync } from 'fs' import { existsSync, readdirSync } from 'fs'
import defu from 'defu' import defu from 'defu'
import { isRelative, joinURL, hasProtocol } from 'ufo' import { isRelative, joinURL, hasProtocol } from 'ufo'

View File

@ -1,4 +1,4 @@
import { join, resolve } from 'path' import { join, resolve } from 'upath'
import env from 'std-env' import env from 'std-env'
import createRequire from 'create-require' import createRequire from 'create-require'
import { pascalCase } from 'scule' import { pascalCase } from 'scule'

View File

@ -1,4 +1,4 @@
import { resolve } from 'path' import { resolve } from 'upath'
import { joinURL } from 'ufo' import { joinURL } from 'ufo'
export default { export default {

View File

@ -1,5 +1,5 @@
import path, { basename, parse } from 'path'
import fs from 'fs' import fs from 'fs'
import path, { basename, parse } from 'upath'
import hash from 'hash-sum' import hash from 'hash-sum'
import consola from 'consola' import consola from 'consola'
import { useNuxt } from '../nuxt' import { useNuxt } from '../nuxt'

View File

@ -1,4 +1,4 @@
import { join } from 'path' import { join, normalize } from 'upath'
import jiti from 'jiti' import jiti from 'jiti'
// TODO: use create-require for jest environment // TODO: use create-require for jest environment
@ -81,7 +81,7 @@ export function requireModulePkg (id: string, opts: RequireModuleOptions = {}) {
/** Resolve the path of a module. */ /** Resolve the path of a module. */
export function resolveModule (id: string, opts: ResolveModuleOptions = {}) { export function resolveModule (id: string, opts: ResolveModuleOptions = {}) {
return _require.resolve(id, { return normalize(_require.resolve(id, {
paths: [].concat( paths: [].concat(
// @ts-ignore // @ts-ignore
global.__NUXT_PREPATHS__, global.__NUXT_PREPATHS__,
@ -90,7 +90,7 @@ export function resolveModule (id: string, opts: ResolveModuleOptions = {}) {
// @ts-ignore // @ts-ignore
global.__NUXT_PATHS__ global.__NUXT_PATHS__
).filter(Boolean) ).filter(Boolean)
}) }))
} }
/** Try to resolve the path of a module, but don't emit an error if it can't be found. */ /** Try to resolve the path of a module, but don't emit an error if it can't be found. */

View File

@ -1,4 +1,4 @@
import { dirname, join, relative, resolve } from 'upath' import { dirname, join, normalize, relative, resolve } from 'upath'
import { InputOptions, OutputOptions } from 'rollup' import { InputOptions, OutputOptions } from 'rollup'
import defu from 'defu' import defu from 'defu'
import { terser } from 'rollup-plugin-terser' import { terser } from 'rollup-plugin-terser'
@ -198,8 +198,8 @@ export const getRollupConfig = (nitroContext: NitroContext) => {
rollupConfig.plugins.push(alias({ rollupConfig.plugins.push(alias({
entries: { entries: {
'#nitro': nitroContext._internal.runtimeDir, '#nitro': nitroContext._internal.runtimeDir,
'#nitro-renderer': require.resolve(resolve(nitroContext._internal.runtimeDir, 'app', renderer)), '#nitro-renderer': normalize(require.resolve(resolve(nitroContext._internal.runtimeDir, 'app', renderer))),
'#config': require.resolve(resolve(nitroContext._internal.runtimeDir, 'app/config')), '#config': normalize(require.resolve(resolve(nitroContext._internal.runtimeDir, 'app/config'))),
'#nitro-vue-renderer': vue2ServerRenderer, '#nitro-vue-renderer': vue2ServerRenderer,
'#build': nitroContext._nuxt.buildDir, '#build': nitroContext._nuxt.buildDir,
'~': nitroContext._nuxt.srcDir, '~': nitroContext._nuxt.srcDir,

View File

@ -1,4 +1,5 @@
import consola from 'consola' import consola from 'consola'
import { normalize } from 'upath'
const internalRegex = /^\.|\?|\.[mc]?js$|.ts$|.json$/ const internalRegex = /^\.|\?|\.[mc]?js$|.ts$|.json$/
@ -9,7 +10,7 @@ export function autoMock () {
if (src && !internalRegex.test(src)) { if (src && !internalRegex.test(src)) {
consola.warn('Auto mock external ', src) consola.warn('Auto mock external ', src)
return { return {
id: require.resolve('unenv/runtime/mock/proxy') id: normalize(require.resolve('unenv/runtime/mock/proxy'))
} }
} }
return null return null

View File

@ -1,6 +1,6 @@
// Based on https://github.com/egoist/rollup-plugin-esbuild (MIT) // Based on https://github.com/egoist/rollup-plugin-esbuild (MIT)
import { extname, relative } from 'path' import { extname, relative } from 'upath'
import { Plugin, PluginContext } from 'rollup' import { Plugin, PluginContext } from 'rollup'
import { Loader, TransformResult, transform } from 'esbuild' import { Loader, TransformResult, transform } from 'esbuild'
import { createFilter, FilterPattern } from '@rollup/pluginutils' import { createFilter, FilterPattern } from '@rollup/pluginutils'

View File

@ -1,4 +1,4 @@
import { resolve, dirname } from 'upath' import { resolve, dirname, normalize } from 'upath'
import { copyFile, mkdirp } from 'fs-extra' import { copyFile, mkdirp } from 'fs-extra'
import { nodeFileTrace, NodeFileTraceOptions } from '@vercel/nft' import { nodeFileTrace, NodeFileTraceOptions } from '@vercel/nft'
import type { Plugin } from 'rollup' import type { Plugin } from 'rollup'
@ -23,6 +23,11 @@ export function externals (opts: NodeExternalsOptions): Plugin {
return null return null
} }
// Normalize path on windows
if (process.platform === 'win32') {
id = id.replace(/\\/g, '/')
}
// Normalize from node_modules // Normalize from node_modules
const _id = id.split('node_modules/').pop() const _id = id.split('node_modules/').pop()
@ -42,7 +47,7 @@ export function externals (opts: NodeExternalsOptions): Plugin {
// Try to resolve for nft // Try to resolve for nft
if (opts.trace !== false) { if (opts.trace !== false) {
let _resolvedId = _id let _resolvedId = _id
try { _resolvedId = require.resolve(_resolvedId, { paths: opts.moduleDirectories }) } catch (_err) {} try { _resolvedId = normalize(require.resolve(_resolvedId, { paths: opts.moduleDirectories })) } catch (_err) { }
resolvedExternals.add(_resolvedId) resolvedExternals.add(_resolvedId)
} }

View File

@ -1,5 +1,5 @@
// Based on https://github.com/rollup/plugins/blob/master/packages/virtual/src/index.ts // Based on https://github.com/rollup/plugins/blob/master/packages/virtual/src/index.ts
import * as path from 'path' import * as path from 'upath'
import { Plugin } from 'rollup' import { Plugin } from 'rollup'

View File

@ -1,3 +1,4 @@
import { normalize } from 'upath'
import { wpfs, getNitroContext, createDevServer, resolveMiddleware, build, prepare, generate } from '@nuxt/nitro' import { wpfs, getNitroContext, createDevServer, resolveMiddleware, build, prepare, generate } from '@nuxt/nitro'
import type { Nuxt } from '@nuxt/kit' import type { Nuxt } from '@nuxt/kit'
@ -22,7 +23,7 @@ export function initNitro (nuxt: Nuxt) {
// Add nitro client plugin (to inject $fetch helper) // Add nitro client plugin (to inject $fetch helper)
nuxt.hook('app:resolve', (app) => { nuxt.hook('app:resolve', (app) => {
app.plugins.push({ src: require.resolve('@nuxt/nitro/dist/runtime/app/nitro.client.mjs') }) app.plugins.push({ src: normalize(require.resolve('@nuxt/nitro/dist/runtime/app/nitro.client.mjs')) })
}) })
// Expose process.env.NITRO_PRESET // Expose process.env.NITRO_PRESET

View File

@ -1,3 +1,4 @@
import { normalize } from 'upath'
import Hookable from 'hookable' import Hookable from 'hookable'
import { loadNuxtConfig, LoadNuxtOptions, Nuxt, NuxtOptions, nuxtCtx, installModule, ModuleContainer } from '@nuxt/kit' import { loadNuxtConfig, LoadNuxtOptions, Nuxt, NuxtOptions, nuxtCtx, installModule, ModuleContainer } from '@nuxt/kit'
import { initNitro } from './nitro' import { initNitro } from './nitro'
@ -52,9 +53,9 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
const { appDir } = await import('@nuxt/app/meta') const { appDir } = await import('@nuxt/app/meta')
options.appDir = appDir options.appDir = appDir
options._majorVersion = 3 options._majorVersion = 3
options.alias.vue = require.resolve('vue/dist/vue.esm-bundler.js') options.alias.vue = normalize(require.resolve('vue/dist/vue.esm-bundler.js'))
options.buildModules.push(require.resolve('@nuxt/pages/module')) options.buildModules.push(normalize(require.resolve('@nuxt/pages/module')))
options.buildModules.push(require.resolve('@nuxt/component-discovery/module')) options.buildModules.push(normalize(require.resolve('@nuxt/component-discovery/module')))
const nuxt = createNuxt(options) const nuxt = createNuxt(options)

View File

@ -1,4 +1,4 @@
import { basename, extname } from 'path' import { basename, extname } from 'upath'
import hash from 'hash-sum' import hash from 'hash-sum'
import { camelCase } from 'scule' import { camelCase } from 'scule'

View File

@ -1,4 +1,4 @@
import { resolve } from 'path' import { resolve } from 'upath'
import * as vite from 'vite' import * as vite from 'vite'
import vitePlugin from '@vitejs/plugin-vue' import vitePlugin from '@vitejs/plugin-vue'
import { cacheDirPlugin } from './plugins/cache-dir' import { cacheDirPlugin } from './plugins/cache-dir'

View File

@ -1,4 +1,4 @@
import { resolve } from 'path' import { resolve } from 'upath'
import * as vite from 'vite' import * as vite from 'vite'
import vuePlugin from '@vitejs/plugin-vue' import vuePlugin from '@vitejs/plugin-vue'
import { mkdirp, writeFile } from 'fs-extra' import { mkdirp, writeFile } from 'fs-extra'

View File

@ -35,6 +35,7 @@
"style-resources-loader": "^1.4.1", "style-resources-loader": "^1.4.1",
"time-fix-plugin": "^2.0.7", "time-fix-plugin": "^2.0.7",
"ufo": "^0.7.7", "ufo": "^0.7.7",
"upath": "^2.0.1",
"url-loader": "^4.1.1", "url-loader": "^4.1.1",
"vue": "3.1.4", "vue": "3.1.4",
"vue-loader": "^16.3.0", "vue-loader": "^16.3.0",

View File

@ -1,5 +1,5 @@
import path from 'path'
import querystring from 'querystring' import querystring from 'querystring'
import path from 'upath'
import webpack from 'webpack' import webpack from 'webpack'
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer' import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'

View File

@ -1,3 +1,4 @@
import { normalize } from 'upath'
import { getQuery } from 'ufo' import { getQuery } from 'ufo'
export default class NuxtSetupTransformerPlugin { export default class NuxtSetupTransformerPlugin {
@ -10,7 +11,7 @@ export default class NuxtSetupTransformerPlugin {
enforce: 'post', enforce: 'post',
use: [{ use: [{
ident: 'NuxtSetupTransformerPlugin', ident: 'NuxtSetupTransformerPlugin',
loader: require.resolve('@nuxt/webpack-builder/dist/nuxt-setup-loader') loader: normalize(require.resolve('@nuxt/webpack-builder/dist/nuxt-setup-loader'))
}] }]
}) })
} }

View File

@ -3,7 +3,7 @@
* https://github.com/vuejs/vue/blob/dev/src/server/webpack-plugin/client.js * https://github.com/vuejs/vue/blob/dev/src/server/webpack-plugin/client.js
*/ */
import { dirname } from 'path' import { dirname } from 'upath'
import hash from 'hash-sum' import hash from 'hash-sum'
import { uniq } from 'lodash' import { uniq } from 'lodash'
import { writeFile, mkdirp } from 'fs-extra' import { writeFile, mkdirp } from 'fs-extra'

View File

@ -1,3 +1,4 @@
import { normalize } from 'upath'
import TerserWebpackPlugin from 'terser-webpack-plugin' import TerserWebpackPlugin from 'terser-webpack-plugin'
import { reservedVueTags } from '../utils/reserved-tags' import { reservedVueTags } from '../utils/reserved-tags'
import { WebpackConfigContext } from '../utils/config' import { WebpackConfigContext } from '../utils/config'
@ -6,7 +7,7 @@ export function babel (ctx: WebpackConfigContext) {
const { config, options } = ctx const { config, options } = ctx
const babelLoader = { const babelLoader = {
loader: require.resolve('babel-loader'), loader: normalize(require.resolve('babel-loader')),
options: getBabelOptions(ctx) options: getBabelOptions(ctx)
} }
@ -66,7 +67,7 @@ function getBabelOptions (ctx: WebpackConfigContext) {
babelOptions.plugins = babelOptions.plugins(ctx) babelOptions.plugins = babelOptions.plugins(ctx)
} }
const defaultPreset = [require.resolve('../../babel-preset-app'), {}] const defaultPreset = [normalize(require.resolve('../../babel-preset-app')), {}]
if (typeof babelOptions.presets === 'function') { if (typeof babelOptions.presets === 'function') {
babelOptions.presets = babelOptions.presets(ctx, defaultPreset) babelOptions.presets = babelOptions.presets(ctx, defaultPreset)

View File

@ -1,4 +1,4 @@
import { resolve, normalize } from 'path' import { resolve, normalize } from 'upath'
import TimeFixPlugin from 'time-fix-plugin' import TimeFixPlugin from 'time-fix-plugin'
import WebpackBar from 'webpackbar' import WebpackBar from 'webpackbar'
import consola from 'consola' import consola from 'consola'

View File

@ -1,4 +1,4 @@
import path from 'path' import path from 'upath'
import MiniCssExtractPlugin from 'mini-css-extract-plugin' import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin' import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
import { fileName, WebpackConfigContext, applyPresets } from '../utils/config' import { fileName, WebpackConfigContext, applyPresets } from '../utils/config'

View File

@ -1,4 +1,4 @@
import { resolve } from 'path' import { resolve } from 'upath'
import VueLoaderPlugin from 'vue-loader/dist/pluginWebpack5' import VueLoaderPlugin from 'vue-loader/dist/pluginWebpack5'
import { DefinePlugin } from 'webpack' import { DefinePlugin } from 'webpack'
import NuxtSetupTransformerPlugin from '../plugins/transform-setup' import NuxtSetupTransformerPlugin from '../plugins/transform-setup'

View File

@ -49,8 +49,8 @@ function getPolyfills (targets, includes, { ignoreBrowserslistConfig, configPath
} }
function isPackageHoisted (packageName) { function isPackageHoisted (packageName) {
const path = require('path') const path = require('upath')
const installedPath = require.resolve(packageName) const installedPath = path.normalize(require.resolve(packageName))
const relativePath = path.resolve(__dirname, '..', 'node_modules', packageName) const relativePath = path.resolve(__dirname, '..', 'node_modules', packageName)
return installedPath !== relativePath return installedPath !== relativePath
} }

View File

@ -1,4 +1,4 @@
import path from 'path' import path from 'upath'
import pify from 'pify' import pify from 'pify'
import { Volume, createFsFromVolume } from 'memfs' import { Volume, createFsFromVolume } from 'memfs'

View File

@ -1,6 +1,6 @@
// @ts-nocheck // @ts-nocheck
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'upath'
import consola from 'consola' import consola from 'consola'
import { defaults, merge, cloneDeep } from 'lodash' import { defaults, merge, cloneDeep } from 'lodash'
import createResolver from 'postcss-import-resolver' import createResolver from 'postcss-import-resolver'

View File

@ -1,5 +1,5 @@
import path from 'path'
import type { IncomingMessage, ServerResponse } from 'http' import type { IncomingMessage, ServerResponse } from 'http'
import path from 'upath'
import pify from 'pify' import pify from 'pify'
import webpack from 'webpack' import webpack from 'webpack'
import Glob from 'glob' import Glob from 'glob'

View File

@ -1,6 +1,6 @@
import { promises as fsp } from 'fs' import { promises as fsp } from 'fs'
import { resolve } from 'path'
import { execSync } from 'child_process' import { execSync } from 'child_process'
import { resolve } from 'upath'
import globby from 'globby' import globby from 'globby'
async function loadPackage (dir: string) { async function loadPackage (dir: string) {

View File

@ -1,4 +1,4 @@
import { resolve } from 'path' import { resolve } from 'upath'
import { readFile } from 'fs-extra' import { readFile } from 'fs-extra'
import { JSDOM } from 'jsdom' import { JSDOM } from 'jsdom'

View File

@ -1,4 +1,4 @@
import { resolve } from 'path' import { resolve } from 'upath'
import { testNitroBuild, setupTest, testNitroBehavior } from './_utils' import { testNitroBuild, setupTest, testNitroBehavior } from './_utils'
describe('nitro:preset:lambda', () => { describe('nitro:preset:lambda', () => {

View File

@ -1,4 +1,4 @@
import { resolve } from 'path' import { resolve } from 'upath'
import { testNitroBuild, startServer, setupTest, testNitroBehavior } from './_utils' import { testNitroBuild, startServer, setupTest, testNitroBehavior } from './_utils'
describe('nitro:preset:node', () => { describe('nitro:preset:node', () => {

View File

@ -1,4 +1,4 @@
import { resolve } from 'path' import { resolve } from 'upath'
import { testNitroBuild, setupTest, startServer, testNitroBehavior } from './_utils' import { testNitroBuild, setupTest, startServer, testNitroBehavior } from './_utils'
describe('nitro:preset:vercel', () => { describe('nitro:preset:vercel', () => {

View File

@ -1,6 +1,6 @@
import { resolve, dirname } from 'path'
import { existsSync, readFileSync, writeFileSync, rmSync, mkdirSync } from 'fs' import { existsSync, readFileSync, writeFileSync, rmSync, mkdirSync } from 'fs'
import { execSync } from 'child_process' import { execSync } from 'child_process'
import { resolve, dirname } from 'upath'
import defu from 'defu' import defu from 'defu'
import hash from 'object-hash' import hash from 'object-hash'
import type { LoadNuxtOptions, NuxtConfig } from '@nuxt/kit' import type { LoadNuxtOptions, NuxtConfig } from '@nuxt/kit'

View File

@ -1660,6 +1660,7 @@ __metadata:
hookable: ^4.4.1 hookable: ^4.4.1
ohmyfetch: ^0.2.0 ohmyfetch: ^0.2.0
unbuild: ^0.3.1 unbuild: ^0.3.1
upath: ^2.0.1
vue: ^3.1.4 vue: ^3.1.4
vue-router: ^4.0.10 vue-router: ^4.0.10
vuex5: ^0.5.0-testing.3 vuex5: ^0.5.0-testing.3
@ -1865,6 +1866,7 @@ __metadata:
time-fix-plugin: ^2.0.7 time-fix-plugin: ^2.0.7
ufo: ^0.7.7 ufo: ^0.7.7
unbuild: ^0.3.1 unbuild: ^0.3.1
upath: ^2.0.1
url-loader: ^4.1.1 url-loader: ^4.1.1
vue: 3.1.4 vue: 3.1.4
vue-loader: ^16.3.0 vue-loader: ^16.3.0
@ -9981,6 +9983,7 @@ __metadata:
listhen: ^0.2.4 listhen: ^0.2.4
mri: ^1.1.6 mri: ^1.1.6
unbuild: ^0.3.1 unbuild: ^0.3.1
upath: ^2.0.1
v8-compile-cache: ^2.3.0 v8-compile-cache: ^2.3.0
dependenciesMeta: dependenciesMeta:
fsevents: fsevents:
@ -10011,6 +10014,7 @@ __metadata:
object-hash: ^2.2.0 object-hash: ^2.2.0
typescript: ^4.3.5 typescript: ^4.3.5
unbuild: ^0.3.1 unbuild: ^0.3.1
upath: ^2.0.1
languageName: unknown languageName: unknown
linkType: soft linkType: soft