Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix extension resolving for esbuild #1827

Merged
merged 1 commit into from
Mar 5, 2024
Merged
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
35 changes: 35 additions & 0 deletions packages/vite/src/esbuild-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import { resolve, join } from 'path';
import { hbsToJS } from '@embroider/core';
import { Preprocessor } from 'content-tag';

function* candidates(path: string) {
yield path;
yield path + '.hbs';
yield path + '.gjs';
yield path + '.gts';
}

export function esBuildResolver(root = process.cwd()): EsBuildPlugin {
let resolverLoader = new ResolverLoader(process.cwd());
let macrosConfig: PluginItem | undefined;
Expand All @@ -16,6 +23,34 @@ export function esBuildResolver(root = process.cwd()): EsBuildPlugin {
return {
name: 'embroider-esbuild-resolver',
setup(build) {
// This resolver plugin is designed to test candidates for extensions and interoperates with our other embroider specific plugin
build.onResolve({ filter: /./ }, async ({ path, importer, namespace, resolveDir, pluginData, kind }) => {
if (pluginData?.embroiderExtensionSearch) {
return null;
}

let firstFailure;

for (let candidate of candidates(path)) {
let result = await build.resolve(candidate, {
namespace,
resolveDir,
importer,
kind,
pluginData: { ...pluginData, embroiderExtensionSearch: true },
});

if (result.errors.length === 0) {
return result;
}

if (!firstFailure) {
firstFailure = result;
}
}

return firstFailure;
});
build.onResolve({ filter: /./ }, async ({ path, importer, pluginData, kind }) => {
let request = EsBuildModuleRequest.from(build, kind, path, importer, pluginData);
if (!request) {
Expand Down
Loading