@loozo/angular-launch 0.0.6 → 0.1.0
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/README.md +715 -255
- package/builders/application.js +32 -3
- package/builders/channel-forwarding.d.ts +15 -0
- package/builders/channel-forwarding.js +61 -0
- package/builders/options.d.ts +6 -2
- package/builders/options.js +16 -5
- package/builders/serve.js +198 -140
- package/channel.d.ts +3 -1
- package/channel.js +3 -2
- package/client.d.ts +14 -24
- package/generation/index.d.ts +2 -123
- package/generation/index.js +3 -685
- package/generation/redirects.d.ts +14 -0
- package/generation/redirects.js +43 -0
- package/generation/run.d.ts +168 -0
- package/generation/run.js +659 -0
- package/index.d.ts +2 -0
- package/index.js +1 -0
- package/launch-queries.d.ts +16 -0
- package/launch-queries.js +3 -0
- package/navigation.d.ts +3 -3
- package/navigation.js +1 -1
- package/node/index.d.ts +3 -0
- package/node/index.js +6 -3
- package/node/upgrade-listener-slot.d.ts +1 -0
- package/node/upgrade-listener-slot.js +4 -0
- package/outcomes.d.ts +23 -7
- package/outcomes.js +58 -12
- package/package.json +15 -11
- package/redirect-translation.d.ts +53 -0
- package/redirect-translation.js +141 -0
- package/{generated.js → remote-client.js} +27 -21
- package/route-types.d.ts +130 -0
- package/route-types.js +1 -0
- package/route.d.ts +45 -0
- package/route.js +113 -0
- package/schemas/application.json +19 -3
- package/schemas/serve.json +3 -3
- package/server/application.d.ts +107 -0
- package/server/application.js +108 -0
- package/server/backend.d.ts +25 -13
- package/server/backend.js +39 -24
- package/server/channel-messages.d.ts +1 -1
- package/server/channel-messages.js +1 -1
- package/server/channel-socket.d.ts +1 -1
- package/server/definitions.d.ts +146 -298
- package/server/definitions.js +29 -117
- package/server/dispatch.d.ts +67 -63
- package/server/dispatch.js +121 -61
- package/server/event-stream.d.ts +2 -2
- package/server/event-stream.js +1 -1
- package/server/generated.d.ts +2 -1
- package/server/generated.js +2 -1
- package/server/index.d.ts +3 -2
- package/server/index.js +2 -1
- package/server/outcomes.d.ts +26 -13
- package/server/outcomes.js +43 -16
- package/server/read-cookies.d.ts +19 -0
- package/server/read-cookies.js +39 -0
- package/server/response-effects.d.ts +2 -2
- package/server/stages.d.ts +62 -0
- package/server/stages.js +51 -0
- package/server/upgrade.d.ts +11 -12
- package/server/upgrade.js +13 -14
- package/source-text.d.ts +1 -0
- package/source-text.js +56 -0
- package/stream.d.ts +6 -3
- package/stream.js +8 -6
- package/tanstack-query/README.md +15 -15
- package/tanstack-query/create-queries.d.ts +2 -0
- package/tanstack-query/{generated.js → create-queries.js} +8 -9
- package/tanstack-query/hydration-window.d.ts +11 -0
- package/tanstack-query/hydration-window.js +9 -0
- package/tanstack-query/hydration.d.ts +4 -14
- package/tanstack-query/hydration.js +9 -12
- package/tanstack-query/index.d.ts +1 -1
- package/tanstack-query/queries.d.ts +42 -27
- package/testing/call-procedure.d.ts +154 -0
- package/testing/call-procedure.js +97 -0
- package/testing/index.d.ts +2 -0
- package/testing/index.js +1 -0
- package/generation/context-file.d.ts +0 -2
- package/generation/context-file.js +0 -3
- package/tanstack-query/generated.d.ts +0 -5
- /package/{generated.d.ts → remote-client.d.ts} +0 -0
package/builders/application.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createBuilder, } from "@angular-devkit/architect";
|
|
2
|
-
import {
|
|
2
|
+
import { runGeneration } from "../generation/run.js";
|
|
3
|
+
import { localeTable, localeTableWarnings, projectI18n, projectLocalization, withLocaleTable, } from "@loozo/angular-router/_generation";
|
|
3
4
|
import { message, split } from "./options.js";
|
|
4
5
|
const officialApplicationBuilder = "@angular/build:application";
|
|
5
|
-
// The conditions @angular/build 22.
|
|
6
|
+
// The conditions @angular/build 22.3's bundler uses when none are configured, chosen from the
|
|
6
7
|
// normalized optimization as it chooses them.
|
|
7
8
|
function defaultConditions(optimization = true) {
|
|
8
9
|
let scripts = optimization;
|
|
@@ -41,7 +42,35 @@ const builder = createBuilder(async (options, context) => {
|
|
|
41
42
|
if (official.conditions === false) {
|
|
42
43
|
official.conditions = defaultConditions(official.optimization);
|
|
43
44
|
}
|
|
44
|
-
generation =
|
|
45
|
+
generation = (async () => {
|
|
46
|
+
const project = context.target?.project;
|
|
47
|
+
if (launch.translateSegments === true) {
|
|
48
|
+
if (!project) {
|
|
49
|
+
throw new Error("translateSegments needs the application builder to run as a project target");
|
|
50
|
+
}
|
|
51
|
+
launch.localization = await projectLocalization(context, project, official.polyfills);
|
|
52
|
+
}
|
|
53
|
+
const words = await runGeneration(context.workspaceRoot, launch, () => stopped);
|
|
54
|
+
// Angular's own builder needs a project target to localize, so a build without one fails
|
|
55
|
+
// there.
|
|
56
|
+
if (!project || official.localize === undefined || official.localize === false) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// The router's locale table, from the words generation just validated, so localeUrls and
|
|
60
|
+
// the inlined destination text agree.
|
|
61
|
+
const table = localeTable({
|
|
62
|
+
i18n: await projectI18n(context, project),
|
|
63
|
+
baseHref: official.baseHref,
|
|
64
|
+
localize: official.localize,
|
|
65
|
+
words,
|
|
66
|
+
});
|
|
67
|
+
if (table) {
|
|
68
|
+
for (const warning of localeTableWarnings(table)) {
|
|
69
|
+
context.logger.warn(warning);
|
|
70
|
+
}
|
|
71
|
+
official.define = withLocaleTable(official.define, table);
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
45
74
|
try {
|
|
46
75
|
await generation;
|
|
47
76
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BuilderContext } from "@angular-devkit/architect";
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
3
|
+
/** A connect middleware, as Angular's dev server takes it. */
|
|
4
|
+
export type DevServerMiddleware = (request: IncomingMessage, response: ServerResponse, next: (error?: unknown) => void) => void;
|
|
5
|
+
/**
|
|
6
|
+
* The dev server's connect middleware that forwards channel upgrades to the app.
|
|
7
|
+
*
|
|
8
|
+
* Vite's HTTP server hands websocket upgrades to its `upgrade` listeners, never to middleware,
|
|
9
|
+
* so on the first request through a server this attaches one listener to it. That listener passes
|
|
10
|
+
* `/_rpc/` upgrades to the latest listener `createUpgradeHandler` created, which the server
|
|
11
|
+
* module creates at its top level each time Vite loads it, and leaves every other upgrade, such
|
|
12
|
+
* as Vite's HMR socket, to the server's own listeners. Until a listener exists it answers them
|
|
13
|
+
* with a plain-text 503 and warns once. The middleware itself always calls `next()`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function forwardChannels(logger: BuilderContext["logger"]): DevServerMiddleware;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { upgradeListenerSlot } from "../node/upgrade-listener-slot.js";
|
|
3
|
+
const unavailableBody = "Channels aren't available: the server module created no upgrade handler\n";
|
|
4
|
+
const unavailable = "HTTP/1.1 503 Service Unavailable\r\n" +
|
|
5
|
+
"content-type: text/plain\r\n" +
|
|
6
|
+
`content-length: ${Buffer.byteLength(unavailableBody)}\r\n` +
|
|
7
|
+
"connection: close\r\n\r\n" +
|
|
8
|
+
unavailableBody;
|
|
9
|
+
function ignore() { }
|
|
10
|
+
/**
|
|
11
|
+
* The dev server's connect middleware that forwards channel upgrades to the app.
|
|
12
|
+
*
|
|
13
|
+
* Vite's HTTP server hands websocket upgrades to its `upgrade` listeners, never to middleware,
|
|
14
|
+
* so on the first request through a server this attaches one listener to it. That listener passes
|
|
15
|
+
* `/_rpc/` upgrades to the latest listener `createUpgradeHandler` created, which the server
|
|
16
|
+
* module creates at its top level each time Vite loads it, and leaves every other upgrade, such
|
|
17
|
+
* as Vite's HMR socket, to the server's own listeners. Until a listener exists it answers them
|
|
18
|
+
* with a plain-text 503 and warns once. The middleware itself always calls `next()`.
|
|
19
|
+
*/
|
|
20
|
+
export function forwardChannels(logger) {
|
|
21
|
+
const servers = new WeakSet();
|
|
22
|
+
let reportedNoServer = false;
|
|
23
|
+
let reportedNoListener = false;
|
|
24
|
+
function forward(request, socket, head) {
|
|
25
|
+
if (!request.url?.startsWith("/_rpc/")) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const listener = globalThis[upgradeListenerSlot];
|
|
29
|
+
if (listener !== undefined) {
|
|
30
|
+
listener(request, socket, head);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!reportedNoListener) {
|
|
34
|
+
reportedNoListener = true;
|
|
35
|
+
logger.warn(`A channel upgrade to ${request.url} was answered 503: no createUpgradeHandler listener ` +
|
|
36
|
+
"exists. Create it at your server module's top level; the dev server loads that module " +
|
|
37
|
+
"with the first request it passes to server.ts, such as a page.");
|
|
38
|
+
}
|
|
39
|
+
// A client resetting while the refusal is written must not crash the dev server.
|
|
40
|
+
socket.on("error", ignore);
|
|
41
|
+
if (!socket.destroyed) {
|
|
42
|
+
socket.end(unavailable);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return (request, _response, next) => {
|
|
46
|
+
// Node records the server that accepted a connection on its socket, undocumented.
|
|
47
|
+
const server = request.socket.server;
|
|
48
|
+
if (server instanceof EventEmitter) {
|
|
49
|
+
if (!servers.has(server)) {
|
|
50
|
+
servers.add(server);
|
|
51
|
+
server.on("upgrade", forward);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else if (!reportedNoServer) {
|
|
55
|
+
reportedNoServer = true;
|
|
56
|
+
logger.warn("Launch can't forward channel upgrades under this dev server: its requests don't expose " +
|
|
57
|
+
"their HTTP server, so channels won't connect.");
|
|
58
|
+
}
|
|
59
|
+
next();
|
|
60
|
+
};
|
|
61
|
+
}
|
package/builders/options.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type BuilderContext } from "@angular-devkit/architect";
|
|
2
|
-
import type { GenerationOptions } from "../generation/
|
|
2
|
+
import type { GenerationOptions } from "../generation/run.js";
|
|
3
3
|
export type JsonObject = NonNullable<Parameters<BuilderContext["scheduleBuilder"]>[1]>;
|
|
4
4
|
export declare const applicationBuilder = "@loozo/angular-launch:application";
|
|
5
5
|
export declare function message(error: unknown): string;
|
|
@@ -7,4 +7,8 @@ export declare function split(options: JsonObject): {
|
|
|
7
7
|
launch: GenerationOptions;
|
|
8
8
|
official: JsonObject;
|
|
9
9
|
};
|
|
10
|
-
export declare function buildTargetOptions(context: BuilderContext, buildTarget: string): Promise<
|
|
10
|
+
export declare function buildTargetOptions(context: BuilderContext, buildTarget: string): Promise<{
|
|
11
|
+
launch: GenerationOptions;
|
|
12
|
+
official: JsonObject;
|
|
13
|
+
project: string;
|
|
14
|
+
}>;
|
package/builders/options.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { targetFromTargetString } from "@angular-devkit/architect";
|
|
2
|
+
import { checkLocaleTableDefine, projectLocalization } from "@loozo/angular-router/_generation";
|
|
2
3
|
export const applicationBuilder = "@loozo/angular-launch:application";
|
|
3
4
|
function validateLaunchOptions(value) {
|
|
4
5
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
@@ -16,7 +17,7 @@ function validateLaunchOptions(value) {
|
|
|
16
17
|
scanDirectories.some((scan) => typeof scan !== "string" || scan.trim() === "")) {
|
|
17
18
|
throw new Error("scanDirectories must contain exactly one nonempty string");
|
|
18
19
|
}
|
|
19
|
-
for (const key of ["tanstackQuery", "check"]) {
|
|
20
|
+
for (const key of ["tanstackQuery", "translateSegments", "check"]) {
|
|
20
21
|
if (Object.hasOwn(value, key) && typeof value[key] !== "boolean") {
|
|
21
22
|
throw new Error(`${key} must be a boolean`);
|
|
22
23
|
}
|
|
@@ -28,20 +29,27 @@ export function message(error) {
|
|
|
28
29
|
}
|
|
29
30
|
return String(error);
|
|
30
31
|
}
|
|
31
|
-
// Launch options drive generation; everything else belongs to Angular's application builder
|
|
32
|
+
// Launch options drive generation; everything else belongs to Angular's application builder,
|
|
33
|
+
// except define.loozoRouterLocales, which the builders set for the router's locale table.
|
|
32
34
|
export function split(options) {
|
|
33
35
|
validateLaunchOptions(options);
|
|
34
|
-
const { tsconfig, scanDirectories, outDirectory, tanstackQuery, check, ...official } = options;
|
|
36
|
+
const { tsconfig, scanDirectories, outDirectory, tanstackQuery, translateSegments, check, ...official } = options;
|
|
35
37
|
const launch = { tsconfig, scanDirectories, outDirectory };
|
|
38
|
+
checkLocaleTableDefine(official.define);
|
|
36
39
|
if (tanstackQuery !== undefined) {
|
|
37
40
|
launch.tanstackQuery = tanstackQuery;
|
|
38
41
|
}
|
|
42
|
+
if (translateSegments !== undefined) {
|
|
43
|
+
launch.translateSegments = translateSegments;
|
|
44
|
+
}
|
|
39
45
|
if (check !== undefined) {
|
|
40
46
|
launch.check = check;
|
|
41
47
|
}
|
|
42
48
|
return { launch, official };
|
|
43
49
|
}
|
|
44
50
|
// Launch options for serve come from its build target, resolved as Angular's dev server resolves it.
|
|
51
|
+
// The official options give the locale table its baseHref and localize; project is the build
|
|
52
|
+
// target's.
|
|
45
53
|
export async function buildTargetOptions(context, buildTarget) {
|
|
46
54
|
const project = context.target?.project;
|
|
47
55
|
if (!project) {
|
|
@@ -56,9 +64,12 @@ export async function buildTargetOptions(context, buildTarget) {
|
|
|
56
64
|
throw new Error(`buildTarget ${target.project}:${target.target} must use ${applicationBuilder}, not ${builder}`);
|
|
57
65
|
}
|
|
58
66
|
const options = await context.validateOptions(raw, builder);
|
|
59
|
-
const { launch } = split(options);
|
|
67
|
+
const { launch, official } = split(options);
|
|
60
68
|
if (launch.check === true) {
|
|
61
69
|
throw new Error("Serve writes generated files; its buildTarget must not resolve check: true");
|
|
62
70
|
}
|
|
63
|
-
|
|
71
|
+
if (launch.translateSegments === true) {
|
|
72
|
+
launch.localization = await projectLocalization(context, target.project, official.polyfills);
|
|
73
|
+
}
|
|
74
|
+
return { launch, official, project: target.project };
|
|
64
75
|
}
|
package/builders/serve.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { createBuilder, } from "@angular-devkit/architect";
|
|
2
2
|
import chokidar from "chokidar";
|
|
3
3
|
import { Observable } from "rxjs";
|
|
4
|
-
import {
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { basename, dirname, resolve } from "node:path";
|
|
5
6
|
import { readFile, realpath } from "node:fs/promises";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
8
|
+
import { changedTableWarning, checkLocaleTableDefine, localeTable, localeTableWarnings, projectI18n, withLocaleTable, } from "@loozo/angular-router/_generation";
|
|
9
|
+
import { createBuilderSession } from "../generation/run.js";
|
|
10
|
+
import { forwardChannels } from "./channel-forwarding.js";
|
|
9
11
|
import { buildTargetOptions, message } from "./options.js";
|
|
10
12
|
// Polling catches what Angular 22.2's native watcher (@parcel/watcher) misses: edits to files
|
|
11
13
|
// inside a renamed directory, which otherwise leave the dev server serving stale output.
|
|
@@ -17,77 +19,70 @@ const devServerBuilder = "@angular/build:dev-server";
|
|
|
17
19
|
const settleDelay = 150;
|
|
18
20
|
// Generation's own marked outputs in the scan directory; their events need no further pass. The
|
|
19
21
|
// output directory can't overlap the scan directory, so its files never reach the watcher. The
|
|
20
|
-
// router's
|
|
21
|
-
// redundant pass, which writes nothing.
|
|
22
|
+
// router's markers aren't part of its generation seam; if this copy drifts, a write only causes one
|
|
23
|
+
// redundant pass, which writes nothing. The router's per-route copies are line-aligned with their
|
|
24
|
+
// declaration, so they carry the marker on their last line; other router outputs on their first.
|
|
22
25
|
const generatedMarkers = {
|
|
23
|
-
"route.generated.ts":
|
|
24
|
-
|
|
26
|
+
"route.generated.ts": {
|
|
27
|
+
marker: "// @loozo/angular-router routegen: owned route.generated.ts",
|
|
28
|
+
line: "last",
|
|
29
|
+
},
|
|
30
|
+
"destination.generated.ts": {
|
|
31
|
+
marker: "// @loozo/angular-router routegen: owned destination.generated.ts",
|
|
32
|
+
line: "last",
|
|
33
|
+
},
|
|
34
|
+
"children.generated.ts": {
|
|
35
|
+
marker: "// @loozo/angular-router routegen: owned children.generated.ts",
|
|
36
|
+
line: "first",
|
|
37
|
+
},
|
|
25
38
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
// Angular's dev server from the @angular/build the workspace resolves, as Architect resolved the
|
|
40
|
+
// "@angular/build:dev-server" builder.
|
|
41
|
+
async function loadDevServer(workspaceRoot) {
|
|
42
|
+
const entry = createRequire(import.meta.url).resolve("@angular/build", {
|
|
43
|
+
paths: [workspaceRoot],
|
|
44
|
+
});
|
|
45
|
+
const angularBuild = await import(pathToFileURL(entry).href);
|
|
46
|
+
return angularBuild.executeDevServerBuilder;
|
|
29
47
|
}
|
|
30
48
|
// Annotated so the emitted declaration doesn't reach into @angular-devkit/core.
|
|
31
49
|
const builder = createBuilder((options, context) => new Observable((subscriber) => {
|
|
32
50
|
let stopped = false;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
|
|
51
|
+
// One pass at a time. "pending" lasts until the initial generation starts, which covers the
|
|
52
|
+
// edits before it. An edit during a "running" pass makes it "rerun": exactly one more pass
|
|
53
|
+
// follows it, however many edits arrive.
|
|
54
|
+
let regeneration = "pending";
|
|
55
|
+
// The latest pass, settled once idle; stopping waits for it.
|
|
56
|
+
let pass = Promise.resolve();
|
|
57
|
+
// What start() acquired, released last-acquired first. Each release runs as stop() is called;
|
|
58
|
+
// the promises they return settle together, with the latest pass.
|
|
59
|
+
const releases = [];
|
|
41
60
|
let cleanup;
|
|
42
|
-
let cancelReady;
|
|
43
61
|
let settling;
|
|
44
62
|
// Resolved before the watcher starts.
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (stopped || contextFile === undefined || contextFile === watchedContext) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const previous = contextWatcher;
|
|
56
|
-
contextWatcher = undefined;
|
|
57
|
-
watchedContext = contextFile;
|
|
58
|
-
void previous?.close().catch((error) => context.logger.error(String(error)));
|
|
59
|
-
if (contains(scanRoot, contextFile)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const followed = chokidar.watch(contextFile, {
|
|
63
|
-
ignoreInitial: true,
|
|
64
|
-
followSymlinks: false,
|
|
65
|
-
});
|
|
66
|
-
contextWatcher = followed;
|
|
67
|
-
followed.on("error", (error) => context.logger.error(String(error)));
|
|
68
|
-
followed.on("all", (_event, path) => {
|
|
69
|
-
void changed(path).catch((error) => context.logger.error(String(error)));
|
|
70
|
-
});
|
|
71
|
-
// The pass that found this path read the context before its watch existed, so an edit since
|
|
72
|
-
// went unseen. Once the watch is live, one more pass reads the current text; the watch
|
|
73
|
-
// covers the rest.
|
|
74
|
-
followed.once("ready", () => {
|
|
75
|
-
if (stopped || contextWatcher !== followed) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
dirty = true;
|
|
79
|
-
pump();
|
|
80
|
-
});
|
|
81
|
-
}
|
|
63
|
+
let session;
|
|
64
|
+
// The router's locale table of a pass, from the build target's options and that pass's words.
|
|
65
|
+
let tableOf = () => undefined;
|
|
66
|
+
// The table the dev server started with: its define is read once, at its start.
|
|
67
|
+
let started;
|
|
68
|
+
// Each later table that differed from it, by JSON, so each is warned about once.
|
|
69
|
+
const warned = new Set();
|
|
82
70
|
async function changed(path) {
|
|
83
71
|
if (stopped) {
|
|
84
72
|
return;
|
|
85
73
|
}
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
74
|
+
const owned = generatedMarkers[basename(path)];
|
|
75
|
+
if (owned !== undefined) {
|
|
88
76
|
try {
|
|
89
77
|
const bytes = await readFile(path, "utf8");
|
|
90
|
-
|
|
78
|
+
const lines = bytes.split("\n");
|
|
79
|
+
let line = lines[0];
|
|
80
|
+
if (owned.line === "last") {
|
|
81
|
+
line = lines.findLast((text) => text !== "" && text !== "\r") ?? "";
|
|
82
|
+
}
|
|
83
|
+
// Git may check the file out with CRLF line endings (core.autocrlf on Windows); the
|
|
84
|
+
// router's generation still treats it as its own output.
|
|
85
|
+
if (line === owned.marker || line === `${owned.marker}\r`) {
|
|
91
86
|
return;
|
|
92
87
|
}
|
|
93
88
|
}
|
|
@@ -103,57 +98,61 @@ const builder = createBuilder((options, context) => new Observable((subscriber)
|
|
|
103
98
|
clearTimeout(settling);
|
|
104
99
|
settling = setTimeout(() => {
|
|
105
100
|
settling = undefined;
|
|
106
|
-
|
|
107
|
-
pump();
|
|
101
|
+
edited();
|
|
108
102
|
}, settleDelay);
|
|
109
103
|
}
|
|
110
104
|
// A failed or stopped pass leaves the session clean; the next pass starts fresh.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
await session.generate(undefined, () => stopped);
|
|
114
|
-
}
|
|
115
|
-
finally {
|
|
116
|
-
followContext();
|
|
117
|
-
}
|
|
105
|
+
function regenerate() {
|
|
106
|
+
return session.generate(undefined, () => stopped);
|
|
118
107
|
}
|
|
119
108
|
function stop() {
|
|
109
|
+
if (cleanup) {
|
|
110
|
+
return cleanup;
|
|
111
|
+
}
|
|
120
112
|
stopped = true;
|
|
121
|
-
dirty = false;
|
|
122
113
|
clearTimeout(settling);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const close = Promise.all([watcher?.close(), contextWatcher?.close()]);
|
|
127
|
-
const delegateStop = acquisition?.then((run) => run.stop(), () => undefined);
|
|
128
|
-
const drain = active?.catch(() => undefined);
|
|
129
|
-
cleanup = Promise.all([close, delegateStop, drain, session?.dispose()]).then(() => undefined);
|
|
114
|
+
const closing = [pass.catch(() => undefined)];
|
|
115
|
+
for (let index = releases.length - 1; index >= 0; index--) {
|
|
116
|
+
closing.push(releases[index]());
|
|
130
117
|
}
|
|
118
|
+
cleanup = Promise.all(closing).then(() => undefined);
|
|
131
119
|
return cleanup;
|
|
132
120
|
}
|
|
133
121
|
context.addTeardown(stop);
|
|
134
|
-
|
|
135
|
-
|
|
122
|
+
// A later pass whose table differs from the started one: the running dev server keeps the
|
|
123
|
+
// started table, so the developer learns to restart it.
|
|
124
|
+
function compareTable(words) {
|
|
125
|
+
const current = tableOf(words);
|
|
126
|
+
if (!started || !current) {
|
|
136
127
|
return;
|
|
137
128
|
}
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
129
|
+
const json = JSON.stringify(current);
|
|
130
|
+
if (json === JSON.stringify(started) || warned.has(json)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
warned.add(json);
|
|
134
|
+
context.logger.warn(changedTableWarning(started, current));
|
|
135
|
+
}
|
|
136
|
+
// Later passes log their failures and keep serving.
|
|
137
|
+
function startPass() {
|
|
138
|
+
regeneration = "running";
|
|
139
|
+
pass = regenerate().then(compareTable, (error) => context.logger.error(message(error)));
|
|
140
|
+
void pass.then(passEnded);
|
|
141
|
+
}
|
|
142
|
+
function passEnded() {
|
|
143
|
+
if (regeneration === "rerun" && !stopped) {
|
|
144
|
+
startPass();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
regeneration = "idle";
|
|
148
|
+
}
|
|
149
|
+
function edited() {
|
|
150
|
+
if (regeneration === "idle") {
|
|
151
|
+
startPass();
|
|
152
|
+
}
|
|
153
|
+
else if (regeneration === "running") {
|
|
154
|
+
regeneration = "rerun";
|
|
155
|
+
}
|
|
157
156
|
}
|
|
158
157
|
async function start() {
|
|
159
158
|
const { poll = defaultPoll, ...devServer } = options;
|
|
@@ -163,7 +162,22 @@ const builder = createBuilder((options, context) => new Observable((subscriber)
|
|
|
163
162
|
// Architect already validated the dev-server options against schemas/serve.json, Angular's
|
|
164
163
|
// dev-server schema with this poll. The build target is validated before the watcher and
|
|
165
164
|
// generation too, so invalid options never write.
|
|
166
|
-
|
|
165
|
+
checkLocaleTableDefine(devServer.define);
|
|
166
|
+
const { launch, official, project } = await buildTargetOptions(context, options.buildTarget);
|
|
167
|
+
if (stopped) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
// Angular's dev server localizes only a single-locale list, so only that gets a table.
|
|
171
|
+
if (Array.isArray(official.localize) && official.localize.length === 1) {
|
|
172
|
+
const i18n = await projectI18n(context, project);
|
|
173
|
+
tableOf = (words) => localeTable({
|
|
174
|
+
i18n,
|
|
175
|
+
baseHref: official.baseHref,
|
|
176
|
+
localize: official.localize,
|
|
177
|
+
served: true,
|
|
178
|
+
words,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
167
181
|
if (stopped) {
|
|
168
182
|
return;
|
|
169
183
|
}
|
|
@@ -171,33 +185,42 @@ const builder = createBuilder((options, context) => new Observable((subscriber)
|
|
|
171
185
|
if (stopped) {
|
|
172
186
|
return;
|
|
173
187
|
}
|
|
174
|
-
scanRoot = resolve(dirname(resolve(application, launch.tsconfig)), launch.scanDirectories[0]);
|
|
175
|
-
session =
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
const scanRoot = resolve(dirname(resolve(application, launch.tsconfig)), launch.scanDirectories[0]);
|
|
189
|
+
session = createBuilderSession(context.workspaceRoot, launch);
|
|
190
|
+
releases.push(() => session.dispose());
|
|
191
|
+
// A catalog edit regenerates too: bytes stay the same, so only the per-locale check runs.
|
|
192
|
+
// Angular's dev server applies a catalog at its next rebuild, not at this edit.
|
|
193
|
+
const watched = [scanRoot];
|
|
194
|
+
for (const locale of launch.localization?.locales ?? []) {
|
|
195
|
+
watched.push(...locale.files);
|
|
196
|
+
}
|
|
197
|
+
const watcher = chokidar.watch(watched, { ignoreInitial: true, followSymlinks: false });
|
|
198
|
+
const ready = Promise.withResolvers();
|
|
199
|
+
releases.push(() => {
|
|
200
|
+
ready.resolve(false);
|
|
201
|
+
return watcher.close();
|
|
202
|
+
});
|
|
203
|
+
// A watcher error fails startup until the watcher is ready. From then on, including during
|
|
204
|
+
// the initial generation, it's logged and serve carries on.
|
|
205
|
+
watcher.on("error", ready.reject);
|
|
206
|
+
watcher.once("ready", () => {
|
|
207
|
+
watcher.off("error", ready.reject);
|
|
208
|
+
watcher.on("error", (error) => context.logger.error(String(error)));
|
|
209
|
+
ready.resolve(true);
|
|
191
210
|
});
|
|
192
|
-
|
|
211
|
+
watcher.on("all", (_event, path) => {
|
|
212
|
+
void changed(path).catch((error) => context.logger.error(String(error)));
|
|
213
|
+
});
|
|
214
|
+
const readyForGeneration = await ready.promise;
|
|
193
215
|
if (stopped || !readyForGeneration) {
|
|
194
216
|
return;
|
|
195
217
|
}
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
|
|
218
|
+
regeneration = "running";
|
|
219
|
+
const initial = regenerate();
|
|
220
|
+
let words;
|
|
221
|
+
pass = initial;
|
|
199
222
|
try {
|
|
200
|
-
await
|
|
223
|
+
words = await initial;
|
|
201
224
|
}
|
|
202
225
|
catch (error) {
|
|
203
226
|
// The dev server never starts on a failed initial generation; report it as a build failure.
|
|
@@ -207,36 +230,71 @@ const builder = createBuilder((options, context) => new Observable((subscriber)
|
|
|
207
230
|
subscriber.complete();
|
|
208
231
|
return;
|
|
209
232
|
}
|
|
210
|
-
finally {
|
|
211
|
-
if (active === generation) {
|
|
212
|
-
active = undefined;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
233
|
if (stopped) {
|
|
216
234
|
return;
|
|
217
235
|
}
|
|
218
|
-
|
|
219
|
-
|
|
236
|
+
// Before a queued pass can compare its table with it.
|
|
237
|
+
started = tableOf(words);
|
|
238
|
+
passEnded();
|
|
220
239
|
if (stopped) {
|
|
221
240
|
return;
|
|
222
241
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
242
|
+
if (started) {
|
|
243
|
+
for (const warning of localeTableWarnings(started)) {
|
|
244
|
+
context.logger.warn(warning);
|
|
245
|
+
}
|
|
246
|
+
devServer.define = withLocaleTable(devServer.define, started);
|
|
247
|
+
}
|
|
248
|
+
// Run directly, the dev server gets its options as given, so they're validated and
|
|
249
|
+
// defaulted against its schema as scheduling it did.
|
|
250
|
+
const validated = await context.validateOptions(devServer, devServerBuilder);
|
|
251
|
+
const executeDevServer = await loadDevServer(context.workspaceRoot);
|
|
227
252
|
if (stopped) {
|
|
228
|
-
await run.stop();
|
|
229
253
|
return;
|
|
230
254
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
255
|
+
// Angular's dev server adds its own teardowns, which close Vite's server and abort the
|
|
256
|
+
// build's watch, to the context it runs in. Architect runs a context's teardowns only on a
|
|
257
|
+
// Stop, not when the builder fails or ends, so the dev server gets a context that collects
|
|
258
|
+
// them here, and its release runs them for every way serving ends.
|
|
259
|
+
const devServerTeardowns = [];
|
|
260
|
+
const devServerContext = {
|
|
261
|
+
...context,
|
|
262
|
+
addTeardown(teardown) {
|
|
263
|
+
devServerTeardowns.push(teardown);
|
|
238
264
|
},
|
|
265
|
+
};
|
|
266
|
+
const serving = executeDevServer(validated, devServerContext, {
|
|
267
|
+
middleware: [forwardChannels(context.logger)],
|
|
268
|
+
})[Symbol.asyncIterator]();
|
|
269
|
+
const stopping = Promise.withResolvers();
|
|
270
|
+
releases.push(() => {
|
|
271
|
+
stopping.resolve(undefined);
|
|
272
|
+
const closing = [];
|
|
273
|
+
for (const teardown of devServerTeardowns) {
|
|
274
|
+
closing.push(Promise.resolve(teardown()));
|
|
275
|
+
}
|
|
276
|
+
// Ending the iteration releases the dev server's generator if it's waiting at a yield.
|
|
277
|
+
// It isn't awaited: a pending step settles only once the teardowns above closed the
|
|
278
|
+
// dev server.
|
|
279
|
+
void serving.return?.().catch((error) => context.logger.error(String(error)));
|
|
280
|
+
return Promise.all(closing);
|
|
239
281
|
});
|
|
282
|
+
while (!stopped) {
|
|
283
|
+
const next = serving.next();
|
|
284
|
+
// Once stopping wins the race nothing reads this step, so its failure is handled here.
|
|
285
|
+
next.catch(() => undefined);
|
|
286
|
+
const result = await Promise.race([next, stopping.promise]);
|
|
287
|
+
if (result === undefined || result.done) {
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
subscriber.next(result.value);
|
|
291
|
+
}
|
|
292
|
+
if (stopped) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
// The dev server ended on its own.
|
|
296
|
+
await stop();
|
|
297
|
+
subscriber.complete();
|
|
240
298
|
}
|
|
241
299
|
void start().catch((error) => {
|
|
242
300
|
void stop().then(() => subscriber.error(error), () => subscriber.error(error));
|
package/channel.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ChannelCallOptions, ErrorMetadata, RpcError } from "./client.js";
|
|
2
|
+
import type { TranslateRedirect } from "./redirect-translation.js";
|
|
2
3
|
/**
|
|
3
4
|
* An open channel: the values its handler yields, and `send` for messages to it.
|
|
4
5
|
*
|
|
@@ -49,5 +50,6 @@ export interface Channel<Received, Sent> extends AsyncIterable<Received> {
|
|
|
49
50
|
* @param options - The call options.
|
|
50
51
|
* @param opened - Called once the socket opens.
|
|
51
52
|
* @param refused - Fails the channel at once with this error, without a connection.
|
|
53
|
+
* @param translate - Puts a redirect's listed words in this build's language.
|
|
52
54
|
*/
|
|
53
|
-
export declare function openChannel(path: string, declared: readonly ErrorMetadata[], own: (error: RpcError<string, unknown>) => RpcError<string, unknown>, { signal }: ChannelCallOptions, opened?: () => void, refused?: Error): Channel<unknown, unknown>;
|
|
55
|
+
export declare function openChannel(path: string, declared: readonly ErrorMetadata[], own: (error: RpcError<string, unknown>) => RpcError<string, unknown>, { signal }: ChannelCallOptions, opened?: () => void, refused?: Error, translate?: TranslateRedirect): Channel<unknown, unknown>;
|