Skip to content

Commit 4afe82b

Browse files
add gt/ge/lt/le functions to unity version
improved version checking
1 parent 644eb53 commit 4afe82b

4 files changed

Lines changed: 25 additions & 13 deletions

File tree

src/android-sdk.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async function createRepositoryCfg(): Promise<void> {
6464
async function getJDKPath(editor: UnityEditor): Promise<string> {
6565
let jdkPath: string | undefined = undefined;
6666

67-
if (satisfies(editor.version.version, '>=2019.0.0')) {
67+
if (editor.version.isGreaterThanOrEqualTo('2019.0.0')) {
6868
logger.info('Using JDK bundled with Unity 2019+');
6969
jdkPath = await ResolveGlobToPath([editor.editorRootPath, '**', 'AndroidPlayer', 'OpenJDK']);
7070

@@ -73,7 +73,6 @@ async function getJDKPath(editor: UnityEditor): Promise<string> {
7373
}
7474
} else {
7575
logger.info('Using system JDK for Unity versions prior to 2019');
76-
// use system JDK
7776
jdkPath = process.env.JAVA_HOME || process.env.JDK_HOME;
7877

7978
if (!jdkPath) {
@@ -88,7 +87,7 @@ async function getJDKPath(editor: UnityEditor): Promise<string> {
8887

8988
async function getSdkManager(editor: UnityEditor): Promise<string> {
9089
let globPath: string[] = [];
91-
if (satisfies(editor.version.version, '>=2019.0.0')) {
90+
if (editor.version.isGreaterThanOrEqualTo('2019.0.0')) {
9291
logger.info('Using sdkmanager bundled with Unity 2019+');
9392
switch (process.platform) {
9493
case 'darwin':
@@ -138,7 +137,7 @@ async function getAndroidSdkPath(editor: UnityEditor, androidTargetSdk: number):
138137
let sdkPath: string;
139138

140139
// if 2019+ test editor path, else use system android installation
141-
if (satisfies(editor.version.version, '>=2019.0.0')) {
140+
if (editor.version.isGreaterThanOrEqualTo('2019.0.0')) {
142141
try {
143142
sdkPath = await ResolveGlobToPath([editor.editorPath, '**', 'PlaybackEngines', 'AndroidPlayer', 'SDK', 'platforms', `android-${androidTargetSdk}/`]);
144143
} catch (error) {
@@ -185,7 +184,6 @@ async function execSdkManager(sdkManagerPath: string, javaPath: string, args: st
185184
cmdEnv.JAVA_HOME = process.platform === 'win32' ? `"${javaPath}"` : javaPath;
186185
cmdEnv.JDK_HOME = process.platform === 'win32' ? `"${javaPath}"` : javaPath;
187186
cmdEnv.SKIP_JDK_VERSION_CHECK = 'true';
188-
cmdEnv.JAVA_TOOL_OPTIONS = '--enable-native-access=ALL-UNNAMED';
189187
let cmd = sdkManagerPath;
190188
let cmdArgs = args;
191189

src/unity-editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class UnityEditor {
6767
this.version = version;
6868
}
6969

70-
this.autoAddNoGraphics = this.version.satisfies('>2018.0.0');
70+
this.autoAddNoGraphics = this.version.isGreaterThan('2018.0.0');
7171

7272
const hubMetaDataPath = path.join(this.editorRootPath, 'metadata.hub.json');
7373
if (!fs.existsSync(hubMetaDataPath)) {

src/unity-hub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ chmod -R 777 "$hubPath"`]);
705705
editorPath = exactEditor.editorPath;
706706
} else if (allowPartialMatches) {
707707
// Fallback: semver satisfies
708-
const versionEditors = editors.filter(e => e.version && unityVersion.satisfies(e.version.version));
708+
const versionEditors = editors.filter(e => e.version && unityVersion.satisfies(e.version));
709709

710710
if (versionEditors.length === 0) {
711711
return undefined;

src/unity-version.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,28 @@ export class UnityVersion {
103103
return this;
104104
}
105105

106-
satisfies(version: string): boolean {
107-
const coercedVersion = coerce(version);
106+
satisfies(version: UnityVersion): boolean {
107+
return satisfies(version.semVer, `^${this.semVer.version}`);
108+
}
108109

109-
if (!coercedVersion) {
110-
throw new Error(`Invalid version to check against: ${version}`);
111-
}
110+
isGreaterThan(other: string | UnityVersion): boolean {
111+
const otherVersion = other instanceof UnityVersion ? other : new UnityVersion(other);
112+
return UnityVersion.compare(this, otherVersion) > 0;
113+
}
114+
115+
isGreaterThanOrEqualTo(other: string | UnityVersion): boolean {
116+
const otherVersion = other instanceof UnityVersion ? other : new UnityVersion(other);
117+
return UnityVersion.compare(this, otherVersion) >= 0;
118+
}
119+
120+
isLessThan(other: string | UnityVersion): boolean {
121+
const otherVersion = other instanceof UnityVersion ? other : new UnityVersion(other);
122+
return UnityVersion.compare(this, otherVersion) < 0;
123+
}
112124

113-
return satisfies(coercedVersion, `^${this.semVer.version}`);
125+
isLessThanOrEqualTo(other: string | UnityVersion): boolean {
126+
const otherVersion = other instanceof UnityVersion ? other : new UnityVersion(other);
127+
return UnityVersion.compare(this, otherVersion) <= 0;
114128
}
115129

116130
equals(other: UnityVersion): boolean {

0 commit comments

Comments
 (0)