// Dependencies.
var through = require("through2");
var PluginError = require("plugin-error");
let fs = require("fs");

/**
 * Add .js to all local imports
 */
function processImports(sourceCode) {
    return sourceCode.replace(/((import|export)(.*)('|")(@babylonjs|\.{1,2}\/)(.*))('|");/g, "$1.js$7;").replace(/(\.js){2,}/g, ".js");
}

/**
 * Add .js to all local imports
 */
function main() {
    return through.obj(function (file, enc, cb) {
        if (file.isNull()) {
            cb(null, file);
            return;
        }
        if (file.isStream()) {
            cb(new PluginError("Process Imports", "Streaming not supported."));
        }

        let data = file.contents.toString();
        data = processImports(data);

        // Go to disk.
        fs.writeFileSync(file.path, data);

        return cb();
    });
}

module.exports = main;

@@ -251,17 +251,14 @@
 ort)
-(
 .*
-)('%7C%22)
+%5B%22'%5D
 (@ba
@@ -264,16 +264,22 @@
 abylonjs
+%5C/.*%5C/
 %7C%5C.%7B1,2%7D
@@ -285,17 +285,15 @@
 %7D%5C/)
-(
 .*)
-)('%7C%22
+(%22%7C'
 );/g
@@ -305,9 +305,9 @@
 .js$
-7
+4
 ;%22).

fix the regex to not match base packages