fix(core): update
This commit is contained in:
parent
62f8106fc6
commit
d0ac8f1418
@ -91,21 +91,22 @@ export class NpmPackage {
|
|||||||
public async saveToCache() {}
|
public async saveToCache() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get file from package
|
* get files from package
|
||||||
*/
|
*/
|
||||||
public async getFileFromPackage(
|
public async getFilesFromPackage(
|
||||||
filePath: string,
|
filePath: string,
|
||||||
optionsArg?: {
|
optionsArg: {
|
||||||
distTag?: string;
|
distTag?: string;
|
||||||
version?: string;
|
version?: string;
|
||||||
}
|
},
|
||||||
): Promise<plugins.smartfile.Smartfile> {
|
returnOnFirstArg = false
|
||||||
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();
|
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
|
||||||
let tarballUrl = this.dist.tarball;
|
let tarballUrl = this.dist?.tarball;
|
||||||
if (optionsArg && (optionsArg.version || optionsArg.distTag)) {
|
if (optionsArg?.version || optionsArg?.distTag) {
|
||||||
if (optionsArg.distTag && optionsArg.version) {
|
if (optionsArg.distTag && optionsArg.version) {
|
||||||
throw new Error('Please either sepcify version OR disttag, not both.');
|
throw new Error('Please either specify version OR disttag, not both.');
|
||||||
}
|
}
|
||||||
let targetVersion: plugins.smartversion.SmartVersion;
|
let targetVersion: plugins.smartversion.SmartVersion;
|
||||||
if (optionsArg.distTag) {
|
if (optionsArg.distTag) {
|
||||||
@ -131,27 +132,43 @@ export class NpmPackage {
|
|||||||
}
|
}
|
||||||
const fileObservable = await smartarchiveInstance.extractArchiveFromUrlToObservable(tarballUrl);
|
const fileObservable = await smartarchiveInstance.extractArchiveFromUrlToObservable(tarballUrl);
|
||||||
const wantedFilePath = plugins.path.join('package', filePath);
|
const wantedFilePath = plugins.path.join('package', filePath);
|
||||||
|
const allMatchingFiles: plugins.smartfile.Smartfile[] = [];
|
||||||
const subscription = fileObservable.subscribe(
|
const subscription = fileObservable.subscribe(
|
||||||
(fileArg) => {
|
(fileArg) => {
|
||||||
if (fileArg.path === wantedFilePath) {
|
// returnOnFirstArg requires exact match
|
||||||
// lets care about caching
|
if (returnOnFirstArg && fileArg.path === wantedFilePath) {
|
||||||
|
|
||||||
// lets resolve with the wanted file
|
// lets resolve with the wanted file
|
||||||
done.resolve(fileArg);
|
done.resolve([fileArg]);
|
||||||
subscription.unsubscribe();
|
subscription.unsubscribe();
|
||||||
|
} else if(fileArg.path.startsWith(wantedFilePath)) {
|
||||||
|
allMatchingFiles.push(fileArg);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
done.resolve(null);
|
done.resolve(allMatchingFiles);
|
||||||
subscription.unsubscribe();
|
subscription.unsubscribe();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get files from package
|
||||||
|
*/
|
||||||
|
public async getFileFromPackage(
|
||||||
|
filePath: string,
|
||||||
|
optionsArg?: {
|
||||||
|
distTag?: string;
|
||||||
|
version?: string;
|
||||||
|
}
|
||||||
|
): Promise<plugins.smartfile.Smartfile> {
|
||||||
|
const result = await this.getFilesFromPackage(filePath, optionsArg, true);
|
||||||
|
return result[0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updates the package with information from the registry
|
* updates the package with information from the registry
|
||||||
*/
|
*/
|
||||||
|
@ -36,6 +36,9 @@ export class NpmRegistry {
|
|||||||
const fullMetadata = await plugins.packageJson(packageName, {
|
const fullMetadata = await plugins.packageJson(packageName, {
|
||||||
registryUrl: this.options.npmRegistryUrl,
|
registryUrl: this.options.npmRegistryUrl,
|
||||||
fullMetadata: true,
|
fullMetadata: true,
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
const versionData = await plugins.packageJson(packageName, {
|
const versionData = await plugins.packageJson(packageName, {
|
||||||
registryUrl: this.options.npmRegistryUrl,
|
registryUrl: this.options.npmRegistryUrl,
|
||||||
@ -75,6 +78,13 @@ export class NpmRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getFilesFromPackage(packageNameArg: string, filePath: string, optionsArg: {
|
||||||
|
distTag?: string;
|
||||||
|
version?: string;
|
||||||
|
}): Promise<plugins.smartfile.Smartfile[]> {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
public async getPackageAsSmartfileVirtualDir(packageNameArg: string): Promise<plugins.smartfile.VirtualDirectory> {
|
public async getPackageAsSmartfileVirtualDir(packageNameArg: string): Promise<plugins.smartfile.VirtualDirectory> {
|
||||||
/**
|
/**
|
||||||
* TODO: rewrite as memory only
|
* TODO: rewrite as memory only
|
||||||
|
Loading…
Reference in New Issue
Block a user