From 31a543dfbebb8dcd4408de5f718c688ef4b5124e Mon Sep 17 00:00:00 2001 From: Tzahi Date: Tue, 22 Sep 2020 12:05:02 +0300 Subject: [PATCH 01/14] docs: fix typo in en.json (#5885) [ci skip] --- packages/@vue/cli-ui/locales/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@vue/cli-ui/locales/en.json b/packages/@vue/cli-ui/locales/en.json index 72623848d3..d0db1bffbc 100644 --- a/packages/@vue/cli-ui/locales/en.json +++ b/packages/@vue/cli-ui/locales/en.json @@ -629,7 +629,7 @@ "css": { "modules": { "label": "Enable CSS Modules", - "description": "By default, only files that ends in *.module.[ext] are treated as CSS modules. Enabling this will treat all style files as CSS modules." + "description": "By default, only files that end with *.module.[ext] are treated as CSS modules. Enabling this will treat all style files as CSS modules." }, "extract": { "label": "Extract CSS", From 5b70fc2f10533f0a4f0eedce704ada600885f2b0 Mon Sep 17 00:00:00 2001 From: Bodo Graumann Date: Wed, 23 Sep 2020 07:35:48 +0200 Subject: [PATCH 02/14] fix: respect scope when resolving package metadata (#5892) This should fix the remaining issue reported in #5411. In particular, if the user configured a dedicated npm registry for a specific scope, this setting was previously disregarded by vue-cli. Thus it was impossible to use vue upgrade if the packages were not also published to the official npm registry. --- .../cli/lib/util/ProjectPackageManager.js | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/packages/@vue/cli/lib/util/ProjectPackageManager.js b/packages/@vue/cli/lib/util/ProjectPackageManager.js index 2ab3877bf5..168065b994 100644 --- a/packages/@vue/cli/lib/util/ProjectPackageManager.js +++ b/packages/@vue/cli/lib/util/ProjectPackageManager.js @@ -85,9 +85,23 @@ function stripVersion (packageName) { return result[1] } +// extract the package scope from the full package name +// the result includes the initial @ character +function extractPackageScope (packageName) { + const scopedNameRegExp = /^(@[^\/]+)\/.*$/ + const result = packageName.match(scopedNameRegExp) + + if (!result) { + return undefined + } + + return result[1] +} + class PackageManager { constructor ({ context, forcePackageManager } = {}) { this.context = context || process.cwd() + this._registries = {} if (forcePackageManager) { this.bin = forcePackageManager @@ -146,9 +160,10 @@ class PackageManager { // Any command that implemented registry-related feature should support // `-r` / `--registry` option - async getRegistry () { - if (this._registry) { - return this._registry + async getRegistry (scope) { + const cacheKey = scope || '' + if (this._registries[cacheKey]) { + return this._registries[cacheKey] } const args = minimist(process.argv, { @@ -157,24 +172,30 @@ class PackageManager { } }) + let registry if (args.registry) { - this._registry = args.registry + registry = args.registry } else if (!process.env.VUE_CLI_TEST && await shouldUseTaobao(this.bin)) { - this._registry = registries.taobao + registry = registries.taobao } else { try { - this._registry = (await execa(this.bin, ['config', 'get', 'registry'])).stdout + if (scope) { + registry = (await execa(this.bin, ['config', 'get', scope + ':registry'])).stdout + } + if (!registry || registry === 'undefined') { + registry = (await execa(this.bin, ['config', 'get', 'registry'])).stdout + } } catch (e) { // Yarn 2 uses `npmRegistryServer` instead of `registry` - this._registry = (await execa(this.bin, ['config', 'get', 'npmRegistryServer'])).stdout + registry = (await execa(this.bin, ['config', 'get', 'npmRegistryServer'])).stdout } } - this._registry = stripAnsi(this._registry).trim() - return this._registry + this._registries[cacheKey] = stripAnsi(registry).trim() + return this._registries[cacheKey] } - async getAuthToken () { + async getAuthToken (scope) { // get npmrc (https://docs.npmjs.com/configuring-npm/npmrc.html#files) const possibleRcPaths = [ path.resolve(this.context, '.npmrc'), @@ -197,7 +218,7 @@ class PackageManager { } } - const registry = await this.getRegistry() + const registry = await this.getRegistry(scope) const registryWithoutProtocol = registry .replace(/https?:/, '') // remove leading protocol .replace(/([^/])$/, '$1/') // ensure ending with slash @@ -255,8 +276,9 @@ class PackageManager { // https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md async getMetadata (packageName, { full = false } = {}) { - const registry = await this.getRegistry() - const authToken = await this.getAuthToken() + const scope = extractPackageScope(packageName) + const registry = await this.getRegistry(scope) + const authToken = await this.getAuthToken(scope) const metadataKey = `${this.bin}-${registry}-${packageName}` let metadata = metadataCache.get(metadataKey) From 468986b2c1584c62da76a163ec500b6125fea709 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 23 Sep 2020 13:41:27 +0800 Subject: [PATCH 03/14] docs: remove mention of Node.js v8 npm workaround, as it's been fixed [skip ci] --- docs/guide/installation.md | 3 --- docs/zh/guide/installation.md | 3 --- 2 files changed, 6 deletions(-) diff --git a/docs/guide/installation.md b/docs/guide/installation.md index c35003e888..67a9838f6b 100644 --- a/docs/guide/installation.md +++ b/docs/guide/installation.md @@ -7,9 +7,6 @@ If you have the previous `vue-cli` (1.x or 2.x) package installed globally, you ::: tip Node Version Requirement Vue CLI 4.x requires [Node.js](https://nodejs.org/) version 8.9 or above (v10+ recommended). You can manage multiple versions of Node on the same machine with [n](https://github.com/tj/n), [nvm](https://github.com/creationix/nvm) or [nvm-windows](https://github.com/coreybutler/nvm-windows). - -As Node.js v8 has reached end-of-life, it's now recommended to use Node.js v10+ for best compatibility. -If you have to stay with Node.js v8, please make sure npm v6 is used as the default package manager. (`npm -v` to check the version, and `vue config --set packageManager npm` to set the default package manager.) ::: To install the new package, use one of the following commands. You need administrator privileges to execute these unless npm was installed on your system through a Node.js version manager (e.g. n or nvm). diff --git a/docs/zh/guide/installation.md b/docs/zh/guide/installation.md index 0027230b13..d337264aea 100644 --- a/docs/zh/guide/installation.md +++ b/docs/zh/guide/installation.md @@ -7,9 +7,6 @@ Vue CLI 的包名称由 `vue-cli` 改成了 `@vue/cli`。 ::: tip Node 版本要求 Vue CLI 4.x 需要 [Node.js](https://nodejs.org/) v8.9 或更高版本 (推荐 v10 以上)。你可以使用 [n](https://github.com/tj/n),[nvm](https://github.com/creationix/nvm) 或 [nvm-windows](https://github.com/coreybutler/nvm-windows) 在同一台电脑中管理多个 Node 版本。 - -由于 Node.js v8 已不再维护,我们建议使用 Node.js v10 以上的版本,以保证最佳的兼容性。 -如果暂时无法升级 Node.js 版本,请使用 npm v6 作为默认的包管理工具。(可以用 `npm -v` 检查 npm 版本,然后运行 `vue config --set packageManager npm` 以设置默认包管理工具。) ::: 可以使用下列任一命令安装这个新的包: From d7ac62575cf508bacb21c7df7c499ebfe7ef0f0f Mon Sep 17 00:00:00 2001 From: Pablion <36828324+Pablion@users.noreply.github.com> Date: Thu, 24 Sep 2020 14:41:21 +0200 Subject: [PATCH 04/14] docs(zh): in build-targets.md add "using vuex" (#5883) [skip ci] --- docs/zh/guide/build-targets.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/zh/guide/build-targets.md b/docs/zh/guide/build-targets.md index a0cd4d795c..b7a6afc456 100644 --- a/docs/zh/guide/build-targets.md +++ b/docs/zh/guide/build-targets.md @@ -144,3 +144,20 @@ dist/foo.1.js 5.24 kb 1.64 kb ``` + +## 在构建时使用 vuex +在构建 [Web Components 组件](#web-components-组件)或[库](#库)时,入口点不是 `main.js` ,而是 `entry-wc.js` 文件,该文件由此生成: https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/commands/build/resolveWcEntry.js + +因此,要在 Web Components 组件的目标中使用 vuex ,你需要在 `App.vue` 中初始化存储 (store): +``` js +import store from './store' + +// ... + +export default { + store, + name: 'App', + // ... +} +``` + From eda18b05424c8c3e6862a7a5e2e15b7513bebbe4 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 27 Sep 2020 16:35:30 +0800 Subject: [PATCH 05/14] fix: shouldn't remove attribute quotes in HTML (#5899) --- .../__tests__/pwaPlugin.spec.js | 10 +-- .../@vue/cli-service/__tests__/build.spec.js | 14 ++-- .../@vue/cli-service/__tests__/cors.spec.js | 6 +- .../cli-service/__tests__/modernMode.spec.js | 28 ++++---- .../cli-service/__tests__/multiPage.spec.js | 68 +++++++++---------- packages/@vue/cli-service/lib/config/app.js | 1 - 6 files changed, 63 insertions(+), 64 deletions(-) diff --git a/packages/@vue/cli-plugin-pwa/__tests__/pwaPlugin.spec.js b/packages/@vue/cli-plugin-pwa/__tests__/pwaPlugin.spec.js index 070be9e4a7..1f349b9416 100644 --- a/packages/@vue/cli-plugin-pwa/__tests__/pwaPlugin.spec.js +++ b/packages/@vue/cli-plugin-pwa/__tests__/pwaPlugin.spec.js @@ -30,16 +30,16 @@ test('pwa', async () => { const index = await project.read('dist/index.html') // should split and preload app.js & vendor.js - expect(index).toMatch(/]+js\/app[^>]+\.js rel=preload as=script>/) - expect(index).toMatch(/]+js\/chunk-vendors[^>]+\.js rel=preload as=script>/) + expect(index).toMatch(/]+js\/app[^>]+\.js" rel="preload" as="script">/) + expect(index).toMatch(/]+js\/chunk-vendors[^>]+\.js" rel="preload" as="script">/) // should preload css - expect(index).toMatch(/]+app[^>]+\.css rel=preload as=style>/) + expect(index).toMatch(/]+app[^>]+\.css" rel="preload" as="style">/) // PWA specific directives - expect(index).toMatch(``) + expect(index).toMatch(``) // favicon is not minified because it's technically a comment expect(index).toMatch(``) - expect(index).toMatch(``) + expect(index).toMatch(``) // should import service worker script const main = await project.read('src/main.js') diff --git a/packages/@vue/cli-service/__tests__/build.spec.js b/packages/@vue/cli-service/__tests__/build.spec.js index 070d29a559..85948f1217 100644 --- a/packages/@vue/cli-service/__tests__/build.spec.js +++ b/packages/@vue/cli-service/__tests__/build.spec.js @@ -28,19 +28,19 @@ test('build', async () => { const index = await project.read('dist/index.html') // should split and preload app.js & vendor.js - expect(index).toMatch(/]+js\/app[^>]+\.js rel=preload as=script>/) - expect(index).toMatch(/]+js\/chunk-vendors[^>]+\.js rel=preload as=script>/) + expect(index).toMatch(/]+js\/app[^>]+\.js" rel="preload" as="script">/) + expect(index).toMatch(/]+js\/chunk-vendors[^>]+\.js" rel="preload" as="script">/) // should preload css - expect(index).toMatch(/]+app[^>]+\.css rel=preload as=style>/) + expect(index).toMatch(/]+app[^>]+\.css" rel="preload" as="style">/) // should inject scripts - expect(index).toMatch(/