@pulse-editor/cli 0.1.1-beta.21 → 0.1.1-beta.23

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.
@@ -65,9 +65,18 @@ app.all(/^\/server-function\/(.*)/, async (req, res) => {
65
65
  });
66
66
  const dir = path.resolve('node_modules/@pulse-editor/cli/dist/lib/server/preview/backend/load-remote.cjs');
67
67
  const fileUrl = pathToFileURL(dir).href;
68
- const { loadAndCall } = await import(fileUrl);
68
+ const { loadFunc, loadPrice } = await import(fileUrl);
69
+ const price = await loadPrice(func, pulseConfig.id, 'http://localhost:3030', pulseConfig.version);
70
+ if (price) {
71
+ // Make func name and price bold in console
72
+ console.log(`🏃 Running function \x1b[1m${func}\x1b[0m, credits consumed: \x1b[1m${price}\x1b[0m`);
73
+ }
74
+ else {
75
+ console.log(`🏃 Running function \x1b[1m${func}\x1b[0m.`);
76
+ }
69
77
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
- const response = await loadAndCall(func, request, pulseConfig.id, 'http://localhost:3030', pulseConfig.version);
78
+ const loadedFunc = await loadFunc(func, pulseConfig.id, 'http://localhost:3030', pulseConfig.version);
79
+ const response = await loadedFunc(request);
71
80
  const streamPipeline = promisify(pipeline);
72
81
  if (response) {
73
82
  // 1️⃣ Set status code
@@ -1,23 +1,33 @@
1
- const { createInstance } = require("@module-federation/runtime");
1
+ const {createInstance} = require('@module-federation/runtime');
2
2
 
3
- async function loadAndCall(func, req, appId, origin, version) {
4
- // here we assign the return value of the init() function, which can be used to do some more complex
5
- // things with the module federation runtime
6
- const instance = createInstance({
7
- name: "server_function_runner",
8
- remotes: [
9
- {
10
- name: appId + "_server",
11
- entry: `${origin}/${appId}/${version}/server/remoteEntry.js`,
12
- },
13
- ],
14
- });
3
+ async function importRemoteModule(func, appId, origin, version) {
4
+ const instance = createInstance({
5
+ name: 'server_function_runner',
6
+ remotes: [
7
+ {
8
+ name: appId + '_server',
9
+ entry: `${origin}/${appId}/${version}/server/remoteEntry.js`,
10
+ },
11
+ ],
12
+ });
15
13
 
16
- const loadedFunc = (await instance.loadRemote(`${appId}_server/${func}`))
17
- .default;
14
+ const loadedModule = await instance.loadRemote(`${appId}_server/${func}`);
15
+ return loadedModule;
16
+ }
17
+
18
+ async function loadFunc(func, appId, origin, version) {
19
+ // here we assign the return value of the init() function, which can be used to do some more complex
20
+ // things with the module federation runtime
21
+ const module = await importRemoteModule(func, appId, origin, version);
22
+ const loadedFunc = module.default;
23
+
24
+ return loadedFunc;
25
+ }
18
26
 
19
- const res = await loadedFunc(req);
20
- return res;
27
+ async function loadPrice(func, appId, origin, version) {
28
+ const module = await importRemoteModule(func, appId, origin, version);
29
+ const price = module._CREDIT_PER_CALL;
30
+ return price;
21
31
  }
22
32
 
23
- module.exports = { loadAndCall };
33
+ module.exports = {loadFunc, loadPrice};
@@ -284,54 +284,6 @@ ${Object.entries(funcs)
284
284
  level: 'warn',
285
285
  },
286
286
  };
287
- const previewHostConfig = {
288
- mode: mode,
289
- entry: './node_modules/@pulse-editor/cli/dist/lib/server/preview/backend/index.js',
290
- target: 'async-node',
291
- output: {
292
- publicPath: 'auto',
293
- library: { type: 'commonjs-module' },
294
- path: path.resolve(projectDirName, 'dist/preview/backend'),
295
- filename: 'index.cjs',
296
- },
297
- resolve: {
298
- extensions: ['.ts', '.js'],
299
- },
300
- module: {
301
- rules: [
302
- {
303
- test: /\.tsx?$/,
304
- use: [
305
- {
306
- loader: 'ts-loader',
307
- options: {
308
- transpileOnly: false, // Enables type-checking and .d.ts file emission
309
- },
310
- },
311
- ],
312
- exclude: [/node_modules/, /dist/],
313
- },
314
- ],
315
- },
316
- plugins: [
317
- new NodeFederationPlugin({
318
- remoteType: 'script',
319
- name: 'preview_host',
320
- useRuntimePlugin: true,
321
- exposes: {},
322
- }, {}),
323
- ],
324
- stats: {
325
- all: false,
326
- errors: true,
327
- warnings: true,
328
- logging: 'warn',
329
- colors: true,
330
- },
331
- infrastructureLogging: {
332
- level: 'warn',
333
- },
334
- };
335
287
  const mfClientConfig = {
336
288
  mode: mode,
337
289
  name: 'client',
@@ -531,7 +483,7 @@ ${Object.entries(funcs)
531
483
  };
532
484
  // #endregion
533
485
  if (isPreview) {
534
- return [previewClientConfig, previewHostConfig, mfServerConfig];
486
+ return [previewClientConfig, mfServerConfig];
535
487
  }
536
488
  else if (buildTarget === 'server') {
537
489
  return [mfServerConfig];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pulse-editor/cli",
3
- "version": "0.1.1-beta.21",
3
+ "version": "0.1.1-beta.23",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "pulse": "dist/cli.js"
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "@module-federation/enhanced": "0.21.6",
23
- "@module-federation/node": "^2.7.25",
23
+ "@module-federation/node": "2.7.25",
24
24
  "@module-federation/runtime": "0.21.6",
25
25
  "@pulse-editor/shared-utils": "^0.1.1-beta.67",
26
26
  "concurrently": "^9.2.1",