Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

feat(nuxt): add workspaceDir option and add it to modulesDir #7439

Merged
merged 5 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"ohmyfetch": "^0.4.18",
"pathe": "^0.3.7",
"perfect-debounce": "^0.1.3",
"pkg-types": "^0.3.5",
"scule": "^0.3.2",
"strip-literal": "^0.4.0",
"ufo": "^0.8.5",
Expand Down
1 change: 1 addition & 0 deletions packages/nuxt/src/core/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export async function initNitro (nuxt: Nuxt) {
const _nitroConfig = ((nuxt.options as any).nitro || {}) as NitroConfig
const nitroConfig: NitroConfig = defu(_nitroConfig, <NitroConfig>{
rootDir: nuxt.options.rootDir,
workspaceDir: nuxt.options.workspaceDir,
srcDir: join(nuxt.options.srcDir, 'server'),
dev: nuxt.options.dev,
preset: nuxt.options.dev ? 'nitro-dev' : undefined,
Expand Down
3 changes: 3 additions & 0 deletions packages/nuxt/src/core/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { loadNuxtConfig, LoadNuxtOptions, nuxtCtx, installModule, addComponent,
import escapeRE from 'escape-string-regexp'
import fse from 'fs-extra'
import { withoutLeadingSlash } from 'ufo'
import { findWorkspaceDir } from 'pkg-types'
import pagesModule from '../pages/module'
import metaModule from '../head/module'
import componentsModule from '../components/module'
Expand Down Expand Up @@ -204,6 +205,8 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
.map(i => new RegExp(`(^|\\/)${escapeRE(i.cwd!.split('node_modules/').pop()!)}(\\/|$)(?!node_modules\\/)`))
}
}])
options.workspaceDir = options.workspaceDir || await findWorkspaceDir(options.rootDir)
options.modulesDir.push(resolve(options.workspaceDir, 'node_modules'))
options.modulesDir.push(resolve(pkgDir, 'node_modules'))
options.build.transpile.push('@nuxt/ui-templates')
options.alias['vue-demi'] = resolve(options.appDir, 'compat/vue-demi')
Expand Down
15 changes: 14 additions & 1 deletion packages/schema/src/config/_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default defineUntypedSchema({
theme: null,

/**
* Define the workspace directory of your application.
* Define the root directory of your application.
*
* This property can be overwritten (for example, running `nuxt ./my-app/`
* will set the `rootDir` to the absolute path of `./my-app/` from the
Expand All @@ -51,6 +51,19 @@ export default defineUntypedSchema({
$resolve: val => typeof val === 'string' ? resolve(val) : process.cwd()
},

/**
* Define the workspace directory of your application.
*
* Often this is used when in a monorepo setup. Nuxt will attempt to detect
* your workspace directory automatically, but you can override it here.
*
* It is normally not needed to configure this option.
* @version 3
*/
workspaceDir: {
$resolve: (val, get) => val ? resolve(get('rootDir'), val) : ''
danielroe marked this conversation as resolved.
Show resolved Hide resolved
},

/**
* Define the source directory of your Nuxt application.
*
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10259,6 +10259,7 @@ __metadata:
ohmyfetch: ^0.4.18
pathe: ^0.3.7
perfect-debounce: ^0.1.3
pkg-types: ^0.3.5
scule: ^0.3.2
strip-literal: ^0.4.0
ufo: ^0.8.5
Expand Down