Skip to content

Commit

Permalink
Fix #217 bundle has root folder (#218)
Browse files Browse the repository at this point in the history
* remove root folder from bundle

* add new test
  • Loading branch information
ojkelly authored May 29, 2022
1 parent 7dad981 commit 8fa056a
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 7 deletions.
11 changes: 11 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
1 change: 1 addition & 0 deletions e2e/lambda-project/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dist

.pnp.cjs
.pnp.*
.yarn/*
!.yarn/cache
!.yarn/patches
Expand Down
Binary file not shown.
65 changes: 64 additions & 1 deletion e2e/lambda-project/lambda-project.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import * as os from "os";
import * as crypto from "crypto";
import * as path from "path";
import * as execa from "execa";
import StreamZip from "node-stream-zip";

test("bundling lambda-project to a zip", async () => {
const workDir = getTempDirName();
const bundleOutput = getTempDirName();
const defaultArchiveName = "bundle.zip";

// Stage the test project far from the yarn.build project
fs.copySync(__dirname, workDir, {
Expand All @@ -27,10 +29,45 @@ test("bundling lambda-project to a zip", async () => {
);

// THEN
const zipPath = path.join(bundleOutput, "bundle.zip");
const zipPath = path.join(bundleOutput, defaultArchiveName);

expect(fs.existsSync(zipPath)).toEqual(true);
expect(fs.statSync(zipPath).isFile()).toEqual(true);

await validateZip({ bundleOutput, archiveName: defaultArchiveName });
});

test("bundling lambda-project to a zip with custom name", async () => {
const workDir = getTempDirName();
const bundleOutput = getTempDirName();
const archiveName = "function.zip";

// Stage the test project far from the yarn.build project
fs.copySync(__dirname, workDir, {
recursive: true,
errorOnExist: true,
});

// WHEN
yarnCmd(workDir, "workspace", "lambda", "build");
yarnCmd(
workDir,
"workspace",
"lambda",
"bundle",
"--output-directory",
bundleOutput,
"--archive-name",
archiveName
);

// THEN
const zipPath = path.join(bundleOutput, archiveName);

expect(fs.existsSync(zipPath)).toEqual(true);
expect(fs.statSync(zipPath).isFile()).toEqual(true);

await validateZip({ bundleOutput, archiveName });
});

test("run lambda-project after bundling without compression", async () => {
Expand Down Expand Up @@ -99,3 +136,29 @@ function getTempDirName() {
"integ" + crypto.randomBytes(10).toString("hex")
);
}

const validateZip = async (opts: {
bundleOutput: string;
archiveName: string;
}) => {
const zip = new StreamZip.async({
file: path.join(opts.bundleOutput, opts.archiveName),
skipEntryNameValidation: true,
});

const entries = await zip.entries();

for (const entry of Object.values(entries)) {
// validate entrypoint js
if (
entry.isFile &&
entry.name.endsWith("entrypoint.js") &&
entry.name != "entrypoint.js"
) {
await zip.close();

throw new Error("missing entrypoint.js or it's not in the root folder");
}
}
await zip.close();
};
1 change: 1 addition & 0 deletions e2e/lambda-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"jest": "^26.6.3",
"jest-pnp-resolver": "^1.2.1",
"node-fetch": "^3.0.0",
"node-stream-zip": "^1.15.0",
"ts-jest": "^26.4.4",
"ts-pnp": "^1.2.0",
"typescript": "^4.3.2"
Expand Down
8 changes: 8 additions & 0 deletions e2e/lambda-project/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3441,6 +3441,7 @@ __metadata:
jest: ^26.6.3
jest-pnp-resolver: ^1.2.1
node-fetch: ^3.0.0
node-stream-zip: ^1.15.0
ts-jest: ^26.4.4
ts-pnp: ^1.2.0
typescript: ^4.3.2
Expand Down Expand Up @@ -3864,6 +3865,13 @@ __metadata:
languageName: node
linkType: hard

"node-stream-zip@npm:^1.15.0":
version: 1.15.0
resolution: "node-stream-zip@npm:1.15.0"
checksum: 0b73ffbb09490e479c8f47038d7cba803e6242618fbc1b71c26782009d388742ed6fb5ce6e9d31f528b410249e7eb1c6e7534e9d3792a0cafd99813ac5a35107
languageName: node
linkType: hard

"nopt@npm:^5.0.0":
version: 5.0.0
resolution: "nopt@npm:5.0.0"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"dependencies": {
"@kablamo/kerosene": "^0.0.20",
"is-ci": "^3.0.0",
"node-stream-zip": "^1.15.0",
"typescript": "^4.3.2"
},
"resolutions": {
Expand Down
11 changes: 5 additions & 6 deletions packages/plugins/plugin-bundle/src/commands/bundle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ export default class Bundler extends BaseCommand {
});

progress(code: MESSAGE_CODE, group: MESSAGE_GROUP, msg: string): void {
// if (this.quiet !== true) {
console.info(`➤ ${code}:${group}${msg}`);
// }
if (this.quiet !== true) {
console.info(`➤ ${code}:${group}${msg}`);
}
}

async removeUnusedPackages(
Expand Down Expand Up @@ -522,11 +522,10 @@ export default class Bundler extends BaseCommand {
libzip,
});

const prefixPath = "bundle" as PortablePath;

report.reportInfo(null, "Copying files to archive");

await zipFs.copyPromise(prefixPath, tmpDir, {
// copy into the root of the zip file
await zipFs.copyPromise("/" as PortablePath, tmpDir, {
baseFs,
});

Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6814,6 +6814,13 @@ fsevents@^2.1.2:
languageName: node
linkType: hard

"node-stream-zip@npm:^1.15.0":
version: 1.15.0
resolution: "node-stream-zip@npm:1.15.0"
checksum: 0b73ffbb09490e479c8f47038d7cba803e6242618fbc1b71c26782009d388742ed6fb5ce6e9d31f528b410249e7eb1c6e7534e9d3792a0cafd99813ac5a35107
languageName: node
linkType: hard

"node.extend@npm:^2.0.0":
version: 2.0.2
resolution: "node.extend@npm:2.0.2"
Expand Down Expand Up @@ -9619,6 +9626,7 @@ resolve@^2.0.0-next.3:
is-ci: ^3.0.0
jest: ^26.6.3
jest-pnp-resolver: ^1.2.1
node-stream-zip: ^1.15.0
prettier: ^2.2.1
rimraf: ^3.0.2
shx: ^0.3.3
Expand Down

0 comments on commit 8fa056a

Please sign in to comment.