Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(layers): add createRequire banner in esm #2232

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions layers/src/layer-publisher-stack.ts
Original file line number Diff line number Diff line change
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