fix(core): update

This commit is contained in:
Philipp Kunz 2021-04-19 12:55:11 +00:00
parent 6b13e46947
commit d59875f23f
7 changed files with 581 additions and 187 deletions

701
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,15 +15,16 @@
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.11.2",
"@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^14.14.41",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@pushrocks/consolecolor": "^2.0.1",
"@pushrocks/smartarchive": "^1.0.12",
"@pushrocks/smartfile": "^8.0.4",
"@pushrocks/smartarchive": "^2.0.2",
"@pushrocks/smartfile": "^8.0.9",
"@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartrequest": "^1.1.51",
"package-json": "^6.5.0"
},

View File

@ -39,8 +39,9 @@ tap.test('should get package from verdaccio', async () => {
tap.test('should get a specific file from a package', async () => {
const bundleFile = await verdaccioRegistry.getFileFromPackage(
'@pushrocks/websetup',
'dist_bundle/bundle.js'
'ts/index.ts'
);
console.log(bundleFile.contentBuffer.toString());
});
tap.start();

View File

@ -48,9 +48,9 @@ export class NpmPackage {
} = null;
public searchScore: number = null;
public npmRegistry: NpmRegistry;
public npmRegistryRef: NpmRegistry;
constructor(npmRegistryArg: NpmRegistry) {
this.npmRegistry = npmRegistryArg;
this.npmRegistryRef = npmRegistryArg;
}
/**
@ -58,6 +58,38 @@ export class NpmPackage {
*/
public async saveToDisk(targetDir: string) {
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
await smartarchiveInstance.extractArchiveFromUrl(this.dist.tarball, targetDir);
await smartarchiveInstance.extractArchiveFromUrlToFs(this.dist.tarball, targetDir);
}
/**
* saves the package to memory
*/
public async saveToMemory() {}
/**
* get file from package
*/
public async getFileFromPackage(filePath: string): Promise<plugins.smartfile.Smartfile> {
const done = plugins.smartpromise.defer<plugins.smartfile.Smartfile>();
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
const fileObservable = await smartarchiveInstance.extractArchiveFromUrlToObservable(
this.dist.tarball
);
const wantedFilePath = plugins.path.join('package', filePath);
const subscription = fileObservable.subscribe(
(fileArg) => {
if (fileArg.path === wantedFilePath) {
done.resolve(fileArg);
subscription.unsubscribe();
}
},
(err) => {
console.log(err);
},
() => {
subscription.unsubscribe();
}
);
return done.promise;
}
}

View File

@ -45,6 +45,7 @@ export class NpmRegistry {
* @param targetDir
*/
public async savePackageToDisk(packageName: string, targetDir: string): Promise<void> {
plugins.smartfile.fs.ensureDirSync(paths.nogitDir);
const npmPackage = await this.getPackageInfo(packageName);
await npmPackage.saveToDisk(targetDir);
}
@ -52,15 +53,9 @@ export class NpmRegistry {
/**
* gets a file from a package as Smartfile
*/
public async getFileFromPackage(packageNameArg: string, filePath: string) {
const baseDir = plugins.path.join(paths.nogitDir, packageNameArg.replace('/', '__'));
await plugins.smartfile.fs.ensureDir(baseDir);
await this.savePackageToDisk(packageNameArg, baseDir);
const smartfile = await plugins.smartfile.Smartfile.fromFilePath(
plugins.path.join(baseDir, 'package', filePath)
);
await plugins.smartfile.fs.remove(baseDir);
return smartfile;
public async getFileFromPackage(packageNameArg: string, filePath: string): Promise<plugins.smartfile.Smartfile> {
const npmPackage = await this.getPackageInfo(packageNameArg);
return npmPackage.getFileFromPackage(filePath);
}
public async getPackageAsSmartfileVirtualDir(packageNameArg: string): Promise<plugins.smartfile.VirtualDirectory> {

View File

@ -2,4 +2,3 @@ import * as plugins from './smartnpm.plugins';
export const packageDir = plugins.path.join(__dirname, '../');
export const nogitDir = plugins.path.join(packageDir, '.nogit/');
plugins.smartfile.fs.ensureDirSync(nogitDir);

View File

@ -7,9 +7,10 @@ export { path };
import * as consolecolor from '@pushrocks/consolecolor';
import * as smartarchive from '@pushrocks/smartarchive';
import * as smartfile from '@pushrocks/smartfile';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
export { consolecolor, smartarchive, smartfile, smartrequest };
export { consolecolor, smartarchive, smartfile, smartpromise, smartrequest };
// third party scope
import packageJson from 'package-json';