aboutsummaryrefslogtreecommitdiff
path: root/sandbox/testAppNevena/Front/node_modules/npm-install-checks/index.js
diff options
context:
space:
mode:
authorNevena Bojovic <nenabojov@gmail.com>2022-03-01 20:05:50 +0100
committerNevena Bojovic <nenabojov@gmail.com>2022-03-01 20:05:50 +0100
commit291803c31f829fe0d32bb3207bc11def95a7408c (patch)
treec7d43107d79291b19d8c9eceefbe91c9f9a52acf /sandbox/testAppNevena/Front/node_modules/npm-install-checks/index.js
parent1fa69862057db4db53cfda5be9c24b4228ef63f7 (diff)
Urađena test aplikacija. Povezan front i back.
Diffstat (limited to 'sandbox/testAppNevena/Front/node_modules/npm-install-checks/index.js')
-rw-r--r--sandbox/testAppNevena/Front/node_modules/npm-install-checks/index.js79
1 files changed, 79 insertions, 0 deletions
diff --git a/sandbox/testAppNevena/Front/node_modules/npm-install-checks/index.js b/sandbox/testAppNevena/Front/node_modules/npm-install-checks/index.js
new file mode 100644
index 00000000..732888ef
--- /dev/null
+++ b/sandbox/testAppNevena/Front/node_modules/npm-install-checks/index.js
@@ -0,0 +1,79 @@
+const {format} = require('util')
+const semver = require('semver')
+
+const checkEngine = (target, npmVer, nodeVer, force = false) => {
+ const nodev = force ? null : nodeVer
+ const eng = target.engines
+ const opt = { includePrerelease: true }
+ if (!eng) {
+ return
+ }
+
+ const nodeFail = nodev && eng.node && !semver.satisfies(nodev, eng.node, opt)
+ const npmFail = npmVer && eng.npm && !semver.satisfies(npmVer, eng.npm, opt)
+ if (nodeFail || npmFail) {
+ throw Object.assign(new Error('Unsupported engine'), {
+ pkgid: target._id,
+ current: { node: nodeVer, npm: npmVer },
+ required: eng,
+ code: 'EBADENGINE'
+ })
+ }
+}
+
+const checkPlatform = (target, force = false) => {
+ if (force) {
+ return
+ }
+
+ const platform = process.platform
+ const arch = process.arch
+ const osOk = target.os ? checkList(platform, target.os) : true
+ const cpuOk = target.cpu ? checkList(arch, target.cpu) : true
+
+ if (!osOk || !cpuOk) {
+ throw Object.assign(new Error('Unsupported platform'), {
+ pkgid: target._id,
+ current: {
+ os: platform,
+ cpu: arch
+ },
+ required: {
+ os: target.os,
+ cpu: target.cpu
+ },
+ code: 'EBADPLATFORM'
+ })
+ }
+}
+
+const checkList = (value, list) => {
+ if (typeof list === 'string') {
+ list = [list]
+ }
+ if (list.length === 1 && list[0] === 'any') {
+ return true
+ }
+ // match none of the negated values, and at least one of the
+ // non-negated values, if any are present.
+ let negated = 0
+ let match = false
+ for (const entry of list) {
+ const negate = entry.charAt(0) === '!'
+ const test = negate ? entry.slice(1) : entry
+ if (negate) {
+ negated ++
+ if (value === test) {
+ return false
+ }
+ } else {
+ match = match || value === test
+ }
+ }
+ return match || negated === list.length
+}
+
+module.exports = {
+ checkEngine,
+ checkPlatform
+}