]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
build: make @vue/shared public
authorEvan You <yyx990803@gmail.com>
Sun, 1 Mar 2020 03:04:42 +0000 (22:04 -0500)
committerEvan You <yyx990803@gmail.com>
Sun, 1 Mar 2020 03:04:42 +0000 (22:04 -0500)
This avoids it being inlined multiple times in esm bundler builds

18 files changed:
.github/contributing.md
package.json
packages/compiler-core/package.json
packages/compiler-core/src/index.ts
packages/compiler-dom/package.json
packages/compiler-sfc/package.json
packages/compiler-ssr/package.json
packages/reactivity/package.json
packages/runtime-core/package.json
packages/runtime-core/src/index.ts
packages/runtime-dom/package.json
packages/runtime-test/package.json
packages/server-renderer/package.json
packages/shared/api-extractor.json [new file with mode: 0644]
packages/shared/index.js [new file with mode: 0644]
packages/shared/package.json
packages/vue/package.json
rollup.config.js

index 122cf0e0c528d485ce7c9ca881a7890bf462d325..f1656ce4cf49adbe8b7918aedb06b90f7c5beb7f 100644 (file)
@@ -185,16 +185,7 @@ This repository employs a [monorepo](https://en.wikipedia.org/wiki/Monorepo) set
 
   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).
 
