0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/frontend/asset-processor/rollup-plugins/discourse-file-search.js
David Taylor de793bc6ed
DEV: add typescript support for core, themes and plugins (#41478)
We've been using basic type-checking via JSDoc for some time. This
commit allows us to author proper `.ts`/`.gts` files, and use the full
typescript syntax. Initially, only d-button and a single chat file are
migrated, as proof of functionality.

In future, we may migrate more files, and consider making our tsconfig
more strict.
2026-07-08 12:57:18 +01:00

34 lines
985 B
JavaScript
Vendored

export default function discourseFileSearch() {
return {
name: "discourse-file-search",
async resolveId(source, context, options) {
if (source.match(/\.\w+$/)) {
// Already has an extension
return null;
}
for (const ext of ["", ".js", ".gjs", ".ts", ".gts", ".hbs"]) {
const resolved = await this.resolve(`${source}${ext}`, context, {
attributes: options.attributes,
});
if (resolved) {
return resolved;
}
}
// If lookup has no extension, and is not /index already, check for an /index file
if (!source.match(/\.\w+$/) && !source.endsWith("/index")) {
const resolved = await this.resolve(`${source}/index`, context, {
skipSelf: false, // We want extensionsearch on the `/index` lookup as well
attributes: options.attributes,
});
if (resolved) {
return resolved;
}
}
return null;
},
};
}