@highstate/cli 0.20.0 → 0.26.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.
@@ -1,15 +1,17 @@
1
1
  import { readFile } from "node:fs/promises"
2
2
  import { Command, Option } from "clipanion"
3
- import { detectPackageManager } from "nypm"
3
+ import { readPackageJSON, resolvePackageJSON } from "pkg-types"
4
4
  import semver from "semver"
5
5
  import {
6
6
  applyOverrides,
7
7
  buildOverrides,
8
8
  fetchManifest,
9
+ fetchNpmPackument,
9
10
  getDependencyRange,
10
11
  getProjectPlatformVersion,
11
12
  logger,
12
13
  resolveVersionBundle,
14
+ writeJsonFile,
13
15
  } from "../shared"
14
16
 
15
17
  export class UpdateCommand extends Command {
@@ -42,7 +44,7 @@ export class UpdateCommand extends Command {
42
44
  async execute(): Promise<void> {
43
45
  const projectRoot = process.cwd()
44
46
 
45
- const packageManager = await resolveProjectPackageManager(projectRoot)
47
+ await assertPackageJsonExists(projectRoot)
46
48
 
47
49
  if (this.platformOnly && this.stdlibOnly) {
48
50
  throw new Error('Flags "--platform" and "--stdlib" cannot be used together')
@@ -51,55 +53,36 @@ export class UpdateCommand extends Command {
51
53
  const updatePlatform = this.platformOnly || !this.stdlibOnly
52
54
  const updateStdlib = this.stdlibOnly || !this.platformOnly
53
55
 
56
+ let currentPlatformVersion: string | undefined
57
+ let resolvedStdlibVersion = this.stdlibVersion
58
+
54
59
  if (this.stdlibOnly) {
55
- const currentPlatformVersion = await getProjectPlatformVersion(projectRoot, {
56
- packageManager,
57
- })
58
- if (!currentPlatformVersion) {
60
+ const projectPlatformVersion = await getProjectPlatformVersion(projectRoot)
61
+ if (!projectPlatformVersion) {
59
62
  throw new Error('Current platform version is not set in overrides for "@highstate/pulumi"')
60
63
  }
61
64
 
62
- const targetStdlibVersion = (this.stdlibVersion ?? "").trim()
63
- if (targetStdlibVersion.length === 0) {
64
- throw new Error('Flag "--stdlib-version" must be provided when using "--stdlib"')
65
- }
66
-
67
- const stdlibManifest = await fetchManifest("@highstate/library", targetStdlibVersion)
68
- const supportedPlatformRange = getDependencyRange(stdlibManifest, "@highstate/pulumi")
69
- if (!supportedPlatformRange) {
70
- throw new Error(
71
- `Unable to infer "@highstate/pulumi" version from "@highstate/library@${targetStdlibVersion}"`,
72
- )
73
- }
74
-
75
- const validPlatform = semver.valid(currentPlatformVersion)
76
- if (!validPlatform) {
77
- throw new Error(
78
- `Current platform version is not a valid semver "${currentPlatformVersion}"`,
79
- )
80
- }
81
-
82
- const ok = semver.satisfies(validPlatform, supportedPlatformRange, {
83
- includePrerelease: true,
65
+ currentPlatformVersion = projectPlatformVersion
66
+ resolvedStdlibVersion = await resolveCompatibleStdlibVersion({
67
+ currentPlatformVersion: projectPlatformVersion,
68
+ stdlibVersion: this.stdlibVersion,
84
69
  })
85
- if (!ok) {
86
- throw new Error(
87
- `Current platform version "${currentPlatformVersion}" does not satisfy requirement "${supportedPlatformRange}"`,
88
- )
89
- }
90
70
  }
91
71
 
92
72
  const bundle = await resolveVersionBundle({
93
- platformVersion: updatePlatform ? this.platformVersion : undefined,
94
- stdlibVersion: updateStdlib ? this.stdlibVersion : undefined,
73
+ platformVersion: updatePlatform ? this.platformVersion : currentPlatformVersion,
74
+ stdlibVersion: updateStdlib ? resolvedStdlibVersion : undefined,
95
75
  })
96
76
 
97
77
  const overrides = buildOverrides(bundle)
98
78
  await applyOverrides({
99
79
  projectRoot,
100
- packageManager,
101
80
  overrides,
102
81
  })
82
+ await syncRootPulumiDependency({
83
+ projectRoot,
84
+ pulumiVersion: bundle.pulumiVersion,
85
+ })
103
86
 
104
87
  logger.info(
105
88
  "updated overrides: platform=%s stdlib=%s pulumi=%s",
@@ -111,11 +94,11 @@ export class UpdateCommand extends Command {
111
94
  if (this.install) {
112
95
  const { installDependencies } = await import("nypm")
113
96
 
114
- logger.info("installing dependencies using %s...", packageManager)
97
+ logger.info("installing dependencies using bun...")
115
98
 
116
99
  await installDependencies({
117
100
  cwd: projectRoot,
118
- packageManager,
101
+ packageManager: "bun",
119
102
  silent: false,
120
103
  })
121
104
  }
@@ -124,27 +107,78 @@ export class UpdateCommand extends Command {
124
107
  }
125
108
  }
126
109
 
127
- async function resolveProjectPackageManager(projectRoot: string) {
128
- const detected = await detectPackageManager(projectRoot)
129
- if (!detected?.name) {
130
- throw new Error("Unable to detect package manager for this project")
131
- }
110
+ type ResolveCompatibleStdlibVersionArgs = {
111
+ currentPlatformVersion: string
112
+ stdlibVersion?: string
113
+ }
132
114
 
133
- if (detected.name === "bun") {
134
- throw new Error('Package manager "bun" is not supported')
115
+ async function resolveCompatibleStdlibVersion(
116
+ args: ResolveCompatibleStdlibVersionArgs,
117
+ ): Promise<string> {
118
+ const validPlatform = semver.valid(args.currentPlatformVersion)
119
+ if (!validPlatform) {
120
+ throw new Error(
121
+ `Current platform version is not a valid semver "${args.currentPlatformVersion}"`,
122
+ )
135
123
  }
136
124
 
137
- if (detected.name === "deno") {
138
- throw new Error('Package manager "deno" is not supported')
125
+ const targetStdlibVersion = args.stdlibVersion?.trim()
126
+ if (targetStdlibVersion) {
127
+ await assertStdlibSupportsPlatform({
128
+ currentPlatformVersion: validPlatform,
129
+ stdlibVersion: targetStdlibVersion,
130
+ })
131
+
132
+ return targetStdlibVersion
139
133
  }
140
134
 
141
- if (detected.name !== "npm" && detected.name !== "pnpm" && detected.name !== "yarn") {
142
- throw new Error(`Unsupported package manager: "${detected.name}"`)
135
+ const packument = await fetchNpmPackument("@highstate/library")
136
+ const sortedVersions = Object.entries(packument.versions ?? {})
137
+ .filter(([version]) => semver.valid(version))
138
+ .sort(([a], [b]) => semver.rcompare(a, b))
139
+
140
+ for (const [stdlibVersion, stdlibManifest] of sortedVersions) {
141
+ const supportedPlatformRange = getDependencyRange(stdlibManifest, "@highstate/pulumi")
142
+ if (!supportedPlatformRange) {
143
+ continue
144
+ }
145
+
146
+ const ok = semver.satisfies(validPlatform, supportedPlatformRange, {
147
+ includePrerelease: true,
148
+ })
149
+
150
+ if (ok) {
151
+ return stdlibVersion
152
+ }
143
153
  }
144
154
 
145
- await assertPackageJsonExists(projectRoot)
155
+ throw new Error(
156
+ `Unable to find "@highstate/library" version compatible with platform "${validPlatform}"`,
157
+ )
158
+ }
146
159
 
147
- return detected.name
160
+ type StdlibPlatformCompatibilityArgs = {
161
+ currentPlatformVersion: string
162
+ stdlibVersion: string
163
+ }
164
+
165
+ async function assertStdlibSupportsPlatform(args: StdlibPlatformCompatibilityArgs): Promise<void> {
166
+ const stdlibManifest = await fetchManifest("@highstate/library", args.stdlibVersion)
167
+ const supportedPlatformRange = getDependencyRange(stdlibManifest, "@highstate/pulumi")
168
+ if (!supportedPlatformRange) {
169
+ throw new Error(
170
+ `Unable to infer "@highstate/pulumi" version from "@highstate/library@${args.stdlibVersion}"`,
171
+ )
172
+ }
173
+
174
+ const ok = semver.satisfies(args.currentPlatformVersion, supportedPlatformRange, {
175
+ includePrerelease: true,
176
+ })
177
+ if (!ok) {
178
+ throw new Error(
179
+ `Current platform version "${args.currentPlatformVersion}" does not satisfy requirement "${supportedPlatformRange}"`,
180
+ )
181
+ }
148
182
  }
149
183
 
150
184
  async function assertPackageJsonExists(projectRoot: string): Promise<void> {
@@ -154,3 +188,19 @@ async function assertPackageJsonExists(projectRoot: string): Promise<void> {
154
188
  throw new Error(`File "package.json" not found in "${projectRoot}"`)
155
189
  }
156
190
  }
191
+
192
+ async function syncRootPulumiDependency(args: {
193
+ projectRoot: string
194
+ pulumiVersion: string
195
+ }): Promise<void> {
196
+ const packageJsonPath = await resolvePackageJSON(args.projectRoot)
197
+ const packageJson = await readPackageJSON(packageJsonPath)
198
+
199
+ await writeJsonFile(packageJsonPath, {
200
+ ...packageJson,
201
+ dependencies: {
202
+ ...(packageJson.dependencies ?? {}),
203
+ "@pulumi/pulumi": args.pulumiVersion,
204
+ },
205
+ })
206
+ }
@@ -1,8 +1,7 @@
1
- import type { Plugin } from "esbuild"
2
1
  import { readFile } from "node:fs/promises"
3
2
  import { logger } from "./logger"
4
3
 
5
- export function createBinTransformerPlugin(sourceFilePaths: string[]): Plugin {
4
+ export function createBinTransformerPlugin(sourceFilePaths: string[]): Bun.BunPlugin {
6
5
  const filter = new RegExp(`(${sourceFilePaths.join("|")})$`)
7
6
 
8
7
  logger.debug("created bin transformer plugin with filter: %s", filter)
@@ -14,7 +13,7 @@ export function createBinTransformerPlugin(sourceFilePaths: string[]): Plugin {
14
13
  const content = await readFile(args.path, "utf-8")
15
14
 
16
15
  return {
17
- contents: `#!/usr/bin/env node\n\n${content}`,
16
+ contents: `#!/usr/bin/env bun\n\n${content}`,
18
17
  loader: "ts",
19
18
  }
20
19
  })
@@ -5,7 +5,6 @@ export * from "./logger"
5
5
  export * from "./npm-registry"
6
6
  export * from "./overrides"
7
7
  export * from "./package-json"
8
- export * from "./pnpm-workspace"
9
8
  export * from "./project-versions"
10
9
  export * from "./pulumi-cli"
11
10
  export * from "./schema-transformer"
@@ -1,9 +1,6 @@
1
- import type { PackageManagerName } from "nypm"
2
1
  import type { VersionBundle } from "./version-bundle"
3
- import { access } from "node:fs/promises"
4
2
  import { readPackageJSON, resolvePackageJSON } from "pkg-types"
5
3
  import { writeJsonFile } from "./package-json"
6
- import { readPnpmWorkspace, resolvePnpmWorkspacePath, writePnpmWorkspace } from "./pnpm-workspace"
7
4
  import { PLATFORM_PACKAGES, PULUMI_PACKAGES, STDLIB_PACKAGES } from "./version-sets"
8
5
 
9
6
  export type Overrides = Record<string, string>
@@ -23,51 +20,18 @@ export function buildOverrides(bundle: VersionBundle): Overrides {
23
20
  }
24
21
 
25
22
  export type ApplyOverridesArgs = {
26
- packageManager: PackageManagerName
27
23
  overrides: Overrides
28
24
  projectRoot: string
29
25
  }
30
26
 
31
27
  export async function applyOverrides(args: ApplyOverridesArgs): Promise<void> {
32
- const { packageManager, overrides, projectRoot } = args
33
-
34
- if (packageManager === "pnpm") {
35
- const pnpmWorkspacePath = resolvePnpmWorkspacePath(projectRoot)
36
-
37
- try {
38
- await access(pnpmWorkspacePath)
39
- } catch {
40
- throw new Error(`PNPM workspace file is missing: "${pnpmWorkspacePath}"`)
41
- }
42
-
43
- const workspace = await readPnpmWorkspace(pnpmWorkspacePath)
44
- const nextWorkspace = {
45
- ...workspace,
46
- overrides,
47
- }
48
-
49
- await writePnpmWorkspace(pnpmWorkspacePath, nextWorkspace)
50
- return
51
- }
28
+ const { overrides, projectRoot } = args
52
29
 
53
30
  const packageJsonPath = await resolvePackageJSON(projectRoot)
54
31
  const packageJson = await readPackageJSON(projectRoot)
55
32
 
56
- if (packageManager === "npm") {
57
- await writeJsonFile(packageJsonPath, {
58
- ...packageJson,
59
- overrides,
60
- })
61
- return
62
- }
63
-
64
- if (packageManager === "yarn") {
65
- await writeJsonFile(packageJsonPath, {
66
- ...packageJson,
67
- resolutions: overrides,
68
- })
69
- return
70
- }
71
-
72
- await writeJsonFile(packageJsonPath, packageJson)
33
+ await writeJsonFile(packageJsonPath, {
34
+ ...packageJson,
35
+ overrides,
36
+ })
73
37
  }
@@ -1,54 +1,29 @@
1
- import type { PackageManagerName } from "nypm"
2
1
  import type { PackageJson } from "pkg-types"
3
2
  import { readFile } from "node:fs/promises"
4
3
  import { resolvePackageJSON } from "pkg-types"
5
- import { readPnpmWorkspace, resolvePnpmWorkspacePath } from "./pnpm-workspace"
6
4
 
7
5
  export async function getProjectOverrideVersion(
8
6
  projectRoot: string,
9
- args: { packageManager: PackageManagerName; packageName: string },
7
+ args: { packageName: string },
10
8
  ): Promise<string | null> {
11
- const { packageManager, packageName } = args
12
-
13
- if (packageManager === "pnpm") {
14
- const path = resolvePnpmWorkspacePath(projectRoot)
15
- const workspace = await readPnpmWorkspace(path)
16
- return workspace.overrides?.[packageName] ?? null
17
- }
9
+ const { packageName } = args
18
10
 
19
11
  const packageJsonPath = await resolvePackageJSON(projectRoot)
20
12
  const rawPackageJson = await readFile(packageJsonPath, "utf8")
21
13
  const packageJson = JSON.parse(rawPackageJson) as PackageJson
22
14
 
23
- if (packageManager === "npm") {
24
- const overrides = packageJson.overrides as Record<string, string> | undefined
25
- return overrides?.[packageName] ?? null
26
- }
27
-
28
- if (packageManager === "yarn") {
29
- const resolutions = packageJson.resolutions as Record<string, string> | undefined
30
- return resolutions?.[packageName] ?? null
31
- }
32
-
33
- return null
15
+ const overrides = packageJson.overrides as Record<string, string> | undefined
16
+ return overrides?.[packageName] ?? null
34
17
  }
35
18
 
36
- export async function getProjectPlatformVersion(
37
- projectRoot: string,
38
- args: { packageManager: PackageManagerName },
39
- ): Promise<string | null> {
19
+ export async function getProjectPlatformVersion(projectRoot: string): Promise<string | null> {
40
20
  return await getProjectOverrideVersion(projectRoot, {
41
- packageManager: args.packageManager,
42
21
  packageName: "@highstate/pulumi",
43
22
  })
44
23
  }
45
24
 
46
- export async function getProjectPulumiSdkVersion(
47
- projectRoot: string,
48
- args: { packageManager: PackageManagerName },
49
- ): Promise<string | null> {
25
+ export async function getProjectPulumiSdkVersion(projectRoot: string): Promise<string | null> {
50
26
  return await getProjectOverrideVersion(projectRoot, {
51
- packageManager: args.packageManager,
52
27
  packageName: "@pulumi/pulumi",
53
28
  })
54
29
  }
@@ -3,9 +3,12 @@ import { promisify } from "node:util"
3
3
 
4
4
  const execFileAsync = promisify(execFile)
5
5
 
6
- export async function getPulumiCliVersion(cwd: string): Promise<string | null> {
6
+ export async function getPulumiCliVersion(
7
+ cwd: string,
8
+ commandPath = "pulumi",
9
+ ): Promise<string | null> {
7
10
  try {
8
- const { stdout } = await execFileAsync("pulumi", ["version"], {
11
+ const { stdout } = await execFileAsync(commandPath, ["version"], {
9
12
  cwd,
10
13
  })
11
14
 
@@ -1,4 +1,3 @@
1
- import type { Plugin } from "esbuild"
2
1
  import { readFile } from "node:fs/promises"
3
2
  import MagicString from "magic-string"
4
3
  import {
@@ -10,7 +9,7 @@ import {
10
9
  } from "oxc-parser"
11
10
  import { type Node, walk } from "oxc-walker"
12
11
 
13
- export const schemaTransformerPlugin: Plugin = {
12
+ export const schemaTransformerPlugin: Bun.BunPlugin = {
14
13
  name: "schema-transformer",
15
14
  setup(build) {
16
15
  build.onLoad({ filter: /src\/.*\.ts$/ }, async args => {
@@ -1,6 +1,7 @@
1
1
  import type { Logger } from "pino"
2
2
  import { readFile, writeFile } from "node:fs/promises"
3
- import { dirname, relative, resolve } from "node:path"
3
+ import { builtinModules } from "node:module"
4
+ import { dirname, isAbsolute, relative, resolve } from "node:path"
4
5
  import { fileURLToPath, pathToFileURL } from "node:url"
5
6
  import { crc32 } from "@aws-crypto/crc32"
6
7
  import { resolve as importMetaResolve } from "import-meta-resolve"
@@ -53,6 +54,19 @@ export function parseFileDependencies(filePath: string, content: string): FileDe
53
54
  fullPath,
54
55
  })
55
56
  } else if (npmPackage) {
57
+ const normalizedPackageName = npmPackage.startsWith("node:")
58
+ ? npmPackage.slice("node:".length)
59
+ : npmPackage
60
+ const builtinName = normalizedPackageName.split("/")[0]
61
+ if (
62
+ builtinModules.includes(normalizedPackageName) ||
63
+ builtinModules.includes(builtinName) ||
64
+ builtinModules.includes(`node:${normalizedPackageName}`) ||
65
+ builtinModules.includes(`node:${builtinName}`)
66
+ ) {
67
+ continue
68
+ }
69
+
56
70
  dependencies.push({
57
71
  type: "npm",
58
72
  id: `npm:${npmPackage}`,
@@ -255,7 +269,17 @@ export class SourceHashCalculator {
255
269
  // throw new Error(`"${dependency.package}" imported without "node:" prefix`)
256
270
  // }
257
271
 
258
- const resolvedPath = fileURLToPath(resolvedUrl)
272
+ const resolvedPath = this.resolveDependencyPath(dependency.package, resolvedUrl)
273
+ if (!resolvedPath) {
274
+ this.logger.debug(
275
+ `using package version as a fallback hash for "%s" due to unsupported resolver output "%s"`,
276
+ dependency.package,
277
+ resolvedUrl,
278
+ )
279
+
280
+ const [, depPackageJson] = await this.getPackageJsonFromPackageName(dependency.package)
281
+ return this.hashString(depPackageJson.version ?? "0.0.0")
282
+ }
259
283
 
260
284
  const [depPackageJsonPath, depPackageJson] = await this.getPackageJson(resolvedPath)
261
285
  const packageName = depPackageJson.name!
@@ -310,6 +334,35 @@ export class SourceHashCalculator {
310
334
  }
311
335
  }
312
336
 
337
+ private resolveDependencyPath(packageName: string, resolvedUrl: string): string | null {
338
+ if (resolvedUrl.startsWith("file:")) {
339
+ return fileURLToPath(resolvedUrl)
340
+ }
341
+
342
+ if (isAbsolute(resolvedUrl)) {
343
+ return resolvedUrl
344
+ }
345
+
346
+ if (resolvedUrl.startsWith("node:")) {
347
+ return null
348
+ }
349
+
350
+ // Bun resolver may return non-file URL schemes for certain modules.
351
+ if (resolvedUrl.includes(":")) {
352
+ return null
353
+ }
354
+
355
+ const baseDir = dirname(this.packageJsonPath)
356
+ return resolve(baseDir, "node_modules", packageName)
357
+ }
358
+
359
+ private async getPackageJsonFromPackageName(packageName: string): Promise<[string, PackageJson]> {
360
+ const baseDir = dirname(this.packageJsonPath)
361
+ const packagePath = resolve(baseDir, "node_modules", packageName)
362
+
363
+ return await this.getPackageJson(packagePath)
364
+ }
365
+
313
366
  private async getPackageJson(basePath: string): Promise<[string, PackageJson]> {
314
367
  while (true) {
315
368
  const packageJson = await readPackageJSON(basePath)
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Exeteres
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,4 +0,0 @@
1
- {{#if isPnpm}}
2
- packages:
3
- - "packages/*"
4
- {{/if}}
@@ -1 +0,0 @@
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"]}