Skip to content

Commit

Permalink
fix: add scanDirs to auto-import include (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Jun 12, 2022
1 parent f05d843 commit 3f8a08e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"destr": "^1.1.1",
"dot-prop": "^7.2.0",
"esbuild": "^0.14.43",
"escape-string-regexp": "^5.0.0",
"etag": "^1.8.1",
"fs-extra": "^10.1.0",
"globby": "^13.1.2",
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

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

10 changes: 10 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { loadConfig } from 'c12'
import { klona } from 'klona/full'
import { camelCase } from 'scule'
import defu from 'defu'
import escapeRE from 'escape-string-regexp'
import { withLeadingSlash, withoutTrailingSlash, withTrailingSlash } from 'ufo'
import { isTest } from 'std-env'
import { resolvePath as resovleModule } from 'mlly'
Expand Down Expand Up @@ -135,6 +136,15 @@ export async function loadOptions (userConfig: NitroConfig = {}): Promise<NitroO
options.scanDirs = [options.srcDir]
}

options.autoImport.include = [
...Array.isArray(options.autoImport.include)
? options.autoImport.include
: [options.autoImport.include].filter(Boolean),
...options.scanDirs
.filter(i => i.includes('node_modules'))
.map(i => new RegExp(`(^|\\/)${escapeRE(i.split('node_modules/').pop())}(\\/|$)(?!node_modules\\/)`))
]

options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL))
options.runtimeConfig = defu(options.runtimeConfig, {
app: {
Expand Down
5 changes: 3 additions & 2 deletions src/types/nitro.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-use-before-define */
import type { Preset as UnenvPreset } from 'unenv'
import type { Unimport, UnimportOptions } from 'unimport'
import type { Unimport } from 'unimport'
import type { UnimportPluginOptions } from 'unimport/unplugin'
import type { PluginVisualizerOptions } from 'rollup-plugin-visualizer'
import type { NestedHooks, Hookable } from 'hookable'
import type { Consola, LogLevel } from 'consola'
Expand Down Expand Up @@ -121,7 +122,7 @@ export interface NitroOptions {
}
serverAssets: ServerAssetDir[]
publicAssets: PublicAssetDir[]
autoImport: UnimportOptions
autoImport: UnimportPluginOptions
plugins: string[]
virtual: Record<string, string | (() => string | Promise<string>)>

Expand Down

0 comments on commit 3f8a08e

Please sign in to comment.