Skip to content

Commit bcb2a9b

Browse files
committed
build: make @vue/shared public
This avoids it being inlined multiple times in esm bundler builds
1 parent e1660f4 commit bcb2a9b

File tree

18 files changed

+88
-68
lines changed

18 files changed

+88
-68
lines changed

.github/contributing.md

+1-10
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,7 @@ This repository employs a [monorepo](https://en.wikipedia.org/wiki/Monorepo) set
185185

186186
A [live version](https://vue-next-template-explorer.netlify.com) of the template explorer is also available, which can be used for providing reproductions for compiler bugs. You can also pick the deployment for a specific commit from the [deploy logs](https://app.netlify.com/sites/vue-next-template-explorer/deploys).
187187

188-
- `shared`: **Private.** Utilities shared across multiple packages (especially by both runtime and compiler packages). This package is private and not published. Instead, it is **inlined** into the package that imports it during build.
189-
190-
- **Note:** if re-exporting a function from `@vue/shared` as a public API, it is necessary to re-define its type before exporting so that the final `d.ts` doesn't attempt to import `@vue/shared`, e.g.:
191-
192-
```ts
193-
import { foo } from '@vue/shared'
194-
export const publicFoo = foo as {
195-
/* re-define type */
196-
}
197-
```
188+
- `shared`: Internal utilities shared across multiple packages (especially environment-agnostic utils used by both runtime and compiler packages).
198189

199190
- `vue`: The public facing "full build" which includes both the runtime AND the compiler.
200191

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"size": "node scripts/build.js vue runtime-dom size-check -p -f global",
1111
"lint": "prettier --write --parser typescript \"packages/**/*.ts?(x)\"",
1212
"test": "node scripts/build.js vue -f global -d && jest",
13-
"test-dts": "node scripts/build.js reactivity runtime-core runtime-dom -dt -f esm-bundler && tsd",
13+
"test-dts": "node scripts/build.js shared reactivity runtime-core runtime-dom -dt -f esm-bundler && tsd",
1414
"release": "node scripts/release.js",
1515
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
1616
"dev-compiler": "npm-run-all --parallel \"dev template-explorer\" serve",

packages/compiler-core/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@
1818
},
1919
"repository": {
2020
"type": "git",
21-
"url": "git+https://github.com/vuejs/vue.git"
21+
"url": "git+https://github.com/vuejs/vue-next.git"
2222
},
2323
"keywords": [
2424
"vue"
2525
],
2626
"author": "Evan You",
2727
"license": "MIT",
2828
"bugs": {
29-
"url": "https://github.com/vuejs/vue/issues"
29+
"url": "https://github.com/vuejs/vue-next/issues"
3030
},
31-
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/compiler-core#readme",
31+
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-core#readme",
3232
"dependencies": {
33+
"@vue/shared": "3.0.0-alpha.7",
3334
"@babel/parser": "^7.8.6",
3435
"@babel/types": "^7.8.6",
3536
"estree-walker": "^0.8.1",

packages/compiler-core/src/index.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,4 @@ export {
5050
} from './transforms/vSlot'
5151
export { resolveComponentType, buildProps } from './transforms/transformElement'
5252
export { processSlotOutlet } from './transforms/transformSlotOutlet'
53-
54-
// utility, but need to rewrite typing to avoid dts relying on @vue/shared
55-
import { generateCodeFrame as _genCodeFrame } from '@vue/shared'
56-
const generateCodeFrame = _genCodeFrame as (
57-
source: string,
58-
start?: number,
59-
end?: number
60-
) => string
61-
export { generateCodeFrame }
53+
export { generateCodeFrame } from '@vue/shared'

packages/compiler-dom/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@
2222
},
2323
"repository": {
2424
"type": "git",
25-
"url": "git+https://github.com/vuejs/vue.git"
25+
"url": "git+https://github.com/vuejs/vue-next.git"
2626
},
2727
"keywords": [
2828
"vue"
2929
],
3030
"author": "Evan You",
3131
"license": "MIT",
3232
"bugs": {
33-
"url": "https://github.com/vuejs/vue/issues"
33+
"url": "https://github.com/vuejs/vue-next/issues"
3434
},
35-
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/compiler-dom#readme",
35+
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-dom#readme",
3636
"dependencies": {
37+
"@vue/shared": "3.0.0-alpha.7",
3738
"@vue/compiler-core": "3.0.0-alpha.7"
3839
}
3940
}

