From bcc44235ee172232531c10f62a246482dcbee180 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 21 Dec 2020 16:09:52 +0900 Subject: [PATCH] change vue-i18n and core es module for bundler (#247) * change vue-i18n and core es module for bundler * update e2e * update warning message --- docs/essentials/fallback.md | 4 ++-- docs/essentials/local.md | 4 ++-- e2e/fallback/basic.test.js | 4 ++-- e2e/fallback/default-format.test.js | 18 +++++++++--------- e2e/fallback/format.test.js | 2 +- e2e/fallback/option.test.js | 2 +- e2e/fallback/suppress.test.js | 2 +- e2e/missing/handler.test.js | 2 +- e2e/missing/option.test.js | 2 +- e2e/missing/suppress.test.js | 2 +- jest.config.js | 1 - packages/core-base/package.json | 12 ++++++++++-- packages/core-base/src/translate.ts | 5 ++++- packages/core/package.json | 7 +++++-- packages/global.d.ts | 1 - packages/message-compiler/package.json | 12 ++++++++++-- packages/runtime/package.json | 17 ++++++++++++++--- packages/shared/src/index.ts | 3 +-- packages/vue-i18n/package.json | 7 +++++-- rollup.config.js | 4 ---- 20 files changed, 70 insertions(+), 41 deletions(-) diff --git a/docs/essentials/fallback.md b/docs/essentials/fallback.md index 44c7c1365..22f32184a 100644 --- a/docs/essentials/fallback.md +++ b/docs/essentials/fallback.md @@ -52,8 +52,8 @@ Output: By default, falling back to `fallbackLocale` generates two console warnings: ``` -[vue-i18n] Not found 'hello' key in 'ja' locale messages. -[vue-i18n] Fall back to translate 'hello' key with 'en' locale. +[intlify] Not found 'hello' key in 'ja' locale messages. +[intlify] Fall back to translate 'hello' key with 'en' locale. ``` The first warning message is printed the key, due to given to the translation function `$t` is not in the `ja` locale messages and the second warning message that comes out when you fall back to resolve localized messages from `en` locale messages. These warning messages are output to support debugging using Vue I18n. diff --git a/docs/essentials/local.md b/docs/essentials/local.md index c3c5a2a1f..49e544758 100644 --- a/docs/essentials/local.md +++ b/docs/essentials/local.md @@ -86,8 +86,8 @@ As in the example above, if the component doesn’t have the locale message, it And also, as explained the [here](fallback#explicit-fallback-with-one-locale), note that, by default, falling back to global scope generates two warnings in the console: ``` -[vue-i18n] Not found 'message.greeting' key in 'ja' locale messages. -[vue-i18n] Fall back to translate 'message.greeting' with root locale. +[intlify] Not found 'message.greeting' key in 'ja' locale messages. +[intlify] Fall back to translate 'message.greeting' with root locale. ``` If you want to localize using the component locale, you can do that with `sync: false` and `locale` in the `i18n` component option. diff --git a/e2e/fallback/basic.test.js b/e2e/fallback/basic.test.js index 658f6b666..3636dcc1b 100644 --- a/e2e/fallback/basic.test.js +++ b/e2e/fallback/basic.test.js @@ -13,11 +13,11 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line test('warning', () => { // missing warning expect(warnings[0]).toEqual( - `[vue-i18n] Not found 'message.hello' key in 'ja' locale messages.` + `[intlify] Not found 'message.hello' key in 'ja' locale messages.` ) // fallback warning expect(warnings[1]).toEqual( - `[vue-i18n] Fall back to translate 'message.hello' key with 'en' locale.` + `[intlify] Fall back to translate 'message.hello' key with 'en' locale.` ) }) diff --git a/e2e/fallback/default-format.test.js b/e2e/fallback/default-format.test.js index 18216cdc9..1692cdf2c 100644 --- a/e2e/fallback/default-format.test.js +++ b/e2e/fallback/default-format.test.js @@ -12,15 +12,15 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line test('warning', () => { expect(warnings).toEqual([ - `[vue-i18n] Not found 'messages.hello' key in 'ja' locale messages.`, - `[vue-i18n] Fall back to translate 'messages.hello' key with 'en' locale.`, - `[vue-i18n] Not found 'messages.hello' key in 'en' locale messages.`, - `[vue-i18n] Not found 'messages.hello' key in 'ja' locale messages.`, - `[vue-i18n] Fall back to translate 'messages.hello' key with 'en' locale.`, - `[vue-i18n] Not found 'messages.hello' key in 'en' locale messages.`, - `[vue-i18n] Not found 'good morning, {name}!' key in 'ja' locale messages.`, - `[vue-i18n] Fall back to translate 'good morning, {name}!' key with 'en' locale.`, - `[vue-i18n] Not found 'good morning, {name}!' key in 'en' locale messages.` + `[intlify] Not found 'messages.hello' key in 'ja' locale messages.`, + `[intlify] Fall back to translate 'messages.hello' key with 'en' locale.`, + `[intlify] Not found 'messages.hello' key in 'en' locale messages.`, + `[intlify] Not found 'messages.hello' key in 'ja' locale messages.`, + `[intlify] Fall back to translate 'messages.hello' key with 'en' locale.`, + `[intlify] Not found 'messages.hello' key in 'en' locale messages.`, + `[intlify] Not found 'good morning, {name}!' key in 'ja' locale messages.`, + `[intlify] Fall back to translate 'good morning, {name}!' key with 'en' locale.`, + `[intlify] Not found 'good morning, {name}!' key in 'en' locale messages.` ]) }) diff --git a/e2e/fallback/format.test.js b/e2e/fallback/format.test.js index f3f84d443..908b9f5bc 100644 --- a/e2e/fallback/format.test.js +++ b/e2e/fallback/format.test.js @@ -13,7 +13,7 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line test('warning', () => { // missing warning only expect(warnings[0]).toEqual( - `[vue-i18n] Not found 'hello, {name}!' key in 'ja' locale messages.` + `[intlify] Not found 'hello, {name}!' key in 'ja' locale messages.` ) }) diff --git a/e2e/fallback/option.test.js b/e2e/fallback/option.test.js index 180e18e47..483139e68 100644 --- a/e2e/fallback/option.test.js +++ b/e2e/fallback/option.test.js @@ -13,7 +13,7 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line test('warning', () => { // missing warning only! expect(warnings[0]).toEqual( - `[vue-i18n] Not found 'message.hello' key in 'ja' locale messages.` + `[intlify] Not found 'message.hello' key in 'ja' locale messages.` ) }) diff --git a/e2e/fallback/suppress.test.js b/e2e/fallback/suppress.test.js index ec2c797b0..fa5cb14a8 100644 --- a/e2e/fallback/suppress.test.js +++ b/e2e/fallback/suppress.test.js @@ -13,7 +13,7 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line test('warning', () => { // missing warning only! expect(warnings[0]).toEqual( - `[vue-i18n] Not found 'message.hello' key in 'ja' locale messages.` + `[intlify] Not found 'message.hello' key in 'ja' locale messages.` ) }) diff --git a/e2e/missing/handler.test.js b/e2e/missing/handler.test.js index cc0d04a69..258277500 100644 --- a/e2e/missing/handler.test.js +++ b/e2e/missing/handler.test.js @@ -15,7 +15,7 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line expect(warnings[0]).toEqual(`detect 'message.hello' key missing in 'ja'`) // fallback warning expect(warnings[1]).toEqual( - `[vue-i18n] Fall back to translate 'message.hello' key with 'en' locale.` + `[intlify] Fall back to translate 'message.hello' key with 'en' locale.` ) }) diff --git a/e2e/missing/option.test.js b/e2e/missing/option.test.js index 85279377a..5786f36bd 100644 --- a/e2e/missing/option.test.js +++ b/e2e/missing/option.test.js @@ -13,7 +13,7 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line test('warning', () => { // fallback warning only expect(warnings[0]).toEqual( - `[vue-i18n] Fall back to translate 'message.hello' key with 'en' locale.` + `[intlify] Fall back to translate 'message.hello' key with 'en' locale.` ) }) diff --git a/e2e/missing/suppress.test.js b/e2e/missing/suppress.test.js index ed39b5e96..fed1a4552 100644 --- a/e2e/missing/suppress.test.js +++ b/e2e/missing/suppress.test.js @@ -13,7 +13,7 @@ const { setupWarningConsole } = require('../helper') // eslint-disable-line test('warning', () => { // fallback warning only expect(warnings[0]).toEqual( - `[vue-i18n] Fall back to translate 'message.hello' key with 'en' locale.` + `[intlify] Fall back to translate 'message.hello' key with 'en' locale.` ) }) diff --git a/jest.config.js b/jest.config.js index f5bfba14f..8595eafe9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -67,7 +67,6 @@ module.exports = { __BROWSER__: false, __GLOBAL__: false, __RUNTIME__: false, - __WARN_LABEL__: `'vue-i18n'`, __BUNDLE_FILENAME__: 'test.bundle.js', __ESM_BUNDLER__: true, __ESM_BROWSER__: false, diff --git a/packages/core-base/package.json b/packages/core-base/package.json index 930b1a5c4..68e129932 100644 --- a/packages/core-base/package.json +++ b/packages/core-base/package.json @@ -23,7 +23,10 @@ "bugs": { "url": "https://github.com/intlify/vue-i18n-next/issues" }, - "files": ["index.js", "dist"], + "files": [ + "index.js", + "dist" + ], "main": "index.js", "module": "dist/core-base.esm-bundler.js", "unpkg": "dist/core-base.global.js", @@ -40,7 +43,12 @@ }, "buildOptions": { "name": "IntlifyCoreBase", - "formats": ["esm-bundler", "esm-browser", "cjs", "global"] + "formats": [ + "esm-bundler", + "esm-browser", + "cjs", + "global" + ] }, "sideEffects": false } diff --git a/packages/core-base/src/translate.ts b/packages/core-base/src/translate.ts index f90a767de..d024f3311 100644 --- a/packages/core-base/src/translate.ts +++ b/packages/core-base/src/translate.ts @@ -293,7 +293,10 @@ export function translate( if (__DEV__ && isString(format) && context.messageCompiler == null) { warn( - `Message format compilation is not supported in this build, because message compiler isn't included, you need to pre-compilation all message format.` + `The message format compilation is not supported in this build. ` + + `Because message compiler isn't included. ` + + `You need to pre-compilation all message format. ` + + `So translate function return '${key}'.` ) return key as MessageType } diff --git a/packages/core/package.json b/packages/core/package.json index 9794e228f..a2b7bbad9 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -23,9 +23,12 @@ "bugs": { "url": "https://github.com/intlify/vue-i18n-next/issues" }, - "files": ["index.js", "dist"], + "files": [ + "index.js", + "dist" + ], "main": "index.js", - "module": "dist/core.esm-bundler.js", + "module": "dist/core.runtime.esm-bundler.js", "unpkg": "dist/core.global.js", "jsdelivr": "dist/core.global.js", "types": "dist/core.d.ts", diff --git a/packages/global.d.ts b/packages/global.d.ts index ee7157147..c0652dd36 100644 --- a/packages/global.d.ts +++ b/packages/global.d.ts @@ -7,7 +7,6 @@ declare let __RUNTIME__: boolean declare let __ESM_BUNDLER__: boolean declare let __NODE_JS__: boolean declare let __VERSION__: string -declare let __WARN_LABEL__: string declare let __BUNDLE_FILENAME__: string declare let __COMMIT__: string diff --git a/packages/message-compiler/package.json b/packages/message-compiler/package.json index 187f2b92f..0893dd8a0 100644 --- a/packages/message-compiler/package.json +++ b/packages/message-compiler/package.json @@ -23,7 +23,10 @@ "bugs": { "url": "https://github.com/intlify/vue-i18n-next/issues" }, - "files": ["index.js", "dist"], + "files": [ + "index.js", + "dist" + ], "main": "index.js", "module": "dist/message-compiler.esm-bundler.js", "unpkg": "dist/message-compiler.global.js", @@ -39,7 +42,12 @@ }, "buildOptions": { "name": "IntlifyMessageCompiler", - "formats": ["esm-bundler", "esm-browser", "cjs", "global"] + "formats": [ + "esm-bundler", + "esm-browser", + "cjs", + "global" + ] }, "sideEffects": false } diff --git a/packages/runtime/package.json b/packages/runtime/package.json index 71fde13ad..9d950f0c3 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -2,7 +2,12 @@ "name": "@intlify/runtime", "version": "9.0.0-beta.14", "description": "@intlify/runtime", - "keywords": ["i18n", "internationalization", "intlify", "runtime"], + "keywords": [ + "i18n", + "internationalization", + "intlify", + "runtime" + ], "license": "MIT", "author": { "name": "kazuya kawaguchi", @@ -17,7 +22,10 @@ "bugs": { "url": "https://github.com/intlify/vue-i18n-next/issues" }, - "files": ["index.js", "dist"], + "files": [ + "index.js", + "dist" + ], "main": "index.js", "module": "dist/runtime.esm-bundler.js", "types": "dist/runtime.d.ts", @@ -31,7 +39,10 @@ }, "buildOptions": { "name": "IntlifyRuntime", - "formats": ["esm-bundler", "cjs"] + "formats": [ + "esm-bundler", + "cjs" + ] }, "sideEffects": false } diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index b7bbcbbb6..8fb5a22b4 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -79,8 +79,7 @@ export const isEmptyObject = (val: unknown): val is boolean => export function warn(msg: string, err?: Error): void { if (typeof console !== 'undefined') { - const label = __WARN_LABEL__ ? __WARN_LABEL__ : 'intlify' - console.warn(`[${label}] ` + msg) + console.warn(`[intlify] ` + msg) /* istanbul ignore if */ if (err) { console.warn(err.stack) diff --git a/packages/vue-i18n/package.json b/packages/vue-i18n/package.json index 57db33de4..93332fc2e 100644 --- a/packages/vue-i18n/package.json +++ b/packages/vue-i18n/package.json @@ -24,9 +24,12 @@ "bugs": { "url": "https://github.com/intlify/vue-i18n-next/issues" }, - "files": ["index.js", "dist"], + "files": [ + "index.js", + "dist" + ], "main": "index.js", - "module": "dist/vue-i18n.esm-bundler.js", + "module": "dist/vue-i18n.runtime.esm-bundler.js", "unpkg": "dist/vue-i18n.global.js", "jsdelivr": "dist/vue-i18n.global.js", "types": "dist/vue-i18n.d.ts", diff --git a/rollup.config.js b/rollup.config.js index 8ffb0dcd6..410676970 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -174,7 +174,6 @@ function createConfig(format, output, plugins = []) { isGlobalBuild, isNodeBuild, isRuntimeOnlyBuild, - name === 'vue-i18n' ? name : 'intlify', path.parse(output.file).base || '' ), ...nodePlugins, @@ -200,7 +199,6 @@ function createReplacePlugin( isGlobalBuild, isNodeBuild, isRuntimeOnlyBuild, - warnLabel, bundleFilename ) { const replacements = { @@ -218,8 +216,6 @@ function createReplacePlugin( __GLOBAL__: isGlobalBuild, // for runtime only __RUNTIME__: isRuntimeOnlyBuild, - // warning label - __WARN_LABEL__: `'${warnLabel}'`, // bundle filename __BUNDLE_FILENAME__: `'${bundleFilename}'`, __ESM_BUNDLER__: isBundlerESMBuild,