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

fix: stop looking for local snapshot artefacts when the native prepare is skipped #1117

Merged
merged 2 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/after-prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
14 changes: 13 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const os = require("os");
const { dirname } = require("path");
const { existsSync, mkdirSync } = require("fs");
const { isAndroid } = require("../projectHelpers");

function shouldSnapshot(config) {
Expand All @@ -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
};
3 changes: 2 additions & 1 deletion plugins/NativeScriptSnapshotPlugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand All @@ -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"]) || [];
Expand Down