@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 +16 -31
- package/lib/index.js.map +2 -2
- package/lib/public/docs.json +1 -1
- package/package.json +2 -1
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
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
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);
|