@arkstack/common 0.17.18 → 0.17.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +32 -1
- package/dist/index.js +62 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference path="./app.d.ts" />
|
|
2
2
|
import { A as GlobalConfig, B as LoggerLog, C as DotPath, D as EnvRegistry, E as EnvLookup, F as HookPos, G as PublishConfirmation, H as MergedConfig, I as HookPositions, J as PublishGroup, K as PublishEntry, L as HookRegistry, M as HookArgs, N as HookFor, O as EnvReturn, P as HookName, R as IHook, S as ConfigShape, T as EnvKey, U as PaginationOptions, V as LoggerParseSignature, W as Primitive, X as Logger, Y as UnionToIntersection, _ as ArkstackErrorPayload, a as abortIf, b as Choices, c as getModelSync, d as normalizePositiveInteger, f as perPage, g as AppConfig, h as Encryption, i as abort, j as GlobalEnv, k as FileImporter, l as initializeGlobalContext, m as Hash, n as ModelConstructor, o as assertFound, p as resolvePagination, q as PublishFilter, r as ModelRegistry, s as getModel, t as AbstractModelConstructor, u as isClass, v as ArkstackErrorShape, w as DotPathValue, x as ConfigRegistry, y as Choice, z as LoggerChalk } from "./helpers-E_O2UDRn.js";
|
|
3
3
|
import { Arkstack } from "@arkstack/contract";
|
|
4
|
+
import { ForkOptions } from "node:child_process";
|
|
4
5
|
import pino from "pino";
|
|
5
6
|
//#region src/lifecycle.d.ts
|
|
6
7
|
declare const bindGracefulShutdown: (shutdown: () => Promise<void> | void, defer?: boolean) => void;
|
|
@@ -483,4 +484,34 @@ declare const devTlsCredentials: (host?: string) => Promise<TlsCredentials>;
|
|
|
483
484
|
*/
|
|
484
485
|
declare const localNetworkAddress: () => string | undefined;
|
|
485
486
|
//#endregion
|
|
486
|
-
|
|
487
|
+
//#region src/dev-server.d.ts
|
|
488
|
+
interface OutputChunk {
|
|
489
|
+
facadeModuleId?: string | null;
|
|
490
|
+
isEntry?: boolean;
|
|
491
|
+
}
|
|
492
|
+
interface OutputOptions {
|
|
493
|
+
dir?: string;
|
|
494
|
+
file?: string;
|
|
495
|
+
}
|
|
496
|
+
interface DevServerRunnerOptions extends ForkOptions {
|
|
497
|
+
input: string;
|
|
498
|
+
args?: readonly string[];
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Run the emitted server entry after a watched build has completely settled.
|
|
502
|
+
*
|
|
503
|
+
* This runner does not replace the live process immediately in `writeBundle`.
|
|
504
|
+
* Tsdown can still finalize or replace its output after that hook, creating a
|
|
505
|
+
* short window where Node cannot resolve the entry.
|
|
506
|
+
*/
|
|
507
|
+
declare const devServer: (options: DevServerRunnerOptions) => {
|
|
508
|
+
name: string;
|
|
509
|
+
writeBundle?: undefined;
|
|
510
|
+
closeWatcher?: undefined;
|
|
511
|
+
} | {
|
|
512
|
+
name: string;
|
|
513
|
+
writeBundle(output: OutputOptions, bundle: Record<string, OutputChunk>): void;
|
|
514
|
+
closeWatcher(): Promise<void>;
|
|
515
|
+
};
|
|
516
|
+
//#endregion
|
|
517
|
+
export { AbstractModelConstructor, AppConfig, AppException, ArkstackErrorPayload, ArkstackErrorShape, CONFIG_KEY, Choice, Choices, ConfigLoader, ConfigRegistry, ConfigShape, DevServerRunnerOptions, DotPath, DotPathValue, Encryption, EnvKey, EnvLoader, EnvLookup, EnvRegistry, EnvReturn, ErrorHandler, Exception, FileImporter, GlobalConfig, GlobalEnv, Hash, Hook, HookArgs, HookFor, HookName, HookPos, HookPositions, HookRegistry, IHook, Logger, LoggerChalk, LoggerLog, LoggerParseSignature, MergedConfig, ModelConstructor, ModelRegistry, PaginationOptions, Primitive, PublishConfirmation, PublishEntry, PublishFilter, PublishGroup, Publisher, RequestException, TlsCredentials, UnionToIntersection, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, configLoader, createErrorPayload, devServer, devTlsCredentials, discoverCommands, env, envLoader, getErrorLogger, getModel, getModelSync, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, localNetworkAddress, logUnhandledError, nodeEnv, normalizePositiveInteger, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolvePagination, resolveRuntimeDir, resolveRuntimeModule, serializeError, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,8 @@ import { Hook as Hook$1 } from "@arkstack/foundry";
|
|
|
4
4
|
import { Arkstack } from "@arkstack/contract";
|
|
5
5
|
import { str } from "@h3ravel/support";
|
|
6
6
|
import path from "node:path";
|
|
7
|
+
import { access, stat } from "node:fs/promises";
|
|
8
|
+
import { fork } from "node:child_process";
|
|
7
9
|
import { detect } from "detect-port";
|
|
8
10
|
import pino from "pino";
|
|
9
11
|
import chalk from "chalk";
|
|
@@ -599,4 +601,63 @@ const localNetworkAddress = () => {
|
|
|
599
601
|
for (const list of Object.values(networkInterfaces())) for (const net of list ?? []) if (net.family === "IPv4" && !net.internal) return net.address;
|
|
600
602
|
};
|
|
601
603
|
//#endregion
|
|
602
|
-
|
|
604
|
+
//#region src/dev-server.ts
|
|
605
|
+
/**
|
|
606
|
+
* Run the emitted server entry after a watched build has completely settled.
|
|
607
|
+
*
|
|
608
|
+
* This runner does not replace the live process immediately in `writeBundle`.
|
|
609
|
+
* Tsdown can still finalize or replace its output after that hook, creating a
|
|
610
|
+
* short window where Node cannot resolve the entry.
|
|
611
|
+
*/
|
|
612
|
+
const devServer = (options) => {
|
|
613
|
+
if (nodeEnv() !== "dev" || process.env.CLI_BUILD === "true") return { name: "arkstack-dev-server-disabled" };
|
|
614
|
+
let child;
|
|
615
|
+
let restart = Promise.resolve();
|
|
616
|
+
const { input: sourceInput, args: runnerArgs = [], ...forkOptions } = options;
|
|
617
|
+
const input = path.resolve(sourceInput);
|
|
618
|
+
const args = [...runnerArgs];
|
|
619
|
+
const waitUntilStable = async (entry) => {
|
|
620
|
+
let previousSize = -1;
|
|
621
|
+
for (let attempt = 0; attempt < 50; attempt++) {
|
|
622
|
+
try {
|
|
623
|
+
await access(entry);
|
|
624
|
+
const size = (await stat(entry)).size;
|
|
625
|
+
if (size > 0 && size === previousSize) return;
|
|
626
|
+
previousSize = size;
|
|
627
|
+
} catch {
|
|
628
|
+
previousSize = -1;
|
|
629
|
+
}
|
|
630
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
631
|
+
}
|
|
632
|
+
throw new Error(`The emitted server entry was not ready: ${entry}`);
|
|
633
|
+
};
|
|
634
|
+
const stopChild = async () => {
|
|
635
|
+
if (!child || child.exitCode !== null) return;
|
|
636
|
+
const exited = new Promise((resolve) => child?.once("exit", () => resolve()));
|
|
637
|
+
child.kill();
|
|
638
|
+
await exited;
|
|
639
|
+
};
|
|
640
|
+
return {
|
|
641
|
+
name: "arkstack-dev-server",
|
|
642
|
+
writeBundle(output, bundle) {
|
|
643
|
+
const fileName = Object.keys(bundle).find((name) => {
|
|
644
|
+
const chunk = bundle[name];
|
|
645
|
+
return chunk?.isEntry && path.resolve(chunk.facadeModuleId ?? "") === input;
|
|
646
|
+
});
|
|
647
|
+
if (!fileName) throw new Error("Could not find the emitted server entry");
|
|
648
|
+
const directory = output.dir ?? path.dirname(output.file ?? "");
|
|
649
|
+
const entry = path.join(directory, fileName);
|
|
650
|
+
restart = restart.then(async () => {
|
|
651
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
652
|
+
await waitUntilStable(entry);
|
|
653
|
+
await stopChild();
|
|
654
|
+
child = fork(entry, args, forkOptions);
|
|
655
|
+
});
|
|
656
|
+
},
|
|
657
|
+
async closeWatcher() {
|
|
658
|
+
await stopChild();
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
};
|
|
662
|
+
//#endregion
|
|
663
|
+
export { AppException, CONFIG_KEY, ConfigLoader, Encryption, EnvLoader, ErrorHandler, Exception, Hash, Hook, Logger, Publisher, RequestException, abort, abortIf, appKey, appUrl, assertFound, bindGracefulShutdown, bootWithDetectedPort, config, configLoader, createErrorPayload, devServer, devTlsCredentials, discoverCommands, env, envLoader, getErrorLogger, getModel, getModelSync, getPrimaryError, getValidationErrors, importFile, initializeGlobalContext, interopDefault, isClass, isModelNotFoundError, isValidationError, loadPrototypes, localNetworkAddress, logUnhandledError, nodeEnv, normalizePositiveInteger, normalizeStatusCode, outputDir, perPage, rebuildOutput, renderError, resolvePagination, resolveRuntimeDir, resolveRuntimeModule, serializeError, shouldHideStack, shouldLogError, toErrorShape, toOutputPath };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/common",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Core utilities, primitives, and shared infrastructure for the Arkstack ecosystem.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@h3ravel/support": "^2.2.7",
|
|
49
49
|
"arkormx": "^2.12.8",
|
|
50
|
-
"@arkstack/contract": "^0.17.
|
|
51
|
-
"@arkstack/foundry": "^0.17.
|
|
50
|
+
"@arkstack/contract": "^0.17.20",
|
|
51
|
+
"@arkstack/foundry": "^0.17.20"
|
|
52
52
|
},
|
|
53
53
|
"optionalDependencies": {
|
|
54
54
|
"@faker-js/faker": "^10.4.0"
|