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" ) ;
33const validateOptions = require ( "schema-utils" ) ;
44
55const ProjectSnapshotGenerator = 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+ function ensureDirectoryExistence ( filePath ) {
74+ var dir = dirname ( filePath ) ;
75+ if ( existsSync ( dir ) ) {
76+ return true ;
77+ }
78+ ensureDirectoryExistence ( dir ) ;
79+ mkdirSync ( dir ) ;
80+ }
81+
7282 NativeScriptSnapshotPlugin . getInternalRequireModules = function ( webpackContext ) {
7383 const packageJson = getPackageJson ( webpackContext ) ;
7484 return ( packageJson && packageJson [ "android" ] && packageJson [ "android" ] [ "requireModules" ] ) || [ ] ;
0 commit comments