-
Notifications
You must be signed in to change notification settings - Fork 3
/
ElmAsset.js
31 lines (26 loc) · 834 Bytes
/
ElmAsset.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
const elmCompiler = require('node-elm-compiler');
const { findAllDependencies } = require('find-elm-dependencies');
const process = require('process');
const JSAsset = require('parcel-bundler/src/assets/JSAsset');
class ElmAsset extends JSAsset {
getParserOptions() {
const defaultOptions = {
cwd: process.cwd(),
};
return defaultOptions;
}
async getDependencies() {
await super.getDependencies()
let deps = await findAllDependencies(this.name);
deps.forEach(dep => {
this.addDependency(dep, { includedInParent: true });
});
}
async parse(code) {
const options = this.getParserOptions();
const data = elmCompiler.compileToStringSync(this.name, options);
this.contents = data.toString();
return await super.parse(this.contents);
}
}
module.exports = ElmAsset;