@decohere/forge 0.0.1-dev.111 → 0.0.1-dev.113

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.
Files changed (59) hide show
  1. package/README.md +2 -0
  2. package/commonjs/src/actions/index.js +1 -0
  3. package/commonjs/src/actions/paths.action.js +109 -0
  4. package/commonjs/src/commands/index.js +1 -0
  5. package/commonjs/src/commands/paths.command.js +24 -0
  6. package/commonjs/src/extensions/project.extensions.js +1 -1
  7. package/commonjs/src/factories/swc-config.factory.js +10 -1
  8. package/commonjs/src/forge.module.js +2 -0
  9. package/commonjs/src/index.js +4 -0
  10. package/commonjs/src/packaging/release-exports.js +4 -2
  11. package/commonjs/src/services/file-writer.service.js +0 -7
  12. package/commonjs/src/services/incremental-watch.js +24 -0
  13. package/commonjs/src/services/output-cache.js +39 -0
  14. package/commonjs/src/services/swc-transpiler.js +42 -113
  15. package/commonjs/src/services/transpile-cache.js +44 -0
  16. package/commonjs/src/services/type-emitter.js +13 -6
  17. package/commonjs/src/types/transform-response.model.js +3 -16
  18. package/commonjs/src/vitest/forge-build.plugin.js +25 -40
  19. package/es6/src/actions/index.js +1 -0
  20. package/es6/src/actions/paths.action.js +86 -0
  21. package/es6/src/commands/index.js +1 -0
  22. package/es6/src/commands/paths.command.js +14 -0
  23. package/es6/src/extensions/project.extensions.js +1 -1
  24. package/es6/src/factories/swc-config.factory.js +10 -1
  25. package/es6/src/forge.module.js +2 -0
  26. package/es6/src/index.js +1 -0
  27. package/es6/src/packaging/release-exports.js +4 -2
  28. package/es6/src/services/file-writer.service.js +0 -7
  29. package/es6/src/services/incremental-watch.js +18 -0
  30. package/es6/src/services/output-cache.js +29 -0
  31. package/es6/src/services/swc-transpiler.js +42 -113
  32. package/es6/src/services/transpile-cache.js +29 -0
  33. package/es6/src/services/type-emitter.js +13 -6
  34. package/es6/src/types/transform-response.model.js +0 -5
  35. package/es6/src/vitest/forge-build.plugin.js +26 -41
  36. package/package.json +5 -5
  37. package/types/src/actions/index.d.ts +1 -0
  38. package/types/src/actions/paths.action.d.ts +28 -0
  39. package/types/src/commands/index.d.ts +1 -0
  40. package/types/src/commands/paths.command.d.ts +6 -0
  41. package/types/src/factories/swc-config.factory.d.ts +1 -1
  42. package/types/src/forge.module.d.ts +2 -0
  43. package/types/src/index.d.ts +1 -0
  44. package/types/src/packaging/release-exports.d.ts +2 -2
  45. package/types/src/services/file-writer.service.d.ts +0 -1
  46. package/types/src/services/incremental-watch.d.ts +13 -0
  47. package/types/src/services/output-cache.d.ts +10 -0
  48. package/types/src/services/swc-transpiler.d.ts +14 -20
  49. package/types/src/services/transpile-cache.d.ts +17 -0
  50. package/types/src/services/type-emitter.d.ts +6 -7
  51. package/types/src/types/transform-response.model.d.ts +0 -5
  52. package/types/src/types/transformer.type.d.ts +0 -9
  53. package/types/src/vitest/forge-build.plugin.d.ts +0 -2
  54. package/commonjs/src/mixins/caches-outputs.mixin.js +0 -42
  55. package/commonjs/src/mixins/incremental-transform.mixin.js +0 -34
  56. package/es6/src/mixins/caches-outputs.mixin.js +0 -32
  57. package/es6/src/mixins/incremental-transform.mixin.js +0 -24
  58. package/types/src/mixins/caches-outputs.mixin.d.ts +0 -7
  59. package/types/src/mixins/incremental-transform.mixin.d.ts +0 -13
@@ -1,10 +1,9 @@
1
- import type { Project, ProjectFileEvent, Tsconfig, Workspace } from "@decohere/mesh";
1
+ import { type Project, type Tsconfig, type Workspace } from "@decohere/mesh";
2
2
  import type { FileEx } from "@decohere/nexus/io";
3
3
  import { type Options } from "@swc/core";
4
+ import type { Observable } from "rxjs";
4
5
  import { type BuildTarget, type TranspileTarget } from "../types/build-target.type.js";
5
6
  import "../extensions/project.extensions.js";
