1- // @ts -nocheck
21import * as os from "os" ;
32import * as fs_path from "path" ;
43import * as fs from "fs" ;
4+ import { fileURLToPath , pathToFileURL } from "url" ;
5+
6+ type Tag = { Key : string ; Value : string } ;
57
68export const PROJECT_CONFIG = "cdk.json" ;
79export const USER_DEFAULTS = "~/.cdk.json" ;
810const CONTEXT_KEY = "context" ;
911
10- let cdkToolkitPath : string ;
12+ let cdkToolkitPath = "" ;
13+ let cdkToolkitUrl = "" ;
14+
1115try {
12- const cdkToolkitUrl = await import . meta. resolve ! ( "@aws-cdk/toolkit-lib" ) ;
13- cdkToolkitPath = new URL ( cdkToolkitUrl ) . pathname ;
16+ cdkToolkitUrl = await import . meta. resolve ! ( "@aws-cdk/toolkit-lib" ) ;
17+ cdkToolkitPath = fileURLToPath ( cdkToolkitUrl ) ;
1418} catch ( e ) {
1519 // Fallback for test environment where import.meta.resolve is not available
1620 const module = await import ( "module" ) ;
1721 const require = ( module as any ) . createRequire ( import . meta. url ) ;
1822 cdkToolkitPath = require . resolve ( "@aws-cdk/toolkit-lib" ) ;
23+ cdkToolkitUrl = pathToFileURL ( cdkToolkitPath ) . href ;
1924}
20- const { ToolkitError } = await import ( cdkToolkitPath ) ;
25+
26+ const { ToolkitError } = await import ( cdkToolkitUrl ) ;
2127const { Context, PROJECT_CONTEXT } = await import (
22- fs_path . resolve ( cdkToolkitPath , ".." , "api" , "context.js" )
28+ pathToFileURL ( fs_path . resolve ( cdkToolkitPath , ".." , "api" , "context.js" ) ) . href
2329) ;
2430const { Settings } = await import (
25- fs_path . resolve ( cdkToolkitPath , ".." , "api" , "settings.js" )
31+ pathToFileURL ( fs_path . resolve ( cdkToolkitPath , ".." , "api" , "settings.js" ) )
32+ . href
2633) ;
2734const { Tags } = await import (
28- fs_path . resolve ( cdkToolkitPath , ".." , "api" , "tags" , "index.js" )
35+ pathToFileURL (
36+ fs_path . resolve ( cdkToolkitPath , ".." , "api" , "tags" , "index.js" )
37+ ) . href
2938) ;
3039
3140export enum Command {
@@ -103,10 +112,10 @@ export class Configuration {
103112 output : "cdk.out" ,
104113 } ) ;
105114
106- private readonly commandLineArguments : Settings ;
107- private readonly commandLineContext : Settings ;
108- private _projectConfig ?: Settings ;
109- private _projectContext ?: Settings ;
115+ private readonly commandLineArguments : typeof Settings ;
116+ private readonly commandLineContext : typeof Settings ;
117+ private _projectConfig ?: typeof Settings ;
118+ private _projectContext ?: typeof Settings ;
110119 private loaded = false ;
111120
112121 constructor ( private readonly props : ConfigurationProps = { } ) {
@@ -192,11 +201,11 @@ export class Configuration {
192201 }
193202}
194203
195- async function loadAndLog ( fileName : string ) : Promise < Settings > {
204+ async function loadAndLog ( fileName : string ) : Promise < typeof Settings > {
196205 return await settingsFromFile ( fileName ) ;
197206}
198207
199- async function settingsFromFile ( fileName : string ) : Promise < Settings > {
208+ async function settingsFromFile ( fileName : string ) : Promise < typeof Settings > {
200209 let settings ;
201210 const expanded = expandHomeDir ( fileName ) ;
202211 if ( fs . existsSync ( expanded ) ) {
@@ -218,7 +227,7 @@ async function settingsFromFile(fileName: string): Promise<Settings> {
218227}
219228
220229function prohibitContextKeys (
221- settings : Settings ,
230+ settings : typeof Settings ,
222231 keys : string [ ] ,
223232 fileName : string
224233) {
@@ -239,7 +248,7 @@ function prohibitContextKeys(
239248}
240249
241250function warnAboutContextKey (
242- settings : Settings ,
251+ settings : typeof Settings ,
243252 prefix : string ,
244253 fileName : string
245254) {
0 commit comments