1 // Handles JSAN imports and adds the JSAN adaptor as needed.
3 const path = require('path');
4 const fs = require('fs');
5 const loaderUtils = require('loader-utils');
11 isChildOf } = require("./utils.js");
13 module.exports = function() {
15 const callback = this.async();
16 const options = loaderUtils.getOptions(this);
17 var rpath = this.resourcePath;
18 fs.readFile(rpath, function read(err, data) {
22 var JSAN_adapt = "require('"+JSAN_adaptor+"');\n";
24 var replac_func = function(match,group1,group2){
25 head = head || JSAN_adapt;
26 var relpath = group1||group2;
27 var src_path = path.resolve(path.dirname(rpath),relpath);
28 return isChildOf(src_path,options.legacyPath) ? src_path_to_JSAN(options.legacyPath,src_path) : match;
30 var out = String(data).replace(import_regex,replac_func)
31 .replace(common_js_regex,replac_func);
32 callback(null, head+out);