From 636d1e38bb7a6b864c123bace33ad16469669f49 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 28 Mar 2021 23:12:16 +0200 Subject: [PATCH] refactor: flatten nuxt3 src some packages yet to be externalized --- packages/nuxt3/src/{builder => }/app.ts | 0 packages/nuxt3/src/{builder => }/builder.ts | 12 ++++++++++-- packages/nuxt3/src/builder/index.ts | 12 ------------ packages/nuxt3/src/core/index.ts | 4 ---- packages/nuxt3/src/core/load.ts | 17 ----------------- packages/nuxt3/src/{builder => }/ignore.ts | 0 packages/nuxt3/src/index.ts | 3 +-- packages/nuxt3/src/{core => }/module.ts | 1 - packages/nuxt3/src/{core => }/nitro.ts | 0 packages/nuxt3/src/{core => }/nuxt.ts | 19 ++++++++++++++++--- packages/nuxt3/src/{builder => }/nxt.ts | 0 packages/nuxt3/src/{builder => }/pages.ts | 0 packages/nuxt3/src/{builder => }/plugins.ts | 0 packages/nuxt3/src/{core => }/resolver.ts | 2 +- packages/nuxt3/src/{builder => }/template.ts | 0 packages/nuxt3/src/{builder => }/utils.ts | 0 packages/nuxt3/src/{builder => }/vite/vite.ts | 0 packages/nuxt3/src/{builder => }/watch.ts | 0 .../{builder => }/webpack/configs/client.ts | 0 .../{builder => }/webpack/configs/index.ts | 0 .../{builder => }/webpack/configs/server.ts | 0 .../webpack/plugins/externals.ts | 0 .../webpack/plugins/vue/client.ts | 0 .../webpack/plugins/vue/server.ts | 0 .../{builder => }/webpack/plugins/vue/util.ts | 0 .../webpack/plugins/warning-ignore.ts | 0 .../{builder => }/webpack/presets/assets.ts | 0 .../{builder => }/webpack/presets/babel.ts | 0 .../src/{builder => }/webpack/presets/base.ts | 0 .../{builder => }/webpack/presets/esbuild.ts | 0 .../src/{builder => }/webpack/presets/node.ts | 0 .../src/{builder => }/webpack/presets/nuxt.ts | 0 .../src/{builder => }/webpack/presets/pug.ts | 0 .../{builder => }/webpack/presets/style.ts | 0 .../src/{builder => }/webpack/presets/vue.ts | 0 .../src/{builder => }/webpack/utils/config.ts | 0 .../src/{builder => }/webpack/utils/index.ts | 0 .../src/{builder => }/webpack/utils/mfs.ts | 0 .../{builder => }/webpack/utils/postcss.ts | 0 .../webpack/utils/reserved-tags.ts | 0 .../src/{builder => }/webpack/webpack.ts | 0 41 files changed, 28 insertions(+), 42 deletions(-) rename packages/nuxt3/src/{builder => }/app.ts (100%) rename packages/nuxt3/src/{builder => }/builder.ts (93%) delete mode 100644 packages/nuxt3/src/builder/index.ts delete mode 100644 packages/nuxt3/src/core/index.ts delete mode 100644 packages/nuxt3/src/core/load.ts rename packages/nuxt3/src/{builder => }/ignore.ts (100%) rename packages/nuxt3/src/{core => }/module.ts (99%) rename packages/nuxt3/src/{core => }/nitro.ts (100%) rename packages/nuxt3/src/{core => }/nuxt.ts (81%) rename packages/nuxt3/src/{builder => }/nxt.ts (100%) rename packages/nuxt3/src/{builder => }/pages.ts (100%) rename packages/nuxt3/src/{builder => }/plugins.ts (100%) rename packages/nuxt3/src/{core => }/resolver.ts (99%) rename packages/nuxt3/src/{builder => }/template.ts (100%) rename packages/nuxt3/src/{builder => }/utils.ts (100%) rename packages/nuxt3/src/{builder => }/vite/vite.ts (100%) rename packages/nuxt3/src/{builder => }/watch.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/configs/client.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/configs/index.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/configs/server.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/plugins/externals.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/plugins/vue/client.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/plugins/vue/server.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/plugins/vue/util.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/plugins/warning-ignore.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/presets/assets.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/presets/babel.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/presets/base.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/presets/esbuild.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/presets/node.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/presets/nuxt.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/presets/pug.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/presets/style.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/presets/vue.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/utils/config.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/utils/index.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/utils/mfs.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/utils/postcss.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/utils/reserved-tags.ts (100%) rename packages/nuxt3/src/{builder => }/webpack/webpack.ts (100%) diff --git a/packages/nuxt3/src/builder/app.ts b/packages/nuxt3/src/app.ts similarity index 100% rename from packages/nuxt3/src/builder/app.ts rename to packages/nuxt3/src/app.ts diff --git a/packages/nuxt3/src/builder/builder.ts b/packages/nuxt3/src/builder.ts similarity index 93% rename from packages/nuxt3/src/builder/builder.ts rename to packages/nuxt3/src/builder.ts index e44ed8af96..13852c3c6d 100644 --- a/packages/nuxt3/src/builder/builder.ts +++ b/packages/nuxt3/src/builder.ts @@ -32,7 +32,7 @@ export class Builder { } build () { - return build(this) + return _build(this) } close () { @@ -41,7 +41,7 @@ export class Builder { } // Extends VueRouter -async function build (builder: Builder) { +async function _build (builder: Builder) { const { nuxt } = builder await fsExtra.emptyDir(nuxt.options.buildDir) @@ -107,3 +107,11 @@ async function bundle ({ nuxt }: Builder) { .then(p => p.bundle) return bundle(nuxt) } + +export function getBuilder (nuxt: Nuxt) { + return new Builder(nuxt) +} + +export function build (nuxt: Nuxt) { + return getBuilder(nuxt).build() +} diff --git a/packages/nuxt3/src/builder/index.ts b/packages/nuxt3/src/builder/index.ts deleted file mode 100644 index 3e66af7be8..0000000000 --- a/packages/nuxt3/src/builder/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { Nuxt } from '../core' -import { Builder } from './builder' - -export { Builder } from './builder' - -export function getBuilder (nuxt: Nuxt) { - return new Builder(nuxt) -} - -export function build (nuxt: Nuxt) { - return getBuilder(nuxt).build() -} diff --git a/packages/nuxt3/src/core/index.ts b/packages/nuxt3/src/core/index.ts deleted file mode 100644 index acdb747ab0..0000000000 --- a/packages/nuxt3/src/core/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { default as Module } from './module' -export { default as Nuxt } from './nuxt' -export { default as Resolver } from './resolver' -export { loadNuxt } from './load' diff --git a/packages/nuxt3/src/core/load.ts b/packages/nuxt3/src/core/load.ts deleted file mode 100644 index 6584be162e..0000000000 --- a/packages/nuxt3/src/core/load.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { dirname } from 'path' -import { loadNuxtConfig } from '@nuxt/kit' -import Nuxt from './nuxt' -export interface LoadNuxtOptions { -} - -export async function loadNuxt (opts: LoadNuxtOptions) { - const options = await loadNuxtConfig(opts) - - // Temp - options.appDir = dirname(require.resolve('@nuxt/app')) - options._majorVersion = 3 - - const nuxt = new Nuxt(options) - await nuxt.ready() - return nuxt -} diff --git a/packages/nuxt3/src/builder/ignore.ts b/packages/nuxt3/src/ignore.ts similarity index 100% rename from packages/nuxt3/src/builder/ignore.ts rename to packages/nuxt3/src/ignore.ts diff --git a/packages/nuxt3/src/index.ts b/packages/nuxt3/src/index.ts index a918a9a721..2d0382cf33 100644 --- a/packages/nuxt3/src/index.ts +++ b/packages/nuxt3/src/index.ts @@ -1,3 +1,2 @@ -export { loadNuxt } from './core' +export { Nuxt, loadNuxt } from './nuxt' export { build } from './builder' -export { main } from '../../nu/src' diff --git a/packages/nuxt3/src/core/module.ts b/packages/nuxt3/src/module.ts similarity index 99% rename from packages/nuxt3/src/core/module.ts rename to packages/nuxt3/src/module.ts index 6314c033c7..2c8278cf67 100644 --- a/packages/nuxt3/src/core/module.ts +++ b/packages/nuxt3/src/module.ts @@ -2,7 +2,6 @@ import path from 'path' import fs from 'fs' import hash from 'hash-sum' import consola from 'consola' - import { chainFn, sequence } from '@nuxt/kit' import Nuxt from './nuxt' diff --git a/packages/nuxt3/src/core/nitro.ts b/packages/nuxt3/src/nitro.ts similarity index 100% rename from packages/nuxt3/src/core/nitro.ts rename to packages/nuxt3/src/nitro.ts diff --git a/packages/nuxt3/src/core/nuxt.ts b/packages/nuxt3/src/nuxt.ts similarity index 81% rename from packages/nuxt3/src/core/nuxt.ts rename to packages/nuxt3/src/nuxt.ts index 205c7b243f..7203c930a8 100644 --- a/packages/nuxt3/src/core/nuxt.ts +++ b/packages/nuxt3/src/nuxt.ts @@ -1,10 +1,11 @@ import type { IncomingHttpHeaders } from 'http' +import { dirname } from 'path' import isPlainObject from 'lodash/isPlainObject' import consola from 'consola' import Hookable from 'hookable' - -import { version } from '../../package.json' +import { loadNuxtConfig } from '@nuxt/kit' +import { version } from '../package.json' import ModuleContainer from './module' import Resolver from './resolver' @@ -18,7 +19,7 @@ declare global { } } -export default class Nuxt extends Hookable { +export class Nuxt extends Hookable { _ready?: Promise _initCalled?: boolean @@ -92,3 +93,15 @@ export default class Nuxt extends Hookable { } } } + +export async function loadNuxt (opts: LoadNuxtOptions) { + const options = await loadNuxtConfig(opts) + + // Temp + options.appDir = dirname(require.resolve('@nuxt/app')) + options._majorVersion = 3 + + const nuxt = new Nuxt(options) + await nuxt.ready() + return nuxt +} diff --git a/packages/nuxt3/src/builder/nxt.ts b/packages/nuxt3/src/nxt.ts similarity index 100% rename from packages/nuxt3/src/builder/nxt.ts rename to packages/nuxt3/src/nxt.ts diff --git a/packages/nuxt3/src/builder/pages.ts b/packages/nuxt3/src/pages.ts similarity index 100% rename from packages/nuxt3/src/builder/pages.ts rename to packages/nuxt3/src/pages.ts diff --git a/packages/nuxt3/src/builder/plugins.ts b/packages/nuxt3/src/plugins.ts similarity index 100% rename from packages/nuxt3/src/builder/plugins.ts rename to packages/nuxt3/src/plugins.ts diff --git a/packages/nuxt3/src/core/resolver.ts b/packages/nuxt3/src/resolver.ts similarity index 99% rename from packages/nuxt3/src/core/resolver.ts rename to packages/nuxt3/src/resolver.ts index a7888f9f18..28881915ba 100644 --- a/packages/nuxt3/src/core/resolver.ts +++ b/packages/nuxt3/src/resolver.ts @@ -8,7 +8,7 @@ import { isExternalDependency, clearRequireCache } from '@nuxt/kit' -import { Nuxt } from '../core' +import { Nuxt } from './nuxt' interface ResolvePathOptions { isAlias?: boolean diff --git a/packages/nuxt3/src/builder/template.ts b/packages/nuxt3/src/template.ts similarity index 100% rename from packages/nuxt3/src/builder/template.ts rename to packages/nuxt3/src/template.ts diff --git a/packages/nuxt3/src/builder/utils.ts b/packages/nuxt3/src/utils.ts similarity index 100% rename from packages/nuxt3/src/builder/utils.ts rename to packages/nuxt3/src/utils.ts diff --git a/packages/nuxt3/src/builder/vite/vite.ts b/packages/nuxt3/src/vite/vite.ts similarity index 100% rename from packages/nuxt3/src/builder/vite/vite.ts rename to packages/nuxt3/src/vite/vite.ts diff --git a/packages/nuxt3/src/builder/watch.ts b/packages/nuxt3/src/watch.ts similarity index 100% rename from packages/nuxt3/src/builder/watch.ts rename to packages/nuxt3/src/watch.ts diff --git a/packages/nuxt3/src/builder/webpack/configs/client.ts b/packages/nuxt3/src/webpack/configs/client.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/configs/client.ts rename to packages/nuxt3/src/webpack/configs/client.ts diff --git a/packages/nuxt3/src/builder/webpack/configs/index.ts b/packages/nuxt3/src/webpack/configs/index.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/configs/index.ts rename to packages/nuxt3/src/webpack/configs/index.ts diff --git a/packages/nuxt3/src/builder/webpack/configs/server.ts b/packages/nuxt3/src/webpack/configs/server.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/configs/server.ts rename to packages/nuxt3/src/webpack/configs/server.ts diff --git a/packages/nuxt3/src/builder/webpack/plugins/externals.ts b/packages/nuxt3/src/webpack/plugins/externals.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/plugins/externals.ts rename to packages/nuxt3/src/webpack/plugins/externals.ts diff --git a/packages/nuxt3/src/builder/webpack/plugins/vue/client.ts b/packages/nuxt3/src/webpack/plugins/vue/client.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/plugins/vue/client.ts rename to packages/nuxt3/src/webpack/plugins/vue/client.ts diff --git a/packages/nuxt3/src/builder/webpack/plugins/vue/server.ts b/packages/nuxt3/src/webpack/plugins/vue/server.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/plugins/vue/server.ts rename to packages/nuxt3/src/webpack/plugins/vue/server.ts diff --git a/packages/nuxt3/src/builder/webpack/plugins/vue/util.ts b/packages/nuxt3/src/webpack/plugins/vue/util.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/plugins/vue/util.ts rename to packages/nuxt3/src/webpack/plugins/vue/util.ts diff --git a/packages/nuxt3/src/builder/webpack/plugins/warning-ignore.ts b/packages/nuxt3/src/webpack/plugins/warning-ignore.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/plugins/warning-ignore.ts rename to packages/nuxt3/src/webpack/plugins/warning-ignore.ts diff --git a/packages/nuxt3/src/builder/webpack/presets/assets.ts b/packages/nuxt3/src/webpack/presets/assets.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/presets/assets.ts rename to packages/nuxt3/src/webpack/presets/assets.ts diff --git a/packages/nuxt3/src/builder/webpack/presets/babel.ts b/packages/nuxt3/src/webpack/presets/babel.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/presets/babel.ts rename to packages/nuxt3/src/webpack/presets/babel.ts diff --git a/packages/nuxt3/src/builder/webpack/presets/base.ts b/packages/nuxt3/src/webpack/presets/base.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/presets/base.ts rename to packages/nuxt3/src/webpack/presets/base.ts diff --git a/packages/nuxt3/src/builder/webpack/presets/esbuild.ts b/packages/nuxt3/src/webpack/presets/esbuild.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/presets/esbuild.ts rename to packages/nuxt3/src/webpack/presets/esbuild.ts diff --git a/packages/nuxt3/src/builder/webpack/presets/node.ts b/packages/nuxt3/src/webpack/presets/node.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/presets/node.ts rename to packages/nuxt3/src/webpack/presets/node.ts diff --git a/packages/nuxt3/src/builder/webpack/presets/nuxt.ts b/packages/nuxt3/src/webpack/presets/nuxt.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/presets/nuxt.ts rename to packages/nuxt3/src/webpack/presets/nuxt.ts diff --git a/packages/nuxt3/src/builder/webpack/presets/pug.ts b/packages/nuxt3/src/webpack/presets/pug.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/presets/pug.ts rename to packages/nuxt3/src/webpack/presets/pug.ts diff --git a/packages/nuxt3/src/builder/webpack/presets/style.ts b/packages/nuxt3/src/webpack/presets/style.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/presets/style.ts rename to packages/nuxt3/src/webpack/presets/style.ts diff --git a/packages/nuxt3/src/builder/webpack/presets/vue.ts b/packages/nuxt3/src/webpack/presets/vue.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/presets/vue.ts rename to packages/nuxt3/src/webpack/presets/vue.ts diff --git a/packages/nuxt3/src/builder/webpack/utils/config.ts b/packages/nuxt3/src/webpack/utils/config.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/utils/config.ts rename to packages/nuxt3/src/webpack/utils/config.ts diff --git a/packages/nuxt3/src/builder/webpack/utils/index.ts b/packages/nuxt3/src/webpack/utils/index.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/utils/index.ts rename to packages/nuxt3/src/webpack/utils/index.ts diff --git a/packages/nuxt3/src/builder/webpack/utils/mfs.ts b/packages/nuxt3/src/webpack/utils/mfs.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/utils/mfs.ts rename to packages/nuxt3/src/webpack/utils/mfs.ts diff --git a/packages/nuxt3/src/builder/webpack/utils/postcss.ts b/packages/nuxt3/src/webpack/utils/postcss.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/utils/postcss.ts rename to packages/nuxt3/src/webpack/utils/postcss.ts diff --git a/packages/nuxt3/src/builder/webpack/utils/reserved-tags.ts b/packages/nuxt3/src/webpack/utils/reserved-tags.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/utils/reserved-tags.ts rename to packages/nuxt3/src/webpack/utils/reserved-tags.ts diff --git a/packages/nuxt3/src/builder/webpack/webpack.ts b/packages/nuxt3/src/webpack/webpack.ts similarity index 100% rename from packages/nuxt3/src/builder/webpack/webpack.ts rename to packages/nuxt3/src/webpack/webpack.ts