Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions denops/dpp/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const main: Entrypoint = (denops: Denops) => {

const [context, options] = await contextBuilder.get(denops);

return await extAction(
return extAction(
denops,
loader,
context,
Expand Down Expand Up @@ -154,7 +154,7 @@ export const main: Entrypoint = (denops: Denops) => {
const extName = ensure(arg1, is.String);
const [_, options] = await contextBuilder.get(denops);

return await dpp.getExt(
return dpp.getExt(
denops,
options,
extName,
Expand All @@ -163,7 +163,7 @@ export const main: Entrypoint = (denops: Denops) => {
async getProtocols(): Promise<Record<ProtocolName, Protocol>> {
const [_, options] = await contextBuilder.get(denops);

return await dpp.getProtocols(
return dpp.getProtocols(
denops,
options,
);
Expand Down
16 changes: 8 additions & 8 deletions denops/dpp/dpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ export class DppImpl implements Dpp {
this.#loader = loader;
}

async extAction(
extAction(
denops: Denops,
context: Context,
options: DppOptions,
extName: ExtName,
actionName: ActionName,
actionParams: BaseParams = {},
): Promise<unknown | undefined> {
return await extAction(
return extAction(
denops,
this.#loader,
context,
Expand All @@ -62,7 +62,7 @@ export class DppImpl implements Dpp {
);
}

async getExt(
getExt(
denops: Denops,
options: DppOptions,
extName: ExtName,
Expand All @@ -73,19 +73,19 @@ export class DppImpl implements Dpp {
BaseParams,
]
> {
return await getExt(
return getExt(
denops,
this.#loader,
options,
extName,
);
}

async getProtocols(
getProtocols(
denops: Denops,
options: DppOptions,
): Promise<Record<ProtocolName, Protocol>> {
return await getProtocols(denops, this.#loader, options);
return getProtocols(denops, this.#loader, options);
}

async makeState(
Expand All @@ -103,7 +103,7 @@ export class DppImpl implements Dpp {
let multipleHooks = configReturn.multipleHooks ?? [];

// Check plugin-option-if is enabled
const checkIf = async (plugin: Plugin) => {
const checkIf = (plugin: Plugin) => {
if (!("if" in plugin)) {
return true;
}
Expand All @@ -113,7 +113,7 @@ export class DppImpl implements Dpp {
}

// Eval plugin-option-if string.
return await denops.call("eval", plugin.if) as boolean;
return denops.call("eval", plugin.if) as Promise<boolean>;
};

// Initialize plugins
Expand Down
20 changes: 18 additions & 2 deletions denops/dpp/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@
}
}

const importMapCache = new Map<string, ImportMap | null>();
const importerCache = new Map<string, ImportMapImporter>();

export async function tryLoadImportMap(
script: string,
): Promise<ImportMap | undefined> {
Expand All @@ -255,10 +258,17 @@
? fromFileUrl(new URL(script))
: script;
const parentDir = dirname(scriptPath);

if (importMapCache.has(parentDir)) {
return importMapCache.get(parentDir) ?? undefined;
}

for (const pattern of PATTERNS) {
const importMapPath = join(parentDir, pattern);
try {
return await loadImportMap(importMapPath);
const importMap = await loadImportMap(importMapPath);
importMapCache.set(parentDir, importMap);
return importMap;
} catch (err: unknown) {
if (err instanceof Deno.errors.NotFound) {
// Ignore NotFound errors and try the next pattern
Expand All @@ -267,6 +277,7 @@
throw err; // Rethrow other errors
}
}
importMapCache.set(parentDir, null);
return undefined;
}

Expand All @@ -277,10 +288,15 @@
const url = toFileUrl(path).href;
const importMap = await tryLoadImportMap(path);
if (importMap) {
const importer = new ImportMapImporter(importMap);
const parentDir = dirname(path);
let importer = importerCache.get(parentDir);
if (!importer) {
importer = new ImportMapImporter(importMap);
importerCache.set(parentDir, importer);
}
return await importer.import(`${url}#${suffix}`);
} else {
return await import(`${url}#${suffix}`);

Check warning on line 299 in denops/dpp/utils.ts

View workflow job for this annotation

GitHub Actions / deno-test-publish

unable to analyze dynamic import
}
}

Expand Down
Loading