Skip to content

Commit

Permalink
added import map chunk support
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Duda committed Mar 20, 2024
1 parent b0e9131 commit 4712ff3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ npm i scope-tags -D
}
]
```
> To use multiple files use a file name with `{x}` specifying current import map chunk.
- Option `gitCommitCountLimit` is a maximum number of commits to search for when doing rev walk on git push hook - used just on the user side while running commands `--verify-unpushed-commits` or `--skip`. It this number is reached you'll get a warning and ignoring it may result in some files being ommited from tag verification.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scope-tags",
"version": "0.1.20",
"version": "0.1.21",
"description": "Output human readable test scope report for QA",
"main": "dist/scope.js",
"types": "dist/scope.d.ts",
Expand Down
4 changes: 3 additions & 1 deletion src/Commands/runReportForCommitListCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export async function runReportForCommitListCommand(args: Array<string>, root: s
if (!fileExists(project.useExternalImportMap)) {
console.log(`'useExternalImportMap' - External map for project ${project.name} not found at ${project.useExternalImportMap}, so there won't be references found for files: ${project.supportedFiles}`);
} else {
referenceFinders.push(new ExternalMapReferenceFinder(project.useExternalImportMap, project.supportedFiles));
const externalMapReferenceFinder = new ExternalMapReferenceFinder(project.useExternalImportMap, project.supportedFiles);
referenceFinders.push(externalMapReferenceFinder);
Logger.setConfigurationProperty("Import map chunks", externalMapReferenceFinder.getImportMapChunkCount().toString());
}
}
})
Expand Down
28 changes: 26 additions & 2 deletions src/References/ExternalMapReferenceFinder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { JSONFile } from "../FileSystem/JSONFile";
import { fileExists } from "../FileSystem/fileSystemUtils";
import { IReferenceFinder, ReferencedFileInfo } from "./IReferenceFinder";

type FileImport = { file: string, imports: Array<string> };
Expand All @@ -9,13 +10,36 @@ export class ExternalMapReferenceFinder implements IReferenceFinder {
private _importMap: ImportMapFile;
private _supportedFileExtensions: Array<string>;

private _chunks: number = 0;

constructor(importMapFilePath: string, supportedFileExtensions: Array<string>) {
this._importMap = this._loadImportMap(importMapFilePath);
this._supportedFileExtensions = supportedFileExtensions;
}

private _loadImportMap(path: string): ImportMapFile {
return JSONFile.loadFrom<ImportMapFile>(path);
if (!path.includes("{x}")) {
return JSONFile.loadFrom<ImportMapFile>(path);
} else {
let loadedImportMap: ImportMapFile = [];

while (true) {
const currentChunkFilePath = path.replace("{x}", this._chunks.toString());

if (!fileExists(currentChunkFilePath)) {
return loadedImportMap;
}

const loadedChunk = JSONFile.loadFrom<ImportMapFile>(path);
loadedImportMap = loadedImportMap.concat(loadedChunk);

this._chunks++;
}
}
}

public getImportMapChunkCount(): number {
return this._chunks;
}

public getSupportedFilesExtension(): string[] {
Expand All @@ -32,7 +56,7 @@ export class ExternalMapReferenceFinder implements IReferenceFinder {
unused: false
});
}
})
});

return referenceList;
}
Expand Down

0 comments on commit 4712ff3

Please sign in to comment.