Skip to content

Commit

Permalink
types: glob types hardcoded
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyhuman committed Dec 2, 2023
1 parent 9c2b2d5 commit f344bfc
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@ import { defu } from "defu";
import glob from "tiny-glob";
import { EventEmitter } from "node:events";

export type GlobOptions = {
cwd?: string;
dot?: boolean;
absolute?: boolean;
filesOnly?: boolean;
flush?: boolean;
};

export type FilePath = string;

class ContextManager {
initialConfig: esbuild.BuildOptions = {};
contextConfigs: esbuild.BuildOptions[] = [];
contexts: esbuild.BuildContext[] = [];
queue = [];
#contextConfigs: esbuild.BuildOptions[] = [];
#contexts: esbuild.BuildContext[] = [];
#eventBus = new EventEmitter();

constructor(initial: esbuild.BuildOptions) {
this.initialConfig = initial;
}

config(conf: esbuild.BuildOptions) {
this.contextConfigs.push(defu(conf, this.initialConfig));
this.#contextConfigs.push(defu(conf, this.initialConfig));
}

glob(pattern: string, opts: any) {
glob(pattern: string, opts: GlobOptions): Promise<FilePath[]> {
return glob(pattern, opts);
}

Expand All @@ -35,7 +44,7 @@ class ContextManager {
const eBus = this.#eventBus;
let cfg;

while ((cfg = this.contextConfigs.shift())) {
while ((cfg = this.#contextConfigs.shift())) {
try {
cfg.plugins ||= [];

Expand All @@ -52,7 +61,7 @@ class ContextManager {

const context = await esbuild.context(defu(cfg, this.initialConfig));

this.contexts.push(context);
this.#contexts.push(context);
} catch (err) {
this.#eventBus.emit("error", err);
break;
Expand All @@ -62,14 +71,14 @@ class ContextManager {

async build() {
await this.#createContext();
this.contexts.forEach((x) => x.rebuild());
this.#contexts.forEach((x) => x.rebuild());

this.#eventBus.emit("build");
}

async watch() {
await this.#createContext();
await Promise.all(this.contexts.map((x) => x.watch()));
await Promise.all(this.#contexts.map((x) => x.watch()));
}
}

Expand Down

0 comments on commit f344bfc

Please sign in to comment.