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",
"object-hash": "^2.2.0",
"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 = {
appDir: resolve(__dirname, 'dist')

View File

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

View File

@ -33,6 +33,7 @@
"listhen": "^0.2.4",
"mri": "^1.1.6",
"unbuild": "^0.3.1",
"upath": "^2.0.1",
"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'
export async function invoke (args) {

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
import { resolve } from 'path'
import { existsSync } from 'fs'
import { resolve } from 'upath'
import defu from 'defu'
import { applyDefaults } from 'untyped'
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 defu from 'defu'
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 createRequire from 'create-require'
import { pascalCase } from 'scule'

View File

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

View File

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

View File

@ -1,4 +1,4 @@
import { join } from 'path'
import { join, normalize } from 'upath'
import jiti from 'jiti'
// TODO: use create-require for jest environment
@ -81,7 +81,7 @@ export function requireModulePkg (id: string, opts: RequireModuleOptions = {}) {
/** Resolve the path of a module. */
export function resolveModule (id: string, opts: ResolveModuleOptions = {}) {
return _require.resolve(id, {
return normalize(_require.resolve(id, {
paths: [].concat(
// @ts-ignore
global.__NUXT_PREPATHS__,
@ -90,7 +90,7 @@ export function resolveModule (id: string, opts: ResolveModuleOptions = {}) {
// @ts-ignore
global.__NUXT_PATHS__
).filter(Boolean)
})
}))
}
/** 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 defu from 'defu'
import { terser } from 'rollup-plugin-terser'
@ -198,8 +198,8 @@ export const getRollupConfig = (nitroContext: NitroContext) => {
rollupConfig.plugins.push(alias({
entries: {
'#nitro': nitroContext._internal.runtimeDir,
'#nitro-renderer': require.resolve(resolve(nitroContext._internal.runtimeDir, 'app', renderer)),
'#config': require.resolve(resolve(nitroContext._internal.runtimeDir, 'app/config')),
'#nitro-renderer': normalize(require.resolve(resolve(nitroContext._internal.runtimeDir, 'app', renderer))),
'#config': normalize(require.resolve(resolve(nitroContext._internal.runtimeDir, 'app/config'))),
'#nitro-vue-renderer': vue2ServerRenderer,
'#build': nitroContext._nuxt.buildDir,
'~': nitroContext._nuxt.srcDir,

View File

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

View File

@ -1,6 +1,6 @@
// 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 { Loader, TransformResult, transform } from 'esbuild'
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 { nodeFileTrace, NodeFileTraceOptions } from '@vercel/nft'
import type { Plugin } from 'rollup'
@ -23,6 +23,11 @@ export function externals (opts: NodeExternalsOptions): Plugin {
return null
}
// Normalize path on windows
if (process.platform === 'win32') {
id = id.replace(/\\/g, '/')
}
// Normalize from node_modules
const _id = id.split('node_modules/').pop()
@ -42,7 +47,7 @@ export function externals (opts: NodeExternalsOptions): Plugin {
// Try to resolve for nft
if (opts.trace !== false) {
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)
}

View File

@ -1,5 +1,5 @@
// 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'

View File

@ -1,3 +1,4 @@
import { normalize } from 'upath'
import { wpfs, getNitroContext, createDevServer, resolveMiddleware, build, prepare, generate } from '@nuxt/nitro'
import type { Nuxt } from '@nuxt/kit'
@ -22,7 +23,7 @@ export function initNitro (nuxt: Nuxt) {
// Add nitro client plugin (to inject $fetch helper)
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

View File

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

View File

@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'upath'
import * as vite from 'vite'
import vitePlugin from '@vitejs/plugin-vue'
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 vuePlugin from '@vitejs/plugin-vue'
import { mkdirp, writeFile } from 'fs-extra'

View File

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

View File

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

View File

@ -1,3 +1,4 @@
import { normalize } from 'upath'
import { getQuery } from 'ufo'
export default class NuxtSetupTransformerPlugin {
@ -10,7 +11,7 @@ export default class NuxtSetupTransformerPlugin {
enforce: 'post',
use: [{
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
*/
import { dirname } from 'path'
import { dirname } from 'upath'
import hash from 'hash-sum'
import { uniq } from 'lodash'
import { writeFile, mkdirp } from 'fs-extra'

View File

@ -1,3 +1,4 @@
import { normalize } from 'upath'
import TerserWebpackPlugin from 'terser-webpack-plugin'
import { reservedVueTags } from '../utils/reserved-tags'
import { WebpackConfigContext } from '../utils/config'
@ -6,7 +7,7 @@ export function babel (ctx: WebpackConfigContext) {
const { config, options } = ctx
const babelLoader = {
loader: require.resolve('babel-loader'),
loader: normalize(require.resolve('babel-loader')),
options: getBabelOptions(ctx)
}
@ -66,7 +67,7 @@ function getBabelOptions (ctx: WebpackConfigContext) {
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') {
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 WebpackBar from 'webpackbar'
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 CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
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 { DefinePlugin } from 'webpack'
import NuxtSetupTransformerPlugin from '../plugins/transform-setup'

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
import { promises as fsp } from 'fs'
import { resolve } from 'path'
import { execSync } from 'child_process'
import { resolve } from 'upath'
import globby from 'globby'
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 { JSDOM } from 'jsdom'

View File

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

View File

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

View File

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