forked from parcel-bundler/parcel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackager.js
44 lines (35 loc) · 994 Bytes
/
Packager.js
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
const fs = require('fs');
const promisify = require('../utils/promisify');
const path = require('path');
const {mkdirp} = require('../utils/fs');
class Packager {
constructor(bundle, bundler) {
this.bundle = bundle;
this.bundler = bundler;
this.options = bundler.options;
}
async setup() {
// Create sub-directories if needed
if (this.bundle.name.includes(path.sep)) {
await mkdirp(path.dirname(this.bundle.name));
}
this.dest = fs.createWriteStream(this.bundle.name);
this.dest.write = promisify(this.dest.write.bind(this.dest));
this.dest.end = promisify(this.dest.end.bind(this.dest));
}
async write(string) {
await this.dest.write(string);
}
async start() {}
// eslint-disable-next-line no-unused-vars
async addAsset(asset) {
throw new Error('Must be implemented by subclasses');
}
getSize() {
return this.dest.bytesWritten;
}
async end() {
await this.dest.end();
}
}
module.exports = Packager;