Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 2a0eaf6

Browse files
committed
fix: ensure the js snapshot entry dir if not created (avoid ENOENT error)
1 parent 53cac58 commit 2a0eaf6

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

  • plugins/NativeScriptSnapshotPlugin

‎plugins/NativeScriptSnapshotPlugin/index.js‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const{ relative, resolve, join }=require("path");
2-
const{ closeSync, openSync, writeFileSync }=require("fs");
1+
const{ relative, resolve, join, dirname}=require("path");
2+
const{ closeSync, openSync, writeFileSync, existsSync, mkdirSync}=require("fs");
33
constvalidateOptions=require("schema-utils");
44

55
constProjectSnapshotGenerator=require("../../snapshot/android/project-snapshot-generator");
@@ -57,6 +57,7 @@ exports.NativeScriptSnapshotPlugin = (function () {
5757
snapshotEntryContent+=[...requireModules, ...internalRequireModules]
5858
.map(mod=>`require('${mod}')`).join(";");
5959

60+
ensureDirectoryExistence(snapshotEntryPath);
6061
writeFileSync(snapshotEntryPath,snapshotEntryContent,{encoding: "utf8"});
6162

6263
// add the module to the entry points to make sure it's content is evaluated
@@ -69,6 +70,15 @@ exports.NativeScriptSnapshotPlugin = (function () {
6970
webpackConfig.optimization.runtimeChunk={name: SNAPSHOT_ENTRY_NAME};
7071
}
7172

73+
functionensureDirectoryExistence(filePath){
74+
vardir=dirname(filePath);
75+
if(existsSync(dir)){
76+
returntrue;
77+
}
78+
ensureDirectoryExistence(dir);
79+
mkdirSync(dir);
80+
}
81+
7282
NativeScriptSnapshotPlugin.getInternalRequireModules=function(webpackContext){
7383
constpackageJson=getPackageJson(webpackContext);
7484
return(packageJson&&packageJson["android"]&&packageJson["android"]["requireModules"])||[];

0 commit comments

Comments
 (0)