UNPKG

2.15 kBJavaScriptView Raw
1const semver = require("semver");
2
3const webpackPackageName = "@nativescript/webpack";
4
5module.exports = function ($staticConfig, hookArgs) {
6 const cliVersion = semver.parse($staticConfig.version);
7 const platfrom = hookArgs.prepareData.platform;
8 const projectData = hookArgs.projectData;
9
10 // Required CLI version for building IOS: 6.2.0
11 if (platfrom.toLowerCase() === "ios" &&
12 !satisfiesRequriredVersion(cliVersion, 6, 2)) {
13 throw new Error(`Building @nativescript/core for iOS requires NativeScript CLI with version at least 6.2.0. Please upgrade your NativeScript CLI version (npm i -g nativescript).`);
14 }
15
16 // Required webpack version for angular projects: 1.3.0
17 if (projectData.projectType === "Angular") {
18 const webpackMinVer = getMinWebpackVersion(projectData);
19
20 if (webpackMinVer && !satisfiesRequriredVersion(webpackMinVer, 1, 3)) {
21 throw new Error(`Building @nativescript/core for Angular requires ${webpackPackageName} with version at least 1.3.0. Please upgrade: npm i ${webpackPackageName} --save-dev.`);
22 }
23 }
24};
25
26/**
27 * Checks if semver object satisifies a major/minor requirement. Pre-release versions are OK too!
28 */
29function satisfiesRequriredVersion(actualVersion, requiredMajor, requiredMinor) {
30 // Return true for null version to handle tags (ex. "next", "rc")
31 if (!actualVersion) {
32 return true;
33 }
34
35 if (actualVersion.major < requiredMajor) {
36 return false;
37 }
38
39 if (actualVersion.major === requiredMajor && actualVersion.minor < requiredMinor) {
40 return false;
41 }
42
43 return true;
44}
45
46function getMinWebpackVersion(projectData) {
47 const devDependencies = projectData.devDependencies || {};
48 const dependencies = projectData.dependencies || {};
49 const webpackVer = dependencies[webpackPackageName] || devDependencies[webpackPackageName];
50
51 let webpackMinVer = null;
52
53 if (semver.valid(webpackVer)) {
54 webpackMinVer = semver.parse(webpackVer);
55 } else if (semver.validRange(webpackVer)) {
56 webpackMinVer = semver.minVersion(webpackVer);
57 }
58
59 return webpackMinVer;
60}
\No newline at end of file