Skip to content

Commit 6db0d9b

Browse files
authored
refactor(cli,cli-lib-alpha): restrict relative package imports (#492)
Enabled the linter rule `import/no-relative-packages` to disallow relative imports from other monorepo packages. While relative imports are generally possible, they require special handling w.r.t. to bundling of the JS code **and** type declarations. Hence we discourage them by default. There are currently two packages that require relative imports: `aws-cdk` (the CLI) and `cli-lib-alpha`. Both depend on functionality that is not publicly available in the respective monorepo packages, so we need to import relatively. `cli-lib-alpha` is about to be deprecated, and `aws-cdk` should eventually move to only use public features from `toolkit-lib`. Both packages have their relative imports updated to optimize for the number of files allowed to still import relatively. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent ca6953e commit 6db0d9b

File tree

92 files changed

+131
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+131
-165
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,6 @@ const cli = configureProject(
10241024
nodeBundle,
10251025
yargsGen,
10261026
cliPluginContract,
1027-
toolkitLib,
10281027
'@octokit/rest',
10291028
'@types/archiver',
10301029
'@types/fs-extra@^9',
@@ -1051,6 +1050,7 @@ const cli = configureProject(
10511050
cloudAssemblySchema.customizeReference({ versionType: 'minimal' }),
10521051
cloudFormationDiff.customizeReference({ versionType: 'exact' }),
10531052
cxApi,
1053+
toolkitLib,
10541054
'archiver',
10551055
`@aws-sdk/client-appsync@${CLI_SDK_V3_RANGE}`,
10561056
`@aws-sdk/client-cloudformation@${CLI_SDK_V3_RANGE}`,

packages/@aws-cdk-testing/cli-integ/.eslintrc.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/cdk-cli-wrapper/.eslintrc.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/cli-lib-alpha/.eslintrc.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
/* eslint-disable import/no-relative-packages */
3+
export { prepareContext, prepareDefaultEnvironment } from '../../../aws-cdk/lib/api/cloud-assembly';
4+
export { createAssembly } from '../../../aws-cdk/lib/cxapp/exec';
5+
export { exec } from '../../../aws-cdk';
6+
export { debug } from '../../../aws-cdk/lib/logging';

packages/@aws-cdk/cli-lib-alpha/lib/cli.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1+
import { exec as runCli, debug, createAssembly, prepareContext, prepareDefaultEnvironment } from './aws-cdk';
12
import type { SharedOptions, DeployOptions, DestroyOptions, BootstrapOptions, SynthOptions, ListOptions } from './commands';
23
import { StackActivityProgress, HotswapMode } from './commands';
3-
import { exec as runCli } from '../../../aws-cdk/lib';
4-
import { prepareContext, prepareDefaultEnvironment } from '../../../aws-cdk/lib/api/cloud-assembly';
5-
import { createAssembly } from '../../../aws-cdk/lib/cxapp';
6-
import { debug } from '../../../aws-cdk/lib/legacy-exports';
74

85
const debugFn = async (msg: string) => void debug(msg);
96

packages/@aws-cdk/cli-lib-alpha/test/cli.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { join } from 'path';
22
import * as core from 'aws-cdk-lib/core';
3-
import * as cli from '../../../aws-cdk/lib';
43
import { AwsCdkCli } from '../lib';
4+
import * as cli from '../lib/aws-cdk';
55

66
// These tests synthesize an actual CDK app and take a bit longer
77
jest.setTimeout(60_000);
88

9-
jest.mock('../../../aws-cdk/lib', () => {
10-
const original = jest.requireActual('../../../aws-cdk/lib');
9+
jest.mock('../lib/aws-cdk', () => {
10+
const original = jest.requireActual('../lib/aws-cdk');
1111
return {
1212
...original,
1313
exec: jest.fn(original.exec),

packages/@aws-cdk/cli-lib-alpha/test/commands.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import * as cli from 'aws-cdk';
12
import * as core from 'aws-cdk-lib/core';
2-
import * as cli from '../../../aws-cdk/lib';
33
import { AwsCdkCli } from '../lib';
44
import { HotswapMode, RequireApproval, StackActivityProgress } from '../lib/commands';
55

packages/@aws-cdk/cli-plugin-contract/.eslintrc.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)