Skip to content

Commit d875790

Browse files
feat: Window support (#92) (#93)
* feat: Window support (#92) * fix: path * fix: add-bang script
1 parent 66c9b2a commit d875790

File tree

5 files changed

+40
-29
lines changed

5 files changed

+40
-29
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
"lint": "eslint . --fix",
4545
"prettier": "prettier . --write",
4646
"prepare": "husky",
47-
"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",
47+
"add-bang": "echo '#!/usr/bin/env node' | cat - ./dist/lldebugger.mjs > ./dist/lldebugger.mjs.tmp && mv ./dist/lldebugger.mjs.tmp ./dist/lldebugger.mjs",
4848
"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",
4949
"bundle-extension": "cd src/extension && npm run build && cd ../../",
5050
"deploy-github-role": "aws cloudformation deploy --stack-name lld-deploy-role --template-file cloudformation/gitHubDeployRole.yaml --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM --profile lldebugger",
51-
"deploy-tests": "npm run deploy --workspaces",
51+
"deploy-tests": "npm run deploy --workspaces --if-present --parallel",
5252
"test": "npm run build && RUN_TEST_FROM_CLI=true vitest run && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run",
5353
"test-cdk-basic": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/cdk-basic.test.ts",
5454
"test-cdk-basic-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/cdk-basic.test.ts",

src/frameworks/cdkFramework.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as esbuild from 'esbuild';
22
import * as fs from 'fs/promises';
33
import * as path from 'path';
4+
import { pathToFileURL } from 'url';
45
import { BundlingType, LambdaResource } from '../types/resourcesDiscovery.js';
56
import { outputFolder } from '../constants.js';
67
import { findPackageJson } from '../utils/findPackageJson.js';
@@ -287,7 +288,11 @@ export class CdkFramework implements IFramework {
287288
? 'js'
288289
: (fileExtension as esbuild.Loader);
289290
// Inject code to get the file path of the Lambda function and CDK hierarchy
290-
if (args.path.includes('aws-cdk-lib/aws-lambda/lib/function.')) {
291+
if (
292+
args.path.includes(
293+
path.join('aws-cdk-lib', 'aws-lambda', 'lib', 'function.'),
294+
)
295+
) {
291296
const codeToFind =
292297
'try{jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_FunctionProps(props)}';
293298

@@ -487,20 +492,21 @@ export class CdkFramework implements IFramework {
487492
compileCodeFile: string;
488493
}) {
489494
const lambdas: any[] = await new Promise((resolve, reject) => {
490-
const worker = new Worker(
495+
const workerPath = pathToFileURL(
491496
path.resolve(
492497
path.join(getModuleDirname(), 'frameworks/cdkFrameworkWorker.mjs'),
493498
),
494-
{
495-
workerData: {
496-
verbose: config.verbose,
497-
awsCdkLibPath,
498-
projectDirname: getProjectDirname(),
499-
moduleDirname: getModuleDirname(),
500-
subfolder: config.subfolder,
501-
},
499+
).href;
500+
501+
const worker = new Worker(new URL(workerPath), {
502+
workerData: {
503+
verbose: config.verbose,
504+
awsCdkLibPath,
505+
projectDirname: getProjectDirname(),
506+
moduleDirname: getModuleDirname(),
507+
subfolder: config.subfolder,
502508
},
503-
);
509+
});
504510

505511
worker.on('message', async (message) => {
506512
resolve(message);

src/frameworks/cdkFrameworkWorker.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-nocheck
22
import { workerData, parentPort } from 'node:worker_threads';
3+
import { pathToFileURL } from 'url';
34
import { Logger } from '../logger.mjs';
45

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

1617
// execute code to get the data into global.lambdas
17-
await import(data.compileOutput);
18+
await import(pathToFileURL(data.compileOutput).href);
1819

1920
if (!global.lambdas || global.lambdas?.length === 0) {
2021
throw new Error('No Lambda functions found in the CDK code');

src/nodeWorker.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Worker } from 'node:worker_threads';
22
import { FuctionRequest } from './ioTService.js';
33
import * as path from 'path';
4+
import { pathToFileURL } from 'url';
45
import { Configuration } from './configuration.js';
56
import { getModuleDirname, getProjectDirname } from './getDirname.js';
67
import { Logger } from './logger.js';
@@ -125,22 +126,23 @@ function startWorker(input: WorkerRequest) {
125126

126127
const localProjectDir = getProjectDirname();
127128

128-
const worker: MyWorker = new Worker(
129+
const workerPath = pathToFileURL(
129130
path.resolve(path.join(getModuleDirname(), `./nodeWorkerRunner.mjs`)),
130-
{
131-
env: {
132-
...input.environment,
133-
IS_LOCAL: 'true',
134-
LOCAL_PROJECT_DIR: localProjectDir,
135-
},
136-
execArgv: ['--enable-source-maps'],
137-
workerData: input,
138-
stderr: true,
139-
stdin: true,
140-
stdout: true,
141-
//type: "module",
131+
).href;
132+
133+
const worker: MyWorker = new Worker(new URL(workerPath), {
134+
env: {
135+
...input.environment,
136+
IS_LOCAL: 'true',
137+
LOCAL_PROJECT_DIR: localProjectDir,
142138
},
143-
);
139+
execArgv: ['--enable-source-maps'],
140+
workerData: input,
141+
stderr: true,
142+
stdin: true,
143+
stdout: true,
144+
//type: "module",
145+
});
144146

145147
worker.stdout.on('data', (data: Buffer) => {
146148
Logger.log(`[Function ${input.functionId}]`, data.toString());

src/nodeWorkerRunner.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-nocheck
22
import { createRequire as topLevelCreateRequire } from 'module';
3+
import { pathToFileURL } from 'url';
34
// eslint-disable-next-line @typescript-eslint/no-unused-vars
45
const require = topLevelCreateRequire(import.meta.url);
56

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

2022
if (!fn) {

0 commit comments

Comments
 (0)