@chialab/esbuild-plugin-html
Advanced tools
Comparing version 0.10.0 to 0.11.0
@@ -0,1 +1,5 @@ | ||
import path from 'path'; | ||
import { readFile, writeFile, mkdir } from 'fs/promises'; | ||
import crypto from 'crypto'; | ||
/** | ||
@@ -9,3 +13,3 @@ * @typedef {Object} Entrypoint | ||
/** | ||
* @typedef {{ scriptsTarget?: string, modulesTarget?: string, addBundleMetafile?: (meta: import('esbuild').Metafile) => number|void }} PluginOptions | ||
* @typedef {{ scriptsTarget?: string, modulesTarget?: string }} PluginOptions | ||
*/ | ||
@@ -19,3 +23,3 @@ | ||
*/ | ||
export default function({ scriptsTarget = 'es2015', modulesTarget = 'es2020', addBundleMetafile = () => {} } = {}, esbuildModule) { | ||
export default function({ scriptsTarget = 'es2015', modulesTarget = 'es2020' } = {}, esbuildModule) { | ||
/** | ||
@@ -28,8 +32,34 @@ * @type {import('esbuild').Plugin} | ||
const options = build.initialOptions; | ||
const { stdin, sourceRoot } = options; | ||
const input = stdin ? stdin.sourcefile : undefined; | ||
const fullInput = input && path.resolve(sourceRoot || process.cwd(), input); | ||
/** | ||
* @type {import('esbuild').BuildResult[]} | ||
*/ | ||
let results = []; | ||
build.onStart(() => { | ||
results = []; | ||
}); | ||
build.onEnd((result) => { | ||
results.forEach((res) => { | ||
result.errors.push(...res.errors); | ||
result.warnings.push(...res.warnings); | ||
if (result.metafile && res.metafile) { | ||
result.metafile.inputs = { | ||
...result.metafile.inputs, | ||
...res.metafile.inputs, | ||
}; | ||
result.metafile.outputs = { | ||
...result.metafile.outputs, | ||
...res.metafile.outputs, | ||
}; | ||
} | ||
}); | ||
}); | ||
build.onLoad({ filter: /\.html$/ }, async ({ path: filePath }) => { | ||
const [ | ||
{ default: path }, | ||
{ default: crypto }, | ||
{ promises: { readFile, writeFile, mkdir } }, | ||
cheerio, | ||
@@ -43,5 +73,2 @@ { collectStyles }, | ||
] = await Promise.all([ | ||
import('path'), | ||
import('crypto'), | ||
import('fs'), | ||
import('cheerio'), | ||
@@ -61,3 +88,3 @@ import('./collectStyles.js'), | ||
const contents = await readFile(filePath, 'utf-8'); | ||
const contents = filePath === fullInput && stdin ? stdin.contents : await readFile(filePath, 'utf-8'); | ||
const basePath = path.dirname(filePath); | ||
@@ -82,4 +109,2 @@ const outdir = /** @type {string} */ (options.outdir || (options.outfile && path.dirname(options.outfile))); | ||
let outputFile; | ||
/** @type {import('esbuild').Metafile} */ | ||
let metafile; | ||
if (entrypoint.loader === 'file') { | ||
@@ -112,21 +137,25 @@ const files = /** @type {string[]|undefined}} */ (entrypoint.options.entryPoints); | ||
const bytes = Buffer.byteLength(buffer); | ||
metafile = { | ||
inputs: { | ||
[inputFile]: { | ||
bytes, | ||
imports: [], | ||
results.push({ | ||
errors: [], | ||
warnings: [], | ||
metafile: { | ||
inputs: { | ||
[inputFile]: { | ||
bytes, | ||
imports: [], | ||
}, | ||
}, | ||
}, | ||
outputs: { | ||
[outputFile]: { | ||
bytes, | ||
imports: [], | ||
entryPoint: inputFile, | ||
exports: [], | ||
inputs: { | ||
[inputFile]: { bytesInOutput: bytes }, | ||
outputs: { | ||
[outputFile]: { | ||
bytes, | ||
imports: [], | ||
entryPoint: inputFile, | ||
exports: [], | ||
inputs: { | ||
[inputFile]: { bytesInOutput: bytes }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
}); | ||
} else { | ||
@@ -154,5 +183,4 @@ /** @type {import('esbuild').BuildOptions} */ | ||
.find((output) => inputFiles.includes(path.resolve(/** @type {string} */(outputs[output].entryPoint)))) || outputFiles[0]; | ||
metafile = result.metafile; | ||
results.push(result); | ||
} | ||
addBundleMetafile(metafile); | ||
await entrypoint.finisher(outputFile, outputFiles); | ||
@@ -159,0 +187,0 @@ } |
{ | ||
"name": "@chialab/esbuild-plugin-html", | ||
"type": "module", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "A HTML loader plugin for esbuild.", | ||
@@ -45,5 +45,5 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"typescript": "^4.2.3" | ||
"typescript": "^4.3.0" | ||
}, | ||
"gitHead": "c77e08a61882aa710601732c035efd9fb7164bc3" | ||
"gitHead": "2113318a74e860b8962591325c65a58bdd1db16f" | ||
} |
@@ -8,3 +8,3 @@ /** | ||
/** | ||
* @typedef {{ scriptsTarget?: string, modulesTarget?: string, addBundleMetafile?: (meta: import('esbuild').Metafile) => number|void }} PluginOptions | ||
* @typedef {{ scriptsTarget?: string, modulesTarget?: string }} PluginOptions | ||
*/ | ||
@@ -17,3 +17,3 @@ /** | ||
*/ | ||
export default function _default({ scriptsTarget, modulesTarget, addBundleMetafile }?: PluginOptions, esbuildModule?: typeof import("esbuild") | undefined): import("esbuild").Plugin; | ||
export default function _default({ scriptsTarget, modulesTarget }?: PluginOptions, esbuildModule?: typeof import("esbuild") | undefined): import("esbuild").Plugin; | ||
export type Entrypoint = { | ||
@@ -34,5 +34,4 @@ /** | ||
export type PluginOptions = { | ||
scriptsTarget?: string | undefined; | ||
modulesTarget?: string | undefined; | ||
addBundleMetafile?: ((meta: import('esbuild').Metafile) => number | void) | undefined; | ||
scriptsTarget?: string; | ||
modulesTarget?: string; | ||
}; |
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
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
49671
1002
3