likec4 1.48.0 → 1.49.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.
Files changed (113) hide show
  1. package/README.md +11 -1
  2. package/__app__/src/likec4.js +5595 -4127
  3. package/__app__/src/routes/index.js +3 -153
  4. package/__app__/src/routes/projects.js +21 -1087
  5. package/__app__/src/routes/single.js +1221 -16
  6. package/__app__/src/style.css +1 -1
  7. package/__app__/src/vendors.js +3507 -894
  8. package/__app__/src/webcomponent.js +1 -1
  9. package/config/schema.json +155 -143
  10. package/dist/THIRD-PARTY-LICENSES.md +1739 -0
  11. package/dist/_chunks/GraphvizBinaryAdapter.mjs +72 -0
  12. package/dist/_chunks/filenames.mjs +14 -0
  13. package/dist/_chunks/index.d.mts +224 -129
  14. package/dist/_chunks/index2.d.mts +2033 -1908
  15. package/dist/_chunks/libs/@chevrotain/gast.mjs +1 -3969
  16. package/dist/_chunks/libs/@chevrotain/regexp-to-ast.mjs +9 -785
  17. package/dist/_chunks/libs/@chevrotain/utils.mjs +1 -37
  18. package/dist/_chunks/libs/@hono/mcp.mjs +34 -0
  19. package/dist/_chunks/libs/@hono/node-server.mjs +1 -436
  20. package/dist/_chunks/libs/@logtape/logtape.d.mts +741 -0
  21. package/dist/_chunks/libs/@logtape/logtape.mjs +6 -1354
  22. package/dist/_chunks/libs/@lume/kiwi.mjs +1 -1355
  23. package/dist/_chunks/libs/@modelcontextprotocol/sdk.d.mts +14 -14
  24. package/dist/_chunks/libs/@modelcontextprotocol/sdk.mjs +12 -25105
  25. package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -1503
  26. package/dist/_chunks/libs/@nanostores/react.mjs +1 -30
  27. package/dist/_chunks/libs/@smithy/util-base64.mjs +1 -100
  28. package/dist/_chunks/libs/ajv.mjs +1 -777
  29. package/dist/_chunks/libs/atomically.mjs +1 -362
  30. package/dist/_chunks/libs/birpc.mjs +1 -201
  31. package/dist/_chunks/libs/chevrotain-allstar.mjs +2 -850
  32. package/dist/_chunks/libs/chevrotain.mjs +55 -6229
  33. package/dist/_chunks/libs/conf.mjs +1 -2258
  34. package/dist/_chunks/libs/defu.mjs +1 -42
  35. package/dist/_chunks/libs/esm-env.mjs +1 -5
  36. package/dist/_chunks/libs/eventemitter3.mjs +1 -243
  37. package/dist/_chunks/libs/fast-equals.mjs +1 -446
  38. package/dist/_chunks/libs/find-up-simple.mjs +1 -24
  39. package/dist/_chunks/libs/get-port.mjs +1 -107
  40. package/dist/_chunks/libs/is-docker.mjs +1 -26
  41. package/dist/_chunks/libs/is-error-instance.mjs +1 -26
  42. package/dist/_chunks/libs/is-inside-container.mjs +1 -20
  43. package/dist/_chunks/libs/is-plain-obj.mjs +1 -9
  44. package/dist/_chunks/libs/isexe.mjs +1 -127
  45. package/dist/_chunks/libs/json5.mjs +14 -959
  46. package/dist/_chunks/libs/khroma.mjs +1 -605
  47. package/dist/_chunks/libs/ky.mjs +2 -807
  48. package/dist/_chunks/libs/langium.d.mts +2880 -2844
  49. package/dist/_chunks/libs/langium.mjs +32 -20351
  50. package/dist/_chunks/libs/merge-error-cause.mjs +2 -746
  51. package/dist/_chunks/libs/nanostores.mjs +1 -198
  52. package/dist/_chunks/libs/p-limit.mjs +1 -120
  53. package/dist/_chunks/libs/p-queue.mjs +1 -449
  54. package/dist/_chunks/libs/package-manager-detector.mjs +1 -559
  55. package/dist/_chunks/libs/package-up.mjs +1 -10
  56. package/dist/_chunks/libs/parse-ms.mjs +1 -36
  57. package/dist/_chunks/libs/pathe.mjs +1 -0
  58. package/dist/_chunks/libs/picomatch.mjs +1 -1673
  59. package/dist/_chunks/libs/pretty-ms.mjs +1 -80
  60. package/dist/_chunks/libs/remeda.mjs +1 -690
  61. package/dist/_chunks/libs/safe-stringify.mjs +1 -21
  62. package/dist/_chunks/libs/strip-indent.mjs +1 -15
  63. package/dist/_chunks/libs/tinyrainbow.mjs +1 -88
  64. package/dist/_chunks/libs/ts-graphviz.mjs +4 -725
  65. package/dist/_chunks/libs/ufo.mjs +1 -240
  66. package/dist/_chunks/libs/which.mjs +1 -84
  67. package/dist/_chunks/libs/word-wrap.mjs +12 -43
  68. package/dist/_chunks/node.mjs +481 -0
  69. package/dist/_chunks/plugin.mjs +98 -772
  70. package/dist/_chunks/rolldown-runtime.mjs +1 -48
  71. package/dist/_chunks/sequence-view.mjs +1 -575
  72. package/dist/cli/index.mjs +127 -1846
  73. package/dist/config/index.d.mts +2 -2
  74. package/dist/config/index.mjs +1 -6
  75. package/dist/index.d.mts +148 -7
  76. package/dist/index.mjs +1 -21
  77. package/dist/model/builder.mjs +1 -3
  78. package/dist/model/index.d.mts +57 -3
  79. package/dist/model/index.mjs +1 -5
  80. package/dist/vite-plugin/index.d.mts +4 -3
  81. package/dist/vite-plugin/index.mjs +1 -22
  82. package/dist/vite-plugin/internal.d.mts +5 -5
  83. package/dist/vite-plugin/internal.mjs +1 -68
  84. package/package.json +60 -41
  85. package/react/{index.d.ts → index.d.mts} +112 -70
  86. package/react/{index.js → index.mjs} +21361 -22064
  87. package/react/package.json +2 -5
  88. package/vite-plugin-modules.d.ts +5 -5
  89. package/dist/_chunks/LikeC4.d.mts +0 -121
  90. package/dist/_chunks/LikeC4.mjs +0 -202
  91. package/dist/_chunks/config-app.prod.d.mts +0 -18
  92. package/dist/_chunks/config-app.prod.mjs +0 -188
  93. package/dist/_chunks/config-webcomponent.prod.mjs +0 -71
  94. package/dist/_chunks/define-config.mjs +0 -409
  95. package/dist/_chunks/index3.d.mts +0 -60
  96. package/dist/_chunks/index4.d.mts +0 -1
  97. package/dist/_chunks/libs/@smithy/is-array-buffer.mjs +0 -10
  98. package/dist/_chunks/libs/hono.mjs +0 -1829
  99. package/dist/_chunks/libs/nanoid.mjs +0 -29
  100. package/dist/_chunks/model.mjs +0 -12
  101. package/dist/_chunks/module.d.mts +0 -71
  102. package/dist/_chunks/module.mjs +0 -18657
  103. package/dist/_chunks/vite-build.mjs +0 -69
  104. package/dist/_chunks/vite-dev.mjs +0 -79
  105. package/dist/_chunks/vite-preview.mjs +0 -27
  106. package/dist/language/module.d.mts +0 -5
  107. package/dist/language/module.mjs +0 -20
  108. package/dist/vite/vite-build.d.mts +0 -26
  109. package/dist/vite/vite-build.mjs +0 -27
  110. package/dist/vite/vite-dev.d.mts +0 -34
  111. package/dist/vite/vite-dev.mjs +0 -29
  112. package/dist/vite/vite-preview.d.mts +0 -20
  113. package/dist/vite/vite-preview.mjs +0 -26
