@mingxy/ocosay 1.1.15 → 1.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/plugin.js +95 -0
- package/mingxy-ocosay-1.1.15.tgz +0 -0
- package/package.json +1 -1
package/dist/package.json
CHANGED
package/dist/plugin.js
CHANGED
|
@@ -10062,6 +10062,100 @@ async function ensureNaudiodonCompiled() {
|
|
|
10062
10062
|
}
|
|
10063
10063
|
}
|
|
10064
10064
|
}
|
|
10065
|
+
async function verifyModuleLoad(dep) {
|
|
10066
|
+
try {
|
|
10067
|
+
require2(dep);
|
|
10068
|
+
logger8.info(`${dep} loaded successfully`);
|
|
10069
|
+
return true;
|
|
10070
|
+
} catch (err) {
|
|
10071
|
+
logger8.warn({ err }, `${dep} load failed`);
|
|
10072
|
+
return false;
|
|
10073
|
+
}
|
|
10074
|
+
}
|
|
10075
|
+
async function fixOptionalDep(dep, depPath, maxRetries = 5) {
|
|
10076
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
10077
|
+
if (await verifyModuleLoad(dep)) {
|
|
10078
|
+
return true;
|
|
10079
|
+
}
|
|
10080
|
+
logger8.info({ attempt, dep }, "module not loadable, trying rebuild");
|
|
10081
|
+
notificationService.info(`\u6B63\u5728\u7F16\u8BD1 ${dep} (${attempt + 1}/${maxRetries})...`, "Ocosay", 3e3);
|
|
10082
|
+
try {
|
|
10083
|
+
execSync2("npm rebuild", {
|
|
10084
|
+
cwd: depPath,
|
|
10085
|
+
stdio: "inherit"
|
|
10086
|
+
});
|
|
10087
|
+
logger8.info(`${dep} rebuilt`);
|
|
10088
|
+
} catch (err) {
|
|
10089
|
+
logger8.warn({ err }, `${dep} rebuild failed`);
|
|
10090
|
+
}
|
|
10091
|
+
if (await verifyModuleLoad(dep)) {
|
|
10092
|
+
return true;
|
|
10093
|
+
}
|
|
10094
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
10095
|
+
}
|
|
10096
|
+
return await verifyModuleLoad(dep);
|
|
10097
|
+
}
|
|
10098
|
+
async function ensureOptionalDepsInstalled() {
|
|
10099
|
+
const optionalDeps = ["play-sound", "speaker"];
|
|
10100
|
+
const missingDeps = [];
|
|
10101
|
+
const basePath = dirname2(require2.resolve("./package.json"));
|
|
10102
|
+
for (const dep of optionalDeps) {
|
|
10103
|
+
if (await verifyModuleLoad(dep)) {
|
|
10104
|
+
continue;
|
|
10105
|
+
}
|
|
10106
|
+
missingDeps.push(dep);
|
|
10107
|
+
}
|
|
10108
|
+
if (missingDeps.length === 0) {
|
|
10109
|
+
return;
|
|
10110
|
+
}
|
|
10111
|
+
notificationService.info(
|
|
10112
|
+
`\u6B63\u5728\u5B89\u88C5\u53EF\u9009\u4F9D\u8D56: ${missingDeps.join(", ")}...`,
|
|
10113
|
+
"Ocosay \u97F3\u9891\u540E\u7AEF",
|
|
10114
|
+
5e3
|
|
10115
|
+
);
|
|
10116
|
+
try {
|
|
10117
|
+
const depsStr = missingDeps.join(" ");
|
|
10118
|
+
logger8.info({ deps: depsStr }, "installing optional dependencies");
|
|
10119
|
+
execSync2(`npm install ${depsStr}`, {
|
|
10120
|
+
cwd: basePath,
|
|
10121
|
+
stdio: "inherit"
|
|
10122
|
+
});
|
|
10123
|
+
logger8.info("optional dependencies installed");
|
|
10124
|
+
} catch (err) {
|
|
10125
|
+
logger8.warn({ err }, "optional dependencies install failed");
|
|
10126
|
+
notificationService.warning(
|
|
10127
|
+
"\u53EF\u9009\u4F9D\u8D56\u5B89\u88C5\u5931\u8D25",
|
|
10128
|
+
`\u8BF7\u624B\u52A8\u8FD0\u884C: npm install ${missingDeps.join(" ")}`,
|
|
10129
|
+
8e3
|
|
10130
|
+
);
|
|
10131
|
+
return;
|
|
10132
|
+
}
|
|
10133
|
+
let allLoaded = true;
|
|
10134
|
+
for (const dep of missingDeps) {
|
|
10135
|
+
const depPath = dirname2(require2.resolve(dep, { paths: [basePath] }));
|
|
10136
|
+
if (await verifyModuleLoad(dep)) {
|
|
10137
|
+
continue;
|
|
10138
|
+
}
|
|
10139
|
+
notificationService.warning(`${dep} \u52A0\u8F7D\u5931\u8D25\uFF0C\u6B63\u5728\u5C1D\u8BD5\u7F16\u8BD1...`, "Ocosay", 5e3);
|
|
10140
|
+
const fixed = await fixOptionalDep(dep, depPath);
|
|
10141
|
+
if (!fixed) {
|
|
10142
|
+
allLoaded = false;
|
|
10143
|
+
}
|
|
10144
|
+
}
|
|
10145
|
+
if (allLoaded) {
|
|
10146
|
+
notificationService.success(
|
|
10147
|
+
"\u53EF\u9009\u4F9D\u8D56\u5B89\u88C5\u6210\u529F",
|
|
10148
|
+
"play-sound & speaker \u5DF2\u5C31\u7EEA",
|
|
10149
|
+
5e3
|
|
10150
|
+
);
|
|
10151
|
+
} else {
|
|
10152
|
+
notificationService.warning(
|
|
10153
|
+
"\u90E8\u5206\u53EF\u9009\u4F9D\u8D56\u5B89\u88C5\u5931\u8D25",
|
|
10154
|
+
`\u8BF7\u624B\u52A8\u8FD0\u884C: npm install ${missingDeps.join(" ")} && npm rebuild`,
|
|
10155
|
+
8e3
|
|
10156
|
+
);
|
|
10157
|
+
}
|
|
10158
|
+
}
|
|
10065
10159
|
function execCmd2(cmd) {
|
|
10066
10160
|
try {
|
|
10067
10161
|
const output = execSync2(cmd, { stdio: "pipe", encoding: "utf8" });
|
|
@@ -10351,6 +10445,7 @@ var server = (async (input, _options) => {
|
|
|
10351
10445
|
logger8.error({ error: initError }, "initialization failed");
|
|
10352
10446
|
}
|
|
10353
10447
|
await ensureNaudiodonCompiled();
|
|
10448
|
+
await ensureOptionalDepsInstalled();
|
|
10354
10449
|
await checkAudioEnvironmentForBackend();
|
|
10355
10450
|
setTimeout(() => {
|
|
10356
10451
|
if (initError) {
|
|
Binary file
|