@chialab/esbuild-plugin-html
Advanced tools
Comparing version 0.9.12 to 0.10.0
@@ -1,6 +0,4 @@ | ||
import { promises } from 'fs'; | ||
import { mkdir } from 'fs/promises'; | ||
import path from 'path'; | ||
const { mkdir } = promises; | ||
const FAVICONS = [ | ||
@@ -7,0 +5,0 @@ { |
@@ -1,5 +0,15 @@ | ||
import { promises } from 'fs'; | ||
import { readFile, writeFile, mkdir } from 'fs/promises'; | ||
import path from 'path'; | ||
const { readFile, writeFile, mkdir } = promises; | ||
/** | ||
* @param {string} filePath | ||
*/ | ||
async function load(filePath, fallback = {}) { | ||
try { | ||
const contents = await readFile(filePath, 'utf-8'); | ||
return JSON.parse(contents); | ||
} catch { | ||
return fallback; | ||
} | ||
} | ||
@@ -21,11 +31,9 @@ /** | ||
const iconElement = dom.find('link[rel*="icon"]'); | ||
const element = dom | ||
.find('link[rel="manifest"]') | ||
.get() | ||
.filter((element) => $(element).attr('href'))[0]; | ||
if (!element) { | ||
const element = dom.find('link[rel="manifest"]'); | ||
const href = /** @type {string} */($(element).attr('href')); | ||
if (!href) { | ||
return []; | ||
} | ||
const entryPoint = path.resolve(base, /** @type {string} */($(element).attr('href'))); | ||
const entryPoint = path.resolve(base, href); | ||
return [ | ||
@@ -43,4 +51,3 @@ { | ||
async finisher(filePath) { | ||
const contents = await readFile(filePath, 'utf-8'); | ||
const json = JSON.parse(contents); | ||
const json = await load(filePath); | ||
json.name = json.name || titleElement.text() || undefined; | ||
@@ -47,0 +54,0 @@ json.short_name = json.short_name || json.name || titleElement.text() || undefined; |
@@ -9,3 +9,3 @@ /** | ||
/** | ||
* @typedef {{ scriptsTarget?: string, modulesTarget?: string }} PluginOptions | ||
* @typedef {{ scriptsTarget?: string, modulesTarget?: string, addBundleMetafile?: (meta: import('esbuild').Metafile) => number|void }} PluginOptions | ||
*/ | ||
@@ -19,3 +19,3 @@ | ||
*/ | ||
export default function({ scriptsTarget = 'es2015', modulesTarget = 'es2020' } = {}, esbuildModule) { | ||
export default function({ scriptsTarget = 'es2015', modulesTarget = 'es2020', addBundleMetafile = () => {} } = {}, esbuildModule) { | ||
/** | ||
@@ -79,2 +79,4 @@ * @type {import('esbuild').Plugin} | ||
let outputFile; | ||
/** @type {import('esbuild').Metafile} */ | ||
let metafile; | ||
if (entrypoint.loader === 'file') { | ||
@@ -104,2 +106,24 @@ const files = /** @type {string[]|undefined}} */ (entrypoint.options.entryPoints); | ||
outputFiles.push(outputFile); | ||
// manually build metafile data | ||
const inputFile = path.relative(process.cwd(), file); | ||
const bytes = Buffer.byteLength(buffer); | ||
metafile = { | ||
inputs: { | ||
[inputFile]: { | ||
bytes, | ||
imports: [], | ||
}, | ||
}, | ||
outputs: { | ||
[outputFile]: { | ||
bytes, | ||
imports: [], | ||
entryPoint: inputFile, | ||
exports: [], | ||
inputs: { | ||
[inputFile]: { bytesInOutput: bytes }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} else { | ||
@@ -127,3 +151,5 @@ /** @type {import('esbuild').BuildOptions} */ | ||
.find((output) => inputFiles.includes(path.resolve(/** @type {string} */(outputs[output].entryPoint)))) || outputFiles[0]; | ||
metafile = result.metafile; | ||
} | ||
addBundleMetafile(metafile); | ||
await entrypoint.finisher(outputFile, outputFiles); | ||
@@ -130,0 +156,0 @@ } |
{ | ||
"name": "@chialab/esbuild-plugin-html", | ||
"type": "module", | ||
"version": "0.9.12", | ||
"version": "0.10.0", | ||
"description": "A HTML loader plugin for esbuild.", | ||
@@ -47,3 +47,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "697e574c292bc00241e1218ab74a8510aba4e03e" | ||
"gitHead": "c77e08a61882aa710601732c035efd9fb7164bc3" | ||
} |
@@ -8,3 +8,3 @@ /** | ||
/** | ||
* @typedef {{ scriptsTarget?: string, modulesTarget?: string }} PluginOptions | ||
* @typedef {{ scriptsTarget?: string, modulesTarget?: string, addBundleMetafile?: (meta: import('esbuild').Metafile) => number|void }} PluginOptions | ||
*/ | ||
@@ -17,3 +17,3 @@ /** | ||
*/ | ||
export default function _default({ scriptsTarget, modulesTarget }?: PluginOptions, esbuildModule?: typeof import("esbuild") | undefined): import("esbuild").Plugin; | ||
export default function _default({ scriptsTarget, modulesTarget, addBundleMetafile }?: PluginOptions, esbuildModule?: typeof import("esbuild") | undefined): import("esbuild").Plugin; | ||
export type Entrypoint = { | ||
@@ -34,4 +34,5 @@ /** | ||
export type PluginOptions = { | ||
scriptsTarget?: string; | ||
modulesTarget?: string; | ||
scriptsTarget?: string | undefined; | ||
modulesTarget?: string | undefined; | ||
addBundleMetafile?: ((meta: import('esbuild').Metafile) => number | void) | undefined; | ||
}; |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
48905
979