@plugjs/plug
Version:
PlugJS Build System ===================
67 lines (66 loc) • 2.68 kB
TypeScript
import { Files } from './files';
import { Context } from './pipe';
import type { AbsolutePath } from './paths';
import type { Plug, PlugName, PlugResult } from './pipe';
/**
* Options accepted by {@link ForkingPlug}'s instrumenting how the process
* will be spawned (environment variables to be passed to the child process).
*/
export interface ForkOptions {
/** The directory where coverage data will be saved */
coverageDir?: string;
/** Force the specified module type when dynamically transpiling TypeScript */
forceModule?: 'commonjs' | 'module';
}
/** Fork data, from parent to child process */
export interface ForkData {
/** Script name for the Plug to execute */
scriptFile: AbsolutePath;
/** Export name in the script for the Plug to execute */
exportName: string;
/** Plug constructor arguments */
constructorArgs: any[];
/** Task name (for logs) */
taskName: string;
/** Build file name */
buildFile: AbsolutePath;
/** Files directory */
filesDir: AbsolutePath;
/** All files to pipe */
filesList: AbsolutePath[];
logIndent: number;
}
/** Fork result, from child to parent process */
export interface ForkResult {
/** If this is `true` we _might_ have `filesDir` and `filesList` */
failed: boolean;
/** Files directory of the result */
filesDir?: AbsolutePath | undefined;
/** All files returned by the plug */
filesList?: AbsolutePath[] | undefined;
}
export declare abstract class ForkingPlug implements Plug<PlugResult> {
private readonly _scriptFile;
private readonly _arguments;
private readonly _exportName;
constructor(_scriptFile: AbsolutePath, _arguments: any[], _exportName: string);
pipe(files: Files, context: Context): Promise<PlugResult>;
}
/**
* Install a _forking_ {@link Plug} in the {@link Pipe}, in other words
* execute the plug in a separate process.
*
* As a contract, if the _last non-null_ parameter of the constructor is an
* object and contains the key `coverageDir`, the process will be forked with
* the approptiately resolved `NODE_V8_COVERAGE` environment variable.
*
* Also, forking plugs require some special attention:
*
* * plug functions are not supported, only classes implementing the
* {@link Plug} interface can be used with this.
*
* * the class itself _MUST_ be exported as the _default_ export for the
* `scriptFile` specified below. This is to simplify interoperability between
* CommonJS and ESM modules as we use dynamic `import(...)` statements.
*/
export declare function installForking<Name extends PlugName>(plugName: Name, scriptFile: AbsolutePath, exportName?: string): void;