Skip to content

Commit

Permalink
Dynamically import jiti
Browse files Browse the repository at this point in the history
  - Dynamically import `jiti` to avoid unnecessary initialization for non TS config files
  • Loading branch information
aryaemami59 committed Mar 12, 2024
1 parent c6174ba commit 8a40708
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/size-limit/get-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import bytes from 'bytes-iec'
import { globby } from 'globby'
import buildJiti from 'jiti'
import { lilconfig } from 'lilconfig'
import { createRequire } from 'node:module'
import { dirname, isAbsolute, join, relative } from 'node:path'
Expand All @@ -10,8 +9,6 @@ import { SizeLimitError } from './size-limit-error.js'

const require = createRequire(import.meta.url)

const jiti = buildJiti(fileURLToPath(import.meta.url), { interopDefault: true })

let OPTIONS = {
brotli: 'file',
compareWith: 'webpack',
Expand Down Expand Up @@ -103,9 +100,14 @@ const dynamicImport = async filePath => (await import(filePath)).default
* without pre-compilation.
*
* @param {string} filePath - The path to the TypeScript file to be loaded.
* @returns {any} The module exports from the loaded TypeScript file.
* @returns {Promise<any>} The module exports from the loaded TypeScript file.
*/
const tsLoader = filePath => jiti(filePath)
const tsLoader = async filePath => {
const jiti = (await import('jiti')).default(fileURLToPath(import.meta.url), {
interopDefault: true
})
return jiti(filePath)
}

export default async function getConfig(plugins, process, args, pkg) {
let config = {
Expand Down

0 comments on commit 8a40708

Please sign in to comment.