From 463643ca12abe96ef806fd63ed9f344eed4821a0 Mon Sep 17 00:00:00 2001 From: Jorge Lanzarotti Date: Tue, 7 Oct 2025 09:37:49 +0900 Subject: [PATCH 1/5] Fix conflicts user-configuration.ts --- packages/sst/src/credentials.ts | 3 ++- packages/sst/src/stacks/deploy.ts | 3 ++- packages/sst/src/stacks/synth.ts | 3 ++- packages/sst/src/util/user-configuration.ts | 14 ++++++++++---- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/sst/src/credentials.ts b/packages/sst/src/credentials.ts index dc506e222..052d8f9ea 100644 --- a/packages/sst/src/credentials.ts +++ b/packages/sst/src/credentials.ts @@ -1,4 +1,5 @@ import path from "path"; +import { fileURLToPath } from "url"; import type { AwsCredentialIdentityProvider } from "@aws-sdk/types"; import { fromNodeProviderChain } from "@aws-sdk/credential-providers"; import { GetCallerIdentityCommand, STSClient } from "@aws-sdk/client-sts"; @@ -146,7 +147,7 @@ export function useAWSClient( export const useAWSProvider = lazy(async () => { const cdkToolkitUrl = await import.meta.resolve!("@aws-cdk/toolkit-lib"); - const cdkToolkitPath = new URL(cdkToolkitUrl).pathname; + const cdkToolkitPath = fileURLToPath(cdkToolkitUrl); const { SdkProvider } = await import( path.resolve(cdkToolkitPath, "..", "api", "aws-auth", "sdk-provider.js") ); diff --git a/packages/sst/src/stacks/deploy.ts b/packages/sst/src/stacks/deploy.ts index a0c6071cb..80b621aab 100644 --- a/packages/sst/src/stacks/deploy.ts +++ b/packages/sst/src/stacks/deploy.ts @@ -1,4 +1,5 @@ import path from "path"; +import { fileURLToPath } from "url"; import { useBus } from "../bus.js"; import { ConfigOptions, useProject } from "../project.js"; import { useAWSClient, useAWSProvider } from "../credentials.js"; @@ -249,7 +250,7 @@ async function addInUseExports( async function createCdkDeployments() { const cdkToolkitUrl = await import.meta.resolve!("@aws-cdk/toolkit-lib"); - const cdkToolkitPath = new URL(cdkToolkitUrl).pathname; + const cdkToolkitPath = fileURLToPath(cdkToolkitUrl); const { Deployments } = await import( path.resolve(cdkToolkitPath, "..", "api", "deployments", "deployments.js") ); diff --git a/packages/sst/src/stacks/synth.ts b/packages/sst/src/stacks/synth.ts index 1963dc55e..479681191 100644 --- a/packages/sst/src/stacks/synth.ts +++ b/packages/sst/src/stacks/synth.ts @@ -3,6 +3,7 @@ import type { App } from "../constructs/App.js"; import { useProject } from "../project.js"; import { useAWSProvider, useSTSIdentity } from "../credentials.js"; import path from "path"; +import { fileURLToPath } from "url"; import { VisibleError } from "../error.js"; import { Semaphore } from "../util/semaphore.js"; import { Configuration } from "../util/user-configuration.js"; @@ -24,7 +25,7 @@ export async function synth(opts: SynthOptions) { const cxapi = await import("@aws-cdk/cx-api"); const cdkToolkitUrl = await import.meta.resolve!("@aws-cdk/toolkit-lib"); - const cdkToolkitPath = new URL(cdkToolkitUrl).pathname; + const cdkToolkitPath = fileURLToPath(cdkToolkitUrl); const { IoHelper } = await import( path.resolve(cdkToolkitPath, "..", "api", "io", "private", "io-helper.js") ); diff --git a/packages/sst/src/util/user-configuration.ts b/packages/sst/src/util/user-configuration.ts index ff526add9..f9489ebc9 100644 --- a/packages/sst/src/util/user-configuration.ts +++ b/packages/sst/src/util/user-configuration.ts @@ -2,30 +2,36 @@ import * as os from "os"; import * as fs_path from "path"; import * as fs from "fs"; +import { fileURLToPath, pathToFileURL } from "url"; export const PROJECT_CONFIG = "cdk.json"; export const USER_DEFAULTS = "~/.cdk.json"; const CONTEXT_KEY = "context"; let cdkToolkitPath: string; + try { const cdkToolkitUrl = await import.meta.resolve!("@aws-cdk/toolkit-lib"); - cdkToolkitPath = new URL(cdkToolkitUrl).pathname; + cdkToolkitPath = fileURLToPath(cdkToolkitUrl); } catch (e) { // Fallback for test environment where import.meta.resolve is not available const module = await import("module"); const require = (module as any).createRequire(import.meta.url); cdkToolkitPath = require.resolve("@aws-cdk/toolkit-lib"); } + const { ToolkitError } = await import(cdkToolkitPath); const { Context, PROJECT_CONTEXT } = await import( - fs_path.resolve(cdkToolkitPath, "..", "api", "context.js") + pathToFileURL(fs_path.resolve(cdkToolkitPath, "..", "api", "context.js")).href ); const { Settings } = await import( - fs_path.resolve(cdkToolkitPath, "..", "api", "settings.js") + pathToFileURL(fs_path.resolve(cdkToolkitPath, "..", "api", "settings.js")) + .href ); const { Tags } = await import( - fs_path.resolve(cdkToolkitPath, "..", "api", "tags", "index.js") + pathToFileURL( + fs_path.resolve(cdkToolkitPath, "..", "api", "tags", "index.js") + ).href ); export enum Command { From 19161a59c248cc307b68f3cdbc1a9c369de7d2bf Mon Sep 17 00:00:00 2001 From: Jorge Lanzarotti Date: Mon, 7 Jul 2025 23:29:48 +0900 Subject: [PATCH 2/5] More fixes --- packages/sst/src/credentials.ts | 14 ++++++++++---- packages/sst/src/stacks/deploy.ts | 10 +++++++--- packages/sst/src/stacks/synth.ts | 15 +++++++++++---- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/packages/sst/src/credentials.ts b/packages/sst/src/credentials.ts index 052d8f9ea..69bf233bc 100644 --- a/packages/sst/src/credentials.ts +++ b/packages/sst/src/credentials.ts @@ -1,5 +1,5 @@ -import path from "path"; -import { fileURLToPath } from "url"; +import fs from "path"; +import { fileURLToPath, pathToFileURL } from "url"; import type { AwsCredentialIdentityProvider } from "@aws-sdk/types"; import { fromNodeProviderChain } from "@aws-sdk/credential-providers"; import { GetCallerIdentityCommand, STSClient } from "@aws-sdk/client-sts"; @@ -149,11 +149,17 @@ export const useAWSProvider = lazy(async () => { const cdkToolkitUrl = await import.meta.resolve!("@aws-cdk/toolkit-lib"); const cdkToolkitPath = fileURLToPath(cdkToolkitUrl); const { SdkProvider } = await import( - path.resolve(cdkToolkitPath, "..", "api", "aws-auth", "sdk-provider.js") + pathToFileURL( + fs.resolve(cdkToolkitPath, "..", "api", "aws-auth", "sdk-provider.js") + ).href ); + const { IoHelper } = await import( - path.resolve(cdkToolkitPath, "..", "api", "io", "private", "io-helper.js") + pathToFileURL( + fs.resolve(cdkToolkitPath, "..", "api", "io", "private", "io-helper.js") + ).href ); + const project = useProject(); return new SdkProvider(useAWSCredentialsProvider(), project.config.region!, { ioHelper: IoHelper.fromActionAwareIoHost({ diff --git a/packages/sst/src/stacks/deploy.ts b/packages/sst/src/stacks/deploy.ts index 80b621aab..f1e995a15 100644 --- a/packages/sst/src/stacks/deploy.ts +++ b/packages/sst/src/stacks/deploy.ts @@ -1,5 +1,5 @@ import path from "path"; -import { fileURLToPath } from "url"; +import { fileURLToPath, pathToFileURL } from "url"; import { useBus } from "../bus.js"; import { ConfigOptions, useProject } from "../project.js"; import { useAWSClient, useAWSProvider } from "../credentials.js"; @@ -252,10 +252,14 @@ async function createCdkDeployments() { const cdkToolkitUrl = await import.meta.resolve!("@aws-cdk/toolkit-lib"); const cdkToolkitPath = fileURLToPath(cdkToolkitUrl); const { Deployments } = await import( - path.resolve(cdkToolkitPath, "..", "api", "deployments", "deployments.js") + pathToFileURL( + path.resolve(cdkToolkitPath, "..", "api", "deployments", "deployments.js") + ).href ); const { IoHelper } = await import( - path.resolve(cdkToolkitPath, "..", "api", "io", "private", "io-helper.js") + pathToFileURL( + path.resolve(cdkToolkitPath, "..", "api", "io", "private", "io-helper.js") + ).href ); const provider = await useAWSProvider(); await useAWSProvider(); diff --git a/packages/sst/src/stacks/synth.ts b/packages/sst/src/stacks/synth.ts index 479681191..151234a2f 100644 --- a/packages/sst/src/stacks/synth.ts +++ b/packages/sst/src/stacks/synth.ts @@ -3,7 +3,7 @@ import type { App } from "../constructs/App.js"; import { useProject } from "../project.js"; import { useAWSProvider, useSTSIdentity } from "../credentials.js"; import path from "path"; -import { fileURLToPath } from "url"; +import { fileURLToPath, pathToFileURL } from "url"; import { VisibleError } from "../error.js"; import { Semaphore } from "../util/semaphore.js"; import { Configuration } from "../util/user-configuration.js"; @@ -27,13 +27,20 @@ export async function synth(opts: SynthOptions) { const cdkToolkitUrl = await import.meta.resolve!("@aws-cdk/toolkit-lib"); const cdkToolkitPath = fileURLToPath(cdkToolkitUrl); const { IoHelper } = await import( - path.resolve(cdkToolkitPath, "..", "api", "io", "private", "io-helper.js") + pathToFileURL( + path.resolve(cdkToolkitPath, "..", "api", "io", "private", "io-helper.js") + ).href ); const { PluginHost } = await import( - path.resolve(cdkToolkitPath, "..", "api", "plugin", "plugin.js") + pathToFileURL( + path.resolve(cdkToolkitPath, "..", "api", "plugin", "plugin.js") + ).href ); + const { provideContextValues } = await import( - path.resolve(cdkToolkitPath, "..", "context-providers", "index.js") + pathToFileURL( + path.resolve(cdkToolkitPath, "..", "context-providers", "index.js") + ).href ); const project = useProject(); From ccfc17f1c67d3066eb0ffa3a9a515728f6711701 Mon Sep 17 00:00:00 2001 From: Jorge Lanzarotti Date: Tue, 7 Oct 2025 09:41:55 +0900 Subject: [PATCH 3/5] Fix conflicts user-configuration.ts toolKitError --- packages/sst/src/util/user-configuration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sst/src/util/user-configuration.ts b/packages/sst/src/util/user-configuration.ts index f9489ebc9..f5d98df59 100644 --- a/packages/sst/src/util/user-configuration.ts +++ b/packages/sst/src/util/user-configuration.ts @@ -20,7 +20,7 @@ try { cdkToolkitPath = require.resolve("@aws-cdk/toolkit-lib"); } -const { ToolkitError } = await import(cdkToolkitPath); +const { ToolkitError } = await import(cdkToolkitUrl); const { Context, PROJECT_CONTEXT } = await import( pathToFileURL(fs_path.resolve(cdkToolkitPath, "..", "api", "context.js")).href ); From f41833c1592fad1a6eebea1f784dbbf9b5e1ecca Mon Sep 17 00:00:00 2001 From: Jorge Lanzarotti Date: Tue, 8 Jul 2025 09:00:33 +0900 Subject: [PATCH 4/5] Revert path import --- packages/sst/src/credentials.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/sst/src/credentials.ts b/packages/sst/src/credentials.ts index 69bf233bc..825e4184d 100644 --- a/packages/sst/src/credentials.ts +++ b/packages/sst/src/credentials.ts @@ -1,4 +1,4 @@ -import fs from "path"; +import path from "path"; import { fileURLToPath, pathToFileURL } from "url"; import type { AwsCredentialIdentityProvider } from "@aws-sdk/types"; import { fromNodeProviderChain } from "@aws-sdk/credential-providers"; @@ -150,13 +150,13 @@ export const useAWSProvider = lazy(async () => { const cdkToolkitPath = fileURLToPath(cdkToolkitUrl); const { SdkProvider } = await import( pathToFileURL( - fs.resolve(cdkToolkitPath, "..", "api", "aws-auth", "sdk-provider.js") + path.resolve(cdkToolkitPath, "..", "api", "aws-auth", "sdk-provider.js") ).href ); const { IoHelper } = await import( pathToFileURL( - fs.resolve(cdkToolkitPath, "..", "api", "io", "private", "io-helper.js") + path.resolve(cdkToolkitPath, "..", "api", "io", "private", "io-helper.js") ).href ); From 5628336c9d714107883bf6b92c2c045f05caa74b Mon Sep 17 00:00:00 2001 From: Jorge Lanzarotti Date: Tue, 7 Oct 2025 11:40:16 +0900 Subject: [PATCH 5/5] Fix tests --- packages/sst/src/iot.ts | 5 ++--- packages/sst/src/util/user-configuration.ts | 25 ++++++++++++--------- packages/sst/test/constructs/helper.ts | 18 ++++++--------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/packages/sst/src/iot.ts b/packages/sst/src/iot.ts index f6edbfcf9..cfd446308 100644 --- a/packages/sst/src/iot.ts +++ b/packages/sst/src/iot.ts @@ -1,6 +1,8 @@ import { IoTClient, DescribeEndpointCommand } from "@aws-sdk/client-iot"; import { useAWSClient, useAWSCredentials } from "./credentials.js"; import { VisibleError } from "./error.js"; +import { lazy } from "./util/lazy.js"; +import { Logger } from "./logger.js"; export const useIOTEndpoint = lazy(async () => { const iot = useAWSClient(IoTClient); @@ -21,11 +23,8 @@ export const useIOTEndpoint = lazy(async () => { import iot from "aws-iot-device-sdk"; import { EventPayload, Events, EventTypes, useBus } from "./bus.js"; import { useProject } from "./project.js"; -import { Logger } from "./logger.js"; -import { randomUUID } from "crypto"; import { useBootstrap } from "./bootstrap.js"; import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3"; -import { lazy } from "./util/lazy.js"; interface Fragment { id: string; diff --git a/packages/sst/src/util/user-configuration.ts b/packages/sst/src/util/user-configuration.ts index f5d98df59..c71d4d040 100644 --- a/packages/sst/src/util/user-configuration.ts +++ b/packages/sst/src/util/user-configuration.ts @@ -1,23 +1,26 @@ -// @ts-nocheck import * as os from "os"; import * as fs_path from "path"; import * as fs from "fs"; import { fileURLToPath, pathToFileURL } from "url"; +type Tag = { Key: string; Value: string }; + export const PROJECT_CONFIG = "cdk.json"; export const USER_DEFAULTS = "~/.cdk.json"; const CONTEXT_KEY = "context"; -let cdkToolkitPath: string; +let cdkToolkitPath = ""; +let cdkToolkitUrl = ""; try { - const cdkToolkitUrl = await import.meta.resolve!("@aws-cdk/toolkit-lib"); + cdkToolkitUrl = await import.meta.resolve!("@aws-cdk/toolkit-lib"); cdkToolkitPath = fileURLToPath(cdkToolkitUrl); } catch (e) { // Fallback for test environment where import.meta.resolve is not available const module = await import("module"); const require = (module as any).createRequire(import.meta.url); cdkToolkitPath = require.resolve("@aws-cdk/toolkit-lib"); + cdkToolkitUrl = pathToFileURL(cdkToolkitPath).href; } const { ToolkitError } = await import(cdkToolkitUrl); @@ -109,10 +112,10 @@ export class Configuration { output: "cdk.out", }); - private readonly commandLineArguments: Settings; - private readonly commandLineContext: Settings; - private _projectConfig?: Settings; - private _projectContext?: Settings; + private readonly commandLineArguments: typeof Settings; + private readonly commandLineContext: typeof Settings; + private _projectConfig?: typeof Settings; + private _projectContext?: typeof Settings; private loaded = false; constructor(private readonly props: ConfigurationProps = {}) { @@ -198,11 +201,11 @@ export class Configuration { } } -async function loadAndLog(fileName: string): Promise { +async function loadAndLog(fileName: string): Promise { return await settingsFromFile(fileName); } -async function settingsFromFile(fileName: string): Promise { +async function settingsFromFile(fileName: string): Promise { let settings; const expanded = expandHomeDir(fileName); if (fs.existsSync(expanded)) { @@ -224,7 +227,7 @@ async function settingsFromFile(fileName: string): Promise { } function prohibitContextKeys( - settings: Settings, + settings: typeof Settings, keys: string[], fileName: string ) { @@ -245,7 +248,7 @@ function prohibitContextKeys( } function warnAboutContextKey( - settings: Settings, + settings: typeof Settings, prefix: string, fileName: string ) { diff --git a/packages/sst/test/constructs/helper.ts b/packages/sst/test/constructs/helper.ts index acbf76cc0..455977e85 100644 --- a/packages/sst/test/constructs/helper.ts +++ b/packages/sst/test/constructs/helper.ts @@ -1,17 +1,12 @@ import { Match, Matcher, MatchResult, Template } from "aws-cdk-lib/assertions"; import { Stack } from "aws-cdk-lib"; -import { App, AppDeployProps, AppProps } from "../../dist/constructs"; +import { App, AppDeployProps } from "../../dist/constructs"; import { setProject, useProject } from "../../dist/project.js"; -import { useNodeHandler } from "../../dist/runtime/handlers/node.js"; -import { usePythonHandler } from "../../dist/runtime/handlers/python.js"; -import { useDotnetHandler } from "../../dist/runtime/handlers/dotnet.js"; -import { useJavaHandler } from "../../dist/runtime/handlers/java.js"; -import { useGoHandler } from "../../dist/runtime/handlers/go.js"; -import { useContainerHandler } from "../../dist/runtime/handlers/container.js"; -import os from "os"; -import path from "path"; -import fs from "fs/promises"; -import crypto from "crypto"; + +import * as os from "os"; +import * as path from "path"; +import * as fs from "fs/promises"; +import * as crypto from "crypto"; /////////////////////// // Matcher functions // @@ -34,6 +29,7 @@ export async function createApp(props?: Partial) { setProject({ version: "test", cdkVersion: "test", + constructsVersion: "test", stacks: async () => {}, metafile: null as any, config: {