Skip to content

Commit 91dafc2

Browse files
refactor(frontend/aiscript): AiScriptバージョン取得・判定ロジックを統一 (#16845)
* refactor(frontend): AiScriptバージョン取得・判定ロジックを統一 * fix
1 parent 4edd6a6 commit 91dafc2

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

packages/frontend/src/aiscript/common.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
import { errors, utils } from '@syuilo/aiscript';
77
import type { values } from '@syuilo/aiscript';
88

9-
const extractVersionIdentifier = /^\/\/\/\s*@\s*(\d+)\.(\d+)\.\d+$/m;
10-
11-
export function getAiScriptVersion(script: string): { major: number; minor: number } | undefined {
12-
const match = extractVersionIdentifier.exec(script);
13-
return match ? { major: Number(match[1]), minor: Number(match[2]) } : undefined;
14-
}
15-
169
export function assertStringAndIsIn<A extends readonly string[]>(value: values.Value | undefined, expects: A): asserts value is values.VStr & { value: A[number] } {
1710
utils.assertString(value);
1811
const str = value.value;

packages/frontend/src/pages/flash/flash.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ SPDX-License-Identifier: AGPL-3.0-only
6363
<script lang="ts" setup>
6464
import { computed, onDeactivated, onUnmounted, ref, watch, shallowRef, defineAsyncComponent } from 'vue';
6565
import * as Misskey from 'misskey-js';
66+
import { utils } from '@syuilo/aiscript';
67+
import { compareVersions } from 'compare-versions';
6668
import { url } from '@@/js/config.js';
6769
import type { Ref } from 'vue';
6870
import type { AsUiComponent, AsUiRoot } from '@/aiscript/ui.js';
@@ -74,7 +76,6 @@ import { misskeyApi } from '@/utility/misskey-api.js';
7476
import { i18n } from '@/i18n.js';
7577
import { definePage } from '@/page.js';
7678
import MkAsUi from '@/components/MkAsUi.vue';
77-
import { getAiScriptVersion } from '@/aiscript/common.js';
7879
import { registerAsUiLib } from '@/aiscript/ui.js';
7980
import { aiScriptReadline, createAiScriptEnv } from '@/aiscript/api.js';
8081
import MkFolder from '@/components/MkFolder.vue';
@@ -191,12 +192,21 @@ function start() {
191192
run();
192193
}
193194
195+
function getIsLegacy(version: string | null): boolean {
196+
if (version == null) return false;
197+
try {
198+
return compareVersions(version, '1.0.0') < 0;
199+
} catch {
200+
return false;
201+
}
202+
}
203+
194204
async function run() {
195205
if (aiscript.value) aiscript.value.abort();
196206
if (!flash.value) return;
197207
198-
const version = getAiScriptVersion(flash.value.script);
199-
const isLegacy = version ? version.major < 1 : false;
208+
const version = utils.getLangVersion(flash.value.script);
209+
const isLegacy = version != null && getIsLegacy(version);
200210
201211
const { Interpreter, Parser, values } = isLegacy ? (await import('@syuilo/aiscript-0-19-0') as any) : await import('@syuilo/aiscript');
202212

0 commit comments

Comments
 (0)