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

Commit

Permalink
refactor(schema): upgrade to untyped 0.5 (#7452)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 12, 2022
1 parent 9382b42 commit ceb61ad
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 144 deletions.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"pathe": "^0.3.7",
"rimraf": "^3.0.2",
"scule": "^0.3.2",
"untyped": "^0.4.7",
"untyped": "^0.5.0",
"vue-mq": "^1.0.1",
"vue-plausible": "^1.3.2"
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"nuxt": "link:./packages/nuxt",
"nuxt3": "link:./packages/nuxt",
"vite": "~3.1.0",
"unbuild": "^0.8.10"
"unbuild": "^0.8.11"
},
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "^11.0.0",
Expand All @@ -64,7 +64,7 @@
"pathe": "^0.3.7",
"rimraf": "^3.0.2",
"typescript": "^4.8.3",
"unbuild": "^0.8.10",
"unbuild": "^0.8.11",
"vitest": "~0.19.1",
"vue-tsc": "^0.39.5"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"semver": "^7.3.7",
"unctx": "^2.0.2",
"unimport": "^0.6.7",
"untyped": "^0.4.7"
"untyped": "^0.5.0"
},
"devDependencies": {
"@types/lodash.template": "^4",
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/loader/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ export async function loadNuxtConfig (opts: LoadNuxtConfigOptions): Promise<Nuxt
}

// Resolve and apply defaults
return applyDefaults(NuxtConfigSchema, nuxtConfig) as NuxtOptions
return await applyDefaults(NuxtConfigSchema, nuxtConfig) as NuxtOptions
}
4 changes: 2 additions & 2 deletions packages/kit/src/module/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export function defineNuxtModule<OptionsT extends ModuleOptions> (definition: Mo
}

