chore: upgrade to monorepo

This commit is contained in:
Pooya Parsa 2021-03-18 15:26:41 +01:00
parent 8d6b97a4ac
commit a16e13b1de
44 changed files with 12028 additions and 98 deletions

12
.editorconfig Normal file
View File

@ -0,0 +1,12 @@
root = true
[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

3
.eslintignore Normal file
View File

@ -0,0 +1,3 @@
dist
node_modules
_templates

12
.eslintrc Normal file
View File

@ -0,0 +1,12 @@
{
"globals": {
"NodeJS": true
},
"extends": [
"@nuxtjs/eslint-config-typescript"
],
"rules": {
"no-console": "off",
"vue/one-component-per-file": "off"
}
}

54
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,54 @@
name: ci
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
ci:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node: [14]
steps:
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: checkout
uses: actions/checkout@master
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: yarn --frozen-lockfile --non-interactive
- name: Lint
run: yarn lint
- name: Build
run: yarn build
# - name: Test
# run: yarn jest
# - name: Coverage
# uses: codecov/codecov-action@v1

57
.gitignore vendored Normal file
View File

@ -0,0 +1,57 @@
# Dependencies
node_modules
jspm_packages
# Only keep yarn.lock in the root
package-lock.json
*/**/yarn.lock
# Logs
*.log
# Temp directories
.temp
.tmp
.cache
# Generated dirs
dist
.nuxt*
.output
# Junit reports
reports
# Coverage reports
coverage
*.lcov
.nyc_output
# VSCode
.vscode
# Intellij idea
*.iml
.idea
# OSX
.DS_Store
.AppleDouble
.LSOverride
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
CHANGELOG.md

7
README.md Normal file
View File

@ -0,0 +1,7 @@
# Nuxt Monorepo
## Development
- Clone repository
- Install dependencies with `yarn install`
- Open playground with `yarn play`

24
lerna.json Normal file
View File

@ -0,0 +1,24 @@
{
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true,
"conventionalCommits": true,
"packages": [
"packages/*"
],
"command": {
"publish": {
"npmClient": "npm"
}
},
"changelog": {
"labels": {
"feat": "New Feature",
"fix": "Bug Fix",
"docs": "Documentation",
"types": "Types",
"perf": "Performance",
"refactor": "Refactor"
}
}
}

43
package.json Normal file
View File

@ -0,0 +1,43 @@
{
"name": "nuxt-framework",
"private": "true",
"license": "MIT",
"workspaces": [
"packages/*"
],
"scripts": {
"link": "lerna link",
"nuxt": "jiti ./scripts/nuxt",
"build": "yarn workspaces run build",
"stub": "yarn workspaces run stub",
"play": "yarn nuxt dev playground",
"lint": "eslint --ext .vue,.ts,.js .",
"test": "yarn lint",
"postinstall": "yarn stub"
},
"devDependencies": {
"@nuxtjs/eslint-config": "^6.0.0",
"@nuxtjs/eslint-config-typescript": "^6.0.0",
"@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-node-resolve": "^11.2.0",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.35",
"chalk": "^4.1.0",
"defu": "^3.2.2",
"esbuild": "^0.9.3",
"eslint": "^7.22.0",
"jest": "^26.6.3",
"jiti": "^1.6.4",
"lerna": "^4.0.0",
"mkdist": "^0.1.2",
"pretty-bytes": "^5.6.0",
"rimraf": "^3.0.2",
"rollup": "^2.41.5",
"rollup-plugin-dts": "^3.0.1",
"rollup-plugin-esbuild": "^3.0.2",
"standard-version": "^9.1.1",
"ts-jest": "^26.5.3",
"typescript": "^4.2.3"
}
}

View File

@ -0,0 +1,84 @@
{
"name": "@nuxt/nitro",
"version": "0.1.11",
"license": "MIT",
"main": "dist/index.js",
"files": [
"dist",
"compat.js"
],
"scripts": {
"build": "jiti ../../scripts/build .",
"stub": "yarn build --stub",
"prepublishOnly": "yarn build"
},
"build": {
"entries": {
"index": {},
"compat": { "format": "cjs" },
"runtime/": {}
},
"dependencies": [
"@cloudflare/kv-asset-handler",
"@nuxt/devalue",
"connect",
"destr",
"ohmyfetch",
"ora",
"vue-bundle-renderer",
"vue-server-renderer",
"@vue/server-renderer"
]
},
"dependencies": {
"@cloudflare/kv-asset-handler": "^0.1.0",
"@nuxt/devalue": "^1.2.5",
"@nuxt/un": "^0.1.1",
"@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-inject": "^4.0.2",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.2.0",
"@rollup/plugin-replace": "^2.4.1",
"@rollup/plugin-virtual": "^2.0.3",
"@rollup/pluginutils": "^4.1.0",
"@vercel/nft": "^0.9.5",
"@vue/server-renderer": "^3.0.7",
"archiver": "^5.2.0",
"chalk": "^4.1.0",
"chokidar": "^3.5.1",
"connect": "^3.7.0",
"consola": "^2.15.3",
"debounce": "^1.2.0",
"defu": "^3.2.2",
"destr": "^1.1.0",
"dot-prop": "^6.0.1",
"esbuild": "^0.9.3",
"etag": "^1.8.1",
"fs-extra": "^9.1.0",
"globby": "^11.0.2",
"gzip-size": "^6.0.0",
"h3": "^0.2.5",
"hasha": "^5.2.2",
"hookable": "^4.4.1",
"http-proxy": "^1.18.1",
"is-primitive": "^3.0.1",
"jiti": "^1.6.0",
"listhen": "^0.1.4",
"mime": "^2.5.2",
"node-fetch": "^2.6.1",
"ohmyfetch": "^0.1.8",
"ora": "^5.3.0",
"pretty-bytes": "^5.6.0",
"rollup": "^2.40.0",
"rollup-plugin-analyzer": "^4.0.0",
"rollup-plugin-terser": "^7.0.2",
"serve-placeholder": "^1.2.3",
"serve-static": "^1.14.1",
"std-env": "^2.3.0",
"table": "^6.0.7",
"upath": "^2.0.1",
"vue-bundle-renderer": "^0.2.3",
"vue-server-renderer": "^2.6.12"
}
}

View File

@ -2,7 +2,7 @@
import { extname, relative } from 'path'
import { Plugin, PluginContext } from 'rollup'
import { startService, Loader, Service, TransformResult } from 'esbuild'
import { Loader, TransformResult, transform } from 'esbuild'
import { createFilter, FilterPattern } from '@rollup/pluginutils'
const defaultLoaders: { [ext: string]: Loader } = {
@ -64,24 +64,9 @@ export function esbuild (options: Options = {}): Plugin {
options.exclude || EXCLUDE_REGEXP
)
let service: Service | undefined
const stopService = () => {
if (service) {
service.stop()
service = undefined
}
}
return {
name: 'esbuild',
async buildStart () {
if (!service) {
service = await startService()
}
},
async transform (code, id) {
if (!filter(id)) {
return null
@ -90,13 +75,13 @@ export function esbuild (options: Options = {}): Plugin {
const ext = extname(id)
const loader = loaders[ext]
if (!loader || !service) {
if (!loader) {
return null
}
target = options.target || 'node12'
const result = await service.transform(code, {
const result = await transform(code, {
loader,
target,
define: options.define,
@ -114,16 +99,9 @@ export function esbuild (options: Options = {}): Plugin {
)
},
buildEnd (error) {
// Stop the service early if there's error
if (error && !this.meta.watchMode) {
stopService()
}
},
async renderChunk (code) {
if (options.minify && service) {
const result = await service.transform(code, {
if (options.minify) {
const result = await transform(code, {
loader: 'js',
minify: true,
target
@ -136,12 +114,6 @@ export function esbuild (options: Options = {}): Plugin {
}
}
return null
},
generateBundle () {
if (!this.meta.watchMode) {
stopService()
}
}
}
}

View File

@ -3,6 +3,7 @@ import { $fetch } from 'ohmyfetch'
_global.process = _global.process || {};
// eslint-disable-next-line
(function () { const o = Date.now(); const t = () => Date.now() - o; _global.process.hrtime = _global.process.hrtime || ((o) => { const e = Math.floor(0.001 * (Date.now() - t())); const a = 0.001 * t(); let l = Math.floor(a) + e; let n = Math.floor(a % 1 * 1e9); return o && (l -= o[0], n -= o[1], n < 0 && (l--, n += 1e9)), [l, n] }) })()
global.$fetch = $fetch

124
packages/nuxt3/package.json Normal file
View File

@ -0,0 +1,124 @@
{
"name": "nuxt3",
"version": "0.1.0",
"repository": "nuxt/framework",
"license": "MIT",
"main": "./dist/index.js",
"files": [
"dist"
],
"scripts": {
"build": "jiti ../../scripts/build .",
"stub": "yarn build --stub",
"prepublishOnly": "yarn build"
},
"build": {
"entries": {
"index": {},
"app/": {}
},
"dependencies": [
"@vue/compiler-sfc",
"postcss",
"postcss-loader",
"postcss-import-resolver",
"@vue/babel-preset-jsx",
"@vueuse/head",
"babel-loader",
"vue-loader",
"chalk",
"core-js",
"css-loader",
"file-loader",
"style-resources-loader",
"url-loader",
"vue",
"vue-router",
"vuex5",
"vue-style-loader"
]
},
"dependencies": {
"@nuxt/friendly-errors-webpack-plugin": "^2.5.0",
"@nuxt/nitro": "^0.1.11",
"@vitejs/plugin-vue": "^1.1.5",
"@vue/babel-preset-jsx": "^1.2.4",
"@vue/compiler-sfc": "^3.0.7",
"@vueuse/head": "^0.5.1",
"babel-loader": "^8.2.2",
"chalk": "^4.1.0",
"chokidar": "^3.5.1",
"consola": "^2.15.3",
"core-js": "^3.9.1",
"create-require": "^1.1.1",
"css-loader": "^5.1.3",
"css-minimizer-webpack-plugin": "^1.3.0",
"defu": "^3.2.2",
"destr": "^1.1.0",
"dotenv": "^8.2.0",
"esbuild-loader": "^2.10.0",
"file-loader": "^6.2.0",
"fs-extra": "^9.1.0",
"glob": "^7.1.6",
"globby": "^11.0.2",
"hash-sum": "^2.0.0",
"hookable": "^4.4.1",
"ignore": "^5.1.8",
"jiti": "^1.6.4",
"lodash": "^4.17.21",
"memfs": "^3.2.0",
"mini-css-extract-plugin": "^1.3.9",
"pify": "^5.0.0",
"postcss": "^8.2.8",
"postcss-import-resolver": "^2.0.0",
"postcss-loader": "^5.2.0",
"rc9": "^1.2.0",
"scule": "^0.1.1",
"std-env": "3.0.0-alpha",
"style-resources-loader": "^1.4.1",
"time-fix-plugin": "^2.0.7",
"ufo": "^0.6.10",
"url-loader": "^4.1.1",
"vite": "^2.1.1",
"vue": "^3.0.7",
"vue-loader": "npm:@pi0/vue-loader@^16.1.2-patch.1",
"vue-router": "^4.0.5",
"vue-style-loader": "^4.1.3",
"vuex5": "0.5.0-testing.3",
"webpack": "^5.26.2",
"webpack-bundle-analyzer": "^4.4.0",
"webpack-dev-middleware": "^4.1.0",
"webpack-hot-middleware": "^2.25.0",
"webpackbar": "^5.0.0-3"
},
"devDependencies": {
"@types/autoprefixer": "^10.2.0",
"@types/compression": "^1.7.0",
"@types/etag": "^1.8.0",
"@types/exit": "^0.1.31",
"@types/file-loader": "^4.2.0",
"@types/fs-extra": "^9.0.8",
"@types/glob": "^7.1.3",
"@types/hash-sum": "^1.0.0",
"@types/html-minifier": "^4.0.0",
"@types/jest": "^26.0.20",
"@types/jsdom": "^16.2.7",
"@types/less": "^3.0.2",
"@types/lodash": "^4.14.168",
"@types/lru-cache": "^5.1.0",
"@types/minimist": "^1.2.1",
"@types/on-headers": "^1.0.0",
"@types/opener": "^1.4.0",
"@types/pify": "^5.0.0",
"@types/pug": "^2.0.4",
"@types/semver": "^7.3.4",
"@types/serialize-javascript": "^5.0.0",
"@types/serve-static": "^1.13.9",
"@types/server-destroy": "^1.0.1",
"@types/terser-webpack-plugin": "^5.0.2",
"@types/webpack-bundle-analyzer": "^3.9.1",
"@types/webpack-dev-middleware": "^4.1.0",
"@types/webpack-hot-middleware": "^2.25.3",
"@types/wrap-ansi": "^3.0.0"
}
}

View File

@ -29,7 +29,9 @@
stroke-linecap="round"
stroke-linejoin="round"
><path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z" /><path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z" /></svg>
<div class="ml-4 text-lg leading-7 font-semibold"><a href="https://nuxtjs.com" class="hover:underline text-gray-900 dark:text-white">Documentation</a></div>
<div class="ml-4 text-lg leading-7 font-semibold">
<a href="https://nuxtjs.com" class="hover:underline text-gray-900 dark:text-white">Documentation</a>
</div>
</div>
<div class="ml-10">
<div class="mt-2 text-gray-600 dark:text-gray-400 text-sm">
@ -51,7 +53,9 @@
stroke-linecap="round"
stroke-linejoin="round"
><path d="M23 3a10.9 10.9 0 0 1-3.14 1.53 4.48 4.48 0 0 0-7.86 3v1A10.66 10.66 0 0 1 3 4s-4 9 5 13a11.64 11.64 0 0 1-7 2c9 5 20 0 20-11.5a4.5 4.5 0 0 0-.08-.83A7.72 7.72 0 0 0 23 3z" /></svg>
<div class="ml-4 text-lg leading-7 font-semibold"><a href="https://twitter.com/nuxt_js" class="hover:underline text-gray-900 dark:text-white">Twitter</a></div>
<div class="ml-4 text-lg leading-7 font-semibold">
<a href="https://twitter.com/nuxt_js" class="hover:underline text-gray-900 dark:text-white">Twitter</a>
</div>
</div>
<div class="ml-10">
<div class="mt-2 text-gray-600 dark:text-gray-400 text-sm">

View File

@ -1,4 +1,4 @@
import type { Nuxt } from 'src/core'
import type { Nuxt } from '../core'
import { Builder } from './builder'
export { Builder } from './builder'

View File

@ -12,6 +12,24 @@ export interface NuxtRoute {
children: NuxtRoute[]
}
// TODO: should be const
enum SegmentParserState {
initial,
static,
dynamic,
}
// TODO: should be const
enum SegmentTokenType {
static,
dynamic,
}
interface SegmentToken {
type: SegmentTokenType
value: string
}
export async function resolvePagesRoutes (builder: Builder, app: NuxtApp) {
const pagesDir = resolve(app.dir, app.pages!.dir)
const pagesPattern = `${app.pages!.dir}/**/*.{${app.extensions.join(',')}}`
@ -87,24 +105,6 @@ function getRoutePath (tokens: SegmentToken[]): string {
}, '/')
}
// TODO: should be const
enum SegmentParserState {
initial,
static,
dynamic,
}
// TODO: should be const
enum SegmentTokenType {
static,
dynamic,
}
interface SegmentToken {
type: SegmentTokenType
value: string
}
const PARAM_CHAR_RE = /[\w\d_]/
function parseSegment (segment: string) {

View File

@ -1,5 +1,5 @@
import { resolve } from 'path'
import { Nuxt } from 'src/core'
import { Nuxt } from 'sr..c/core'
import { mkdirp, writeFile } from 'fs-extra'
import vue from '@vitejs/plugin-vue'
import consola from 'consola'

View File

@ -4,8 +4,8 @@ import WebpackBar from 'webpackbar'
import consola from 'consola'
import { DefinePlugin, Configuration } from 'webpack'
import FriendlyErrorsWebpackPlugin from '@nuxt/friendly-errors-webpack-plugin'
import { isUrl, urlJoin, TARGETS } from 'src/utils'
import escapeRegExp from 'lodash/escapeRegExp'
import { isUrl, urlJoin, TARGETS } from '../../../utils'
import WarningIgnorePlugin from '../plugins/warning-ignore'
import { WebpackConfigContext, applyPresets, fileName } from '../utils/config'

View File

@ -1,4 +1,4 @@
import { ESBuildPlugin, ESBuildMinifyPlugin } from 'esbuild-loader'
import { ESBuildMinifyPlugin } from 'esbuild-loader'
import { WebpackConfigContext } from '../utils/config'
export function esbuild (ctx: WebpackConfigContext) {
@ -11,8 +11,6 @@ export function esbuild (ctx: WebpackConfigContext) {
config.optimization.minimizer.push(new ESBuildMinifyPlugin())
config.plugins.push(new ESBuildPlugin())
config.module.rules.push(
{
test: /\.[jt]sx?$/,

View File

@ -1,7 +1,7 @@
import path from 'path'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
import { wrapArray } from 'src/utils'
import { wrapArray } from '../../../utils'
import { fileName, WebpackConfigContext, applyPresets } from '../utils/config'
export function style (ctx: WebpackConfigContext) {

View File

@ -1,7 +1,7 @@
import consola from 'consola'
import cloneDeep from 'lodash/cloneDeep'
import { Configuration } from 'webpack'
import { Nuxt } from 'src/core'
import { Nuxt } from '../../../core'
export interface WebpackConfigContext extends ReturnType<typeof createWebpackConfigContext>{ }

View File

@ -6,9 +6,9 @@ import merge from 'lodash/merge'
import cloneDeep from 'lodash/cloneDeep'
import createResolver from 'postcss-import-resolver'
import type { Nuxt } from 'src/core'
import type { NormalizedConfiguration } from 'src/config'
import { isPureObject } from 'src/utils'
import type { Nuxt } from '../../../core'
import type { NormalizedConfiguration } from '../../../config'
import { isPureObject } from '../../../utils'
export const orderPresets = {
cssnanoLast (names) {

View File

@ -10,8 +10,8 @@ import type { Compiler, Watching } from 'webpack'
import type { Context as WebpackDevMiddlewareContext, Options as WebpackDevMiddlewareOptions } from 'webpack-dev-middleware'
import type { MiddlewareOptions as WebpackHotMiddlewareOptions } from 'webpack-hot-middleware'
import { Nuxt } from 'src/core'
import { TARGETS, parallel, sequence, wrapArray } from 'src/utils'
import { Nuxt } from '../../core'
import { TARGETS, parallel, sequence, wrapArray } from '../../utils'
import { createMFS } from './utils/mfs'
import { client, server } from './configs'
import { createWebpackConfigContext, applyPresets, getWebpackConfig } from './utils/config'
@ -138,7 +138,7 @@ class WebpackBundler {
// Client build
if (['client', 'modern'].includes(name)) {
return new Promise((resolve, reject) => {
compiler.hooks.done.tap('nuxt-dev', () => { resolve() })
compiler.hooks.done.tap('nuxt-dev', () => { resolve(null) })
compiler.hooks.failed.tap('nuxt-errorlog', (err) => { reject(err) })
// Start watch
this.webpackDev(compiler)
@ -151,7 +151,7 @@ class WebpackBundler {
if (err) {
return reject(err)
}
resolve()
resolve(null)
})
watching.closeAsync = pify(watching.close)
@ -181,6 +181,7 @@ class WebpackBundler {
const { name } = compiler.options
const buildOptions = this.nuxt.options.build
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { client, ...hotMiddlewareOptions } = buildOptions.hotMiddleware || {}
// Create webpack dev middleware

View File

@ -1,5 +1,6 @@
import { resolve } from 'path'
import { loadNuxt, build } from '.'
import { loadNuxt } from './core/load'
import { build } from './builder'
async function _main () {
const args = process.argv.splice(2)

View File

@ -1,14 +1,14 @@
import type { WatchOptions as ChokidarWatchOptions } from 'chokidar'
import type express from 'express'
import type { configHooksT } from 'hookable'
import { APP_DIR } from 'src/index'
import ignore from 'ignore'
import capitalize from 'lodash/capitalize'
import env from 'std-env'
import type { Configuration as WebpackConfiguration } from 'webpack'
import { TARGETS, MODES, Target, Mode } from 'src/utils'
import Hookable from 'hookable'
import { TARGETS, MODES, Target, Mode } from '../../utils'
import { APP_DIR } from '../../consts'
import type { NormalizedConfiguration } from '../options'
type IgnoreOptions = Parameters<typeof ignore>[0]

View File

@ -1,4 +1,4 @@
import { MODES } from 'src/utils'
import { MODES } from '../../utils'
export default () => ({
[MODES.universal]: {

View File

@ -3,14 +3,14 @@ import fs from 'fs'
import defu from 'defu'
import consola from 'consola'
import dotenv from 'dotenv'
import { clearRequireCache, scanRequireTree } from 'src/utils'
import jiti from 'jiti'
import _createRequire from 'create-require'
import destr from 'destr'
import * as rc from 'rc9'
import { clearRequireCache, scanRequireTree } from '../utils'
import { LoadOptions } from 'src/core/load'
import { CliConfiguration, Configuration } from 'src/config/options'
import { LoadOptions } from '../core/load'
import { CliConfiguration, Configuration } from '../config/options'
import { defaultNuxtConfigFile } from './config'
// @ts-ignore

View File

@ -6,8 +6,8 @@ import defaultsDeep from 'lodash/defaultsDeep'
import pick from 'lodash/pick'
import uniq from 'lodash/uniq'
import destr from 'destr'
import { TARGETS, MODES, guardDir, isNonEmptyString, isPureObject, isUrl, getMainModule, urlJoin, getPKG } from 'src/utils'
import type { EnvConfig } from 'src/config/load'
import { TARGETS, MODES, guardDir, isNonEmptyString, isPureObject, isUrl, getMainModule, urlJoin, getPKG } from '../utils'
import type { EnvConfig } from '../config/load'
import { DefaultConfiguration, defaultNuxtConfigFile, getDefaultNuxtConfig } from './config'
import { deleteProp, mergeConfigs, setProp, overrideProp, Optional } from './transformers'

View File

@ -22,6 +22,7 @@ export function deleteProp<O extends Record<string, any>, K extends string> (obj
type MergeArrays<S, T> = S extends Array<infer A1> ? T extends Array<infer A2> ? Array<A1 | A2> : T | Array<A1> : T | S
type MergeObjects<S extends Record<string, any>, T extends Record<string, any>> = Omit<S & T, keyof S & keyof T> & {
// eslint-disable-next-line no-use-before-define
-readonly [K in keyof S & keyof T]: Merge<S[K], T[K]>
}
type Merge<S, T> = S extends Array<any> ? MergeArrays<S, T> : S extends Function ? S | T : S extends RegExp ? S | T : S extends Promise<any> ? S | T : T extends Function ? S | T : S extends Record<string, any> ? T extends Record<string, any> ? MergeObjects<S, T> : S | T : MergeArrays<S, T>

View File

@ -0,0 +1,3 @@
import { resolve } from 'path'
export const APP_DIR = resolve(__dirname, 'app')

View File

@ -1,5 +1,5 @@
export { default as Module } from './module'
export { default as Nuxt } from './nuxt'
export { default as Resolver } from './resolver'
export { loadNuxtConfig } from 'src/config'
export { loadNuxtConfig } from '../config'
export { loadNuxt } from './load'

View File

@ -1,4 +1,4 @@
import { EnvConfig } from 'src/config/load'
import { EnvConfig } from '../config/load'
import { loadNuxtConfig } from '../config'
import Nuxt from './nuxt'

View File

@ -3,10 +3,10 @@ import fs from 'fs'
import hash from 'hash-sum'
import consola from 'consola'
import type { NormalizedConfiguration } from 'src/config'
import { chainFn, sequence } from 'src/utils'
import type { NormalizedConfiguration } from '../config'
import { chainFn, sequence } from '../utils'
import type { NuxtModule, ModuleHandler } from 'src/config/config/_common'
import type { NuxtModule, ModuleHandler } from '../config/config/_common'
import Nuxt from './nuxt'
interface TemplateInput {

View File

@ -1,12 +1,5 @@
import {
wpfs,
getNitroContext,
createDevServer,
resolveMiddleware,
build,
prepare,
generate
} from '@nuxt/nitro'
// eslint-disable-next-line import/named
import { wpfs, getNitroContext, createDevServer, resolveMiddleware, build, prepare, generate } from '@nuxt/nitro'
import type { Nuxt } from './index'
export function initNitro (nuxt: Nuxt) {

View File

@ -4,7 +4,7 @@ import isPlainObject from 'lodash/isPlainObject'
import consola from 'consola'
import Hookable from 'hookable'
import { getNuxtConfig, Configuration, NormalizedConfiguration } from 'src/config'
import { getNuxtConfig, Configuration, NormalizedConfiguration } from '../config'
import { version } from '../../package.json'

View File

@ -1,14 +1,14 @@
import { resolve, join } from 'path'
import fs from 'fs-extra'
import { Nuxt } from 'src/core'
import jiti from 'jiti'
import { Nuxt } from '../core'
import {
startsWithRootAlias,
startsWithSrcAlias,
isExternalDependency,
clearRequireCache
} from 'src/utils'
} from '../utils'
interface ResolvePathOptions {
isAlias?: boolean

View File

@ -1,6 +1,3 @@
import { resolve } from 'path'
export const APP_DIR = resolve(__dirname, 'app')
export { loadNuxt } from './core'
export { build } from './builder'

5
playground/app.vue Normal file
View File

@ -0,0 +1,5 @@
<template>
<div>
<NuxtPage />
</div>
</template>

View File

@ -0,0 +1,3 @@
export default {
vite: true
}

View File

@ -0,0 +1,5 @@
<template>
<div>
Hello world
</div>
</template>

5
renovate.json Normal file
View File

@ -0,0 +1,5 @@
{
"extends": [
"@nuxtjs"
]
}

216
scripts/build.ts Normal file
View File

@ -0,0 +1,216 @@
import { promisify } from 'util'
import { resolve, relative, dirname } from 'path'
import Module from 'module'
import { writeFile, mkdir } from 'fs/promises'
import chalk from 'chalk'
import consola from 'consola'
import rimraf from 'rimraf'
import { RollupOptions, OutputOptions, OutputChunk, rollup } from 'rollup'
import commonjs from '@rollup/plugin-commonjs'
import nodeResolve from '@rollup/plugin-node-resolve'
import alias from '@rollup/plugin-alias'
import esbuild from 'rollup-plugin-esbuild'
import { mkdist } from 'mkdist'
import prettyBytes from 'pretty-bytes'
interface BuildEntry {
name: string
input: string
output: string
bundle: boolean
format: 'esm' | 'cjs'
}
interface BuildContext {
rootDir: string
entries: BuildEntry[]
externals: string[]
}
async function main () {
const args = process.argv.splice(2)
const ctx: BuildContext = {
rootDir: resolve(args.shift() || '.'),
entries: [],
externals: [...Module.builtinModules]
}
const pkg = require(resolve(ctx.rootDir, 'package.json'))
const buildOptions = pkg.build || {}
if (buildOptions.entries) {
if (!Array.isArray(buildOptions.entries)) {
buildOptions.entries = Object.entries(buildOptions.entries)
} ctx.entries.push(...buildOptions.entries.map(entry => resolveEntry(entry)))
}
if (pkg.dependencies) {
ctx.externals.push(...Object.keys(pkg.dependencies))
}
await promisify(rimraf)(resolve(ctx.rootDir, 'dist'))
if (args.includes('--stub')) {
const stubbed: string[] = []
for (const entry of ctx.entries) {
if (entry.bundle) {
const input = resolve(ctx.rootDir, entry.input)
stubbed.push(entry.output)
const output = resolve(ctx.rootDir, entry.output) + '.js'
await mkdir(dirname(output)).catch(() => { })
await writeFile(output, entry.format === 'cjs'
? `module.exports = require('jiti')()('${input}')`
: `export * from '${input}'`
)
}
}
consola.success(`Stub done: ${stubbed.join(', ')}`)
return
}
consola.info(`${chalk.cyan(`Builduing ${pkg.name}`)}
${chalk.bold('Root dir:')} ${ctx.rootDir}
${chalk.bold('Entries:')}
${ctx.entries.map(entry => ' ' + dumpObject(entry)).join('\n')}
`)
const rollupOptions = getRollupOptions(ctx)
const buildResult = await rollup(rollupOptions)
const outputOptions = rollupOptions.output as OutputOptions
const { output } = await buildResult.write(outputOptions)
const usedImports = new Set<string>()
const buildEntries: { path: string, bytes?: number, exports?: string[], chunks?: string[] }[] = []
for (const entry of output.filter(e => e.type === 'chunk') as OutputChunk[]) {
for (const id of entry.imports) {
usedImports.add(id)
}
if (entry.isEntry) {
buildEntries.push({
path: entry.fileName,
bytes: entry.code.length * 4,
exports: entry.exports
})
}
}
for (const entry of ctx.entries.filter(e => !e.bundle)) {
const { writtenFiles } = await mkdist({
rootDir: ctx.rootDir,
srcDir: entry.input,
distDir: entry.output,
format: entry.format
})
buildEntries.push({
path: entry.output,
bytes: 0,
chunks: writtenFiles.map(p => relative(resolve(ctx.rootDir, entry.output), p))
})
}
consola.success(`${chalk.green('Build succeed')}\n
${buildEntries.map(entry => `${chalk.bold(entry.path)}
size: ${chalk.cyan(entry.bytes ? prettyBytes(entry.bytes) : '-')}
exports: ${chalk.gray(entry.exports ? entry.exports.join(', ') : '-')}
chunks: ${chalk.gray(entry.chunks ? entry.chunks.join(', ') : '-')}`
).join('\n')}`)
const usedDependencies = new Set<string>()
const unusedDependencies = new Set<string>(Object.keys(pkg.dependencies))
const implicitDependnecies = new Set<string>()
for (const id of usedImports) {
unusedDependencies.delete(id)
usedDependencies.add(id)
}
if (Array.isArray(buildOptions.dependencies)) {
for (const id of buildOptions.dependencies) {
unusedDependencies.delete(id)
}
}
for (const id of usedDependencies) {
if (
!ctx.externals.includes(id) &&
!id.startsWith('chunks/') &&
!ctx.externals.includes(id.split('/')[0]) // lodash/get
) {
implicitDependnecies.add(id)
}
}
if (unusedDependencies.size) {
consola.warn('Potential unused dependencies found:', Array.from(unusedDependencies).map(id => chalk.cyan(id)).join(', '))
}
if (implicitDependnecies.size) {
consola.warn('Potential implicit dependencies found:', Array.from(implicitDependnecies).map(id => chalk.cyan(id)).join(', '))
}
}
function resolveEntry (input: string | [string, Partial<BuildEntry>] | Partial<BuildEntry>): BuildEntry {
let entry: Partial<BuildEntry>
if (typeof input === 'string') {
entry = { name: input }
}
if (Array.isArray(input)) {
entry = { name: input[0], ...input[1] }
}
entry.input = entry.input ?? `src/${entry.name}`
entry.output = entry.output ?? `dist/${entry.name}`
entry.bundle = entry.bundle ?? !entry.input.endsWith('/')
entry.format = entry.format ?? 'esm'
return entry as BuildEntry
}
function dumpObject (obj) {
return '{ ' + Object.keys(obj).map(key => `${key}: ${JSON.stringify(obj[key])}`).join(', ') + ' }'
}
function getRollupOptions (ctx: BuildContext): RollupOptions {
const extensions = ['.ts', '.mjs', '.js', '.json']
const r = (...path) => resolve(ctx.rootDir, ...path)
return <RollupOptions>{
input: ctx.entries.filter(e => e.bundle).map(e => e.input),
output: {
dir: r('dist'),
format: 'cjs',
chunkFileNames: 'chunks/[hash].js',
exports: 'auto',
preferConst: true
},
external (id) {
if (id[0] === '.' || id.includes('src/')) {
return false
}
return !!ctx.externals.find(ext => id.includes(ext))
},
plugins: [
alias({
entries: {
src: resolve(__dirname, 'src')
}
}),
nodeResolve({
extensions
}),
esbuild({
target: 'node12',
loaders: {
'.json': 'json'
}
}),
commonjs({
extensions
})
]
}
}
main().catch(consola.error)

1
scripts/nuxt.ts Executable file
View File

@ -0,0 +1 @@
require('nuxt3').main()

14
tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"esModuleInterop": true,
"target": "ESNext",
"moduleResolution": "Node",
"strict": false,
"allowJs": true,
"resolveJsonModule": true,
"types": [
"node",
"jest"
]
}
}

11290
yarn.lock Normal file

File diff suppressed because it is too large Load Diff