Skip to content

Commit

Permalink
Working on #671
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Feb 5, 2024
1 parent b77d506 commit 3b5ce14
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/tooling/piral-cli/src/apps/debug-piral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ export async function debugPiral(baseDir = process.cwd(), options: DebugPiralOpt

await hooks.beforeBuild?.({ root, publicUrl, externals, entryFiles, piralInstances });

watcherContext.watch(join(root, packageJson));
watcherContext.watch(join(root, piralJson));

const bundler = await callPiralDebug(
{
root,
Expand All @@ -162,6 +159,10 @@ export async function debugPiral(baseDir = process.cwd(), options: DebugPiralOpt
bundlerName,
);

watcherContext.watch(join(root, packageJson));
watcherContext.watch(join(root, piralJson));
watcherContext.onClean(() => bundler.stop());

bundler.ready().then(() => logDone(`Ready!`));

bundler.on((args) => {
Expand Down
3 changes: 3 additions & 0 deletions src/tooling/piral-cli/src/build/bundler-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function createBundler(cwd: string, ps: ChildProcess, args: any) {
});
}
},
stop() {
ps.kill();
},
on(cb: BundleListener) {
listeners.push(cb);
},
Expand Down
13 changes: 5 additions & 8 deletions src/tooling/piral-cli/src/common/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface WatcherRef<T> {
}

export interface WatcherContext {
onClean(dispose: () => void): void;
onClean(dispose: () => void | Promise<void>): void;
watch(file: string): void;
dependOn<T>(ref: WatcherRef<T>): void;
close(): void;
Expand All @@ -19,7 +19,7 @@ export function watcherTask<T = void>(cb: (watcherContext: WatcherContext) => Pr
let pending = false;
let notify = () => {};

const disposers: Array<() => void> = [];
const disposers: Array<() => void | Promise<void>> = [];
const triggers: Array<() => void> = [];
const end = new Promise<void>(resolve => {
notify = resolve;
Expand All @@ -36,16 +36,13 @@ export function watcherTask<T = void>(cb: (watcherContext: WatcherContext) => Pr
if (!pending) {
pending = true;
await running;
disposers.splice(0, disposers.length).forEach((dispose) => {
dispose();
});
await Promise.all(disposers.splice(0, disposers.length).map((dispose) => dispose()));

pending = false;
context.status = 'reoccuring';
await run();

triggers.splice(0, triggers.length).forEach((trigger) => {
trigger();
});
triggers.splice(0, triggers.length).forEach((trigger) => trigger());
}
};

Expand Down
1 change: 1 addition & 0 deletions src/tooling/piral-cli/src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export interface BundleDetails {
export interface Bundler {
readonly bundle: BundleDetails;
start(): void;
stop(): void;
on(cb: (args: any) => void): void;
off(cb: (args: any) => void): void;
ready(): Promise<void>;
Expand Down

0 comments on commit 3b5ce14

Please sign in to comment.