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 hbs plugin not resolving .hbs due to broken Regex #2151

Merged
merged 1 commit into from
Oct 9, 2024
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
2 changes: 1 addition & 1 deletion packages/shared-internals/src/colocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function syntheticJStoHBS(source: string): string | null {
// only ever JS (never TS or anything else). And extensionless imports are
// handled by the default resolving system doing extension search.
if (cleanUrl(source).endsWith('.js')) {
return source.replace(/.js(\?.*)?/, '.hbs$1');
return source.replace(/\.js(\?.*)?$/, '.hbs$1');
}

return null;
Expand Down
25 changes: 25 additions & 0 deletions packages/shared-internals/tests/colocation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { syntheticJStoHBS } from '../src';

describe('colocation utils', function () {
describe('syntheticJStoHBS', function () {
test('it returns .hbs files for .js', function () {
const testCases = [
['foo.js', 'foo.hbs'],
['foo.js?qp', 'foo.hbs?qp'],
['foo/json.js', 'foo/json.hbs'],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the case that failed before:
image

];

for (const [from, to] of testCases) {
expect(syntheticJStoHBS(from)).toEqual(to);
}
});

test('it ignores non .js files', function () {
const testCases = ['foo.ts', 'foo.hbs', 'foo.js.xxx'];

for (const from of testCases) {
expect(syntheticJStoHBS(from)).toEqual(null);
}
});
});
});