Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"lint": "eslint . --fix",
"prettier": "prettier . --write",
"prepare": "husky",
"add-bang": "printf '#!/usr/bin/env node\\n%s' \"$(cat ./dist/lldebugger.mjs)\" > ./dist/lldebugger.mjs.tmp && mv ./dist/lldebugger.mjs.tmp ./dist/lldebugger.mjs",
"add-bang": "echo '#!/usr/bin/env node' | cat - ./dist/lldebugger.mjs > ./dist/lldebugger.mjs.tmp && mv ./dist/lldebugger.mjs.tmp ./dist/lldebugger.mjs",
"build": "tsc -p tsconfig.build.json && cp src/nodeWorkerRunner.mjs dist && cp src/frameworks/cdkFrameworkWorker.mjs dist/frameworks && node fix-imports.js && npm run add-bang && npm run bundle-extension",
"bundle-extension": "cd src/extension && npm run build && cd ../../",
"deploy-github-role": "aws cloudformation deploy --stack-name lld-deploy-role --template-file cloudformation/gitHubDeployRole.yaml --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM --profile lldebugger",
"deploy-tests": "npm run deploy --workspaces",
"deploy-tests": "npm run deploy --workspaces --if-present --parallel",
"test": "npm run build && RUN_TEST_FROM_CLI=true vitest run && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run",
"test-cdk-basic": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/cdk-basic.test.ts",
"test-cdk-basic-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/cdk-basic.test.ts",
Expand Down
28 changes: 17 additions & 11 deletions src/frameworks/cdkFramework.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as esbuild from 'esbuild';
import * as fs from 'fs/promises';
import * as path from 'path';
import { pathToFileURL } from 'url';
import { BundlingType, LambdaResource } from '../types/resourcesDiscovery.js';
import { outputFolder } from '../constants.js';
import { findPackageJson } from '../utils/findPackageJson.js';
Expand Down Expand Up @@ -287,7 +288,11 @@ export class CdkFramework implements IFramework {
? 'js'
: (fileExtension as esbuild.Loader);
// Inject code to get the file path of the Lambda function and CDK hierarchy
if (args.path.includes('aws-cdk-lib/aws-lambda/lib/function.')) {
if (
args.path.includes(
path.join('aws-cdk-lib', 'aws-lambda', 'lib', 'function.'),
)
) {
const codeToFind =
'try{jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_FunctionProps(props)}';

Expand Down Expand Up @@ -487,20 +492,21 @@ export class CdkFramework implements IFramework {
compileCodeFile: string;
}) {
const lambdas: any[] = await new Promise((resolve, reject) => {
const worker = new Worker(
const workerPath = pathToFileURL(
path.resolve(
path.join(getModuleDirname(), 'frameworks/cdkFrameworkWorker.mjs'),
),
{
workerData: {
verbose: config.verbose,
awsCdkLibPath,
projectDirname: getProjectDirname(),
moduleDirname: getModuleDirname(),
subfolder: config.subfolder,
},
).href;

const worker = new Worker(new URL(workerPath), {
workerData: {
verbose: config.verbose,
awsCdkLibPath,
projectDirname: getProjectDirname(),
moduleDirname: getModuleDirname(),
subfolder: config.subfolder,
},
);
});

worker.on('message', async (message) => {
resolve(message);
Expand Down
3 changes: 2 additions & 1 deletion src/frameworks/cdkFrameworkWorker.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-nocheck
import { workerData, parentPort } from 'node:worker_threads';
import { pathToFileURL } from 'url';
import { Logger } from '../logger.mjs';

Logger.setVerbose(workerData.verbose);
Expand All @@ -14,7 +15,7 @@ parentPort.on('message', async (data) => {
Logger.verbose(`[Worker] Received message`, data);

// execute code to get the data into global.lambdas
await import(data.compileOutput);
await import(pathToFileURL(data.compileOutput).href);

if (!global.lambdas || global.lambdas?.length === 0) {
throw new Error('No Lambda functions found in the CDK code');
Expand Down
30 changes: 16 additions & 14 deletions src/nodeWorker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Worker } from 'node:worker_threads';
import { FuctionRequest } from './ioTService.js';
import * as path from 'path';
import { pathToFileURL } from 'url';
import { Configuration } from './configuration.js';
import { getModuleDirname, getProjectDirname } from './getDirname.js';
import { Logger } from './logger.js';
Expand Down Expand Up @@ -125,22 +126,23 @@ function startWorker(input: WorkerRequest) {

const localProjectDir = getProjectDirname();

const worker: MyWorker = new Worker(
const workerPath = pathToFileURL(
path.resolve(path.join(getModuleDirname(), `./nodeWorkerRunner.mjs`)),
{
env: {
...input.environment,
IS_LOCAL: 'true',
LOCAL_PROJECT_DIR: localProjectDir,
},
execArgv: ['--enable-source-maps'],
workerData: input,
stderr: true,
stdin: true,
stdout: true,
//type: "module",
).href;

const worker: MyWorker = new Worker(new URL(workerPath), {
env: {
...input.environment,
IS_LOCAL: 'true',
LOCAL_PROJECT_DIR: localProjectDir,
},
);
execArgv: ['--enable-source-maps'],
workerData: input,
stderr: true,
stdin: true,
stdout: true,
//type: "module",
});

worker.stdout.on('data', (data: Buffer) => {
Logger.log(`[Function ${input.functionId}]`, data.toString());
Expand Down
4 changes: 3 additions & 1 deletion src/nodeWorkerRunner.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-nocheck
import { createRequire as topLevelCreateRequire } from 'module';
import { pathToFileURL } from 'url';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const require = topLevelCreateRequire(import.meta.url);

Expand All @@ -14,7 +15,8 @@ Logger.verbose(
parentPort.on('message', async (data) => {
Logger.verbose(`[Worker ${workerData.workerId}] Received message`, data);
try {
const mod = await import(workerData.artifactFile);
const artifactFile = pathToFileURL(workerData.artifactFile).href;
const mod = await import(artifactFile);
const fn = mod[workerData.handler];

if (!fn) {
Expand Down
Loading