import type { DiagnosticOptions, Transformer as TransformerOpts, Resolver as ResolverOpts, Namer as NamerOpts, Optimizer as OptimizerOpts, Reporter as ReporterOpts, } from './types'; export * from './types'; // Parcel finds a plugin's methods under a key for the kind of plugin it is configured as, which // every copy of this package agrees on. A plugin of another kind, or one written for Parcel 2, // fails with a diagnostic rather than misbehaving. export class Transformer { constructor(opts: TransformerOpts) { // @ts-ignore this[Symbol.for('parcel.plugin.v3.transformer')] = opts; } } export class Resolver { constructor(opts: ResolverOpts) { // @ts-ignore this[Symbol.for('parcel.plugin.v3.resolver')] = opts; } } export class Namer { constructor(opts: NamerOpts) { // @ts-ignore this[Symbol.for('parcel.plugin.v3.namer')] = opts; } } export class Optimizer { constructor(opts: OptimizerOpts) { // @ts-ignore this[Symbol.for('parcel.plugin.v3.optimizer')] = opts; } } export class Reporter { constructor(opts: ReporterOpts) { // @ts-ignore this[Symbol.for('parcel.plugin.v3.reporter')] = opts; } } /** * An error carrying one or more diagnostics. Throw it from a plugin to fail with them, or pass * it to a `console` method to log them at that level. */ export class Diagnostic extends Error { readonly diagnostics: Array; constructor(diagnostic: DiagnosticOptions | Array) { let diagnostics = Array.isArray(diagnostic) ? diagnostic : [diagnostic]; super(diagnostics[0]?.message ?? ''); this.name = 'Diagnostic'; this.diagnostics = diagnostics; } } // Parcel reads the diagnostics from this symbol, which every copy of this package agrees on. Object.defineProperty(Diagnostic.prototype, Symbol.for('parcel-diagnostics'), { get(this: Diagnostic) { return this.diagnostics; }, });