Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ServerlessLife committed Apr 7, 2024
1 parent b745b84 commit ecb6ad5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 70 deletions.
49 changes: 21 additions & 28 deletions src/nodeEsBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ async function build(input: {
result: esbuild.BuildResult;
ctx: esbuild.BuildContext;
}> {
const out = path.join(`.lldebugger/artifacts`, input.functionId);
await fs.rm(out, { recursive: true, force: true });
await fs.mkdir(out, { recursive: true });
const targetFolder = path.join(`.lldebugger/artifacts`, input.functionId);
await fs.rm(targetFolder, { recursive: true, force: true });
await fs.mkdir(targetFolder, { recursive: true });

const esbuildOptions = removeUndefinedProperties(
input.function.esbuildOptions
Expand All @@ -62,20 +62,11 @@ async function build(input: {

let isESM = !!(esbuildOptions?.format === "esm");

const relative = path.resolve(handlerParsedPath.dir);
let ctx = input.oldCtx;

const extension = isESM ? ".mjs" : ".cjs";
const target = path.join(
out,
!relative.startsWith("..") && !path.isAbsolute(input.function.codePath!)
? relative
: "",
handlerParsedPath.name.replace(".", "-") + extension
console.log(
`Building ${handlerCodePath}. Module type: ${isESM ? "ESM" : "CJS"}`
);
const targetFolder = path.dirname(target);
const artifactFolder = out;

let ctx = input.oldCtx;

if (!ctx) {
const optionsDefault: BuildOptions = {
Expand Down Expand Up @@ -150,23 +141,25 @@ async function build(input: {

//console.log("ESBUILD OPTIONS", options);
ctx = await esbuild.context(options);

//copy package.json to output folder
const root = await findAboveFolderWithAFile(
handlerParsedPath.dir,
"package.json"
);

if (root) {
await fs.copyFile(
path.join(root, "package.json"),
path.join(artifactFolder, "package.json")
);
}
}

const result = await ctx.rebuild();

//copy package.json to output folder
const packageJsonRoot = await findAboveFolderWithAFile(
handlerParsedPath.dir,
"package.json"
);

if (packageJsonRoot) {
const from = path.join(packageJsonRoot, "package.json");
const to = path.join(targetFolder, "package.json");

console.log(`Copying package.json from ${from} to ${to}`);

await fs.copyFile(from, to);
}

return {
ctx: ctx as esbuild.BuildContext,
result: result as esbuild.BuildResult,
Expand Down
59 changes: 29 additions & 30 deletions test/cdk-simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,39 @@ describe("cdk-simple", () => {
await execAsync("npm run deploy", {
cwd: sampleFolder,
});
}

console.log("Starting LLD...");

// start the debugger
lldProcess = spawn("node ../../dist/lldebugger.js", {
cwd: sampleFolder,
shell: true,
});
console.log("Starting LLD...");

// wait for the debugger to start
let error = false;
await new Promise((resolve, reject) => {
lldProcess.stdout?.on("data", (data) => {
console.log("LLD: " + data.toString());
const line = data.toString();
if (line.includes("IoT connected")) {
resolve(true);
}
});
lldProcess.stderr?.on("data", (data) => {
console.log("LLD ERROR: " + data.toString());
error = true;
lldProcess = spawn("node ../../dist/lldebugger.js", {
cwd: sampleFolder,
shell: true,
});
lldProcess.on("close", (error) => {
console.log("LLD CLOSED");
if (error) {
reject(error);
} else {
resolve(true);
}

// wait for the debugger to start
let error = false;
await new Promise((resolve, reject) => {
lldProcess.stdout?.on("data", (data) => {
console.log("LLD: " + data.toString());
const line = data.toString();
if (line.includes("IoT connected")) {
resolve(true);
}
});
lldProcess.stderr?.on("data", (data) => {
console.log("LLD ERROR: " + data.toString());
error = true;
});
lldProcess.on("close", (error) => {
console.log("LLD CLOSED");
if (error) {
reject(error);
} else {
resolve(true);
}
});
});
});
await setTimeout(3000);
await setTimeout(4000);
}
});

afterAll(async () => {
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit ecb6ad5

Please sign in to comment.