Skip to content

Commit 870c7f0

Browse files
committed
👍 Support Deno cache issue detection on Deno 1.38
See #358 (comment) for detail
1 parent 2312c62 commit 870c7f0

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

denops/@denops-private/service.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,7 @@ class Plugin {
151151
} catch (e) {
152152
// Show a warning message when Deno module cache issue is detected
153153
// https://github.com/vim-denops/denops.vim/issues/358
154-
if (
155-
e instanceof TypeError &&
156-
e.message.startsWith(
157-
"Could not find constraint in the list of versions: ",
158-
)
159-
) {
154+
if (isDenoCacheIssueError(e)) {
160155
console.warn("*".repeat(80));
161156
console.warn(`Deno module cache issue is detected.`);
162157
console.warn(
@@ -200,6 +195,18 @@ function resolveScriptUrl(script: string): string {
200195
}
201196
}
202197

198+
// See https://github.com/vim-denops/denops.vim/issues/358 for details
199+
function isDenoCacheIssueError(e: unknown): boolean {
200+
const expects = [
201+
"Could not find constraint in the list of versions: ", // Deno 1.40?
202+
"Could not find version of ", // Deno 1.38
203+
] as const;
204+
if (e instanceof TypeError) {
205+
return expects.some((expect) => e.message.startsWith(expect));
206+
}
207+
return false;
208+
}
209+
203210
// NOTE:
204211
// Vim/Neovim does not handle JavaScript Error instance thus use string instead
205212
function toVimError(err: unknown): string {

denops/@denops-private/service_test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const scriptInvalid =
2222
const scriptInvalidConstraint =
2323
new URL("./testdata/dummy_invalid_constraint_plugin.ts", import.meta.url)
2424
.href;
25+
const scriptInvalidConstraint2 =
26+
new URL("./testdata/dummy_invalid_constraint_plugin2.ts", import.meta.url)
27+
.href;
2528

2629
Deno.test("Service", async (t) => {
2730
const meta: Meta = {
@@ -189,6 +192,48 @@ Deno.test("Service", async (t) => {
189192
},
190193
);
191194

195+
await t.step(
196+
"load() loads plugin and emits autocmd events (could not find version)",
197+
async () => {
198+
const c = stub(console, "warn");
199+
const s = stub(host, "call");
200+
try {
201+
await service.load("dummyFailConstraint2", scriptInvalidConstraint2);
202+
const expects = [
203+
"********************************************************************************",
204+
"Deno module cache issue is detected.",
205+
"Execute 'call denops#cache#update(#{reload: v:true})' and restart Vim/Neovim.",
206+
"See https://github.com/vim-denops/denops.vim/issues/358 for more detail.",
207+
"********************************************************************************",
208+
];
209+
assertSpyCalls(c, expects.length);
210+
for (let i = 0; i < expects.length; i++) {
211+
assertSpyCall(c, i, {
212+
args: [expects[i]],
213+
});
214+
}
215+
assertSpyCalls(s, 2);
216+
assertSpyCall(s, 0, {
217+
args: [
218+
"denops#api#cmd",
219+
"doautocmd <nomodeline> User DenopsSystemPluginPre:dummyFailConstraint2",
220+
{},
221+
],
222+
});
223+
assertSpyCall(s, 1, {
224+
args: [
225+
"denops#api#cmd",
226+
"doautocmd <nomodeline> User DenopsSystemPluginFail:dummyFailConstraint2",
227+
{},
228+
],
229+
});
230+
} finally {
231+
s.restore();
232+
c.restore();
233+
}
234+
},
235+
);
236+
192237
await t.step(
193238
"load() does nothing when the plugin is already loaded",
194239
async () => {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { Entrypoint } from "https://deno.land/x/denops_core@v6.1.0/mod.ts";
2+
3+
export const main: Entrypoint = (_denops) => {
4+
// Mimic the situation
5+
throw new TypeError(
6+
"Could not find version of '@std/path' that matches specified version constraint '0.225.2'",
7+
);
8+
};

0 commit comments

Comments
 (0)