@@ -1,7 +1,4 @@
1
1
  {
2
- "name": "@likec4/react",
3
- "type": "module",
4
- "sideEffects": false,
5
- "types": "./index.d.ts",
6
- "module": "./index.js"
2
+ "types": "index.d.mts",
3
+ "module": "index.mjs"
7
4
  }
@@ -28,7 +28,7 @@ declare module 'likec4:icons' {
28
28
  }
29
29
 
30
30
  export type ElementIconRenderer = (props: ElementIconRendererProps) => ReactNode
31
- export const ProjectIcons: (props: ElementIconRendererProps & { projectId: string }) => ReactNode
31
+ export function getProjectIcons(projectId: string): ElementIconRenderer
32
32
  }
33
33
 
34
34
  declare module 'likec4:model' {
@@ -54,8 +54,8 @@ declare module 'likec4:single-project' {
54
54
  types,
55
55
  UnknownLayouted,
56
56
  } from 'likec4/model'
57
- import type { ElementIconRenderer } from 'likec4:icons'
58
57
  import type { Atom } from 'likec4/vite-plugin/internal'
58
+ import type { ElementIconRenderer } from 'likec4:icons'
59
59
 
60
60
  export const $likec4data: Atom<LayoutedLikeC4ModelData>
61
61
  export const $likec4model: Atom<LikeC4Model<UnknownLayouted>>
@@ -117,7 +117,7 @@ declare module 'likec4:model/*' {
117
117
  import type { Atom } from 'likec4:model'
118
118
 
119
119
  // This will be used later for augmenting the types
120
- declare interface Types extends UnknownLayouted {
120
+ interface Types extends UnknownLayouted {
121
121
  }
122
122
 
123
123
  export type LikeC4ViewId = aux.ViewId<Types>
@@ -165,7 +165,7 @@ declare module 'likec4:rpc' {
165
165
  import type { LikeC4VitePluginRpc } from 'likec4/vite-plugin/internal'
166
166
 
167
167
  export type { LikeC4VitePluginRpc }
168
- export declare const likec4rpc: LikeC4VitePluginRpc
168
+ export const likec4rpc: LikeC4VitePluginRpc
169
169
 
170
- export declare const isRpcAvailable: boolean
170
+ export const isRpcAvailable: boolean
171
171
  }
@@ -1,121 +0,0 @@
1
- import { i as ProjectsManager, r as LikeC4Views, t as LikeC4LanguageServices } from "./index2.mjs";
2
- import { a as createLanguageServices, o as Logger } from "./module.mjs";
3
- import { M as index_d_exports, v as LikeC4Model } from "./index3.mjs";
4
- import { NonEmptyArray, ProjectId } from "@likec4/core";
5
-
6
- //#region src/LikeC4.d.ts
7
- type LikeC4Langium = ReturnType<typeof createLanguageServices>;
8
- type LikeC4Options = {
9
- /**
10
- * By default, if LikeC4 model is invalid, errors are printed to the console.
11
- * Disable this behavior by setting this option to false.
12
- *
13
- * @default true
14
- */
15
- printErrors?: boolean;
16
- /**
17
- * If true, initialization will return rejected promise with the LikeC4 instance.
18
- * Use `likec4.getErrors()` to get the errors.
19
- * @default false
20
- */
21
- throwIfInvalid?: boolean;
22
- /**
23
- * Logger to use for the language service.
24
- * false - no output
25
- * @default 'default'
26
- */
27
- logger?: Logger | 'vite' | 'default' | false;
28
- /**
29
- * Whether to use the `dot` binary for layouting or the WebAssembly version.
30
- * @default 'wasm'
31
- */
32
- graphviz?: 'wasm' | 'binary';
33
- /**
34
- * Whether to start MCP server
35
- * @default false
36
- */
37
- mcp?: false | 'stdio' | {
38
- port: number;
39
- };
40
- /**
41
- * Whether to watch for changes in the workspace.
42
- * @default false
43
- */
44
- watch?: boolean;
45
- };
46
- declare class LikeC4 {
47
- readonly workspace: string;
48
- readonly langium: LikeC4Langium;
49
- static fromSource(likec4SourceCode: string, opts?: LikeC4Options): Promise<LikeC4>;
50
- /**
51
- * Prevents multiple instances of LikeC4 for the same workspace
52
- */
53
- private static likec4Instances;
54
- /**
55
- * Initializes a LikeC4 instance from the specified workspace path.
56
- * By default in current folder
57
- */
58
- static fromWorkspace(path?: string, opts?: LikeC4Options): Promise<LikeC4>;
59
- private logger;
60
- private constructor();
61
- get languageServices(): LikeC4LanguageServices;
62
- get projectsManager(): ProjectsManager;
63
- get viewsService(): LikeC4Views;
64
- private get LangiumDocuments();
65
- ensureSingleProject(): void;
66
- /**
67
- * Diagram is a computed view, layouted using Graphviz
68
- * If diagram has manual layout, it will be used.
69
- * Used in React components
70
- */
71
- diagrams(projectId?: ProjectId | undefined): Promise<index_d_exports.DiagramView[]>;
72
- /**
73
- * Builds LikeC4Model from all documents
74
- * Only computes view predicates {@link ComputedView} - i.e. no layout
75
- * Not ready for rendering, but enough to traverse
76
- *
77
- * Sync version does not read manual layouts
78
- * Use {@link computedModel} for a version that includes manual layouts
79
- */
80
- syncComputedModel(project?: ProjectId | undefined): LikeC4Model.Computed;
81
- /**
82
- * Builds LikeC4Model from all documents
83
- * Only computes view predicates {@link ComputedView} - i.e. no layout
84
- * Not ready for rendering, but enough to traverse
85
- */
86
- computedModel(project?: ProjectId | undefined): Promise<LikeC4Model.Computed>;
87
- projects(): NonEmptyArray<ProjectId>;
88
- /**
89
- * Same as {@link computedModel()}, but also applies layout
90
- * Ready for rendering
91
- */
92
- layoutedModel(project?: ProjectId | undefined): Promise<LikeC4Model.Layouted>;
93
- getErrors(): Array<{
94
- message: string;
95
- line: number;
96
- range: {
97
- start: {
98
- line: number;
99
- character: number;
100
- };
101
- end: {
102
- line: number;
103
- character: number;
104
- };
105
- };
106
- sourceFsPath: string;
107
- }>;
108
- hasErrors(): boolean;
109
- /**
110
- * @returns true if there are errors
111
- */
112
- printErrors(): boolean;
113
- /**
114
- * @returns a function to dispose the listener
115
- */
116
- onModelUpdate(listener: () => void): () => void;
117
- dispose(): Promise<void>;
118
- [Symbol.asyncDispose](): Promise<void>;
119
- }
120
- //#endregion
121
- export { LikeC4Options as n, LikeC4 as t };
@@ -1,202 +0,0 @@
1
- import { t as defu } from "./libs/defu.mjs";
2
- import { $ as init_main, G as DiagnosticSeverity, L as UriUtils, R as URI } from "./libs/langium.mjs";
3
- import { h as t, l as e } from "./libs/remeda.mjs";
4
- import { t as u } from "./libs/tinyrainbow.mjs";
5
- import { n as createLanguageServices } from "./module.mjs";
6
- import { existsSync } from "node:fs";
7
- import { basename, resolve } from "node:path";
8
- import { pathToFileURL } from "node:url";
9
-
10
- //#region src/LikeC4.ts
11
- init_main();
12
- const validationErrorsToError = (likec4) => /* @__PURE__ */ new Error(`Invalid model:\n${likec4.getErrors().map((e) => ` ${e.sourceFsPath}:${e.line} ${e.message.slice(0, 200)}`).join("\n")}`);
13
- var LikeC4 = class LikeC4 {
14
- static async fromSource(likec4SourceCode, opts) {
15
- const langium = createLanguageServices(defu(opts, {
16
- useFileSystem: false,
17
- watch: false,
18
- logger: false,
19
- graphviz: "wasm",
20
- mcp: false
21
- }));
22
- const workspaceUri = URI.from({
23
- scheme: "virtual",
24
- path: "/workspace"
25
- });
26
- const uri = UriUtils.joinPath(workspaceUri, "source.likec4");
27
- const doc = langium.shared.workspace.LangiumDocuments.createDocument(uri, likec4SourceCode);
28
- await langium.cli.Workspace.initWorkspace({
29
- uri: workspaceUri.toString(),
30
- name: "virtual"
31
- });
32
- await langium.shared.workspace.DocumentBuilder.build([doc], { validation: true });
33
- const likec4 = new LikeC4(workspaceUri.path, langium);
34
- if (opts?.throwIfInvalid === true && likec4.hasErrors()) {
35
- await likec4.dispose();
36
- return Promise.reject(validationErrorsToError(likec4));
37
- }
38
- if (opts?.printErrors !== false && likec4.hasErrors()) likec4.printErrors();
39
- return likec4;
40
- }
41
- /**
42
- * Prevents multiple instances of LikeC4 for the same workspace
43
- */
44
- static likec4Instances = /* @__PURE__ */ new Map();
45
- /**
46
- * Initializes a LikeC4 instance from the specified workspace path.
47
- * By default in current folder
48
- */
49
- static async fromWorkspace(path = ".", opts) {
50
- const workspace = resolve(path);
51
- if (!existsSync(workspace)) throw new Error(`Workspace not found: ${workspace}`);
52
- let likec4 = LikeC4.likec4Instances.get(workspace);
53
- if (!likec4) {
54
- const langium = createLanguageServices(defu(opts, {
55
- useFileSystem: true,
56
- watch: false,
57
- logger: "default",
58
- graphviz: "wasm",
59
- mcp: false
60
- }));
61
- likec4 = new LikeC4(workspace, langium);
62
- LikeC4.likec4Instances.set(workspace, likec4);
63
- await langium.cli.Workspace.initWorkspace({
64
- uri: pathToFileURL(workspace).toString(),
65
- name: basename(workspace)
66
- });
67
- if (opts?.printErrors !== false && likec4.hasErrors()) likec4.printErrors();
68
- }
69
- if (opts?.throwIfInvalid === true && likec4.hasErrors()) {
70
- await likec4.dispose();
71
- return Promise.reject(validationErrorsToError(likec4));
72
- }
73
- return likec4;
74
- }
75
- logger;
76
- constructor(workspace, langium) {
77
- this.workspace = workspace;
78
- this.langium = langium;
79
- this.logger = langium.logger;
80
- }
81
- get languageServices() {
82
- return this.langium.likec4.LanguageServices;
83
- }
84
- get projectsManager() {
85
- return this.langium.shared.workspace.ProjectsManager;
86
- }
87
- get viewsService() {
88
- return this.langium.likec4.Views;
89
- }
90
- get LangiumDocuments() {
91
- return this.langium.shared.workspace.LangiumDocuments;
92
- }
93
- ensureSingleProject() {
94
- const projects = this.langium.likec4.LanguageServices.projects();
95
- if (projects.length > 1) {
96
- this.logger.error(`Multiple projects found:
97
- ${projects.map((p) => ` - ${p.folder.fsPath}`).join("\n")}
98
-
99
- ${u.red("Please specify a project folder")}
100
- `);
101
- throw new Error(`Multiple projects found`);
102
- }
103
- }
104
- /**
105
- * Diagram is a computed view, layouted using Graphviz
106
- * If diagram has manual layout, it will be used.
107
- * Used in React components
108
- */
109
- async diagrams(projectId) {
110
- return await this.langium.likec4.Views.diagrams(projectId);
111
- }
112
- /**
113
- * Builds LikeC4Model from all documents
114
- * Only computes view predicates {@link ComputedView} - i.e. no layout
115
- * Not ready for rendering, but enough to traverse
116
- *
117
- * Sync version does not read manual layouts
118
- * Use {@link computedModel} for a version that includes manual layouts
119
- */
120
- syncComputedModel(project) {
121
- const projectId = this.langium.shared.workspace.ProjectsManager.ensureProjectId(project);
122
- return this.langium.likec4.ModelBuilder.unsafeSyncComputeModel(projectId);
123
- }
124
- /**
125
- * Builds LikeC4Model from all documents
126
- * Only computes view predicates {@link ComputedView} - i.e. no layout
127
- * Not ready for rendering, but enough to traverse
128
- */
129
- async computedModel(project) {
130
- return await this.langium.likec4.ModelBuilder.computeModel(project);
131
- }
132
- projects() {
133
- return t(this.langium.likec4.LanguageServices.projects(), e("id"));
134
- }
135
- /**
136
- * Same as {@link computedModel()}, but also applies layout
137
- * Ready for rendering
138
- */
139
- async layoutedModel(project) {
140
- return await this.langium.likec4.LanguageServices.layoutedModel(project);
141
- }
142
- getErrors() {
143
- return this.LangiumDocuments.all.toArray().flatMap((doc) => {
144
- return (doc.diagnostics ?? []).filter((d) => d.severity === DiagnosticSeverity.Error).map(({ message, range }) => ({
145
- message,
146
- line: range.start.line,
147
- range,
148
- sourceFsPath: doc.uri.fsPath
149
- }));
150
- });
151
- }
152
- hasErrors() {
153
- return this.LangiumDocuments.all.some((doc) => {
154
- return doc.diagnostics?.some((d) => d.severity === DiagnosticSeverity.Error) ?? false;
155
- });
156
- }
157
- /**
158
- * @returns true if there are errors
159
- */
160
- printErrors() {
161
- let hasErrors = false;
162
- for (const doc of this.LangiumDocuments.all) {
163
- const errors = doc.diagnostics?.filter((e) => e.severity === 1);
164
- if (errors && errors.length > 0) {
165
- hasErrors = true;
166
- const messages = errors.flatMap((validationError) => {
167
- const line = validationError.range.start.line;
168
- const messages = validationError.message.split("\n");
169
- if (messages.length > 10) {
170
- messages.length = 10;
171
- messages.push("...");
172
- }
173
- return messages.map((message, i) => {
174
- if (i === 0) return " " + u.dim(`Line ${line}: `) + u.red(message);
175
- return " ".repeat(10) + u.red(message);
176
- });
177
- }).join("\n");
178
- this.logger.error(`Invalid ${doc.uri.fsPath}\n${messages}`);
179
- }
180
- }
181
- return hasErrors;
182
- }
183
- /**
184
- * @returns a function to dispose the listener
185
- */
186
- onModelUpdate(listener) {
187
- const sib = this.langium.likec4.ModelBuilder.onModelParsed(() => listener());
188
- return () => {
189
- sib.dispose();
190
- };
191
- }
192
- async dispose() {
193
- await this.langium.likec4.LanguageServices.dispose();
194
- for (const [path, likec4] of LikeC4.likec4Instances) if (likec4 === this) LikeC4.likec4Instances.delete(path);
195
- }
196
- async [Symbol.asyncDispose]() {
197
- await this.dispose();
198
- }
199
- };
200
-
201
- //#endregion
202
- export { LikeC4 as t };
@@ -1,18 +0,0 @@
1
- import { s as ViteLogger } from "./module.mjs";
2
- import { t as LikeC4 } from "./LikeC4.mjs";
3
- import "vite";
4
-
5
- //#region src/vite/config-app.prod.d.ts
6
- type LikeC4ViteConfig = {
7
- customLogger?: ViteLogger;
8
- languageServices: LikeC4;
9
- outputDir?: string | undefined;
10
- base?: string | undefined;
11
- title?: string | undefined;
12
- webcomponentPrefix?: string | undefined;
13
- useHashHistory?: boolean | undefined;
14
- likec4AssetsDir: string;
15
- outputSingleFile?: boolean | undefined;
16
- };
17
- //#endregion
18
- export { LikeC4ViteConfig as t };
@@ -1,188 +0,0 @@
1
- import { H as r } from "./libs/remeda.mjs";
2
- import { t as u } from "./libs/tinyrainbow.mjs";
3
- import { d as logger, i as createLikeC4Logger } from "./module.mjs";
4
- import { c as withLeadingSlash, r as hasProtocol, u as withTrailingSlash } from "./libs/ufo.mjs";
5
- import { t as packageUpSync } from "./libs/package-up.mjs";
6
- import { t as LikeC4VitePlugin } from "./plugin.mjs";
7
- import { existsSync } from "node:fs";
8
- import { dirname, join, resolve } from "node:path";
9
- import { fileURLToPath } from "node:url";
10
- import { mkdtemp, writeFile } from "node:fs/promises";
11
- import { tmpdir } from "node:os";
12
- import react from "@vitejs/plugin-react";
13
- import { viteSingleFile } from "vite-plugin-singlefile";
14
-
15
- //#region src/vite/utils.ts
16
- const viteLogger = createLikeC4Logger("vite");
17
- const _dirname = dirname(fileURLToPath(import.meta.url));
18
- const banner = `
19
- /* prettier-ignore-start */
20
- /* eslint-disable */
21
-
22
- /******************************************************************************
23
- * This file was generated
24
- * DO NOT EDIT MANUALLY!
25
- ******************************************************************************/
26
-
27
- `.trimStart();
28
- const footer = `
29
-
30
- /* prettier-ignore-end */
31
- `;
32
- const JsBanners = {
33
- banner,
34
- footer
35
- };
36
- function findPkgRoot() {
37
- const pkgRoot = packageUpSync({ cwd: _dirname });
38
- if (!pkgRoot) throw new Error(`likec4 package folder not found`);
39
- return dirname(pkgRoot);
40
- }
41
- function viteAppRoot() {
42
- const roots = [
43
- resolve(findPkgRoot(), "__app__"),
44
- resolve(_dirname, "../__app__"),
45
- resolve(_dirname, "../../__app__"),
46
- resolve(_dirname, "../../dist/__app__")
47
- ];
48
- const root = r(roots, existsSync);
49
- if (!root) {
50
- logger.error(`likec4 app root does not exist, tried:\n${roots.join("\n")}`);
51
- throw new Error(`likec4 app root does not exist`);
52
- }
53
- return root;
54
- }
55
- async function mkTempPublicDir() {
56
- const publicDir = await mkdtemp(join(tmpdir(), ".likec4-public-"));
57
- await writeFile(join(publicDir, "likec4-views.js"), "// generated by likec4\n");
58
- return publicDir;
59
- }
60
- /**
61
- * Adjust chunk size warning limit (in kB).
62
- */
63
- const chunkSizeWarningLimit = 1e4;
64
-
65
- //#endregion
66
- //#region src/vite/aliases.prod.ts
67
- function viteAliases() {
68
- const pkg = findPkgRoot();
69
- return {
70
- "likec4/icons": "@likec4/icons",
71
- "likec4/react": resolve(pkg, "react/index.js"),
72
- "likec4/model": resolve(pkg, "dist/model/index.mjs"),
73
- "likec4/vite-plugin/internal": resolve(pkg, "dist/vite-plugin/internal.mjs")
74
- };
75
- }
76
-
77
- //#endregion
78
- //#region src/vite/config-app.prod.ts
79
- const viteConfig = async ({ languageServices, likec4AssetsDir, ...cfg }) => {
80
- const customLogger = cfg.customLogger ?? viteLogger;
81
- const root = viteAppRoot();
82
- customLogger.info(`${u.cyan("likec4 app root")} ${u.dim(root)}`);
83
- const outDir = cfg.outputDir ?? resolve(languageServices.workspace, "dist");
84
- customLogger.info(u.cyan("outDir") + " " + u.dim(outDir));
85
- let base = "/";
86
- if (cfg.base) {
87
- base = withTrailingSlash(cfg.base);
88
- if (!hasProtocol(base) && base !== "./") base = withLeadingSlash(base);
89
- }
90
- if (base !== "/") customLogger.info(`${u.green("app base url")} ${u.dim(base)}`);
91
- const webcomponentPrefix = cfg.webcomponentPrefix ?? "likec4";
92
- const title = cfg.title ?? "LikeC4";
93
- const isSingleFile = cfg.outputSingleFile ?? false;
94
- return {
95
- isDev: false,
96
- likec4AssetsDir,
97
- webcomponentPrefix,
98
- title,
99
- root,
100
- languageServices,
101
- clearScreen: false,
102
- base,
103
- resolve: {
104
- conditions: ["production"],
105
- dedupe: [
106
- "react",
107
- "react-dom",
108
- "react/jsx-runtime",
109
- "react/jsx-dev-runtime",
110
- "react-dom/client"
111
- ],
112
- alias: {
113
- ...viteAliases(),
114
- "likec4/previews": likec4AssetsDir
115
- }
116
- },
117
- configFile: false,
118
- mode: "production",
119
- optimizeDeps: {
120
- include: [
121
- "react",
122
- "react-dom",
123
- "react/jsx-runtime",
124
- "react/jsx-dev-runtime",
125
- "react-dom/client",
126
- "@likec4/core/types",
127
- "@likec4/core/model",
128
- "@likec4/core/styles",
129
- "@likec4/core/utils",
130
- "@likec4/core",
131
- "likec4/model",
132
- "likec4/react",
133
- "likec4/vite-plugin/internal"
134
- ],
135
- noDiscovery: true
136
- },
137
- esbuild: { tsconfigRaw: { compilerOptions: {
138
- target: "ESNext",
139
- jsx: "react-jsx"
140
- } } },
141
- define: {
142
- WEBCOMPONENT_PREFIX: JSON.stringify(webcomponentPrefix),
143
- PAGE_TITLE: JSON.stringify(title),
144
- __USE_HASH_HISTORY__: cfg?.useHashHistory === true ? "true" : "false",
145
- "process.env.NODE_ENV": "\"production\""
146
- },
147
- build: {
148
- outDir,
149
- emptyOutDir: false,
150
- sourcemap: false,
151
- cssMinify: false,
152
- minify: true,
153
- copyPublicDir: true,
154
- chunkSizeWarningLimit,
155
- assetsInlineLimit: 1e5,
156
- rollupOptions: {
157
- treeshake: { preset: "recommended" },
158
- ...!isSingleFile && {
159
- input: [
160
- resolve(root, "index.html"),
161
- resolve(root, "src", "main.js"),
162
- resolve(root, "src", "fonts.css"),
163
- resolve(root, "src", "style.css")
164
- ],
165
- output: { manualChunks: (id) => {
166
- if (id.endsWith(".css") || id.endsWith(".html") || id.includes("likec4/icons")) return;
167
- if (id.includes("__app__")) {
168
- let match = id.match(/__app__\/src\/([\w]+)\.js/)?.[1];
169
- if (match) return match[1];
170
- return;
171
- }
172
- if (id.includes("node_modules/likec4") || id.includes("node_modules/@likec4")) return "likec4";
173
- if (id.includes("node_modules")) return "vendors";
174
- } }
175
- }
176
- }
177
- },
178
- customLogger,
179
- plugins: [
180
- react(),
181
- LikeC4VitePlugin({ languageServices: languageServices.languageServices }),
182
- isSingleFile ? viteSingleFile() : void 0
183
- ]
184
- };
185
- };
186
-
187
- //#endregion
188
- export { mkTempPublicDir as a, chunkSizeWarningLimit as i, viteAliases as n, viteAppRoot as o, JsBanners as r, viteConfig as t };
@@ -1,71 +0,0 @@
1
- import { t as u } from "./libs/tinyrainbow.mjs";
2
- import { i as createLikeC4Logger } from "./module.mjs";
3
- import { i as chunkSizeWarningLimit, n as viteAliases, o as viteAppRoot, r as JsBanners } from "./config-app.prod.mjs";
4
- import { t as LikeC4VitePlugin } from "./plugin.mjs";
5
- import react from "@vitejs/plugin-react";
6
-
7
- //#region src/vite/config-webcomponent.prod.ts
8
- async function viteWebcomponentConfig({ languageServices, outDir, base, webcomponentPrefix = "likec4", filename = "likec4-views.js" }) {
9
- const customLogger = createLikeC4Logger(["vite", "webcomponent"]);
10
- const root = viteAppRoot();
11
- customLogger.info(u.cyan("outDir") + " " + u.dim(outDir));
12
- return {
13
- root,
14
- clearScreen: false,
15
- base,
16
- configFile: false,
17
- publicDir: false,
18
- mode: "production",
19
- resolve: {
20
- conditions: ["production"],
21
- alias: viteAliases(),
22
- dedupe: [
23
- "react",
24
- "react-dom",
25
- "react/jsx-runtime",
26
- "react/jsx-dev-runtime",
27
- "react-dom/client"
28
- ]
29
- },
30
- define: {
31
- WEBCOMPONENT_PREFIX: JSON.stringify(webcomponentPrefix),
32
- "process.env.NODE_ENV": "\"production\""
33
- },
34
- esbuild: {
35
- ...JsBanners,
36
- tsconfigRaw: { compilerOptions: {
37
- target: "ESNext",
38
- jsx: "react-jsx"
39
- } }
40
- },
41
- build: {
42
- outDir,
43
- emptyOutDir: false,
44
- sourcemap: false,
45
- minify: true,
46
- assetsInlineLimit: 1024 * 1024,
47
- chunkSizeWarningLimit,
48
- lib: {
49
- entry: "src/webcomponent.js",
50
- fileName(_format, _entryName) {
51
- return filename;
52
- },
53
- formats: ["iife"],
54
- name: "LikeC4Views"
55
- },
56
- rollupOptions: {
57
- treeshake: { preset: "recommended" },
58
- output: {
59
- format: "iife",
60
- hoistTransitiveImports: false,
61
- compact: true
62
- }
63
- }
64
- },
65
- customLogger,
66
- plugins: [react(), LikeC4VitePlugin({ languageServices: languageServices.languageServices })]
67
- };
68
- }
69
-
70
- //#endregion
71
- export { viteWebcomponentConfig as t };