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

Commit a92876f

Browse files
author
Dimitar Kerezov
committed
fix: allow snapshot only in release
1 parent adb896c commit a92876f

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

Diff for: lib/after-prepare.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ const utils = require("./utils");
33

44
module.exports = function ($mobileHelper, $projectData, hookArgs) {
55
const env = hookArgs.env || {};
6-
if (env.snapshot && utils.shouldSnapshot($mobileHelper, hookArgs.platform, hookArgs.appFilesUpdaterOptions.bundle)) {
6+
const shouldSnapshotOptions = {
7+
platform: hookArgs.platform,
8+
bundle: hookArgs.appFilesUpdaterOptions.bundle,
9+
release: hookArgs.appFilesUpdaterOptions.release
10+
};
11+
12+
if (env.snapshot && utils.shouldSnapshot($mobileHelper, shouldSnapshotOptions)) {
713
snapshotGenerator.installSnapshotArtefacts($projectData.projectDir);
814
}
915
}

Diff for: lib/before-prepareJS.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
const { runWebpackCompiler } = require("./compiler");
22

3-
module.exports = function ($mobileHelper, $projectData, hookArgs) {
3+
module.exports = function ($mobileHelper, $projectData, $logger, hookArgs) {
44
const env = hookArgs.config.env || {};
55
const platform = hookArgs.config.platform;
66
const appFilesUpdaterOptions = hookArgs.config.appFilesUpdaterOptions;
77
const config = {
88
env,
99
platform,
10-
bundle: appFilesUpdaterOptions.bundle
10+
bundle: appFilesUpdaterOptions.bundle,
11+
release: appFilesUpdaterOptions.release,
1112
};
12-
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, $mobileHelper, $projectData, hookArgs);
13+
const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, $mobileHelper, $projectData, $logger, hookArgs);
1314
return result;
1415
}

Diff for: lib/before-watch.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { runWebpackCompiler } = require("./compiler");
22

3-
module.exports = function ($mobileHelper, $projectData, hookArgs) {
3+
module.exports = function ($mobileHelper, $projectData, $logger, hookArgs) {
44
if (hookArgs.config) {
55
const appFilesUpdaterOptions = hookArgs.config.appFilesUpdaterOptions;
66
if (appFilesUpdaterOptions.bundle) {
@@ -11,10 +11,11 @@ module.exports = function ($mobileHelper, $projectData, hookArgs) {
1111
env,
1212
platform,
1313
bundle: appFilesUpdaterOptions.bundle,
14+
release: appFilesUpdaterOptions.release,
1415
watch: true
1516
};
1617

17-
return runWebpackCompiler(config, $mobileHelper, $projectData, hookArgs);
18+
return runWebpackCompiler(config, $mobileHelper, $projectData, $logger, hookArgs);
1819
}));
1920
}
2021
}

Diff for: lib/compiler.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ const { AppDirectoryLocation } = require("./constants");
99
let hasBeenInvoked = false;
1010

1111
let webpackProcess = null;
12+
let hasLoggedSnapshotWarningMessage = false;
13+
14+
function logdSnapshotWarningMessage($logger) {
15+
if (!hasLoggedSnapshotWarningMessage) {
16+
$logger.warn("Stripping the snapshot flag. Bear in mind that snapshot is only available in release builds and is NOT available on Windows systems.");
17+
}
18+
}
1219

1320
exports.getWebpackProcess = function getWebpackProcess() {
1421
return webpackProcess;
1522
}
1623

17-
exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper, $projectData, hookArgs, originalArgs, originalMethod) {
24+
exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper, $projectData, $logger, hookArgs) {
1825
if (config.bundle) {
1926
return new Promise(function (resolveBase, rejectBase) {
2027
if (webpackProcess) {
@@ -37,7 +44,8 @@ exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper,
3744
const envFlagNames = Object.keys(config.env).concat([config.platform.toLowerCase()]);
3845

3946
const snapshotEnvIndex = envFlagNames.indexOf("snapshot");
40-
if (snapshotEnvIndex !== -1 && !utils.shouldSnapshot($mobileHelper, config.platform, config.bundle)) {
47+
if (snapshotEnvIndex !== -1 && !utils.shouldSnapshot($mobileHelper, config)) {
48+
logdSnapshotWarningMessage($logger);
4149
envFlagNames.splice(snapshotEnvIndex, 1);
4250
}
4351

Diff for: lib/utils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const os = require("os");
22

3-
function shouldSnapshot($mobileHelper, platform, bundle) {
4-
const platformSupportsSnapshot = $mobileHelper.isAndroidPlatform(platform);
3+
function shouldSnapshot($mobileHelper, config) {
4+
const platformSupportsSnapshot = $mobileHelper.isAndroidPlatform(config.platform);
55
const osSupportsSnapshot = os.type() !== "Windows_NT";
6-
return bundle && platformSupportsSnapshot && osSupportsSnapshot;
6+
return config.bundle && config.release && platformSupportsSnapshot && osSupportsSnapshot;
77
}
88

99
module.exports.shouldSnapshot = shouldSnapshot;

0 commit comments

Comments
 (0)