@tanstack/devtools-vite 0.8.5 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/plugin.js +3 -2
- package/dist/esm/plugin.js.map +1 -1
- package/package.json +5 -8
- package/skills/devtools-vite-plugin/SKILL.md +1 -1
- package/src/plugin.ts +13 -2
- package/bin/intent.js +0 -20
package/dist/esm/plugin.js
CHANGED
|
@@ -31,6 +31,7 @@ var devtools = (args) => {
|
|
|
31
31
|
return config.mode === "development" && injectSourceConfig.enabled;
|
|
32
32
|
},
|
|
33
33
|
transform: {
|
|
34
|
+
order: "pre",
|
|
34
35
|
filter: { id: { exclude: [
|
|
35
36
|
/node_modules/,
|
|
36
37
|
/\?raw/,
|
|
@@ -290,7 +291,7 @@ var devtools = (args) => {
|
|
|
290
291
|
code: { exclude: /__tsdConsolePipe/ }
|
|
291
292
|
},
|
|
292
293
|
handler(code) {
|
|
293
|
-
if (/<html[\s>]/i.test(code) || code.includes("StartClient") || code.includes("hydrateRoot") || code.includes("createRoot") || code.includes("solid-js/web") && code.includes("render(")) return `${generateConsolePipeCode(consolePipingLevels, `http://localhost:${port}`)}\n${code}`;
|
|
294
|
+
if (/<html[\s>]/i.test(code) || code.includes("StartClient") || code.includes("hydrateRoot") || code.includes("createRoot") || (code.includes("solid-js/web") || code.includes("@solidjs/web")) && code.includes("render(")) return `${generateConsolePipeCode(consolePipingLevels, `http://localhost:${port}`)}\n${code}`;
|
|
294
295
|
}
|
|
295
296
|
}
|
|
296
297
|
},
|
|
@@ -313,7 +314,7 @@ var devtools = (args) => {
|
|
|
313
314
|
},
|
|
314
315
|
transform(code, id) {
|
|
315
316
|
if (!(code.includes("__TANSTACK_DEVTOOLS_PORT__") || code.includes("__TANSTACK_DEVTOOLS_HOST__") || code.includes("__TANSTACK_DEVTOOLS_PROTOCOL__"))) return;
|
|
316
|
-
if (!id.includes("@tanstack/devtools") && !id.includes("@tanstack/event-bus")) return;
|
|
317
|
+
if (!id.includes("@tanstack/devtools") && !id.includes("@tanstack/event-bus") && !id.includes("/.vite/deps")) return;
|
|
317
318
|
const portValue = devtoolsPort ?? 4206;
|
|
318
319
|
const hostValue = devtoolsHost ?? "localhost";
|
|
319
320
|
const protocolValue = devtoolsProtocol ?? "http";
|
package/dist/esm/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","names":[],"sources":["../../src/plugin.ts"],"sourcesContent":["import { devtoolsEventClient } from '@tanstack/devtools-client'\nimport { ServerEventBus } from '@tanstack/devtools-event-bus/server'\nimport chalk from 'chalk'\nimport {\n DEFAULT_EDITOR_CONFIG,\n TANSTACK_DEVTOOLS_PACKAGES,\n addPluginToDevtools,\n addSourceToJsx,\n detectDevtoolsFile,\n emitOutdatedDeps,\n enhanceConsoleLog,\n generateConsolePipeCode,\n handleDevToolsRequest,\n handleOpenSource,\n injectPluginIntoFile,\n injectRuntimeBridge,\n installPackage,\n normalizePath,\n readPackageJson,\n removeDevtools,\n stripEnhancedLogPrefix,\n wireRuntimeBridgeChannels,\n} from '@tanstack/devtools-bundler-core'\nimport type {\n ConsoleLevel,\n EditorConfig,\n TanStackDevtoolsConfig,\n} from '@tanstack/devtools-bundler-core'\nimport type { ServerResponse } from 'node:http'\nimport type { Plugin } from 'vite'\nimport type { HttpServerLike } from '@tanstack/devtools-event-bus/server'\n\nexport type { ConsoleLevel } from '@tanstack/devtools-bundler-core'\nexport type TanStackDevtoolsViteConfig = TanStackDevtoolsConfig\n\nexport const defineDevtoolsConfig = (config: TanStackDevtoolsViteConfig) =>\n config\n\nexport const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {\n let port = 5173\n const logging = args?.logging ?? true\n const enhancedLogsConfig = args?.enhancedLogs ?? { enabled: true }\n const injectSourceConfig = args?.injectSource ?? { enabled: true }\n const removeDevtoolsOnBuild = args?.removeDevtoolsOnBuild ?? true\n const serverBusEnabled = args?.eventBusConfig?.enabled ?? true\n const consolePipingConfig = args?.consolePiping ?? { enabled: true }\n const consolePipingLevels: Array<ConsoleLevel> =\n consolePipingConfig.levels ?? ['log', 'warn', 'error', 'info', 'debug']\n\n let devtoolsFileId: string | null = null\n let devtoolsPort: number | null = null\n let devtoolsHost: string | null = null\n let devtoolsProtocol: 'http' | 'https' | null = null\n\n return [\n {\n enforce: 'pre',\n name: '@tanstack/devtools:inject-source',\n apply(config) {\n return config.mode === 'development' && injectSourceConfig.enabled\n },\n transform: {\n filter: {\n id: {\n exclude: [/node_modules/, /\\?raw/, /\\/dist\\//, /\\/build\\//],\n },\n },\n handler(code, id) {\n return addSourceToJsx(code, id, args?.injectSource?.ignore)\n },\n },\n },\n {\n name: '@tanstack/devtools:config',\n enforce: 'pre',\n config(_, { command }) {\n // we do not apply any config changes for build\n if (command !== 'serve') {\n return\n }\n\n /* const solidDedupeDeps = [\n 'solid-js',\n 'solid-js/web',\n 'solid-js/store',\n 'solid-js/html',\n 'solid-js/h',\n ]\n\n return {\n resolve: {\n dedupe: solidDedupeDeps,\n },\n optimizeDeps: {\n include: solidDedupeDeps,\n },\n } */\n },\n },\n {\n enforce: 'pre',\n name: '@tanstack/devtools:custom-server',\n apply(config) {\n // Custom server is only needed in development for piping events to the client\n return config.mode === 'development'\n },\n async configureServer(server) {\n if (serverBusEnabled) {\n const preferredPort = args?.eventBusConfig?.port ?? 4206\n const isHttps = !!server.config.server.https\n const serverHost =\n typeof server.config.server.host === 'string'\n ? server.config.server.host\n : 'localhost'\n\n devtoolsProtocol = isHttps ? 'https' : 'http'\n devtoolsHost = serverHost\n\n const bus = new ServerEventBus({\n ...args?.eventBusConfig,\n port: preferredPort,\n host: serverHost,\n // When HTTPS is enabled, piggyback on Vite's server\n // so WebSocket/SSE connections share the same TLS certificate\n ...(isHttps && server.httpServer\n ? { httpServer: server.httpServer as HttpServerLike }\n : {}),\n })\n // start() now handles EADDRINUSE and returns the actual port\n devtoolsPort = await bus.start()\n if ((server as any).environments) {\n const teardownBridge = wireRuntimeBridgeChannels(\n server as unknown as Parameters<\n typeof wireRuntimeBridgeChannels\n >[0],\n () => globalThis.__TANSTACK_EVENT_TARGET__,\n )\n server.httpServer?.on('close', teardownBridge)\n }\n }\n\n server.middlewares.use((req, _res, next) => {\n if (req.socket.localPort && req.socket.localPort !== port) {\n port = req.socket.localPort\n }\n next()\n })\n if (server.config.server.port) {\n port = server.config.server.port\n }\n\n server.httpServer?.on('listening', () => {\n port = server.config.server.port\n })\n\n const editor = args?.editor ?? DEFAULT_EDITOR_CONFIG\n const openInEditor: EditorConfig['open'] = async (\n path,\n lineNum,\n columnNum,\n ) => {\n if (!path) {\n return\n }\n await editor.open(path, lineNum, columnNum)\n }\n\n const originalConsole = Object.fromEntries(\n consolePipingLevels.map((l) => [l, console[l].bind(console)]),\n ) as Partial<Record<ConsoleLevel, typeof console.log>>\n\n // SSE clients for broadcasting server logs to browser\n const sseClients: Array<{\n res: ServerResponse\n id: number\n }> = []\n let sseClientId = 0\n const consolePipingEnabled = consolePipingConfig.enabled ?? true\n\n server.middlewares.use((req, res, next) =>\n handleDevToolsRequest(req, res, next, {\n onOpenSource: (parsedData) => {\n const { data, routine } = parsedData\n if (routine === 'open-source') {\n return handleOpenSource({\n data: { type: data.type, data },\n openInEditor,\n })\n }\n return\n },\n ...(consolePipingEnabled\n ? {\n onConsolePipe: (entries) => {\n for (const entry of entries) {\n const prefix = chalk.cyan('[Client]')\n const logMethod =\n originalConsole[entry.level as ConsoleLevel] ??\n // log exists in consolePipingLevels\n originalConsole.log!\n\n const cleanedArgs = stripEnhancedLogPrefix(\n entry.args,\n (loc) => chalk.gray(loc),\n )\n logMethod(prefix, ...cleanedArgs)\n }\n },\n onConsolePipeSSE: (res, req) => {\n res.setHeader('Content-Type', 'text/event-stream')\n res.setHeader('Cache-Control', 'no-cache')\n res.setHeader('Connection', 'keep-alive')\n res.setHeader('Access-Control-Allow-Origin', '*')\n res.flushHeaders()\n\n const clientId = ++sseClientId\n sseClients.push({ res, id: clientId })\n\n req.on('close', () => {\n const index = sseClients.findIndex(\n (c) => c.id === clientId,\n )\n if (index !== -1) {\n sseClients.splice(index, 1)\n }\n })\n },\n onServerConsolePipe: (entries) => {\n try {\n const data = JSON.stringify({\n entries: entries.map((e) => ({\n level: e.level,\n args: e.args,\n source: 'server',\n timestamp: e.timestamp || Date.now(),\n })),\n })\n\n for (const client of sseClients) {\n client.res.write(`data: ${data}\\n\\n`)\n }\n } catch {}\n },\n }\n : {}),\n }),\n )\n },\n },\n {\n name: '@tanstack/devtools:remove-devtools-on-build',\n apply(config, { command }) {\n // Check both command and mode to support various hosting providers\n // Some providers (Cloudflare, Netlify, Heroku) might not use 'build' command\n // but will always set mode to 'production' for production builds\n return (\n (command !== 'serve' || config.mode === 'production') &&\n removeDevtoolsOnBuild\n )\n },\n enforce: 'pre',\n transform(code, id) {\n if (\n id.includes('node_modules') ||\n id.includes('?raw') ||\n !TANSTACK_DEVTOOLS_PACKAGES.some((pkg) => code.includes(pkg))\n )\n return\n const transform = removeDevtools(code, id)\n if (!transform) return\n if (logging) {\n console.log(\n `\\n${chalk.greenBright(`[@tanstack/devtools-vite]`)} Removed devtools code from: ${id.replace(normalizePath(process.cwd()), '')}\\n`,\n )\n }\n return transform\n },\n },\n {\n name: '@tanstack/devtools:event-client-setup',\n apply(config, { command }) {\n if (\n process.env.CI ||\n process.env.NODE_ENV !== 'development' ||\n command !== 'serve'\n )\n return false\n return config.mode === 'development'\n },\n async configureServer() {\n const packageJson = await readPackageJson()\n const outdatedDeps = emitOutdatedDeps().then((deps) => deps)\n\n // Listen for package installation requests\n devtoolsEventClient.on('install-devtools', async (event) => {\n const result = await installPackage(event.payload.packageName)\n devtoolsEventClient.emit('devtools-installed', {\n packageName: event.payload.packageName,\n success: result.success,\n error: result.error,\n })\n\n // If installation was successful, automatically add the plugin to devtools\n if (result.success) {\n const { packageName, pluginName, pluginImport } = event.payload\n\n console.log(\n chalk.blueBright(\n `[@tanstack/devtools-vite] Auto-adding ${packageName} to devtools...`,\n ),\n )\n\n const injectResult = addPluginToDevtools(\n devtoolsFileId,\n packageName,\n pluginName,\n pluginImport,\n )\n\n if (injectResult.success) {\n // Emit plugin-added event so the UI updates\n devtoolsEventClient.emit('plugin-added', {\n packageName,\n success: true,\n })\n\n // Also re-read package.json to update the UI with the newly installed package\n const updatedPackageJson = await readPackageJson()\n devtoolsEventClient.emit('package-json-read', {\n packageJson: updatedPackageJson,\n })\n }\n }\n })\n\n // Listen for add plugin to devtools requests\n devtoolsEventClient.on('add-plugin-to-devtools', (event) => {\n const { packageName, pluginName, pluginImport } = event.payload\n\n console.log(\n chalk.blueBright(\n `[@tanstack/devtools-vite] Adding ${packageName} to devtools...`,\n ),\n )\n\n const result = addPluginToDevtools(\n devtoolsFileId,\n packageName,\n pluginName,\n pluginImport,\n )\n\n devtoolsEventClient.emit('plugin-added', {\n packageName,\n success: result.success,\n error: result.error,\n })\n })\n\n // Handle bump-package-version event\n devtoolsEventClient.on('bump-package-version', async (event) => {\n const {\n packageName,\n devtoolsPackage,\n pluginName,\n minVersion,\n pluginImport,\n } = event.payload\n\n console.log(\n chalk.blueBright(\n `[@tanstack/devtools-vite] Bumping ${packageName} to version ${minVersion}...`,\n ),\n )\n\n // Install the package with the minimum version\n const packageWithVersion = minVersion\n ? `${packageName}@^${minVersion}`\n : packageName\n\n const result = await installPackage(packageWithVersion)\n\n if (!result.success) {\n console.log(\n chalk.redBright(\n `[@tanstack/devtools-vite] Failed to bump ${packageName}: ${result.error}`,\n ),\n )\n devtoolsEventClient.emit('devtools-installed', {\n packageName: devtoolsPackage,\n success: false,\n error: result.error,\n })\n return\n }\n\n console.log(\n chalk.greenBright(\n `[@tanstack/devtools-vite] Successfully bumped ${packageName} to ${minVersion}!`,\n ),\n )\n\n // Check if we found the devtools file\n if (!devtoolsFileId) {\n console.log(\n chalk.yellowBright(\n `[@tanstack/devtools-vite] Devtools file not found. Skipping auto-injection.`,\n ),\n )\n devtoolsEventClient.emit('devtools-installed', {\n packageName: devtoolsPackage,\n success: true,\n })\n return\n }\n\n // Now inject the devtools plugin\n console.log(\n chalk.blueBright(\n `[@tanstack/devtools-vite] Adding ${devtoolsPackage} to devtools...`,\n ),\n )\n\n const injectResult = injectPluginIntoFile(devtoolsFileId, {\n packageName: devtoolsPackage,\n pluginName,\n pluginImport,\n })\n\n if (injectResult.success) {\n console.log(\n chalk.greenBright(\n `[@tanstack/devtools-vite] Successfully added ${devtoolsPackage} to devtools!`,\n ),\n )\n\n devtoolsEventClient.emit('plugin-added', {\n packageName: devtoolsPackage,\n success: true,\n })\n\n // Re-read package.json to update the UI\n const updatedPackageJson = await readPackageJson()\n devtoolsEventClient.emit('package-json-read', {\n packageJson: updatedPackageJson,\n })\n } else {\n console.log(\n chalk.redBright(\n `[@tanstack/devtools-vite] Failed to add ${devtoolsPackage} to devtools: ${injectResult.error}`,\n ),\n )\n\n devtoolsEventClient.emit('plugin-added', {\n packageName: devtoolsPackage,\n success: false,\n error: injectResult.error,\n })\n }\n })\n\n // whenever a client mounts we send all the current info to the subscribers\n devtoolsEventClient.on('mounted', async () => {\n devtoolsEventClient.emit('outdated-deps-read', {\n outdatedDeps: await outdatedDeps,\n })\n devtoolsEventClient.emit('package-json-read', {\n packageJson,\n })\n })\n\n // Console piping is now handled via HTTP endpoints in the custom-server plugin\n },\n async handleHotUpdate({ file }) {\n if (file.endsWith('package.json')) {\n const newPackageJson = await readPackageJson()\n devtoolsEventClient.emit('package-json-read', {\n packageJson: newPackageJson,\n })\n emitOutdatedDeps()\n }\n },\n },\n // Enhanced logs must run BEFORE console-pipe-transform: the latter\n // prepends a multi-line IIFE to root entry files, which would shift\n // every line number computed by the oxc-parser AST and produce\n // \"Go to Source\" links pointing past the end of the user's file.\n {\n name: '@tanstack/devtools:better-console-logs',\n enforce: 'pre',\n apply(config) {\n return config.mode === 'development' && enhancedLogsConfig.enabled\n },\n transform: {\n filter: {\n id: {\n exclude: [/node_modules/, /\\?raw/, /\\/dist\\//, /\\/build\\//],\n },\n code: {\n include: 'console.',\n },\n },\n handler(code, id) {\n return enhanceConsoleLog(code, id, port)\n },\n },\n },\n // Inject console piping code into entry files (both client and server)\n {\n name: '@tanstack/devtools:console-pipe-transform',\n enforce: 'pre',\n apply(config, { command }) {\n return (\n config.mode === 'development' &&\n command === 'serve' &&\n (consolePipingConfig.enabled ?? true)\n )\n },\n transform: {\n filter: {\n id: {\n include: /\\.(tsx?|jsx?)$/,\n exclude: [/node_modules/, /\\/dist\\//, /\\?/],\n },\n code: {\n exclude: /__tsdConsolePipe/, // avoid transforming files that already contain the console pipe code\n },\n },\n handler(code) {\n // Check if this is a root entry file (with <html> JSX or client entry points)\n // In SSR frameworks, this file runs on BOTH server (SSR) and client (hydration)\n // so our runtime check (typeof window === 'undefined') handles both environments\n const isRootEntry =\n /<html[\\s>]/i.test(code) ||\n code.includes('StartClient') ||\n code.includes('hydrateRoot') ||\n code.includes('createRoot') ||\n (code.includes('solid-js/web') && code.includes('render('))\n\n if (isRootEntry) {\n const viteServerUrl = `http://localhost:${port}`\n const inlineCode = generateConsolePipeCode(\n consolePipingLevels,\n viteServerUrl,\n )\n\n return `${inlineCode}\\n${code}`\n }\n\n return undefined\n },\n },\n },\n {\n name: '@tanstack/devtools:inject-plugin',\n apply(config, { command }) {\n return config.mode === 'development' && command === 'serve'\n },\n transform(code, id) {\n // First pass: find where TanStackDevtools is imported\n if (!devtoolsFileId && detectDevtoolsFile(code)) {\n // Extract actual file path (remove query params)\n const [filePath] = id.split('?')\n if (filePath) {\n devtoolsFileId = filePath\n }\n }\n\n return undefined\n },\n },\n {\n name: '@tanstack/devtools:connection-injection',\n apply(config, { command }) {\n return config.mode === 'development' && command === 'serve'\n },\n transform(code, id) {\n // Only transform @tanstack packages that contain the connection placeholders\n const hasPlaceholder =\n code.includes('__TANSTACK_DEVTOOLS_PORT__') ||\n code.includes('__TANSTACK_DEVTOOLS_HOST__') ||\n code.includes('__TANSTACK_DEVTOOLS_PROTOCOL__')\n if (!hasPlaceholder) return\n if (\n !id.includes('@tanstack/devtools') &&\n !id.includes('@tanstack/event-bus')\n )\n return\n\n // Replace placeholders with actual values (or fallback defaults)\n const portValue = devtoolsPort ?? 4206\n const hostValue = devtoolsHost ?? 'localhost'\n const protocolValue = devtoolsProtocol ?? 'http'\n\n let result = code\n result = result.replace(\n /__TANSTACK_DEVTOOLS_PORT__/g,\n String(portValue),\n )\n result = result.replace(\n /__TANSTACK_DEVTOOLS_HOST__/g,\n JSON.stringify(hostValue),\n )\n result = result.replace(\n /__TANSTACK_DEVTOOLS_PROTOCOL__/g,\n JSON.stringify(protocolValue),\n )\n return result\n },\n },\n {\n name: '@tanstack/devtools:runtime-bridge',\n apply(config, { command }) {\n return config.mode === 'development' && command === 'serve'\n },\n transform(code, id) {\n if (id.includes('?')) return\n return injectRuntimeBridge(\n code,\n id,\n (this as any).environment?.name as string | undefined,\n )\n },\n },\n ]\n}\n"],"mappings":";;;;;AAmCA,IAAa,wBAAwB,WACnC;AAEF,IAAa,YAAY,SAAqD;CAC5E,IAAI,OAAO;CACX,MAAM,UAAU,MAAM,WAAW;CACjC,MAAM,qBAAqB,MAAM,gBAAgB,EAAE,SAAS,MAAM;CAClE,MAAM,qBAAqB,MAAM,gBAAgB,EAAE,SAAS,MAAM;CAClE,MAAM,wBAAwB,MAAM,yBAAyB;CAC7D,MAAM,mBAAmB,MAAM,gBAAgB,WAAW;CAC1D,MAAM,sBAAsB,MAAM,iBAAiB,EAAE,SAAS,MAAM;CACpE,MAAM,sBACJ,oBAAoB,UAAU;EAAC;EAAO;EAAQ;EAAS;EAAQ;EAAQ;CAEzE,IAAI,iBAAgC;CACpC,IAAI,eAA8B;CAClC,IAAI,eAA8B;CAClC,IAAI,mBAA4C;CAEhD,OAAO;EACL;GACE,SAAS;GACT,MAAM;GACN,MAAM,QAAQ;IACZ,OAAO,OAAO,SAAS,iBAAiB,mBAAmB;;GAE7D,WAAW;IACT,QAAQ,EACN,IAAI,EACF,SAAS;KAAC;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C1B,KAAK,SAAS,eAAe,IAAI,KAAK,SAAS,UAAU,EAS1D,OAAO,GALY,wBACjB,qBACA,oBAHwC,OAMhC,CAAW,IAAI;;IAK9B;GACF;EACD;GACE,MAAM;GACN,MAAM,QAAQ,EAAE,WAAW;IACzB,OAAO,OAAO,SAAS,iBAAiB,YAAY;;GAEtD,UAAU,MAAM,IAAI;IAElB,IAAI,CAAC,kBAAkB,mBAAmB,KAAK,EAAE;KAE/C,MAAM,CAAC,YAAY,GAAG,MAAM,IAAI;KAChC,IAAI,UACF,iBAAiB;;;GAMxB;EACD;GACE,MAAM;GACN,MAAM,QAAQ,EAAE,WAAW;IACzB,OAAO,OAAO,SAAS,iBAAiB,YAAY;;GAEtD,UAAU,MAAM,IAAI;IAMlB,IAAI,EAHF,KAAK,SAAS,6BAA6B,IAC3C,KAAK,SAAS,6BAA6B,IAC3C,KAAK,SAAS,iCAAiC,GAC5B;IACrB,IACE,CAAC,GAAG,SAAS,qBAAqB,IAClC,CAAC,GAAG,SAAS,sBAAsB,EAEnC;IAGF,MAAM,YAAY,gBAAgB;IAClC,MAAM,YAAY,gBAAgB;IAClC,MAAM,gBAAgB,oBAAoB;IAE1C,IAAI,SAAS;IACb,SAAS,OAAO,QACd,+BACA,OAAO,UAAU,CAClB;IACD,SAAS,OAAO,QACd,+BACA,KAAK,UAAU,UAAU,CAC1B;IACD,SAAS,OAAO,QACd,mCACA,KAAK,UAAU,cAAc,CAC9B;IACD,OAAO;;GAEV;EACD;GACE,MAAM;GACN,MAAM,QAAQ,EAAE,WAAW;IACzB,OAAO,OAAO,SAAS,iBAAiB,YAAY;;GAEtD,UAAU,MAAM,IAAI;IAClB,IAAI,GAAG,SAAS,IAAI,EAAE;IACtB,OAAO,oBACL,MACA,IACC,KAAa,aAAa,KAC5B;;GAEJ;EACF"}
|
|
1
|
+
{"version":3,"file":"plugin.js","names":[],"sources":["../../src/plugin.ts"],"sourcesContent":["import { devtoolsEventClient } from '@tanstack/devtools-client'\nimport { ServerEventBus } from '@tanstack/devtools-event-bus/server'\nimport chalk from 'chalk'\nimport {\n DEFAULT_EDITOR_CONFIG,\n TANSTACK_DEVTOOLS_PACKAGES,\n addPluginToDevtools,\n addSourceToJsx,\n detectDevtoolsFile,\n emitOutdatedDeps,\n enhanceConsoleLog,\n generateConsolePipeCode,\n handleDevToolsRequest,\n handleOpenSource,\n injectPluginIntoFile,\n injectRuntimeBridge,\n installPackage,\n normalizePath,\n readPackageJson,\n removeDevtools,\n stripEnhancedLogPrefix,\n wireRuntimeBridgeChannels,\n} from '@tanstack/devtools-bundler-core'\nimport type {\n ConsoleLevel,\n EditorConfig,\n TanStackDevtoolsConfig,\n} from '@tanstack/devtools-bundler-core'\nimport type { ServerResponse } from 'node:http'\nimport type { Plugin } from 'vite'\nimport type { HttpServerLike } from '@tanstack/devtools-event-bus/server'\n\nexport type { ConsoleLevel } from '@tanstack/devtools-bundler-core'\nexport type TanStackDevtoolsViteConfig = TanStackDevtoolsConfig\n\nexport const defineDevtoolsConfig = (config: TanStackDevtoolsViteConfig) =>\n config\n\nexport const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {\n let port = 5173\n const logging = args?.logging ?? true\n const enhancedLogsConfig = args?.enhancedLogs ?? { enabled: true }\n const injectSourceConfig = args?.injectSource ?? { enabled: true }\n const removeDevtoolsOnBuild = args?.removeDevtoolsOnBuild ?? true\n const serverBusEnabled = args?.eventBusConfig?.enabled ?? true\n const consolePipingConfig = args?.consolePiping ?? { enabled: true }\n const consolePipingLevels: Array<ConsoleLevel> =\n consolePipingConfig.levels ?? ['log', 'warn', 'error', 'info', 'debug']\n\n let devtoolsFileId: string | null = null\n let devtoolsPort: number | null = null\n let devtoolsHost: string | null = null\n let devtoolsProtocol: 'http' | 'https' | null = null\n\n return [\n {\n enforce: 'pre',\n name: '@tanstack/devtools:inject-source',\n apply(config) {\n return config.mode === 'development' && injectSourceConfig.enabled\n },\n transform: {\n // Run before the transforms of plugins without `order: 'pre'`, also when\n // devtools() is not first in the plugins array. A plugin that changes\n // the code of one environment only would shift the lines and make the\n // SSR and client locations differ, which breaks hydration. An earlier\n // plugin whose transform also has `order: 'pre'` still runs first.\n order: 'pre',\n filter: {\n id: {\n exclude: [/node_modules/, /\\?raw/, /\\/dist\\//, /\\/build\\//],\n },\n },\n handler(code, id) {\n return addSourceToJsx(code, id, args?.injectSource?.ignore)\n },\n },\n },\n {\n name: '@tanstack/devtools:config',\n enforce: 'pre',\n config(_, { command }) {\n // we do not apply any config changes for build\n if (command !== 'serve') {\n return\n }\n\n /* const solidDedupeDeps = [\n 'solid-js',\n 'solid-js/web',\n 'solid-js/store',\n 'solid-js/html',\n 'solid-js/h',\n ]\n\n return {\n resolve: {\n dedupe: solidDedupeDeps,\n },\n optimizeDeps: {\n include: solidDedupeDeps,\n },\n } */\n },\n },\n {\n enforce: 'pre',\n name: '@tanstack/devtools:custom-server',\n apply(config) {\n // Custom server is only needed in development for piping events to the client\n return config.mode === 'development'\n },\n async configureServer(server) {\n if (serverBusEnabled) {\n const preferredPort = args?.eventBusConfig?.port ?? 4206\n const isHttps = !!server.config.server.https\n const serverHost =\n typeof server.config.server.host === 'string'\n ? server.config.server.host\n : 'localhost'\n\n devtoolsProtocol = isHttps ? 'https' : 'http'\n devtoolsHost = serverHost\n\n const bus = new ServerEventBus({\n ...args?.eventBusConfig,\n port: preferredPort,\n host: serverHost,\n // When HTTPS is enabled, piggyback on Vite's server\n // so WebSocket/SSE connections share the same TLS certificate\n ...(isHttps && server.httpServer\n ? { httpServer: server.httpServer as HttpServerLike }\n : {}),\n })\n // start() now handles EADDRINUSE and returns the actual port\n devtoolsPort = await bus.start()\n if ((server as any).environments) {\n const teardownBridge = wireRuntimeBridgeChannels(\n server as unknown as Parameters<\n typeof wireRuntimeBridgeChannels\n >[0],\n () => globalThis.__TANSTACK_EVENT_TARGET__,\n )\n server.httpServer?.on('close', teardownBridge)\n }\n }\n\n server.middlewares.use((req, _res, next) => {\n if (req.socket.localPort && req.socket.localPort !== port) {\n port = req.socket.localPort\n }\n next()\n })\n if (server.config.server.port) {\n port = server.config.server.port\n }\n\n server.httpServer?.on('listening', () => {\n port = server.config.server.port\n })\n\n const editor = args?.editor ?? DEFAULT_EDITOR_CONFIG\n const openInEditor: EditorConfig['open'] = async (\n path,\n lineNum,\n columnNum,\n ) => {\n if (!path) {\n return\n }\n await editor.open(path, lineNum, columnNum)\n }\n\n const originalConsole = Object.fromEntries(\n consolePipingLevels.map((l) => [l, console[l].bind(console)]),\n ) as Partial<Record<ConsoleLevel, typeof console.log>>\n\n // SSE clients for broadcasting server logs to browser\n const sseClients: Array<{\n res: ServerResponse\n id: number\n }> = []\n let sseClientId = 0\n const consolePipingEnabled = consolePipingConfig.enabled ?? true\n\n server.middlewares.use((req, res, next) =>\n handleDevToolsRequest(req, res, next, {\n onOpenSource: (parsedData) => {\n const { data, routine } = parsedData\n if (routine === 'open-source') {\n return handleOpenSource({\n data: { type: data.type, data },\n openInEditor,\n })\n }\n return\n },\n ...(consolePipingEnabled\n ? {\n onConsolePipe: (entries) => {\n for (const entry of entries) {\n const prefix = chalk.cyan('[Client]')\n const logMethod =\n originalConsole[entry.level as ConsoleLevel] ??\n // log exists in consolePipingLevels\n originalConsole.log!\n\n const cleanedArgs = stripEnhancedLogPrefix(\n entry.args,\n (loc) => chalk.gray(loc),\n )\n logMethod(prefix, ...cleanedArgs)\n }\n },\n onConsolePipeSSE: (res, req) => {\n res.setHeader('Content-Type', 'text/event-stream')\n res.setHeader('Cache-Control', 'no-cache')\n res.setHeader('Connection', 'keep-alive')\n res.setHeader('Access-Control-Allow-Origin', '*')\n res.flushHeaders()\n\n const clientId = ++sseClientId\n sseClients.push({ res, id: clientId })\n\n req.on('close', () => {\n const index = sseClients.findIndex(\n (c) => c.id === clientId,\n )\n if (index !== -1) {\n sseClients.splice(index, 1)\n }\n })\n },\n onServerConsolePipe: (entries) => {\n try {\n const data = JSON.stringify({\n entries: entries.map((e) => ({\n level: e.level,\n args: e.args,\n source: 'server',\n timestamp: e.timestamp || Date.now(),\n })),\n })\n\n for (const client of sseClients) {\n client.res.write(`data: ${data}\\n\\n`)\n }\n } catch {}\n },\n }\n : {}),\n }),\n )\n },\n },\n {\n name: '@tanstack/devtools:remove-devtools-on-build',\n apply(config, { command }) {\n // Check both command and mode to support various hosting providers\n // Some providers (Cloudflare, Netlify, Heroku) might not use 'build' command\n // but will always set mode to 'production' for production builds\n return (\n (command !== 'serve' || config.mode === 'production') &&\n removeDevtoolsOnBuild\n )\n },\n enforce: 'pre',\n transform(code, id) {\n if (\n id.includes('node_modules') ||\n id.includes('?raw') ||\n !TANSTACK_DEVTOOLS_PACKAGES.some((pkg) => code.includes(pkg))\n )\n return\n const transform = removeDevtools(code, id)\n if (!transform) return\n if (logging) {\n console.log(\n `\\n${chalk.greenBright(`[@tanstack/devtools-vite]`)} Removed devtools code from: ${id.replace(normalizePath(process.cwd()), '')}\\n`,\n )\n }\n return transform\n },\n },\n {\n name: '@tanstack/devtools:event-client-setup',\n apply(config, { command }) {\n if (\n process.env.CI ||\n process.env.NODE_ENV !== 'development' ||\n command !== 'serve'\n )\n return false\n return config.mode === 'development'\n },\n async configureServer() {\n const packageJson = await readPackageJson()\n const outdatedDeps = emitOutdatedDeps().then((deps) => deps)\n\n // Listen for package installation requests\n devtoolsEventClient.on('install-devtools', async (event) => {\n const result = await installPackage(event.payload.packageName)\n devtoolsEventClient.emit('devtools-installed', {\n packageName: event.payload.packageName,\n success: result.success,\n error: result.error,\n })\n\n // If installation was successful, automatically add the plugin to devtools\n if (result.success) {\n const { packageName, pluginName, pluginImport } = event.payload\n\n console.log(\n chalk.blueBright(\n `[@tanstack/devtools-vite] Auto-adding ${packageName} to devtools...`,\n ),\n )\n\n const injectResult = addPluginToDevtools(\n devtoolsFileId,\n packageName,\n pluginName,\n pluginImport,\n )\n\n if (injectResult.success) {\n // Emit plugin-added event so the UI updates\n devtoolsEventClient.emit('plugin-added', {\n packageName,\n success: true,\n })\n\n // Also re-read package.json to update the UI with the newly installed package\n const updatedPackageJson = await readPackageJson()\n devtoolsEventClient.emit('package-json-read', {\n packageJson: updatedPackageJson,\n })\n }\n }\n })\n\n // Listen for add plugin to devtools requests\n devtoolsEventClient.on('add-plugin-to-devtools', (event) => {\n const { packageName, pluginName, pluginImport } = event.payload\n\n console.log(\n chalk.blueBright(\n `[@tanstack/devtools-vite] Adding ${packageName} to devtools...`,\n ),\n )\n\n const result = addPluginToDevtools(\n devtoolsFileId,\n packageName,\n pluginName,\n pluginImport,\n )\n\n devtoolsEventClient.emit('plugin-added', {\n packageName,\n success: result.success,\n error: result.error,\n })\n })\n\n // Handle bump-package-version event\n devtoolsEventClient.on('bump-package-version', async (event) => {\n const {\n packageName,\n devtoolsPackage,\n pluginName,\n minVersion,\n pluginImport,\n } = event.payload\n\n console.log(\n chalk.blueBright(\n `[@tanstack/devtools-vite] Bumping ${packageName} to version ${minVersion}...`,\n ),\n )\n\n // Install the package with the minimum version\n const packageWithVersion = minVersion\n ? `${packageName}@^${minVersion}`\n : packageName\n\n const result = await installPackage(packageWithVersion)\n\n if (!result.success) {\n console.log(\n chalk.redBright(\n `[@tanstack/devtools-vite] Failed to bump ${packageName}: ${result.error}`,\n ),\n )\n devtoolsEventClient.emit('devtools-installed', {\n packageName: devtoolsPackage,\n success: false,\n error: result.error,\n })\n return\n }\n\n console.log(\n chalk.greenBright(\n `[@tanstack/devtools-vite] Successfully bumped ${packageName} to ${minVersion}!`,\n ),\n )\n\n // Check if we found the devtools file\n if (!devtoolsFileId) {\n console.log(\n chalk.yellowBright(\n `[@tanstack/devtools-vite] Devtools file not found. Skipping auto-injection.`,\n ),\n )\n devtoolsEventClient.emit('devtools-installed', {\n packageName: devtoolsPackage,\n success: true,\n })\n return\n }\n\n // Now inject the devtools plugin\n console.log(\n chalk.blueBright(\n `[@tanstack/devtools-vite] Adding ${devtoolsPackage} to devtools...`,\n ),\n )\n\n const injectResult = injectPluginIntoFile(devtoolsFileId, {\n packageName: devtoolsPackage,\n pluginName,\n pluginImport,\n })\n\n if (injectResult.success) {\n console.log(\n chalk.greenBright(\n `[@tanstack/devtools-vite] Successfully added ${devtoolsPackage} to devtools!`,\n ),\n )\n\n devtoolsEventClient.emit('plugin-added', {\n packageName: devtoolsPackage,\n success: true,\n })\n\n // Re-read package.json to update the UI\n const updatedPackageJson = await readPackageJson()\n devtoolsEventClient.emit('package-json-read', {\n packageJson: updatedPackageJson,\n })\n } else {\n console.log(\n chalk.redBright(\n `[@tanstack/devtools-vite] Failed to add ${devtoolsPackage} to devtools: ${injectResult.error}`,\n ),\n )\n\n devtoolsEventClient.emit('plugin-added', {\n packageName: devtoolsPackage,\n success: false,\n error: injectResult.error,\n })\n }\n })\n\n // whenever a client mounts we send all the current info to the subscribers\n devtoolsEventClient.on('mounted', async () => {\n devtoolsEventClient.emit('outdated-deps-read', {\n outdatedDeps: await outdatedDeps,\n })\n devtoolsEventClient.emit('package-json-read', {\n packageJson,\n })\n })\n\n // Console piping is now handled via HTTP endpoints in the custom-server plugin\n },\n async handleHotUpdate({ file }) {\n if (file.endsWith('package.json')) {\n const newPackageJson = await readPackageJson()\n devtoolsEventClient.emit('package-json-read', {\n packageJson: newPackageJson,\n })\n emitOutdatedDeps()\n }\n },\n },\n // Enhanced logs must run BEFORE console-pipe-transform: the latter\n // prepends a multi-line IIFE to root entry files, which would shift\n // every line number computed by the oxc-parser AST and produce\n // \"Go to Source\" links pointing past the end of the user's file.\n {\n name: '@tanstack/devtools:better-console-logs',\n enforce: 'pre',\n apply(config) {\n return config.mode === 'development' && enhancedLogsConfig.enabled\n },\n transform: {\n filter: {\n id: {\n exclude: [/node_modules/, /\\?raw/, /\\/dist\\//, /\\/build\\//],\n },\n code: {\n include: 'console.',\n },\n },\n handler(code, id) {\n return enhanceConsoleLog(code, id, port)\n },\n },\n },\n // Inject console piping code into entry files (both client and server)\n {\n name: '@tanstack/devtools:console-pipe-transform',\n enforce: 'pre',\n apply(config, { command }) {\n return (\n config.mode === 'development' &&\n command === 'serve' &&\n (consolePipingConfig.enabled ?? true)\n )\n },\n transform: {\n filter: {\n id: {\n include: /\\.(tsx?|jsx?)$/,\n exclude: [/node_modules/, /\\/dist\\//, /\\?/],\n },\n code: {\n exclude: /__tsdConsolePipe/, // avoid transforming files that already contain the console pipe code\n },\n },\n handler(code) {\n // Check if this is a root entry file (with <html> JSX or client entry points)\n // In SSR frameworks, this file runs on BOTH server (SSR) and client (hydration)\n // so our runtime check (typeof window === 'undefined') handles both environments\n const isRootEntry =\n /<html[\\s>]/i.test(code) ||\n code.includes('StartClient') ||\n code.includes('hydrateRoot') ||\n code.includes('createRoot') ||\n // Solid 1 renders from `solid-js/web`, Solid 2 from `@solidjs/web`.\n ((code.includes('solid-js/web') || code.includes('@solidjs/web')) &&\n code.includes('render('))\n\n if (isRootEntry) {\n const viteServerUrl = `http://localhost:${port}`\n const inlineCode = generateConsolePipeCode(\n consolePipingLevels,\n viteServerUrl,\n )\n\n return `${inlineCode}\\n${code}`\n }\n\n return undefined\n },\n },\n },\n {\n name: '@tanstack/devtools:inject-plugin',\n apply(config, { command }) {\n return config.mode === 'development' && command === 'serve'\n },\n transform(code, id) {\n // First pass: find where TanStackDevtools is imported\n if (!devtoolsFileId && detectDevtoolsFile(code)) {\n // Extract actual file path (remove query params)\n const [filePath] = id.split('?')\n if (filePath) {\n devtoolsFileId = filePath\n }\n }\n\n return undefined\n },\n },\n {\n name: '@tanstack/devtools:connection-injection',\n apply(config, { command }) {\n return config.mode === 'development' && command === 'serve'\n },\n transform(code, id) {\n // Only transform @tanstack packages that contain the connection placeholders\n const hasPlaceholder =\n code.includes('__TANSTACK_DEVTOOLS_PORT__') ||\n code.includes('__TANSTACK_DEVTOOLS_HOST__') ||\n code.includes('__TANSTACK_DEVTOOLS_PROTOCOL__')\n if (!hasPlaceholder) return\n // Vite pre-bundles npm installs into chunks under `.vite/deps*`, whose\n // ids no longer name the package.\n if (\n !id.includes('@tanstack/devtools') &&\n !id.includes('@tanstack/event-bus') &&\n !id.includes('/.vite/deps')\n )\n return\n\n // Replace placeholders with actual values (or fallback defaults)\n const portValue = devtoolsPort ?? 4206\n const hostValue = devtoolsHost ?? 'localhost'\n const protocolValue = devtoolsProtocol ?? 'http'\n\n let result = code\n result = result.replace(\n /__TANSTACK_DEVTOOLS_PORT__/g,\n String(portValue),\n )\n result = result.replace(\n /__TANSTACK_DEVTOOLS_HOST__/g,\n JSON.stringify(hostValue),\n )\n result = result.replace(\n /__TANSTACK_DEVTOOLS_PROTOCOL__/g,\n JSON.stringify(protocolValue),\n )\n return result\n },\n },\n {\n name: '@tanstack/devtools:runtime-bridge',\n apply(config, { command }) {\n return config.mode === 'development' && command === 'serve'\n },\n transform(code, id) {\n if (id.includes('?')) return\n return injectRuntimeBridge(\n code,\n id,\n (this as any).environment?.name as string | undefined,\n )\n },\n },\n ]\n}\n"],"mappings":";;;;;AAmCA,IAAa,wBAAwB,WACnC;AAEF,IAAa,YAAY,SAAqD;CAC5E,IAAI,OAAO;CACX,MAAM,UAAU,MAAM,WAAW;CACjC,MAAM,qBAAqB,MAAM,gBAAgB,EAAE,SAAS,MAAM;CAClE,MAAM,qBAAqB,MAAM,gBAAgB,EAAE,SAAS,MAAM;CAClE,MAAM,wBAAwB,MAAM,yBAAyB;CAC7D,MAAM,mBAAmB,MAAM,gBAAgB,WAAW;CAC1D,MAAM,sBAAsB,MAAM,iBAAiB,EAAE,SAAS,MAAM;CACpE,MAAM,sBACJ,oBAAoB,UAAU;EAAC;EAAO;EAAQ;EAAS;EAAQ;EAAQ;CAEzE,IAAI,iBAAgC;CACpC,IAAI,eAA8B;CAClC,IAAI,eAA8B;CAClC,IAAI,mBAA4C;CAEhD,OAAO;EACL;GACE,SAAS;GACT,MAAM;GACN,MAAM,QAAQ;IACZ,OAAO,OAAO,SAAS,iBAAiB,mBAAmB;;GAE7D,WAAW;IAMT,OAAO;IACP,QAAQ,EACN,IAAI,EACF,SAAS;KAAC;KAAgB;KAAS;KAAY;KAAY,EAC5D,EACF;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
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.7",
|
|
4
4
|
"description": "TanStack Vite plugin used to enhance the core devtools with additional functionalities",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"url": "https://github.com/sponsors/tannerlinsley"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
|
-
"devtools"
|
|
21
|
+
"devtools",
|
|
22
|
+
"tanstack-intent"
|
|
22
23
|
],
|
|
23
24
|
"type": "module",
|
|
24
25
|
"types": "dist/esm//index.d.ts",
|
|
@@ -32,9 +33,6 @@
|
|
|
32
33
|
},
|
|
33
34
|
"./package.json": "./package.json"
|
|
34
35
|
},
|
|
35
|
-
"bin": {
|
|
36
|
-
"intent": "./bin/intent.js"
|
|
37
|
-
},
|
|
38
36
|
"sideEffects": false,
|
|
39
37
|
"engines": {
|
|
40
38
|
"node": ">=18"
|
|
@@ -42,15 +40,14 @@
|
|
|
42
40
|
"files": [
|
|
43
41
|
"dist/",
|
|
44
42
|
"src",
|
|
45
|
-
"skills"
|
|
46
|
-
"bin"
|
|
43
|
+
"skills"
|
|
47
44
|
],
|
|
48
45
|
"peerDependencies": {
|
|
49
46
|
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
50
47
|
},
|
|
51
48
|
"dependencies": {
|
|
52
49
|
"chalk": "^5.6.2",
|
|
53
|
-
"@tanstack/devtools-bundler-core": "0.1.
|
|
50
|
+
"@tanstack/devtools-bundler-core": "0.1.4",
|
|
54
51
|
"@tanstack/devtools-client": "0.0.8",
|
|
55
52
|
"@tanstack/devtools-event-bus": "0.4.3"
|
|
56
53
|
},
|
|
@@ -122,7 +122,7 @@ Bidirectional console piping between client and server. Injects runtime code (II
|
|
|
122
122
|
1. Wraps `console[level]` to batch and POST entries to `<viteServerUrl>/__tsd/console-pipe/server`
|
|
123
123
|
2. These are then broadcast to all SSE clients
|
|
124
124
|
|
|
125
|
-
**Entry file detection:** looks for `<html` tag, `StartClient`, `hydrateRoot`, `createRoot`, or `solid-js/web` + `render(` in code.
|
|
125
|
+
**Entry file detection:** looks for `<html` tag, `StartClient`, `hydrateRoot`, `createRoot`, or `solid-js/web` / `@solidjs/web` + `render(` in code.
|
|
126
126
|
|
|
127
127
|
**Source files:** `packages/devtools-vite/src/virtual-console.ts`, `packages/devtools-vite/src/utils.ts` (middleware handlers)
|
|
128
128
|
|
package/src/plugin.ts
CHANGED
|
@@ -60,6 +60,12 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
|
|
|
60
60
|
return config.mode === 'development' && injectSourceConfig.enabled
|
|
61
61
|
},
|
|
62
62
|
transform: {
|
|
63
|
+
// Run before the transforms of plugins without `order: 'pre'`, also when
|
|
64
|
+
// devtools() is not first in the plugins array. A plugin that changes
|
|
65
|
+
// the code of one environment only would shift the lines and make the
|
|
66
|
+
// SSR and client locations differ, which breaks hydration. An earlier
|
|
67
|
+
// plugin whose transform also has `order: 'pre'` still runs first.
|
|
68
|
+
order: 'pre',
|
|
63
69
|
filter: {
|
|
64
70
|
id: {
|
|
65
71
|
exclude: [/node_modules/, /\?raw/, /\/dist\//, /\/build\//],
|
|
@@ -535,7 +541,9 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
|
|
|
535
541
|
code.includes('StartClient') ||
|
|
536
542
|
code.includes('hydrateRoot') ||
|
|
537
543
|
code.includes('createRoot') ||
|
|
538
|
-
|
|
544
|
+
// Solid 1 renders from `solid-js/web`, Solid 2 from `@solidjs/web`.
|
|
545
|
+
((code.includes('solid-js/web') || code.includes('@solidjs/web')) &&
|
|
546
|
+
code.includes('render('))
|
|
539
547
|
|
|
540
548
|
if (isRootEntry) {
|
|
541
549
|
const viteServerUrl = `http://localhost:${port}`
|
|
@@ -581,9 +589,12 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
|
|
|
581
589
|
code.includes('__TANSTACK_DEVTOOLS_HOST__') ||
|
|
582
590
|
code.includes('__TANSTACK_DEVTOOLS_PROTOCOL__')
|
|
583
591
|
if (!hasPlaceholder) return
|
|
592
|
+
// Vite pre-bundles npm installs into chunks under `.vite/deps*`, whose
|
|
593
|
+
// ids no longer name the package.
|
|
584
594
|
if (
|
|
585
595
|
!id.includes('@tanstack/devtools') &&
|
|
586
|
-
!id.includes('@tanstack/event-bus')
|
|
596
|
+
!id.includes('@tanstack/event-bus') &&
|
|
597
|
+
!id.includes('/.vite/deps')
|
|
587
598
|
)
|
|
588
599
|
return
|
|
589
600
|
|
package/bin/intent.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Auto-generated by @tanstack/intent setup
|
|
3
|
-
// Exposes the intent end-user CLI for consumers of this library.
|
|
4
|
-
// Commit this file, then add to your package.json:
|
|
5
|
-
// "bin": { "intent": "./bin/intent.js" }
|
|
6
|
-
try {
|
|
7
|
-
await import('@tanstack/intent/intent-library')
|
|
8
|
-
} catch (e) {
|
|
9
|
-
if (e?.code === 'ERR_MODULE_NOT_FOUND' || e?.code === 'MODULE_NOT_FOUND') {
|
|
10
|
-
console.error('@tanstack/intent is not installed.')
|
|
11
|
-
console.error('')
|
|
12
|
-
console.error('Install it as a dev dependency:')
|
|
13
|
-
console.error(' npm add -D @tanstack/intent')
|
|
14
|
-
console.error('')
|
|
15
|
-
console.error('Or run directly:')
|
|
16
|
-
console.error(' npx @tanstack/intent@latest list')
|
|
17
|
-
process.exit(1)
|
|
18
|
-
}
|
|
19
|
-
throw e
|
|
20
|
-
}
|