@chialab/esbuild-rna
Advanced tools
Comparing version 0.16.2 to 0.16.3
@@ -180,2 +180,14 @@ import path from 'path'; | ||
/** | ||
* The current plugin instance. | ||
* @type {Plugin} | ||
*/ | ||
plugin = { name: 'unknown', setup() {} }; | ||
/** | ||
* The current plugin name. | ||
* @type {string} | ||
*/ | ||
pluginName = ''; | ||
/** | ||
* Manager instance. | ||
@@ -424,4 +436,8 @@ * @type {import('./BuildManager.js').BuildManager} | ||
'.js': 'js', | ||
'.mjs': 'js', | ||
'.cjs': 'js', | ||
'.jsx': 'jsx', | ||
'.ts': 'ts', | ||
'.mts': 'ts', | ||
'.cts': 'ts', | ||
'.tsx': 'tsx', | ||
@@ -683,3 +699,11 @@ ...(this.getOption('loader') || {}), | ||
const maps = []; | ||
/** | ||
* @type {Message[]} | ||
*/ | ||
const warnings = []; | ||
/** | ||
* @type {Message[]} | ||
*/ | ||
const errors = []; | ||
@@ -696,23 +720,40 @@ for (const { options, callback } of this.onTransformRules) { | ||
const result = await callback({ | ||
...args, | ||
code: typeof code !== 'string' ? code.toString() : code, | ||
loader, | ||
}); | ||
if (result) { | ||
if (result.code) { | ||
code = result.code; | ||
try { | ||
const result = await callback({ | ||
...args, | ||
code: typeof code !== 'string' ? code.toString() : code, | ||
loader, | ||
}); | ||
if (result) { | ||
if (result.code) { | ||
code = result.code; | ||
} | ||
if (result.warnings) { | ||
warnings.push(...result.warnings); | ||
} | ||
if (result.errors) { | ||
errors.push(...result.errors); | ||
} | ||
if (result.map) { | ||
maps.push(result.map); | ||
} | ||
if (result.resolveDir) { | ||
resolveDir = result.resolveDir; | ||
} | ||
} | ||
if (result.warnings) { | ||
warnings.push(...result.warnings); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
const pluginName = this.pluginName; | ||
errors.push({ | ||
id: 'transform-error', | ||
pluginName, | ||
text: error.message, | ||
location: null, | ||
notes: [], | ||
detail: error, | ||
}); | ||
} else { | ||
throw error; | ||
} | ||
if (result.errors) { | ||
errors.push(...result.errors); | ||
} | ||
if (result.map) { | ||
maps.push(result.map); | ||
} | ||
if (result.resolveDir) { | ||
resolveDir = result.resolveDir; | ||
} | ||
break; | ||
} | ||
@@ -880,3 +921,2 @@ } | ||
* Insert dependency plugins in the build plugins list. | ||
* @param {Plugin} plugin The current plugin. | ||
* @param {Plugin[]} plugins A list of required plugins . | ||
@@ -886,3 +926,3 @@ * @param {'before'|'after'} [mode] Where insert the missing plugin. | ||
*/ | ||
async setupPlugin(plugin, plugins, mode = 'before') { | ||
async setupPlugin(plugins, mode = 'before') { | ||
if (this.isChunk()) { | ||
@@ -900,3 +940,3 @@ return []; | ||
let last = plugin; | ||
let last = this.plugin; | ||
for (let i = 0; i < plugins.length; i++) { | ||
@@ -903,0 +943,0 @@ const dependency = plugins[i]; |
@@ -12,6 +12,11 @@ import { BuildManager } from './BuildManager.js'; | ||
/** | ||
* @typedef {import('./Build').Build & { pluginName: string }} PluginBuild | ||
*/ | ||
/** | ||
* Enrich the esbuild build with a transformation pipeline and emit methods. | ||
* @param {import('esbuild').Plugin} pluginInstance The esbuild plugin instance. | ||
* @param {import('esbuild').PluginBuild} pluginBuild The esbuild build. | ||
*/ | ||
export function useRna(pluginBuild) { | ||
export function useRna(pluginInstance, pluginBuild) { | ||
const build = manager.getBuild(pluginBuild); | ||
@@ -30,3 +35,7 @@ const stdin = build.getOption('stdin'); | ||
} | ||
return build; | ||
const extendedBuild = /** @type {import('./Build.js').Build} */ (Object.create(build)); | ||
extendedBuild.plugin = pluginInstance; | ||
extendedBuild.pluginName = pluginInstance.name; | ||
return extendedBuild; | ||
} | ||
@@ -38,8 +47,13 @@ | ||
export function rnaPlugin() { | ||
return { | ||
/** | ||
* @type {import('esbuild').Plugin} | ||
*/ | ||
const plugin = { | ||
name: 'rna', | ||
setup(build) { | ||
useRna(build); | ||
useRna(plugin, build); | ||
}, | ||
}; | ||
return plugin; | ||
} |
{ | ||
"name": "@chialab/esbuild-rna", | ||
"type": "module", | ||
"version": "0.16.2", | ||
"version": "0.16.3", | ||
"description": "A framework for esbuild plugins with transform and emit capabilities.", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
@@ -146,2 +146,12 @@ /// <reference types="node" /> | ||
/** | ||
* The current plugin instance. | ||
* @type {Plugin} | ||
*/ | ||
plugin: Plugin; | ||
/** | ||
* The current plugin name. | ||
* @type {string} | ||
*/ | ||
pluginName: string; | ||
/** | ||
* Manager instance. | ||
@@ -442,3 +452,2 @@ * @type {import('./BuildManager.js').BuildManager} | ||
* Insert dependency plugins in the build plugins list. | ||
* @param {Plugin} plugin The current plugin. | ||
* @param {Plugin[]} plugins A list of required plugins . | ||
@@ -448,3 +457,3 @@ * @param {'before'|'after'} [mode] Where insert the missing plugin. | ||
*/ | ||
setupPlugin(plugin: Plugin, plugins: Plugin[], mode?: "before" | "after" | undefined): Promise<string[]>; | ||
setupPlugin(plugins: Plugin[], mode?: "before" | "after" | undefined): Promise<string[]>; | ||
/** | ||
@@ -451,0 +460,0 @@ * Add dependencies to the build. |
/** | ||
* @typedef {import('./Build').Build & { pluginName: string }} PluginBuild | ||
*/ | ||
/** | ||
* Enrich the esbuild build with a transformation pipeline and emit methods. | ||
* @param {import('esbuild').Plugin} pluginInstance The esbuild plugin instance. | ||
* @param {import('esbuild').PluginBuild} pluginBuild The esbuild build. | ||
*/ | ||
export function useRna(pluginBuild: import('esbuild').PluginBuild): import("./Build.js").Build; | ||
export function useRna(pluginInstance: import('esbuild').Plugin, pluginBuild: import('esbuild').PluginBuild): import("./Build.js").Build; | ||
/** | ||
@@ -12,1 +16,4 @@ * @returns {import('esbuild').Plugin} | ||
export * from "./helpers.js"; | ||
export type PluginBuild = import('./Build').Build & { | ||
pluginName: 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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
67460
1885
0