@squiz/edge-dev-render-runtime-lib 2.5.8 → 2.6.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/lib/index.js CHANGED
@@ -98,41 +98,26 @@ var esbuild = __toESM(require("esbuild"));
98
98
  var import_node_path = __toESM(require("node:path"));
99
99
  var import_node_vm = __toESM(require("node:vm"));
100
100
  var import_module = require("module");
101
+ var import_local_component_runtime = require("@squiz/local-component-runtime");
101
102
  var DevelopmentComponentRunnerService = class {
102
103
  async executeEdgeComponentFunction(task, contextAwareness) {
103
- const webRequestEvents = await this.setUpWebRequestEventForResolveUri(task);
104
- const builtComponent = await esbuild.build({
105
- entryPoints: [task.functionEntryFilePath],
106
- write: false,
107
- format: "cjs",
108
- bundle: true,
109
- loader: {
110
- ".js": "jsx"
104
+ const runtimeService = new ContentRuntimeService(task.manifest, task.manifestPath);
105
+ const output = await (0, import_local_component_runtime.runComponentFunction)(
106
+ {
107
+ entrypoint: task.functionEntryFilePath,
108
+ functionName: task.componentFunction.name,
109
+ helpers: {
110
+ resolveUri: (uri) => runtimeService.getContentItemPreview(uri)
111
+ }
111
112
  },
112
- platform: "node"
113
- });
114
- if (builtComponent.errors.length > 0) {
115
- for (const e of builtComponent.errors) {
116
- console.error(e.text);
117
- }
118
- throw new Error("Failed to build component");
119
- }
120
- const componentContext = this.getComponentContext(task, webRequestEvents, contextAwareness);
121
- const vmContext = import_node_vm.default.createContext({
122
- ...globalThis,
123
- module: {},
124
- exports: {},
125
- require: (0, import_module.createRequire)(task.functionEntryFilePath)
126
- });
127
- const script = new import_node_vm.default.Script(builtComponent.outputFiles[0].text, { filename: task.functionEntryFilePath });
128
- script.runInContext(vmContext);
129
- const f = vmContext.module.exports.default[task.componentFunction.name];
130
- if (typeof f === "function") {
131
- return await Promise.resolve(f(task.args[0] ?? {}, componentContext));
132
- }
133
- throw Error(
134
- `Function "${task.componentFunction.name}" not defined in the fn entry js file ${task.functionEntryFilePath}!`
113
+ task.args[0],
114
+ { environmentVariables: task.environment, ctx: contextAwareness }
135
115
  );
116
+ if (task.componentFunction.output.responseType === "json") {
117
+ return JSON.parse(output);
118
+ } else {
119
+ return output;
120
+ }
136
121
  }
137
122
  async executeServerComponentFunction(task) {
138
123
  const webRequestEvents = await this.setUpWebRequestEventForResolveUri(task);