diff --git a/lib/after-prepare.js b/lib/after-prepare.js index 7138b402..333e60f7 100644 --- a/lib/after-prepare.js +++ b/lib/after-prepare.js @@ -12,7 +12,12 @@ module.exports = function (hookArgs) { release: hookArgs.prepareData.release }; - if (env.snapshot && shouldSnapshot(shouldSnapshotOptions)) { + if (env.snapshot && + shouldSnapshot(shouldSnapshotOptions) && + (!hookArgs.prepareData || + !hookArgs.prepareData.nativePrepare || + !hookArgs.prepareData.nativePrepare.skipNativePrepare)) { + installSnapshotArtefacts(hookArgs.prepareData.projectDir); } } diff --git a/lib/utils.js b/lib/utils.js index 8876252a..17b1eb33 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,4 +1,6 @@ const os = require("os"); +const { dirname } = require("path"); +const { existsSync, mkdirSync } = require("fs"); const { isAndroid } = require("../projectHelpers"); function shouldSnapshot(config) { @@ -21,9 +23,19 @@ function warn(message) { } } +function ensureDirectoryExistence(filePath) { + var dir = dirname(filePath); + if (existsSync(dir)) { + return true; + } + ensureDirectoryExistence(dir); + mkdirSync(dir); +} + module.exports = { shouldSnapshot, convertToUnixPath, isWinOS, - warn + warn, + ensureDirectoryExistence }; diff --git a/plugins/NativeScriptSnapshotPlugin/index.js b/plugins/NativeScriptSnapshotPlugin/index.js index fe32ce1b..58b14876 100644 --- a/plugins/NativeScriptSnapshotPlugin/index.js +++ b/plugins/NativeScriptSnapshotPlugin/index.js @@ -8,6 +8,7 @@ const { ANDROID_PROJECT_DIR, ANDROID_APP_PATH, } = require("../../androidProjectHelpers"); +const { ensureDirectoryExistence } = require("../../lib/utils"); const schema = require("./options.json"); const SNAPSHOT_ENTRY_NAME = "snapshot-entry"; @@ -57,6 +58,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 @@ -68,7 +70,6 @@ exports.NativeScriptSnapshotPlugin = (function () { // ensure that the runtime is installed only in the snapshotted chunk webpackConfig.optimization.runtimeChunk = { name: SNAPSHOT_ENTRY_NAME }; } - NativeScriptSnapshotPlugin.getInternalRequireModules = function (webpackContext) { const packageJson = getPackageJson(webpackContext); return (packageJson && packageJson["android"] && packageJson["android"]["requireModules"]) || [];