Skip to content

Commit

Permalink
0.1.6 again again
Browse files Browse the repository at this point in the history
  • Loading branch information
dicko2 committed Jan 21, 2025
1 parent 1fedb61 commit 83067fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ describe('viteTimingPlugin', () => {

it('should not inject scripts in production mode', () => {
const html = '<html><head></head><body></body></html>';
const result = plugin.transformIndexHtml?.(html, { mode: 'production' });
const result = plugin.transformIndexHtml?.(html, {
command: 'build',
originalUrl: '/'
});

expect(result).toBe(html); // Should return unmodified HTML
expect(result).not.toContain('window.__VITE_TIMING__');
expect(result).not.toContain('import.meta.hot');
expect(result).toBe(html);
});

it('should handle HMR updates with module count', () => {
Expand Down
9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import { performance } from 'perf_hooks';
import path from 'path';
import type { Plugin, ViteDevServer } from 'vite';
import type { Plugin, ViteDevServer, IndexHtmlTransformContext } from 'vite';

Check failure on line 3 in src/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'IndexHtmlTransformContext' is defined but never used

Check failure on line 3 in src/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'IndexHtmlTransformContext' is defined but never used

Check failure on line 3 in src/index.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'IndexHtmlTransformContext' is defined but never used
import type { TimingEntry, HMRUpdate, ClientMessage } from './types';
import { getCommonMetadata } from './utils/metadata';
import { sendMetrics } from './utils/metrics';
Expand Down Expand Up @@ -170,9 +169,9 @@ export default function viteTimingPlugin(): ViteTimingPlugin {
});
},

transformIndexHtml(html: string, { mode }) {
// Only inject scripts in development mode
if (mode === 'development') {
transformIndexHtml(html: string, ctx?: { [key: string]: any }) {

Check warning on line 172 in src/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type

Check warning on line 172 in src/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected any. Specify a different type

Check warning on line 172 in src/index.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Unexpected any. Specify a different type
// Check if we're in development based on context
if (!ctx || ctx.command !== 'build') {
// Insert the main timing function first
html = html.replace(
'</head>',
Expand Down

0 comments on commit 83067fa

Please sign in to comment.