Use import-fresh package to require w/out cache
authorRaphael von der Grün <raphinesse@gmail.com>
Sat, 12 May 2018 22:29:50 +0000 (00:29 +0200)
committerRaphael von der Grün <raphinesse@gmail.com>
Sat, 12 May 2018 22:29:50 +0000 (00:29 +0200)
index.js
package.json

index 459559b..5ef138e 100644 (file)
--- a/index.js
+++ b/index.js
@@ -23,6 +23,7 @@ var url = require('url');
 
 var Q = require('q');
 var shell = require('shelljs');
+var requireFresh = require('import-fresh');
 var validateIdentifier = require('valid-identifier');
 
 var fetch = require('cordova-fetch');
@@ -197,9 +198,7 @@ module.exports = function (dir, optionalId, optionalName, cfg, extEvents) {
             // handle when input wants to specify sub-directory (specified in index.js as "dirname" export);
             var isSubDir = false;
             try {
-                // Delete cached require incase one exists
-                delete require.cache[require.resolve(input_directory)];
-                var templatePkg = require(input_directory);
+                var templatePkg = requireFresh(input_directory);
                 if (templatePkg && templatePkg.dirname) {
                     import_from_path = templatePkg.dirname;
                     isSubDir = true;
@@ -247,8 +246,7 @@ module.exports = function (dir, optionalId, optionalName, cfg, extEvents) {
             var pkgjsonPath = path.join(dir, 'package.json');
             // Update package.json name and version fields
             if (fs.existsSync(pkgjsonPath)) {
-                delete require.cache[require.resolve(pkgjsonPath)];
-                var pkgjson = require(pkgjsonPath);
+                var pkgjson = requireFresh(pkgjsonPath);
 
                 // Pkjson.displayName should equal config's name.
                 if (cfg.name) {
index f89a74b..f0c09f0 100644 (file)
@@ -28,6 +28,7 @@
     "cordova-app-hello-world": "^3.11.0",
     "cordova-common": "^2.2.0",
     "cordova-fetch": "^1.3.0",
+    "import-fresh": "^2.0.0",
     "q": "1.0.1",
     "shelljs": "0.3.0",
     "valid-identifier": "0.0.1"