Skip to content

Commit

Permalink
chore: update build scripts (nuxt#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Apr 9, 2021
1 parent 030327b commit c351574
Show file tree
Hide file tree
Showing 33 changed files with 384 additions and 869 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: yarn # --immutable


- name: Stub
run: yarn stub

- name: Lint
run: yarn lint

Expand Down
28 changes: 7 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,28 @@
"packages/*"
],
"scripts": {
"link": "lerna link",
"build": "jiti ./scripts/build-all",
"stub": "yarn build --stub",
"gentypes": "yarn workspace @nuxt/kit jiti ./scripts/gentypes",
"release": "yarn build && lerna publish -m \"chore: release\" && yarn stub",
"build": "FORCE_COLOR=1 lerna run prepack --stream --no-prefix",
"stub": "lerna run prepack -- --stub",
"release": "yarn && yarn build && FORCE_COLOR=1 lerna publish -m \"chore: release\" && yarn stub",
"nu": "./node_modules/.bin/nu",
"play": "yarn run nu dev playground",
"lint": "yarn gentypes && eslint --ext .vue,.ts,.js .",
"test": "yarn lint",
"lint": "eslint --ext .vue,.ts,.js .",
"postinstall": "yarn stub",
"version": "yarn && git add yarn.lock"
},
"resolutions": {
"esbuild": "0.10.2"
},
"devDependencies": {
"@nuxtjs/eslint-config": "^6.0.0",
"@nuxtjs/eslint-config-typescript": "^6.0.0",
"@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@types/jest": "^26.0.22",
"@types/node": "^14.14.37",
"@types/rimraf": "^3.0.0",
"chalk": "^4.1.0",
"defu": "^3.2.2",
"esbuild": "^0.10.0",
"eslint": "^7.23.0",
"execa": "^5.0.0",
"jest": "^26.6.3",
"jiti": "^1.6.4",
"lerna": "^4.0.0",
"mkdist": "^0.1.3",
"pretty-bytes": "^5.6.0",
"rimraf": "^3.0.2",
"rollup": "^2.44.0",
"rollup-plugin-dts": "^3.0.1",
"rollup-plugin-esbuild": "^3.0.2",
"standard-version": "^9.1.1",
"ts-jest": "^26.5.4",
"typescript": "^4.2.3"
}
Expand Down
14 changes: 14 additions & 0 deletions packages/app/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BuildConfig } from 'unbuild'

export default <BuildConfig>{
declaration: false,
entries: [
{ input: 'src/', name: 'app' }
],
dependencies: [
'@vueuse/head',
'ohmyfetch',
'vue-router',
'vuex5'
]
}
2 changes: 1 addition & 1 deletion packages/app/meta.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { resolve } = require('path')

module.exports = {
appDir: resolve(__dirname, 'dist')
appDir: resolve(__dirname, 'dist/app')
}
25 changes: 9 additions & 16 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,25 @@
"version": "0.2.1",
"repository": "nuxt/framework",
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.js",
"main": "./dist/app/index.js",
"module": "./dist/app/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"meta.js"
],
"scripts": {
"prepack": "unbuild"
},
"devDependencies": {
"unbuild": "^0.1.11"
},
"dependencies": {
"@vueuse/head": "^0.5.1",
"hookable": "^4.4.1",
"ohmyfetch": "^0.2.0",
"vue": "^3.0.11",
"vue-router": "^4.0.6",
"vuex5": "^0.5.0-testing.3"
},
"build": {
"entries": {
"index": {
"distDir": ".gen"
},
"/": {}
},
"dependencies": [
"@vueuse/head",
"ohmyfetch",
"vue-router",
"vuex5"
]
}
}
3 changes: 1 addition & 2 deletions packages/app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { useNuxt } from './nuxt/composables'

export * from './nuxt'
export * from './shim'
export * from './composables'
39 changes: 36 additions & 3 deletions packages/app/src/nuxt/index.ts → packages/app/src/nuxt.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { App, getCurrentInstance } from 'vue'
import Hookable from 'hookable'
import type { App } from 'vue'
import { defineGetter } from '../utils'
import { callWithNuxt } from './composables'
import { defineGetter } from './utils'

export interface Nuxt {
app: App
Expand Down Expand Up @@ -93,3 +92,37 @@ export async function applyPlugins (nuxt: Nuxt, plugins: Plugin[]) {
await applyPlugin(nuxt, plugin)
}
}

let currentNuxtInstance: Nuxt | null

export const setNuxtInstance = (nuxt: Nuxt | null) => {
currentNuxtInstance = nuxt
}

