Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update jsdoc for ignore-prefix to clarify ignored files #27065

Merged
merged 3 commits into from
May 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
133 changes: 95 additions & 38 deletions packages/schema/src/config/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default defineUntypedSchema({
* It is normally not needed to configure this option.
*/
rootDir: {
$resolve: val => typeof val === 'string' ? resolve(val) : process.cwd(),
$resolve: val => (typeof val === 'string' ? resolve(val) : process.cwd()),
},

/**
Expand All @@ -52,8 +52,10 @@ export default defineUntypedSchema({
*/
workspaceDir: {
$resolve: async (val: string | undefined, get): Promise<string> => {
const rootDir = await get('rootDir') as string
return val ? resolve(rootDir, val) : await findWorkspaceDir(rootDir).catch(() => rootDir)
const rootDir = (await get('rootDir')) as string
return val
? resolve(rootDir, val)
: await findWorkspaceDir(rootDir).catch(() => rootDir)
},
},

Expand Down Expand Up @@ -91,12 +93,14 @@ export default defineUntypedSchema({
srcDir: {
$resolve: async (val: string | undefined, get): Promise<string> => {
if (val) {
return resolve(await get('rootDir') as string, val)
return resolve((await get('rootDir')) as string, val)
}

const [rootDir, isV4] = await Promise.all([
get('rootDir') as Promise<string>,
(get('future') as Promise<Record<string, unknown>>).then(r => r.compatibilityVersion === 4),
(get('future') as Promise<Record<string, unknown>>).then(
r => r.compatibilityVersion === 4,
),
])

if (!isV4) {
Expand All @@ -110,8 +114,16 @@ export default defineUntypedSchema({
return rootDir
}
}
const keys = ['assets', 'layouts', 'middleware', 'pages', 'plugins'] as const
const dirs = await Promise.all(keys.map(key => get(`dir.${key}`) as Promise<string>))
const keys = [
'assets',
'layouts',
'middleware',
'pages',
'plugins',
] as const
const dirs = await Promise.all(
keys.map(key => get(`dir.${key}`) as Promise<string>),
)
for (const dir of dirs) {
if (existsSync(resolve(rootDir, dir))) {
return rootDir
Expand All @@ -131,9 +143,16 @@ export default defineUntypedSchema({
*/
serverDir: {
$resolve: async (val: string | undefined, get): Promise<string> => {
const isV4 = ((await get('future') as Record<string, unknown>).compatibilityVersion === 4)

return resolve(await get('rootDir') as string, (val || isV4) ? 'server' : resolve(await get('srcDir') as string, 'server'))
const isV4 =
((await get('future')) as Record<string, unknown>)
.compatibilityVersion === 4

return resolve(
(await get('rootDir')) as string,
val || isV4
? 'server'
: resolve((await get('srcDir')) as string, 'server'),
)
},
},

Expand All @@ -150,7 +169,8 @@ export default defineUntypedSchema({
* ```
*/
buildDir: {
$resolve: async (val: string | undefined, get): Promise<string> => resolve(await get('rootDir') as string, val || '.nuxt'),
$resolve: async (val: string | undefined, get): Promise<string> =>
resolve((await get('rootDir')) as string, val || '.nuxt'),
},

/**
Expand All @@ -170,11 +190,13 @@ export default defineUntypedSchema({
modulesDir: {
$default: ['node_modules'],
$resolve: async (val: string[] | undefined, get): Promise<string[]> => {
const rootDir = await get('rootDir') as string
return [...new Set([
...(val || []).map((dir: string) => resolve(rootDir, dir)),
resolve(rootDir, 'node_modules'),
])]
const rootDir = (await get('rootDir')) as string
return [
...new Set([
...(val || []).map((dir: string) => resolve(rootDir, dir)),
resolve(rootDir, 'node_modules'),
]),
]
},
},

Expand All @@ -184,9 +206,10 @@ export default defineUntypedSchema({
* If a relative path is specified, it will be relative to your `rootDir`.
*/
analyzeDir: {
$resolve: async (val: string | undefined, get): Promise<string> => val
? resolve(await get('rootDir') as string, val)
: resolve(await get('buildDir') as string, 'analyze'),
$resolve: async (val: string | undefined, get): Promise<string> =>
val
? resolve((await get('rootDir')) as string, val)
: resolve((await get('buildDir')) as string, 'analyze'),
},

/**
Expand Down Expand Up @@ -245,7 +268,8 @@ 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: string[] | undefined): string[] => (val || []).filter(Boolean),
$resolve: (val: string[] | undefined): string[] =>
(val || []).filter(Boolean),
},

/**
Expand All @@ -256,9 +280,11 @@ export default defineUntypedSchema({
dir: {
app: {
$resolve: async (val: string | undefined, get) => {
const isV4 = (await get('future') as Record<string, unknown>).compatibilityVersion === 4
const isV4 =
((await get('future')) as Record<string, unknown>)
.compatibilityVersion === 4
if (isV4) {
return resolve(await get('srcDir') as string, val || '.')
return resolve((await get('srcDir')) as string, val || '.')
}
return val || 'app'
},
Expand All @@ -283,9 +309,11 @@ export default defineUntypedSchema({
*/
modules: {
$resolve: async (val: string | undefined, get) => {
const isV4 = (await get('future') as Record<string, unknown>).compatibilityVersion === 4
const isV4 =
((await get('future')) as Record<string, unknown>)
.compatibilityVersion === 4
if (isV4) {
return resolve(await get('rootDir') as string, val || 'modules')
return resolve((await get('rootDir')) as string, val || 'modules')
}
return val || 'modules'
},
Expand All @@ -307,25 +335,34 @@ export default defineUntypedSchema({
*/
public: {
$resolve: async (val: string | undefined, get) => {
const isV4 = (await get('future') as Record<string, unknown>).compatibilityVersion === 4
const isV4 =
((await get('future')) as Record<string, unknown>)
.compatibilityVersion === 4
if (isV4) {
return resolve(await get('rootDir') as string, val || await get('dir.static') as string || 'public')
return resolve(
(await get('rootDir')) as string,
val || ((await get('dir.static')) as string) || 'public',
)
}
return val || await get('dir.static') as string || 'public'
return val || ((await get('dir.static')) as string) || 'public'
},
},

static: {
$schema: { deprecated: 'use `dir.public` option instead' },
$resolve: async (val, get) => val || await get('dir.public') || 'public',
$resolve: async (val, get) =>
val || (await get('dir.public')) || 'public',
},
},

/**
* The extensions that should be resolved by the Nuxt resolver.
*/
extensions: {
$resolve: (val: string[] | undefined): string[] => ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.vue', ...val || []].filter(Boolean),
$resolve: (val: string[] | undefined): string[] =>
['.js', '.jsx', '.mjs', '.ts', '.tsx', '.vue', ...(val || [])].filter(
Boolean,
),
},

/**
Expand Down Expand Up @@ -369,8 +406,16 @@ export default defineUntypedSchema({
* @type {Record<string, string>}
*/
alias: {
$resolve: async (val: Record<string, string>, get): Promise<Record<string, string>> => {
const [srcDir, rootDir, assetsDir, publicDir] = await Promise.all([get('srcDir'), get('rootDir'), get('dir.assets'), get('dir.public')]) as [string, string, string, string]
$resolve: async (
val: Record<string, string>,
get,
): Promise<Record<string, string>> => {
const [srcDir, rootDir, assetsDir, publicDir] = (await Promise.all([
get('srcDir'),
get('rootDir'),
get('dir.assets'),
get('dir.public'),
])) as [string, string, string, string]
return {
'~': srcDir,
'@': srcDir,
Expand All @@ -397,8 +442,10 @@ export default defineUntypedSchema({
ignoreOptions: undefined,

/**
* Any file in `pages/`, `layouts/`, `middleware/` or `store/` will be ignored during
* building if its filename starts with the prefix specified by `ignorePrefix`.
* Any file in `pages/`, `layouts/`, `middleware/`, `store/`, and `public/` directories will be ignored during
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think store can be removed here (was Nuxt 2 specific).
Besides that, it'd be good to check in the code which other parts are affected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manniL oh. I'm sorry. I ran lint:fix to see if stylistic changes are allowed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, if they are from lint:fix that that's fine 馃檲

* the build process if its filename starts with the prefix specified by `ignorePrefix`. This is intended to prevent
* certain files from being processed or served in the built application.
* By default, the `ignorePrefix` is set to '-', ignoring any files starting with '-'.
*/
ignorePrefix: {
$resolve: val => val ?? '-',
Expand All @@ -410,7 +457,12 @@ export default defineUntypedSchema({
*/
ignore: {
$resolve: async (val: string[] | undefined, get): Promise<string[]> => {
const [rootDir, ignorePrefix, analyzeDir, buildDir] = await Promise.all([get('rootDir'), get('ignorePrefix'), get('analyzeDir'), get('buildDir')]) as [string, string, string, string]
const [rootDir, ignorePrefix, analyzeDir, buildDir] = (await Promise.all([
get('rootDir'),
get('ignorePrefix'),
get('analyzeDir'),
get('buildDir'),
])) as [string, string, string, string]
return [
'**/*.stories.{js,cts,mts,ts,jsx,tsx}', // ignore storybook files
'**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}', // ignore tests
Expand All @@ -419,7 +471,7 @@ export default defineUntypedSchema({
relative(rootDir, analyzeDir),
relative(rootDir, buildDir),
ignorePrefix && `**/${ignorePrefix}*.*`,
...val || [],
...(val || []),
].filter(Boolean)
},
},
Expand All @@ -434,7 +486,9 @@ export default defineUntypedSchema({
*/
watch: {
$resolve: (val: Array<unknown> | undefined) => {
return (val || []).filter((b: unknown) => typeof b === 'string' || b instanceof RegExp)
return (val || []).filter(
(b: unknown) => typeof b === 'string' || b instanceof RegExp,
)
},
},

Expand Down Expand Up @@ -516,8 +570,11 @@ export default defineUntypedSchema({
* @type {typeof import('../src/types/config').RuntimeConfig}
*/
runtimeConfig: {
$resolve: async (val: RuntimeConfig, get): Promise<Record<string, unknown>> => {
const app = await get('app') as Record<string, string>
$resolve: async (
val: RuntimeConfig,
get,
): Promise<Record<string, unknown>> => {
const app = (await get('app')) as Record<string, string>
provideFallbackValues(val)
return defu(val, {
public: {},
Expand Down