packages/compiler-sfc/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@
1515
},
1616
"repository": {
1717
"type": "git",
18-
"url": "git+https://github.com/vuejs/vue.git"
18+
"url": "git+https://github.com/vuejs/vue-next.git"
1919
},
2020
"keywords": [
2121
"vue"
2222
],
2323
"author": "Evan You",
2424
"license": "MIT",
2525
"bugs": {
26-
"url": "https://github.com/vuejs/vue/issues"
26+
"url": "https://github.com/vuejs/vue-next/issues"
2727
},
28-
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/compiler-sfc#readme",
28+
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-sfc#readme",
2929
"peerDependencies": {
3030
"vue": "3.0.0-alpha.7"
3131
},
3232
"dependencies": {
33+
"@vue/shared": "3.0.0-alpha.7",
3334
"@vue/compiler-core": "3.0.0-alpha.7",
3435
"@vue/compiler-dom": "3.0.0-alpha.7",
3536
"consolidate": "^0.15.1",

packages/compiler-ssr/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
},
1616
"repository": {
1717
"type": "git",
18-
"url": "git+https://github.com/vuejs/vue.git"
18+
"url": "git+https://github.com/vuejs/vue-next.git"
1919
},
2020
"keywords": [
2121
"vue"
2222
],
2323
"author": "Evan You",
2424
"license": "MIT",
2525
"bugs": {
26-
"url": "https://github.com/vuejs/vue/issues"
26+
"url": "https://github.com/vuejs/vue-next/issues"
2727
},
28-
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/compiler-ssr#readme",
28+
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-ssr#readme",
2929
"dependencies": {
30+
"@vue/shared": "3.0.0-alpha.7",
3031
"@vue/compiler-dom": "3.0.0-alpha.7"
3132
}
3233
}

packages/reactivity/package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"sideEffects": false,
1414
"repository": {
1515
"type": "git",
16-
"url": "git+https://github.com/vuejs/vue.git"
16+
"url": "git+https://github.com/vuejs/vue-next.git"
1717
},
1818
"buildOptions": {
1919
"name": "VueReactivity",
@@ -30,7 +30,10 @@
3030
"author": "Evan You",
3131
"license": "MIT",
3232
"bugs": {
33-
"url": "https://github.com/vuejs/vue/issues"
33+
"url": "https://github.com/vuejs/vue-next/issues"
3434
},
35-
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/reactivity#readme"
35+
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/reactivity#readme",
36+
"dependencies": {
37+
"@vue/shared": "3.0.0-alpha.7"
38+
}
3639
}

packages/runtime-core/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@
1919
"sideEffects": false,
2020
"repository": {
2121
"type": "git",
22-
"url": "git+https://github.com/vuejs/vue.git"
22+
"url": "git+https://github.com/vuejs/vue-next.git"
2323
},
2424
"keywords": [
2525
"vue"
2626
],
2727
"author": "Evan You",
2828
"license": "MIT",
2929
"bugs": {
30-
"url": "https://github.com/vuejs/vue/issues"
30+
"url": "https://github.com/vuejs/vue-next/issues"
3131
},
32-
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/runtime-core#readme",
32+
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/runtime-core#readme",
3333
"dependencies": {
34+
"@vue/shared": "3.0.0-alpha.7",
3435
"@vue/reactivity": "3.0.0-alpha.7"
3536
}
3637
}

packages/runtime-core/src/index.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,7 @@ export {
101101
createCommentVNode,
102102
createStaticVNode
103103
} from './vnode'
104-
// Since @vue/shared is inlined into final builds,
105-
// when re-exporting from @vue/shared we need to avoid relying on their original
106-
// types so that the bundled d.ts does not attempt to import from it.
107-
import {
108-
toDisplayString as _toDisplayString,
109-
camelize as _camelize
110-
} from '@vue/shared'
111-
export const toDisplayString = _toDisplayString as (s: unknown) => string
112-
export const camelize = _camelize as (s: string) => string
104+
export { toDisplayString, camelize } from '@vue/shared'
113105

114106
// For integration with runtime compiler
115107
export { registerRuntimeCompiler } from './component'

packages/runtime-dom/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@
2525
},
2626
"repository": {
2727
"type": "git",
28-
"url": "git+https://github.com/vuejs/vue.git"
28+
"url": "git+https://github.com/vuejs/vue-next.git"
2929
},
3030
"keywords": [
3131
"vue"
3232
],
3333
"author": "Evan You",
3434
"license": "MIT",
3535
"bugs": {
36-
"url": "https://github.com/vuejs/vue/issues"
36+
"url": "https://github.com/vuejs/vue-next/issues"
3737
},
38-
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/runtime-dom#readme",
38+
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/runtime-dom#readme",
3939
"dependencies": {
40+
"@vue/shared": "3.0.0-alpha.7",
4041
"@vue/runtime-core": "3.0.0-alpha.7",
4142
"csstype": "^2.6.8"
4243
}

