Skip to content

Commit

Permalink
feat: allow to remap directories
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrs committed Aug 29, 2023
1 parent c33860a commit f59d6da
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,46 @@ export class MainCommand extends Command {
filter: (file) => {
if (binary.files) {
return Boolean(
binary.files.some((f) => f.source === file.path),
binary.files.some((f) => {
if (f.source === file.path) {
return true;
}
// Compare by path. For example, if source is shellcheck/ and
// file is shellcheck/LICENSE.txt, we want to return true.
if (
f.source.endsWith("/") &&
file.path.startsWith(f.source)
) {
return true;
}
}),
);
}

return true;
},
map: (file) => {
if (binary.files) {
const f = binary.files.find((f) => f.source === file.path);
let remapDirectory = false;
const f = binary.files.find((f) => {
if (f.source === file.path) {
return true;
}
// Compare by path. For example, if source is shellcheck/ and
// target is directory/, and file is shellcheck/LICENSE.txt, we
// want to map it to directory/LICENSE.txt.
if (
f.source.endsWith("/") &&
file.path.startsWith(f.source)
) {
remapDirectory = true;
return true;
}
});
if (f) {
file.path = f.target;
file.path = remapDirectory
? file.path.replace(f.source, f.target)
: f.target;
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ describe("bindl", () => {
).toBeTruthy();
});

it("downloads shellcheck remapping directory", async () => {
const result = await execa.command(
`${bin} --config ${configDirectory}/remap-directory.bindl.config.cjs`,
);
expect(result.stdout).toContain(`downloading and extracting`);
expect(result.exitCode).toBe(0);

expect(
shell.test("-f", "./binaries/linux/x64/directory/shellcheck"),
).toBeTruthy();
expect(shell.test("-f", "./binaries/linux/x64/shellcheck")).toBeTruthy();
});

it("downloads only linux-arm64 binary when npm_config_arch is set", async () => {
const result = await execa.command(`${bin} --config ${configPath}`, {
// eslint-disable-next-line camelcase
Expand Down
32 changes: 32 additions & 0 deletions test/res/remap-directory.bindl.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-env node */

const version = "v0.8.0";
const shellcheckReleaseUrl = `https://github.com/koalaman/shellcheck/releases/download/${version}/shellcheck-${version}`;

module.exports = {
decompressPlugins: ["@felipecrs/decompress-tarxz"],
binaries: [
{
platform: "linux",
arch: "x64",
url: `${shellcheckReleaseUrl}.linux.x86_64.tar.xz`,
files: [
{
source: `shellcheck-${version}/`,
target: "directory/",
},
],
},
{
platform: "linux",
arch: "x64",
url: `${shellcheckReleaseUrl}.linux.x86_64.tar.xz`,
files: [
{
source: `shellcheck-${version}/`,
target: "",
},
],
},
],
};

0 comments on commit f59d6da

Please sign in to comment.