Skip to content

Commit

Permalink
add dep
Browse files Browse the repository at this point in the history
  • Loading branch information
Feverqwe committed Sep 19, 2023
1 parent 175cebd commit 07be926
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/resolvers/md2md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ export async function resolveMd2Md(options: ResolveMd2MdOptions): Promise<void>

const cacheKey = CacheService.getHashKey(inputPath, rawContentHash, varsHashList);

const content = await getContentWithUpdatedMetadata(
rawContent,
metadata,
vars.__system,
);

let result: string;
let changelogs: ChangelogItem[];

Expand All @@ -41,6 +35,12 @@ export async function resolveMd2Md(options: ResolveMd2MdOptions): Promise<void>
result = results.result;
changelogs = results.changelogs;
} else {
const content = await getContentWithUpdatedMetadata(
rawContent,
metadata,
vars.__system,
);

const cacheFile = cacheServiceBuildMd.createFile(cacheKey, inputPath, rawContentHash, varsHashList);
const envApi = PluginEnvApi.create({
root: resolve(input),
Expand Down
7 changes: 4 additions & 3 deletions src/services/cache/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ export class CacheService {
return hash;
}

static getHashKey(filename: string, contentHash: string, varsHashList: string[]) {
static getHashKey(filename: string, contentHash: string, varsHashList: string[], extra?: Record<string, unknown>) {
if (!argsHash) {
const args = ArgvService.getConfig();
const staticArgs = pick(args, [
'varsPreset', 'ignore', 'outputFormat', 'allowHTML', 'vars', 'applyPresets',
'resolveConditions', 'conditionsInCode', 'disableLiquid', 'strict', 'ignoreStage', 'singlePage',
'removeHiddenTocItems', 'connector', 'lang', 'lintConfig', 'resources',
'removeHiddenTocItems', 'connector', 'lang', 'lintConfig', 'resources', 'addSystemMeta',
'contributors', 'ignoreAuthorPatterns', 'allowCustomResources',
]);
argsHash = CacheService.getHash(JSON.stringify(staticArgs));
}
return this.getHash(JSON.stringify({filename, contentHash, varsHashList, argsHash}));
return this.getHash(JSON.stringify({filename, contentHash, varsHashList, argsHash, extra}));
}

private readonly storeName;
Expand Down
15 changes: 9 additions & 6 deletions src/utils/pluginEnvApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ class PluginEnvApi {

readFileSync<T extends BufferEncoding>(rawTarget: string, encoding: T) {
const target = safeRelativePath(rawTarget);
const fullTarget = path.join(this.root, target);

const result = fs.readFileSync(path.join(this.root, target), encoding);
const result = fs.readFileSync(fullTarget, encoding);
if (this.cacheFile) {
this.cacheFile.addFileDep({filename: target, content: result});
}
Expand All @@ -49,20 +50,22 @@ class PluginEnvApi {

fileExistsSync(rawTarget: string) {
const target = safeRelativePath(rawTarget);
const fullTarget = path.join(this.root, target);

const result = fs.existsSync(path.join(this.root, target));
const result = fs.existsSync(fullTarget);
if (this.cacheFile) {
this.cacheFile.addFileExists({filename: target, state: result});
}
return result;
}

writeFileSync(rawTarget: string, data: string) {
const target = safeRelativePath(rawTarget);
writeFileSync(rawTo: string, data: string) {
const to = safeRelativePath(rawTo);
const fullTo = path.join(this.distRoot, to);

fs.writeFileSync(path.join(this.distRoot, target), data);
fs.writeFileSync(fullTo, data);
if (this.cacheFile) {
this.cacheFile.addWriteFile(target, data);
this.cacheFile.addWriteFile(to, data);
}
}

Expand Down

0 comments on commit 07be926

Please sign in to comment.