( environment: PartialEnvironment, resolvers: CSSAtImportResolvers, maxWorkers: number | undefined, )
| 2773 | // #region Less |
| 2774 | // .less |
| 2775 | const makeLessWorker = ( |
| 2776 | environment: PartialEnvironment, |
| 2777 | resolvers: CSSAtImportResolvers, |
| 2778 | maxWorkers: number | undefined, |
| 2779 | ) => { |
| 2780 | const skipRebaseUrls = (unquotedUrl: string, _rawUrl: string) => { |
| 2781 | // matches both |
| 2782 | // - interpolation: `url('@{foo}')` |
| 2783 | // - variable: `url(@foo)` |
| 2784 | return unquotedUrl[0] === '@' |
| 2785 | } |
| 2786 | |
| 2787 | const viteLessResolve = async ( |
| 2788 | filename: string, |
| 2789 | dir: string, |
| 2790 | rootFile: string, |
| 2791 | mime: string | undefined, |
| 2792 | ) => { |
| 2793 | const resolved = await resolvers.less( |
| 2794 | environment, |
| 2795 | filename, |
| 2796 | // Less only exposes the importer's directory, not the file, so Vite can't |
| 2797 | // pass a real importer like CSS/Sass do. `resolve.tsconfigPaths` therefore |
| 2798 | // does not apply inside `.less` files. See the `resolve.tsconfigPaths` docs. |
| 2799 | path.join(dir, '*'), |
| 2800 | ) |
| 2801 | if (!resolved) return undefined |
| 2802 | |
| 2803 | // don't rebase URLs in JavaScript plugins |
| 2804 | if (mime === 'application/javascript') { |
| 2805 | const file = path.resolve(resolved) // ensure os-specific flashes |
| 2806 | return { resolved: file } |
| 2807 | } |
| 2808 | |
| 2809 | const result = await rebaseUrls( |
| 2810 | environment, |
| 2811 | resolved, |
| 2812 | rootFile, |
| 2813 | resolvers.less, |
| 2814 | skipRebaseUrls, |
| 2815 | ) |
| 2816 | return { |
| 2817 | resolved, |
| 2818 | contents: 'contents' in result ? result.contents : undefined, |
| 2819 | } |
| 2820 | } |
| 2821 | |
| 2822 | const worker = new WorkerWithFallback( |
| 2823 | async () => { |
| 2824 | const [fsp, path] = await Promise.all([ |
| 2825 | import('node:fs/promises'), |
| 2826 | import('node:path'), |
| 2827 | ]) |
| 2828 | |
| 2829 | let ViteLessManager: any |
| 2830 | const createViteLessPlugin = ( |
| 2831 | less: typeof Less, |
| 2832 | rootFile: string, |
no test coverage detected