Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/nuxi/src/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { defineNuxtCommand } from './index'
export default defineNuxtCommand({
meta: {
name: 'prepare',
usage: 'npx nuxi prepare [--log-level] [rootDir]',
usage: 'npx nuxi prepare [--log-level] [--module] [rootDir]',
description: 'Prepare nuxt for development/build'
},
async invoke (args) {
Expand All @@ -20,7 +20,10 @@ export default defineNuxtCommand({
rootDir,
overrides: {
_prepare: true,
logLevel: args['log-level']
logLevel: args['log-level'],
experimental: {
moduleBuilderMode: 'module' in args
}
}
})
await clearBuildDir(nuxt.options.buildDir)
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/core/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function generateApp (nuxt: Nuxt, app: NuxtApp, options: { filter?:
nuxt.vfs[fullPath.replace(/\//g, '\\')] = contents
}

if (template.write) {
if (template.write || nuxt.options.experimental.moduleBuilderMode) {
await fsp.mkdir(dirname(fullPath), { recursive: true })
await fsp.writeFile(fullPath, contents, 'utf8')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/imports/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial<ImportsOptions
addTemplate({
filename: 'types/imports.d.ts',
getContents: async () => '// Generated by auto imports\n' + (
options.autoImport
options.autoImport && !nuxt.options.experimental.moduleBuilderMode
? await ctx.generateTypeDeclarations({ resolvePath: r })
: '// Implicit auto importing is disabled, you can use explicitly import from `#imports` instead.'
)
Expand Down
1 change: 1 addition & 0 deletions packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"dependencies": {
"defu": "^6.1.2",
"hookable": "^5.5.3",
"mlly": "^1.2.0",
"pathe": "^1.1.0",
"pkg-types": "^1.0.3",
"postcss-import-resolver": "^2.0.0",
Expand Down
14 changes: 12 additions & 2 deletions packages/schema/src/config/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineUntypedSchema } from 'untyped'
import { join, resolve } from 'pathe'
import { resolvePath } from 'mlly'
import { isDebug, isDevelopment } from 'std-env'
import { defu } from 'defu'
import { findWorkspaceDir } from 'pkg-types'
Expand Down Expand Up @@ -145,7 +146,7 @@ export default defineUntypedSchema({
* If a relative path is specified, it will be relative to your `rootDir`.
*/
analyzeDir: {
$resolve: async (val, get) => val
$resolve: async (val, get) => val
? resolve(await get('rootDir'), val)
: resolve(await get('buildDir'), 'analyze')
},
Expand Down Expand Up @@ -208,7 +209,16 @@ export default defineUntypedSchema({
* @type {(typeof import('../src/types/module').NuxtModule | string | [typeof import('../src/types/module').NuxtModule | string, Record<string, any>] | undefined | null | false)[]}
*/
modules: {
$resolve: val => [].concat(val).filter(Boolean)
$resolve: async (val, get) => {
const modules = ([] as string[]).concat(val)
if (await get('experimental.moduleBuilderMode')) {
const path = await resolvePath("./src/module", { url: await get('rootDir'), extensions: await get('extensions') }).catch(() => null)
if (path) {
modules.push(path)
}
}
return modules.filter(Boolean)
}
},

/**
Expand Down
7 changes: 7 additions & 0 deletions packages/schema/src/config/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ export default defineUntypedSchema({
/** Enable the new experimental typed router using [unplugin-vue-router](https://github.com/posva/unplugin-vue-router). */
typedPages: false,

/**
* Enable 'module builder' mode which sets up a number of features specifically for module authors.
*/
moduleBuilderMode: {
$resolve: async (val, get) => val ?? false
},

/**
* Set an alternative watcher that will be used as the watching service for Nuxt.
*
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.