packages/runtime-test/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"repository": {
1414
"type": "git",
15-
"url": "git+https://github.com/vuejs/vue.git"
15+
"url": "git+https://github.com/vuejs/vue-next.git"
1616
},
1717
"buildOptions": {
1818
"name": "VueRuntimeTest",
@@ -26,10 +26,11 @@
2626
"author": "Evan You",
2727
"license": "MIT",
2828
"bugs": {
29-
"url": "https://github.com/vuejs/vue/issues"
29+
"url": "https://github.com/vuejs/vue-next/issues"
3030
},
31-
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/runtime-test#readme",
31+
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/runtime-test#readme",
3232
"dependencies": {
33+
"@vue/shared": "3.0.0-alpha.7",
3334
"@vue/runtime-core": "3.0.0-alpha.7"
3435
}
3536
}

packages/server-renderer/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@
1515
},
1616
"repository": {
1717
"type": "git",
18-
"url": "git+https://github.com/vuejs/vue.git"
18+
"url": "git+https://github.com/vuejs/vue-next.git"
1919
},
2020
"keywords": [
2121
"vue"
2222
],
2323
"author": "Evan You",
2424
"license": "MIT",
2525
"bugs": {
26-
"url": "https://github.com/vuejs/vue/issues"
26+
"url": "https://github.com/vuejs/vue-next/issues"
2727
},
28-
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/server-renderer#readme",
28+
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/server-renderer#readme",
2929
"peerDependencies": {
3030
"vue": "3.0.0-alpha.7"
3131
},
3232
"dependencies": {
33+
"@vue/shared": "3.0.0-alpha.7",
3334
"@vue/compiler-ssr": "3.0.0-alpha.7"
3435
}
3536
}

packages/shared/api-extractor.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../api-extractor.json",
3+
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
4+
"dtsRollup": {
5+
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
6+
}
7+
}

packages/shared/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict'
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
module.exports = require('./dist/shared.cjs.prod.js')
5+
} else {
6+
module.exports = require('./dist/shared.cjs.js')
7+
}

packages/shared/package.json

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
{
22
"name": "@vue/shared",
33
"version": "3.0.0-alpha.7",
4-
"private": true
4+
"description": "internal utils shared across @vue packages",
5+
"main": "index.js",
6+
"module": "dist/shared.esm-bundler.js",
7+
"types": "dist/shared.d.ts",
8+
"files": [
9+
"index.js",
10+
"dist"
11+
],
12+
"buildOptions": {
13+
"formats": [
14+
"esm-bundler",
15+
"cjs"
16+
]
17+
},
18+
"repository": {
19+
"type": "git",
20+
"url": "git+https://github.com/vuejs/vue-next.git"
21+
},
22+
"keywords": [
23+
"vue"
24+
],
25+
"author": "Evan You",
26+
"license": "MIT",
27+
"bugs": {
28+
"url": "https://github.com/vuejs/vue-next/issues"
29+
},
30+
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/shared#readme"
531
}

packages/vue/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@
2424
},
2525
"repository": {
2626
"type": "git",
27-
"url": "git+https://github.com/vuejs/vue.git"
27+
"url": "git+https://github.com/vuejs/vue-next.git"
2828
},
2929
"keywords": [
3030
"vue"
3131
],
3232
"author": "Evan You",
3333
"license": "MIT",
3434
"bugs": {
35-
"url": "https://github.com/vuejs/vue/issues"
35+
"url": "https://github.com/vuejs/vue-next/issues"
3636
},
37-
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/vue#readme",
37+
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/vue#readme",
3838
"dependencies": {
39+
"@vue/shared": "3.0.0-alpha.7",
3940
"@vue/compiler-dom": "3.0.0-alpha.7",
4041
"@vue/runtime-dom": "3.0.0-alpha.7"
4142
},

rollup.config.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fs from 'fs'
21
import path from 'path'
32
import ts from 'rollup-plugin-typescript2'
43
import replace from '@rollup/plugin-replace'
@@ -16,10 +15,6 @@ const resolve = p => path.resolve(packageDir, p)
1615
const pkg = require(resolve(`package.json`))
1716
const packageOptions = pkg.buildOptions || {}
1817

19-
const knownExternals = fs.readdirSync(packagesDir).filter(p => {
20-
return p !== '@vue/shared'
21-
})
22-
2318
// ensure TS checks only once for each build
2419
let hasTSChecked = false
2520

@@ -112,9 +107,7 @@ function createConfig(format, output, plugins = []) {
112107
format === 'esm-bundler-runtime' ? `src/runtime.ts` : `src/index.ts`
113108

114109
const external =
115-
isGlobalBuild || isRawESMBuild
116-
? []
117-
: knownExternals.concat(Object.keys(pkg.dependencies || []))
110+
isGlobalBuild || isRawESMBuild ? [] : Object.keys(pkg.dependencies || {})
118111

119112
const nodePlugins = packageOptions.enableNonBrowserBranches
120113
? [

0 commit comments

Comments
 (0)