chore: migrate to unenv and mkbuild 0.2 (#108)

This commit is contained in:
pooya parsa 2021-04-21 17:10:53 +02:00 committed by GitHub
parent 4c0dba202f
commit de9dffb0d6
37 changed files with 117 additions and 102 deletions

View File

@ -30,6 +30,6 @@
"lerna": "^4.0.0",
"ts-jest": "^26.5.5",
"typescript": "^4.2.4",
"unbuild": "^0.1.13"
"unbuild": "^0.2.2"
}
}

View File

@ -1,6 +1,6 @@
import { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'
export default <BuildConfig>{
export default defineBuildConfig({
declaration: true,
entries: [
{ input: 'src/', name: 'app' }
@ -11,4 +11,4 @@ export default <BuildConfig>{
'vue-router',
'vuex5'
]
}
})

View File

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

View File

@ -3,8 +3,12 @@
"version": "0.3.1",
"repository": "nuxt/framework",
"license": "MIT",
"main": "./dist/app/index.js",
"module": "./dist/app/index.js",
"exports": {
".": "./dist",
"./meta": "./meta.js"
},
"main": "./dist",
"module": "./dist",
"types": "./types/index.d.ts",
"files": [
"dist",
@ -14,9 +18,6 @@
"scripts": {
"prepack": "unbuild"
},
"devDependencies": {
"unbuild": "^0.1.13"
},
"dependencies": {
"@vueuse/head": "^0.5.1",
"hookable": "^4.4.1",
@ -24,5 +25,8 @@
"vue": "^3.0.11",
"vue-router": "^4.0.6",
"vuex5": "^0.5.0-testing.3"
},
"devDependencies": {
"unbuild": "^0.2.2"
}
}

View File

@ -6,6 +6,6 @@
<body {{ BODY_ATTRS }}>
<div id="__nuxt">{{ APP }}</div>
<% if (nuxtOptions.vite && nuxtOptions.dev) { %><script type="module" src="/@vite/client"></script>
<script type="module" src="/entry.client.js"></script><% } %>
<script type="module" src="/entry.client.mjs"></script><% } %>
</body>
</html>

View File

@ -1,3 +1,3 @@
import './shims'
export * from '../dist/app'
export * from '../dist'

View File

@ -28,7 +28,7 @@ declare module '*.vue' {
}
declare module 'vue' {
import type { Nuxt } from '../dist/app'
import type { Nuxt } from '../dist'
interface App {
$nuxt: Nuxt

View File

@ -1,6 +1,6 @@
import type { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'
export default <BuildConfig>{
export default defineBuildConfig({
declaration: false,
inlineDependencies: true,
entries: [
@ -10,4 +10,4 @@ export default <BuildConfig>{
'@nuxt/kit',
'fsevents'
]
}
})

View File

@ -32,7 +32,7 @@
"flat": "^5.0.2",
"listhen": "^0.2.4",
"mri": "^1.1.6",
"unbuild": "^0.1.13",
"unbuild": "^0.2.2",
"v8-compile-cache": "^2.3.0"
}
}

1
packages/kit/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
schema

View File

@ -1,10 +1,11 @@
import type { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'
export default <BuildConfig>{
export default defineBuildConfig({
declaration: true,
entries: [
{
input: 'src/config/schema/index',
outDir: 'schema',
name: 'config',
builder: 'untyped',
defaults: {
@ -18,4 +19,4 @@ export default <BuildConfig>{
'nuxt',
'nuxt3'
]
}
})

View File

@ -6,13 +6,14 @@
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
"dist",
"schema"
],
"scripts": {
"prepack": "unbuild"
},
"devDependencies": {
"unbuild": "^0.1.13"
"unbuild": "^0.2.2"
},
"dependencies": {
"consola": "^2.15.3",

View File

@ -1,4 +1,4 @@
import { ConfigSchema } from '../../.gen/config/config'
import { ConfigSchema } from '../../schema/config'
import { ModuleInstallOptions } from './module'
import { NuxtHooks } from './hooks'

View File

@ -1,11 +1,12 @@
import type { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'
export default <BuildConfig>{
export default defineBuildConfig({
declaration: true,
entries: [
'src/index',
'src/compat',
{ input: 'src/runtime/', format: 'esm' }
{ input: 'src/runtime/', outDir: 'dist/runtime', format: 'esm' },
{ input: 'src/runtime/', outDir: 'dist/runtime', format: 'cjs', declaration: false }
],
dependencies: [
'@cloudflare/kv-asset-handler',
@ -20,4 +21,4 @@ export default <BuildConfig>{
'@vue/server-renderer',
'vue'
]
}
})

View File

@ -17,7 +17,6 @@
"@netlify/functions": "^0.7.0",
"@nuxt/devalue": "^1.2.5",
"@nuxt/kit": "^0.5.0",
"@nuxt/un": "^0.1.1",
"@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-inject": "^4.0.2",
@ -62,6 +61,7 @@
"std-env": "^2.3.0",
"table": "^6.3.0",
"ufo": "^0.6.11",
"unenv": "^0.2.1",
"unstorage": "^0.1.5",
"upath": "^2.0.1",
"vue": "3.0.11",
@ -74,6 +74,6 @@
"@types/http-proxy": "^1.17.5",
"@types/node-fetch": "^2.5.10",
"@types/serve-static": "^1.13.9",
"unbuild": "^0.1.13"
"unbuild": "^0.2.2"
}
}

View File

@ -2,7 +2,7 @@ import { resolve, dirname } from 'upath'
import defu from 'defu'
import type { NuxtOptions } from '@nuxt/kit'
import Hookable, { configHooksT } from 'hookable'
import type { Preset } from '@nuxt/un'
import type { Preset } from 'unenv'
import { tryImport, resolvePath, detectTarget, extendPreset } from './utils'
import * as PRESETS from './presets'
import type { NodeExternalsOptions } from './rollup/plugins/externals'

View File

@ -10,8 +10,8 @@ import replace from '@rollup/plugin-replace'
import virtual from '@rollup/plugin-virtual'
import inject from '@rollup/plugin-inject'
import analyze from 'rollup-plugin-analyzer'
import type { Preset } from '@nuxt/un'
import * as un from '@nuxt/un'
import type { Preset } from 'unenv'
import * as unenv from 'unenv'
import { NitroContext } from '../context'
import { resolvePath, MODULE_DIR } from '../utils'
@ -32,31 +32,31 @@ export type RollupConfig = InputOptions & { output: OutputOptions }
export const getRollupConfig = (nitroContext: NitroContext) => {
const extensions: string[] = ['.ts', '.mjs', '.js', '.json', '.node']
const nodePreset = nitroContext.node === false ? un.nodeless : un.node
const nodePreset = nitroContext.node === false ? unenv.nodeless : unenv.node
const builtinPreset: Preset = {
alias: {
// General
debug: 'un/npm/debug',
depd: 'un/npm/depd',
consola: 'un/npm/consola',
debug: 'unenv/runtime/npm/debug',
depd: 'unenv/runtime/npm/depd',
consola: 'unenv/runtime/npm/consola',
// Vue 2
encoding: 'un/mock/proxy',
he: 'un/mock/proxy',
resolve: 'un/mock/proxy',
'source-map': 'un/mock/proxy',
'lodash.template': 'un/mock/proxy',
'serialize-javascript': 'un/mock/proxy',
encoding: 'unenv/runtime/mock/proxy',
he: 'unenv/runtime/mock/proxy',
resolve: 'unenv/runtime/mock/proxy',
'source-map': 'unenv/runtime/mock/proxy',
'lodash.template': 'unenv/runtime/mock/proxy',
'serialize-javascript': 'unenv/runtime/mock/proxy',
// Vue 3
'estree-walker': 'un/mock/proxy',
'@babel/parser': 'un/mock/proxy',
'@vue/compiler-core': 'un/mock/proxy',
'@vue/compiler-dom': 'un/mock/proxy',
'@vue/compiler-ssr': 'un/mock/proxy'
'estree-walker': 'unenv/runtime/mock/proxy',
'@babel/parser': 'unenv/runtime/mock/proxy',
'@vue/compiler-core': 'unenv/runtime/mock/proxy',
'@vue/compiler-dom': 'unenv/runtime/mock/proxy',
'@vue/compiler-ssr': 'unenv/runtime/mock/proxy'
}
}
const env = un.env(nodePreset, builtinPreset, nitroContext.env)
const env = unenv.env(nodePreset, builtinPreset, nitroContext.env)
delete env.alias['node-fetch'] // FIX ME

View File

@ -7,7 +7,7 @@ export function autoMock () {
if (src && !src.startsWith('.') && !src.includes('?') && !src.includes('.js')) {
consola.warn('Auto mock external ', src)
return {
id: require.resolve('@nuxt/un/runtime/mock/proxy')
id: require.resolve('unenv/runtime/mock/proxy')
}
}
return null

View File

@ -2,7 +2,7 @@ import '../app/config'
import { createApp, useBase } from 'h3'
import { createFetch } from 'ohmyfetch'
import destr from 'destr'
import { createCall, createFetch as createLocalFetch } from '@nuxt/un/runtime/fetch'
import { createCall, createFetch as createLocalFetch } from 'unenv/runtime/fetch'
import { timingMiddleware } from './timing'
import { handleError } from './error'
// @ts-ignore

View File

@ -1,6 +1,6 @@
import type { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'
export default <BuildConfig>{
export default defineBuildConfig({
declaration: false,
entries: [
'src/index'
@ -11,4 +11,4 @@ export default <BuildConfig>{
'@nuxt/webpack-builder',
'nuxt-cli'
]
}
})

View File

@ -40,6 +40,6 @@
"@types/fs-extra": "^9.0.11",
"@types/hash-sum": "^1.0.0",
"@types/lodash": "^4.14.168",
"unbuild": "^0.1.13"
"unbuild": "^0.2.2"
}
}

View File

@ -43,7 +43,7 @@ export function compileTemplates (templates: NuxtTemplate[], destDir: string) {
export async function scanTemplates (dir: string, data?: Record<string, any>) {
const templateFiles = (await globby(join(dir, '/**')))
return templateFiles.map(src => ({
return templateFiles.filter(src => !src.endsWith('.d.ts')).map(src => ({
src,
path: relative(dir, src),
data

View File

@ -1,6 +1,6 @@
import type { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'
export default <BuildConfig>{
export default defineBuildConfig({
declaration: false,
entries: [
'src/index'
@ -10,4 +10,4 @@ export default <BuildConfig>{
'@vue/compiler-sfc',
'vue'
]
}
})

View File

@ -11,7 +11,7 @@
"prepack": "unbuild"
},
"devDependencies": {
"unbuild": "^0.1.13"
"unbuild": "^0.2.2"
},
"dependencies": {
"@nuxt/kit": "^0.5.0",

View File

@ -72,7 +72,7 @@ async function buildClient (ctx: ViteBuildContext) {
outDir: 'dist/client',
assetsDir: '.',
rollupOptions: {
input: resolve(ctx.nuxt.options.buildDir, './entry.client.js')
input: resolve(ctx.nuxt.options.buildDir, './entry.client')
}
},
server: {
@ -106,7 +106,7 @@ async function buildServer (ctx: ViteBuildContext) {
outDir: 'dist/server',
ssr: true,
rollupOptions: {
input: resolve(ctx.nuxt.options.buildDir, './entry.server.js'),
input: resolve(ctx.nuxt.options.buildDir, './entry.server'),
onwarn (warning, rollupWarn) {
if (!['UNUSED_EXTERNAL_IMPORT'].includes(warning.code)) {
rollupWarn(warning)
@ -119,7 +119,7 @@ async function buildServer (ctx: ViteBuildContext) {
const serverDist = resolve(ctx.nuxt.options.buildDir, 'dist/server')
await mkdirp(serverDist)
await writeFile(resolve(serverDist, 'client.manifest.json'), 'false')
await writeFile(resolve(serverDist, 'server.js'), 'const entry = require("./entry.server.js"); module.exports = entry.default || entry;')
await writeFile(resolve(serverDist, 'server.js'), 'const entry = require("./entry.server"); module.exports = entry.default || entry;')
await vite.build(serverConfig)

View File

@ -1,6 +1,6 @@
import type { BuildConfig } from 'unbuild'
import { defineBuildConfig } from 'unbuild'
export default <BuildConfig>{
export default defineBuildConfig({
declaration: false,
entries: [
'src/index'
@ -22,4 +22,4 @@ export default <BuildConfig>{
'@babel/core',
'vue'
]
}
})

View File

@ -51,6 +51,6 @@
"@types/webpack-bundle-analyzer": "^4.4.0",
"@types/webpack-dev-middleware": "^4.1.2",
"@types/webpack-hot-middleware": "^2.25.4",
"unbuild": "^0.1.13"
"unbuild": "^0.2.2"
}
}

View File

@ -21,6 +21,9 @@ export function babel (ctx: WebpackConfigContext) {
// item in transpile can be string or regex object
return !ctx.transpile.some(module => module.test(file))
},
resolve: {
fullySpecified: false
},
use: babelLoader
})

View File

@ -127,6 +127,7 @@ function baseResolve (ctx: WebpackConfigContext) {
extensions: ['.wasm', '.mjs', '.js', '.ts', '.json', '.vue', '.jsx', '.tsx'],
alias: ctx.alias,
modules: webpackModulesDir,
fullySpecified: false,
...config.resolve
}

View File

@ -13,7 +13,7 @@ export function esbuild (ctx: WebpackConfigContext) {
config.module.rules.push(
{
test: /\.[jt]sx?$/,
test: /\.m?[jt]sx?$/i,
loader: 'esbuild-loader',
exclude: (file) => {
file = file.split('node_modules', 2)[1]
@ -26,6 +26,9 @@ export function esbuild (ctx: WebpackConfigContext) {
// Item in transpile can be string or regex object
return !ctx.transpile.some(module => module.test(file))
},
resolve: {
fullySpecified: false
},
options: {
loader: 'ts',
target

View File

@ -1671,7 +1671,7 @@ __metadata:
"@vueuse/head": ^0.5.1
hookable: ^4.4.1
ohmyfetch: ^0.2.0
unbuild: ^0.1.13
unbuild: ^0.2.2
vue: ^3.0.11
vue-router: ^4.0.6
vuex5: ^0.5.0-testing.3
@ -1715,7 +1715,7 @@ __metadata:
scule: ^0.1.1
std-env: ^2.3.0
ufo: ^0.6.11
unbuild: ^0.1.13
unbuild: ^0.2.2
unctx: ^0.0.3
untyped: ^0.2.5
upath: ^2.0.1
@ -1730,7 +1730,6 @@ __metadata:
"@netlify/functions": ^0.7.0
"@nuxt/devalue": ^1.2.5
"@nuxt/kit": ^0.5.0
"@nuxt/un": ^0.1.1
"@rollup/plugin-alias": ^3.1.2
"@rollup/plugin-commonjs": ^18.0.0
"@rollup/plugin-inject": ^4.0.2
@ -1780,7 +1779,8 @@ __metadata:
std-env: ^2.3.0
table: ^6.3.0
ufo: ^0.6.11
unbuild: ^0.1.13
unbuild: ^0.2.2
unenv: ^0.2.1
unstorage: ^0.1.5
upath: ^2.0.1
vue: 3.0.11
@ -1789,23 +1789,6 @@ __metadata:
languageName: unknown
linkType: soft
"@nuxt/un@npm:^0.1.1":
version: 0.1.1
resolution: "@nuxt/un@npm:0.1.1"
dependencies:
buffer: ^6.0.2
defu: ^3.2.2
events: ^3.2.0
inherits: ^2.0.4
mime: ^2.4.6
node-fetch: ^2.6.1
process: ^0.11.10
upath: ^2.0.1
util: ^0.12.3
checksum: 484e6cac7a529f1f69990fa11468b087563148a71a2732024ce8e8c9a6a049d43ee46929a64b1b5cf98518cdae3c2ccf7beaa004803fe2e13f44f54b34425305
languageName: node
linkType: hard
"@nuxt/vite-builder@^0.3.0, @nuxt/vite-builder@workspace:packages/vite":
version: 0.0.0-use.local
resolution: "@nuxt/vite-builder@workspace:packages/vite"
@ -1815,7 +1798,7 @@ __metadata:
"@vue/compiler-sfc": ^3.0.11
consola: ^2.15.3
fs-extra: ^9.1.0
unbuild: ^0.1.13
unbuild: ^0.2.2
vite: ^2.2.1
vue: 3.0.11
languageName: unknown
@ -1854,7 +1837,7 @@ __metadata:
style-resources-loader: ^1.4.1
time-fix-plugin: ^2.0.7
ufo: ^0.6.11
unbuild: ^0.1.13
unbuild: ^0.2.2
url-loader: ^4.1.1
vue: 3.0.11
vue-loader: ^16.2.0
@ -10015,9 +9998,9 @@ __metadata:
languageName: node
linkType: hard
"mkdist@npm:^0.1.6":
version: 0.1.7
resolution: "mkdist@npm:0.1.7"
"mkdist@npm:^0.2.0":
version: 0.2.0
resolution: "mkdist@npm:0.2.0"
dependencies:
defu: ^3.2.2
esbuild: ^0.11.6
@ -10034,7 +10017,7 @@ __metadata:
optional: true
bin:
mkdist: dist/cli.js
checksum: 503703fbc27a18e123f16ae770645c22a11f0c1fe5149f7e8ebdd7744e07bacbc1439c3db83d6110d372c4599b3f13edd14fc2f7c8a3f185bf900d24174fa03d
checksum: 72d6cd3f28d531ea3d384b9e07bcc10de99b7f5ce9acb7a6d3d1834cd56b1948219b566ecf15b6c3e650a4ef4c65b3c4e66c3456d2098698cbc4b532335f6acc
languageName: node
linkType: hard
@ -10566,7 +10549,7 @@ __metadata:
fsevents: ~2.3.2
listhen: ^0.2.4
mri: ^1.1.6
unbuild: ^0.1.13
unbuild: ^0.2.2
v8-compile-cache: ^2.3.0
dependenciesMeta:
fsevents:
@ -10593,7 +10576,7 @@ __metadata:
lerna: ^4.0.0
ts-jest: ^26.5.5
typescript: ^4.2.4
unbuild: ^0.1.13
unbuild: ^0.2.2
languageName: unknown
linkType: soft
@ -10621,7 +10604,7 @@ __metadata:
nuxt-cli: ^0.3.0
scule: ^0.1.1
ufo: ^0.6.11
unbuild: ^0.1.13
unbuild: ^0.2.2
upath: ^2.0.1
bin:
nu: ./bin/nuxt.js
@ -14362,9 +14345,9 @@ typescript@^4.2.4:
languageName: node
linkType: hard
"unbuild@npm:^0.1.13":
version: 0.1.13
resolution: "unbuild@npm:0.1.13"
"unbuild@npm:^0.2.2":
version: 0.2.2
resolution: "unbuild@npm:0.2.2"
dependencies:
"@rollup/plugin-alias": ^3.1.2
"@rollup/plugin-commonjs": ^18.0.0
@ -14376,7 +14359,7 @@ typescript@^4.2.4:
esbuild: ^0.11.6
jiti: ^1.9.1
mkdirp: ^1.0.4
mkdist: ^0.1.6
mkdist: ^0.2.0
mri: ^1.1.6
pretty-bytes: ^5.6.0
rimraf: ^3.0.2
@ -14389,7 +14372,7 @@ typescript@^4.2.4:
upath: ^2.0.1
bin:
unbuild: bin/unbuild.js
checksum: fcbd7918214bbeeede7c39e7358835ca1a09f0a364d1ba37991108ff1c48266d1916f03f9e35e5997e0d888444fc7c609263c524a9c9a2c39cb9ab4777e1fb60
checksum: 9f1e842aaf43bd6a29d9eeb158d647fd118ac466e3c82c6ae04547661fac087ff43f2abb03e13647a030f963ed9e942a3bf05fb674aa6900a43c4a5d61071985
languageName: node
linkType: hard
@ -14400,6 +14383,23 @@ typescript@^4.2.4:
languageName: node
linkType: hard
"unenv@npm:^0.2.1":
version: 0.2.1
resolution: "unenv@npm:0.2.1"
dependencies:
buffer: ^6.0.2
defu: ^3.2.2
events: ^3.2.0
inherits: ^2.0.4
mime: ^2.4.6
node-fetch: ^2.6.1
process: ^0.11.10
upath: ^2.0.1
util: ^0.12.3
checksum: 29e0840cdf55070160f3172db023cf7641ac6dfd74c990f0279dfe8db717d34cadaea9e897cb6ec4a2c87a9a521df8c63bfa13df4a99f3c8de7cc801ab52882a
languageName: node
linkType: hard
"unified@npm:^9.1.0, unified@npm:^9.2.1":
version: 9.2.1
resolution: "unified@npm:9.2.1"