@merkur/cli 0.35.4 → 0.35.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merkur/cli",
3
- "version": "0.35.4",
3
+ "version": "0.35.5",
4
4
  "description": "Merkur is tiny and extensible library for creating front-end microservices.",
5
5
  "bin": {
6
6
  "merkur": "./bin/merkur.mjs"
@@ -54,6 +54,7 @@
54
54
  "esbuild": "^0.20.1",
55
55
  "esbuild-plugin-manifest": "^1.0.3",
56
56
  "express": "^4.18.2",
57
+ "npm-run-path": "^5.3.0",
57
58
  "ws": "^8.16.0"
58
59
  },
59
60
  "devDependencies": {
@@ -65,5 +66,5 @@
65
66
  "engines": {
66
67
  "node": ">=20"
67
68
  },
68
- "gitHead": "a78cf3d373ad20dbb2700e4070a52965cebd5a17"
69
+ "gitHead": "e5507ce65843bc50a615a3dd17c10ab2b59b3173"
69
70
  }
@@ -1,6 +1,8 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import process from 'node:process';
3
3
 
4
+ import { npmRunPath } from 'npm-run-path';
5
+
4
6
  import { createCLIConfig } from '../CLIConfig.mjs';
5
7
  import { createContext } from '../context.mjs';
6
8
  import { createLogger } from '../logger.mjs';
