UNPKG

vike

Version:

The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.

62 lines (61 loc) 1.93 kB
export { isScriptFile }; export { isPlainJavaScriptFile }; export { isTemplateFile }; export { scriptFileExtensions }; export { scriptFileExtensionList }; import { assert } from './assert.js'; // We can't use a RegExp: // - Needs to work with Micromatch: https://github.com/micromatch/micromatch because: // - Vite's `import.meta.glob()` uses Micromatch // - We need this to be a allowlist because: // - A pattern `*([a-zA-Z0-9]` doesn't work. // - Because of ReScript: `.res` are ReScript source files which need to be ignored. (The ReScript compiler generates `.js` files alongside `.res` files.) // - Block listing doesn't work. // - We cannot implement a blocklist with a glob pattern. // - A post `import.meta.glob()` blocklist filtering doesn't work because Vite would still process the files (e.g. including them in the bundle). // prettier-ignore // biome-ignore format: const extJavaScript = [ 'js', 'ts', 'cjs', 'cts', 'mjs', 'mts', ]; // prettier-ignore // biome-ignore format: const extJsx = [ 'jsx', 'tsx', 'cjsx', 'ctsx', 'mjsx', 'mtsx', ]; // prettier-ignore // biome-ignore format: const extTemplates = [ 'vue', 'svelte', 'marko', 'md', 'mdx' ]; const scriptFileExtensionList = [...extJavaScript, ...extJsx, ...extTemplates]; const scriptFileExtensions = '(' + scriptFileExtensionList.join('|') + ')'; function isScriptFile(filePath) { const yes = scriptFileExtensionList.some((ext) => filePath.endsWith('.' + ext)); if (isPlainJavaScriptFile(filePath)) assert(yes); return yes; } function isPlainJavaScriptFile(filePath) { const yes1 = /\.(c|m)?(j|t)s$/.test(filePath); const yes2 = extJavaScript.some((ext) => filePath.endsWith('.' + ext)); assert(yes1 === yes2); return yes1; } function isTemplateFile(filePath) { return extTemplates.some((ext) => filePath.endsWith('.' + ext)); }