Skip to content

Instantly share code, notes, and snippets.

@forivall
Created October 9, 2021 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forivall/f090fef9b99e1419d880185e09d8f60b to your computer and use it in GitHub Desktop.
Save forivall/f090fef9b99e1419d880185e09d8f60b to your computer and use it in GitHub Desktop.
typescript template for yarn-exec plugin generator scripts
// the .js version must be checked in, as it is needed before anything is installed.
// this file can _not_ use any non-core modules or access any external files.
export {};
// https://github.com/yarnpkg/berry/blob/master/packages/yarnpkg-fslib/sources/path.ts#L10
type NativePath = string & { __pathType?: 0 | 2 };
// https://github.com/yarnpkg/berry/blob/master/packages/plugin-exec/sources/ExecFetcher.ts#L9
/**
* Contains various useful details about the execution context.
*/
interface ExecEnv {
/**
* The absolute path of the empty temporary directory. It is created before the script is invoked.
*/
tempDir: NativePath;
/**
* The absolute path of the empty build directory that will be compressed into an archive and stored within the cache. It is created before the script is invoked.
*/
buildDir: NativePath;
/**
* The stringified Locator identifying the generator package.
*/
locator: string;
}
/** Runtime environment */
declare const execEnv: ExecEnv;
// Node builtin modules are available in the global scope
// https://github.com/yarnpkg/berry/tree/master/packages/plugin-exec#generator-scripts--require
declare const child_process: typeof import('child_process'); // eslint-disable-line @typescript-eslint/naming-convention
declare const fs: typeof import('fs');
declare const path: typeof import('path');
// less used core modules
declare const assert: typeof import('assert');
declare const async_hooks: typeof import('async_hooks'); // eslint-disable-line @typescript-eslint/naming-convention
declare const buffer: typeof import('buffer');
declare const cluster: typeof import('cluster');
declare const console: typeof import('console');
declare const crypto: typeof import('crypto');
declare const dgram: typeof import('dgram');
declare const dns: typeof import('dns');
declare const domain: typeof import('domain');
declare const events: typeof import('events');
declare const http: typeof import('http');
declare const http2: typeof import('http2');
declare const https: typeof import('https');
declare const inspector: typeof import('inspector');
declare const module: typeof import('module');
declare const net: typeof import('net');
declare const os: typeof import('os');
declare const perf_hooks: typeof import('perf_hooks');
declare const process: typeof import('process');
declare const querystring: typeof import('querystring');
declare const readline: typeof import('readline');
declare const repl: typeof import('repl');
declare const stream: typeof import('stream');
declare const string_decoder: typeof import('string_decoder'); // eslint-disable-line @typescript-eslint/naming-convention
declare const timers: typeof import('timers');
declare const tls: typeof import('tls');
declare const trace_events: typeof import('trace_events'); // eslint-disable-line @typescript-eslint/naming-convention
declare const tty: typeof import('tty');
declare const url: typeof import('url');
declare const util: typeof import('util');
declare const v8: typeof import('v8');
declare const vm: typeof import('vm');
declare const wasi: typeof import('wasi');
declare const worker_threads: typeof import('worker_threads'); // eslint-disable-line @typescript-eslint/naming-convention
declare const zlib: typeof import('zlib');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment