Skip to content

Commit

Permalink
feat: add workspaceDir
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Sep 7, 2022
1 parent c902104 commit 58e2d60
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { resolveModuleExportNames, resolvePath as resovleModule } from 'mlly'
// import escapeRE from 'escape-string-regexp'
import { withLeadingSlash, withoutTrailingSlash, withTrailingSlash } from 'ufo'
import { isTest } from 'std-env'
import { findWorkspaceDir } from 'pkg-types'
import { resolvePath, detectTarget } from './utils'
import type { NitroConfig, NitroOptions } from './types'
import { runtimeDir, pkgDir } from './dirs'
Expand Down Expand Up @@ -123,6 +124,7 @@ export async function loadOptions (userConfig: NitroConfig = {}): Promise<NitroO
options.preset = preset

options.rootDir = resolve(options.rootDir || '.')
options.workspaceDir = await findWorkspaceDir(options.rootDir)
options.srcDir = resolve(options.srcDir || options.rootDir)
for (const key of ['srcDir', 'publicDir', 'buildDir']) {
options[key] = resolve(options.rootDir, options[key])
Expand All @@ -146,6 +148,7 @@ export async function loadOptions (userConfig: NitroConfig = {}): Promise<NitroO
options.output.publicDir = resolvePath(options.output.publicDir, options)
options.output.serverDir = resolvePath(options.output.serverDir, options)

options.nodeModulesDirs.push(resolve(options.workspaceDir, 'node_modules'))
options.nodeModulesDirs.push(resolve(options.rootDir, 'node_modules'))
options.nodeModulesDirs.push(resolve(pkgDir, 'node_modules'))
options.nodeModulesDirs = Array.from(new Set(options.nodeModulesDirs))
Expand Down
8 changes: 4 additions & 4 deletions src/presets/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type { Nitro } from '../types'
export const netlify = defineNitroPreset({
extends: 'aws-lambda',
output: {
dir: '{{ rootDir }}/.netlify/functions-internal',
publicDir: '{{ rootDir }}/dist'
dir: '{{ workspaceDir }}/.netlify/functions-internal',
publicDir: '{{ workspaceDir }}/dist'
},
rollupConfig: {
output: {
Expand Down Expand Up @@ -59,8 +59,8 @@ export const netlifyEdge = defineNitroPreset({
extends: 'base-worker',
entry: '#internal/nitro/entries/netlify-edge',
output: {
serverDir: '{{ rootDir }}/.netlify/edge-functions',
publicDir: '{{ rootDir }}/dist'
serverDir: '{{ workspaceDir }}/.netlify/edge-functions',
publicDir: '{{ workspaceDir }}/dist'
},
rollupConfig: {
output: {
Expand Down
2 changes: 1 addition & 1 deletion src/presets/stormkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { defineNitroPreset } from '../preset'
export const stormkit = defineNitroPreset({
entry: '#internal/nitro/entries/stormkit',
output: {
dir: '{{ rootDir }}/.stormkit'
dir: '{{ workspaceDir }}/.stormkit'
}
})
4 changes: 2 additions & 2 deletions src/presets/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const vercel = defineNitroPreset({
extends: 'node',
entry: '#internal/nitro/entries/vercel',
output: {
dir: '{{ rootDir }}/.vercel/output',
dir: '{{ workspaceDir }}/.vercel/output',
serverDir: '{{ output.dir }}/functions/index.func',
publicDir: '{{ output.dir }}/static'
},
Expand Down Expand Up @@ -60,7 +60,7 @@ export const vercelEdge = defineNitroPreset({
extends: 'base-worker',
entry: '#internal/nitro/entries/vercel-edge',
output: {
dir: '{{ rootDir }}/.vercel/output',
dir: '{{ workspaceDir }}/.vercel/output',
serverDir: '{{ output.dir }}/functions/index.func',
publicDir: '{{ output.dir }}/static'
},
Expand Down
1 change: 1 addition & 0 deletions src/types/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export interface NitroOptions {
}

// Dirs
workspaceDir: string
rootDir: string
srcDir: string
scanDirs: string[]
Expand Down

0 comments on commit 58e2d60

Please sign in to comment.