@decohere/workspace 0.0.1-dev.20261108.265 → 0.0.1-dev.20261110.284
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 +13 -2
- package/es6/src/factories/workspace.factory.js +24 -5
- package/es6/src/index.js +1 -0
- package/es6/src/models/package-aliases.js +8 -4
- package/es6/src/models/project-scripts.js +14 -0
- package/es6/src/models/project.model.js +7 -0
- package/es6/src/models/workspace.model.js +2 -2
- package/package.json +4 -4
- package/types/src/factories/workspace.factory.d.ts +6 -1
- package/types/src/index.d.ts +1 -0
- package/types/src/models/project-scripts.d.ts +11 -0
- package/types/src/models/project.model.d.ts +5 -0
- package/types/src/models/workspace.model.d.ts +2 -1
package/README.md
CHANGED
|
@@ -33,7 +33,12 @@ Packages do **not** have to live under `projects/` — that is only the default
|
|
|
33
33
|
|
|
34
34
|
### Optional `.decohere.js`
|
|
35
35
|
|
|
36
|
-
If the file is missing, the workspace package uses the defaults above. Arrays in
|
|
36
|
+
If the file is missing, the workspace package uses the defaults above. The file overrides the defaults, including a tool's own (forge's `configurations` and `copyFiles`). Arrays in it **replace** the defaults, except `ignoreProjects` and `ignore`, which **add** to them: list only what you leave out.
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
// Keep a Pulumi program under projects/ out of forge and flux. node_modules, __fixtures__ and dist stay ignored.
|
|
40
|
+
export default { ignoreProjects: ["projects/infra/**"] };
|
|
41
|
+
```
|
|
37
42
|
|
|
38
43
|
```js
|
|
39
44
|
/** @type {import("@decohere/workspace").WorkspaceOptions} */
|
|
@@ -44,6 +49,10 @@ export default {
|
|
|
44
49
|
|
|
45
50
|
Per-project settings go under `projects`, keyed by package name: `docker` (image, Dockerfile, tags, build args) and `ui` (the UI project a deployable ships, see [forge](../forge/README.md#shipping-the-ui-with-the-api)).
|
|
46
51
|
|
|
52
|
+
### A project's own scripts
|
|
53
|
+
|
|
54
|
+
A project whose `package.json` declares a script for a step has a builder of its own (Astro, Vite, Angular), and Decohere's tools run that script in its folder instead of doing the step: `build` for `forge build`, `dev` or `serve` for `flux serve`. `Project.ownScript(name)` (and `projectScripts.own(scripts, name)`) is that rule, in one place. A script that calls `forge`, `flux` or `decohere` doesn't count: running it would only call the tool again. See [forge](../forge/README.md#projects-with-a-builder-of-their-own).
|
|
55
|
+
|
|
47
56
|
`--config-file` on `forge` / `flux` selects a different config path. The default is `.decohere.js` in the workspace root (`--root-dir`, else the current folder).
|
|
48
57
|
|
|
49
58
|
### Package aliases
|
|
@@ -52,7 +61,7 @@ For each discovered project, the workspace package maps `package.json` `name` to
|
|
|
52
61
|
|
|
53
62
|
- **The entry:** a TypeScript `main` as written (default `src/index.ts`). A `main` or `exports["."]` that describes the published layout (`index.js`, `./es6/src/index.js`) maps back to the source under `src/`.
|
|
54
63
|
- **Each subpath in `exports`:** `./auth` → `./es6/src/auth/auth.extensions.js` becomes `src/auth/auth.extensions.ts`. Entries whose source doesn't exist are left out.
|
|
55
|
-
- **Any other subpath (`name/*`):** `src/<sub>.ts` (or `.tsx`, `.mts` for `.mjs`, `.cts` for `.cjs`), else `src/<sub>/index.ts
|
|
64
|
+
- **Any other subpath (`name/*`):** `src/<sub>.ts` (or `.tsx`, `.mts` for `.mjs`, `.cts` for `.cjs`), else `src/<sub>/index.ts`, else `src/<sub>` itself when it is a file (a UI package's `Button.astro` or `theme.css`). A package with only subpaths and no root entry resolves them under `src/`.
|
|
56
65
|
|
|
57
66
|
Root `tsconfig.json` `paths` override the same keys. In this repo they come from `forge paths`, which writes this map to `tsconfig.paths.json` for `tsc`.
|
|
58
67
|
|
|
@@ -82,4 +91,6 @@ const projects = workspace.getProjects("debug");
|
|
|
82
91
|
const aliases = workspace.getPackageAliases("debug");
|
|
83
92
|
```
|
|
84
93
|
|
|
94
|
+
A tool with defaults of its own passes them as the second argument, `WorkspaceFactory.create(options, defaults)`, so `.decohere.js` can override them. Anything in `options` overrides the user's file.
|
|
95
|
+
|
|
85
96
|
Pass a pre-built `workspace` into Forge/Flux in tests to skip filesystem discovery.
|
|
@@ -6,9 +6,17 @@ import { PackageJson } from "../models/package-json.model.js";
|
|
|
6
6
|
import { Workspace } from "../models/workspace.model.js";
|
|
7
7
|
import { UserConfigFactory } from "./config.factory.js";
|
|
8
8
|
import { ProjectFactory } from "./project.factory.js";
|
|
9
|
+
/** Patterns that leave things out: a user's list adds to the defaults', so they needn't restate them. */ const ADDITIVE = [
|
|
10
|
+
"ignoreProjects",
|
|
11
|
+
"ignore"
|
|
12
|
+
];
|
|
9
13
|
class Factory {
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The workspace from `defaults`, then the user's `.decohere.js`, then `options`, each over the
|
|
16
|
+
* one before. A tool passes its own defaults here, not in `options`, so the user's file can
|
|
17
|
+
* change them. Arrays replace the ones before them, except the ignore lists, which add up.
|
|
18
|
+
*/ async create(options = {}, defaults = WorkspaceDefaults) {
|
|
19
|
+
const config = await this.getMergedConfig(options, defaults);
|
|
12
20
|
const projectSeeds = await ProjectFactory.getProjectSeeds(config);
|
|
13
21
|
const packageJson = await this.getPackageJson(config.rootDir ?? "./");
|
|
14
22
|
const workspace = new Workspace({
|
|
@@ -18,12 +26,23 @@ class Factory {
|
|
|
18
26
|
});
|
|
19
27
|
return workspace;
|
|
20
28
|
}
|
|
21
|
-
async getMergedConfig(options) {
|
|
29
|
+
async getMergedConfig(options, defaults) {
|
|
22
30
|
const { configFile, ...rest } = options;
|
|
23
31
|
const userConfig = await UserConfigFactory.getUserConfig(configFile);
|
|
24
|
-
|
|
32
|
+
const config = merge.withOptions({
|
|
25
33
|
mergeArrays: false
|
|
26
|
-
},
|
|
34
|
+
}, defaults, userConfig, rest);
|
|
35
|
+
for (const key of ADDITIVE){
|
|
36
|
+
const layers = [
|
|
37
|
+
defaults[key],
|
|
38
|
+
userConfig[key],
|
|
39
|
+
rest[key]
|
|
40
|
+
];
|
|
41
|
+
config[key] = [
|
|
42
|
+
...new Set(layers.flatMap((patterns)=>patterns ?? []))
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
return config;
|
|
27
46
|
}
|
|
28
47
|
async getPackageJson(rootDir) {
|
|
29
48
|
const packageJsonPath = path.join(rootDir, PACKAGE_JSON);
|
package/es6/src/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { HasTsConfig } from "./models/has-tsconfig.mixin.js";
|
|
|
8
8
|
export { packageAliases } from "./models/package-aliases.js";
|
|
9
9
|
export { PackageJson } from "./models/package-json.model.js";
|
|
10
10
|
export { Project } from "./models/project.model.js";
|
|
11
|
+
export { projectScripts } from "./models/project-scripts.js";
|
|
11
12
|
export { sourceExtensions } from "./models/source-extensions.js";
|
|
12
13
|
export { DEFAULT_COMPILER_OPTIONS, Tsconfig } from "./models/tsconfig.model.js";
|
|
13
14
|
export { Workspace } from "./models/workspace.model.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
1
|
+
import { existsSync, statSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { sourceExtensions } from "./source-extensions.js";
|
|
4
4
|
/**
|
|
@@ -77,15 +77,19 @@ function toPosixRelative(from, to) {
|
|
|
77
77
|
/**
|
|
78
78
|
* The source file a wildcard subpath names: `<sub>` with a source extension (`.ts`, `.tsx`, or
|
|
79
79
|
* `.mts`/`.cts` for `.mjs`/`.cjs`), else the `index` source of the directory it names (as
|
|
80
|
-
* `@pkg/models` is `src/models/index.ts`), else
|
|
80
|
+
* `@pkg/models` is `src/models/index.ts`), else the file as written when it is one (a UI
|
|
81
|
+
* package's `Button.astro` or `theme.css`), else `<sub>.ts` for the caller to report missing.
|
|
81
82
|
*/ function subpathSource(candidate) {
|
|
82
83
|
const files = sourceExtensions.candidates(candidate);
|
|
83
84
|
const directory = candidate.replace(/\.([mc]?[jt]sx?)$/, "");
|
|
84
85
|
const indexes = sourceExtensions.candidates(path.join(directory, "index"));
|
|
85
|
-
|
|
86
|
+
const found = [
|
|
86
87
|
...files,
|
|
87
88
|
...indexes
|
|
88
|
-
].find((file)=>existsSync(file))
|
|
89
|
+
].find((file)=>existsSync(file));
|
|
90
|
+
if (found != null) return found;
|
|
91
|
+
if (existsSync(candidate) && statSync(candidate).isFile()) return candidate;
|
|
92
|
+
return toTsSourcePath(candidate);
|
|
89
93
|
}
|
|
90
94
|
/** A target as a source path: itself when it is one, else its first source candidate. */ function toTsSourcePath(candidate) {
|
|
91
95
|
return sourceExtensions.candidates(candidate)[0] ?? `${candidate}.ts`;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** A script that runs a Decohere tool hands the step back to Decohere, so it isn't the project's own. */ const DECOHERE_TOOL = /\b(forge|flux|decohere)\b/i;
|
|
2
|
+
/**
|
|
3
|
+
* The command of a project's own script for a step (`build`, `check`, `dev`), or `undefined`.
|
|
4
|
+
* A project that declares one has a builder of its own (Astro, Vite, Angular), and Decohere's
|
|
5
|
+
* tools run that script in its folder instead of doing the step themselves. A script that calls
|
|
6
|
+
* `forge`, `flux` or `decohere` doesn't count: running it would only call the tool again.
|
|
7
|
+
*/ function own(scripts, name) {
|
|
8
|
+
const command = scripts?.[name];
|
|
9
|
+
if (command == null || command.trim() === "" || DECOHERE_TOOL.test(command)) return undefined;
|
|
10
|
+
return command;
|
|
11
|
+
}
|
|
12
|
+
export const projectScripts = {
|
|
13
|
+
own
|
|
14
|
+
};
|
|
@@ -18,6 +18,7 @@ import { WorkspaceConfigurationError } from "../errors.js";
|
|
|
18
18
|
import { HasPackageJson } from "./has-package-json.mixin.js";
|
|
19
19
|
import { HasTsConfig } from "./has-tsconfig.mixin.js";
|
|
20
20
|
import { PackageJson } from "./package-json.model.js";
|
|
21
|
+
import { projectScripts } from "./project-scripts.js";
|
|
21
22
|
import { sourceExtensions } from "./source-extensions.js";
|
|
22
23
|
export class Project extends mixwith(HasPackageJson, HasTsConfig) {
|
|
23
24
|
packageJson;
|
|
@@ -40,6 +41,12 @@ export class Project extends mixwith(HasPackageJson, HasTsConfig) {
|
|
|
40
41
|
get name() {
|
|
41
42
|
return this.#name;
|
|
42
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* The command of this project's own script for a step, when it has one that doesn't call a
|
|
46
|
+
* Decohere tool: forge and flux run it in the project's folder instead of doing the step.
|
|
47
|
+
*/ ownScript(name) {
|
|
48
|
+
return projectScripts.own(this.packageJson?.scripts, name);
|
|
49
|
+
}
|
|
43
50
|
get isPrivate() {
|
|
44
51
|
return this.packageJson?.private === true;
|
|
45
52
|
}
|
|
@@ -86,9 +86,9 @@ export class Workspace extends mixwith(HasPackageJson, HasTsConfig) {
|
|
|
86
86
|
tsconfigPaths: tsconfig?.compilerOptions?.paths
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
async watch(configuration) {
|
|
89
|
+
/** Watch the projects' source files; `include` limits it to some of them. */ async watch(configuration, include = ()=>true) {
|
|
90
90
|
this.stopWatching();
|
|
91
|
-
const projects = this.getProjects(configuration);
|
|
91
|
+
const projects = this.getProjects(configuration).filter(include);
|
|
92
92
|
this.#watchedProjects = projects;
|
|
93
93
|
for (const project of projects){
|
|
94
94
|
await project.watch(configuration);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decohere/workspace",
|
|
3
|
-
"version": "0.0.1-dev.
|
|
3
|
+
"version": "0.0.1-dev.20261110.284",
|
|
4
4
|
"description": "Workspace and project model primitives for monorepo tooling",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@decohere/core": "0.0.1-dev.
|
|
36
|
-
"@decohere/crucible": "0.0.1-dev.
|
|
37
|
-
"@decohere/devkit": "0.0.1-dev.
|
|
35
|
+
"@decohere/core": "0.0.1-dev.20261110.284",
|
|
36
|
+
"@decohere/crucible": "0.0.1-dev.20261110.284",
|
|
37
|
+
"@decohere/devkit": "0.0.1-dev.20261110.284",
|
|
38
38
|
"get-tsconfig": "^4.14.3",
|
|
39
39
|
"picomatch": "^4.0.4"
|
|
40
40
|
},
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Workspace } from "../models/workspace.model.js";
|
|
2
2
|
import type { WorkspaceFactoryOptions, WorkspaceOptions } from "../models/workspace-config.type.js";
|
|
3
3
|
declare class Factory {
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The workspace from `defaults`, then the user's `.decohere.js`, then `options`, each over the
|
|
6
|
+
* one before. A tool passes its own defaults here, not in `options`, so the user's file can
|
|
7
|
+
* change them. Arrays replace the ones before them, except the ignore lists, which add up.
|
|
8
|
+
*/
|
|
9
|
+
create(options?: WorkspaceFactoryOptions & Partial<WorkspaceOptions>, defaults?: WorkspaceOptions): Promise<Workspace>;
|
|
5
10
|
private getMergedConfig;
|
|
6
11
|
private getPackageJson;
|
|
7
12
|
}
|
package/types/src/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type { PackageExports, RepositoryReference } from "./models/package-json.
|
|
|
10
10
|
export { PackageJson } from "./models/package-json.model.js";
|
|
11
11
|
export type { ProjectConfig, ProjectSeed } from "./models/project.model.js";
|
|
12
12
|
export { Project } from "./models/project.model.js";
|
|
13
|
+
export { projectScripts } from "./models/project-scripts.js";
|
|
13
14
|
export { sourceExtensions } from "./models/source-extensions.js";
|
|
14
15
|
export type { ProjectFileEvent } from "./models/project-file-event.js";
|
|
15
16
|
export type { CompilerOptions } from "./models/tsconfig.model.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The command of a project's own script for a step (`build`, `check`, `dev`), or `undefined`.
|
|
3
|
+
* A project that declares one has a builder of its own (Astro, Vite, Angular), and Decohere's
|
|
4
|
+
* tools run that script in its folder instead of doing the step themselves. A script that calls
|
|
5
|
+
* `forge`, `flux` or `decohere` doesn't count: running it would only call the tool again.
|
|
6
|
+
*/
|
|
7
|
+
declare function own(scripts: Readonly<Record<string, string>> | undefined, name: string): string | undefined;
|
|
8
|
+
export declare const projectScripts: {
|
|
9
|
+
own: typeof own;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -18,6 +18,11 @@ export declare class Project extends Project_base {
|
|
|
18
18
|
protected packageJson?: PackageJson;
|
|
19
19
|
constructor(name: string, config?: ProjectConfig, selectedConfigurationName?: string);
|
|
20
20
|
get name(): string;
|
|
21
|
+
/**
|
|
22
|
+
* The command of this project's own script for a step, when it has one that doesn't call a
|
|
23
|
+
* Decohere tool: forge and flux run it in the project's folder instead of doing the step.
|
|
24
|
+
*/
|
|
25
|
+
ownScript(name: string): string | undefined;
|
|
21
26
|
get isPrivate(): boolean;
|
|
22
27
|
toString(): string;
|
|
23
28
|
get projectDirectory(): string;
|
|
@@ -34,7 +34,8 @@ export declare class Workspace extends Workspace_base {
|
|
|
34
34
|
* instead of assembling the map themselves.
|
|
35
35
|
*/
|
|
36
36
|
getPackageAliases(configuration: string): PackageAliases;
|
|
37
|
-
|
|
37
|
+
/** Watch the projects' source files; `include` limits it to some of them. */
|
|
38
|
+
watch(configuration: string, include?: (project: Project) => boolean): Promise<void>;
|
|
38
39
|
stopWatching(): void;
|
|
39
40
|
[Symbol.dispose](): void;
|
|
40
41
|
get projectFileChanged$(): import("@decohere/core/system").Observable<ProjectFileEvent>;
|