@jahed/terraform 1.13.3 → 1.13.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +2 -2
  2. package/lib/cli.js +4 -4
  3. package/lib/debug.d.ts +1 -3
  4. package/lib/debug.js +2 -3
  5. package/lib/download.d.ts +1 -6
  6. package/lib/download.js +9 -22
  7. package/lib/downloadTerraformToFile.d.ts +5 -2
  8. package/lib/downloadTerraformToFile.js +6 -11
  9. package/lib/downloadTerraformToMemory.d.ts +2 -2
  10. package/lib/downloadTerraformToMemory.js +13 -19
  11. package/lib/extractArchive.d.ts +2 -3
  12. package/lib/extractArchive.js +19 -54
  13. package/lib/fileExists.d.ts +1 -2
  14. package/lib/fileExists.js +13 -17
  15. package/lib/getArchitecture.d.ts +1 -2
  16. package/lib/getArchitecture.js +13 -10
  17. package/lib/getDownloadFilename.d.ts +2 -3
  18. package/lib/getDownloadFilename.js +3 -4
  19. package/lib/getDownloadUrl.d.ts +2 -3
  20. package/lib/getDownloadUrl.js +3 -4
  21. package/lib/getExpectedHash.d.ts +2 -3
  22. package/lib/getExpectedHash.js +29 -20
  23. package/lib/getOutputs.d.ts +2 -8
  24. package/lib/getOutputs.js +12 -13
  25. package/lib/getPlatform.d.ts +1 -2
  26. package/lib/getPlatform.js +17 -17
  27. package/lib/getVersion.d.ts +2 -3
  28. package/lib/getVersion.js +3 -5
  29. package/lib/install.d.ts +2 -2
  30. package/lib/install.js +10 -17
  31. package/lib/makeDirectory.d.ts +1 -2
  32. package/lib/makeDirectory.js +5 -6
  33. package/lib/makeExecutable.d.ts +1 -2
  34. package/lib/makeExecutable.js +12 -17
  35. package/lib/readFile.d.ts +1 -4
  36. package/lib/readFile.js +13 -17
  37. package/lib/removeDirectory.d.ts +1 -2
  38. package/lib/removeDirectory.js +8 -6
  39. package/lib/setupOutputDirectory.d.ts +2 -2
  40. package/lib/setupOutputDirectory.js +8 -5
  41. package/lib/terraform.d.ts +1 -7
  42. package/lib/types.d.ts +0 -2
  43. package/package.json +21 -12
package/README.md CHANGED
@@ -108,10 +108,10 @@ calling some other package. If you'd rather not, you can install the package
108
108
 
109
109
  ## Download Directory
110
110
 
111
- This package uses `find-cache-dir` to decide where to download files to.
111
+ This package uses `find-cache-directory` to decide where to download files to.
112
112
  Provide a `CACHE_DIR` environment variable to override the default cache
113
113
  directory. For more information, check
