Skip to content

Commit ca107e5

Browse files
authored
perf(devtools): trim @nuxt/devtools runtime dependencies (#1066)
1 parent 9208bfc commit ca107e5

10 files changed

Lines changed: 23 additions & 99 deletions

File tree

‎package.json‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"@nuxt/schema": "catalog:types",
4141
"@playwright/test": "catalog:cli",
4242
"@types/node": "catalog:types",
43-
"@types/ws": "catalog:types",
4443
"@unocss/eslint-config": "catalog:buildtools",
4544
"@vitejs/devtools-kit": "catalog:types",
4645
"bumpp": "catalog:cli",
@@ -57,7 +56,6 @@
5756
"simple-git-hooks": "catalog:cli",
5857
"skills-npm": "catalog:buildtools",
5958
"taze": "catalog:cli",
60-
"tinyexec": "catalog:prod",
6159
"tsx": "catalog:cli",
6260
"turbo": "catalog:buildtools",
6361
"typescript": "catalog:cli",

‎packages/devtools/client/components/AssetFontPreview.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import type { AssetInfo } from '~/../src/types'
33
import { useStyleTag } from '@vueuse/core'
4-
import { hash } from 'ohash'
4+
import { hash } from 'devframe/utils/hash'
55
import { computed } from 'vue'
66
77
const props = defineProps<{

‎packages/devtools/client/nuxt.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export default defineNuxtConfig({
128128
'error-stack-parser-es',
129129
'fuse.js',
130130
'json-editor-vue',
131-
'ohash',
131+
'devframe/utils/hash',
132132
'perfect-debounce',
133133
'scule',
134134
'vue-virtual-scroller',

‎packages/devtools/package.json‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,22 @@
6666
"@nuxt/devtools-kit": "workspace:*",
6767
"@vitejs/devtools": "catalog:buildtools",
6868
"@vitejs/devtools-kit": "catalog:types",
69-
"birpc": "catalog:frontend",
7069
"consola": "catalog:prod",
7170
"destr": "catalog:prod",
71+
"devframe": "catalog:prod",
7272
"error-stack-parser-es": "catalog:frontend",
7373
"fast-npm-meta": "catalog:prod",
7474
"hookable": "catalog:frontend",
7575
"image-meta": "catalog:prod",
76-
"launch-editor": "catalog:prod",
7776
"local-pkg": "catalog:prod",
7877
"magicast": "catalog:prod",
79-
"ohash": "catalog:frontend",
8078
"pathe": "catalog:frontend",
8179
"perfect-debounce": "catalog:frontend",
8280
"pkg-types": "catalog:prod",
83-
"sirv": "catalog:prod",
84-
"structured-clone-es": "catalog:frontend",
85-
"tinyexec": "catalog:prod",
8681
"tinyglobby": "catalog:prod",
8782
"unstorage": "catalog:prod",
8883
"verkit": "catalog:prod",
89-
"vite-plugin-vue-tracer": "catalog:prod",
90-
"ws": "catalog:prod"
84+
"vite-plugin-vue-tracer": "catalog:prod"
9185
},
9286
"devDependencies": {
9387
"@antfu/utils": "catalog:frontend",
@@ -126,6 +120,7 @@
126120
"scule": "catalog:frontend",
127121
"shiki": "catalog:frontend",
128122
"shiki-codegen": "catalog:buildtools",
123+
"structured-clone-es": "catalog:frontend",
129124
"theme-vitesse": "catalog:frontend",
130125
"tsx": "catalog:cli",
131126
"ua-parser-modern": "catalog:frontend",

‎packages/devtools/src/module-main.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import os from 'node:os'
1010
import { deprecate, NUXT_DEVTOOLS_GROUP_ID } from '@nuxt/devtools-kit'
1111
import { addImports, addPlugin, addTemplate, addVitePlugin, extendViteConfig, logger } from '@nuxt/kit'
1212
import { colors } from 'consola/utils'
13+
import { serveStaticNodeMiddleware } from 'devframe/utils/serve-static'
1314
import { join } from 'pathe'
14-
import sirv from 'sirv'
1515
import { searchForWorkspaceRoot } from 'vite'
1616
import { version } from '../package.json'
1717
import { createDefaultTabOptions, setServerTasksEnabledByDefault } from './constant'
@@ -249,14 +249,13 @@ window.__NUXT_DEVTOOLS_TIME_METRIC__.appInit = Date.now()
249249
nuxt.hook('vite:serverCreated', (server) => {
250250
const devtoolsAnalyzeDir = join(nuxt.options.rootDir, 'node_modules/.cache/nuxt-devtools/analyze')
251251

252-
server.middlewares.use(ROUTE_ANALYZE, sirv(devtoolsAnalyzeDir, { single: false, dev: true, dotfiles: true, ignores: false }))
252+
server.middlewares.use(ROUTE_ANALYZE, serveStaticNodeMiddleware(devtoolsAnalyzeDir, { single: false }))
253253

254254
// Serve the front end in production
255255
if (clientDirExists) {
256256
const indexHtmlPath = join(clientDir, 'index.html')
257257
const indexContent = fs.readFile(indexHtmlPath, 'utf-8')
258-
const handleStatic = sirv(clientDir, {
259-
dev: true,
258+
const handleStatic = serveStaticNodeMiddleware(clientDir, {
260259
single: false,
261260
})
262261
// We replace the base URL in the index.html based on user's settings

‎packages/devtools/src/server-rpc/analyze-build.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import type { NuxtAnalyzeMeta } from '@nuxt/schema'
22
import type { AnalyzeBuildMeta, NuxtDevtoolsServerContext, ServerFunctions } from '../types'
3+
import { execFile } from 'node:child_process'
34
import fs from 'node:fs'
45
import fsp from 'node:fs/promises'
6+
import { promisify } from 'node:util'
57
import { dirname, join } from 'pathe'
6-
import { x } from 'tinyexec'
78
import { glob } from 'tinyglobby'
89
import { createUniqueSessionId } from '../utils/session-id'
910

11+
const execFileAsync = promisify(execFile)
12+
1013
const COLON_RE = /:/g
1114

1215
export function setupAnalyzeBuildRPC(ctx: NuxtDevtoolsServerContext) {
@@ -128,8 +131,8 @@ export function setupAnalyzeBuildRPC(ctx: NuxtDevtoolsServerContext) {
128131
}
129132

130133
async function git(...args: string[]): Promise<string> {
131-
const result = await x('git', args, { nodeOptions: { cwd: nuxt.options.rootDir }, throwOnError: true })
132-
return result.stdout.trim()
134+
const { stdout } = await execFileAsync('git', args, { cwd: nuxt.options.rootDir })
135+
return stdout.trim()
133136
}
134137

135138
async function generateAnalyzeBuildName() {

‎packages/devtools/src/server-rpc/general.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export function setupGeneralRPC({
223223
let editor = getOptions()?.behavior.openInEditor ?? undefined
224224
if (editor === 'auto')
225225
editor = undefined
226-
await import('launch-editor').then(r => (r.default || r)(path + suffix, editor))
226+
await import('devframe/utils/launch-editor').then(r => r.launchEditor(path + suffix, editor))
227227
return true
228228
}
229229
catch (e) {

‎packages/devtools/src/utils/local-options.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { existsSync } from 'node:fs'
22
import fs from 'node:fs/promises'
33
import { homedir } from 'node:os'
44
import { dirname } from 'node:path'
5-
import { hash } from 'ohash'
5+
import { hash } from 'devframe/utils/hash'
66
import { join } from 'pathe'
77

88
interface LocalOptionSearchOptions {

‎pnpm-lock.yaml‎

Lines changed: 6 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)