-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
119 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { GLOBALS_KEY, TGlobal } from '~/constants'; | ||
|
||
export default ((global as any)[GLOBALS_KEY] || | ||
((global as any)[GLOBALS_KEY] = {})) as { [key in TGlobal]: any }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import inVersionRange from './version-range'; | ||
import _ from './globals'; | ||
import { TGlobal } from '~/constants'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
export default function globals<T>(key: TGlobal, initial: T) { | ||
inVersionRange(); | ||
|
||
return { | ||
get(): T { | ||
return _[key] || (_[key] = initial); | ||
}, | ||
set(value: T): void { | ||
_[key] = value; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import read from 'read-pkg-up'; | ||
import cache from '~/utils/cache'; | ||
import { IOfType } from '~/types'; | ||
import errors from '~/utils/errors'; | ||
|
||
export default cache( | ||
null, | ||
(): IOfType<any> => { | ||
try { | ||
return read.sync({ cwd: __dirname }).pkg; | ||
} catch (e) { | ||
throw new errors.CustomError(`Package couldn't be retrieved`, null, e); | ||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { clean, diff } from 'semver'; | ||
import pkg from './pkg'; | ||
import globals from './globals'; | ||
|
||
export default function inVersionRange(): void { | ||
if (!globals.version) { | ||
globals.version = clean(pkg().version); | ||
return; | ||
} | ||
|
||
const executable = globals.version && clean(globals.version); | ||
const local = pkg().version && clean(pkg().version); | ||
|
||
if (!executable || !local) throw Error(`Version could not be parsed`); | ||
|
||
const release = diff(executable, local); | ||
|
||
// `false` if difference is a major version or we're on v0.x.x | ||
if ( | ||
release !== 'major' && | ||
release !== 'premajor' && | ||
(!release || (local as string)[0] !== '0') | ||
) { | ||
return; | ||
} | ||
|
||
throw Error( | ||
`Local kpo version (${local})` + | ||
` doesn't match executing version (${executable})` | ||
); | ||
} |