114
- [`find-cache-dir`'s documentation](https://github.com/avajs/find-cache-dir).
114
+ [`find-cache-directory`'s documentation](https://github.com/sindresorhus/find-cache-directory).
115
115
 
116
116
  ## FAQ & Troubleshooting
117
117
 
package/lib/cli.js CHANGED
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const child_process_1 = require("child_process");
3
+ const node_child_process_1 = require("node:child_process");
4
4
  const getOutputs_1 = require("./getOutputs");
5
5
  const install_1 = require("./install");
6
- const cli = async () => {
6
+ async function cli() {
7
7
  const args = process.argv.slice(2);
8
8
  const outputs = (0, getOutputs_1.getOutputs)();
9
9
  await (0, install_1.install)(outputs);
10
- const terraform = (0, child_process_1.spawn)(outputs.path, args, {
10
+ const terraform = (0, node_child_process_1.spawn)(outputs.path, args, {
11
11
  stdio: [process.stdin, process.stdout, process.stderr],
12
12
  });
13
13
  terraform.on("close", (code) => process.exit(code || undefined));
14
- };
14
+ }
15
15
  cli().catch((error) => {
16
16
  console.error(error);
17
17
  process.exit(1);
package/lib/debug.d.ts CHANGED
@@ -1,3 +1 @@
1
- /// <reference types="node" />
2
- declare const debug: import("util").DebugLogger;
3
- export { debug };
1
+ export declare const debug: import("util").DebugLogger;
package/lib/debug.js CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.debug = void 0;
4
- const util_1 = require("util");
5
- const debug = (0, util_1.debuglog)("@jahed/terraform");
6
- exports.debug = debug;
4
+ const node_util_1 = require("node:util");
5
+ exports.debug = (0, node_util_1.debuglog)("@jahed/terraform");
package/lib/download.d.ts CHANGED
@@ -1,6 +1 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- declare const download: (args: {
4
- url: string;
5
- }) => Promise<Buffer>;
6
- export { download };
1
+ export declare function download(url: string): Promise<Buffer>;
package/lib/download.js CHANGED
@@ -1,25 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.download = void 0;
4
- const https_1 = require("https");
5
- const debug_1 = require("./debug");
6
- const download = (args) => {
7
- (0, debug_1.debug)("downloading", args);
8
- return new Promise((resolve, reject) => {
9
- const req = (0, https_1.get)(args.url, (res) => {
10
- if (res.statusCode !== 200) {
11
- reject(new Error(`status was not okay (${res.statusCode})`));
12
- return;
13
- }
14
- const buffers = [];
15
- res.on("data", (chunk) => {
16
- buffers.push(chunk);
17
- });
18
- res.on("end", () => {
19
- resolve(Buffer.concat(buffers));
20
- });
21
- });
22
- req.on("error", reject);
23
- });
24
- };
25
3
  exports.download = download;
4
+ const debug_1 = require("./debug");
5
+ async function download(url) {
6
+ (0, debug_1.debug)("downloading", { url });
7
+ const response = await fetch(url);
8
+ if (response.status !== 200) {
9
+ throw new Error(`download status was not okay (${response.status})`);
10
+ }
11
+ return Buffer.from(await response.arrayBuffer());
12
+ }
@@ -1,2 +1,5 @@
1
- declare const downloadTerraformToFile: (initial: any) => Promise<any>;
2
- export { downloadTerraformToFile };
1
+ import type { Outputs } from "./types";
2
+ export declare function downloadTerraformToFile({ outdir, outputs, }: {
3
+ outdir?: string;
4
+ outputs: Outputs;
5
+ }): Promise<string>;
@@ -3,16 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.downloadTerraformToFile = void 0;
7
- const promises_1 = require("@jahed/promises");
8
- const path_1 = __importDefault(require("path"));
6
+ exports.downloadTerraformToFile = downloadTerraformToFile;
7
+ const node_path_1 = __importDefault(require("node:path"));
9
8
  const downloadTerraformToMemory_1 = require("./downloadTerraformToMemory");
10
9
  const extractArchive_1 = require("./extractArchive");
11
- const downloadTerraformToFile = (0, promises_1.waterfall)(({ outdir, outputs }) => {
12
- return (0, promises_1.every)({
13
- outputs,
14
- outdir: (0, promises_1.coalesce)(() => (0, promises_1.resolveNullable)(outdir), () => path_1.default.resolve(process.cwd())),
15
- buffer: (0, downloadTerraformToMemory_1.downloadTerraformToMemory)(outputs),
16
- });
17
- }, (args) => (0, extractArchive_1.extractArchive)(args));
18
- exports.downloadTerraformToFile = downloadTerraformToFile;
10
+ async function downloadTerraformToFile({ outdir = node_path_1.default.resolve(process.cwd()), outputs, }) {
11
+ const buffer = await (0, downloadTerraformToMemory_1.downloadTerraformToMemory)(outputs);
12
+ return (0, extractArchive_1.extractArchive)({ outputs, buffer, outdir });
13
+ }
@@ -1,2 +1,2 @@
1
- declare const downloadTerraformToMemory: (initial: any) => Promise<any>;
2
- export { downloadTerraformToMemory };
1
+ import type { Outputs } from "./types";
2
+ export declare function downloadTerraformToMemory(outputs: Outputs): Promise<Buffer>;
@@ -3,31 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.downloadTerraformToMemory = void 0;
7
- const promises_1 = require("@jahed/promises");
8
- const crypto_1 = __importDefault(require("crypto"));
6
+ exports.downloadTerraformToMemory = downloadTerraformToMemory;
7
+ const node_crypto_1 = __importDefault(require("node:crypto"));
9
8
  const download_1 = require("./download");
10
9
  const getArchitecture_1 = require("./getArchitecture");
11
10
  const getDownloadUrl_1 = require("./getDownloadUrl");
12
11
  const getExpectedHash_1 = require("./getExpectedHash");
13
12
  const getPlatform_1 = require("./getPlatform");
14
13
  const getVersion_1 = require("./getVersion");
15
- const downloadTerraformToMemory = (0, promises_1.waterfall)((outputs) => {
16
- return (0, promises_1.every)({
17
- version: (0, getVersion_1.getVersion)(outputs),
18
- platform: (0, getPlatform_1.getPlatform)(),
19
- architecture: (0, getArchitecture_1.getArchitecture)(),
20
- });
21
- }, (args) => {
22
- return (0, promises_1.every)({
23
- buffer: (0, promises_1.waterfall)(() => (0, getDownloadUrl_1.getDownloadUrl)(args), (url) => (0, download_1.download)({ url }))(""),
24
- expectedHash: (0, getExpectedHash_1.getExpectedHash)(args),
25
- });
26
- }, ({ buffer, expectedHash }) => {
27
- const hash = crypto_1.default.createHash("sha256").update(buffer).digest("hex");
14
+ async function downloadTerraformToMemory(outputs) {
15
+ const version = (0, getVersion_1.getVersion)(outputs);
16
+ const platform = (0, getPlatform_1.getPlatform)();
17
+ const architecture = (0, getArchitecture_1.getArchitecture)();
18
+ const downloadArgs = { version, platform, architecture };
19
+ const url = (0, getDownloadUrl_1.getDownloadUrl)(downloadArgs);
20
+ const buffer = await (0, download_1.download)(url);
21
+ const expectedHash = await (0, getExpectedHash_1.getExpectedHash)(downloadArgs);
22
+ const hash = node_crypto_1.default.createHash("sha256").update(buffer).digest("hex");
28
23
  if (hash !== expectedHash) {
29
- return (0, promises_1.rejected)((0, promises_1.reason)("downloaded archive hash did not match expected hash"));
24
+ throw new Error("downloaded archive hash did not match expected hash");
30
25
  }
31
26
  return buffer;
32
- });
33
- exports.downloadTerraformToMemory = downloadTerraformToMemory;
27
+ }
@@ -1,3 +1,2 @@
1
- import { ExtractArgs } from "./types";
2
- declare const extractArchive: ({ outputs, buffer, outdir }: ExtractArgs) => Promise<unknown>;
3
- export { extractArchive };
1
+ import type { ExtractArgs } from "./types";
2
+ export declare function extractArchive({ outputs, buffer, outdir, }: ExtractArgs): Promise<string>;
@@ -3,63 +3,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.extractArchive = void 0;
7
- const promises_1 = require("@jahed/promises");
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- const yauzl_1 = __importDefault(require("yauzl"));
6
+ exports.extractArchive = extractArchive;
7
+ const fflate_1 = __importDefault(require("fflate"));
8
+ const promises_1 = __importDefault(require("node:fs/promises"));
9
+ const node_path_1 = __importDefault(require("node:path"));
11
10
  const debug_1 = require("./debug");
12
- const extractArchive = ({ outputs, buffer, outdir }) => {
11
+ async function extractArchive({ outputs, buffer, outdir, }) {
13
12
  (0, debug_1.debug)("extracting", { outdir });
14
- return (0, promises_1.eventually)((resolve, reject) => {
15
- yauzl_1.default.fromBuffer(buffer, { lazyEntries: true }, (err, archive) => {
16
- if (err) {
17
- reject(err);
18
- return;
19
- }
20
- if (!archive) {
21
- // bad @types/yauzl
22
- reject(new Error("failed to read archive and no reason was given."));
13
+ const { [outputs.originalFilename]: fileContent } = await new Promise((resolve, reject) => {
14
+ fflate_1.default.unzip(buffer, {
15
+ filter: (file) => file.name === outputs.originalFilename,
16
+ }, (error, unzipped) => {
17
+ if (error) {
18
+ reject(error);
23
19
  return;
24
20
  }
25
- archive.on("error", (error) => reject(error));
26
- archive.on("entry", (entry) => {
27
- if (entry.fileName !== outputs.originalFilename) {
28
- // ignore LICENSE.txt and any other additional files
29
- archive.readEntry();
30
- return;
31
- }
32
- archive.openReadStream(entry, (err, readStream) => {
33
- if (err) {
34
- reject(err);
35
- return;
36
- }
37
- if (!readStream) {
38
- // bad @types/yauzl
39
- reject(new Error("failed to read archive entry and no reason was given."));
40
- return;
41
- }
42
- const filePath = path_1.default.resolve(outdir, outputs.versionedFilename);
43
- const fileStream = fs_1.default.createWriteStream(filePath);
44
- readStream.on("error", (error) => reject(error));
45
- readStream.on("end", () => {
46
- archive.close();
47
- fileStream.close((error) => {
48
- if (error) {
49
- reject(error);
50
- return;
51
- }
52
- resolve(filePath);
53
- });
54
- });
55
- readStream.pipe(fileStream);
56
- });
57
- });
58
- archive.on("end", () => {
59
- reject((0, promises_1.reason)(`expected zip to contain a terraform executable. (${outputs.originalFilename})`));
60
- });
61
- archive.readEntry();
21
+ resolve(unzipped);
62
22
  });
63
23
  });
64
- };
65
- exports.extractArchive = extractArchive;
24
+ if (!fileContent) {
25
+ throw new Error(`expected zip to contain a terraform executable. (${outputs.originalFilename})`);
26
+ }
27
+ const filePath = node_path_1.default.resolve(outdir, outputs.versionedFilename);
28
+ await promises_1.default.writeFile(filePath, fileContent);
29
+ return filePath;
30
+ }
@@ -1,2 +1 @@
1
- declare const fileExists: (file: string) => Promise<void>;
2
- export { fileExists };
1
+ export declare function fileExists(file: string): Promise<boolean>;
package/lib/fileExists.js CHANGED
@@ -3,21 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.fileExists = void 0;
7
- const promises_1 = require("@jahed/promises");
8
- const fs_1 = __importDefault(require("fs"));
9
- const debug_1 = require("./debug");
10
- const fileExists = (file) => {
11
- return (0, promises_1.eventually)((resolve, reject) => {
12
- fs_1.default.access(file, (err) => {
13
- if (err) {
14
- (0, debug_1.debug)("file does not exist", { file });
15
- reject(err);
16
- return;
17
- }
18
- (0, debug_1.debug)("file already exists", { file });
19
- resolve();
20
- });
21
- });
22
- };
23
6
  exports.fileExists = fileExists;
7
+ const promises_1 = __importDefault(require("node:fs/promises"));
8
+ const debug_1 = require("./debug");
9
+ async function fileExists(file) {
10
+ try {
11
+ await promises_1.default.access(file);
12
+ (0, debug_1.debug)("file already exists", { file });
13
+ return true;
14
+ }
15
+ catch {
16
+ (0, debug_1.debug)("file does not exist", { file });
17
+ return false;
18
+ }
19
+ }
@@ -1,2 +1 @@
1
- declare const getArchitecture: () => Promise<string>;
2
- export { getArchitecture };
1
+ export declare function getArchitecture(): string;
@@ -1,13 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getArchitecture = void 0;
4
- const promises_1 = require("@jahed/promises");
5
- const getArchitecture = () => {
6
- return (0, promises_1.resolveNullable)({
7
- arm: "arm",
8
- arm64: "arm64",
9
- x32: "386",
10
- x64: "amd64",
11
- }[process.arch], (0, promises_1.reason)(`"${process.arch}" architecture is not supported by terraform.`));
12
- };
13
3
  exports.getArchitecture = getArchitecture;
4
+ function getArchitecture() {
5
+ switch (process.arch) {
6
+ case "x64":
7
+ return "amd64";
8
+ case "arm64":
9
+ return "arm64";
10
+ case "ia32":
11
+ return "386";
12
+ case "arm":
13
+ return "arm";
14
+ }
15
+ throw new Error(`"${process.arch}" architecture is not supported by terraform.`);
16
+ }
@@ -1,3 +1,2 @@
1
- import { DownloadArgs } from "./types";
2
- declare const getDownloadFilename: ({ version, platform, architecture, }: DownloadArgs) => string;
3
- export { getDownloadFilename };
1
+ import type { DownloadArgs } from "./types";
2
+ export declare function getDownloadFilename({ version, platform, architecture, }: DownloadArgs): string;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDownloadFilename = void 0;
4
- const getDownloadFilename = ({ version, platform, architecture, }) => {
5
- return `terraform_${version}_${platform}_${architecture}.zip`;
6
- };
7
3
  exports.getDownloadFilename = getDownloadFilename;
4
+ function getDownloadFilename({ version, platform, architecture, }) {
5
+ return `terraform_${version}_${platform}_${architecture}.zip`;
6
+ }
@@ -1,3 +1,2 @@
1
- import { DownloadArgs } from "./types";
2
- declare const getDownloadUrl: (args: DownloadArgs) => string;
3
- export { getDownloadUrl };
1
+ import type { DownloadArgs } from "./types";
2
+ export declare function getDownloadUrl(args: DownloadArgs): string;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDownloadUrl = void 0;
3
+ exports.getDownloadUrl = getDownloadUrl;
4
4
  const getDownloadFilename_1 = require("./getDownloadFilename");
5
- const getDownloadUrl = (args) => {
5
+ function getDownloadUrl(args) {
6
6
  return `https://releases.hashicorp.com/terraform/${args.version}/${(0, getDownloadFilename_1.getDownloadFilename)(args)}`;
7
- };
8
- exports.getDownloadUrl = getDownloadUrl;
7
+ }
@@ -1,3 +1,2 @@
1
- import { DownloadArgs } from "./types";
2
- declare const getExpectedHash: (args: DownloadArgs) => Promise<string>;
3
- export { getExpectedHash };
1
+ import type { DownloadArgs } from "./types";
2
+ export declare function getExpectedHash(args: DownloadArgs): Promise<string>;
@@ -15,34 +15,44 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getExpectedHash = void 0;
30
- const path_1 = __importDefault(require("path"));
31
- const getDownloadFilename_1 = require("./getDownloadFilename");
32
- const promises_1 = require("fs/promises");
33
- const download_1 = require("./download");
39
+ exports.getExpectedHash = getExpectedHash;
40
+ const promises_1 = require("node:fs/promises");
41
+ const node_path_1 = __importDefault(require("node:path"));
34
42
  const openpgp = __importStar(require("openpgp"));
35
- const getHashesUrl = ({ version }) => {
43
+ const download_1 = require("./download");
44
+ const getDownloadFilename_1 = require("./getDownloadFilename");
45
+ function getHashesUrl({ version }) {
36
46
  return `https://releases.hashicorp.com/terraform/${version}/terraform_${version}_SHA256SUMS`;
37
- };
38
- const getExpectedHash = async (args) => {
47
+ }
48
+ async function getExpectedHash(args) {
39
49
  const hashUrl = getHashesUrl(args);
40
- const hashes = await (0, download_1.download)({ url: hashUrl });
50
+ const hashes = await (0, download_1.download)(hashUrl);
41
51
  const publicKey = await openpgp.readKey({
42
- armoredKey: await (0, promises_1.readFile)(path_1.default.resolve(__dirname, "../hashicorp.asc"), "utf-8"),
52
+ armoredKey: await (0, promises_1.readFile)(node_path_1.default.resolve(__dirname, "../hashicorp.asc"), "utf-8"),
43
53
  });
44
54
  const signature = await openpgp.readSignature({
45
- binarySignature: await (0, download_1.download)({ url: `${hashUrl}.sig` }),
55
+ binarySignature: await (0, download_1.download)(`${hashUrl}.sig`),
46
56
  });
47
57
  const { signatures: [{ verified }], } = await openpgp.verify({
48
58
  message: await openpgp.createMessage({ binary: hashes }),
@@ -63,5 +73,4 @@ const getExpectedHash = async (args) => {
63
73
  }
64
74
  }
65
75
  throw new Error(`expected hash not found for file (${filename})`);
66
- };
67
- exports.getExpectedHash = getExpectedHash;
76
+ }
@@ -1,8 +1,2 @@
1
- declare const getOutputs: () => {
2
- version: any;
3
- path: string;
4
- filename: string;
5
- versionedFilename: string;
6
- originalFilename: string;
7
- };
8
- export { getOutputs };
1
+ import type { Outputs } from "./types";
2
+ export declare function getOutputs(): Outputs;
package/lib/getOutputs.js CHANGED
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getOutputs = void 0;
7
- const find_cache_dir_1 = __importDefault(require("find-cache-dir"));
8
- const path_1 = __importDefault(require("path"));
9
- const fs_1 = __importDefault(require("fs"));
10
- const getFilenames = (version) => {
6
+ exports.getOutputs = getOutputs;
7
+ const find_cache_directory_1 = __importDefault(require("find-cache-directory"));
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ function getFilenames(version) {
11
11
  if (process.platform === "win32") {
12
12
  return {
13
13
  originalFilename: "terraform.exe",
@@ -18,13 +18,13 @@ const getFilenames = (version) => {
18
18
  originalFilename: "terraform",
19
19
  versionedFilename: `terraform-v${version}`,
20
20
  };
21
- };
22
- const getOutputs = () => {
23
- const packageJson = JSON.parse(fs_1.default
24
- .readFileSync(path_1.default.resolve(__dirname, "../package.json"))
21
+ }
22
+ function getOutputs() {
23
+ const packageJson = JSON.parse(node_fs_1.default
24
+ .readFileSync(node_path_1.default.resolve(__dirname, "../package.json"))
25
25
  .toString("utf-8"));
26
26
  const version = packageJson.version.split("-")[0];
27
- const cacheDir = (0, find_cache_dir_1.default)({
27
+ const cacheDir = (0, find_cache_directory_1.default)({
28
28
  name: packageJson.name,
29
29
  cwd: process.env.INIT_CWD,
30
30
  });
@@ -32,7 +32,7 @@ const getOutputs = () => {
32
32
  throw new Error("could not find cache directory");
33
33
  }
34
34
  const { originalFilename, versionedFilename } = getFilenames(version);
35
- const execPath = path_1.default.resolve(cacheDir, versionedFilename);
35
+ const execPath = node_path_1.default.resolve(cacheDir, versionedFilename);
36
36
  return {
37
37
  version,
38
38
  path: execPath,
@@ -40,5 +40,4 @@ const getOutputs = () => {
40
40
  versionedFilename,
41
41
  originalFilename,
42
42
  };
43
- };
44
- exports.getOutputs = getOutputs;
43
+ }
@@ -1,2 +1 @@
1
- declare const getPlatform: () => Promise<string | null>;
2
- export { getPlatform };
1
+ export declare function getPlatform(): string;
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPlatform = void 0;
4
- const promises_1 = require("@jahed/promises");
5
- const getPlatform = () => {
6
- return (0, promises_1.resolveNullable)({
7
- aix: null,
8
- darwin: "darwin",
9
- freebsd: "freebsd",
10
- linux: "linux",
11
- openbsd: "openbsd",
12
- sunos: "solaris",
13
- win32: "windows",
14
- android: null,
15
- cygwin: null,
16
- netbsd: null,
17
- haiku: null,
18
- }[process.platform], (0, promises_1.reason)(`"${process.platform}" platform is not supported by terraform.`));
19
- };
20
3
  exports.getPlatform = getPlatform;
4
+ function getPlatform() {
5
+ switch (process.platform) {
6
+ case "darwin":
7
+ return "darwin";
8
+ case "freebsd":
9
+ return "freebsd";
10
+ case "linux":
11
+ return "linux";
12
+ case "openbsd":
13
+ return "openbsd";
14
+ case "sunos":
15
+ return "solaris";
16
+ case "win32":
17
+ return "windows";
18
+ }
19
+ throw new Error(`"${process.platform}" platform is not supported by terraform.`);
20
+ }
@@ -1,3 +1,2 @@
1
- import { Outputs } from "./types";
2
- declare const getVersion: (outputs: Outputs) => Promise<string>;
3
- export { getVersion };
1
+ import type { Outputs } from "./types";
2
+ export declare function getVersion(outputs: Outputs): string;
package/lib/getVersion.js CHANGED
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVersion = void 0;
4
- const promises_1 = require("@jahed/promises");
5
- const getVersion = (outputs) => {
6
- return (0, promises_1.resolved)(outputs.version);
7
- };
8
3
  exports.getVersion = getVersion;
4
+ function getVersion(outputs) {
5
+ return outputs.version;
6
+ }
package/lib/install.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const install: (initial: any) => Promise<any>;
2
- export { install };
1
+ import type { Outputs } from "./types";
2
+ export declare function install(outputs: Outputs): Promise<string>;
package/lib/install.js CHANGED
@@ -1,25 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.install = void 0;
4
- const promises_1 = require("@jahed/promises");
3
+ exports.install = install;
5
4
  const debug_1 = require("./debug");
6
5
  const downloadTerraformToFile_1 = require("./downloadTerraformToFile");
7
6
  const fileExists_1 = require("./fileExists");
8
7
  const makeExecutable_1 = require("./makeExecutable");
9
8
  const setupOutputDirectory_1 = require("./setupOutputDirectory");
10
- const exit = () => (0, promises_1.branch)((filePath) => {
9
+ async function install(outputs) {
10
+ if (await (0, fileExists_1.fileExists)(outputs.path)) {
11
+ return outputs.path;
12
+ }
13
+ const outdir = await (0, setupOutputDirectory_1.setupOutputDirectory)(outputs);
14
+ const filePath = await (0, downloadTerraformToFile_1.downloadTerraformToFile)({ outputs, outdir });
15
+ await (0, makeExecutable_1.makeExecutable)(filePath);
11
16
  (0, debug_1.debug)("installed terraform", { path: filePath });
12
- }, (error) => {
13
- (0, debug_1.debug)("failed to install terraform.", error);
14
- process.exit(1);
15
- });
16
- const downloadTerraformToDirectory = () => (0, promises_1.waterfall)((outputs) => (0, promises_1.every)({
17
- outputs,
18
- outdir: (0, setupOutputDirectory_1.setupOutputDirectory)(outputs),
19
- }), (args) => (0, downloadTerraformToFile_1.downloadTerraformToFile)(args), (0, promises_1.relay)((filePath) => (0, makeExecutable_1.makeExecutable)(filePath)));
20
- const doInstall = () => (0, promises_1.compose)(downloadTerraformToDirectory(), exit());
21
- const checkPrerequisites = () => {
22
- return (0, promises_1.relay)((outputs) => (0, promises_1.not)((0, fileExists_1.fileExists)(outputs.path)));
23
- };
24
- const install = (0, promises_1.compose)(checkPrerequisites(), (0, promises_1.branch)(doInstall(), (0, promises_1.doNothing)()));
25
- exports.install = install;
17
+ return filePath;
18
+ }
@@ -1,2 +1 @@
1
- declare const makeDirectory: (directory: string) => Promise<string | undefined>;
2
- export { makeDirectory };
1
+ export declare function makeDirectory(directory: string): Promise<void>;
@@ -3,11 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.makeDirectory = void 0;
7
- const fs_1 = __importDefault(require("fs"));
6
+ exports.makeDirectory = makeDirectory;
7
+ const promises_1 = __importDefault(require("node:fs/promises"));
8
8
  const debug_1 = require("./debug");
9
- const makeDirectory = (directory) => {
9
+ async function makeDirectory(directory) {
10
10
  (0, debug_1.debug)("making directory", { directory });
11
- return fs_1.default.promises.mkdir(directory, { recursive: true });
12
- };
13
- exports.makeDirectory = makeDirectory;
11
+ await promises_1.default.mkdir(directory, { recursive: true });
12
+ }
@@ -1,2 +1 @@
1
- declare const makeExecutable: (file: string) => Promise<void>;
2
- export { makeExecutable };
1
+ export declare function makeExecutable(file: string): Promise<void>;
@@ -3,21 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.makeExecutable = void 0;
7
- const promises_1 = require("@jahed/promises");
8
- const fs_1 = __importDefault(require("fs"));
9
- const debug_1 = require("./debug");
10
- const makeExecutable = (file) => {
11
- return (0, promises_1.eventually)((resolve, reject) => {
12
- fs_1.default.chmod(file, 0o700, (err) => {
13
- if (err) {
14
- (0, debug_1.debug)("failed to make file executable", { file });
15
- reject(err);
16
- return;
17
- }
18
- (0, debug_1.debug)("made file executable", { file });
19
- resolve();
20
- });
21
- });
22
- };
23
6
  exports.makeExecutable = makeExecutable;
7
+ const promises_1 = __importDefault(require("node:fs/promises"));
8
+ const debug_1 = require("./debug");
9
+ async function makeExecutable(file) {
10
+ try {
11
+ await promises_1.default.chmod(file, 0o700);
12
+ (0, debug_1.debug)("made file executable", { file });
13
+ }
14
+ catch (error) {
15
+ (0, debug_1.debug)("failed to make file executable", { file });
16
+ throw error;
17
+ }
18
+ }
package/lib/readFile.d.ts CHANGED
@@ -1,4 +1 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- declare const readFile: (file: string) => Promise<Buffer>;
4
- export { readFile };
1
+ export declare function readFile(file: string): Promise<Buffer>;
package/lib/readFile.js CHANGED
@@ -3,21 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.readFile = void 0;
7
- const promises_1 = require("@jahed/promises");
8
- const fs_1 = __importDefault(require("fs"));
9
- const debug_1 = require("./debug");
10
- const readFile = (file) => {
11
- return (0, promises_1.eventually)((resolve, reject) => {
12
- fs_1.default.readFile(file, (err, buffer) => {
13
- if (err) {
14
- (0, debug_1.debug)("failed to read file", { file });
15
- reject(err);
16
- return;
17
- }
18
- (0, debug_1.debug)("read file", { file });
19
- resolve(buffer);
20
- });
21
- });
22
- };
23
6
  exports.readFile = readFile;
7
+ const promises_1 = __importDefault(require("node:fs/promises"));
8
+ const debug_1 = require("./debug");
9
+ async function readFile(file) {
10
+ try {
11
+ const buffer = await promises_1.default.readFile(file);
12
+ (0, debug_1.debug)("read file", { file });
13
+ return buffer;
14
+ }
15
+ catch (error) {
16
+ (0, debug_1.debug)("failed to read file", { file });
17
+ throw error;
18
+ }
19
+ }
@@ -1,2 +1 @@
1
- declare const removeDirectory: (directory: string) => Promise<void>;
2
- export { removeDirectory };
1
+ export declare function removeDirectory(directory: string): Promise<void>;
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeDirectory = void 0;
6
+ exports.removeDirectory = removeDirectory;
7
+ const promises_1 = __importDefault(require("node:fs/promises"));
4
8
  const debug_1 = require("./debug");
5
- const promises_1 = require("fs/promises");
6
- const removeDirectory = (directory) => {
9
+ async function removeDirectory(directory) {
7
10
  (0, debug_1.debug)("removing directory", { directory });
8
- return (0, promises_1.rm)(directory, { recursive: true, force: true });
9
- };
10
- exports.removeDirectory = removeDirectory;
11
+ await promises_1.default.rm(directory, { recursive: true, force: true });
12
+ }
@@ -1,2 +1,2 @@
1
- declare const setupOutputDirectory: (initial: any) => Promise<any>;
2
- export { setupOutputDirectory };
1
+ import type { Outputs } from "./types";
2
+ export declare function setupOutputDirectory(outputs: Outputs): Promise<string>;
@@ -3,10 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.setupOutputDirectory = void 0;
7
- const promises_1 = require("@jahed/promises");
8
- const path_1 = __importDefault(require("path"));
6
+ exports.setupOutputDirectory = setupOutputDirectory;
7
+ const node_path_1 = __importDefault(require("node:path"));
9
8
  const makeDirectory_1 = require("./makeDirectory");
10
9
  const removeDirectory_1 = require("./removeDirectory");
11
- const setupOutputDirectory = (0, promises_1.waterfall)((outputs) => path_1.default.dirname(outputs.path), (0, promises_1.relay)((outdir) => (0, removeDirectory_1.removeDirectory)(outdir), (outdir) => (0, makeDirectory_1.makeDirectory)(outdir)));
12
- exports.setupOutputDirectory = setupOutputDirectory;
10
+ async function setupOutputDirectory(outputs) {
11
+ const outdir = node_path_1.default.dirname(outputs.path);
12
+ await (0, removeDirectory_1.removeDirectory)(outdir);
13
+ await (0, makeDirectory_1.makeDirectory)(outdir);
14
+ return outdir;
15
+ }
@@ -1,8 +1,2 @@
1
- declare const _default: {
2
- version: any;
3
- path: string;
4
- filename: string;
5
- versionedFilename: string;
6
- originalFilename: string;
7
- };
1
+ declare const _default: import("./types").Outputs;
8
2
  export default _default;
package/lib/types.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  export type Outputs = {
4
2
  path: string;
5
3
  version: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jahed/terraform",
3
- "version": "1.13.3",
3
+ "version": "1.13.5",
4
4
  "description": "A wrapper which downloads and runs Terraform locally via npm.",
5
5
  "author": "Jahed Ahmed <jahed.public@gmail.com> (https://jahed.dev)",
6
6
  "license": "MIT",
@@ -25,24 +25,33 @@
25
25
  "lib",
26
26
  "hashicorp.asc"
27
27
  ],
28
+ "devEngines": {
29
+ "runtime": {
30
+ "name": "node",
31
+ "version": "20",
32
+ "onFail": "warn"
33
+ },
34
+ "packageManager": {
35
+ "name": "npm",
36
+ "version": "10",
37
+ "onFail": "warn"
38
+ }
39
+ },
28
40
  "scripts": {
29
41
  "lint": "prettier -c .",
42
+ "format": "prettier -w .",
30
43
  "build": "rm -rf ./lib ./artifacts && tsc && mkdir ./artifacts && mv \"$(npm pack)\" ./artifacts/package.tgz",
31
44
  "test": "./tests/run.sh"
32
45
  },
33
46
  "dependencies": {
34
- "@jahed/promises": "^1.0.2",
35
- "find-cache-dir": "^3.3.2",
36
- "openpgp": "^5.11.3",
37
- "yauzl": "^2.10.0"
47
+ "fflate": "^0.8.2",
48
+ "find-cache-directory": "^6.0.0",
49
+ "openpgp": "^6.0.0"
38
50
  },
39
51
  "devDependencies": {
40
- "@tsconfig/node16": "^1.0.4",
41
- "@types/find-cache-dir": "^3.2.1",
42
- "@types/node": "^16.18.126",
43
- "@types/yauzl": "^2.10.3",
44
- "npm-check-updates": "^16.14.20",
45
- "prettier": "^2.8.8",
46
- "typescript": "4.9.x"
52
+ "@tsconfig/node20": "^20.1.6",
53
+ "@types/node": "^20.19.17",
54
+ "prettier": "^3.6.2",
55
+ "typescript": "5.9.x"
47
56
  }
48
57
  }