-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.js
55 lines (46 loc) · 1.42 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
var path = require("path");
module.exports = function(content) {
const defaultConfig = {
basePath: [],
rewritePath: undefined,
emit: true
};
const config = Object.assign(defaultConfig, this.query);
const fileName = path.basename(this.resourcePath);
if (config.emit) {
if (this.emitFile) {
this.emitFile(fileName, content, false);
} else {
throw new Error("emitFile function is not available");
}
}
this.addDependency(this.resourcePath);
if (config.rewritePath) {
let filePath;
if (config.rewritePath === "./" || config.rewritePath === ".\\") {
filePath = JSON.stringify(config.rewritePath + fileName);
} else {
filePath = JSON.stringify(path.join(config.rewritePath, fileName));
}
return (
"try { global.process.dlopen(module, " +
filePath +
"); } " +
"catch(exception) { throw new Error('Cannot open ' + " +
filePath +
" + ': ' + exception); };"
);
} else {
const filePathArray = config.basePath.concat(fileName);
const filePath = JSON.stringify(filePathArray).slice(1, -1);
return (
"const path = require('path');" +
"const filePath = path.resolve(__dirname, " +
filePath +
");" +
"try { global.process.dlopen(module, filePath); } " +
"catch(exception) { throw new Error('Cannot open ' + filePath + ': ' + exception); };"
);
}
};
module.exports.raw = true;