@@ -25,6 +27,7 @@ export async function test({ args, command }) {
25
27
  const runner = spawn('./node_modules/.bin/jest', args, {
26
28
  env: {
27
29
  ...process.env,
30
+ PATH: npmRunPath(),
28
31
  NODE_CONFIG_DIR: './server/config',
29
32
  MERKUR_CONFIG: JSON.stringify(merkurConfig),
30
33
  CLI_CONFIG: JSON.stringify(cliConfig),
package/src/devServer.mjs CHANGED
@@ -25,8 +25,7 @@ export async function runDevServer({ context, merkurConfig, cliConfig }) {
25
25
  path: playgroundPath,
26
26
  widgetHandler,
27
27
  } = merkurConfig.playground;
28
- const { cliFolder, command, writeToDisk, buildFolder, projectFolder } =
29
- cliConfig;
28
+ const { cliFolder, command, writeToDisk } = cliConfig;
30
29
 
31
30
  return new Promise((resolve, reject) => {
32
31
  const app = express();
@@ -61,14 +60,18 @@ export async function runDevServer({ context, merkurConfig, cliConfig }) {
61
60
  );
62
61
 
63
62
  if (asset.type.includes('inline')) {
64
- const path = asset.source.replace(origin, '');
63
+ const assetPath = asset.source.replace(origin, '');
65
64
  if (writeToDisk) {
66
- asset.source = fs.readFileSync(
67
- path.join(path.resolve(projectFolder, buildFolder), path),
68
- 'utf8',
69
- );
65
+ // widget Server Handle right inline
66
+ // asset.source = fs.readFileSync(
67
+ // path.join(
68
+ // path.resolve(projectFolder, buildFolder),
69
+ // assetPath,
70
+ // ),
71
+ // 'utf8',
72
+ // );
70
73
  } else {
71
- asset.source = context.memory[path]?.text;
74
+ asset.source = context.memory[assetPath]?.text;
72
75
  }
73
76
  }
74
77
 
@@ -84,15 +87,19 @@ export async function runDevServer({ context, merkurConfig, cliConfig }) {
84
87
  }
85
88
 
86
89
  if (asset.type.includes('inline')) {
87
- const assetPath = asset.source.replace(origin, '');
90
+ const assetPath = asset.source[assetVersion].replace(
91
+ origin,
92
+ '',
93
+ );
88
94
  if (writeToDisk) {
89
- asset.source = fs.readFileSync(
90
- path.join(
91
- path.resolve(projectFolder, buildFolder),
92
- assetPath,
93
- ),
94
- 'utf8',
95
- );
95
+ // widget Server Handle right inline
96
+ // asset.source[assetVersion] = fs.readFileSync(
97
+ // path.join(
98
+ // path.resolve(projectFolder, buildFolder),
99
+ // assetPath,
100
+ // ),
101
+ // 'utf8',
102
+ // );
96
103
  } else {
97
104
  asset.source = context.memory[assetPath]?.text;
98
105
  }
@@ -23,4 +23,17 @@
23
23
  <script src='<%= asset.source.es13 %>' defer='true' data-name="<%= asset.name %>"></script>
24
24
  <% } %>
25
25
  <% } %>
26
+
27
+ <%if (asset.type==='inlineScript' ) { %>
28
+ <%if (typeof asset.source==='string' ) { %>
29
+ <script data-name="<%= asset.name %>">
30
+ <%- asset.source %>
31
+ </script>
32
+ <% } %>
33
+ <%if (typeof asset.source==='object' ) { %>
34
+ <script data-name="<%= asset.name %>">
35
+ <%- asset.source %>
36
+ </script>
37
+ <% } %>
38
+ <% } %>
26
39
  <% }); %>
package/types.d.ts ADDED
@@ -0,0 +1,103 @@
1
+ import type { BuildOptions } from 'esbuild';
2
+ import type { Request, Response } from '@types/express';
3
+
4
+ export interface CLIConfig {
5
+ environment: string;
6
+ isProduction: boolean;
7
+ watch: boolean;
8
+ writeToDisk: boolean;
9
+ outFile: string;
10
+ port: number;
11
+ runTask: string[];
12
+ devServerPort: number;
13
+ projectFolder: string;
14
+ cliFolder: string;
15
+ buildFolder: string;
16
+ staticFolder: string;
17
+ staticPath: string;
18
+ hasRunDevServer: boolean;
19
+ hasRunWidgetServer: boolean;
20
+ inspect: boolean;
21
+ verbose: boolean;
22
+ }
23
+
24
+ export type Extend =
25
+ | '@merkur/preact/cli'
26
+ | '@merkur/svelte/cli'
27
+ | '@merkur/uhtml/cli'
28
+ | string
29
+ | undefined;
30
+
31
+ export interface Task {
32
+ name: 'es13' | 'es9' | 'node' | string;
33
+ build: BuildOptions;
34
+ [key: string]: any;
35
+ }
36
+
37
+ export interface DevServer {
38
+ protocol: string;
39
+ host: string;
40
+ port: number;
41
+ origin: string;
42
+ staticPath: string;
43
+ staticFolder: string;
44
+ }
45
+
46
+ export interface Playground {
47
+ template: string;
48
+ templateFolder: string;
49
+ path: string;
50
+ widgetHandler(req: Request, res: Response): Record<string, unknown>;
51
+ widgetParams(req: Request): URLSearchParams;
52
+ }
53
+
54
+ export interface SocketServer {
55
+ protocol: string;
56
+ host: string;
57
+ port: number;
58
+ }
59
+
60
+ export interface WidgetServer {
61
+ protocol: string;
62
+ host: string;
63
+ port: number;
64
+ origin: string;
65
+ staticFolder: string;
66
+ staticPath: string;
67
+ buildFolder: string;
68
+ clusters: number;
69
+ }
70
+
71
+ export interface MerkurConfig {
72
+ HMR: boolean;
73
+ cliConfig: CLIConfig;
74
+ extends: Extend[];
75
+ task: {
76
+ [key: string]: Task;
77
+ };
78
+ devServer: DevServer;
79
+ defaultEntries: {
80
+ client: string;
81
+ server: string;
82
+ [key: string]: string;
83
+ };
84
+ playground: Playground;
85
+ socketServer: SocketServer;
86
+ widgetServer: WidgetServer;
87
+ onMerkurConfig: ({
88
+ merkurConfig: MerkurConfig,
89
+ cliConfig: CLIConfig,
90
+ }) => Partial<MerkurConfig>;
91
+ onCliConfig: ({ cliConfig: CLIConfig }) => Partial<CLIConfig>;
92
+ onTaskBuild: ({
93
+ definition: Task,
94
+ build: BuildOptions,
95
+ cliConfig: CLIConfig,
96
+ merkurConfig: MerkurConfig,
97
+ }) => Partial<BuildOptions>;
98
+ }
99
+
100
+ export function defineConfig({
101
+ merkurConfig: MerkurConfig,
102
+ cliConfig: CLIConfig,
103
+ }): Partial<MerkurConfig>;