@highstate/cli 0.9.16 → 0.9.18

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.
@@ -0,0 +1,11 @@
1
+ // src/shared/utils.ts
2
+ function int32ToBytes(value) {
3
+ const buffer = new ArrayBuffer(4);
4
+ const view = new DataView(buffer);
5
+ view.setInt32(0, value, true);
6
+ return new Uint8Array(buffer);
7
+ }
8
+
9
+ export { int32ToBytes };
10
+ //# sourceMappingURL=chunk-CMECLVT7.js.map
11
+ //# sourceMappingURL=chunk-CMECLVT7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/utils.ts"],"names":[],"mappings":";AAAO,SAAS,aAAa,KAAA,EAA2B;AACtD,EAAA,MAAM,MAAA,GAAS,IAAI,WAAA,CAAY,CAAC,CAAA;AAChC,EAAA,MAAM,IAAA,GAAO,IAAI,QAAA,CAAS,MAAM,CAAA;AAChC,EAAA,IAAA,CAAK,QAAA,CAAS,CAAA,EAAG,KAAA,EAAO,IAAI,CAAA;AAC5B,EAAA,OAAO,IAAI,WAAW,MAAM,CAAA;AAC9B","file":"chunk-CMECLVT7.js","sourcesContent":["export function int32ToBytes(value: number): Uint8Array {\n const buffer = new ArrayBuffer(4)\n const view = new DataView(buffer)\n view.setInt32(0, value, true) // true for little-endian\n return new Uint8Array(buffer)\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "sourceHashes": {
3
- "./dist/main.js": "9fd51e93203bb202368349807424add573043c4fe8254095b4f5e4dfa76fedc0"
3
+ "./dist/main.js": 264201095
4
4
  }
5
5
  }
