diff --git a/package-lock.json b/package-lock.json index ae4d31981e..cb11c48441 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "glob": "11.0.0", "hotkeys-js": "3.13.6", "immer": "9.0.21", - "kuromoji": "github:VOICEVOX/kuromoji.js#path.joinをなくす", + "kuromoji": "github:VOICEVOX/kuromoji.js#すべてを書き換えうr", "markdown-it": "13.0.2", "move-file": "3.0.0", "multistream": "4.1.0", @@ -57,7 +57,6 @@ "@types/async-lock": "1.4.0", "@types/encoding-japanese": "1.0.18", "@types/glob": "8.0.0", - "@types/kuromoji": "0.1.3", "@types/markdown-it": "12.2.0", "@types/multistream": "4.1.0", "@types/semver": "7.3.9", @@ -3355,13 +3354,6 @@ "@types/ms": "*" } }, - "node_modules/@types/doublearray": { - "version": "0.0.32", - "resolved": "https://registry.npmjs.org/@types/doublearray/-/doublearray-0.0.32.tgz", - "integrity": "sha512-HloTru3I3a55runIVqZX1YBQi2L5A4peNQPh33yshzB4ttt1qHCnHPkuhy9Djy/cTx7i5xJvxItKRPCmvnfpGw==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/earcut": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/@types/earcut/-/earcut-2.1.4.tgz", @@ -3434,16 +3426,6 @@ "@types/node": "*" } }, - "node_modules/@types/kuromoji": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/@types/kuromoji/-/kuromoji-0.1.3.tgz", - "integrity": "sha512-u+YwX6eJj6Fmm0F5qunsyA+X8HSiyRNNE5ON3itD3tERax4meq9tv+S7bjTMXkPjqbdBGUmH2maGDCuEvpODwg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/doublearray": "*" - } - }, "node_modules/@types/linkify-it": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz", @@ -8153,7 +8135,6 @@ "version": "0.8.2", "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz", "integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==", - "dev": true, "license": "MIT" }, "node_modules/figures": { @@ -10180,13 +10161,13 @@ } }, "node_modules/kuromoji": { - "version": "0.1.2", - "resolved": "git+ssh://git@github.com/VOICEVOX/kuromoji.js.git#8ec8953543ea362a6b068ec48e0c81a919162ab1", + "version": "0.0.1", + "resolved": "git+ssh://git@github.com/VOICEVOX/kuromoji.js.git#b4952ad1f8be79f5acd2f297faca0602da338229", "license": "Apache-2.0", "dependencies": { "async": "^2.0.1", "doublearray": "0.0.2", - "zlibjs": "^0.3.1" + "fflate": "^0.8.2" } }, "node_modules/kuromoji/node_modules/async": { @@ -17538,15 +17519,6 @@ "node": "*" } }, - "node_modules/zlibjs": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/zlibjs/-/zlibjs-0.3.1.tgz", - "integrity": "sha512-+J9RrgTKOmlxFSDHo0pI1xM6BLVUv+o0ZT9ANtCxGkjIVCCUdx9alUF8Gm+dGLKbkkkidWIHFDZHDMpfITt4+w==", - "license": "MIT", - "engines": { - "node": "*" - } - }, "node_modules/zod": { "version": "3.22.4", "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz", diff --git a/package.json b/package.json index 89aa520a58..81e8cbb788 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "glob": "11.0.0", "hotkeys-js": "3.13.6", "immer": "9.0.21", - "kuromoji": "github:VOICEVOX/kuromoji.js#path.joinをなくす", + "kuromoji": "github:VOICEVOX/kuromoji.js#すべてを書き換えうr", "markdown-it": "13.0.2", "move-file": "3.0.0", "multistream": "4.1.0", @@ -94,7 +94,6 @@ "@types/async-lock": "1.4.0", "@types/encoding-japanese": "1.0.18", "@types/glob": "8.0.0", - "@types/kuromoji": "0.1.3", "@types/markdown-it": "12.2.0", "@types/multistream": "4.1.0", "@types/semver": "7.3.9", diff --git a/src/mock/engineMock/talkModelMock.ts b/src/mock/engineMock/talkModelMock.ts index 746a488dfe..bda0e55385 100644 --- a/src/mock/engineMock/talkModelMock.ts +++ b/src/mock/engineMock/talkModelMock.ts @@ -3,32 +3,27 @@ * 値は適当だが、テストで使えるよう決定論的に決まるようにしたり、UIのバグに気づけるようある程度規則を持たせている。 */ -import kuromoji, { IpadicFeatures, Tokenizer } from "kuromoji"; +import { builder, IpadicFeatures, Tokenizer } from "kuromoji"; import { moraToPhonemes } from "./phonemeMock"; import { moraPattern } from "@/domain/japanese"; import { AccentPhrase, Mora } from "@/openapi"; +/** Nodeとして動いてほしいかを判定する */ +const isNode = + // window.documentがなければNode + typeof window == "undefined" || + typeof window.document == "undefined" || + // happy-domのときはNode + typeof (window as { happyDOM?: unknown }).happyDOM != "undefined"; + let _tokenizer: Tokenizer | undefined; /** kuromoji用の辞書のパスを取得する */ function getDicPath() { // ブラウザのときはCDNから辞書を取得し、Nodeのときはローカルから取得する - const pathForBrowser = `https://cdn.jsdelivr.net/npm/kuromoji@0.1.2/dict`; const pathForNode = "node_modules/kuromoji/dict"; - - // window.documentがなければNode - if (typeof window == "undefined" || typeof window.document == "undefined") { - return pathForNode; - } - - // happy-domのときはNode - if (typeof (window as { happyDOM?: unknown }).happyDOM != "undefined") { - return pathForNode; - } - - // それ以外はブラウザ - return pathForBrowser; + return isNode ? pathForNode : pathForBrowser; } /** テキストをトークン列に変換するトークナイザーを取得する */ @@ -38,16 +33,17 @@ async function createOrGetTokenizer() { } return new Promise>((resolve, reject) => { - kuromoji - .builder({ dicPath: getDicPath() }) - .build((err: Error, tokenizer: Tokenizer) => { - if (err) { - reject(err); - } else { - _tokenizer = tokenizer; - resolve(tokenizer); - } - }); + builder({ + dicPath: getDicPath(), + nodeOrBrowser: isNode ? "node" : "browser", + }).build((err: Error, tokenizer: Tokenizer) => { + if (err) { + reject(err); + } else { + _tokenizer = tokenizer; + resolve(tokenizer); + } + }); }); }