-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (55 loc) · 1.54 KB
/
index.js
File metadata and controls
63 lines (55 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
const assert = require('node:assert');
const NpmFsBuilder = require('./npm_fs_builder');
const TnpmFsBuilder = require('./tnpm_fs_builder');
const { NpmFsMode } = require('../constants');
const { Bar } = require('../logger');
class NpmFs {
/**
* @param {NpmBlobManager} blobManager -
* @param {object} [options] -
* @param {string} [options.mode] -
* @param {number} [options.uid] -
* @param {number} [options.gid] -
* @param {boolean} [options.singleMount] -
*/
constructor(blobManager, options) {
this.blobManager = blobManager;
this.options = Object.assign({
uid: process.getuid(),
gid: process.getgid(),
mode: NpmFsMode.NPM,
singleMount: false,
}, options);
}
get mode() {
return this.options.mode;
}
get singleMount() {
return this.options.singleMount;
}
async getFsMeta(pkgLockJson, pkgPath = '') {
this.bar = new Bar({
type: 'fs meta',
total: Object.keys(pkgLockJson.packages).length,
});
const builderClazz = this._getFsMetaBuilder();
const builder = new builderClazz(this.blobManager, this.options);
const res = await builder.generateFsMeta(pkgLockJson, pkgPath, entryName => {
this.bar.update(entryName);
});
this.bar.stop();
return res;
}
_getFsMetaBuilder() {
switch (this.mode) {
case NpmFsMode.NPM:
return NpmFsBuilder;
case NpmFsMode.NPMINSTALL:
return TnpmFsBuilder;
default:
assert.fail(`npm fs mode: ${this.mode} not impl`);
}
}
}
module.exports = NpmFs;