@highstate/cli 0.9.20 → 0.9.21
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/dist/highstate.manifest.json +1 -1
- package/dist/{library-loader-6TJTW2HX.js → library-loader-PZWYMBAE.js} +3 -3
- package/dist/{library-loader-6TJTW2HX.js.map → library-loader-PZWYMBAE.js.map} +1 -1
- package/dist/main.js +212 -186
- package/dist/main.js.map +1 -1
- package/package.json +10 -5
- package/src/commands/build.ts +13 -71
- package/src/commands/designer.ts +2 -2
- package/src/commands/package/create.ts +3 -3
- package/src/commands/package/index.ts +2 -2
- package/src/main.ts +4 -4
- package/src/shared/entry-points.ts +116 -0
- package/src/shared/index.ts +4 -3
- package/src/shared/library-loader.ts +1 -1
- package/src/shared/logger.ts +1 -1
- package/src/shared/schema-transformer.spec.ts +2 -1
- package/src/shared/schema-transformer.ts +5 -5
- package/src/shared/source-hash-calculator.ts +5 -5
- package/src/shared/workspace.ts +2 -9
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Command, Option } from "clipanion"
|
|
2
2
|
import {
|
|
3
|
-
findWorkspaceRoot,
|
|
4
3
|
createPackage,
|
|
5
|
-
|
|
6
|
-
scanWorkspacePackages,
|
|
4
|
+
findWorkspaceRoot,
|
|
7
5
|
highstateConfigSchema,
|
|
6
|
+
scanWorkspacePackages,
|
|
7
|
+
updateTsconfigReferences,
|
|
8
8
|
} from "../../shared"
|
|
9
9
|
|
|
10
10
|
export class CreateCommand extends Command {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { UpdateReferencesCommand } from "./update-references"
|
|
2
|
-
export { ListCommand } from "./list"
|
|
3
1
|
export { CreateCommand } from "./create"
|
|
2
|
+
export { ListCommand } from "./list"
|
|
4
3
|
export { RemoveCommand } from "./remove"
|
|
4
|
+
export { UpdateReferencesCommand } from "./update-references"
|
package/src/main.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Builtins, Cli } from "clipanion"
|
|
2
2
|
import { version } from "../package.json"
|
|
3
|
-
import { DesignerCommand } from "./commands/designer"
|
|
4
|
-
import { BuildCommand } from "./commands/build"
|
|
5
3
|
import { BackendIdentityCommand } from "./commands/backend/identity"
|
|
4
|
+
import { BuildCommand } from "./commands/build"
|
|
5
|
+
import { DesignerCommand } from "./commands/designer"
|
|
6
6
|
import {
|
|
7
|
-
UpdateReferencesCommand,
|
|
8
|
-
ListCommand as PackageListCommand,
|
|
9
7
|
CreateCommand as PackageCreateCommand,
|
|
8
|
+
ListCommand as PackageListCommand,
|
|
10
9
|
RemoveCommand as PackageRemoveCommand,
|
|
10
|
+
UpdateReferencesCommand,
|
|
11
11
|
} from "./commands/package"
|
|
12
12
|
|
|
13
13
|
const cli = new Cli({
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { PackageJson } from "pkg-types"
|
|
2
|
+
import { logger } from "./logger"
|
|
3
|
+
|
|
4
|
+
export interface EntryPoint {
|
|
5
|
+
targetName: string
|
|
6
|
+
entryPoint: string
|
|
7
|
+
distPath: string
|
|
8
|
+
isBin: boolean
|
|
9
|
+
key: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Extracts entry points from package.json exports and bin fields
|
|
14
|
+
*/
|
|
15
|
+
export function extractEntryPoints(packageJson: PackageJson): Record<string, EntryPoint> {
|
|
16
|
+
const exports = packageJson.exports
|
|
17
|
+
let bin = packageJson.bin
|
|
18
|
+
|
|
19
|
+
if (!exports && !bin) {
|
|
20
|
+
logger.warn("no exports or bin found in package.json")
|
|
21
|
+
return {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (exports !== undefined && (typeof exports !== "object" || Array.isArray(exports))) {
|
|
25
|
+
throw new Error("Exports field in package.json must be an object")
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (bin !== undefined && typeof bin !== "object") {
|
|
29
|
+
if (!packageJson.name) {
|
|
30
|
+
throw new Error("Package name is required when bin is a string")
|
|
31
|
+
}
|
|
32
|
+
bin = { [packageJson.name]: bin as string }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const result: Record<string, EntryPoint> = {}
|
|
36
|
+
|
|
37
|
+
// process exports entries
|
|
38
|
+
if (exports) {
|
|
39
|
+
for (const [key, value] of Object.entries(exports)) {
|
|
40
|
+
let distPath: string
|
|
41
|
+
|
|
42
|
+
if (typeof value === "string") {
|
|
43
|
+
distPath = value
|
|
44
|
+
} else if (typeof value === "object" && !Array.isArray(value)) {
|
|
45
|
+
if (!value.default) {
|
|
46
|
+
throw new Error(`Export "${key}" must have a default field in package.json`)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (typeof value.default !== "string") {
|
|
50
|
+
throw new Error(`Export "${key}" default field must be a string in package.json`)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
distPath = value.default
|
|
54
|
+
} else {
|
|
55
|
+
throw new Error(`Export "${key}" must be a string or an object in package.json`)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!distPath.startsWith("./dist/")) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`The default value of export "${key}" must start with "./dist/" in package.json, got "${distPath}"`,
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!distPath.endsWith(".js")) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`The default value of export "${key}" must end with ".js" in package.json, got "${distPath}"`,
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const targetName = distPath.slice(7).slice(0, -3)
|
|
71
|
+
|
|
72
|
+
result[targetName] = {
|
|
73
|
+
entryPoint: `./src/${targetName}.ts`,
|
|
74
|
+
targetName,
|
|
75
|
+
distPath,
|
|
76
|
+
isBin: false,
|
|
77
|
+
key,
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// process bin entries
|
|
83
|
+
if (bin) {
|
|
84
|
+
for (const [key, value] of Object.entries(bin)) {
|
|
85
|
+
if (typeof value !== "string") {
|
|
86
|
+
throw new Error(`Bin entry "${key}" must be a string in package.json`)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const distPath = value
|
|
90
|
+
|
|
91
|
+
if (!distPath.startsWith("./dist/")) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`The value of bin entry "${key}" must start with "./dist/" in package.json, got "${distPath}"`,
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!distPath.endsWith(".js")) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`The value of bin entry "${key}" must end with ".js" in package.json, got "${distPath}"`,
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const targetName = distPath.slice(7).slice(0, -3)
|
|
104
|
+
|
|
105
|
+
result[targetName] = {
|
|
106
|
+
entryPoint: `./src/${targetName}.ts`,
|
|
107
|
+
targetName,
|
|
108
|
+
distPath,
|
|
109
|
+
isBin: true,
|
|
110
|
+
key,
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return result
|
|
116
|
+
}
|
package/src/shared/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./bin-transformer"
|
|
2
|
+
export * from "./entry-points"
|
|
2
3
|
export * from "./logger"
|
|
3
4
|
export * from "./schema-transformer"
|
|
4
|
-
export * from "./source-hash-calculator"
|
|
5
|
-
export * from "./bin-transformer"
|
|
6
5
|
export * from "./schemas"
|
|
6
|
+
export * from "./services"
|
|
7
|
+
export * from "./source-hash-calculator"
|
|
7
8
|
export * from "./workspace"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Logger } from "pino"
|
|
2
2
|
import console from "node:console"
|
|
3
|
+
import { Crc32, crc32 } from "@aws-crypto/crc32"
|
|
3
4
|
import {
|
|
4
5
|
type Component,
|
|
5
6
|
type ComponentModel,
|
|
@@ -9,7 +10,6 @@ import {
|
|
|
9
10
|
isEntity,
|
|
10
11
|
isUnitModel,
|
|
11
12
|
} from "@highstate/contract"
|
|
12
|
-
import { Crc32, crc32 } from "@aws-crypto/crc32"
|
|
13
13
|
import { encode } from "@msgpack/msgpack"
|
|
14
14
|
import { int32ToBytes } from "./utils"
|
|
15
15
|
|
package/src/shared/logger.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe,
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
2
|
import { applySchemaTransformations } from "./schema-transformer"
|
|
3
3
|
|
|
4
4
|
describe("applySchemaTransformations", () => {
|
|
@@ -200,6 +200,7 @@ const spec = {
|
|
|
200
200
|
const result = await applySchemaTransformations(input)
|
|
201
201
|
|
|
202
202
|
expect(result).toContain(
|
|
203
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: it is example code
|
|
203
204
|
"$addArgumentDescription(Type.String(), `This is a description with \\`backticks\\` and \\${template} literals.",
|
|
204
205
|
)
|
|
205
206
|
expect(result).toContain("It also has multiple lines.`)")
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Plugin } from "esbuild"
|
|
2
2
|
import { readFile } from "node:fs/promises"
|
|
3
|
+
import MagicString from "magic-string"
|
|
3
4
|
import {
|
|
4
|
-
parseAsync,
|
|
5
|
-
type Comment,
|
|
6
5
|
type CallExpression,
|
|
7
|
-
type
|
|
6
|
+
type Comment,
|
|
8
7
|
type MemberExpression,
|
|
8
|
+
type ObjectProperty,
|
|
9
|
+
parseAsync,
|
|
9
10
|
} from "oxc-parser"
|
|
10
|
-
import {
|
|
11
|
-
import MagicString from "magic-string"
|
|
11
|
+
import { type Node, walk } from "oxc-walker"
|
|
12
12
|
|
|
13
13
|
export const schemaTransformerPlugin: Plugin = {
|
|
14
14
|
name: "schema-transformer",
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Logger } from "pino"
|
|
2
|
-
import { dirname, relative, resolve } from "node:path"
|
|
3
2
|
import { readFile, writeFile } from "node:fs/promises"
|
|
3
|
+
import { dirname, relative, resolve } from "node:path"
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url"
|
|
5
|
-
import { readPackageJSON, resolvePackageJSON, type PackageJson } from "pkg-types"
|
|
6
5
|
import { crc32 } from "@aws-crypto/crc32"
|
|
7
6
|
import { resolve as importMetaResolve } from "import-meta-resolve"
|
|
7
|
+
import { type PackageJson, readPackageJSON, resolvePackageJSON } from "pkg-types"
|
|
8
8
|
import { z } from "zod"
|
|
9
9
|
import {
|
|
10
|
-
type HighstateManifest,
|
|
11
10
|
type HighstateConfig,
|
|
12
|
-
type
|
|
11
|
+
type HighstateManifest,
|
|
13
12
|
highstateConfigSchema,
|
|
14
13
|
highstateManifestSchema,
|
|
14
|
+
type SourceHashConfig,
|
|
15
15
|
sourceHashConfigSchema,
|
|
16
16
|
} from "./schemas"
|
|
17
17
|
import { int32ToBytes } from "./utils"
|
|
@@ -202,7 +202,7 @@ export class SourceHashCalculator {
|
|
|
202
202
|
return await this.getFileHash(dependency.fullPath)
|
|
203
203
|
}
|
|
204
204
|
case "npm": {
|
|
205
|
-
let resolvedUrl
|
|
205
|
+
let resolvedUrl: string
|
|
206
206
|
try {
|
|
207
207
|
const baseUrl = pathToFileURL(dirname(this.packageJsonPath))
|
|
208
208
|
|
package/src/shared/workspace.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { readdir, readFile, writeFile, mkdir } from "node:fs/promises"
|
|
2
|
-
import { join, relative, resolve } from "node:path"
|
|
3
1
|
import { existsSync } from "node:fs"
|
|
2
|
+
import { mkdir, readdir, readFile, writeFile } from "node:fs/promises"
|
|
3
|
+
import { join, relative, resolve } from "node:path"
|
|
4
4
|
import { z } from "zod"
|
|
5
5
|
import { highstateConfigSchema } from "./schemas"
|
|
6
6
|
|
|
@@ -221,13 +221,6 @@ export async function createPackage(
|
|
|
221
221
|
"utf-8",
|
|
222
222
|
)
|
|
223
223
|
|
|
224
|
-
// create CHANGELOG.md
|
|
225
|
-
await writeFile(
|
|
226
|
-
join(packagePath, "CHANGELOG.md"),
|
|
227
|
-
`# Changelog\n\nAll notable changes to this project will be documented in this file.\n`,
|
|
228
|
-
"utf-8",
|
|
229
|
-
)
|
|
230
|
-
|
|
231
224
|
// create basic index.ts
|
|
232
225
|
await writeFile(join(srcPath, "index.ts"), `// ${name} package\n`, "utf-8")
|
|
233
226
|
|