From 38109fe915808647a072de9359af32466fcb1a9b Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 19 Sep 2018 21:51:21 -0400 Subject: [PATCH] workflow: adjust esm-bundler build file name --- packages/compiler-core/package.json | 4 +-- packages/compiler-dom/package.json | 4 +-- packages/compiler-server/package.json | 4 +-- packages/core/package.json | 2 +- packages/core/src/createRenderer.ts | 2 +- packages/core/src/h.ts | 4 +-- packages/core/src/index.ts | 14 +-------- packages/observer/package.json | 2 +- packages/renderer-dom/package.json | 2 +- packages/renderer-dom/src/index.ts | 43 +++++++-------------------- packages/renderer-server/package.json | 6 ++-- packages/scheduler/package.json | 2 +- rollup.config.js | 12 +++++--- scripts/bootstrap.js | 2 +- tsconfig.json | 7 ++++- 15 files changed, 43 insertions(+), 67 deletions(-) diff --git a/packages/compiler-core/package.json b/packages/compiler-core/package.json index 9b84d9f4..7d500b33 100644 --- a/packages/compiler-core/package.json +++ b/packages/compiler-core/package.json @@ -3,7 +3,7 @@ "version": "3.0.0-alpha.1", "description": "@vue/compiler-core", "main": "index.js", - "module": "dist/compiler-core.esm.js", + "module": "dist/compiler-core.esm-bundler.js", "typings": "dist/index.d.ts", "repository": { "type": "git", @@ -18,4 +18,4 @@ "url": "https://github.com/vuejs/vue/issues" }, "homepage": "https://github.com/vuejs/vue/tree/dev/packages/compiler-core#readme" -} \ No newline at end of file +} diff --git a/packages/compiler-dom/package.json b/packages/compiler-dom/package.json index b2bb68af..d04e769f 100644 --- a/packages/compiler-dom/package.json +++ b/packages/compiler-dom/package.json @@ -3,7 +3,7 @@ "version": "3.0.0-alpha.1", "description": "@vue/compiler-dom", "main": "index.js", - "module": "dist/compiler-dom.esm.js", + "module": "dist/compiler-dom.esm-bundler.js", "typings": "dist/index.d.ts", "repository": { "type": "git", @@ -18,4 +18,4 @@ "url": "https://github.com/vuejs/vue/issues" }, "homepage": "https://github.com/vuejs/vue/tree/dev/packages/compiler-dom#readme" -} \ No newline at end of file +} diff --git a/packages/compiler-server/package.json b/packages/compiler-server/package.json index b8c1e017..1e508dd7 100644 --- a/packages/compiler-server/package.json +++ b/packages/compiler-server/package.json @@ -3,7 +3,7 @@ "version": "3.0.0-alpha.1", "description": "@vue/compiler-server", "main": "index.js", - "module": "dist/compiler-server.esm.js", + "module": "dist/compiler-server.esm-bundler.js", "typings": "dist/index.d.ts", "repository": { "type": "git", @@ -18,4 +18,4 @@ "url": "https://github.com/vuejs/vue/issues" }, "homepage": "https://github.com/vuejs/vue/tree/dev/packages/compiler-server#readme" -} \ No newline at end of file +} diff --git a/packages/core/package.json b/packages/core/package.json index 9d27e66c..f2c18036 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -3,7 +3,7 @@ "version": "3.0.0-alpha.1", "description": "@vue/core", "main": "index.js", - "module": "dist/core.esm.js", + "module": "dist/core.esm-bundler.js", "typings": "dist/index.d.ts", "repository": { "type": "git", diff --git a/packages/core/src/createRenderer.ts b/packages/core/src/createRenderer.ts index ddae8cf4..7d5ccd63 100644 --- a/packages/core/src/createRenderer.ts +++ b/packages/core/src/createRenderer.ts @@ -1283,7 +1283,7 @@ export function createRenderer(options: RendererOptions) { // API ----------------------------------------------------------------------- - function render(vnode: VNode | null, container: RenderNode) { + function render(vnode: VNode | null, container: any) { const prevVNode = container.vnode if (vnode && vnode.el) { vnode = cloneVNode(vnode) diff --git a/packages/core/src/h.ts b/packages/core/src/h.ts index 9236fb5a..be913246 100644 --- a/packages/core/src/h.ts +++ b/packages/core/src/h.ts @@ -22,7 +22,7 @@ type ElementType = | typeof Portal export interface createElement { - (tag: ElementType, data: any, children: any): VNode + (tag: ElementType, data?: any, children?: any): VNode c: typeof createComponentVNode e: typeof createElementVNode t: typeof createTextVNode @@ -30,7 +30,7 @@ export interface createElement { p: typeof createPortal } -export const h = ((tag: ElementType, data: any, children: any): VNode => { +export const h = ((tag: ElementType, data?: any, children?: any): VNode => { if (Array.isArray(data) || (data !== void 0 && typeof data !== 'object')) { children = data data = null diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index f37e98e3..14fa9679 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -4,23 +4,11 @@ export { cloneVNode, createPortal, createFragment } from './vdom' export { createRenderer } from './createRenderer' import { Component as InternalComponent, ComponentClass } from './component' - // the public component constructor with proper type inference. export const Component = InternalComponent as ComponentClass // observer api -export { - autorun, - stop, - observable, - immutable, - computed, - isObservable, - isImmutable, - markImmutable, - markNonReactive, - unwrap -} from '@vue/observer' +export * from '@vue/observer' // flags & types export { FunctionalComponent } from './component' diff --git a/packages/observer/package.json b/packages/observer/package.json index d5fa3f5e..8150a7cd 100644 --- a/packages/observer/package.json +++ b/packages/observer/package.json @@ -3,7 +3,7 @@ "version": "3.0.0-alpha.1", "description": "@vue/observer", "main": "index.js", - "module": "dist/observer.esm.js", + "module": "dist/observer.esm-bundler.js", "typings": "dist/index.d.ts", "unpkg": "dist/observer.global.js", "repository": { diff --git a/packages/renderer-dom/package.json b/packages/renderer-dom/package.json index a379956b..a45d035b 100644 --- a/packages/renderer-dom/package.json +++ b/packages/renderer-dom/package.json @@ -3,7 +3,7 @@ "version": "3.0.0-alpha.1", "description": "@vue/renderer-dom", "main": "index.js", - "module": "dist/renderer-dom.esm.js", + "module": "dist/renderer-dom.esm-bundler.js", "typings": "dist/index.d.ts", "unpkg": "dist/renderer-dom.global.js", "buildOptions": { diff --git a/packages/renderer-dom/src/index.ts b/packages/renderer-dom/src/index.ts index bb9e3ad6..423f9a1e 100644 --- a/packages/renderer-dom/src/index.ts +++ b/packages/renderer-dom/src/index.ts @@ -1,46 +1,23 @@ -import { - h, - cloneVNode, - createPortal, - Component, - createRenderer -} from '@vue/core' - -import { queueJob, nextTick } from '@vue/scheduler' +import { createRenderer, VNode } from '@vue/core' +import { queueJob } from '@vue/scheduler' import { nodeOps } from './nodeOps' import { patchData } from './patchData' import { teardownVNode } from './teardownVNode' -const { render } = createRenderer({ +const { render: _render } = createRenderer({ queueJob, nodeOps, patchData, teardownVNode }) -// important: inline the definition for nextTick -const publicNextTick = nextTick as (fn: Function) => Promise +type publicRender = (node: VNode | null, container: HTMLElement) => void +export const render = _render as publicRender -export { - h, - cloneVNode, - createPortal, - Component, - render, - publicNextTick as nextTick -} +// nextTick from scheduler +export { nextTick } from '@vue/scheduler' -// also expose observer API -export { - autorun, - stop, - observable, - immutable, - computed, - isObservable, - isImmutable, - markImmutable, - markNonReactive, - unwrap -} from '@vue/core' +// re-export everything from core +// h, Component, observer API, flags & types +export * from '@vue/core' diff --git a/packages/renderer-server/package.json b/packages/renderer-server/package.json index 9c776548..2c1ee256 100644 --- a/packages/renderer-server/package.json +++ b/packages/renderer-server/package.json @@ -3,8 +3,10 @@ "version": "3.0.0-alpha.1", "description": "@vue/renderer-server", "main": "index.js", - "module": "dist/renderer-server.esm.js", "typings": "dist/index.d.ts", + "buildOptions": { + "formats": ["cjs"] + }, "repository": { "type": "git", "url": "git+https://github.com/vuejs/vue.git" @@ -18,4 +20,4 @@ "url": "https://github.com/vuejs/vue/issues" }, "homepage": "https://github.com/vuejs/vue/tree/dev/packages/renderer-server#readme" -} \ No newline at end of file +} diff --git a/packages/scheduler/package.json b/packages/scheduler/package.json index b65d87c8..6898c2ff 100644 --- a/packages/scheduler/package.json +++ b/packages/scheduler/package.json @@ -3,7 +3,7 @@ "version": "3.0.0-alpha.1", "description": "@vue/scheduler", "main": "index.js", - "module": "dist/scheduler.esm.js", + "module": "dist/scheduler.esm-bundler.js", "typings": "dist/index.d.ts", "repository": { "type": "git", diff --git a/rollup.config.js b/rollup.config.js index 99d8e5ce..6e469054 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -18,7 +18,10 @@ const packageOptions = pkg.buildOptions || {} // build aliases dynamically const aliasOptions = { resolve: ['.ts'] } fs.readdirSync(packagesDir).forEach(dir => { - if (fs.statSync(path.resolve(packagesDir, dir)).isDirectory()) { + if ( + dir !== 'vue' && + fs.statSync(path.resolve(packagesDir, dir)).isDirectory() + ) { aliasOptions[`@vue/${dir}`] = path.resolve(packagesDir, `${dir}/src/index`) } }) @@ -71,6 +74,7 @@ function createConfig(output, plugins = []) { const isGlobalBuild = /\.global(\.prod)?\.js$/.test(output.file) const isBunlderESMBuild = /\.esm\.js$/.test(output.file) const isBrowserESMBuild = /esm-browser(\.prod)?\.js$/.test(output.file) + const isCompat = /dist\/vue\./.test(output.file) if (isGlobalBuild) { output.name = packageOptions.name @@ -100,7 +104,7 @@ function createConfig(output, plugins = []) { plugins: [ tsPlugin, aliasPlugin, - createReplacePlugin(isProductionBuild, isBunlderESMBuild), + createReplacePlugin(isProductionBuild, isBunlderESMBuild, isCompat), ...plugins ], output, @@ -112,7 +116,7 @@ function createConfig(output, plugins = []) { } } -function createReplacePlugin(isProduction, isBunlderESMBuild) { +function createReplacePlugin(isProduction, isBunlderESMBuild, isCompat) { return replace({ __DEV__: isBunlderESMBuild ? // preserve to be handled by bundlers @@ -120,7 +124,7 @@ function createReplacePlugin(isProduction, isBunlderESMBuild) { : // hard coded dev/prod builds !isProduction, // compatibility builds - __COMPAT__: !!process.env.COMPAT + __COMPAT__: !!packageOptions.compat }) } diff --git a/scripts/bootstrap.js b/scripts/bootstrap.js index 21098b3f..021aa40a 100644 --- a/scripts/bootstrap.js +++ b/scripts/bootstrap.js @@ -21,7 +21,7 @@ files.forEach(shortName => { version: baseVersion, description: name, main: 'index.js', - module: `dist/${shortName}.esm.js`, + module: `dist/${shortName}.esm-bundler.js`, typings: 'dist/index.d.ts', repository: { type: 'git', diff --git a/tsconfig.json b/tsconfig.json index cc1cedfa..3a203397 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,7 +21,12 @@ "paths": { "@vue/core": ["packages/core/src"], "@vue/observer": ["packages/observer/src"], - "@vue/scheduler": ["packages/scheduler/src"] + "@vue/scheduler": ["packages/scheduler/src"], + "@vue/renderer-dom": ["packages/renderer-dom/src"], + "@vue/renderer-server": ["packages/renderer-server/src"], + "@vue/compiler-core": ["packages/compiler-core/src"], + "@vue/compiler-dom": ["packages/compiler-dom/src"], + "@vue/compiler-server": ["packages/compiler-server/src"] } }, "include": [