orchajs 0.19.0 → 0.20.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 CHANGED
@@ -763,10 +763,41 @@ they need every judge result to finish and persist.
763
763
 
764
764
  ### Production and Serverless builds
765
765
 
766
- For esbuild production applications, add `orchaPlugin()` from
767
- `orchajs/esbuild` to the build that bundles the application handlers. It
768
- compiles the registry and replaces exact `orchajs` imports with the
769
- self-contained generated runtime:
766
+ For Serverless Framework projects, install `serverless-esbuild` and register
767
+ the Orcha integration after it:
768
+
769
+ ```bash
770
+ npm install --save-dev serverless-esbuild
771
+ ```
772
+
773
+ ```yaml
774
+ plugins:
775
+ - serverless-esbuild
776
+ - orchajs/serverless
777
+ ```
778
+
779
+ Serverless Framework v4 users must opt out of its built-in builder before
780
+ loading `serverless-esbuild`:
781
+
782
+ ```yaml
783
+ build:
784
+ esbuild: false
785
+ ```
786
+
787
+ No separate `orcha build` command or deployment script is required. During
788
+ `serverless package` and `serverless deploy`, the integration adds Orcha to the
789
+ existing esbuild pipeline. It preserves other esbuild plugins, compiles the
790
+ registry, and replaces exact `orchajs` imports with the generated production
791
+ runtime. It rejects configurations that externalize `orchajs`, because those
792
+ would copy the full development package into the Lambda artifact.
793
+
794
+ `serverless-plugin-typescript` and plain `tsc` do not bundle dependencies.
795
+ Remove that build plugin when switching the service to `serverless-esbuild`.
796
+ Keep `serverless-esbuild` before `orchajs/serverless` and before
797
+ `serverless-offline`.
798
+
799
+ For non-Serverless esbuild applications, add `orchaPlugin()` from
800
+ `orchajs/esbuild` to the build that bundles the application:
770
801
 
771
802
  ```js
772
803
  const { orchaPlugin } = require("orchajs/esbuild");
@@ -777,11 +808,9 @@ module.exports = {
777
808
  };
778
809
  ```
779
810
 
780
- For Serverless Framework, use `serverless-esbuild` and point
781
- `custom.esbuild.config` at that configuration file. Plain TypeScript,
782
- `serverless-plugin-typescript`, or running `orcha build` separately is not
783
- enough: `orcha build` creates `.orcha/dist/bundle.js`, but it does not rewrite
784
- imports in already-built handlers.
811
+ Running `orcha build` separately is not enough: it creates
812
+ `.orcha/dist/bundle.js`, but does not rewrite imports in already-built
813
+ handlers.
785
814
 
786
815
  Production CI should package the same way as deployment and verify that:
787
816
 
