@decohere/flux 0.0.1-dev.19 → 0.0.1-dev.20261105.103
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/LICENSE +15 -0
- package/README.md +274 -0
- package/es6/src/deferred-script-runner.js +46 -0
- package/es6/src/flux.command.js +3 -3
- package/es6/src/flux.js +41 -0
- package/es6/src/flux.module.js +9 -8
- package/es6/src/hot-reload-server.js +287 -175
- package/es6/src/index.js +5 -3
- package/es6/src/rewrite-serve-specifier.js +51 -0
- package/es6/src/run.action.js +37 -0
- package/es6/src/run.command.js +55 -0
- package/es6/src/serve.action.js +73 -9
- package/es6/src/serve.command.js +35 -4
- package/es6/src/slice-serve.js +105 -0
- package/es6/src/source-module-loader.js +332 -0
- package/es6/src/static-imports.js +27 -0
- package/es6/src/transpile-disk-cache.js +142 -0
- package/package.json +18 -9
- package/types/src/deferred-script-runner.d.ts +18 -0
- package/types/src/flux.command.d.ts +2 -2
- package/types/src/flux.d.ts +43 -0
- package/types/src/flux.module.d.ts +6 -4
- package/types/src/hot-reload-server.d.ts +57 -23
- package/types/src/index.d.ts +8 -1
- package/types/src/rewrite-serve-specifier.d.ts +14 -0
- package/types/src/run.action.d.ts +15 -0
- package/types/src/run.command.d.ts +11 -0
- package/types/src/serve.action.d.ts +13 -3
- package/types/src/serve.command.d.ts +7 -1
- package/types/src/slice-serve.d.ts +52 -0
- package/types/src/source-module-loader.d.ts +104 -0
- package/types/src/static-imports.d.ts +5 -0
- package/types/src/transpile-disk-cache.d.ts +38 -0
- package/commonjs/src/flux.command.js +0 -27
- package/commonjs/src/flux.module.js +0 -32
- package/commonjs/src/hot-reload-server.js +0 -379
- package/commonjs/src/index.js +0 -22
- package/commonjs/src/serve.action.js +0 -49
- package/commonjs/src/serve.command.js +0 -27
package/es6/src/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { DeferredScriptRunner } from "./deferred-script-runner.js";
|
|
2
|
+
export { flux } from "./flux.js";
|
|
1
3
|
export { FluxModule } from "./flux.module.js";
|
|
2
|
-
export { HotReloadServer } from "./hot-reload-server.js";
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
export { DEFAULT_REBOOT_DEBOUNCE_MS, HotReloadServer } from "./hot-reload-server.js";
|
|
5
|
+
export { classifySliceProject, classifySliceProjects, normalizeSlicePrefix, projectsInSlice, projectsInSlices, resolveDeferScript } from "./slice-serve.js";
|
|
6
|
+
export { SourceModuleLoader } from "./source-module-loader.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
|
+
import { packageAliases, sourceExtensions } from "@decohere/workspace";
|
|
4
|
+
/**
|
|
5
|
+
* Map a resolve-hook specifier to a versioned watched `.ts` file URL.
|
|
6
|
+
* Covers relative `.js` / `.ts` / extensionless imports, directory imports (`./models` is
|
|
7
|
+
* `./models/index.ts`), and bare workspace package names and subpaths. Flux compiles without
|
|
8
|
+
* SWC's own path resolution, so this is the only place imports are mapped to sources.
|
|
9
|
+
*/ export function rewriteServeSpecifier(options) {
|
|
10
|
+
const { specifier, parentUrl, isWatchedTs, resolveBare, versionFileUrl } = options;
|
|
11
|
+
const relativeTs = resolveRelativeWatchedTs(specifier, parentUrl, isWatchedTs);
|
|
12
|
+
if (relativeTs != null) {
|
|
13
|
+
return versionFileUrl(pathToFileURL(relativeTs).toString());
|
|
14
|
+
}
|
|
15
|
+
const bareTarget = resolveBare(specifier);
|
|
16
|
+
const bareTs = bareTarget == null ? null : watchedTs(bareTarget, isWatchedTs);
|
|
17
|
+
if (bareTs != null) {
|
|
18
|
+
return versionFileUrl(pathToFileURL(bareTs).toString());
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The watched source file a path names: itself, or the source its extension stands for (`.js` is
|
|
24
|
+
* `.ts` or `.tsx`, `.mjs` is `.mts`, `.cjs` is `.cts`, none adds `.ts` or `.tsx`), else the
|
|
25
|
+
* `index` source of the directory it names. A file wins over a directory of the same name.
|
|
26
|
+
*/ function watchedTs(filePath, isWatchedTs) {
|
|
27
|
+
const withoutSlash = filePath.replace(/[/\\]+$/, "");
|
|
28
|
+
// The workspace alias lookup may have added `.ts` to a subpath that names a directory (`@lib/models`
|
|
29
|
+
// arrives as `…/models.ts`), so the directory is the path without any extension.
|
|
30
|
+
const directory = withoutSlash.replace(/\.([mc]?[jt]sx?)$/, "");
|
|
31
|
+
const candidates = [
|
|
32
|
+
...sourceExtensions.candidates(withoutSlash),
|
|
33
|
+
...sourceExtensions.candidates(directory),
|
|
34
|
+
...sourceExtensions.candidates(path.join(directory, "index"))
|
|
35
|
+
];
|
|
36
|
+
return candidates.find((candidate)=>isWatchedTs(candidate)) ?? null;
|
|
37
|
+
}
|
|
38
|
+
function resolveRelativeWatchedTs(specifier, parentUrl, isWatchedTs) {
|
|
39
|
+
if (packageAliases.isBareSpecifier(specifier)) return null;
|
|
40
|
+
if (!(specifier.startsWith(".") || specifier.startsWith("/"))) return null;
|
|
41
|
+
const parentClean = parentUrl.split("?")[0];
|
|
42
|
+
if (parentClean == null || parentClean === "") return null;
|
|
43
|
+
let resolved;
|
|
44
|
+
try {
|
|
45
|
+
resolved = new URL(specifier, parentClean);
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
if (resolved.protocol !== "file:") return null;
|
|
50
|
+
return watchedTs(fileURLToPath(resolved), isWatchedTs);
|
|
51
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
}
|
|
7
|
+
function _ts_metadata(k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
}
|
|
10
|
+
import { injectable } from "@decohere/crucible/decorators";
|
|
11
|
+
import { Workspace } from "@decohere/workspace";
|
|
12
|
+
import { ActionResponse } from "@decohere/devkit/cli";
|
|
13
|
+
import { scribe } from "@decohere/scribe";
|
|
14
|
+
import { flux } from "./flux.js";
|
|
15
|
+
export class RunAction {
|
|
16
|
+
workspace;
|
|
17
|
+
logger = scribe.logger(RunAction.name);
|
|
18
|
+
constructor(workspace){
|
|
19
|
+
this.workspace = workspace;
|
|
20
|
+
}
|
|
21
|
+
async run(options) {
|
|
22
|
+
this.logger.trace(`Running ${options.entry}`);
|
|
23
|
+
await flux.run(options.entry, {
|
|
24
|
+
configuration: options.configuration,
|
|
25
|
+
args: options.args,
|
|
26
|
+
workspace: this.workspace
|
|
27
|
+
});
|
|
28
|
+
return ActionResponse.Success(RunAction.name);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
RunAction = _ts_decorate([
|
|
32
|
+
injectable(),
|
|
33
|
+
_ts_metadata("design:type", Function),
|
|
34
|
+
_ts_metadata("design:paramtypes", [
|
|
35
|
+
typeof Workspace === "undefined" ? Object : Workspace
|
|
36
|
+
])
|
|
37
|
+
], RunAction);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ConfigurationOption, DecohereCommand } from "@decohere/devkit/cli";
|
|
2
|
+
import { RunAction } from "./run.action.js";
|
|
3
|
+
export class RunCommand extends DecohereCommand {
|
|
4
|
+
get actions() {
|
|
5
|
+
return [
|
|
6
|
+
RunAction
|
|
7
|
+
];
|
|
8
|
+
}
|
|
9
|
+
constructor(name){
|
|
10
|
+
super(name);
|
|
11
|
+
this.description("Compile and run a TypeScript entry on the fly (no watch / HMR)");
|
|
12
|
+
this.argument("<entry>", "Path to the TypeScript entry file");
|
|
13
|
+
this.argument("[args...]", "Arguments forwarded to the entry after rewriting argv");
|
|
14
|
+
this.addOption(new ConfigurationOption("debug"));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Commander passes positionals before options when `<entry> [args...]` is declared.
|
|
18
|
+
* The CLI host ModuleFactory expects `(opts, cmd)` — normalize and stash entry/args on opts.
|
|
19
|
+
*/ action(fn) {
|
|
20
|
+
return super.action((...args)=>{
|
|
21
|
+
const cmd = args.at(-1);
|
|
22
|
+
const opts = args.at(-2);
|
|
23
|
+
const { entry, entryArgs } = normalizeRunPositionals(args.slice(0, -2));
|
|
24
|
+
cmd.setOptionValue("entry", entry);
|
|
25
|
+
cmd.setOptionValue("args", entryArgs);
|
|
26
|
+
return fn(opts, cmd);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Commander yields `[entry, args[]]` or sometimes a flat list depending on arity. */ function normalizeRunPositionals(positionals) {
|
|
31
|
+
if (positionals.length === 0) {
|
|
32
|
+
return {
|
|
33
|
+
entry: "",
|
|
34
|
+
entryArgs: []
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const first = positionals[0];
|
|
38
|
+
if (typeof first !== "string" || first === "") {
|
|
39
|
+
return {
|
|
40
|
+
entry: "",
|
|
41
|
+
entryArgs: []
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const second = positionals[1];
|
|
45
|
+
if (Array.isArray(second)) {
|
|
46
|
+
return {
|
|
47
|
+
entry: first,
|
|
48
|
+
entryArgs: second.filter((s)=>typeof s === "string")
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
entry: first,
|
|
53
|
+
entryArgs: positionals.slice(1).filter((s)=>typeof s === "string" && s !== "")
|
|
54
|
+
};
|
|
55
|
+
}
|
package/es6/src/serve.action.js
CHANGED
|
@@ -7,35 +7,99 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
7
7
|
function _ts_metadata(k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
}
|
|
10
|
+
import path from "node:path";
|
|
10
11
|
import { injectable } from "@decohere/crucible/decorators";
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
12
|
+
import { Workspace } from "@decohere/workspace";
|
|
13
|
+
import { ActionResponse } from "@decohere/devkit/cli";
|
|
14
|
+
import { scribe } from "@decohere/scribe";
|
|
15
|
+
import { DeferredScriptRunner } from "./deferred-script-runner.js";
|
|
15
16
|
import { HotReloadServer } from "./hot-reload-server.js";
|
|
17
|
+
import { classifySliceProjects, resolveDeferScript } from "./slice-serve.js";
|
|
16
18
|
export class ServeAction {
|
|
17
19
|
server;
|
|
18
20
|
workspace;
|
|
19
|
-
|
|
21
|
+
deferredScripts;
|
|
22
|
+
logger = scribe.logger(ServeAction.name);
|
|
23
|
+
constructor(server, workspace, deferredScripts){
|
|
20
24
|
this.server = server;
|
|
21
25
|
this.workspace = workspace;
|
|
26
|
+
this.deferredScripts = deferredScripts;
|
|
22
27
|
}
|
|
23
28
|
async run(options) {
|
|
29
|
+
const slices = (options.slices ?? []).filter((s)=>s !== "");
|
|
30
|
+
if (slices.length > 0 && options.project != null) {
|
|
31
|
+
throw new Error("Use either directory slices or --project, not both");
|
|
32
|
+
}
|
|
33
|
+
if (slices.length > 0) {
|
|
34
|
+
return this.runSlices(options, slices);
|
|
35
|
+
}
|
|
24
36
|
await this.server.start({
|
|
25
37
|
workspace: this.workspace,
|
|
26
38
|
buildConfig: options.configuration,
|
|
27
|
-
project: options.project
|
|
39
|
+
project: options.project,
|
|
40
|
+
rebootDebounceMs: options.rebootDebounceMs
|
|
28
41
|
});
|
|
29
42
|
return ActionResponse.Blocking(ServeAction.name);
|
|
30
43
|
}
|
|
44
|
+
async runSlices(options, slices) {
|
|
45
|
+
const views = await this.toSliceViews(options.configuration);
|
|
46
|
+
const classified = classifySliceProjects(views, slices);
|
|
47
|
+
const label = slices.join(" ");
|
|
48
|
+
for (const skipped of classified.skip){
|
|
49
|
+
this.logger.info(`skipped ${skipped.projectDirectory} — library (no Flux entry / scripts)`);
|
|
50
|
+
}
|
|
51
|
+
if (classified.flux.length === 0 && classified.defer.length === 0) {
|
|
52
|
+
throw new Error(`No runnable projects in slice(s) "${label}" (need Flux main.ts apps and/or package scripts.dev/serve)`);
|
|
53
|
+
}
|
|
54
|
+
const workspaceRoot = path.resolve(this.workspace.rootDir ?? process.cwd());
|
|
55
|
+
for (const deferred of classified.defer){
|
|
56
|
+
const script = resolveDeferScript(deferred.scripts);
|
|
57
|
+
if (script == null) continue;
|
|
58
|
+
const project = this.findProject(options.configuration, deferred.name);
|
|
59
|
+
this.deferredScripts.start({
|
|
60
|
+
label: deferred.projectDirectory,
|
|
61
|
+
cwd: project.projectRoot,
|
|
62
|
+
script,
|
|
63
|
+
workspaceRoot
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (classified.flux.length > 0) {
|
|
67
|
+
await this.server.start({
|
|
68
|
+
workspace: this.workspace,
|
|
69
|
+
buildConfig: options.configuration,
|
|
70
|
+
projects: classified.flux.map((p)=>p.name),
|
|
71
|
+
rebootDebounceMs: options.rebootDebounceMs
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return ActionResponse.Blocking(ServeAction.name);
|
|
75
|
+
}
|
|
76
|
+
async toSliceViews(configuration) {
|
|
77
|
+
const projects = this.workspace.getProjects(configuration);
|
|
78
|
+
return Promise.all(projects.map((project)=>this.toSliceView(project)));
|
|
79
|
+
}
|
|
80
|
+
async toSliceView(project) {
|
|
81
|
+
const pkg = await project.getPackageJson();
|
|
82
|
+
return {
|
|
83
|
+
name: project.name,
|
|
84
|
+
projectDirectory: project.projectDirectory.replaceAll("\\", "/"),
|
|
85
|
+
main: pkg.main ?? "src/index.ts",
|
|
86
|
+
scripts: pkg.scripts ?? {}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
findProject(configuration, name) {
|
|
90
|
+
const found = this.workspace.getProjects(configuration).find((p)=>p.name === name);
|
|
91
|
+
if (found == null) {
|
|
92
|
+
throw new Error(`Project "${name}" not found in workspace`);
|
|
93
|
+
}
|
|
94
|
+
return found;
|
|
95
|
+
}
|
|
31
96
|
}
|
|
32
97
|
ServeAction = _ts_decorate([
|
|
33
98
|
injectable(),
|
|
34
99
|
_ts_metadata("design:type", Function),
|
|
35
100
|
_ts_metadata("design:paramtypes", [
|
|
36
101
|
typeof HotReloadServer === "undefined" ? Object : HotReloadServer,
|
|
37
|
-
typeof Workspace === "undefined" ? Object : Workspace
|
|
102
|
+
typeof Workspace === "undefined" ? Object : Workspace,
|
|
103
|
+
typeof DeferredScriptRunner === "undefined" ? Object : DeferredScriptRunner
|
|
38
104
|
])
|
|
39
105
|
], ServeAction);
|
|
40
|
-
|
|
41
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9ob21lL3J1bm5lci93b3JrL2RlY29oZXJlL2RlY29oZXJlL3Byb2plY3RzL2ZsdXgvc3JjL3NlcnZlLmFjdGlvbi50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBpbmplY3RhYmxlIH0gZnJvbSBcIkBkZWNvaGVyZS9jcnVjaWJsZS9kZWNvcmF0b3JzXCI7XG4vLyBiaW9tZS1pZ25vcmUgbGludC9zdHlsZS91c2VJbXBvcnRUeXBlOiA8REk+XG5pbXBvcnQgeyBXb3Jrc3BhY2UgfSBmcm9tIFwiQGRlY29oZXJlL21lc2hcIjtcbmltcG9ydCB7IHR5cGUgQWN0aW9uLCBBY3Rpb25SZXNwb25zZSB9IGZyb20gXCJAZGVjb2hlcmUvbmV4dXMvY2xpXCI7XG4vLyBiaW9tZS1pZ25vcmUgbGludC9zdHlsZS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0aW9uIiwicHJvamVjdCIsIkJsb2NraW5nIiwibmFtZSJdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsU0FBU0EsVUFBVSxRQUFRLGdDQUFnQztBQUMzRCw4Q0FBOEM7QUFDOUMsU0FBU0MsU0FBUyxRQUFRLGlCQUFpQjtBQUMzQyxTQUFzQkMsY0FBYyxRQUFRLHNCQUFzQjtBQUNsRSw4Q0FBOEM7QUFDOUMsU0FBU0MsZUFBZSxRQUFRLHlCQUF5QjtBQVF6RCxPQUFPLE1BQU1DOzs7SUFDWixZQUNDLEFBQWlCQyxNQUF1QixFQUN4QyxBQUFpQkMsU0FBb0IsQ0FDcEM7YUFGZ0JELFNBQUFBO2FBQ0FDLFlBQUFBO0lBQ2Y7SUFFSCxNQUFhQyxJQUFJQyxPQUFxQixFQUEyQjtRQUNoRSxNQUFNLElBQUksQ0FBQ0gsTUFBTSxDQUFDSSxLQUFLLENBQUM7WUFDdkJILFdBQVcsSUFBSSxDQUFDQSxTQUFTO1lBQ3pCSSxhQUFhRixRQUFRRyxhQUFhO1lBQ2xDQyxTQUFTSixRQUFRSSxPQUFPO1FBQ3pCO1FBQ0EsT0FBT1YsZUFBZVcsUUFBUSxDQUFDVCxZQUFZVSxJQUFJO0lBQ2hEO0FBQ0QifQ==
|
package/es6/src/serve.command.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ConfigurationOption, DecohereCommand, ProjectOption } from "@decohere/
|
|
1
|
+
import { ConfigurationOption, DecohereCommand, ProjectOption } from "@decohere/devkit/cli";
|
|
2
|
+
import { DEFAULT_REBOOT_DEBOUNCE_MS, resolveRebootDebounceMs } from "./hot-reload-server.js";
|
|
2
3
|
import { ServeAction } from "./serve.action.js";
|
|
3
4
|
export class ServeCommand extends DecohereCommand {
|
|
4
5
|
get actions() {
|
|
@@ -8,10 +9,40 @@ export class ServeCommand extends DecohereCommand {
|
|
|
8
9
|
}
|
|
9
10
|
constructor(name){
|
|
10
11
|
super(name);
|
|
11
|
-
this.description("Serve a project in
|
|
12
|
+
this.description("Serve a project or directory slices (Flux apps in-process; foreign packages via package scripts)");
|
|
13
|
+
this.argument("[slices...]", "Module directories to serve (e.g. funding shell secmaster, or projects/funding)");
|
|
12
14
|
this.addOption(new ConfigurationOption("debug"));
|
|
13
15
|
this.addOption(new ProjectOption());
|
|
16
|
+
this.option("--reboot-debounce-ms <ms>", "Quiet window in milliseconds after the last affecting save before a reboot", (value)=>resolveRebootDebounceMs(Number(value)), DEFAULT_REBOOT_DEBOUNCE_MS);
|
|
14
17
|
}
|
|
18
|
+
runsUntilStopped() {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Commander passes positional args before options when `[slices...]` is declared.
|
|
23
|
+
* The CLI host ModuleFactory expects `(opts, cmd)` — normalize here.
|
|
24
|
+
*/ action(fn) {
|
|
25
|
+
return super.action((...args)=>{
|
|
26
|
+
const cmd = args.at(-1);
|
|
27
|
+
const first = args[0];
|
|
28
|
+
const hasPositionalSlices = Array.isArray(first) || typeof first === "string" || first === undefined;
|
|
29
|
+
const opts = hasPositionalSlices ? args[1] : args[0];
|
|
30
|
+
const slices = normalizePositionalSlices(first);
|
|
31
|
+
if (slices.length > 0) {
|
|
32
|
+
cmd.setOptionValue("slices", slices);
|
|
33
|
+
}
|
|
34
|
+
return fn(opts, cmd);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function normalizePositionalSlices(first) {
|
|
39
|
+
if (Array.isArray(first)) {
|
|
40
|
+
return first.filter((s)=>typeof s === "string" && s !== "");
|
|
41
|
+
}
|
|
42
|
+
if (typeof first === "string" && first !== "") {
|
|
43
|
+
return [
|
|
44
|
+
first
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
return [];
|
|
15
48
|
}
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbI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UFBUSxzQkFBc0I7QUFDMUYsU0FBU0MsV0FBVyxRQUFRLG9CQUFvQjtBQUVoRCxPQUFPLE1BQU1DLHFCQUFxQkg7SUFDakMsSUFBb0JJLFVBQVU7UUFDN0IsT0FBTztZQUFDRjtTQUFZO0lBQ3JCO0lBRUEsWUFBbUJHLElBQVksQ0FBRTtRQUNoQyxLQUFLLENBQUNBO1FBQ04sSUFBSSxDQUFDQyxXQUFXLENBQUM7UUFDakIsSUFBSSxDQUFDQyxTQUFTLENBQUMsSUFBSVIsb0JBQW9CO1FBQ3ZDLElBQUksQ0FBQ1EsU0FBUyxDQUFDLElBQUlOO0lBQ3BCO0FBQ0QifQ==
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directory-slice helpers for `flux serve <dir>…` — classify workspace packages as
|
|
3
|
+
* Flux apps, Nixpacks-style script deferrals, or libraries to skip.
|
|
4
|
+
*/ /** Preferred package scripts for foreign toolchains (Nixpacks-style). */ export const DEFER_SCRIPT_CANDIDATES = [
|
|
5
|
+
"dev",
|
|
6
|
+
"serve"
|
|
7
|
+
];
|
|
8
|
+
/**
|
|
9
|
+
* Normalize a CLI slice token to a `projects/…` prefix without a trailing slash.
|
|
10
|
+
* `funding` and `projects/funding` both become `projects/funding`.
|
|
11
|
+
*/ export function normalizeSlicePrefix(slice) {
|
|
12
|
+
const trimmed = slice.replaceAll("\\", "/").replace(/\/+$/, "");
|
|
13
|
+
if (trimmed === "" || trimmed === ".") {
|
|
14
|
+
throw new Error("Slice directory must be a non-empty path");
|
|
15
|
+
}
|
|
16
|
+
if (trimmed === "projects" || trimmed.startsWith("projects/")) {
|
|
17
|
+
return trimmed;
|
|
18
|
+
}
|
|
19
|
+
return `projects/${trimmed}`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* True when `projectDirectory` belongs to the slice token.
|
|
23
|
+
*
|
|
24
|
+
* Matches:
|
|
25
|
+
* - nested: `projects/funding`, `projects/funding/api`
|
|
26
|
+
* - flat dotted package dirs: `projects/funding.web` for token `funding`
|
|
27
|
+
*
|
|
28
|
+
* Does not match siblings that only share a string prefix (`funding` vs `funding-fee.api`).
|
|
29
|
+
*/ export function isUnderSlice(projectDirectory, slicePrefix) {
|
|
30
|
+
const dir = projectDirectory.replaceAll("\\", "/").replace(/\/+$/, "");
|
|
31
|
+
const prefix = slicePrefix.replaceAll("\\", "/").replace(/\/+$/, "");
|
|
32
|
+
if (dir === prefix || dir.startsWith(`${prefix}/`)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
// Flat monorepo packages: projects/<module>.<role>
|
|
36
|
+
return dir.startsWith(`${prefix}.`);
|
|
37
|
+
}
|
|
38
|
+
export function projectsInSlice(projects, slice) {
|
|
39
|
+
const prefix = normalizeSlicePrefix(slice);
|
|
40
|
+
return projects.filter((p)=>isUnderSlice(p.projectDirectory, prefix));
|
|
41
|
+
}
|
|
42
|
+
/** Union of packages under any of the slice tokens (deduped by package name). */ export function projectsInSlices(projects, slices) {
|
|
43
|
+
const byName = new Map();
|
|
44
|
+
for (const slice of slices){
|
|
45
|
+
for (const project of projectsInSlice(projects, slice)){
|
|
46
|
+
byName.set(project.name, project);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return [
|
|
50
|
+
...byName.values()
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
/** Script invokes Flux (in-process serve stays on Flux, not deferred). */ export function isFluxOwnedScript(script) {
|
|
54
|
+
return /\bflux\b/i.test(script);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* First Nixpacks-style serve script that is not Flux-owned.
|
|
58
|
+
* Prefers `dev`, then `serve`.
|
|
59
|
+
*/ export function resolveDeferScript(scripts) {
|
|
60
|
+
for (const name of DEFER_SCRIPT_CANDIDATES){
|
|
61
|
+
const body = scripts[name];
|
|
62
|
+
if (body != null && body !== "" && !isFluxOwnedScript(body)) {
|
|
63
|
+
return name;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
/** Convention: Flux Node apps use `main` ending in `main.ts` / `main.tsx`. */ export function isFluxAppMain(main) {
|
|
69
|
+
const normalized = main.replaceAll("\\", "/");
|
|
70
|
+
return /(^|\/)main\.tsx?$/.test(normalized);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Classify one package. Foreign serve scripts win over `main.ts` (Vite apps
|
|
74
|
+
* often have a main entry but must not be HMR-booted by Flux).
|
|
75
|
+
*/ export function classifySliceProject(project) {
|
|
76
|
+
if (resolveDeferScript(project.scripts) != null) {
|
|
77
|
+
return "defer";
|
|
78
|
+
}
|
|
79
|
+
if (isFluxAppMain(project.main)) {
|
|
80
|
+
return "flux";
|
|
81
|
+
}
|
|
82
|
+
return "skip";
|
|
83
|
+
}
|
|
84
|
+
export function classifySliceProjects(projects, slices) {
|
|
85
|
+
const tokens = typeof slices === "string" ? [
|
|
86
|
+
slices
|
|
87
|
+
] : [
|
|
88
|
+
...slices
|
|
89
|
+
];
|
|
90
|
+
const inSlice = projectsInSlices(projects, tokens);
|
|
91
|
+
const flux = [];
|
|
92
|
+
const defer = [];
|
|
93
|
+
const skip = [];
|
|
94
|
+
for (const project of inSlice){
|
|
95
|
+
const kind = classifySliceProject(project);
|
|
96
|
+
if (kind === "flux") flux.push(project);
|
|
97
|
+
else if (kind === "defer") defer.push(project);
|
|
98
|
+
else skip.push(project);
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
flux,
|
|
102
|
+
defer,
|
|
103
|
+
skip
|
|
104
|
+
};
|
|
105
|
+
}
|