Skip to content

Commit

Permalink
fix: dts lost in re-compilation if save file with same content (#691)
Browse files Browse the repository at this point in the history
* fix: dts lost in re-compilation if save file with same content

* refactor: make all legacy tsc cache invalid
  • Loading branch information
PeachScript committed Aug 8, 2023
1 parent 4621887 commit ba85ed9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/builder/bundless/dts/index.ts
Expand Up @@ -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
Expand Down Expand Up @@ -94,7 +95,7 @@ export default async function getDeclarations(
tsconfig.options.incremental = true;
tsconfig.options.tsBuildInfoFile = path.join(
tscCacheDir,
'tsconfig.tsbuildinfo',
'tsc.tsbuildinfo',
);
}

Expand All @@ -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(':'),
}),
Expand Down Expand Up @@ -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(':');

Expand Down
6 changes: 5 additions & 1 deletion src/builder/utils.ts
Expand Up @@ -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 */
'';

Expand All @@ -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);
}

0 comments on commit ba85ed9

Please sign in to comment.