Skip to content

Commit 7f15c7b

Browse files
authored
fix: reduce devtools pkgs and size (#1823)
1 parent 16b78e3 commit 7f15c7b

34 files changed

+222
-390
lines changed

packages/core-base/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
"@intlify/shared": "workspace:*"
3838
},
3939
"devDependencies": {
40-
"@intlify/devtools-if": "workspace:*",
41-
"@intlify/vue-devtools": "workspace:*"
40+
"@intlify/devtools-types": "workspace:*"
4241
},
4342
"engines": {
4443
"node": ">= 16"

packages/core-base/src/context.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@ import {
1212
isObject,
1313
warnOnce
1414
} from '@intlify/shared'
15-
import { VueDevToolsTimelineEvents } from '@intlify/vue-devtools'
1615
import { initI18nDevTools } from './devtools'
1716
import { CoreWarnCodes, getWarnMessage } from './warnings'
1817
import { resolveWithKeyValue } from './resolver'
1918
import { fallbackWithSimple } from './fallbacker'
2019

2120
import type { CompileOptions, ResourceNode } from '@intlify/message-compiler'
22-
// HACK: embbed `@intlify/vue-devtools` types to `.d.ts`, because `@intlify/dev-tools` is devDependencies
23-
// TODO: Consider this type dependency when separating into intlify/core
24-
import type { VueDevToolsEmitter } from '../../vue-devtools/src/index'
21+
import type { VueDevToolsEmitter } from '@intlify/devtools-types'
2522
import type { Path, MessageResolver } from './resolver'
2623
import type {
2724
Locale,
@@ -661,7 +658,7 @@ export function handleMissing<Message = string>(
661658
if (__DEV__) {
662659
const emitter = (context as unknown as CoreInternalContext).__v_emitter
663660
if (emitter) {
664-
emitter.emit(VueDevToolsTimelineEvents.MISSING, {
661+
emitter.emit('missing', {
665662
locale,
666663
key,
667664
type,

packages/core-base/src/datetime.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { CoreWarnCodes, getWarnMessage } from './warnings'
1717
import { CoreErrorCodes, createCoreError } from './errors'
1818
import { getLocale } from './fallbacker'
1919
import { Availabilities } from './intl'
20-
import { VueDevToolsTimelineEvents } from '@intlify/vue-devtools'
2120

2221
import type { Locale, FallbackLocale } from './runtime'
2322
import type {
@@ -254,7 +253,7 @@ export function datetime<
254253
if (__DEV__ && locale !== targetLocale) {
255254
const emitter = (context as unknown as CoreInternalContext).__v_emitter
256255
if (emitter) {
257-
emitter.emit(VueDevToolsTimelineEvents.FALBACK, {
256+
emitter.emit('fallback', {
258257
type,
259258
key,
260259
from,

packages/core-base/src/devtools.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
// HACK: embbed `@intlify/devtools-if` enum and type to `.d.ts`, because `@intlify/dev-tools` is devDependencies
2-
// TODO: Consider this type dependency when separating into intlify/core
3-
import {
1+
import type {
42
IntlifyDevToolsHooks,
5-
IntlifyDevToolsEmitter,
6-
IntlifyDevToolsHookPayloads
7-
} from '../../devtools-if/src/index'
3+
IntlifyDevToolsHookPayloads,
4+
IntlifyDevToolsEmitter
5+
} from '@intlify/devtools-types'
86

97
let devtools: IntlifyDevToolsEmitter | null = null
108

@@ -23,17 +21,16 @@ export function initI18nDevTools(
2321
): void {
2422
// TODO: queue if devtools is undefined
2523
devtools &&
26-
devtools.emit(IntlifyDevToolsHooks.I18nInit, {
24+
devtools.emit('i18n:init', {
2725
timestamp: Date.now(),
2826
i18n,
2927
version,
3028
meta
3129
})
3230
}
3331

34-
export const translateDevTools = /* #__PURE__*/ createDevToolsHook(
35-
IntlifyDevToolsHooks.FunctionTranslate
36-
)
32+
export const translateDevTools =
33+
/* #__PURE__*/ createDevToolsHook('function:translate')
3734

3835
function createDevToolsHook(hook: IntlifyDevToolsHooks) {
3936
return (payloads: IntlifyDevToolsHookPayloads[IntlifyDevToolsHooks]) =>

packages/core-base/src/number.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { CoreWarnCodes, getWarnMessage } from './warnings'
1616
import { CoreErrorCodes, createCoreError } from './errors'
1717
import { Availabilities } from './intl'
1818
import { getLocale } from './fallbacker'
19-
import { VueDevToolsTimelineEvents } from '@intlify/vue-devtools'
2019

2120
import type { Locale, FallbackLocale } from './runtime'
2221
import type {
@@ -249,7 +248,7 @@ export function number<
249248
if (__DEV__ && locale !== targetLocale) {
250249
const emitter = (context as unknown as CoreInternalContext).__v_emitter
251250
if (emitter) {
252-
emitter.emit(VueDevToolsTimelineEvents.FALBACK, {
251+
emitter.emit('fallback', {
253252
type,
254253
key,
255254
from,

packages/core-base/src/translate.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ import { CoreWarnCodes, getWarnMessage } from './warnings'
3131
import { CoreErrorCodes, createCoreError } from './errors'
3232
import { translateDevTools } from './devtools'
3333
import { getLocale } from './fallbacker'
34-
import { VueDevToolsTimelineEvents } from '@intlify/vue-devtools'
3534

3635
import type { CompileError, ResourceNode } from '@intlify/message-compiler'
37-
import type { AdditionalPayloads } from '@intlify/devtools-if'
36+
import type { AdditionalPayloads } from '@intlify/devtools-types'
3837
import type { Path, PathValue } from './resolver'
3938
import type {
4039
Locale,
@@ -856,7 +855,7 @@ function resolveMessageFormat<Messages, Message>(
856855
if (__DEV__ && locale !== targetLocale) {
857856
const emitter = (context as unknown as CoreInternalContext).__v_emitter
858857
if (emitter) {
859-
emitter.emit(VueDevToolsTimelineEvents.FALBACK, {
858+
emitter.emit('fallback', {
860859
type,
861860
key,
862861
from,
@@ -890,8 +889,8 @@ function resolveMessageFormat<Messages, Message>(
890889
const end = window.performance.now()
891890
const emitter = (context as unknown as CoreInternalContext).__v_emitter
892891
if (emitter && start && format) {
893-
emitter.emit(VueDevToolsTimelineEvents.MESSAGE_RESOLVE, {
894-
type: VueDevToolsTimelineEvents.MESSAGE_RESOLVE,
892+
emitter.emit('message-resolve', {
893+
type: 'message-resolve',
895894
key,
896895
message: format,
897896
time: end - start,
@@ -978,8 +977,8 @@ function compileMessageFormat<Messages, Message>(
978977
const end = window.performance.now()
979978
const emitter = (context as unknown as CoreInternalContext).__v_emitter
980979
if (emitter && start) {
981-
emitter.emit(VueDevToolsTimelineEvents.MESSAGE_COMPILATION, {
982-
type: VueDevToolsTimelineEvents.MESSAGE_COMPILATION,
980+
emitter.emit('message-compilation', {
981+
type: 'message-compilation',
983982
message: format as string | ResourceNode | MessageFunction,
984983
time: end - start,
985984
groupId: `${'translate'}:${key}`
@@ -1021,8 +1020,8 @@ function evaluateMessage<Messages, Message>(
10211020
const end = window.performance.now()
10221021
const emitter = (context as unknown as CoreInternalContext).__v_emitter
10231022
if (emitter && start) {
1024-
emitter.emit(VueDevToolsTimelineEvents.MESSAGE_EVALUATION, {
1025-
type: VueDevToolsTimelineEvents.MESSAGE_EVALUATION,
1023+
emitter.emit('message-evaluation', {
1024+
type: 'message-evaluation',
10261025
value: messaged,
10271026
time: end - start,
10281027
groupId: `${'translate'}:${(msg as MessageFunctionInternal).key}`
@@ -1108,7 +1107,7 @@ function getCompileContext<Messages, Message>(
11081107
)
11091108
const emitter = (context as unknown as CoreInternalContext).__v_emitter
11101109
if (emitter && _source) {
1111-
emitter.emit(VueDevToolsTimelineEvents.COMPILE_ERROR, {
1110+
emitter.emit('compile-error', {
11121111
message: _source,
11131112
error: err.message,
11141113
start: err.location && err.location.start.offset,

packages/core-base/test/devtools.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { createCoreContext, translate } from '../src/index'
21
import { createEmitter } from '@intlify/shared'
2+
import { createCoreContext, translate } from '../src/index'
33
import { compileToFunction } from '../src/compilation'
4-
import { IntlifyDevToolsHooks } from '@intlify/devtools-if'
54
import { setDevToolsHook, getDevToolsHook } from '../src/devtools'
65

76
import type {
87
IntlifyDevToolsEmitterHooks,
98
IntlifyDevToolsEmitter
10-
} from '@intlify/devtools-if'
9+
} from '@intlify/devtools-types'
1110

1211
let devtools: IntlifyDevToolsEmitter | null = null
1312
beforeEach(() => {
@@ -23,7 +22,7 @@ afterEach(() => {
2322

2423
test('initI18nDevTools', () => {
2524
const fn = vi.fn()
26-
devtools!.on(IntlifyDevToolsHooks.I18nInit, fn)
25+
devtools!.on('i18n:init', fn)
2726

2827
const meta = { framework: 'Vue' }
2928
const ctx = createCoreContext({
@@ -46,7 +45,7 @@ test('initI18nDevTools', () => {
4645
describe('translateDevTools', () => {
4746
test('basic', () => {
4847
const fn = vi.fn()
49-
devtools!.on(IntlifyDevToolsHooks.FunctionTranslate, fn)
48+
devtools!.on('function:translate', fn)
5049

5150
const meta = { __INTLIFY_META__: 'xxx', framework: 'Vue' }
5251
const HELLO = 'Hello {name}!'
@@ -73,7 +72,7 @@ describe('translateDevTools', () => {
7372

7473
test('fallback', () => {
7574
const fn = vi.fn()
76-
devtools!.on(IntlifyDevToolsHooks.FunctionTranslate, fn)
75+
devtools!.on('function:translate', fn)
7776

7877
const HELLO = 'やあ {name}!'
7978
const ctx = createCoreContext({

packages/devtools-if/README.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/devtools-if/index.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/devtools-if/package.json

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)