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

Commit

Permalink
fix: ensure the js snapshot entry dir if not created (avoid ENOENT er…
Browse files Browse the repository at this point in the history
…ror)
  • Loading branch information
DimitarTachev committed Jan 24, 2020
1 parent 53cac58 commit 2a0eaf6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions plugins/NativeScriptSnapshotPlugin/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { relative, resolve, join } = require("path");
const { closeSync, openSync, writeFileSync } = require("fs");
const { relative, resolve, join, dirname } = require("path");
const { closeSync, openSync, writeFileSync, existsSync, mkdirSync } = require("fs");
const validateOptions = require("schema-utils");

const ProjectSnapshotGenerator = require("../../snapshot/android/project-snapshot-generator");
Expand Down Expand Up @@ -57,6 +57,7 @@ exports.NativeScriptSnapshotPlugin = (function () {
snapshotEntryContent += [...requireModules, ...internalRequireModules]
.map(mod => `require('${mod}')`).join(";");

ensureDirectoryExistence(snapshotEntryPath);
writeFileSync(snapshotEntryPath, snapshotEntryContent, { encoding: "utf8" });

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

function ensureDirectoryExistence(filePath) {
var dir = dirname(filePath);
if (existsSync(dir)) {
return true;
}
ensureDirectoryExistence(dir);
mkdirSync(dir);
}

NativeScriptSnapshotPlugin.getInternalRequireModules = function (webpackContext) {
const packageJson = getPackageJson(webpackContext);
return (packageJson && packageJson["android"] && packageJson["android"]["requireModules"]) || [];
Expand Down

0 comments on commit 2a0eaf6

Please sign in to comment.