From 0a8701eb09c62506d86b82f4fbee3078fa7f6837 Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Sun, 12 Feb 2023 03:38:18 -0500 Subject: [PATCH] chore(loader): [`load`] fix esbuild loader configuration - https://esbuild.github.io/api/#loader Signed-off-by: Lexus Drumgold --- README.md | 7 ++++--- loader.mjs | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c0b3782f..ab3163f4 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,9 @@ too :wink:): */ import * as mlly from '@flex-development/mlly' -import pathe from '@flex-development/pathe' +import * as pathe from '@flex-development/pathe' import * as tscu from '@flex-development/tsconfig-utils' +import * as tutils from '@flex-development/tutils' import * as esbuild from 'esbuild' import { fileURLToPath, pathToFileURL } from 'node:url' @@ -135,7 +136,7 @@ export const load = async (url, context) => { /** * File extension of {@linkcode url}. * - * @type {string} + * @type {pathe.Ext | tutils.EmptyString} * @const ext */ const ext = pathe.extname(url) @@ -167,7 +168,7 @@ export const load = async (url, context) => { // transpile source code const { code } = await esbuild.transform(source, { format: ext === '.cts' ? 'cjs' : 'esm', - loader: /^[cm]/.test(ext) ? 'ts' : ext.slice(1), + loader: ext.slice(/^\.[cm]/.test(ext) ? 2 : 1), minify: false, sourcefile: fileURLToPath(url), sourcemap: 'inline', diff --git a/loader.mjs b/loader.mjs index 7a67d21e..77a59d1f 100644 --- a/loader.mjs +++ b/loader.mjs @@ -5,8 +5,9 @@ */ import * as mlly from '@flex-development/mlly' -import pathe from '@flex-development/pathe' +import * as pathe from '@flex-development/pathe' import * as tscu from '@flex-development/tsconfig-utils' +import * as tutils from '@flex-development/tutils' import * as esbuild from 'esbuild' import { fileURLToPath, pathToFileURL } from 'node:url' @@ -53,7 +54,7 @@ export const load = async (url, context) => { /** * File extension of {@linkcode url}. * - * @type {string} + * @type {pathe.Ext | tutils.EmptyString} * @const ext */ const ext = pathe.extname(url) @@ -85,7 +86,7 @@ export const load = async (url, context) => { // transpile source code const { code } = await esbuild.transform(source, { format: ext === '.cts' ? 'cjs' : 'esm', - loader: /^[cm]/.test(ext) ? 'ts' : ext.slice(1), + loader: ext.slice(/^\.[cm]/.test(ext) ? 2 : 1), minify: false, sourcefile: fileURLToPath(url), sourcemap: 'inline',