@@ -1,14 +1,9 @@
1
- // src/shared/library-loader.ts
2
- import {
3
- isComponent,
4
- isEntity,
5
- isUnitModel,
6
- originalCreate
7
- } from "@highstate/contract";
8
- import { serializeFunction } from "@pulumi/pulumi/runtime/index.js";
9
- import { Crc32, crc32 } from "@aws-crypto/crc32";
10
- import { encode } from "@msgpack/msgpack";
11
- import { int32ToBytes } from "@highstate/backend/shared";
1
+ import { int32ToBytes } from './chunk-CMECLVT7.js';
2
+ import console from 'console';
3
+ import { isComponent, isEntity, isUnitModel } from '@highstate/contract';
4
+ import { Crc32, crc32 } from '@aws-crypto/crc32';
5
+ import { encode } from '@msgpack/msgpack';
6
+
12
7
  async function loadLibrary(logger, modulePaths) {
13
8
  const modules = {};
14
9
  for (const modulePath of modulePaths) {
@@ -16,8 +11,9 @@ async function loadLibrary(logger, modulePaths) {
16
11
  logger.debug({ modulePath }, "loading module");
17
12
  modules[modulePath] = await import(modulePath);
18
13
  logger.debug({ modulePath }, "module loaded");
19
- } catch (err) {
20
- logger.error({ modulePath, err }, "module load failed");
14
+ } catch (error) {
15
+ console.error(error);
16
+ throw new Error(`Failed to load module "${modulePath}"`, { cause: error });
21
17
  }
22
18
  }
23
19
  const components = {};
@@ -37,22 +33,31 @@ async function _loadLibrary(value, components, entities) {
37
33
  if (isComponent(value)) {
38
34
  const entityHashes = [];
39
35
  for (const entity of value.entities.values()) {
40
- entity.definitionHash ??= calculateEntityDefinitionHash(entity);
41
- entityHashes.push(entity.definitionHash);
36
+ entity.model.definitionHash ??= calculateEntityDefinitionHash(entity);
37
+ entityHashes.push(entity.model.definitionHash);
42
38
  }
43
39
  components[value.model.type] = value.model;
44
40
  value.model.definitionHash = await calculateComponentDefinitionHash(value, entityHashes);
45
41
  return;
46
42
  }
47
43
  if (isEntity(value)) {
48
- entities[value.type] = value;
44
+ entities[value.type] = value.model;
49
45
  entities[value.type].definitionHash ??= calculateEntityDefinitionHash(value);
50
- delete value.schema;
46
+ delete value.model.schema;
51
47
  return;
52
48
  }
53
49
  if (typeof value !== "object" || value === null) {
54
50
  return;
55
51
  }
52
+ if ("_zod" in value) {
53
+ return;
54
+ }
55
+ if (Array.isArray(value)) {
56
+ for (const item of value) {
57
+ await _loadLibrary(item, components, entities);
58
+ }
59
+ return;
60
+ }
56
61
  for (const key in value) {
57
62
  await _loadLibrary(value[key], components, entities);
58
63
  }
@@ -61,7 +66,7 @@ async function calculateComponentDefinitionHash(component, entityHashes) {
61
66
  const result = new Crc32();
62
67
  result.update(encode(component.model));
63
68
  if (!isUnitModel(component.model)) {
64
- const serializedCreate = await serializeFunction(component[originalCreate]);
69
+ const serializedCreate = { text: "TODO: investigate why serializeFunction hangs" };
65
70
  result.update(Buffer.from(serializedCreate.text));
66
71
  }
67
72
  for (const entityHash of entityHashes) {
@@ -70,9 +75,9 @@ async function calculateComponentDefinitionHash(component, entityHashes) {
70
75
  return result.digest();
71
76
  }
72
77
  function calculateEntityDefinitionHash(entity) {
73
- return crc32(encode(entity));
78
+ return crc32(encode(entity.model));
74
79
  }
75
- export {
76
- loadLibrary
77
- };
78
- //# sourceMappingURL=library-loader-CGEPTS4L.js.map
80
+
81
+ export { loadLibrary };
82
+ //# sourceMappingURL=library-loader-ZABUULFB.js.map
83
+ //# sourceMappingURL=library-loader-ZABUULFB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/library-loader.ts"],"names":[],"mappings":";;;;;;AAoBA,eAAsB,WAAA,CAAY,QAAgB,WAAA,EAAyC;AACzF,EAAA,MAAM,UAAmC,EAAC;AAC1C,EAAA,KAAA,MAAW,cAAc,WAAA,EAAa;AACpC,IAAA,IAAI;AACF,MAAA,MAAA,CAAO,KAAA,CAAM,EAAE,UAAA,EAAW,EAAG,gBAAgB,CAAA;AAC7C,MAAA,OAAA,CAAQ,UAAU,CAAA,GAAI,MAAM,OAAO,UAAA,CAAA;AAEnC,MAAA,MAAA,CAAO,KAAA,CAAM,EAAE,UAAA,EAAW,EAAG,eAAe,CAAA;AAAA,IAC9C,SAAS,KAAA,EAAO;AACd,MAAA,OAAA,CAAQ,MAAM,KAAK,CAAA;AAEnB,MAAA,MAAM,IAAI,MAAM,CAAA,uBAAA,EAA0B,UAAU,KAAK,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,IAC3E;AAAA,EACF;AAEA,EAAA,MAAM,aAA6C,EAAC;AACpD,EAAA,MAAM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loader-ZABUULFB.js","sourcesContent":["import type { Logger } from \"pino\"\nimport console from \"console\"\nimport {\n type Component,\n type ComponentModel,\n type Entity,\n type EntityModel,\n isComponent,\n isEntity,\n isUnitModel,\n} from \"@highstate/contract\"\nimport { Crc32, crc32 } from \"@aws-crypto/crc32\"\nimport { encode } from \"@msgpack/msgpack\"\nimport { int32ToBytes } from \"./utils\"\n\nexport type Library = Readonly<{\n components: Readonly<Record<string, ComponentModel>>\n entities: Readonly<Record<string, EntityModel>>\n}>\n\nexport async function loadLibrary(logger: Logger, modulePaths: string[]): Promise<Library> {\n const modules: Record<string, unknown> = {}\n for (const modulePath of modulePaths) {\n try {\n logger.debug({ modulePath }, \"loading module\")\n modules[modulePath] = await import(modulePath)\n\n logger.debug({ modulePath }, \"module loaded\")\n } catch (error) {\n console.error(error)\n\n throw new Error(`Failed to load module \"${modulePath}\"`, { cause: error })\n }\n }\n\n const components: Record<string, ComponentModel> = {}\n const entities: Record<string, EntityModel> = {}\n\n await _loadLibrary(modules, components, entities)\n\n logger.info(\n {\n componentCount: Object.keys(components).length,\n entityCount: Object.keys(entities).length,\n },\n \"library loaded\",\n )\n\n logger.trace({ components, entities }, \"library content\")\n\n return { components, entities }\n}\n\nasync function _loadLibrary(\n value: unknown,\n components: Record<string, ComponentModel>,\n entities: Record<string, EntityModel>,\n): Promise<void> {\n if (isComponent(value)) {\n const entityHashes: number[] = []\n for (const entity of value.entities.values()) {\n entity.model.definitionHash ??= calculateEntityDefinitionHash(entity)\n entityHashes.push(entity.model.definitionHash)\n }\n\n components[value.model.type] = value.model\n value.model.definitionHash = await calculateComponentDefinitionHash(value, entityHashes)\n\n return\n }\n\n if (isEntity(value)) {\n entities[value.type] = value.model\n entities[value.type].definitionHash ??= calculateEntityDefinitionHash(value)\n\n // @ts-expect-error remove the schema since it's not needed in the designer\n delete value.model.schema\n return\n }\n\n if (typeof value !== \"object\" || value === null) {\n return\n }\n\n if (\"_zod\" in value) {\n // this is a zod schema, we can skip it\n return\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n await _loadLibrary(item, components, entities)\n }\n\n return\n }\n\n for (const key in value) {\n await _loadLibrary((value as Record<string, unknown>)[key], components, entities)\n }\n}\n\nasync function calculateComponentDefinitionHash(\n component: Component,\n entityHashes: number[],\n): Promise<number> {\n const result = new Crc32()\n\n // 1. include the full component model\n result.update(encode(component.model))\n\n if (!isUnitModel(component.model)) {\n // 2. for composite components, include the content of the serialized create function\n // const serializedCreate = await serializeFunction(component[originalCreate])\n const serializedCreate = { text: \"TODO: investigate why serializeFunction hangs\" }\n result.update(Buffer.from(serializedCreate.text))\n }\n\n // 3. include the hashes of all entities\n for (const entityHash of entityHashes) {\n result.update(int32ToBytes(entityHash))\n }\n\n return result.digest()\n}\n\nfunction calculateEntityDefinitionHash(entity: Entity): number {\n return crc32(encode(entity.model))\n}\n"]}
package/dist/main.js CHANGED
@@ -1,23 +1,29 @@
1
1
  #!/usr/bin/env node
2
-
3
- // src/main.ts
4
- import { Builtins, Cli } from "clipanion";
2
+ import { int32ToBytes } from './chunk-CMECLVT7.js';
3
+ import { Command, UsageError, Option, Cli, Builtins } from 'clipanion';
4
+ import { readPackageJSON, resolvePackageJSON } from 'pkg-types';
5
+ import { addDevDependency } from 'nypm';
6
+ import { LogLevels, consola } from 'consola';
7
+ import { colorize } from 'consola/utils';
8
+ import { getPort } from 'get-port-please';
9
+ import { PassThrough } from 'node:stream';
10
+ import pino, { levels } from 'pino';
11
+ import { writeFile, readFile } from 'node:fs/promises';
12
+ import { parseAsync } from 'oxc-parser';
13
+ import { walk } from 'oxc-walker';
14
+ import MagicString from 'magic-string';
15
+ import { resolve, dirname, relative } from 'node:path';
16
+ import { pathToFileURL, fileURLToPath } from 'node:url';
17
+ import { crc32 } from '@aws-crypto/crc32';
18
+ import { resolve as resolve$1 } from 'import-meta-resolve';
19
+ import { z } from 'zod';
20
+ import { pipe, mapValues, mapKeys } from 'remeda';
21
+ import { build } from 'tsup';
22
+ import { encode } from '@msgpack/msgpack';
23
+ import { identityToRecipient } from 'age-encryption';
5
24
 
6
25
  // package.json
7
- var version = "0.9.15";
8
-
9
- // src/commands/designer.ts
10
- import { Command, UsageError } from "clipanion";
11
- import { readPackageJSON as readPackageJSON2 } from "pkg-types";
12
- import { addDevDependency } from "nypm";
13
- import { consola as consola2 } from "consola";
14
- import { colorize } from "consola/utils";
15
- import { getPort } from "get-port-please";
16
-
17
- // src/shared/logger.ts
18
- import { PassThrough } from "node:stream";
19
- import pino, { levels } from "pino";
20
- import { consola, LogLevels } from "consola";
26
+ var version = "0.9.17";
21
27
  var logger = pino(
22
28
  {
23
29
  name: "highstate-cli",
@@ -65,7 +71,7 @@ function getBackendServices() {
65
71
  if (services) {
66
72
  return services;
67
73
  }
68
- services = import("@highstate/backend").then(({ getSharedServices }) => {
74
+ services = import('@highstate/backend').then(({ getSharedServices }) => {
69
75
  return getSharedServices({
70
76
  services: {
71
77
  logger: logger.child({}, { msgPrefix: "[backend] " })
@@ -74,12 +80,6 @@ function getBackendServices() {
74
80
  });
75
81
  return services;
76
82
  }
77
-
78
- // src/shared/schema-transformer.ts
79
- import { readFile } from "node:fs/promises";
80
- import { parseAsync } from "oxc-parser";
81
- import { walk } from "oxc-walker";
82
- import MagicString from "magic-string";
83
83
  var schemaTransformerPlugin = {
84
84
  name: "schema-transformer",
85
85
  setup(build2) {
@@ -93,12 +93,29 @@ var schemaTransformerPlugin = {
93
93
  }
94
94
  };
95
95
  async function applySchemaTransformations(content) {
96
- const magicString = new MagicString(content);
97
96
  const { program, comments } = await parseAsync("file.ts", content);
97
+ const transformations = [];
98
98
  const parentStack = [];
99
99
  walk(program, {
100
100
  enter(node) {
101
101
  parentStack.push(node);
102
+ if (node.type === "Property" && node.key.type === "Identifier" && isInsideZodObject(parentStack)) {
103
+ const jsdoc2 = comments.find((comment) => isLeadingComment(content, node, comment));
104
+ if (jsdoc2) {
105
+ const description2 = cleanJsdoc(jsdoc2.value);
106
+ const fieldName = node.key.name;
107
+ const originalValue2 = content.substring(node.value.start, node.value.end);
108
+ if (!originalValue2.includes(".meta(")) {
109
+ transformations.push({
110
+ start: node.value.start,
111
+ end: node.value.end,
112
+ newValue: `${originalValue2}.meta({ title: __camelCaseToHumanReadable("${fieldName}"), description: \`${description2}\` })`,
113
+ type: "zod-meta"
114
+ });
115
+ }
116
+ }
117
+ return;
118
+ }
102
119
  if (node.type !== "Property" || node.key.type !== "Identifier") {
103
120
  return;
104
121
  }
@@ -116,35 +133,112 @@ async function applySchemaTransformations(content) {
116
133
  const isAlreadyStructured = isStructuredValue(originalValue, entityField);
117
134
  if (isAlreadyStructured) {
118
135
  const modifiedValue = injectDescriptionIntoObject(originalValue, description);
119
- magicString.update(node.value.start, node.value.end, modifiedValue);
136
+ transformations.push({
137
+ start: node.value.start,
138
+ end: node.value.end,
139
+ newValue: modifiedValue,
140
+ type: "schema-structure"
141
+ });
120
142
  } else {
121
- magicString.update(
122
- node.value.start,
123
- node.value.end,
124
- `{
143
+ transformations.push({
144
+ start: node.value.start,
145
+ end: node.value.end,
146
+ newValue: `{
125
147
  ${entityField}: ${originalValue},
126
148
  meta: {
127
149
  description: \`${description}\`,
128
150
  },
129
- }`
130
- );
151
+ }`,
152
+ type: "schema-structure"
153
+ });
131
154
  }
132
155
  },
133
156
  leave() {
134
157
  parentStack.pop();
135
158
  }
136
159
  });
137
- return magicString.toString();
160
+ const zodMetaTransformations = transformations.filter((t) => t.type === "zod-meta");
161
+ const schemaTransformations = transformations.filter((t) => t.type === "schema-structure");
162
+ const processedSchemaTransformations = schemaTransformations.map((schemaTransform) => {
163
+ const containedZodMetas = zodMetaTransformations.filter((zodTransform) => {
164
+ return schemaTransform.start <= zodTransform.start && schemaTransform.end >= zodTransform.end;
165
+ });
166
+ if (containedZodMetas.length > 0) {
167
+ const originalContent = content.substring(schemaTransform.start, schemaTransform.end);
168
+ const tempMagicString = new MagicString(originalContent);
169
+ containedZodMetas.sort((a, b) => b.start - a.start).forEach((zodTransform) => {
170
+ const relativeStart = zodTransform.start - schemaTransform.start;
171
+ const relativeEnd = zodTransform.end - schemaTransform.start;
172
+ tempMagicString.update(relativeStart, relativeEnd, zodTransform.newValue);
173
+ });
174
+ const modifiedContent = tempMagicString.toString();
175
+ const entityField = schemaTransform.newValue.includes("entity:") ? "entity" : "schema";
176
+ const descriptionMatch = schemaTransform.newValue.match(/description: `([^`]+)`/);
177
+ if (descriptionMatch) {
178
+ const description = descriptionMatch[1];
179
+ const isAlreadyStructured = isStructuredValue(
180
+ content.substring(schemaTransform.start, schemaTransform.end),
181
+ entityField
182
+ );
183
+ if (isAlreadyStructured) {
184
+ return {
185
+ ...schemaTransform,
186
+ newValue: injectDescriptionIntoObject(modifiedContent, description),
187
+ containsZodMeta: true
188
+ };
189
+ } else {
190
+ return {
191
+ ...schemaTransform,
192
+ newValue: `{
193
+ ${entityField}: ${modifiedContent},
194
+ meta: {
195
+ description: \`${description}\`,
196
+ },
197
+ }`,
198
+ containsZodMeta: true
199
+ };
200
+ }
201
+ }
202
+ }
203
+ return { ...schemaTransform, containsZodMeta: false };
204
+ });
205
+ const independentZodMetas = zodMetaTransformations.filter((zodTransform) => {
206
+ return !schemaTransformations.some((schemaTransform) => {
207
+ return schemaTransform.start <= zodTransform.start && schemaTransform.end >= zodTransform.end;
208
+ });
209
+ });
210
+ const finalTransformations = [
211
+ ...independentZodMetas,
212
+ ...processedSchemaTransformations.map(({ containsZodMeta, ...rest }) => rest)
213
+ // eslint-disable-line @typescript-eslint/no-unused-vars
214
+ ];
215
+ const hasZodMetaTransformations = zodMetaTransformations.length > 0;
216
+ const needsImport = hasZodMetaTransformations && !content.includes("__camelCaseToHumanReadable");
217
+ let result = content;
218
+ const magicString = new MagicString(result);
219
+ finalTransformations.sort((a, b) => b.start - a.start).forEach((transformation) => {
220
+ magicString.update(transformation.start, transformation.end, transformation.newValue);
221
+ });
222
+ result = magicString.toString();
223
+ if (needsImport) {
224
+ result = 'import { camelCaseToHumanReadable as __camelCaseToHumanReadable } from "@highstate/contract"\n' + result;
225
+ }
226
+ return result;
138
227
  }
139
228
  function injectDescriptionIntoObject(objectString, description) {
140
229
  const trimmed = objectString.trim();
141
230
  const metaRegex = /meta\s*:\s*\{/;
142
231
  if (metaRegex.test(trimmed)) {
143
- return trimmed.replace(
144
- /meta\s*:\s*\{/,
145
- `meta: {
232
+ const hasDescription = /meta\s*:\s*\{[^}]*description\s*:/.test(trimmed);
233
+ if (hasDescription) {
234
+ return trimmed.replace(/description\s*:\s*`[^`]*`/, `description: \`${description}\``);
235
+ } else {
236
+ return trimmed.replace(
237
+ /meta\s*:\s*\{/,
238
+ `meta: {
146
239
  description: \`${description}\`,`
147
- );
240
+ );
241
+ }
148
242
  } else {
149
243
  const lastBraceIndex = trimmed.lastIndexOf("}");
150
244
  if (lastBraceIndex === -1) {
@@ -200,19 +294,41 @@ function isLeadingComment(content, node, comment) {
200
294
  function cleanJsdoc(str) {
201
295
  return str.replace(/^\s*\*/gm, "").replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\${/g, "\\${").trim();
202
296
  }
203
-
204
- // src/shared/source-hash-calculator.ts
205
- import { dirname, relative, resolve } from "node:path";
206
- import { readFile as readFile2, writeFile } from "node:fs/promises";
207
- import { fileURLToPath, pathToFileURL } from "node:url";
208
- import { readPackageJSON, resolvePackageJSON } from "pkg-types";
209
- import { crc32 } from "@aws-crypto/crc32";
210
- import { resolve as importMetaResolve } from "import-meta-resolve";
211
- import { z as z2 } from "zod";
212
- import { int32ToBytes } from "@highstate/backend/shared";
213
-
214
- // src/shared/schemas.ts
215
- import { z } from "zod";
297
+ function isInsideZodObject(parentStack) {
298
+ for (let i = parentStack.length - 1; i >= 0; i--) {
299
+ const node = parentStack[i];
300
+ if (node.type === "CallExpression" && node.callee.type === "MemberExpression" && isZodObjectCall(node.callee)) {
301
+ return true;
302
+ }
303
+ }
304
+ return false;
305
+ }
306
+ function isZodObjectCall(memberExpression) {
307
+ if (memberExpression.type !== "MemberExpression") {
308
+ return false;
309
+ }
310
+ if (memberExpression.object.type === "Identifier" && memberExpression.object.name === "z" && memberExpression.property.type === "Identifier" && memberExpression.property.name === "object") {
311
+ return true;
312
+ }
313
+ if (memberExpression.property.type === "Identifier" && memberExpression.property.name === "object" && memberExpression.object.type === "CallExpression" && memberExpression.object.callee.type === "MemberExpression") {
314
+ return startsWithZodCall(memberExpression.object);
315
+ }
316
+ return false;
317
+ }
318
+ function startsWithZodCall(callExpression) {
319
+ if (!callExpression || callExpression.type !== "CallExpression") {
320
+ return false;
321
+ }
322
+ if (callExpression.callee.type === "MemberExpression") {
323
+ if (callExpression.callee.object.type === "Identifier" && callExpression.callee.object.name === "z") {
324
+ return true;
325
+ }
326
+ if (callExpression.callee.object.type === "CallExpression") {
327
+ return startsWithZodCall(callExpression.callee.object);
328
+ }
329
+ }
330
+ return false;
331
+ }
216
332
  var sourceHashConfigSchema = z.discriminatedUnion("mode", [
217
333
  z.object({
218
334
  mode: z.literal("manual"),
@@ -278,7 +394,7 @@ var SourceHashCalculator = class {
278
394
  if (singleConfigResult.success) {
279
395
  return singleConfigResult.data;
280
396
  }
281
- const recordConfigResult = z2.record(z2.string(), sourceHashConfigSchema).safeParse(highstateConfig.sourceHash);
397
+ const recordConfigResult = z.record(z.string(), sourceHashConfigSchema).safeParse(highstateConfig.sourceHash);
282
398
  if (recordConfigResult.success && exportKey) {
283
399
  const perOutputConfig = recordConfigResult.data[exportKey];
284
400
  if (perOutputConfig) {
@@ -353,7 +469,7 @@ var SourceHashCalculator = class {
353
469
  return hash;
354
470
  }
355
471
  async calculateFileHash(fullPath) {
356
- const content = await readFile2(fullPath, "utf8");
472
+ const content = await readFile(fullPath, "utf8");
357
473
  const fileDeps = this.parseDependencies(fullPath, content);
358
474
  const hashes = await Promise.all([
359
475
  this.hashString(content),
@@ -379,7 +495,7 @@ var SourceHashCalculator = class {
379
495
  let resolvedUrl;
380
496
  try {
381
497
  const baseUrl = pathToFileURL(dirname(this.packageJsonPath));
382
- resolvedUrl = importMetaResolve(dependency.package, baseUrl.toString());
498
+ resolvedUrl = resolve$1(dependency.package, baseUrl.toString());
383
499
  } catch (error) {
384
500
  this.logger.error(`failed to resolve package "%s"`, dependency.package);
385
501
  throw error;
@@ -407,7 +523,7 @@ var SourceHashCalculator = class {
407
523
  );
408
524
  let manifest;
409
525
  try {
410
- const manifestContent = await readFile2(highstateManifestPath, "utf8");
526
+ const manifestContent = await readFile(highstateManifestPath, "utf8");
411
527
  manifest = highstateManifestSchema.parse(JSON.parse(manifestContent));
412
528
  } catch (error) {
413
529
  this.logger.debug(
@@ -455,15 +571,11 @@ var SourceHashCalculator = class {
455
571
  id: `npm:${npmPackage}`,
456
572
  package: npmPackage
457
573
  });
458
- } else if (nodeBuiltin) {
459
- }
574
+ } else ;
460
575
  }
461
576
  return dependencies;
462
577
  }
463
578
  };
464
-
465
- // src/shared/bin-transformer.ts
466
- import { readFile as readFile3 } from "node:fs/promises";
467
579
  function createBinTransformerPlugin(sourceFilePaths) {
468
580
  const filter = new RegExp(`(${sourceFilePaths.join("|")})$`);
469
581
  logger.debug("created bin transformer plugin with filter: %s", filter);
@@ -471,7 +583,7 @@ function createBinTransformerPlugin(sourceFilePaths) {
471
583
  name: "bin-transformer",
472
584
  setup(build2) {
473
585
  build2.onLoad({ filter }, async (args) => {
474
- const content = await readFile3(args.path, "utf-8");
586
+ const content = await readFile(args.path, "utf-8");
475
587
  return {
476
588
  contents: `#!/usr/bin/env node
477
589
 
@@ -491,7 +603,7 @@ var DesignerCommand = class extends Command {
491
603
  description: "Starts the Highstate designer in the current project."
492
604
  });
493
605
  async execute() {
494
- const packageJson = await readPackageJSON2();
606
+ const packageJson = await readPackageJSON();
495
607
  if (!packageJson.devDependencies?.["@highstate/cli"]) {
496
608
  throw new UsageError(
497
609
  "This project is not a Highstate project.\n@highstate/cli must be installed as a devDependency."
@@ -517,7 +629,7 @@ var DesignerCommand = class extends Command {
517
629
  void import(path);
518
630
  });
519
631
  console.log = oldConsoleLog;
520
- consola2.log(
632
+ consola.log(
521
633
  [
522
634
  "\n ",
523
635
  colorize("bold", colorize("cyanBright", "Highstate Designer")),
@@ -529,23 +641,14 @@ var DesignerCommand = class extends Command {
529
641
  );
530
642
  process.on("SIGINT", () => {
531
643
  process.stdout.write("\r");
532
- consola2.info("shutting down highstate designer...");
644
+ consola.info("shutting down highstate designer...");
533
645
  setTimeout(() => process.exit(0), 1e3);
534
646
  });
535
647
  }
536
648
  };
537
-
538
- // src/commands/build.ts
539
- import { resolve as resolve2 } from "node:path";
540
- import { writeFile as writeFile2 } from "node:fs/promises";
541
- import { Command as Command2, Option } from "clipanion";
542
- import { readPackageJSON as readPackageJSON3, resolvePackageJSON as resolvePackageJSON2 } from "pkg-types";
543
- import { mapKeys, mapValues, pipe } from "remeda";
544
- import { build } from "tsup";
545
- import { encode } from "@msgpack/msgpack";
546
- var BuildCommand = class extends Command2 {
649
+ var BuildCommand = class extends Command {
547
650
  static paths = [["build"]];
548
- static usage = Command2.Usage({
651
+ static usage = Command.Usage({
549
652
  category: "Builder",
550
653
  description: "Builds the Highstate library or unit package."
551
654
  });
@@ -554,7 +657,7 @@ var BuildCommand = class extends Command2 {
554
657
  silent = Option.Boolean("--silent", true);
555
658
  noSourceHash = Option.Boolean("--no-source-hash", false);
556
659
  async execute() {
557
- const packageJson = await readPackageJSON3();
660
+ const packageJson = await readPackageJSON();
558
661
  const highstateConfig = highstateConfigSchema.parse(packageJson.highstate ?? {});
559
662
  if (highstateConfig.type === "library") {
560
663
  this.library = true;
@@ -638,10 +741,11 @@ var BuildCommand = class extends Command2 {
638
741
  external: ["@pulumi/pulumi"],
639
742
  esbuildPlugins,
640
743
  treeshake: true,
744
+ removeNodeProtocol: false,
641
745
  silent: this.silent || ["warn", "error", "fatal"].includes(logger.level)
642
746
  });
643
- const packageJsonPath = await resolvePackageJSON2();
644
- const upToDatePackageJson = await readPackageJSON3();
747
+ const packageJsonPath = await resolvePackageJSON();
748
+ const upToDatePackageJson = await readPackageJSON();
645
749
  if (!this.noSourceHash) {
646
750
  const sourceHashCalculator = new SourceHashCalculator(
647
751
  packageJsonPath,
@@ -655,29 +759,25 @@ var BuildCommand = class extends Command2 {
655
759
  await sourceHashCalculator.writeHighstateManifest("./dist", distPathToExportKey);
656
760
  }
657
761
  if (this.library) {
658
- const { loadLibrary } = await import("./library-loader-CGEPTS4L.js");
659
- const fullModulePaths = Object.values(entry).map((value) => resolve2(value.distPath));
762
+ const { loadLibrary } = await import('./library-loader-ZABUULFB.js');
763
+ const fullModulePaths = Object.values(entry).map((value) => resolve(value.distPath));
660
764
  logger.info("evaluating library components from modules: %s", fullModulePaths.join(", "));
661
765
  const library = await loadLibrary(logger, fullModulePaths);
662
- const libraryPath = resolve2("./dist", "highstate.library.msgpack");
663
- await writeFile2(libraryPath, encode(library), "utf8");
766
+ const libraryPath = resolve("./dist", "highstate.library.msgpack");
767
+ await writeFile(libraryPath, encode(library), "utf8");
664
768
  }
665
769
  logger.info("build completed successfully");
666
770
  }
667
771
  };
668
-
669
- // src/commands/backend/identity.ts
670
- import { Command as Command3 } from "clipanion";
671
- import { identityToRecipient } from "age-encryption";
672
- var BackendIdentityCommand = class extends Command3 {
772
+ var BackendIdentityCommand = class extends Command {
673
773
  static paths = [["backend", "identity"]];
674
- static usage = Command3.Usage({
774
+ static usage = Command.Usage({
675
775
  category: "Backend",
676
776
  description: "Ensures the backend identity is set up and returns the recipient."
677
777
  });
678
778
  async execute() {
679
779
  const backendLogger = logger.child({}, { msgPrefix: "[backend] " });
680
- const { getOrCreateBackendIdentity } = await import("@highstate/backend");
780
+ const { getOrCreateBackendIdentity } = await import('@highstate/backend');
681
781
  const backendIdentity = await getOrCreateBackendIdentity(backendLogger);
682
782
  const recipient = await identityToRecipient(backendIdentity);
683
783
  logger.info(`stored backend identity is: ${recipient}`);
@@ -697,4 +797,5 @@ cli.register(BackendIdentityCommand);
697
797
  cli.register(Builtins.HelpCommand);
698
798
  cli.register(Builtins.VersionCommand);
699
799
  await cli.runExit(process.argv.slice(2));
800
+ //# sourceMappingURL=main.js.map
700
801
  //# sourceMappingURL=main.js.map