diff --git a/packages/core-base/package.json b/packages/core-base/package.json index 51c561386..3f07ab205 100644 --- a/packages/core-base/package.json +++ b/packages/core-base/package.json @@ -37,8 +37,7 @@ "@intlify/shared": "workspace:*" }, "devDependencies": { - "@intlify/devtools-if": "workspace:*", - "@intlify/vue-devtools": "workspace:*" + "@intlify/devtools-types": "workspace:*" }, "engines": { "node": ">= 16" diff --git a/packages/core-base/src/context.ts b/packages/core-base/src/context.ts index 24e97a976..051655fb2 100644 --- a/packages/core-base/src/context.ts +++ b/packages/core-base/src/context.ts @@ -12,16 +12,13 @@ import { isObject, warnOnce } from '@intlify/shared' -import { VueDevToolsTimelineEvents } from '@intlify/vue-devtools' import { initI18nDevTools } from './devtools' import { CoreWarnCodes, getWarnMessage } from './warnings' import { resolveWithKeyValue } from './resolver' import { fallbackWithSimple } from './fallbacker' import type { CompileOptions, ResourceNode } from '@intlify/message-compiler' -// HACK: embbed `@intlify/vue-devtools` types to `.d.ts`, because `@intlify/dev-tools` is devDependencies -// TODO: Consider this type dependency when separating into intlify/core -import type { VueDevToolsEmitter } from '../../vue-devtools/src/index' +import type { VueDevToolsEmitter } from '@intlify/devtools-types' import type { Path, MessageResolver } from './resolver' import type { Locale, @@ -661,7 +658,7 @@ export function handleMissing( if (__DEV__) { const emitter = (context as unknown as CoreInternalContext).__v_emitter if (emitter) { - emitter.emit(VueDevToolsTimelineEvents.MISSING, { + emitter.emit('missing', { locale, key, type, diff --git a/packages/core-base/src/datetime.ts b/packages/core-base/src/datetime.ts index 0b9dbb771..d0f545d8f 100644 --- a/packages/core-base/src/datetime.ts +++ b/packages/core-base/src/datetime.ts @@ -17,7 +17,6 @@ import { CoreWarnCodes, getWarnMessage } from './warnings' import { CoreErrorCodes, createCoreError } from './errors' import { getLocale } from './fallbacker' import { Availabilities } from './intl' -import { VueDevToolsTimelineEvents } from '@intlify/vue-devtools' import type { Locale, FallbackLocale } from './runtime' import type { @@ -254,7 +253,7 @@ export function datetime< if (__DEV__ && locale !== targetLocale) { const emitter = (context as unknown as CoreInternalContext).__v_emitter if (emitter) { - emitter.emit(VueDevToolsTimelineEvents.FALBACK, { + emitter.emit('fallback', { type, key, from, diff --git a/packages/core-base/src/devtools.ts b/packages/core-base/src/devtools.ts index 8f9c86645..eefa77038 100644 --- a/packages/core-base/src/devtools.ts +++ b/packages/core-base/src/devtools.ts @@ -1,10 +1,8 @@ -// HACK: embbed `@intlify/devtools-if` enum and type to `.d.ts`, because `@intlify/dev-tools` is devDependencies -// TODO: Consider this type dependency when separating into intlify/core -import { +import type { IntlifyDevToolsHooks, - IntlifyDevToolsEmitter, - IntlifyDevToolsHookPayloads -} from '../../devtools-if/src/index' + IntlifyDevToolsHookPayloads, + IntlifyDevToolsEmitter +} from '@intlify/devtools-types' let devtools: IntlifyDevToolsEmitter | null = null @@ -23,7 +21,7 @@ export function initI18nDevTools( ): void { // TODO: queue if devtools is undefined devtools && - devtools.emit(IntlifyDevToolsHooks.I18nInit, { + devtools.emit('i18n:init', { timestamp: Date.now(), i18n, version, @@ -31,9 +29,8 @@ export function initI18nDevTools( }) } -export const translateDevTools = /* #__PURE__*/ createDevToolsHook( - IntlifyDevToolsHooks.FunctionTranslate -) +export const translateDevTools = + /* #__PURE__*/ createDevToolsHook('function:translate') function createDevToolsHook(hook: IntlifyDevToolsHooks) { return (payloads: IntlifyDevToolsHookPayloads[IntlifyDevToolsHooks]) => diff --git a/packages/core-base/src/number.ts b/packages/core-base/src/number.ts index ab1aa07ba..4415a9504 100644 --- a/packages/core-base/src/number.ts +++ b/packages/core-base/src/number.ts @@ -16,7 +16,6 @@ import { CoreWarnCodes, getWarnMessage } from './warnings' import { CoreErrorCodes, createCoreError } from './errors' import { Availabilities } from './intl' import { getLocale } from './fallbacker' -import { VueDevToolsTimelineEvents } from '@intlify/vue-devtools' import type { Locale, FallbackLocale } from './runtime' import type { @@ -249,7 +248,7 @@ export function number< if (__DEV__ && locale !== targetLocale) { const emitter = (context as unknown as CoreInternalContext).__v_emitter if (emitter) { - emitter.emit(VueDevToolsTimelineEvents.FALBACK, { + emitter.emit('fallback', { type, key, from, diff --git a/packages/core-base/src/translate.ts b/packages/core-base/src/translate.ts index 496664c0f..e15860364 100644 --- a/packages/core-base/src/translate.ts +++ b/packages/core-base/src/translate.ts @@ -31,10 +31,9 @@ import { CoreWarnCodes, getWarnMessage } from './warnings' import { CoreErrorCodes, createCoreError } from './errors' import { translateDevTools } from './devtools' import { getLocale } from './fallbacker' -import { VueDevToolsTimelineEvents } from '@intlify/vue-devtools' import type { CompileError, ResourceNode } from '@intlify/message-compiler' -import type { AdditionalPayloads } from '@intlify/devtools-if' +import type { AdditionalPayloads } from '@intlify/devtools-types' import type { Path, PathValue } from './resolver' import type { Locale, @@ -856,7 +855,7 @@ function resolveMessageFormat( if (__DEV__ && locale !== targetLocale) { const emitter = (context as unknown as CoreInternalContext).__v_emitter if (emitter) { - emitter.emit(VueDevToolsTimelineEvents.FALBACK, { + emitter.emit('fallback', { type, key, from, @@ -890,8 +889,8 @@ function resolveMessageFormat( const end = window.performance.now() const emitter = (context as unknown as CoreInternalContext).__v_emitter if (emitter && start && format) { - emitter.emit(VueDevToolsTimelineEvents.MESSAGE_RESOLVE, { - type: VueDevToolsTimelineEvents.MESSAGE_RESOLVE, + emitter.emit('message-resolve', { + type: 'message-resolve', key, message: format, time: end - start, @@ -978,8 +977,8 @@ function compileMessageFormat( const end = window.performance.now() const emitter = (context as unknown as CoreInternalContext).__v_emitter if (emitter && start) { - emitter.emit(VueDevToolsTimelineEvents.MESSAGE_COMPILATION, { - type: VueDevToolsTimelineEvents.MESSAGE_COMPILATION, + emitter.emit('message-compilation', { + type: 'message-compilation', message: format as string | ResourceNode | MessageFunction, time: end - start, groupId: `${'translate'}:${key}` @@ -1021,8 +1020,8 @@ function evaluateMessage( const end = window.performance.now() const emitter = (context as unknown as CoreInternalContext).__v_emitter if (emitter && start) { - emitter.emit(VueDevToolsTimelineEvents.MESSAGE_EVALUATION, { - type: VueDevToolsTimelineEvents.MESSAGE_EVALUATION, + emitter.emit('message-evaluation', { + type: 'message-evaluation', value: messaged, time: end - start, groupId: `${'translate'}:${(msg as MessageFunctionInternal).key}` @@ -1108,7 +1107,7 @@ function getCompileContext( ) const emitter = (context as unknown as CoreInternalContext).__v_emitter if (emitter && _source) { - emitter.emit(VueDevToolsTimelineEvents.COMPILE_ERROR, { + emitter.emit('compile-error', { message: _source, error: err.message, start: err.location && err.location.start.offset, diff --git a/packages/core-base/test/devtools.test.ts b/packages/core-base/test/devtools.test.ts index 7aa5ad464..dad4dc5ba 100644 --- a/packages/core-base/test/devtools.test.ts +++ b/packages/core-base/test/devtools.test.ts @@ -1,13 +1,12 @@ -import { createCoreContext, translate } from '../src/index' import { createEmitter } from '@intlify/shared' +import { createCoreContext, translate } from '../src/index' import { compileToFunction } from '../src/compilation' -import { IntlifyDevToolsHooks } from '@intlify/devtools-if' import { setDevToolsHook, getDevToolsHook } from '../src/devtools' import type { IntlifyDevToolsEmitterHooks, IntlifyDevToolsEmitter -} from '@intlify/devtools-if' +} from '@intlify/devtools-types' let devtools: IntlifyDevToolsEmitter | null = null beforeEach(() => { @@ -23,7 +22,7 @@ afterEach(() => { test('initI18nDevTools', () => { const fn = vi.fn() - devtools!.on(IntlifyDevToolsHooks.I18nInit, fn) + devtools!.on('i18n:init', fn) const meta = { framework: 'Vue' } const ctx = createCoreContext({ @@ -46,7 +45,7 @@ test('initI18nDevTools', () => { describe('translateDevTools', () => { test('basic', () => { const fn = vi.fn() - devtools!.on(IntlifyDevToolsHooks.FunctionTranslate, fn) + devtools!.on('function:translate', fn) const meta = { __INTLIFY_META__: 'xxx', framework: 'Vue' } const HELLO = 'Hello {name}!' @@ -73,7 +72,7 @@ describe('translateDevTools', () => { test('fallback', () => { const fn = vi.fn() - devtools!.on(IntlifyDevToolsHooks.FunctionTranslate, fn) + devtools!.on('function:translate', fn) const HELLO = 'やあ {name}!' const ctx = createCoreContext({ diff --git a/packages/devtools-if/README.md b/packages/devtools-if/README.md deleted file mode 100644 index cb09235df..000000000 --- a/packages/devtools-if/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# @intlify/devtools-if - -The [`@intlify/devtools`](https://github.com/intlify/devtools) interface(I/F:if) for intlify projects - -## :warning: NOTE: - -This is experimental. - -Don’t use in production yet. - -## :copyright: License - -[MIT](http://opensource.org/licenses/MIT) diff --git a/packages/devtools-if/index.js b/packages/devtools-if/index.js deleted file mode 100644 index 42f9e56ec..000000000 --- a/packages/devtools-if/index.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict' - -if (process.env.NODE_ENV === 'production') { - module.exports = require('./dist/devtools-if.prod.cjs') -} else { - module.exports = require('./dist/devtools-if.cjs') -} diff --git a/packages/devtools-if/package.json b/packages/devtools-if/package.json deleted file mode 100644 index 707ff321f..000000000 --- a/packages/devtools-if/package.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "name": "@intlify/devtools-if", - "version": "10.0.0-alpha.2", - "description": "@intlify/devtools-if", - "keywords": [ - "devtools", - "i18n", - "internationalization", - "intlify" - ], - "license": "MIT", - "author": { - "name": "kazuya kawaguchi", - "email": "kawakazu80@gmail.com" - }, - "homepage": "https://github.com/intlify/vue-i18n-next/tree/master/packages/devtools-if#readme", - "repository": { - "type": "git", - "url": "git+https://github.com/intlify/vue-i18n-next.git", - "directory": "packages/devtools-if" - }, - "bugs": { - "url": "https://github.com/intlify/vue-i18n-next/issues" - }, - "files": [ - "index.js", - "dist" - ], - "main": "index.js", - "module": "dist/devtools-if.mjs", - "types": "dist/devtools-if.d.ts", - "dependencies": { - "@intlify/shared": "workspace:*" - }, - "engines": { - "node": ">= 16" - }, - "buildOptions": { - "name": "IntlifyDevToolsIf", - "formats": [ - "mjs", - "cjs" - ] - }, - "exports": { - ".": { - "types": "./dist/devtools-if.d.ts", - "import": "./dist/devtools-if.mjs", - "node": { - "import": { - "production": "./dist/devtools-if.prod.cjs", - "development": "./dist/devtools-if.mjs", - "default": "./dist/devtools-if.mjs" - }, - "require": { - "production": "./dist/devtools-if.prod.cjs", - "development": "./dist/devtools-if.cjs", - "default": "./index.js" - } - } - }, - "./dist/*": "./dist/*", - "./package.json": "./package.json" - }, - "funding": "https://github.com/sponsors/kazupon", - "publishConfig": { - "access": "public" - }, - "sideEffects": false -} diff --git a/packages/devtools-if/src/index.ts b/packages/devtools-if/src/index.ts deleted file mode 100644 index b0b855596..000000000 --- a/packages/devtools-if/src/index.ts +++ /dev/null @@ -1,42 +0,0 @@ -import type { Emittable } from '@intlify/shared' - -export interface IntlifyRecord { - id: number - i18n: unknown // TODO: - version: string - types: Record // TODO -} - -export const enum IntlifyDevToolsHooks { - I18nInit = 'i18n:init', - FunctionTranslate = 'function:translate' -} - -export type AdditionalPayloads = { - meta?: Record -} - -// export type IntlifyDevToolsHooks = -// (typeof IntlifyDevToolsHooks)[keyof typeof IntlifyDevToolsHooks] - -export type IntlifyDevToolsHookPayloads = { - [IntlifyDevToolsHooks.I18nInit]: { - timestamp: number - i18n: unknown // TODO: - version: string - } & AdditionalPayloads - [IntlifyDevToolsHooks.FunctionTranslate]: { - timestamp: number - message: string | number - key: string - locale: string - format?: string - } & AdditionalPayloads -} - -export type IntlifyDevToolsEmitterHooks = { - [IntlifyDevToolsHooks.I18nInit]: IntlifyDevToolsHookPayloads[IntlifyDevToolsHooks.I18nInit] - [IntlifyDevToolsHooks.FunctionTranslate]: IntlifyDevToolsHookPayloads[IntlifyDevToolsHooks.FunctionTranslate] -} - -export type IntlifyDevToolsEmitter = Emittable diff --git a/packages/devtools-if/test/.gitkeep b/packages/devtools-if/test/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/devtools-if/LICENSE b/packages/devtools-types/LICENSE similarity index 96% rename from packages/devtools-if/LICENSE rename to packages/devtools-types/LICENSE index d50c49b4d..c69bf0cfd 100644 --- a/packages/devtools-if/LICENSE +++ b/packages/devtools-types/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2021 kazuya kawaguchi +Copyright (c) 2024 kazuya kawaguchi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/packages/devtools-types/README.md b/packages/devtools-types/README.md new file mode 100644 index 000000000..4248f8440 --- /dev/null +++ b/packages/devtools-types/README.md @@ -0,0 +1,5 @@ +# @intlify/devtools-types + +## :copyright: License + +[MIT](http://opensource.org/licenses/MIT) diff --git a/packages/devtools-if/api-extractor.json b/packages/devtools-types/api-extractor.json similarity index 100% rename from packages/devtools-if/api-extractor.json rename to packages/devtools-types/api-extractor.json diff --git a/packages/devtools-types/index.js b/packages/devtools-types/index.js new file mode 100644 index 000000000..d64c0e375 --- /dev/null +++ b/packages/devtools-types/index.js @@ -0,0 +1,7 @@ +'use strict' + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./dist/devtools-types.prod.cjs') +} else { + module.exports = require('./dist/devtools-types.cjs') +} diff --git a/packages/vue-devtools/package.json b/packages/devtools-types/package.json similarity index 61% rename from packages/vue-devtools/package.json rename to packages/devtools-types/package.json index 91dad7670..fe477a5f3 100644 --- a/packages/vue-devtools/package.json +++ b/packages/devtools-types/package.json @@ -1,23 +1,23 @@ { - "name": "@intlify/vue-devtools", + "name": "@intlify/devtools-types", "version": "10.0.0-alpha.2", - "description": "@intlify/vue-devtools", + "description": "@intlify/devtools-types", "keywords": [ + "devtools", "i18n", "internationalization", - "intlify", - "vue-devtools" + "intlify" ], "license": "MIT", "author": { "name": "kazuya kawaguchi", "email": "kawakazu80@gmail.com" }, - "homepage": "https://github.com/intlify/vue-i18n-next/tree/master/packages/vue-devtools#readme", + "homepage": "https://github.com/intlify/vue-i18n-next/tree/master/packages/devtools-types#readme", "repository": { "type": "git", "url": "git+https://github.com/intlify/vue-i18n-next.git", - "directory": "packages/vue-devtools" + "directory": "packages/devtools-types" }, "bugs": { "url": "https://github.com/intlify/vue-i18n-next/issues" @@ -27,8 +27,8 @@ "dist" ], "main": "index.js", - "module": "dist/vue-devtools.mjs", - "types": "dist/vue-devtools.d.ts", + "module": "dist/devtools-types.mjs", + "types": "dist/devtools-types.d.ts", "dependencies": { "@intlify/core-base": "workspace:*", "@intlify/shared": "workspace:*" @@ -37,7 +37,7 @@ "node": ">= 16" }, "buildOptions": { - "name": "IntlifyVueDevtools", + "name": "IntlifyDevToolsTypes", "formats": [ "mjs", "cjs" @@ -45,17 +45,17 @@ }, "exports": { ".": { - "types": "./dist/vue-devtools.d.ts", - "import": "./dist/vue-devtools.mjs", + "types": "./dist/devtools-types.d.ts", + "import": "./dist/devtools-types.mjs", "node": { "import": { - "production": "./dist/vue-devtools.prod.cjs", - "development": "./dist/vue-devtools.mjs", - "default": "./dist/vue-devtools.mjs" + "production": "./dist/devtools-types.prod.cjs", + "development": "./dist/devtools-types.mjs", + "default": "./dist/devtools-types.mjs" }, "require": { - "production": "./dist/vue-devtools.prod.cjs", - "development": "./dist/vue-devtools.cjs", + "production": "./dist/devtools-types.prod.cjs", + "development": "./dist/devtools-types.cjs", "default": "./index.js" } } diff --git a/packages/devtools-types/src/index.ts b/packages/devtools-types/src/index.ts new file mode 100644 index 000000000..f5ea14935 --- /dev/null +++ b/packages/devtools-types/src/index.ts @@ -0,0 +1,110 @@ +import type { Emittable } from '@intlify/shared' +import type { + Path, + PathValue, + Locale, + MessageFunction, + ResourceNode, + CoreMissingType +} from '@intlify/core-base' + +export interface IntlifyRecord { + id: number + i18n: unknown // TODO: + version: string + types: Record // TODO +} + +export type IntlifyDevToolsHooks = 'i18n:init' | 'function:translate' + +export type AdditionalPayloads = { + meta?: Record +} + +export type IntlifyDevToolsHookPayloads = { + 'i18n:init': { + timestamp: number + i18n: unknown // TODO: + version: string + } & AdditionalPayloads + 'function:translate': { + timestamp: number + message: string | number + key: string + locale: string + format?: string + } & AdditionalPayloads +} + +export type IntlifyDevToolsEmitterHooks = { + 'i18n:init': IntlifyDevToolsHookPayloads['i18n:init'] + 'function:translate': IntlifyDevToolsHookPayloads['function:translate'] +} + +export type IntlifyDevToolsEmitter = Emittable + +export type VueDevToolsIDs = + | 'vue-devtools-plugin-vue-i18n' + | 'vue-i18n-resource-inspector' + | 'vue-i18n-timeline' + +export type VueDevToolsTimelineEvents = + | 'compile-error' + | 'missing' + | 'fallback' + | 'message-resolve' + | 'message-compilation' + | 'message-evaluation' + +export type VueDevToolsTimelineEventPayloads = { + 'compile-error': { + message: string + error: string + start?: number + end?: number + groupId?: string + } + missing: { + locale: Locale + key: Path + type: CoreMissingType + groupId?: string + } + fallback: { + key: Path + type: CoreMissingType + from?: Locale + to: Locale | 'global' + groupId?: string + } + 'message-resolve': { + type: 'message-resolve' + key: Path + message: PathValue + time: number + groupId?: string + } + 'message-compilation': { + type: 'message-compilation' + message: string | ResourceNode | MessageFunction + time: number + groupId?: string + } + 'message-evaluation': { + type: 'message-evaluation' + value: unknown + time: number + groupId?: string + } +} + +export type VueDevToolsEmitterEvents = { + 'compile-error': VueDevToolsTimelineEventPayloads['compile-error'] + missing: VueDevToolsTimelineEventPayloads['missing'] + fallback: VueDevToolsTimelineEventPayloads['fallback'] + 'message-resolve': VueDevToolsTimelineEventPayloads['message-resolve'] + 'message-compilation': VueDevToolsTimelineEventPayloads['message-compilation'] + 'message-evaluation': VueDevToolsTimelineEventPayloads['message-evaluation'] +} + +export type VueDevToolsEmitter = Emittable diff --git a/packages/petite-vue-i18n/package.json b/packages/petite-vue-i18n/package.json index 0a51b6acf..90cfaab8b 100644 --- a/packages/petite-vue-i18n/package.json +++ b/packages/petite-vue-i18n/package.json @@ -37,11 +37,10 @@ "dependencies": { "@intlify/core-base": "workspace:*", "@intlify/shared": "workspace:*", - "@intlify/vue-devtools": "workspace:*", "@vue/devtools-api": "^6.5.0" }, "devDependencies": { - "@intlify/devtools-if": "workspace:*" + "@intlify/devtools-types": "workspace:*" }, "peerDependencies": { "vue": "^3.0.0" diff --git a/packages/vue-devtools/LICENSE b/packages/vue-devtools/LICENSE deleted file mode 100644 index d50c49b4d..000000000 --- a/packages/vue-devtools/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2021 kazuya kawaguchi - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/vue-devtools/README.md b/packages/vue-devtools/README.md deleted file mode 100644 index 6df4fe77c..000000000 --- a/packages/vue-devtools/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# @intlify/vue-devtools - -The Vue DevTools I/F package for intlify project - -## :copyright: License - -[MIT](http://opensource.org/licenses/MIT) diff --git a/packages/vue-devtools/api-extractor.json b/packages/vue-devtools/api-extractor.json deleted file mode 100644 index 5602b3a6f..000000000 --- a/packages/vue-devtools/api-extractor.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../api-extractor.json", - "mainEntryPointFilePath": "./dist/packages//src/index.d.ts", - "dtsRollup": { - "publicTrimmedFilePath": "./dist/.d.ts" - } -} diff --git a/packages/vue-devtools/index.js b/packages/vue-devtools/index.js deleted file mode 100644 index 276c9ecc8..000000000 --- a/packages/vue-devtools/index.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict' - -if (process.env.NODE_ENV === 'production') { - module.exports = require('./dist/vue-devtools.prod.cjs') -} else { - module.exports = require('./dist/vue-devtools.cjs') -} diff --git a/packages/vue-devtools/src/index.ts b/packages/vue-devtools/src/index.ts deleted file mode 100644 index 69167b624..000000000 --- a/packages/vue-devtools/src/index.ts +++ /dev/null @@ -1,90 +0,0 @@ -import type { Emittable } from '@intlify/shared' -import type { - Path, - PathValue, - Locale, - MessageFunction, - ResourceNode, - CoreMissingType -} from '@intlify/core-base' - -export const enum VueDevToolsIDs { - PLUGIN = 'vue-devtools-plugin-vue-i18n', - CUSTOM_INSPECTOR = 'vue-i18n-resource-inspector', - TIMELINE = 'vue-i18n-timeline' -} - -export const VueDevToolsLabels: Record = { - [VueDevToolsIDs.PLUGIN]: 'Vue I18n devtools', - [VueDevToolsIDs.CUSTOM_INSPECTOR]: 'I18n Resources', - [VueDevToolsIDs.TIMELINE]: 'Vue I18n' -} - -export const VueDevToolsPlaceholders: Record = { - [VueDevToolsIDs.CUSTOM_INSPECTOR]: 'Search for scopes ...' -} - -export const VueDevToolsTimelineColors: Record = { - [VueDevToolsIDs.TIMELINE]: 0xffcd19 -} - -export const enum VueDevToolsTimelineEvents { - COMPILE_ERROR = 'compile-error', - MISSING = 'missing', - FALBACK = 'fallback', - MESSAGE_RESOLVE = 'message-resolve', - MESSAGE_COMPILATION = 'message-compilation', - MESSAGE_EVALUATION = 'message-evaluation' -} - -export type VueDevToolsTimelineEventPayloads = { - [VueDevToolsTimelineEvents.COMPILE_ERROR]: { - message: string - error: string - start?: number - end?: number - groupId?: string - } - [VueDevToolsTimelineEvents.MISSING]: { - locale: Locale - key: Path - type: CoreMissingType - groupId?: string - } - [VueDevToolsTimelineEvents.FALBACK]: { - key: Path - type: CoreMissingType - from?: Locale - to: Locale | 'global' - groupId?: string - } - [VueDevToolsTimelineEvents.MESSAGE_RESOLVE]: { - type: VueDevToolsTimelineEvents.MESSAGE_RESOLVE - key: Path - message: PathValue - time: number - groupId?: string - } - [VueDevToolsTimelineEvents.MESSAGE_COMPILATION]: { - type: VueDevToolsTimelineEvents.MESSAGE_COMPILATION - message: string | ResourceNode | MessageFunction - time: number - groupId?: string - } - [VueDevToolsTimelineEvents.MESSAGE_EVALUATION]: { - type: VueDevToolsTimelineEvents.MESSAGE_EVALUATION - value: unknown - time: number - groupId?: string - } -} - -export type VueDevToolsEmitterEvents = { - [VueDevToolsTimelineEvents.COMPILE_ERROR]: VueDevToolsTimelineEventPayloads[VueDevToolsTimelineEvents.COMPILE_ERROR] - [VueDevToolsTimelineEvents.MISSING]: VueDevToolsTimelineEventPayloads[VueDevToolsTimelineEvents.MISSING] - [VueDevToolsTimelineEvents.FALBACK]: VueDevToolsTimelineEventPayloads[VueDevToolsTimelineEvents.FALBACK] - [VueDevToolsTimelineEvents.MESSAGE_RESOLVE]: VueDevToolsTimelineEventPayloads[VueDevToolsTimelineEvents.MESSAGE_RESOLVE] - [VueDevToolsTimelineEvents.MESSAGE_COMPILATION]: VueDevToolsTimelineEventPayloads[VueDevToolsTimelineEvents.MESSAGE_COMPILATION] - [VueDevToolsTimelineEvents.MESSAGE_EVALUATION]: VueDevToolsTimelineEventPayloads[VueDevToolsTimelineEvents.MESSAGE_EVALUATION] -} -export type VueDevToolsEmitter = Emittable diff --git a/packages/vue-i18n-core/package.json b/packages/vue-i18n-core/package.json index 25afcd8c1..6183721c5 100644 --- a/packages/vue-i18n-core/package.json +++ b/packages/vue-i18n-core/package.json @@ -37,11 +37,10 @@ "dependencies": { "@intlify/core-base": "workspace:*", "@intlify/shared": "workspace:*", - "@intlify/vue-devtools": "workspace:*", "@vue/devtools-api": "^6.5.0" }, "devDependencies": { - "@intlify/devtools-if": "workspace:*" + "@intlify/devtools-types": "workspace:*" }, "peerDependencies": { "vue": "^3.0.0" diff --git a/packages/vue-i18n-core/src/composer.ts b/packages/vue-i18n-core/src/composer.ts index 67ee01319..7c9124c44 100644 --- a/packages/vue-i18n-core/src/composer.ts +++ b/packages/vue-i18n-core/src/composer.ts @@ -40,7 +40,6 @@ import { isMessageAST, isMessageFunction } from '@intlify/core-base' -import { VueDevToolsTimelineEvents } from '@intlify/vue-devtools' import { I18nWarnCodes, getWarnMessage } from './warnings' import { I18nErrorCodes, createI18nError } from './errors' import { @@ -112,7 +111,7 @@ import type { IsEmptyObject, CoreMissingType } from '@intlify/core-base' -import type { VueDevToolsEmitter } from '@intlify/vue-devtools' +import type { VueDevToolsEmitter } from '@intlify/devtools-types' export { DEFAULT_LOCALE } from '@intlify/core-base' @@ -2185,7 +2184,7 @@ export function createComposer(options: any = {}): any { const { __v_emitter: emitter } = _context as unknown as CoreInternalContext if (emitter && _fallbackRoot) { - emitter.emit(VueDevToolsTimelineEvents.FALBACK, { + emitter.emit('fallback', { type: warnType, key, to: 'global', diff --git a/packages/vue-i18n-core/src/devtools.ts b/packages/vue-i18n-core/src/devtools.ts index 51589927d..7c33700e4 100644 --- a/packages/vue-i18n-core/src/devtools.ts +++ b/packages/vue-i18n-core/src/devtools.ts @@ -3,13 +3,6 @@ import { Hooks, ComponentTreeNode } from '@vue/devtools-api' -import { - VueDevToolsIDs, - VueDevToolsTimelineColors, - VueDevToolsLabels, - VueDevToolsPlaceholders, - VueDevToolsTimelineEvents -} from '@intlify/vue-devtools' import { isFunction, isString, @@ -27,7 +20,11 @@ import type { ComponentStateBase, HookPayloads } from '@vue/devtools-api' -import type { VueDevToolsTimelineEventPayloads } from '@intlify/vue-devtools' +import type { + VueDevToolsIDs, + VueDevToolsTimelineEvents, + VueDevToolsTimelineEventPayloads +} from '@intlify/devtools-types' import type { I18n, I18nInternal } from './i18n' import type { Composer } from './composer' import type { VueI18nInternal } from './legacy' @@ -36,6 +33,20 @@ type _I18n = I18n & I18nInternal const VUE_I18N_COMPONENT_TYPES = 'vue-i18n: composer properties' +const VueDevToolsLabels: Record = { + 'vue-devtools-plugin-vue-i18n': 'Vue I18n devtools', + 'vue-i18n-resource-inspector': 'I18n Resources', + 'vue-i18n-timeline': 'Vue I18n' +} + +const VueDevToolsPlaceholders: Record<'vue-i18n-resource-inspector', string> = { + 'vue-i18n-resource-inspector': 'Search for scopes ...' +} + +const VueDevToolsTimelineColors: Record<'vue-i18n-timeline', number> = { + 'vue-i18n-timeline': 0xffcd19 +} + let devtoolsApi: DevtoolsPluginApi<{}> export async function enableDevTools(app: App, i18n: _I18n): Promise { @@ -43,8 +54,8 @@ export async function enableDevTools(app: App, i18n: _I18n): Promise { try { setupDevtoolsPlugin( { - id: VueDevToolsIDs.PLUGIN, - label: VueDevToolsLabels[VueDevToolsIDs.PLUGIN], + id: 'vue-devtools-plugin-vue-i18n', + label: VueDevToolsLabels['vue-devtools-plugin-vue-i18n'], packageName: 'vue-i18n', homepage: 'https://vue-i18n.intlify.dev', logo: 'https://vue-i18n.intlify.dev/vue-i18n-devtools-logo.png', @@ -85,17 +96,17 @@ export async function enableDevTools(app: App, i18n: _I18n): Promise { }) api.addInspector({ - id: VueDevToolsIDs.CUSTOM_INSPECTOR, - label: VueDevToolsLabels[VueDevToolsIDs.CUSTOM_INSPECTOR], + id: 'vue-i18n-resource-inspector', + label: VueDevToolsLabels['vue-i18n-resource-inspector'], icon: 'language', treeFilterPlaceholder: - VueDevToolsPlaceholders[VueDevToolsIDs.CUSTOM_INSPECTOR] + VueDevToolsPlaceholders['vue-i18n-resource-inspector'] }) api.on.getInspectorTree(payload => { if ( payload.app === app && - payload.inspectorId === VueDevToolsIDs.CUSTOM_INSPECTOR + payload.inspectorId === 'vue-i18n-resource-inspector' ) { registerScope(payload, i18n) } @@ -105,7 +116,7 @@ export async function enableDevTools(app: App, i18n: _I18n): Promise { api.on.getInspectorState(async payload => { if ( payload.app === app && - payload.inspectorId === VueDevToolsIDs.CUSTOM_INSPECTOR + payload.inspectorId === 'vue-i18n-resource-inspector' ) { api.unhighlightElement() @@ -127,16 +138,16 @@ export async function enableDevTools(app: App, i18n: _I18n): Promise { api.on.editInspectorState(payload => { if ( payload.app === app && - payload.inspectorId === VueDevToolsIDs.CUSTOM_INSPECTOR + payload.inspectorId === 'vue-i18n-resource-inspector' ) { editScope(payload, i18n) } }) api.addTimelineLayer({ - id: VueDevToolsIDs.TIMELINE, - label: VueDevToolsLabels[VueDevToolsIDs.TIMELINE], - color: VueDevToolsTimelineColors[VueDevToolsIDs.TIMELINE] + id: 'vue-i18n-timeline', + label: VueDevToolsLabels['vue-i18n-timeline'], + color: VueDevToolsTimelineColors['vue-i18n-timeline'] }) resolve(true) @@ -435,7 +446,7 @@ export function addTimelineEvent( delete payload.groupId } devtoolsApi.addTimelineEvent({ - layerId: VueDevToolsIDs.TIMELINE, + layerId: 'vue-i18n-timeline', event: { title: event, groupId, @@ -443,10 +454,9 @@ export function addTimelineEvent( meta: {}, data: payload || {}, logType: - event === VueDevToolsTimelineEvents.COMPILE_ERROR + event === 'compile-error' ? 'error' - : event === VueDevToolsTimelineEvents.FALBACK || - event === VueDevToolsTimelineEvents.MISSING + : event === 'fallback' || event === 'missing' ? 'warning' : 'default' } diff --git a/packages/vue-i18n-core/src/i18n.ts b/packages/vue-i18n-core/src/i18n.ts index ddec2edc6..960989b0f 100644 --- a/packages/vue-i18n-core/src/i18n.ts +++ b/packages/vue-i18n-core/src/i18n.ts @@ -41,7 +41,7 @@ import type { import type { VueDevToolsEmitter, VueDevToolsEmitterEvents -} from '@intlify/vue-devtools' +} from '@intlify/devtools-types' import type { VueMessageType, DefaultLocaleMessageSchema, diff --git a/packages/vue-i18n-core/src/legacy.ts b/packages/vue-i18n-core/src/legacy.ts index 95d8c203d..6cb0c559d 100644 --- a/packages/vue-i18n-core/src/legacy.ts +++ b/packages/vue-i18n-core/src/legacy.ts @@ -48,7 +48,7 @@ import type { IsEmptyObject, IsNever } from '@intlify/core-base' -import type { VueDevToolsEmitter } from '@intlify/vue-devtools' +import type { VueDevToolsEmitter } from '@intlify/devtools-types' import type { VueMessageType, DefaultLocaleMessageSchema, diff --git a/packages/vue-i18n-core/src/mixins.ts b/packages/vue-i18n-core/src/mixins.ts index 722ef4b54..b35555fd4 100644 --- a/packages/vue-i18n-core/src/mixins.ts +++ b/packages/vue-i18n-core/src/mixins.ts @@ -12,7 +12,7 @@ import type { Locale, LocaleMessageValue } from '@intlify/core' import type { VueDevToolsEmitter, VueDevToolsEmitterEvents -} from '@intlify/vue-devtools' +} from '@intlify/devtools-types' import type { Composer, ComposerInternalOptions, diff --git a/packages/vue-i18n-core/test/i18n.test.ts b/packages/vue-i18n-core/test/i18n.test.ts index 7fa6203c2..031dcc93f 100644 --- a/packages/vue-i18n-core/test/i18n.test.ts +++ b/packages/vue-i18n-core/test/i18n.test.ts @@ -26,10 +26,7 @@ import { createI18n, useI18n } from '../src/i18n' import { errorMessages, I18nErrorCodes } from '../src/errors' import { Composer } from '../src/composer' -import { - IntlifyDevToolsEmitterHooks, - IntlifyDevToolsHooks -} from '@intlify/devtools-if' +import { IntlifyDevToolsEmitterHooks } from '@intlify/devtools-types' import type { I18n } from '../src/i18n' import type { VueI18n } from '../src/legacy' @@ -1177,8 +1174,8 @@ test('Intlify devtools hooking', () => { const fnI18nInit = vi.fn() const fnTranslate = vi.fn() - emitter.on(IntlifyDevToolsHooks.I18nInit, fnI18nInit) - emitter.on(IntlifyDevToolsHooks.FunctionTranslate, fnTranslate) + emitter.on('i18n:init', fnI18nInit) + emitter.on('function:translate', fnTranslate) const i18n = createI18n({ locale: 'en', diff --git a/packages/vue-i18n/package.json b/packages/vue-i18n/package.json index 37bc26e87..98eb98bc1 100644 --- a/packages/vue-i18n/package.json +++ b/packages/vue-i18n/package.json @@ -40,8 +40,7 @@ "@vue/devtools-api": "^6.5.0" }, "devDependencies": { - "@intlify/devtools-if": "workspace:*", - "@intlify/vue-devtools": "workspace:*" + "@intlify/devtools-types": "workspace:*" }, "peerDependencies": { "vue": "^3.0.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8fc572ed7..693daf855 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -514,15 +514,15 @@ importers: specifier: workspace:* version: link:../shared devDependencies: - '@intlify/devtools-if': + '@intlify/devtools-types': specifier: workspace:* - version: link:../devtools-if - '@intlify/vue-devtools': - specifier: workspace:* - version: link:../vue-devtools + version: link:../devtools-types - packages/devtools-if: + packages/devtools-types: dependencies: + '@intlify/core-base': + specifier: workspace:* + version: link:../core-base '@intlify/shared': specifier: workspace:* version: link:../shared @@ -569,9 +569,6 @@ importers: '@intlify/shared': specifier: workspace:* version: link:../shared - '@intlify/vue-devtools': - specifier: workspace:* - version: link:../vue-devtools '@vue/devtools-api': specifier: ^6.5.0 version: 6.5.1 @@ -579,9 +576,9 @@ importers: specifier: 3.4.25 version: 3.4.25(typescript@5.4.3) devDependencies: - '@intlify/devtools-if': + '@intlify/devtools-types': specifier: workspace:* - version: link:../devtools-if + version: link:../devtools-types packages/shared: {} @@ -639,15 +636,6 @@ importers: specifier: ^2.0.0 version: 2.0.0(typescript@5.4.3) - packages/vue-devtools: - dependencies: - '@intlify/core-base': - specifier: workspace:* - version: link:../core-base - '@intlify/shared': - specifier: workspace:* - version: link:../shared - packages/vue-i18n: dependencies: '@intlify/core-base': @@ -663,12 +651,9 @@ importers: specifier: 3.4.25 version: 3.4.25(typescript@5.4.3) devDependencies: - '@intlify/devtools-if': - specifier: workspace:* - version: link:../devtools-if - '@intlify/vue-devtools': + '@intlify/devtools-types': specifier: workspace:* - version: link:../vue-devtools + version: link:../devtools-types packages/vue-i18n-core: dependencies: @@ -678,9 +663,6 @@ importers: '@intlify/shared': specifier: workspace:* version: link:../shared - '@intlify/vue-devtools': - specifier: workspace:* - version: link:../vue-devtools '@vue/devtools-api': specifier: ^6.5.0 version: 6.5.1 @@ -688,9 +670,9 @@ importers: specifier: 3.4.25 version: 3.4.25(typescript@5.4.3) devDependencies: - '@intlify/devtools-if': + '@intlify/devtools-types': specifier: workspace:* - version: link:../devtools-if + version: link:../devtools-types packages: diff --git a/scripts/dist-tag.sh b/scripts/dist-tag.sh index 65523d9e8..b93d69a8f 100755 --- a/scripts/dist-tag.sh +++ b/scripts/dist-tag.sh @@ -8,10 +8,9 @@ TAG=$2 PKGS=( @intlify/core @intlify/core-base - @intlify/devtools-if + @intlify/devtools-types @intlify/message-compiler @intlify/shared - @intlify/vue-devtools @intlify/vue-i18n-core petite-vue-i18n vue-i18n