Skip to content

Commit

Permalink
fix: Added explicit error if ts is patched and cached backup is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
nonara committed Jun 22, 2023
1 parent 8802054 commit ac25743
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions projects/core/src/module/ts-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path';
import fs from 'fs';
import type { TsPackage } from '../ts-package';
import { getModuleSource, ModuleSource } from './module-source';
import { getCachePath } from '../system';
import { getCachePath, TspError } from '../system';
import { getModuleFile, ModuleFile } from './module-file';
import { cachedFilePatchedPrefix } from '../config';

Expand Down Expand Up @@ -103,7 +103,6 @@ export function getTsModule(

/* Create Module */
const isPatched = !!moduleFile.patchDetail;
let moduleSource: ModuleSource | undefined;
let originalModuleFile: ModuleFile | undefined;
const tsModule: TsModule = {
package: tsPackage,
Expand All @@ -125,7 +124,14 @@ export function getTsModule(
},

getUnpatchedModuleFile() {
if (!originalModuleFile) originalModuleFile = isPatched ? getModuleFile(backupCachePaths.js) : moduleFile!;
if (!originalModuleFile) {
if (isPatched) {
if (!fs.existsSync(backupCachePaths.js)) throw new TspError(`Cannot find backup cache file for ${moduleName}. Please wipe node_modules and reinstall.`);
originalModuleFile = getModuleFile(backupCachePaths.js);
} else {
originalModuleFile = isPatched ? getModuleFile(backupCachePaths.js) : moduleFile!;
}
}

return originalModuleFile;
}
Expand Down

0 comments on commit ac25743

Please sign in to comment.