@decohere/workspace 0.0.1-dev.20261110.278 → 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 CHANGED
@@ -49,6 +49,10 @@ export default {
49
49
 
50
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)).
51
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
+
52
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).
53
57
 
54
58
  ### Package aliases
@@ -57,7 +61,7 @@ For each discovered project, the workspace package maps `package.json` `name` to
57
61
 
58
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/`.
59
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.
60
- - **Any other subpath (`name/*`):** `src/<sub>.ts` (or `.tsx`, `.mts` for `.mjs`, `.cts` for `.cjs`), else `src/<sub>/index.ts`. A package with only subpaths and no root entry resolves them under `src/`.
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/`.
61
65
 
62
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`.
63
67
 
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 `<sub>.ts` for the caller to report missing.
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
- return [
86
+ const found = [
86
87
  ...files,
87
88
  ...indexes
88
- ].find((file)=>existsSync(file)) ?? toTsSourcePath(candidate);
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.20261110.278",
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.20261110.278",
36
- "@decohere/crucible": "0.0.1-dev.20261110.278",
37
- "@decohere/devkit": "0.0.1-dev.20261110.278",
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
  },
@@ -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
- watch(configuration: string): Promise<void>;
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>;