Skip to content

Commit 3f62476

Browse files
committed
👍 Add workaround for Deno cache issue
See #358 for more detail.
1 parent 963be00 commit 3f62476

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

denops/@denops-private/service.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,24 @@ class Plugin {
149149
await mod.main(this.#denops);
150150
await emit(this.#denops, `DenopsSystemPluginPost:${this.name}`);
151151
} catch (e) {
152+
// Show a warning message when Deno module cache issue is detected
153+
// 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+
) {
160+
console.warn("*".repeat(80));
161+
console.warn(`Deno module cache issue is detected.`);
162+
console.warn(
163+
`Execute 'call denops#cache#update(#{reload: v:true})' and restart Vim/Neovim.`,
164+
);
165+
console.warn(
166+
`See https://github.com/vim-denops/denops.vim/issues/358 for more detail.`,
167+
);
168+
console.warn("*".repeat(80));
169+
}
152170
console.error(`Failed to load plugin '${this.name}': ${e}`);
153171
await emit(this.#denops, `DenopsSystemPluginFail:${this.name}`);
154172
}

denops/@denops-private/service_test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const scriptValid =
1919
new URL("./testdata/dummy_valid_plugin.ts", import.meta.url).href;
2020
const scriptInvalid =
2121
new URL("./testdata/dummy_invalid_plugin.ts", import.meta.url).href;
22+
const scriptInvalidConstraint =
23+
new URL("./testdata/dummy_invalid_constraint_plugin.ts", import.meta.url)
24+
.href;
2225

2326
Deno.test("Service", async (t) => {
2427
const meta: Meta = {
@@ -144,6 +147,48 @@ Deno.test("Service", async (t) => {
144147
},
145148
);
146149

150+
await t.step(
151+
"load() loads plugin and emits autocmd events (could not find constraint)",
152+
async () => {
153+
const c = stub(console, "warn");
154+
const s = stub(host, "call");
155+
try {
156+
await service.load("dummyFailConstraint", scriptInvalidConstraint);
157+
const expects = [
158+
"********************************************************************************",
159+
"Deno module cache issue is detected.",
160+
"Execute 'call denops#cache#update(#{reload: v:true})' and restart Vim/Neovim.",
161+
"See https://github.com/vim-denops/denops.vim/issues/358 for more detail.",
162+
"********************************************************************************",
163+
];
164+
assertSpyCalls(c, expects.length);
165+
for (let i = 0; i < expects.length; i++) {
166+
assertSpyCall(c, i, {
167+
args: [expects[i]],
168+
});
169+
}
170+
assertSpyCalls(s, 2);
171+
assertSpyCall(s, 0, {
172+
args: [
173+
"denops#api#cmd",
174+
"doautocmd <nomodeline> User DenopsSystemPluginPre:dummyFailConstraint",
175+
{},
176+
],
177+
});
178+
assertSpyCall(s, 1, {
179+
args: [
180+
"denops#api#cmd",
181+
"doautocmd <nomodeline> User DenopsSystemPluginFail:dummyFailConstraint",
182+
{},
183+
],
184+
});
185+
} finally {
186+
s.restore();
187+
c.restore();
188+
}
189+
},
190+
);
191+
147192
await t.step(
148193
"load() does nothing when the plugin is already loaded",
149194
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 constraint in the list of versions: @std/encoding@0.224.3",
7+
);
8+
};

0 commit comments

Comments
 (0)