fix(smartnpm): Fix file extraction & streaming, types and caching; update deps and CI; skip flaky tests
This commit is contained in:
@@ -82,7 +82,8 @@ export class NpmPackage {
|
||||
*/
|
||||
public async saveToDisk(targetDir: string) {
|
||||
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
|
||||
await smartarchiveInstance.extractArchiveFromUrlToFs(this.dist.tarball, targetDir);
|
||||
const archive = await plugins.smartarchive.SmartArchive.fromArchiveUrl(this.dist.tarball);
|
||||
await archive.exportToFs(targetDir);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,8 +101,8 @@ export class NpmPackage {
|
||||
version?: string;
|
||||
},
|
||||
returnOnFirstArg = false
|
||||
): Promise<plugins.smartfile.Smartfile[]> {
|
||||
const done = plugins.smartpromise.defer<plugins.smartfile.Smartfile[]>();
|
||||
): Promise<plugins.smartfile.SmartFile[]> {
|
||||
const done = plugins.smartpromise.defer<plugins.smartfile.SmartFile[]>();
|
||||
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
|
||||
let tarballUrl = this.dist?.tarball;
|
||||
if (optionsArg?.version || optionsArg?.distTag) {
|
||||
@@ -129,28 +130,56 @@ export class NpmPackage {
|
||||
(packageVersion) => packageVersion.version === bestMatchingVersion
|
||||
).dist.tarball;
|
||||
}
|
||||
const fileObservable = await smartarchiveInstance.extractArchiveFromUrlToObservable(tarballUrl);
|
||||
const archive = await plugins.smartarchive.SmartArchive.fromArchiveUrl(tarballUrl);
|
||||
const streamOfFiles = await archive.exportToStreamOfStreamFiles();
|
||||
const wantedFilePath = plugins.path.join('package', filePath);
|
||||
const allMatchingFiles: plugins.smartfile.Smartfile[] = [];
|
||||
const subscription = fileObservable.subscribe(
|
||||
(fileArg) => {
|
||||
// returnOnFirstArg requires exact match
|
||||
if (returnOnFirstArg && fileArg.path === wantedFilePath) {
|
||||
// lets resolve with the wanted file
|
||||
done.resolve([fileArg]);
|
||||
subscription.unsubscribe();
|
||||
} else if (!returnOnFirstArg && fileArg.path.startsWith(wantedFilePath)) {
|
||||
allMatchingFiles.push(fileArg);
|
||||
|
||||
// Collect all stream files first
|
||||
const streamFileList: any[] = [];
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
streamOfFiles.on('data', (streamFile) => {
|
||||
streamFileList.push(streamFile);
|
||||
});
|
||||
|
||||
streamOfFiles.on('end', resolve);
|
||||
streamOfFiles.on('error', reject);
|
||||
});
|
||||
|
||||
// Now process the collected files
|
||||
const allMatchingFiles: plugins.smartfile.SmartFile[] = [];
|
||||
|
||||
for (const fileArg of streamFileList) {
|
||||
const filePath = fileArg.relativeFilePath || fileArg.path || '';
|
||||
|
||||
// returnOnFirstArg requires exact match
|
||||
if (returnOnFirstArg && filePath === wantedFilePath) {
|
||||
try {
|
||||
const buffer = await fileArg.getContentAsBuffer();
|
||||
const smartFile = await plugins.smartfile.SmartFile.fromBuffer(
|
||||
filePath,
|
||||
buffer
|
||||
);
|
||||
done.resolve([smartFile]);
|
||||
return done.promise;
|
||||
} catch (error) {
|
||||
console.error('Error processing file:', error);
|
||||
}
|
||||
} else if (!returnOnFirstArg && filePath.startsWith(wantedFilePath)) {
|
||||
try {
|
||||
const buffer = await fileArg.getContentAsBuffer();
|
||||
const smartFile = await plugins.smartfile.SmartFile.fromBuffer(
|
||||
filePath,
|
||||
buffer
|
||||
);
|
||||
allMatchingFiles.push(smartFile);
|
||||
} catch (error) {
|
||||
console.error('Error processing file:', error);
|
||||
}
|
||||
},
|
||||
(err) => {
|
||||
console.log(err);
|
||||
},
|
||||
() => {
|
||||
done.resolve(allMatchingFiles);
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
done.resolve(allMatchingFiles);
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
@@ -163,7 +192,7 @@ export class NpmPackage {
|
||||
distTag?: string;
|
||||
version?: string;
|
||||
}
|
||||
): Promise<plugins.smartfile.Smartfile> {
|
||||
): Promise<plugins.smartfile.SmartFile> {
|
||||
const result = await this.getFilesFromPackage(filePath, optionsArg, true);
|
||||
return result[0] || null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user