@chialab/esbuild-plugin-meta-url
Advanced tools
Comparing version 0.17.3 to 0.17.4
import path from 'path'; | ||
import { readFile } from 'fs/promises'; | ||
import mime from 'mime-types'; | ||
@@ -198,4 +199,6 @@ import { appendSearchParam, getSearchParam, isUrl } from '@chialab/node-resolve'; | ||
const isChunk = entryLoader !== 'file' && entryLoader !== 'json'; | ||
const isIIFE = format === 'iife' && bundle; | ||
let entryPoint; | ||
if (emit) { | ||
if (emit && !isIIFE) { | ||
if (isChunk) { | ||
@@ -212,16 +215,34 @@ const chunk = await build.emitChunk({ path: resolvedPath }); | ||
if (format === 'iife' && bundle) { | ||
const { outputFiles } = await build.emitChunk({ | ||
path: `./${entryPoint}`, | ||
write: false, | ||
}); | ||
if (outputFiles) { | ||
const mimeType = mime.lookup(outputFiles[0].path); | ||
const base64 = Buffer.from(outputFiles[0].contents).toString('base64'); | ||
helpers.overwrite(startToken.start, endToken.end, `new URL('data:${mimeType};base64,${base64}')`); | ||
if (isIIFE) { | ||
let buffer, mimeType; | ||
if (isChunk) { | ||
const { outputFiles } = await build.emitChunk({ | ||
path: `./${entryPoint}`, | ||
write: false, | ||
}); | ||
if (outputFiles) { | ||
mimeType = mime.lookup(outputFiles[0].path); | ||
buffer = Buffer.from(outputFiles[0].contents); | ||
} | ||
} else { | ||
const result = await build.load({ | ||
pluginData: null, | ||
namespace: 'file', | ||
suffix: '', | ||
path: resolvedPath, | ||
}); | ||
if (result && result.contents) { | ||
mimeType = mime.lookup(resolvedPath); | ||
buffer = Buffer.from(result.contents); | ||
} | ||
} | ||
} else { | ||
helpers.overwrite(startToken.start, endToken.end, `new URL('./${entryPoint}', ${baseUrl})`); | ||
if (buffer) { | ||
helpers.overwrite(startToken.start, endToken.end, `new URL('data:${mimeType};base64,${buffer.toString('base64')}')`); | ||
return; | ||
} | ||
} | ||
helpers.overwrite(startToken.start, endToken.end, `new URL('./${entryPoint}', ${baseUrl})`); | ||
return; | ||
@@ -228,0 +249,0 @@ } |
{ | ||
"name": "@chialab/esbuild-plugin-meta-url", | ||
"type": "module", | ||
"version": "0.17.3", | ||
"version": "0.17.4", | ||
"description": "A file loader plugin for esbuild for constructed URLs using import metadata.", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15732
272
1