@@ -0,0 +1,27 @@
1
+ import type { Plugin } from "esbuild";
2
+ type ServerlessEsbuildOptions = {
3
+ config?: string;
4
+ exclude?: string[];
5
+ external?: string[];
6
+ plugins?: Plugin[] | string;
7
+ [key: string]: unknown;
8
+ };
9
+ type ServerlessLike = {
10
+ config?: {
11
+ servicePath?: string;
12
+ };
13
+ service: {
14
+ custom?: {
15
+ esbuild?: ServerlessEsbuildOptions;
16
+ [key: string]: unknown;
17
+ };
18
+ plugins?: string[];
19
+ };
20
+ };
21
+ export declare class OrchaServerlessPlugin {
22
+ private readonly serverless;
23
+ readonly hooks: Record<string, () => void>;
24
+ constructor(serverless: ServerlessLike);
25
+ private configureEsbuild;
26
+ }
27
+ export default OrchaServerlessPlugin;
@@ -0,0 +1,78 @@
1
+ import { createRequire } from "node:module";
2
+ import { resolve } from "node:path";
3
+ import { orchaPlugin } from "./esbuild.js";
4
+ export class OrchaServerlessPlugin {
5
+ serverless;
6
+ hooks;
7
+ constructor(serverless) {
8
+ this.serverless = serverless;
9
+ this.hooks = {
10
+ initialize: () => this.configureEsbuild(),
11
+ };
12
+ }
13
+ configureEsbuild() {
14
+ const servicePath = resolve(this.serverless.config?.servicePath ?? process.cwd());
15
+ const configuredPlugins = this.serverless.service.plugins ?? [];
16
+ if (!configuredPlugins.includes("serverless-esbuild")) {
17
+ throw new Error('The "orchajs/serverless" plugin requires "serverless-esbuild". Add "serverless-esbuild" before "orchajs/serverless" in the Serverless plugins list.');
18
+ }
19
+ const custom = this.serverless.service.custom ?? {};
20
+ const configuredEsbuild = custom.esbuild ?? {};
21
+ const esbuild = configuredEsbuild.config
22
+ ? loadEsbuildConfig(configuredEsbuild.config, servicePath, this.serverless)
23
+ : { ...configuredEsbuild };
24
+ assertOrchaIsBundled(esbuild);
25
+ const existingPlugins = loadEsbuildPlugins(esbuild.plugins, servicePath, this.serverless);
26
+ if (!existingPlugins.some((plugin) => plugin.name === "orchajs")) {
27
+ existingPlugins.push(orchaPlugin({ projectRoot: servicePath }));
28
+ }
29
+ delete esbuild.config;
30
+ esbuild.plugins = existingPlugins;
31
+ custom.esbuild = esbuild;
32
+ this.serverless.service.custom = custom;
33
+ }
34
+ }
35
+ function loadEsbuildConfig(configPath, servicePath, serverless) {
36
+ const loaded = loadProjectModule(configPath, servicePath);
37
+ const config = unwrapDefault(loaded);
38
+ if (typeof config !== "function") {
39
+ throw new Error(`Serverless esbuild config "${configPath}" must export a function.`);
40
+ }
41
+ return config(serverless);
42
+ }
43
+ function loadEsbuildPlugins(plugins, servicePath, serverless) {
44
+ if (!plugins) {
45
+ return [];
46
+ }
47
+ if (Array.isArray(plugins)) {
48
+ return [...plugins];
49
+ }
50
+ const loaded = unwrapDefault(loadProjectModule(plugins, servicePath));
51
+ const resolved = typeof loaded === "function"
52
+ ? loaded(serverless)
53
+ : loaded;
54
+ if (!Array.isArray(resolved)) {
55
+ throw new Error(`Serverless esbuild plugins file "${plugins}" must export an array or a function that returns one.`);
56
+ }
57
+ return [...resolved];
58
+ }
59
+ function loadProjectModule(path, servicePath) {
60
+ const requireFromProject = createRequire(resolve(servicePath, "package.json"));
61
+ return requireFromProject(resolve(servicePath, path));
62
+ }
63
+ function unwrapDefault(value) {
64
+ if (typeof value === "object" &&
65
+ value !== null &&
66
+ "default" in value) {
67
+ return value.default;
68
+ }
69
+ return value;
70
+ }
71
+ function assertOrchaIsBundled(options) {
72
+ for (const key of ["exclude", "external"]) {
73
+ if (options[key]?.includes("orchajs")) {
74
+ throw new Error(`Remove "orchajs" from custom.esbuild.${key}. Orcha must be replaced during bundling, not copied into the Lambda package.`);
75
+ }
76
+ }
77
+ }
78
+ export default OrchaServerlessPlugin;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ module.exports = require("./serverless.js").OrchaServerlessPlugin;
@@ -0,0 +1,125 @@
1
+ "use strict"; const __orchaImportMetaUrl = require("url").pathToFileURL(__filename).href;
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var serverless_exports = {};
21
+ __export(serverless_exports, {
22
+ OrchaServerlessPlugin: () => OrchaServerlessPlugin,
23
+ default: () => serverless_default
24
+ });
25
+ module.exports = __toCommonJS(serverless_exports);
26
+ var import_module = require("module");
27
+ var import_path = require("path");
28
+ var import_esbuild = require("./esbuild.js");
29
+ class OrchaServerlessPlugin {
30
+ constructor(serverless) {
31
+ this.serverless = serverless;
32
+ this.hooks = {
33
+ initialize: () => this.configureEsbuild()
34
+ };
35
+ }
36
+ hooks;
37
+ configureEsbuild() {
38
+ const servicePath = (0, import_path.resolve)(
39
+ this.serverless.config?.servicePath ?? process.cwd()
40
+ );
41
+ const configuredPlugins = this.serverless.service.plugins ?? [];
42
+ if (!configuredPlugins.includes("serverless-esbuild")) {
43
+ throw new Error(
44
+ 'The "orchajs/serverless" plugin requires "serverless-esbuild". Add "serverless-esbuild" before "orchajs/serverless" in the Serverless plugins list.'
45
+ );
46
+ }
47
+ const custom = this.serverless.service.custom ?? {};
48
+ const configuredEsbuild = custom.esbuild ?? {};
49
+ const esbuild = configuredEsbuild.config ? loadEsbuildConfig(
50
+ configuredEsbuild.config,
51
+ servicePath,
52
+ this.serverless
53
+ ) : { ...configuredEsbuild };
54
+ assertOrchaIsBundled(esbuild);
55
+ const existingPlugins = loadEsbuildPlugins(
56
+ esbuild.plugins,
57
+ servicePath,
58
+ this.serverless
59
+ );
60
+ if (!existingPlugins.some((plugin) => plugin.name === "orchajs")) {
61
+ existingPlugins.push((0, import_esbuild.orchaPlugin)({ projectRoot: servicePath }));
62
+ }
63
+ delete esbuild.config;
64
+ esbuild.plugins = existingPlugins;
65
+ custom.esbuild = esbuild;
66
+ this.serverless.service.custom = custom;
67
+ }
68
+ }
69
+ function loadEsbuildConfig(configPath, servicePath, serverless) {
70
+ const loaded = loadProjectModule(
71
+ configPath,
72
+ servicePath
73
+ );
74
+ const config = unwrapDefault(loaded);
75
+ if (typeof config !== "function") {
76
+ throw new Error(
77
+ `Serverless esbuild config "${configPath}" must export a function.`
78
+ );
79
+ }
80
+ return config(serverless);
81
+ }
82
+ function loadEsbuildPlugins(plugins, servicePath, serverless) {
83
+ if (!plugins) {
84
+ return [];
85
+ }
86
+ if (Array.isArray(plugins)) {
87
+ return [...plugins];
88
+ }
89
+ const loaded = unwrapDefault(
90
+ loadProjectModule(plugins, servicePath)
91
+ );
92
+ const resolved = typeof loaded === "function" ? loaded(serverless) : loaded;
93
+ if (!Array.isArray(resolved)) {
94
+ throw new Error(
95
+ `Serverless esbuild plugins file "${plugins}" must export an array or a function that returns one.`
96
+ );
97
+ }
98
+ return [...resolved];
99
+ }
100
+ function loadProjectModule(path, servicePath) {
101
+ const requireFromProject = (0, import_module.createRequire)(
102
+ (0, import_path.resolve)(servicePath, "package.json")
103
+ );
104
+ return requireFromProject((0, import_path.resolve)(servicePath, path));
105
+ }
106
+ function unwrapDefault(value) {
107
+ if (typeof value === "object" && value !== null && "default" in value) {
108
+ return value.default;
109
+ }
110
+ return value;
111
+ }
112
+ function assertOrchaIsBundled(options) {
113
+ for (const key of ["exclude", "external"]) {
114
+ if (options[key]?.includes("orchajs")) {
115
+ throw new Error(
116
+ `Remove "orchajs" from custom.esbuild.${key}. Orcha must be replaced during bundling, not copied into the Lambda package.`
117
+ );
118
+ }
119
+ }
120
+ }
121
+ var serverless_default = OrchaServerlessPlugin;
122
+ // Annotate the CommonJS export names for ESM import in node:
123
+ 0 && (module.exports = {
124
+ OrchaServerlessPlugin
125
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orchajs",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "A filesystem-convention, stateful agent framework for JavaScript.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -31,6 +31,11 @@
31
31
  "import": "./dist/integrations/esbuild.js",
32
32
  "require": "./dist-cjs/integrations/esbuild.js"
33
33
  },
34
+ "./serverless": {
35
+ "types": "./dist/integrations/serverless.d.ts",
36
+ "import": "./dist/integrations/serverless.js",
37
+ "require": "./dist-cjs/integrations/serverless.cjs"
38
+ },
34
39
  "./testing": {
35
40
  "types": "./dist/testing.d.ts",
36
41
  "import": "./dist/testing.js",
@@ -42,6 +47,9 @@
42
47
  "esbuild": [
43
48
  "dist/integrations/esbuild.d.ts"
44
49
  ],
50
+ "serverless": [
51
+ "dist/integrations/serverless.d.ts"
52
+ ],
45
53
  "testing": [
46
54
  "dist/testing.d.ts"
47
55
  ]