/**
* Ensures that the setup function passed in has access to the Nuxt instance via `useNuxt`.
* @param nuxt A Nuxt instance
* @param setup The function to call
*/
export async function callWithNuxt (nuxt: Nuxt, setup: () => any) {
setNuxtInstance(nuxt)
const p = setup()
setNuxtInstance(null)
await p
}

/**
* Returns the current Nuxt instance.
*/
export function useNuxt (): Nuxt {
const vm = getCurrentInstance()

if (!vm) {
if (!currentNuxtInstance) {
throw new Error('nuxt instance unavailable')
}
return currentNuxtInstance
}

return vm.appContext.app.$nuxt
}
36 changes: 0 additions & 36 deletions packages/app/src/nuxt/composables.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/app/src/plugins/head/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Plugin } from '@nuxt/app'
import { createHead, renderHeadToString } from '@vueuse/head'
import type { Plugin } from '@nuxt/app'
import { Head, Html, Body, Title, Meta, Link, Script, Style } from './head'

export default <Plugin> function head (nuxt) {
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/plugins/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
RouterLink
} from 'vue-router'
import type { Plugin } from '@nuxt/app'
// @ts-ignore
import routes from 'nuxt/build/routes'
// @ts-ignore
import NuxtPage from './NuxtPage.vue'

export default <Plugin> function router (nuxt) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/plugins/vuex.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createVuex, defineStore, useStore } from 'vuex5/dist/vuex.esm'
import type { Plugin } from '@nuxt/app'
import { useHydration } from 'nuxt/app/composables'
import { useHydration } from '../composables'

export default <Plugin> function ({ app }) {
const vuex = createVuex({ })
Expand Down
11 changes: 11 additions & 0 deletions packages/cli/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { BuildConfig } from 'unbuild'

export default <BuildConfig>{
declaration: false,
entries: [
'src/index'
],
externals: [
'nuxt3'
]
}
18 changes: 7 additions & 11 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
"nuxt": "./bin/nuxt.js",
"nuxt-cli": "./bin/nuxt.js"
},
"scripts": {
"prepack": "unbuild"
},
"devDependencies": {
"unbuild": "^0.1.11"
},
"files": [
"bin",
"dist"
],
"build": {
"externals": [
"nuxt3"
],
"entries": {
"index": {
"format": "cjs"
}
}
}
]
}
3 changes: 2 additions & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ async function _main () {
const isDev = cmd === 'dev'
const rootDir = resolve(process.cwd(), args[1] || '.')

const { loadNuxt, build } = await import('nuxt3')
const pkg = 'nuxt3'
const { loadNuxt, build } = require(pkg)

const nuxt = await loadNuxt({
for: isDev ? 'dev' : 'build',
Expand Down
16 changes: 16 additions & 0 deletions packages/kit/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { BuildConfig } from 'unbuild'

export default <BuildConfig>{
declaration: true,
entries: [
{
input: 'src/config/schema/index',
name: 'config',
builder: 'untyped',
defaults: {
rootDir: '<rootDir>'
}
},
'src/index'
]
}
14 changes: 6 additions & 8 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"files": [
"dist"
],
"scripts": {
"prepack": "unbuild"
},
"devDependencies": {
"unbuild": "^0.1.11"
},
"dependencies": {
"consola": "^2.15.3",
"create-require": "^1.1.1",
Expand All @@ -22,13 +28,5 @@
"unctx": "^0.0.3",
"untyped": "^0.2.4",
"upath": "^2.0.1"
},
"build": {
"prebuild": "jiti ./scripts/gentypes",
"entries": {
"index": {
"format": "cjs"
}
}
}
}
19 changes: 0 additions & 19 deletions packages/kit/scripts/gentypes.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/kit/src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConfigSchema } from '../../.gen/config'
import { ConfigSchema } from '../../.gen/config/config'
import { ModuleInstallOptions } from './module'
import { NuxtHooks } from './hooks'

Expand Down
23 changes: 23 additions & 0 deletions packages/nitro/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { BuildConfig } from 'unbuild'

export default <BuildConfig>{
declaration: true,
entries: [
'src/index',
'src/compat',
{ input: 'src/runtime/', format: 'esm', declaration: false }
],
dependencies: [
'@cloudflare/kv-asset-handler',
'@netlify/functions',
'@nuxt/devalue',
'connect',
'destr',
'ohmyfetch',
'ora',
'vue-bundle-renderer',
'vue-server-renderer',
'@vue/server-renderer',
'vue'
]
}
Loading

0 comments on commit c351574

Please sign in to comment.