Skip to content

Commit f82d96b

Browse files
authored
chore(core): embedded export for cfn-parse (#19773)
This PR moves `cfn-parse.ts` under a folder within `@aws-cdk/core/lib`, where it is "secretly" exported. You can access the API of `cfn-parse` by importing `import * as cfn_parse from '@aws-cdk/core/lib/cfn-parse';`. The motivation behind this change is to stabilize the code generated by `cfn2ts`. `cfn2ts` imports `cfn_parse` but until now, this was not possible in v2 since `aws-cdk-lib` is export-restricted. This change should allow cdk v2 users the ability to generate L1 code via `cfn2ts`. Closes #18037. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 3665db9 commit f82d96b

File tree

7 files changed

+34
-20
lines changed

7 files changed

+34
-20
lines changed

packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as core from '@aws-cdk/core';
2-
import * as cfn_parse from '@aws-cdk/core/lib/cfn-parse';
2+
import * as cfn_parse from '@aws-cdk/core/lib/helpers-internal';
33
import { Construct } from 'constructs';
44
import * as cfn_type_to_l1_mapping from './cfn-type-to-l1-mapping';
55
import * as futils from './file-utils';

packages/@aws-cdk/core/lib/cfn-codedeploy-blue-green-hook.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Construct } from 'constructs';
22
import { CfnHook } from './cfn-hook';
3-
import { FromCloudFormationOptions } from './cfn-parse';
43
import { CfnResource } from './cfn-resource';
4+
import { FromCloudFormationOptions } from './helpers-internal';
55
import { undefinedIfAllValuesAreEmpty } from './util';
66

77
/**

packages/@aws-cdk/core/lib/cfn-parse.ts renamed to packages/@aws-cdk/core/lib/helpers-internal/cfn-parse.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { CfnCondition } from './cfn-condition';
2-
import { CfnElement } from './cfn-element';
3-
import { Fn } from './cfn-fn';
4-
import { CfnMapping } from './cfn-mapping';
5-
import { Aws } from './cfn-pseudo';
6-
import { CfnResource } from './cfn-resource';
1+
import { CfnCondition } from '../cfn-condition';
2+
import { CfnElement } from '../cfn-element';
3+
import { Fn } from '../cfn-fn';
4+
import { CfnMapping } from '../cfn-mapping';
5+
import { Aws } from '../cfn-pseudo';
6+
import { CfnResource } from '../cfn-resource';
77
import {
88
CfnAutoScalingReplacingUpdate, CfnAutoScalingRollingUpdate, CfnAutoScalingScheduledAction, CfnCodeDeployLambdaAliasUpdate,
99
CfnCreationPolicy, CfnDeletionPolicy, CfnResourceAutoScalingCreationPolicy, CfnResourceSignal, CfnUpdatePolicy,
10-
} from './cfn-resource-policy';
11-
import { CfnTag } from './cfn-tag';
12-
import { Lazy } from './lazy';
13-
import { CfnReference, ReferenceRendering } from './private/cfn-reference';
14-
import { IResolvable } from './resolvable';
15-
import { Validator } from './runtime';
16-
import { isResolvableObject, Token } from './token';
17-
import { undefinedIfAllValuesAreEmpty } from './util';
10+
} from '../cfn-resource-policy';
11+
import { CfnTag } from '../cfn-tag';
12+
import { Lazy } from '../lazy';
13+
import { CfnReference, ReferenceRendering } from '../private/cfn-reference';
14+
import { IResolvable } from '../resolvable';
15+
import { Validator } from '../runtime';
16+
import { isResolvableObject, Token } from '../token';
17+
import { undefinedIfAllValuesAreEmpty } from '../util';
1818

1919
/**
2020
* The class used as the intermediate result from the generated L1 methods
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './cfn-parse';

packages/@aws-cdk/core/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@
162162
"lines": 55,
163163
"branches": 35
164164
},
165+
"ubergen": {
166+
"exports": {
167+
"./lib/helpers-internal": "./lib/helpers-internal/index.js"
168+
}
169+
},
165170
"keywords": [
166171
"aws",
167172
"cdk",

tools/@aws-cdk/cfn2ts/lib/codegen.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ export default class CodeGenerator {
5858
this.code.line('/* eslint-disable max-len */ // This is generated code - line lengths are difficult to control');
5959
this.code.line();
6060
this.code.line(`import * as ${CORE} from '${coreImport}';`);
61-
// explicitly import the cfn-parse.ts file from @core, which is not part of the public API of the module
62-
this.code.line(`import * as ${CFN_PARSE} from '${coreImport}/${coreImport === '.' ? '' : 'lib/'}cfn-parse';`);
61+
// import cfn-parse from an embedded folder inside @core, since it is not part of the public API of the module
62+
this.code.line(`import * as ${CFN_PARSE} from '${coreImport}/${coreImport === '.' ? '' : 'lib/'}helpers-internal';`);
6363
}
6464

6565
public emitCode(): void {

tools/@aws-cdk/ubergen/bin/ubergen.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ interface PackageJson {
9797
* @default true
9898
*/
9999
readonly explicitExports?: boolean;
100+
101+
/**
102+
* An exports section that should be ignored for v1 but included for ubergen
103+
*/
104+
readonly exports?: Record<string, string>;
100105
};
101106
exports?: Record<string, string>;
102107
}
@@ -305,8 +310,11 @@ async function prepareSourceFiles(libraries: readonly LibraryReference[], packag
305310
function copySubmoduleExports(targetExports: Record<string, string>, library: LibraryReference, subdirectory: string) {
306311
const visibleName = library.shortName;
307312

308-
for (const [relPath, relSource] of Object.entries(library.packageJson.exports ?? {})) {
309-
targetExports[`./${unixPath(path.join(visibleName, relPath))}`] = `./${unixPath(path.join(subdirectory, relSource))}`;
313+
// Do both REAL "exports" section, as well as virtual, ubergen-only "exports" section
314+
for (const exportSet of [library.packageJson.exports, library.packageJson.ubergen?.exports]) {
315+
for (const [relPath, relSource] of Object.entries(exportSet ?? {})) {
316+
targetExports[`./${unixPath(path.join(visibleName, relPath))}`] = `./${unixPath(path.join(subdirectory, relSource))}`;
317+
}
310318
}
311319

312320
// If there was an export for '.' in the original submodule, this assignment will overwrite it,

0 commit comments

Comments
 (0)