Skip to content

Commit

Permalink
fix(layers): add createRequire banner in esm (#2232)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Thulbourn <sthulb@users.noreply.github.com>
  • Loading branch information
dreamorosi and sthulb committed Mar 15, 2024
1 parent aa6e6e0 commit 730bcc9
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions layers/src/layer-publisher-stack.ts
Expand Up @@ -174,10 +174,24 @@ export class LayerPublisherStack extends Stack {
.join(' ')}`
);

// Phase 5: Copy files from tmp folder to cdk.out asset folder (the folder is created by CDK)
// Phase 5: patch require keyword in ESM Tracer package due to AWS X-Ray SDK for Node.js not being ESM compatible
const esmTracerPath = join(
tmpBuildDir,
'node_modules',
'@aws-lambda-powertools/tracer',
'lib',
'esm',
'provider',
'ProviderService.js'
);
execSync(
`echo "import { createRequire } from 'module'; const require = createRequire(import.meta.url);$(cat ${esmTracerPath})" > ${esmTracerPath}`
);

// Phase 6: Copy files from tmp folder to cdk.out asset folder (the folder is created by CDK)
execSync(`cp -R ${tmpBuildPath}${sep}* ${outputDir}`);

// Phase 6: (Optional) Restore changes to the project root made by the build
// Phase 7: (Optional) Restore changes to the project root made by the build
buildFromLocal &&
execSync('git restore packages/*/package.json', {
cwd: projectRoot,
Expand Down

0 comments on commit 730bcc9

Please sign in to comment.