From 2a0eaf69dc5bc1be11caf7755765b7aee61cc66f Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Fri, 24 Jan 2020 17:22:41 +0200 Subject: [PATCH 1/2] fix: ensure the js snapshot entry dir if not created (avoid ENOENT error) --- plugins/NativeScriptSnapshotPlugin/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/NativeScriptSnapshotPlugin/index.js b/plugins/NativeScriptSnapshotPlugin/index.js index fe32ce1b..207182c4 100644 --- a/plugins/NativeScriptSnapshotPlugin/index.js +++ b/plugins/NativeScriptSnapshotPlugin/index.js @@ -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"); @@ -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 @@ -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"]) || []; From b8da140f9c7dc211df9b7b998db3ae0d7af1c58f Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Fri, 24 Jan 2020 17:23:50 +0200 Subject: [PATCH 2/2] fix: stop searching for snapshot artefacts when the snapshot tools are skipped (it's a cloud build, there aren't any snapshot artefacts locally) --- lib/after-prepare.js | 7 ++++++- lib/utils.js | 14 +++++++++++++- plugins/NativeScriptSnapshotPlugin/index.js | 15 +++------------ 3 files changed, 22 insertions(+), 14 deletions(-) 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 207182c4..58b14876 100644 --- a/plugins/NativeScriptSnapshotPlugin/index.js +++ b/plugins/NativeScriptSnapshotPlugin/index.js @@ -1,5 +1,5 @@ -const { relative, resolve, join, dirname } = require("path"); -const { closeSync, openSync, writeFileSync, existsSync, mkdirSync } = require("fs"); +const { relative, resolve, join } = require("path"); +const { closeSync, openSync, writeFileSync } = require("fs"); const validateOptions = require("schema-utils"); const ProjectSnapshotGenerator = require("../../snapshot/android/project-snapshot-generator"); @@ -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"; @@ -69,16 +70,6 @@ exports.NativeScriptSnapshotPlugin = (function () { // ensure that the runtime is installed only in the snapshotted chunk 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"]) || [];