Browse Source

refactor: version check

Ryan Chandler 4 years ago
parent
commit
fb8388d0d1
8 changed files with 11 additions and 3 deletions
  1. 0 0
      dist/spruce.js
  2. 0 0
      dist/spruce.js.map
  3. 0 0
      dist/spruce.module.js
  4. 0 0
      dist/spruce.module.js.map
  5. 0 0
      dist/spruce.umd.js
  6. 0 0
      dist/spruce.umd.js.map
  7. 2 3
      src/index.js
  8. 9 0
      src/utils.js

File diff suppressed because it is too large
+ 0 - 0
dist/spruce.js


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.js.map


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.module.js


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.module.js.map


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.umd.js


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.umd.js.map


+ 2 - 3
src/index.js

@@ -1,6 +1,5 @@
-import { domReady, getMethods } from './utils'
+import { domReady, getMethods, checkForAlpine } from './utils'
 import { createObservable } from './observable'
-import compareVersions from 'compare-versions';
 
 const Spruce = {
     stores: {},
@@ -42,7 +41,7 @@ const Spruce = {
     },
 
     attach() {
-        if (!window.Alpine || ! compareVersions.compare(window.Alpine.version, '2.7.0', '>=')) {
+        if (! checkForAlpine()) {
             throw new Error('[Spruce] You must be using Alpine >= 2.5.0 to use Spruce.')
         }
 

+ 9 - 0
src/utils.js

@@ -24,4 +24,13 @@ export const getMethods = obj => {
     Object.entries(obj).filter(([key, value]) => typeof value === 'function').forEach(([key, value]) => methods[key] = value)
 
     return methods
+}
+
+export const isTesting = () => {
+    return navigator.userAgent, navigator.userAgent.includes("Node.js")
+        || navigator.userAgent.includes("jsdom")
+}
+
+export const checkForAlpine = () => {
+    return isTesting() || (! window.Alpine || ! compareVersions.compare(window.Alpine.version, '2.7.0', '>='))
 }

Some files were not shown because too many files changed in this diff