forked from smt116/node-native-ext-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (30 loc) · 1.15 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
var path = require("path");
module.exports = function (content) {
const defaultConfig = {
rewritePath: undefined
};
const config = Object.assign(defaultConfig, this.query);
const fileName = path.basename(this.resourcePath);
if (this.emitFile) {
this.emitFile(fileName, content, false);
this.addDependency(this.resourcePath);
} else {
throw new Error('emitFile function is not available');
}
if (config.rewritePath) {
let filePath;
if (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 {
return "const path = require('path');" +
"const filePath = path.resolve(__dirname, " + JSON.stringify(fileName) + ");" +
"try { global.process.dlopen(module, filePath); } " +
"catch(exception) { throw new Error('Cannot open ' + filePath + ': ' + exception); };";
}
};
module.exports.raw = true;