-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (33 loc) · 991 Bytes
/
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
var alasql = require("alasql");
var loaderUtils = require("loader-utils");
var req = /require\(['"`].*['"`]\)[;\n]?/gi;
var imp = /load\(['"`].*['"`]\)[;\n]?/gi;
function parseRequires(content){
return content.match(req);
};
function removeRequires(content){
return content.replace(req,"");
};
function parseLoads(content){
return content.match(imp);
};
//load("./TEST_LOAD.sql") => require("${whoiam}?emit=false!./TEST_LOAD.sql")
function transformLoad(stmt,whoiam){
return stmt.replace(/(load)\(['"`](.*)['"`]\)[;\n]?/i,($1,$2,$3) => (`require("${whoiam}?emit=false!${$3}")`));
};
function removeLoads(content){
return content.replace(imp,"");
}
function whoami(self){
return self.loaders[self.loaderIndex].path
}
module.exports = function(content) {
var self = this;
//self.cacheable && self.cacheable();
alasql(content);
var value = JSON.stringify(alasql.databases.alasql);
self.value = value;
return `
module.exports=JSON.parse('${value}')
`;
};