-- `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.
-
-  - **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.:
-
-    ```ts
-    import { foo } from '@vue/shared'
-    export const publicFoo = foo as {
-      /* re-define type */
-    }
-    ```
+- `shared`: Internal utilities shared across multiple packages (especially environment-agnostic utils used by both runtime and compiler packages).
 
 - `vue`: The public facing "full build" which includes both the runtime AND the compiler.
 
index 82e828a05d0265b0827262a11cc2ddc9afb63333..8479807c431188429d40ee8283cfc6e22248025e 100644 (file)
@@ -10,7 +10,7 @@
     "size": "node scripts/build.js vue runtime-dom size-check -p -f global",
     "lint": "prettier --write --parser typescript \"packages/**/*.ts?(x)\"",
     "test": "node scripts/build.js vue -f global -d && jest",
-    "test-dts": "node scripts/build.js reactivity runtime-core runtime-dom -dt -f esm-bundler && tsd",
+    "test-dts": "node scripts/build.js shared reactivity runtime-core runtime-dom -dt -f esm-bundler && tsd",
     "release": "node scripts/release.js",
     "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
     "dev-compiler": "npm-run-all --parallel \"dev template-explorer\" serve",
index e11b6e1b208e803b6f3753ef00f1579030aedaec..b2454497faa7eeebdcd8e3e17b74cfbc68ed6bdd 100644 (file)
@@ -18,7 +18,7 @@
   },
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/vuejs/vue.git"
+    "url": "git+https://github.com/vuejs/vue-next.git"
   },
   "keywords": [
     "vue"
   "author": "Evan You",
   "license": "MIT",
   "bugs": {
-    "url": "https://github.com/vuejs/vue/issues"
+    "url": "https://github.com/vuejs/vue-next/issues"
   },
-  "homepage": "https://github.com/vuejs/vue/tree/dev/packages/compiler-core#readme",
+  "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-core#readme",
   "dependencies": {
+    "@vue/shared": "3.0.0-alpha.7",
     "@babel/parser": "^7.8.6",
     "@babel/types": "^7.8.6",
     "estree-walker": "^0.8.1",
index 6a224eb4ac433abb858ed71de84730119635b322..0cb41d11a61274e8e3ed2b314913e8476000ff3e 100644 (file)
@@ -50,12 +50,4 @@ export {
 } from './transforms/vSlot'
 export { resolveComponentType, buildProps } from './transforms/transformElement'
 export { processSlotOutlet } from './transforms/transformSlotOutlet'
-
-// utility, but need to rewrite typing to avoid dts relying on @vue/shared
-import { generateCodeFrame as _genCodeFrame } from '@vue/shared'
-const generateCodeFrame = _genCodeFrame as (
-  source: string,
-  start?: number,
-  end?: number
-) => string
-export { generateCodeFrame }
+export { generateCodeFrame } from '@vue/shared'
index 4b023e1c995f323642ba94bbcaf2c5a0641b34d9..01c77ea236145de9ab3d971e72cd9f7d8d86adf9 100644 (file)
@@ -22,7 +22,7 @@
   },
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/vuejs/vue.git"
+    "url": "git+https://github.com/vuejs/vue-next.git"
   },
   "keywords": [
     "vue"
   "author": "Evan You",
   "license": "MIT",
   "bugs": {
-    "url": "https://github.com/vuejs/vue/issues"
+    "url": "https://github.com/vuejs/vue-next/issues"
   },
-  "homepage": "https://github.com/vuejs/vue/tree/dev/packages/compiler-dom#readme",
+  "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-dom#readme",
   "dependencies": {
+    "@vue/shared": "3.0.0-alpha.7",
     "@vue/compiler-core": "3.0.0-alpha.7"
   }
 }
index 65eecf41d3168d7b95b2f68ff28587b349811025..0dff6d43e4c957846e93ea97c7efac6125cfc925 100644 (file)
@@ -15,7 +15,7 @@
   },
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/vuejs/vue.git"
+    "url": "git+https://github.com/vuejs/vue-next.git"
   },
   "keywords": [
     "vue"
   "author": "Evan You",
   "license": "MIT",
   "bugs": {
-    "url": "https://github.com/vuejs/vue/issues"
+    "url": "https://github.com/vuejs/vue-next/issues"
   },
-  "homepage": "https://github.com/vuejs/vue/tree/dev/packages/compiler-sfc#readme",
+  "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-sfc#readme",
   "peerDependencies": {
     "vue": "3.0.0-alpha.7"
   },
   "dependencies": {
+    "@vue/shared": "3.0.0-alpha.7",
     "@vue/compiler-core": "3.0.0-alpha.7",
     "@vue/compiler-dom": "3.0.0-alpha.7",
     "consolidate": "^0.15.1",
index 617831372eb45265ebca611d67fbf80bba63c1c1..aa3f289b4799098a839a4c49e465adbd0da2d470 100644 (file)
@@ -15,7 +15,7 @@
   },
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/vuejs/vue.git"
+    "url": "git+https://github.com/vuejs/vue-next.git"
   },
   "keywords": [
     "vue"
   "author": "Evan You",
   "license": "MIT",
   "bugs": {
-    "url": "https://github.com/vuejs/vue/issues"
+    "url": "https://github.com/vuejs/vue-next/issues"
   },
-  "homepage": "https://github.com/vuejs/vue/tree/dev/packages/compiler-ssr#readme",
+  "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-ssr#readme",
   "dependencies": {
+    "@vue/shared": "3.0.0-alpha.7",
     "@vue/compiler-dom": "3.0.0-alpha.7"
   }
 }
index badcfd5ee12795d36ec363370d165240d2821f1d..accdade426053a570bc090120093d95cb5fc2c2f 100644 (file)
@@ -13,7 +13,7 @@
   "sideEffects": false,
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/vuejs/vue.git"
+    "url": "git+https://github.com/vuejs/vue-next.git"
   },
   "buildOptions": {
     "name": "VueReactivity",
   "author": "Evan You",
   "license": "MIT",
   "bugs": {
-    "url": "https://github.com/vuejs/vue/issues"
+    "url": "https://github.com/vuejs/vue-next/issues"
   },
-  "homepage": "https://github.com/vuejs/vue/tree/dev/packages/reactivity#readme"
+  "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/reactivity#readme",
+  "dependencies": {
+    "@vue/shared": "3.0.0-alpha.7"
+  }
 }
index fc3f378fd019123d1608a5ca2cd639b88e0a35b6..dd6806599adc66ac1e7e8c8e3e405d3d1eee3d51 100644 (file)
@@ -19,7 +19,7 @@
   "sideEffects": false,
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/vuejs/vue.git"
+    "url": "git+https://github.com/vuejs/vue-next.git"
   },
   "keywords": [
     "vue"
   "author": "Evan You",
   "license": "MIT",
   "bugs": {
-    "url": "https://github.com/vuejs/vue/issues"
+    "url": "https://github.com/vuejs/vue-next/issues"
   },
-  "homepage": "https://github.com/vuejs/vue/tree/dev/packages/runtime-core#readme",
+  "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/runtime-core#readme",
   "dependencies": {
+    "@vue/shared": "3.0.0-alpha.7",
     "@vue/reactivity": "3.0.0-alpha.7"
   }
 }
index 4e9459d4afa0ca7d1e5bd3b75a0c51e7452cf6bc..d0b8444a8fde7189be5cd594894711e920a24768 100644 (file)
@@ -101,15 +101,7 @@ export {
   createCommentVNode,
   createStaticVNode
 } from './vnode'
-// Since @vue/shared is inlined into final builds,
-// when re-exporting from @vue/shared we need to avoid relying on their original
-// types so that the bundled d.ts does not attempt to import from it.
-import {
-  toDisplayString as _toDisplayString,
-  camelize as _camelize
-} from '@vue/shared'
-export const toDisplayString = _toDisplayString as (s: unknown) => string
-export const camelize = _camelize as (s: string) => string
+export { toDisplayString, camelize } from '@vue/shared'
 
 // For integration with runtime compiler
 export { registerRuntimeCompiler } from './component'
index 5cad71b1f16063337ae66c621a0ea999d9bbd34b..04b37986f452c1f9fd7e0c82c68f19af5ee14c55 100644 (file)
@@ -25,7 +25,7 @@
   },
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/vuejs/vue.git"
+    "url": "git+https://github.com/vuejs/vue-next.git"
   },
   "keywords": [
     "vue"
   "author": "Evan You",
   "license": "MIT",
   "bugs": {
-    "url": "https://github.com/vuejs/vue/issues"
+    "url": "https://github.com/vuejs/vue-next/issues"
   },
-  "homepage": "https://github.com/vuejs/vue/tree/dev/packages/runtime-dom#readme",
+  "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/runtime-dom#readme",
   "dependencies": {
+    "@vue/shared": "3.0.0-alpha.7",
     "@vue/runtime-core": "3.0.0-alpha.7",
     "csstype": "^2.6.8"
   }
index c6a6a368ab9bc694880b2a214248fa5d15d8d334..91ae6ea9422d2aceb7339bfa94a71139f9582cfd 100644 (file)
@@ -12,7 +12,7 @@
   ],
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/vuejs/vue.git"
+    "url": "git+https://github.com/vuejs/vue-next.git"
   },
   "buildOptions": {
     "name": "VueRuntimeTest",
   "author": "Evan You",
   "license": "MIT",
   "bugs": {
-    "url": "https://github.com/vuejs/vue/issues"
+    "url": "https://github.com/vuejs/vue-next/issues"
   },
-  "homepage": "https://github.com/vuejs/vue/tree/dev/packages/runtime-test#readme",
+  "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/runtime-test#readme",
   "dependencies": {
+    "@vue/shared": "3.0.0-alpha.7",
     "@vue/runtime-core": "3.0.0-alpha.7"
   }
 }
index ca5719e4c6165548ed1eeb96365a6300abf64de6..7a7f795dd3440cf01e043193a0bb9b6ce7b35a11 100644 (file)
@@ -15,7 +15,7 @@
   },
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/vuejs/vue.git"
+    "url": "git+https://github.com/vuejs/vue-next.git"
   },
   "keywords": [
     "vue"
   "author": "Evan You",
   "license": "MIT",
   "bugs": {
-    "url": "https://github.com/vuejs/vue/issues"
+    "url": "https://github.com/vuejs/vue-next/issues"
   },
-  "homepage": "https://github.com/vuejs/vue/tree/dev/packages/server-renderer#readme",
+  "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/server-renderer#readme",
   "peerDependencies": {
     "vue": "3.0.0-alpha.7"
   },
   "dependencies": {
+    "@vue/shared": "3.0.0-alpha.7",
     "@vue/compiler-ssr": "3.0.0-alpha.7"
   }
 }
diff --git a/packages/shared/api-extractor.json b/packages/shared/api-extractor.json
new file mode 100644 (file)
index 0000000..d182b70
--- /dev/null
@@ -0,0 +1,7 @@
+{
+  "extends": "../../api-extractor.json",
+  "mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
+  "dtsRollup": {
+    "untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
+  }
+}
diff --git a/packages/shared/index.js b/packages/shared/index.js
new file mode 100644 (file)
index 0000000..a2ee43e
--- /dev/null
@@ -0,0 +1,7 @@
+'use strict'
+
+if (process.env.NODE_ENV === 'production') {
+  module.exports = require('./dist/shared.cjs.prod.js')
+} else {
+  module.exports = require('./dist/shared.cjs.js')
+}
index 2fa7c446365c2f52bf1c65da2938981037910a36..eca54142cf652de1479e6ed7be5b2a001af44fa3 100644 (file)
@@ -1,5 +1,31 @@
 {
   "name": "@vue/shared",
   "version": "3.0.0-alpha.7",
-  "private": true
+  "description": "internal utils shared across @vue packages",
+  "main": "index.js",
+  "module": "dist/shared.esm-bundler.js",
+  "types": "dist/shared.d.ts",
+  "files": [
+    "index.js",
+    "dist"
+  ],
+  "buildOptions": {
+    "formats": [
+      "esm-bundler",
+      "cjs"
+    ]
+  },
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/vuejs/vue-next.git"
+  },
+  "keywords": [
+    "vue"
+  ],
+  "author": "Evan You",
+  "license": "MIT",
+  "bugs": {
+    "url": "https://github.com/vuejs/vue-next/issues"
+  },
+  "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/shared#readme"
 }
index 30c9a03ceeb51bc21bce038eaf1e0e9a82173e87..720b2585addf2f6c7ef4fb32b45fcbeda95976c2 100644 (file)
@@ -24,7 +24,7 @@
   },
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/vuejs/vue.git"
+    "url": "git+https://github.com/vuejs/vue-next.git"
   },
   "keywords": [
     "vue"
   "author": "Evan You",
   "license": "MIT",
   "bugs": {
-    "url": "https://github.com/vuejs/vue/issues"
+    "url": "https://github.com/vuejs/vue-next/issues"
   },
-  "homepage": "https://github.com/vuejs/vue/tree/dev/packages/vue#readme",
+  "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/vue#readme",
   "dependencies": {
+    "@vue/shared": "3.0.0-alpha.7",
     "@vue/compiler-dom": "3.0.0-alpha.7",
     "@vue/runtime-dom": "3.0.0-alpha.7"
   },
index b5150fdc630d6ec7875dfcdef117fc7b860ec3d1..46f3d3fccd7e30d9748241835550883a20f72516 100644 (file)
@@ -1,4 +1,3 @@
-import fs from 'fs'
 import path from 'path'
 import ts from 'rollup-plugin-typescript2'
 import replace from '@rollup/plugin-replace'
@@ -16,10 +15,6 @@ const resolve = p => path.resolve(packageDir, p)
 const pkg = require(resolve(`package.json`))
 const packageOptions = pkg.buildOptions || {}
 
-const knownExternals = fs.readdirSync(packagesDir).filter(p => {
-  return p !== '@vue/shared'
-})
-
 // ensure TS checks only once for each build
 let hasTSChecked = false
 
@@ -112,9 +107,7 @@ function createConfig(format, output, plugins = []) {
     format === 'esm-bundler-runtime' ? `src/runtime.ts` : `src/index.ts`
 
   const external =
-    isGlobalBuild || isRawESMBuild
-      ? []
-      : knownExternals.concat(Object.keys(pkg.dependencies || []))
+    isGlobalBuild || isRawESMBuild ? [] : Object.keys(pkg.dependencies || {})
 
   const nodePlugins = packageOptions.enableNonBrowserBranches
     ? [