import * as yaml from 'js-yaml'; import { LoadHookContext } from 'module'; import { Dict } from 'cosmokit'; import { Context, ForkScope, Inject, EffectScope } from '@cordisjs/core'; type ModuleFormat = 'builtin' | 'commonjs' | 'json' | 'module' | 'wasm'; type ModuleSource = string | ArrayBuffer; declare interface ResolveResult { format: ModuleFormat; url: string; } declare interface LoadResult { format: ModuleFormat; source?: ModuleSource; } type LoadCacheData = ModuleJob; declare interface LoadCache extends Omit>, 'get' | 'set' | 'has'> { get(url: string, type?: string): LoadCacheData | undefined; set(url: string, type?: string, job?: LoadCacheData): this; has(url: string, type?: string): boolean; } export interface ModuleWrap { url: string; getNamespace(): any; } export interface ModuleJob { url: string; loader: ModuleLoader; module?: ModuleWrap; importAttributes: ImportAttributes; linked: Promise; instantiate(): Promise; run(): Promise<{ module: ModuleWrap; }>; } export interface ModuleLoader { loadCache: LoadCache; import(specifier: string, parentURL: string, importAttributes: ImportAttributes): Promise; register(specifier: string | URL, parentURL?: string | URL, data?: any, transferList?: any[]): void; getModuleJob(specifier: string, parentURL: string, importAttributes: ImportAttributes): Promise; getModuleJobSync(specifier: string, parentURL: string, importAttributes: ImportAttributes): ModuleJob; resolve(originalSpecifier: string, parentURL: string, importAttributes: ImportAttributes): Promise; resolveSync(originalSpecifier: string, parentURL: string, importAttributes: ImportAttributes): ResolveResult; load(specifier: string, context: Pick): Promise; loadSync(specifier: string, context: Pick): LoadResult; } export abstract class EntryTree { ctx: C; static readonly sep = ":"; url: string; root: EntryGroup; store: Dict>; constructor(ctx: C); get context(): Context; entries(): Generator, void, void>; ensureId(options: Partial): string; resolve(id: string): Entry; resolveGroup(id: string | null): EntryGroup; create(options: Omit, parent?: string | null, position?: number): Promise; remove(id: string): void; update(id: string, options: Omit, parent?: string | null, position?: number): Promise; import(name: string): Promise; abstract write(): void; } export class EntryGroup { ctx: Context; tree: EntryTree; static readonly key: unique symbol; data: EntryOptions[]; constructor(ctx: Context, tree: EntryTree); create(options: Omit): Promise; unlink(options: EntryOptions): void; remove(id: string): void; update(config: EntryOptions[]): void; stop(): void; } export class Group extends EntryGroup { ctx: Context; static reusable: boolean; static initial: Omit[]; static readonly [EntryGroup.key] = true; constructor(ctx: Context); } export const evaluate: ((ctx: object, expr: string) => any); export function interpolate(ctx: object, value: any): any; export interface JsExpr { __jsExpr: string; } export const JsExpr: yaml.Type; export interface EntryOptions { id: string; name: string; config?: any; group?: boolean | null; disabled?: boolean | null; } export interface EntryUpdateMeta { } export class Entry { loader: Loader; static readonly key: unique symbol; ctx: C; fork?: ForkScope; suspend: boolean; parent: EntryGroup; options: EntryOptions; subgroup?: EntryGroup; subtree?: EntryTree; constructor(loader: Loader); get context(): Context; get id(): string; get disabled(): boolean; _check(): boolean; evaluate(expr: string): any; _resolveConfig(plugin: any): [any, any?]; patch(options?: Partial): void; refresh(): Promise; update(options: Partial, override?: boolean): Promise; start(): Promise; stop(): Promise; } export class ImportTree extends EntryTree { ctx: C; static reusable: boolean; file: LoaderFile; constructor(ctx: C); start(): Promise; refresh(): Promise; stop(): void; write(): void; init(baseDir: string, options: Loader.Config): Promise; private _init; } export namespace Import { interface Config { url: string; } } export class Import extends ImportTree { config: Import.Config; constructor(ctx: Context, config: Import.Config); start(): Promise; } export const schema: yaml.Schema; export class LoaderFile { name: string; type?: string | undefined; suspend: boolean; readonly: boolean; trees: ImportTree[]; writeTask?: NodeJS.Timeout; constructor(name: string, type?: string | undefined); ref(tree: ImportTree): void; unref(tree: ImportTree): void; checkAccess(): Promise; read(): Promise; private _write; write(config: EntryOptions[]): void; } export namespace LoaderFile { const writable: { '.json': string; '.yaml': string; '.yml': string; }; const supported: Set; } export interface EntryOptions { inject?: Inject | null; } export const name = "inject"; export function apply(ctx: Context): void; export interface EntryUpdateMeta { newMap: Dict; diff: [string, symbol, symbol, symbol, symbol][]; } export interface EntryOptions { intercept?: Dict | null; isolate?: Dict | null; } export interface Entry { realm: LocalRealm; } export abstract class Realm { protected store: Dict; abstract get suffix(): string; access(key: string, create?: boolean): symbol; delete(key: string): void; get size(): number; } export class LocalRealm extends Realm { private entry; constructor(entry: Entry); get suffix(): string; } export class GlobalRealm extends Realm { label: string; constructor(label: string); get suffix(): string; } export const name = "isolate"; export function apply(ctx: Context): void; declare module '@cordisjs/core' { interface Events { 'exit'(signal: NodeJS.Signals): Promise; 'loader/config-update'(): void; 'loader/entry-init'(entry: Entry): void; 'loader/entry-fork'(entry: Entry, type: string): void; 'loader/entry-check'(entry: Entry): boolean | undefined; 'loader/partial-dispose'(entry: Entry, legacy: Partial, active: boolean): void; 'loader/before-patch'(this: EntryUpdateMeta, entry: Entry): void; 'loader/after-patch'(this: EntryUpdateMeta, entry: Entry): void; } interface Context { baseDir: string; loader: Loader; } interface EnvData { startTime?: number; } interface EffectScope { entry?: Entry; } } export namespace Loader { interface Config { name: string; initial?: Omit[]; filename?: string; } } export abstract class Loader extends ImportTree { ctx: C; config: Loader.Config; static inject: { loader: { required: boolean; }; }; envData: any; params: { env: NodeJS.ProcessEnv; }; files: Dict; delims: Dict; internal?: ModuleLoader; constructor(ctx: C, config: Loader.Config); start(): Promise; locate(ctx?: C): string[]; _locate(scope: EffectScope): Entry[]; exit(): void; unwrapExports(exports: any): any; } declare namespace NodeLoader { interface Config extends Loader.Config { } } declare class NodeLoader extends Loader { static readonly exitCode = 51; init(baseDir: string, options: Loader.Config): Promise; start(): Promise; exit(code?: number): void; } export default NodeLoader;