diff --git a/package.json b/package.json index 99854192..c49505a7 100644 --- a/package.json +++ b/package.json @@ -1,101 +1,34 @@ { - "name": "@nuxt/bridge", + "private": true, "version": "3.0.0", - "repository": "nuxt/framework", + "repository": "nuxt/bridge", "license": "MIT", - "type": "module", - "main": "./module.cjs", - "types": "./types.d.ts", - "files": [ - "bin", - "module.cjs", - "types.d.ts", - "dist" - ], - "bin": { - "nuxi": "./bin/nuxt.mjs" - }, "scripts": { - "build": "pnpm prepack", + "build": "FORCE_COLOR=1 pnpm --filter './packages/**' prepack", + "build:stub": "pnpm --filter './packages/**' prepack --stub", "prepack": "unbuild", "dev": "nuxi dev playground", "dev:build": "nuxi build playground", "dev:preview": "node ./playground/.output/server/index.mjs", - "dev:prepare": "unbuild --stub && nuxi prepare playground", + "dev:prepare": "pnpm build:stub && nuxi prepare playground", "lint": "eslint --ext .vue,.ts,.js,.mjs .", "test:fixtures": "pnpm dev:prepare && JITI_ESM_RESOLVE=1 vitest run --dir test", "test:fixtures:dev": "NUXT_TEST_DEV=true pnpm test:fixtures", "test:fixtures:webpack": "TEST_WITH_WEBPACK=1 pnpm test:fixtures", "test:fixtures:webpack:dev": "TEST_WITH_WEBPACK=1 NUXT_TEST_DEV=true pnpm test:fixtures" }, - "dependencies": { - "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6", - "@babel/plugin-proposal-optional-chaining": "^7.18.9", - "@babel/plugin-transform-typescript": "^7.20.2", - "@nuxt/devalue": "^2.0.0", - "@nuxt/kit": "3.0.0-rc.12", - "@nuxt/postcss8": "^1.1.3", - "@nuxt/schema": "3.0.0-rc.12", - "@nuxt/ui-templates": "^1.0.0", - "@vitejs/plugin-legacy": "^2.3.1", - "@vitejs/plugin-vue2": "^1.1.2", - "acorn": "^8.8.1", - "cookie-es": "^0.5.0", - "defu": "^6.1.1", - "destr": "^1.2.1", - "enhanced-resolve": "^5.12.0", - "escape-string-regexp": "^5.0.0", - "estree-walker": "^2.0.2", - "externality": "^1.0.0", - "fs-extra": "^10.1.0", - "get-port-please": "^2.6.1", - "globby": "^13.1.2", - "h3": "^0.8.6", - "hash-sum": "^2.0.0", - "knitwork": "^1.0.0", - "magic-string": "^0.26.7", - "mlly": "^1.0.0", - "nitropack": "^0.6.1", - "node-fetch": "^3.3.0", - "nuxi": "3.0.0-rc.12", - "ohash": "^1.0.0", - "pathe": "^1.0.0", - "perfect-debounce": "^0.1.3", - "postcss": "^8.4.19", - "postcss-import": "^15.0.0", - "postcss-import-resolver": "^2.0.0", - "postcss-preset-env": "^7.8.3", - "postcss-url": "^10.1.3", - "scule": "^1.0.0", - "semver": "^7.3.8", - "std-env": "^3.3.1", - "terser": "^5.16.0", - "ufo": "^1.0.1", - "unctx": "^2.1.1", - "unimport": "^1.0.1", - "unplugin": "^1.0.0", - "untyped": "^1.0.0", - "vite": "~3.2.4", - "vue-bundle-renderer": "^1.0.0" - }, "devDependencies": { - "@nuxt/bridge": "link:.", - "@nuxt/test-utils": "npm:@nuxt/test-utils-edge@latest", - "@nuxt/types": "^2.15.8", + "@nuxt/test-utils": "^3.0.0", "@nuxtjs/eslint-config": "^12.0.0", "@nuxtjs/eslint-config-typescript": "^12.0.0", - "@types/fs-extra": "^9.0.13", - "@types/hash-sum": "^1.0.0", - "@types/node-fetch": "^3.0.2", - "@vueuse/head": "^0.9.7", "eslint": "^8.28.0", "eslint-plugin-jsdoc": "^39.6.4", "jiti": "^1.16.0", - "nuxt": "^2", - "unbuild": "1.0.1", - "vitest": "^0.25.3", - "vue": "^2.7.12", - "vue-router": "^3.6.5" + "vitest": "^0.25.3" + }, + "resolutions": { + "@nuxt/bridge": "workspace:*", + "@nuxt/bridge-schema": "workspace:*" }, "engines": { "node": "^14.16.0 || ^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" diff --git a/packages/bridge-schema/.gitignore b/packages/bridge-schema/.gitignore new file mode 100644 index 00000000..1c12cf9b --- /dev/null +++ b/packages/bridge-schema/.gitignore @@ -0,0 +1 @@ +schema diff --git a/packages/bridge-schema/build.config.ts b/packages/bridge-schema/build.config.ts new file mode 100644 index 00000000..08a6506a --- /dev/null +++ b/packages/bridge-schema/build.config.ts @@ -0,0 +1,66 @@ +import { defineBuildConfig } from 'unbuild' + +export default defineBuildConfig({ + declaration: true, + entries: [ + { + input: 'src/config/index', + outDir: 'schema', + name: 'config', + builder: 'untyped', + defaults: { + dev: false, + ssr: true, + buildAssetsDir: '_nuxt', + srcDir: '', + buildDir: '.nuxt', + dir: { + store: 'store' + }, + loading: {}, + sourcemap: {}, + vue: {}, + manifest: {}, + messages: {}, + postcss: {}, + build: {}, + generate: {}, + app: {}, + _nuxtConfigFiles: [], + rootDir: '//', + vite: { + base: '/' + } + } + }, + 'src/index' + ], + externals: [ + // Type imports + 'vue-meta', + 'vue-router', + 'vue-bundle-renderer', + '@vueuse/head', + 'vue', + 'hookable', + 'nitropack', + 'webpack', + 'webpack-bundle-analyzer', + 'rollup-plugin-visualizer', + 'vite', + '@vitejs/plugin-vue', + 'mini-css-extract-plugin', + 'terser-webpack-plugin', + 'css-minimizer-webpack-plugin', + 'webpack-dev-middleware', + 'h3', + 'webpack-hot-middleware', + 'postcss', + 'consola', + 'ignore', + // Implicit + '@vue/compiler-core', + '@vue/shared', + 'untyped' + ] +}) diff --git a/packages/bridge-schema/package.json b/packages/bridge-schema/package.json new file mode 100644 index 00000000..1f3dd036 --- /dev/null +++ b/packages/bridge-schema/package.json @@ -0,0 +1,44 @@ +{ + "name": "@nuxt/bridge-schema", + "version": "3.0.0", + "repository": "nuxt/bridge", + "license": "MIT", + "type": "module", + "main": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "files": [ + "dist", + "schema" + ], + "scripts": { + "build": "unbuild", + "prepack": "unbuild" + }, + "devDependencies": { + "@types/lodash.template": "^4", + "@types/semver": "^7", + "@vitejs/plugin-vue": "^3.1.2", + "@vueuse/head": "^0.9.7", + "nitropack": "^1.0.0", + "unbuild": "latest", + "vite": "~3.2.4" + }, + "dependencies": { + "c12": "^1.0.1", + "create-require": "^1.1.1", + "defu": "^6.1.0", + "jiti": "^1.16.0", + "pathe": "^1.0.0", + "pkg-types": "^1.0.1", + "postcss-import-resolver": "^2.0.0", + "scule": "^1.0.0", + "std-env": "^3.3.0", + "ufo": "^1.0.1", + "unbuild": "1.0.1", + "unimport": "^0.6.8", + "untyped": "^1.0.0" + }, + "engines": { + "node": "^14.16.0 || ^16.10.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } +} diff --git a/packages/bridge-schema/src/config.ts b/packages/bridge-schema/src/config.ts new file mode 100644 index 00000000..48e99779 --- /dev/null +++ b/packages/bridge-schema/src/config.ts @@ -0,0 +1,11 @@ +import { ConfigSchema } from '../schema/config' + +type DeepPartial = T extends Function ? T : T extends Record ? { [P in keyof T]?: DeepPartial } : T + +/** User configuration in `nuxt.config` file */ +export interface Nuxt2Config extends DeepPartial> { +} + +/** Normalized Nuxt options available as `nuxt.options.*` */ +export interface Nuxt2Options extends ConfigSchema { +} diff --git a/packages/bridge-schema/src/config/app.ts b/packages/bridge-schema/src/config/app.ts new file mode 100644 index 00000000..c8c5f5e9 --- /dev/null +++ b/packages/bridge-schema/src/config/app.ts @@ -0,0 +1,276 @@ +import { existsSync, readdirSync } from 'node:fs' +import { defineUntypedSchema } from 'untyped' +import { resolve, join } from 'pathe' +import defu from 'defu' + +export default defineUntypedSchema({ + vue: { + /** + * Properties that will be set directly on `Vue.config` for vue@2. + * + * @see [vue@2 Documentation](https://v2.vuejs.org/v2/api/#Global-Config) + * @type {typeof import('vue/types/vue').VueConfiguration} + */ + config: { + silent: { + $resolve: async (val, get) => val ?? !(await get('dev')) + }, + performance: { + $resolve: async (val, get) => val ?? await get('dev') + } + } + }, + + app: { + /** + * The folder name for the built site assets, relative to `baseURL` (or `cdnURL` if set). + * + * @deprecated - use `buildAssetsDir` instead + */ + assetsPath: { + $resolve: async (val, get) => val ?? (await get('buildAssetsDir')) + } + }, + + /** + * The path to an HTML template file for rendering Nuxt responses. + * Uses `/app.html` if it exists, or the Nuxt's default template if not. + * + * @example + * ```html + * + * + * + * {{ HEAD }} + * + * + * {{ APP }} + * + * + * ``` + */ + appTemplatePath: { + $resolve: async (val, get) => { + if (val) { + return resolve(await get('srcDir'), val) + } + if (existsSync(join(await get('srcDir'), 'app.html'))) { + return join(await get('srcDir'), 'app.html') + } + return resolve(await get('buildDir'), 'views/app.template.html') + } + }, + + /** + * Enable or disable Vuex store. + * + * By default, it is enabled if there is a `store/` directory. + */ + 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] !== '.') + }, + + /** + * Options to pass directly to `vue-meta`. + * + * @see [documentation](https://vue-meta.nuxtjs.org/api/#plugin-options). + * @type {typeof import('vue-meta').VueMetaOptions} + */ + vueMeta: null, + + /** + * Set default configuration for `` on every page. + * + * @see [documentation](https://vue-meta.nuxtjs.org/api/#metainfo-properties) for specifics. + * @type {typeof import('vue-meta').MetaInfo} + */ + head: { + /** Each item in the array maps to a newly-created `` element, where object properties map to attributes. */ + meta: [], + /** Each item in the array maps to a newly-created `` element, where object properties map to attributes. */ + link: [], + /** Each item in the array maps to a newly-created `