From 5bbf07c353974f6ec265b663f120aaa197607d8f Mon Sep 17 00:00:00 2001 From: Rico Hermans Date: Wed, 13 Sep 2023 11:36:18 +0200 Subject: [PATCH] chore: fix minimatch imports (#27116) For technical reasons, the way we were importing `minimatch` works in the current version of TypeScript, but is actually illegal according to the ESM spec. This poses problems when running `aws-cdk-lib` through `esbuild`. Update to a different import style that is correct in both. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/aws-cdk-lib/core/lib/fs/ignore.ts | 5 ++++- packages/aws-cdk-lib/core/lib/stack.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/core/lib/fs/ignore.ts b/packages/aws-cdk-lib/core/lib/fs/ignore.ts index 24a7114fb4707..14af4d78ecede 100644 --- a/packages/aws-cdk-lib/core/lib/fs/ignore.ts +++ b/packages/aws-cdk-lib/core/lib/fs/ignore.ts @@ -1,9 +1,12 @@ import * as path from 'path'; import dockerIgnore, * as DockerIgnore from '@balena/dockerignore'; import gitIgnore, * as GitIgnore from 'ignore'; -import * as minimatch from 'minimatch'; import { CopyOptions, IgnoreMode } from './options'; +// Must be a 'require' to not run afoul of ESM module import rules +// eslint-disable-next-line @typescript-eslint/no-require-imports +const minimatch = require('minimatch'); + /** * Represents file path ignoring behavior. */ diff --git a/packages/aws-cdk-lib/core/lib/stack.ts b/packages/aws-cdk-lib/core/lib/stack.ts index 61c85fc110677..54424e8dcafd5 100644 --- a/packages/aws-cdk-lib/core/lib/stack.ts +++ b/packages/aws-cdk-lib/core/lib/stack.ts @@ -1,7 +1,6 @@ import * as fs from 'fs'; import * as path from 'path'; import { IConstruct, Construct, Node } from 'constructs'; -import * as minimatch from 'minimatch'; import { Annotations } from './annotations'; import { App } from './app'; import { Arn, ArnComponents, ArnFormat } from './arn'; @@ -23,6 +22,10 @@ import * as cxschema from '../../cloud-assembly-schema'; import { INCLUDE_PREFIX_IN_UNIQUE_NAME_GENERATION } from '../../cx-api'; import * as cxapi from '../../cx-api'; +// Must be a 'require' to not run afoul of ESM module import rules +// eslint-disable-next-line @typescript-eslint/no-require-imports +const minimatch = require('minimatch'); + const STACK_SYMBOL = Symbol.for('@aws-cdk/core.Stack'); const MY_STACK_CACHE = Symbol.for('@aws-cdk/core.Stack.myStack');