Skip to content

Commit

Permalink
fix(cache): version import transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Nov 14, 2023
1 parent f1088e6 commit 7676143
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/cjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
} from 'get-tsconfig';
import type { TransformOptions } from 'esbuild';
import { installSourceMapSupport, shouldStripSourceMap, stripSourceMap } from '../source-map';
import { transformSync, transformDynamicImport } from '../utils/transform';
import { transformSync } from '../utils/transform';
import { transformDynamicImport } from '../utils/transform/transform-dynamic-import';
import { resolveTsPath } from '../utils/resolve-ts-path';
import { isESM } from '../utils/esm-pattern';

Expand Down
3 changes: 2 additions & 1 deletion src/esm/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import type {
ResolveFnOutput, ResolveHookContext, LoadHook, GlobalPreloadHook, InitializeHook,
} from 'module';
import type { TransformOptions } from 'esbuild';
import { transform, transformDynamicImport } from '../utils/transform';
import { transform } from '../utils/transform';
import { transformDynamicImport } from '../utils/transform/transform-dynamic-import';
import { resolveTsPath } from '../utils/resolve-ts-path';
import { installSourceMapSupport, shouldStripSourceMap, stripSourceMap } from '../source-map';
import { importAttributes } from '../utils/node-features';
Expand Down
18 changes: 13 additions & 5 deletions src/utils/transform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
version as esbuildVersion,
} from 'esbuild';
import { sha1 } from '../sha1';
import { transformDynamicImport } from './transform-dynamic-import';
import { version as transformDynamicImportVersion, transformDynamicImport } from './transform-dynamic-import';
import cache from './cache';
import {
applyTransformersSync,
Expand All @@ -15,8 +15,6 @@ import {
} from './apply-transformers';
import { getEsbuildOptions } from './get-esbuild-options';

export { transformDynamicImport } from './transform-dynamic-import';

// Used by cjs-loader
export function transformSync(
code: string,
Expand All @@ -38,7 +36,12 @@ export function transformSync(
...extendOptions,
});

const hash = sha1(code + JSON.stringify(esbuildOptions) + esbuildVersion);
const hash = sha1([
code,
JSON.stringify(esbuildOptions),
esbuildVersion,
transformDynamicImportVersion,
].join('-'));
let transformed = cache.get(hash);

if (!transformed) {
Expand Down Expand Up @@ -87,7 +90,12 @@ export async function transform(
...extendOptions,
});

const hash = sha1(code + JSON.stringify(esbuildOptions) + esbuildVersion);
const hash = sha1([
code,
JSON.stringify(esbuildOptions),
esbuildVersion,
transformDynamicImportVersion,
].join('-'));
let transformed = cache.get(hash);

if (!transformed) {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/transform/transform-dynamic-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import MagicString from 'magic-string';
import type { RawSourceMap } from '../../source-map';
import { parseEsm } from '../es-module-lexer';

export const version = '1';

const toEsmFunctionString = ((imported: Record<string, unknown>) => {
const d = 'default';
const exports = Object.keys(imported);
Expand Down

0 comments on commit 7676143

Please sign in to comment.