// Resolves module options from inline options, [configKey] in nuxt.config, defaults and schema
function getOptions (inlineOptions?: OptionsT, nuxt: Nuxt = useNuxt()) {
async function getOptions (inlineOptions?: OptionsT, nuxt: Nuxt = useNuxt()) {
const configKey = definition.meta!.configKey || definition.meta!.name!
const _defaults = definition.defaults instanceof Function ? definition.defaults(nuxt) : definition.defaults
let _options = defu(inlineOptions, nuxt.options[configKey as keyof NuxtOptions], _defaults) as OptionsT
if (definition.schema) {
_options = applyDefaults(definition.schema, _options) as OptionsT
_options = await applyDefaults(definition.schema, _options) as OptionsT
}
return Promise.resolve(_options)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"unenv": "^0.6.2",
"unimport": "^0.6.7",
"unplugin": "^0.9.2",
"untyped": "^0.4.7",
"untyped": "^0.5.0",
"vue": "^3.2.39",
"vue-bundle-renderer": "^0.4.2",
"vue-devtools-stub": "^0.1.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/nuxt/src/core/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export { }
const adHocModules = ['router', 'pages', 'imports', 'meta', 'components']
export const schemaTemplate: NuxtTemplate<TemplateContext> = {
filename: 'types/schema.d.ts',
getContents: ({ nuxt }) => {
getContents: async ({ nuxt }) => {
const moduleInfo = nuxt.options._installedModules.map(m => ({
...m.meta || {},
importName: m.entryPath || m.meta?.name
Expand All @@ -128,15 +128,15 @@ export const schemaTemplate: NuxtTemplate<TemplateContext> = {
` [${genString(meta.configKey)}]?: typeof ${genDynamicImport(meta.importName, { wrapper: false })}.default extends NuxtModule<infer O> ? Partial<O> : Record<string, any>`
),
' }',
generateTypes(resolveSchema(Object.fromEntries(Object.entries(nuxt.options.runtimeConfig).filter(([key]) => key !== 'public'))),
generateTypes(await resolveSchema(Object.fromEntries(Object.entries(nuxt.options.runtimeConfig).filter(([key]) => key !== 'public'))),
{
interfaceName: 'RuntimeConfig',
addExport: false,
addDefaults: false,
allowExtraKeys: false,
indentation: 2
}),
generateTypes(resolveSchema(nuxt.options.runtimeConfig.public),
generateTypes(await resolveSchema(nuxt.options.runtimeConfig.public),
{
interfaceName: 'PublicRuntimeConfig',
addExport: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@types/lodash.template": "^4",
"@types/semver": "^7",
"unbuild": "latest",
"untyped": "^0.4.7",
"untyped": "^0.5.0",
"vite": "~3.1.0"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/config/_adhoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default defineUntypedSchema({
* @version 3
*/
components: {
$resolve: (val, get) => {
$resolve: (val) => {
if (Array.isArray(val)) {
return { dirs: val }
}
Expand Down
42 changes: 21 additions & 21 deletions packages/schema/src/config/_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export default defineUntypedSchema({
*/
config: {
silent: {
$resolve: (val, get) => val ?? !get('dev')
$resolve: async (val, get) => val ?? !(await get('dev'))
},
performance: {
$resolve: (val, get) => val ?? get('dev')
$resolve: async (val, get) => val ?? await get('dev')
},
},
/**
Expand Down Expand Up @@ -62,7 +62,7 @@ export default defineUntypedSchema({
* @version 2
*/
assetsPath: {
$resolve: (val, get) => val ?? get('buildAssetsDir')
$resolve: async (val, get) => val ?? (await get('buildAssetsDir'))
},
/**
* An absolute URL to serve the public folder from (production-only).
Expand All @@ -74,7 +74,7 @@ export default defineUntypedSchema({
* ```
*/
cdnURL: {
$resolve: (val, get) => get('dev') ? '' : (process.env.NUXT_APP_CDN_URL ?? val) || ''
$resolve: async (val, get) => (await get('dev')) ? '' : (process.env.NUXT_APP_CDN_URL ?? val) || ''
},
/**
* Set default configuration for `<head>` on every page.
Expand Down Expand Up @@ -111,8 +111,8 @@ export default defineUntypedSchema({
* @version 3
*/
head: {
$resolve: (val, get) => {
const resolved: Required<MetaObject> = defu(val, get('meta'), {
$resolve: async (val, get) => {
const resolved: Required<MetaObject> = defu(val, await get('meta'), {
meta: [],
link: [],
style: [],
Expand Down Expand Up @@ -181,14 +181,14 @@ export default defineUntypedSchema({
* @version 2
*/
appTemplatePath: {
$resolve: (val, get) => {
$resolve: async (val, get) => {
if (val) {
return resolve(get('srcDir'), val)
return resolve(await get('srcDir'), val)
}
if (existsSync(join(get('srcDir'), 'app.html'))) {
return join(get('srcDir'), 'app.html')
if (existsSync(join(await get('srcDir'), 'app.html'))) {
return join(await get('srcDir'), 'app.html')
}
return resolve(get('buildDir'), 'views/app.template.html')
return resolve(await get('buildDir'), 'views/app.template.html')
}
},

Expand All @@ -199,9 +199,9 @@ export default defineUntypedSchema({
* @version 2
*/
store: {
$resolve: (val, get) => val !== false &&
existsSync(join(get('srcDir'), get('dir.store'))) &&
readdirSync(join(get('srcDir'), get('dir.store')))
$resolve: async (val, get) => val !== false &&
existsSync(join(await get('srcDir'), await get('dir.store'))) &&
readdirSync(join(await get('srcDir'), await get('dir.store')))
.find(filename => filename !== 'README.md' && filename[0] !== '.')
},

Expand Down Expand Up @@ -378,15 +378,15 @@ export default defineUntypedSchema({
* @version 2
*/
loadingIndicator: {
$resolve: (val, get) => {
$resolve: async (val, get) => {
val = typeof val === 'string' ? { name: val } : val
return defu(val, {
name: 'default',
color: get('loading.color') || '#D3D3D3',
color: await get('loading.color') || '#D3D3D3',
color2: '#F5F5F5',
background: (get('manifest') && get('manifest.theme_color')) || 'white',
dev: get('dev'),
loading: get('messages.loading')
background: (await get('manifest') && await get('manifest.theme_color')) || 'white',
dev: await get('dev'),
loading: await get('messages.loading')
})
}
},
Expand All @@ -402,12 +402,12 @@ export default defineUntypedSchema({
* @version 2
*/
pageTransition: {
$resolve: (val, get) => {
$resolve: async (val, get) => {
val = typeof val === 'string' ? { name: val } : val
return defu(val, {
name: 'page',
mode: 'out-in',
appear: get('render.ssr') === false || Boolean(val),
appear: await get('render.ssr') === false || Boolean(val),
appearClass: 'appear',
appearActiveClass: 'appear-active',
appearToClass: 'appear-to'
Expand Down
54 changes: 27 additions & 27 deletions packages/schema/src/config/_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default defineUntypedSchema({
* @version 3
*/
srcDir: {
$resolve: (val, get) => resolve(get('rootDir'), val || '.')
$resolve: async (val, get) => resolve(await get('rootDir'), val || '.')
},

/**
Expand All @@ -101,7 +101,7 @@ export default defineUntypedSchema({
* @version 3
*/
buildDir: {
$resolve: (val, get) => resolve(get('rootDir'), val || '.nuxt')
$resolve: async (val, get) => resolve(await get('rootDir'), val || '.nuxt')
},

/**
Expand All @@ -126,7 +126,7 @@ export default defineUntypedSchema({
* @version 2
*/
debug: {
$resolve: (val, get) => val ?? get('dev')
$resolve: async (val, get) => val ?? await get('dev')
},

/**
Expand Down Expand Up @@ -207,7 +207,7 @@ export default defineUntypedSchema({
* @deprecated use `ssr` option
*/
mode: {
$resolve: (val, get) => val || (get('ssr') ? 'spa' : 'universal'),
$resolve: async (val, get) => val || ((await get('ssr')) ? 'spa' : 'universal'),
$schema: { deprecated: '`mode` option is deprecated' }
},

Expand Down Expand Up @@ -446,8 +446,8 @@ export default defineUntypedSchema({
*/
modulesDir: {
$default: ['node_modules'],
$resolve: (val, get) => [
...val.map((dir: string) => resolve(get('rootDir'), dir)),
$resolve: async (val, get) => [
...await Promise.all(val.map(async (dir: string) => resolve(await get('rootDir'), dir))),
resolve(process.cwd(), 'node_modules')
]
},
Expand Down Expand Up @@ -494,12 +494,12 @@ export default defineUntypedSchema({
* @version 3
*/
public: {
$resolve: (val, get) => val || get('dir.static') || 'public',
$resolve: async (val, get) => val || await get('dir.static') || 'public',
},
/** @version 2 */
static: {
$schema: { deprecated: 'use `dir.public` option instead' },
$resolve: (val, get) => val || get('dir.public') || 'public',
$resolve: async (val, get) => val || await get('dir.public') || 'public',
},
/**
* The folder which will be used to auto-generate your Vuex store structure.
Expand Down Expand Up @@ -570,13 +570,13 @@ export default defineUntypedSchema({
* @version 3
*/
alias: {
$resolve: (val, get) => ({
'~~': get('rootDir'),
'@@': get('rootDir'),
'~': get('srcDir'),
'@': get('srcDir'),
[get('dir.assets')]: join(get('srcDir'), get('dir.assets')),
[get('dir.public')]: join(get('srcDir'), get('dir.public')),
$resolve: async (val, get) => ({
'~~': await get('rootDir'),
'@@': await get('rootDir'),
'~': await get('srcDir'),
'@': await get('srcDir'),
[await get('dir.assets')]: join(await get('srcDir'), await get('dir.assets')),
[await get('dir.public')]: join(await get('srcDir'), await get('dir.public')),
...val
})
},
Expand Down Expand Up @@ -612,11 +612,11 @@ export default defineUntypedSchema({
* @version 3
*/
ignore: {
$resolve: (val, get) => [
$resolve: async (val, get) => [
'**/*.stories.{js,ts,jsx,tsx}', // ignore storybook files
'**/*.{spec,test}.{js,ts,jsx,tsx}', // ignore tests
'.output',
get('ignorePrefix') && `**/${get('ignorePrefix')}*.*`
await get('ignorePrefix') && `**/${await get('ignorePrefix')}*.*`
].concat(val).filter(Boolean)
},

Expand All @@ -636,9 +636,9 @@ export default defineUntypedSchema({
* @version 2
*/
watch: {
$resolve: (val, get) => {
const rootDir = get('rootDir')
return Array.from(new Set([].concat(val, get('_nuxtConfigFiles'))
$resolve: async (val, get) => {
const rootDir = await get('rootDir')
return Array.from(new Set([].concat(val, await get('_nuxtConfigFiles'))
.filter(Boolean).map(p => resolve(rootDir, p))
))
}
Expand Down Expand Up @@ -740,14 +740,14 @@ export default defineUntypedSchema({
* @version 3
*/
runtimeConfig: {
$resolve: (val: RuntimeConfig, get) => defu(val, {
...get('publicRuntimeConfig'),
...get('privateRuntimeConfig'),
public: get('publicRuntimeConfig'),
$resolve: async (val: RuntimeConfig, get) => defu(val, {
...await get('publicRuntimeConfig'),
...await get('privateRuntimeConfig'),
public: await get('publicRuntimeConfig'),
app: {
baseURL: get('app').baseURL,
buildAssetsDir: get('app').buildAssetsDir,
cdnURL: get('app').cdnURL,
baseURL: (await get('app')).baseURL,
buildAssetsDir: (await get('app')).buildAssetsDir,
cdnURL: (await get('app')).cdnURL,
}
})
},
Expand Down

0 comments on commit ceb61ad

Please sign in to comment.