6
- import { CachesOutputs } from "../mixins/caches-outputs.mixin.js";
7
- import { IncrementalTransform } from "../mixins/incremental-transform.mixin.js";
8
7
  import type { SwcConfig } from "../types/swc-config.type.js";
9
8
  import { TransformResponse } from "../types/transform-response.model.js";
10
9
  import type { Transformer } from "../types/transformer.type.js";
@@ -16,38 +15,33 @@ export type TranspileOptions = {
16
15
  workspace?: Workspace;
17
16
  projects?: readonly Project[];
18
17
  };
19
- declare const SwcTranspiler_base: abstract new (...args: unknown[]) => CachesOutputs & IncrementalTransform;
20
- export declare class SwcTranspiler extends SwcTranspiler_base implements Transformer {
18
+ export declare class SwcTranspiler implements Transformer {
21
19
  #private;
22
20
  buildTargets: BuildTarget[];
21
+ get incrementalTransform$(): Observable<TransformResponse[]>;
23
22
  watch(workspace: Workspace): void;
24
23
  private withAliasContext;
25
24
  transformProject(projectArrayLike: Project | Project[], fileFilter?: (project: Project) => Promise<FileEx[]>, onOutput?: (response: TransformResponse) => void): Promise<TransformResponse[]>;
26
- transformFile(fileArrayLike: FileEx[] | FileEx, buildTarget: TranspileTarget, options?: TranspileOptions): Promise<TransformResponse[]>;
27
25
  /**
28
26
  * The SWC options for one project and target, without a filename. Building them reads the
29
27
  * workspace's aliases and merges configs, so a caller that transpiles many files builds them
30
- * once and passes them to {@link transformFileSync}.
28
+ * once and passes them to {@link transformCode}.
31
29
  */
32
30
  createBaseConfig(buildTarget: TranspileTarget, options?: TranspileOptions): Options;
31
+ /** Sync variant of {@link transformCode}, for the load hook, which cannot await (#514). */
32
+ transformCodeSync(content: string, file: FileEx, buildTarget: TranspileTarget, baseConfig: Options): TransformResponse;
33
33
  /**
34
- * Synchronous, single-file variant of `transformFile`.
35
- * Reads the file with `fs.readFileSync` and transpiles via `swc.transformSync`.
36
- * Intended for callers that cannot await (e.g. Node.js `registerHooks` load hook).
37
- * Pass `baseConfig` from {@link createBaseConfig} to skip rebuilding it for every file.
34
+ * Compiles `content` as the source of `file`, without reading the file: for callers that
35
+ * already hold the code, such as the Vitest plugin, which must compile what Vite passes it
36
+ * rather than an earlier read of the disk (#517). Async SWC, on the thread pool, so many
37
+ * calls in flight compile in parallel (#661). With a `project`, the response carries where
38
+ * the build writes the output.
38
39
  */
39
- transformFileSync(file: FileEx, buildTarget: TranspileTarget, options?: TranspileOptions, baseConfig?: Options): TransformResponse;
40
- /**
41
- * Async variant of {@link transformFileSync}, with the same result for the same file. SWC
42
- * runs it on libuv's thread pool, so many calls in flight compile in parallel (#661).
43
- */
44
- transformFileAsync(file: FileEx, buildTarget: TranspileTarget, options?: TranspileOptions, baseConfig?: Options): Promise<TransformResponse>;
40
+ transformCode(content: string, file: FileEx, buildTarget: TranspileTarget, baseConfig: Options, project?: Project): Promise<TransformResponse>;
45
41
  private static skippedEmpty;
46
42
  private static succeeded;
47
43
  private transformTarget;
48
- private runTransform;
49
- protected onIncrementalFileEvent(evt: ProjectFileEvent): Promise<TransformResponse[]>;
44
+ private onIncrementalFileEvent;
50
45
  invalidateContentCache(_file: FileEx): void;
51
46
  private getFileContent;
52
47
  }
53
- export {};
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Where compiled code is cached on disk (#514), or null when caching is off:
3
+ *
4
+ * - `DECOHERE_CACHE=0` turns it off.
5
+ * - `DECOHERE_CACHE_DIR` puts it in that directory.
6
+ * - Otherwise `<root>/node_modules/.cache/decohere`, where tools keep caches, or when the
7
+ * workspace has no `node_modules`, `$XDG_CACHE_HOME/decohere`, then the OS temp directory.
8
+ *
9
+ * Flux keeps its entries in the `flux` folder inside it; `forge clean` removes the folder.
10
+ */
11
+ declare function directory(rootDir: string, env?: NodeJS.ProcessEnv): string | null;
12
+ /** The SWC version compiling: part of every cache key, so upgrading SWC misses. */
13
+ export declare const transpileCache: {
14
+ directory: typeof directory;
15
+ swcVersion: string;
16
+ };
17
+ export {};
@@ -1,9 +1,8 @@
1
- import type { Project, ProjectFileEvent } from "@decohere/mesh";
1
+ import type { Project, Workspace } from "@decohere/mesh";
2
2
  import type { FileEx } from "@decohere/nexus/io";
3
+ import type { Observable } from "rxjs";
3
4
  import type ts from "typescript";
4
5
  import "../extensions/project.extensions.js";
5
- import { CachesOutputs } from "../mixins/caches-outputs.mixin.js";
6
- import { IncrementalTransform } from "../mixins/incremental-transform.mixin.js";
7
6
  import { type BuildTarget } from "../types/build-target.type.js";
8
7
  import type { TransformResponse } from "../types/transform-response.model.js";
9
8
  import type { Transformer } from "../types/transformer.type.js";
@@ -31,10 +30,11 @@ export type PrepareProgramsOptions = {
31
30
  includeAllProjects?: boolean;
32
31
  requiredCompilerOptions?: ts.CompilerOptions;
33
32
  };
34
- declare const TypeEmitter_base: abstract new (...args: unknown[]) => CachesOutputs & IncrementalTransform;
35
- export declare class TypeEmitter extends TypeEmitter_base implements Transformer {
33
+ export declare class TypeEmitter implements Transformer {
36
34
  #private;
37
35
  buildTargets: BuildTarget[];
36
+ get incrementalTransform$(): Observable<TransformResponse[]>;
37
+ watch(workspace: Workspace): void;
38
38
  /**
39
39
  * Phase 1: fetch files, create TypeScript programs sequentially.
40
40
  * Called before transformProject() so that the heavy createProgram work
@@ -51,7 +51,6 @@ export declare class TypeEmitter extends TypeEmitter_base implements Transformer
51
51
  formatted: string;
52
52
  }>;
53
53
  private preparePrograms;
54
- protected onIncrementalFileEvent(evt: ProjectFileEvent): Promise<TransformResponse[]>;
54
+ private onIncrementalFileEvent;
55
55
  private invalidateReadFileCache;
56
56
  }
57
- export {};
@@ -2,11 +2,6 @@ import type { Project } from "@decohere/mesh";
2
2
  import type { File } from "@decohere/nexus/io";
3
3
  import type { BuildTarget } from "./build-target.type.js";
4
4
  export type TransformOutcome = "success" | "failure" | "skipped";
5
- export declare const TransformOutcomes: {
6
- success: "success";
7
- failure: "failure";
8
- skipped: "skipped";
9
- };
10
5
  type TransformResponseBase = {
11
6
  file: File;
12
7
  config: unknown;
@@ -3,15 +3,6 @@ import type { FileEx } from "@decohere/nexus/io";
3
3
  import type { Observable } from "rxjs";
4
4
  import type { BuildTarget } from "../types/build-target.type.js";
5
5
  import type { TransformResponse } from "./transform-response.model.js";
6
- export type FileEvent = {
7
- type: "changed" | "added";
8
- file: FileEx;
9
- project?: Project;
10
- } | {
11
- type: "deleted";
12
- file: FileEx;
13
- project: Project;
14
- };
15
6
  export declare const TransformerKey: unique symbol;
16
7
  export interface Transformer {
17
8
  readonly buildTargets: BuildTarget[];
@@ -2,8 +2,6 @@ export type ForgeBuildOptions = {
2
2
  buildConfig?: string;
3
3
  logLevel?: string;
4
4
  workspaceRoot?: string;
5
- /** Skip the build pre-warm entirely (e.g. when a pre-built artifact is already on disk). */
6
- skipBuild?: boolean;
7
5
  };
8
6
  export declare function forgeBuild(options?: ForgeBuildOptions): {
9
7
  name: string;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "CachesOutputs", {
6
- enumerable: true,
7
- get: function() {
8
- return CachesOutputs;
9
- }
10
- });
11
- const _io = require("@decohere/nexus/io");
12
- class CachesOutputs {
13
- /** Maps source file fullPath -> output TransformResponses for cleanup in watch mode. */ get outputCache() {
14
- const self = this;
15
- if (self.__outputCache == null) {
16
- self.__outputCache = new Map();
17
- }
18
- return self.__outputCache;
19
- }
20
- cacheOutputs(responses) {
21
- const byFile = new Map();
22
- for (const response of responses){
23
- if (response.outcome !== "success") continue;
24
- const group = byFile.get(response.file.fullPath) ?? [];
25
- group.push(response);
26
- byFile.set(response.file.fullPath, group);
27
- }
28
- for (const [fullPath, group] of byFile){
29
- this.outputCache.set(fullPath, group);
30
- }
31
- }
32
- deleteCachedOutputs(filePath) {
33
- const outputs = this.outputCache.get(filePath);
34
- if (outputs == null) return;
35
- for (const response of outputs){
36
- if (response.outputPath != null) {
37
- void _io.io.deleteFile(response.outputPath);
38
- }
39
- }
40
- this.outputCache.delete(filePath);
41
- }
42
- }
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "IncrementalTransform", {
6
- enumerable: true,
7
- get: function() {
8
- return IncrementalTransform;
9
- }
10
- });
11
- const _rxjs = require("rxjs");
12
- // WeakMap avoids the private-field-in-mixin problem: private class fields (#x)
13
- // are not accessible when methods are copied onto a different class prototype.
14
- const subjects = new WeakMap();
15
- function getSubject(instance) {
16
- let subject = subjects.get(instance);
17
- if (subject == null) {
18
- subject = new _rxjs.Subject();
19
- subjects.set(instance, subject);
20
- }
21
- return subject;
22
- }
23
- class IncrementalTransform {
24
- get incrementalTransform$() {
25
- return getSubject(this).asObservable();
26
- }
27
- watch(workspace) {
28
- workspace.projectFileChanged$.subscribe((evt)=>{
29
- void this.onIncrementalFileEvent(evt).then((responses)=>{
30
- getSubject(this).next(responses);
31
- });
32
- });
33
- }
34
- }
@@ -1,32 +0,0 @@
1
- import { io } from "@decohere/nexus/io";
2
- export class CachesOutputs {
3
- /** Maps source file fullPath -> output TransformResponses for cleanup in watch mode. */ get outputCache() {
4
- const self = this;
5
- if (self.__outputCache == null) {
6
- self.__outputCache = new Map();
7
- }
8
- return self.__outputCache;
9
- }
10
- cacheOutputs(responses) {
11
- const byFile = new Map();
12
- for (const response of responses){
13
- if (response.outcome !== "success") continue;
14
- const group = byFile.get(response.file.fullPath) ?? [];
15
- group.push(response);
16
- byFile.set(response.file.fullPath, group);
17
- }
18
- for (const [fullPath, group] of byFile){
19
- this.outputCache.set(fullPath, group);
20
- }
21
- }
22
- deleteCachedOutputs(filePath) {
23
- const outputs = this.outputCache.get(filePath);
24
- if (outputs == null) return;
25
- for (const response of outputs){
26
- if (response.outputPath != null) {
27
- void io.deleteFile(response.outputPath);
28
- }
29
- }
30
- this.outputCache.delete(filePath);
31
- }
32
- }
@@ -1,24 +0,0 @@
1
- import { Subject } from "rxjs";
2
- // WeakMap avoids the private-field-in-mixin problem: private class fields (#x)
3
- // are not accessible when methods are copied onto a different class prototype.
4
- const subjects = new WeakMap();
5
- function getSubject(instance) {
6
- let subject = subjects.get(instance);
7
- if (subject == null) {
8
- subject = new Subject();
9
- subjects.set(instance, subject);
10
- }
11
- return subject;
12
- }
13
- export class IncrementalTransform {
14
- get incrementalTransform$() {
15
- return getSubject(this).asObservable();
16
- }
17
- watch(workspace) {
18
- workspace.projectFileChanged$.subscribe((evt)=>{
19
- void this.onIncrementalFileEvent(evt).then((responses)=>{
20
- getSubject(this).next(responses);
21
- });
22
- });
23
- }
24
- }
@@ -1,7 +0,0 @@
1
- import type { TransformResponse } from "../types/transform-response.model.js";
2
- export declare abstract class CachesOutputs {
3
- /** Maps source file fullPath -> output TransformResponses for cleanup in watch mode. */
4
- protected get outputCache(): Map<string, TransformResponse[]>;
5
- protected cacheOutputs(responses: TransformResponse[]): void;
6
- protected deleteCachedOutputs(filePath: string): void;
7
- }
@@ -1,13 +0,0 @@
1
- import type { ProjectFileEvent, Workspace } from "@decohere/mesh";
2
- import type { Observable } from "rxjs";
3
- import type { TransformResponse } from "../types/transform-response.model.js";
4
- export declare abstract class IncrementalTransform {
5
- get incrementalTransform$(): Observable<TransformResponse[]>;
6
- watch(workspace: Workspace): void;
7
- /**
8
- * Called for every workspace file change. Implementations should invalidate
9
- * any internal caches, perform the incremental transform, and return the results.
10
- * Return an empty array for deletions or when no output is produced.
11
- */
12
- protected abstract onIncrementalFileEvent(evt: ProjectFileEvent): Promise<TransformResponse[]>;
13
- }