Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use hash instead mtime for cache key #718

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/builder/bundle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ export interface IBundleWatcher {
close: () => void;
}

interface IBundlessOpts {
interface IBundleOpts {
cwd: string;
configProvider: BundleConfigProvider;
buildDependencies?: string[];
watch?: boolean;
}

function bundless(opts: Omit<IBundlessOpts, 'watch'>): Promise<void>;
function bundless(opts: IBundlessOpts): Promise<IBundleWatcher>;
async function bundless(opts: IBundlessOpts): Promise<void | IBundleWatcher> {
function bundle(opts: Omit<IBundleOpts, 'watch'>): Promise<void>;
function bundle(opts: IBundleOpts): Promise<IBundleWatcher>;
async function bundle(opts: IBundleOpts): Promise<void | IBundleWatcher> {
const enableCache = process.env.FATHER_CACHE !== 'none';
const closeHandlers: webpack.Watching['close'][] = [];

Expand Down Expand Up @@ -192,4 +192,4 @@ async function bundless(opts: IBundlessOpts): Promise<void | IBundleWatcher> {
}
}

export default bundless;
export default bundle;
5 changes: 3 additions & 2 deletions src/builder/bundless/loaders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { runLoaders } from 'loader-runner';
import type { IApi } from '../../../types';
import { getCache } from '../../../utils';
import type { IBundlessConfig } from '../../config';
import { getContentHash } from '../../utils';
import { getTsconfig } from '../dts';
import type { IBundlessLoader, ILoaderOutput } from './types';

Expand Down Expand Up @@ -51,10 +52,10 @@ export default async (
},
) => {
const cache = getCache('bundless-loader');
// format: {path:mtime:config:pkgDeps}
// format: {path:contenthash:config:pkgDeps}
const cacheKey = [
fileAbsPath,
fs.statSync(fileAbsPath).mtimeMs,
getContentHash(fs.readFileSync(fileAbsPath, 'utf-8')),
JSON.stringify(opts.config),
// use for babel opts generator in src/builder/utils.ts
JSON.stringify(
Expand Down
8 changes: 6 additions & 2 deletions src/doctor/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from '@umijs/bundler-utils/compiled/esbuild';
import fs from 'fs';
import path from 'path';
import { getContentHash } from '../builder/utils';
import { getCache } from '../utils';

export type IDoctorSourceParseResult = {
Expand All @@ -14,8 +15,11 @@ export default async (
fileAbsPath: string,
): Promise<IDoctorSourceParseResult> => {
const cache = getCache('doctor-parser');
// format: {path:mtime}
const cacheKey = [fileAbsPath, fs.statSync(fileAbsPath).mtimeMs].join(':');
// format: {path:contenthash}
const cacheKey = [
fileAbsPath,
getContentHash(fs.readFileSync(fileAbsPath, 'utf-8')),
].join(':');
const cacheRet = cache.getSync(cacheKey, '');
const ret: IDoctorSourceParseResult = { imports: [] };

Expand Down
Loading