diff --git a/src/builder/bundless/dts/index.ts b/src/builder/bundless/dts/index.ts index 67f175f1..df539d69 100644 --- a/src/builder/bundless/dts/index.ts +++ b/src/builder/bundless/dts/index.ts @@ -4,6 +4,7 @@ import path from 'path'; import tsPathsTransformer from 'typescript-transform-paths'; import { CACHE_PATH } from '../../../constants'; import { getCache, logger } from '../../../utils'; +import { getContentHash } from '../../utils'; /** * get parsed tsconfig.json for specific path @@ -94,7 +95,7 @@ export default async function getDeclarations( tsconfig.options.incremental = true; tsconfig.options.tsBuildInfoFile = path.join( tscCacheDir, - 'tsconfig.tsbuildinfo', + 'tsc.tsbuildinfo', ); } @@ -105,7 +106,7 @@ export default async function getDeclarations( // format: {path:mtime:config} [file]: [ file, - fs.lstatSync(file).mtimeMs, + getContentHash(fs.readFileSync(file, 'utf-8')), JSON.stringify(tsconfig.options), ].join(':'), }), @@ -147,7 +148,7 @@ export default async function getDeclarations( cacheKeys[sourceFile] || [ sourceFile, - fs.lstatSync(sourceFile).mtimeMs, + getContentHash(fs.readFileSync(sourceFile, 'utf-8')), JSON.stringify(tsconfig.options), ].join(':'); diff --git a/src/builder/utils.ts b/src/builder/utils.ts index 063f4c5a..17bafb46 100644 --- a/src/builder/utils.ts +++ b/src/builder/utils.ts @@ -128,7 +128,7 @@ export function getBabelStyledComponentsOpts(pkg: IApi['pkg']) { const [name, org] = pkg.name.split('/').reverse(); // hash org to make namespace clear const suffix = org - ? `-${createHash('md5').update(org).digest('hex').slice(0, 4)}` + ? `-${getContentHash(org, 4)}` : /* istanbul ignore next -- @preserve */ ''; @@ -138,3 +138,7 @@ export function getBabelStyledComponentsOpts(pkg: IApi['pkg']) { return opts; } + +export function getContentHash(content: string, length = 8) { + return createHash('md5').update(content).digest('hex').slice(0, length); +}