@webiny/pulumi-sdk 6.3.0-beta.4 → 6.4.0-beta.0
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.
- package/Pulumi.js +100 -129
- package/Pulumi.js.map +1 -1
- package/downloadBinaries.js +60 -68
- package/downloadBinaries.js.map +1 -1
- package/downloadFile.js +16 -17
- package/downloadFile.js.map +1 -1
- package/index.js +0 -2
- package/package.json +8 -8
- package/index.js.map +0 -1
package/Pulumi.js
CHANGED
|
@@ -1,144 +1,115 @@
|
|
|
1
1
|
import os from "os";
|
|
2
2
|
import execa from "execa";
|
|
3
|
-
import
|
|
4
|
-
import fs from "fs-extra";
|
|
3
|
+
import fs_extra from "fs-extra";
|
|
5
4
|
import merge from "lodash/merge.js";
|
|
6
5
|
import kebabCase from "lodash/kebabCase.js";
|
|
7
6
|
import set from "lodash/set.js";
|
|
8
7
|
import downloadBinaries from "./downloadBinaries.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
constructor(options = {}) {
|
|
21
|
-
this.options = options;
|
|
22
|
-
this.pulumiDownloadFolder = path.join(options.pulumiFolder || process.cwd(), "pulumi-cli", os.platform());
|
|
23
|
-
this.pulumiFolder = path.join(this.pulumiDownloadFolder, "pulumi");
|
|
24
|
-
this.pulumiBinaryPath = path.join(this.pulumiFolder, "pulumi");
|
|
25
|
-
}
|
|
26
|
-
run(rawArgs) {
|
|
27
|
-
const args = merge({}, this.options, rawArgs);
|
|
28
|
-
if (!Array.isArray(args.command)) {
|
|
29
|
-
args.command = [args.command];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// 1. Prepare Pulumi args.
|
|
33
|
-
const finalArgs = [];
|
|
34
|
-
for (const key in args.args) {
|
|
35
|
-
const value = args.args[key];
|
|
36
|
-
if (!value) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (Array.isArray(value)) {
|
|
40
|
-
for (let i = 0; i < value.length; i++) {
|
|
41
|
-
finalArgs.push(`--${kebabCase(key)}`, value[i]);
|
|
42
|
-
}
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
if (typeof value === "boolean") {
|
|
46
|
-
finalArgs.push(`--${kebabCase(key)}`);
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
finalArgs.push(`--${kebabCase(key)}`, value);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Prepare execa args.
|
|
53
|
-
if (!args.execa) {
|
|
54
|
-
args.execa = {};
|
|
55
|
-
}
|
|
56
|
-
set(args.execa, "env.PULUMI_SKIP_UPDATE_CHECK", "true");
|
|
57
|
-
set(args.execa, "env.PULUMI_HOME", this.pulumiFolder);
|
|
58
|
-
if (os.arch() === "arm64") {
|
|
59
|
-
/**
|
|
60
|
-
* This variable is an attempt to resolve this issue:
|
|
61
|
-
* https://yaleman.org/post/2021/2021-01-01-apple-m1-terraform-and-golang/
|
|
62
|
-
*/
|
|
63
|
-
set(args.execa, "env.GODEBUG", "asyncpreemptoff=1");
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Use ";" when on Windows. For Mac and Linux, use ":".
|
|
67
|
-
const PATH_SEPARATOR = os.platform() === "win32" ? ";" : ":";
|
|
68
|
-
const execaArgs = {
|
|
69
|
-
...args.execa,
|
|
70
|
-
env: {
|
|
71
|
-
...(args.execa.env || {}),
|
|
72
|
-
/**
|
|
73
|
-
* Due to an issue with Pulumi https://github.com/pulumi/pulumi/issues/8374, and even though this
|
|
74
|
-
* commit suggests it should already work like that https://github.com/pulumi/pulumi/commit/c878916901a997a9c0ffcbed23560e19e224a6f1,
|
|
75
|
-
* we need to specify the exact location of our Pulumi binaries, using the PATH environment variable, so it can correctly resolve
|
|
76
|
-
* plugins necessary for custom resources and dynamic providers to work.
|
|
77
|
-
*/
|
|
78
|
-
PATH: this.pulumiFolder + PATH_SEPARATOR + process.env.PATH
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// We want to keep the "interactive" output format of the Pulumi command when `--preview` flag is passed in.
|
|
83
|
-
const flags = args.command && args.command.includes("preview") ? [] : [FLAG_NON_INTERACTIVE];
|
|
84
|
-
const pulumiProcess = execa(this.pulumiBinaryPath, [...args.command, ...finalArgs, ...flags], execaArgs);
|
|
85
|
-
|
|
86
|
-
// We want to throw an instance of PulumiError when the Pulumi command fails.
|
|
87
|
-
// Makes it easier to catch and handle Pulumi errors in the code.
|
|
88
|
-
// Note: this code definitely looks funky, but it is because how `execa` works.
|
|
89
|
-
const wrapped = pulumiProcess.then(result => result, err => {
|
|
90
|
-
throw new PulumiError(err.stderr || err.stdout || err.message, {
|
|
91
|
-
cause: err
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
Object.assign(wrapped, pulumiProcess);
|
|
95
|
-
return wrapped;
|
|
96
|
-
}
|
|
97
|
-
async install(rawArgs) {
|
|
98
|
-
const args = merge({}, this.options, rawArgs);
|
|
99
|
-
return await downloadBinaries(this.pulumiDownloadFolder, args.beforePulumiInstall, args.afterPulumiInstall);
|
|
100
|
-
}
|
|
101
|
-
async ensureAwsPluginIsInstalled() {
|
|
102
|
-
let pulumiAwsVersion = "";
|
|
103
|
-
const {
|
|
104
|
-
stdout
|
|
105
|
-
} = execa.sync("yarn", ["info", "@pulumi/aws", "-A", "-R", "--name-only", "--json"]);
|
|
106
|
-
const match = stdout.match(/npm:(.*?)"/);
|
|
107
|
-
if (match) {
|
|
108
|
-
pulumiAwsVersion = match[1];
|
|
8
|
+
import * as __rspack_external_path from "path";
|
|
9
|
+
const FLAG_NON_INTERACTIVE = "--non-interactive";
|
|
10
|
+
class PulumiError extends Error {
|
|
11
|
+
}
|
|
12
|
+
class Pulumi {
|
|
13
|
+
static async create(options = {}) {
|
|
14
|
+
const pulumi = new Pulumi(options);
|
|
15
|
+
await pulumi.install();
|
|
16
|
+
await pulumi.ensureAwsPluginIsInstalled();
|
|
17
|
+
return pulumi;
|
|
109
18
|
}
|
|
110
|
-
|
|
111
|
-
|
|
19
|
+
constructor(options = {}){
|
|
20
|
+
this.options = options;
|
|
21
|
+
this.pulumiDownloadFolder = __rspack_external_path.join(options.pulumiFolder || process.cwd(), "pulumi-cli", os.platform());
|
|
22
|
+
this.pulumiFolder = __rspack_external_path.join(this.pulumiDownloadFolder, "pulumi");
|
|
23
|
+
this.pulumiBinaryPath = __rspack_external_path.join(this.pulumiFolder, "pulumi");
|
|
112
24
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
25
|
+
run(rawArgs) {
|
|
26
|
+
const args = merge({}, this.options, rawArgs);
|
|
27
|
+
if (!Array.isArray(args.command)) args.command = [
|
|
28
|
+
args.command
|
|
29
|
+
];
|
|
30
|
+
const finalArgs = [];
|
|
31
|
+
for(const key in args.args){
|
|
32
|
+
const value = args.args[key];
|
|
33
|
+
if (value) {
|
|
34
|
+
if (Array.isArray(value)) {
|
|
35
|
+
for(let i = 0; i < value.length; i++)finalArgs.push(`--${kebabCase(key)}`, value[i]);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if ("boolean" == typeof value) {
|
|
39
|
+
finalArgs.push(`--${kebabCase(key)}`);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
finalArgs.push(`--${kebabCase(key)}`, value);
|
|
43
|
+
}
|
|
123
44
|
}
|
|
124
|
-
|
|
45
|
+
if (!args.execa) args.execa = {};
|
|
46
|
+
set(args.execa, "env.PULUMI_SKIP_UPDATE_CHECK", "true");
|
|
47
|
+
set(args.execa, "env.PULUMI_HOME", this.pulumiFolder);
|
|
48
|
+
if ("arm64" === os.arch()) set(args.execa, "env.GODEBUG", "asyncpreemptoff=1");
|
|
49
|
+
const PATH_SEPARATOR = "win32" === os.platform() ? ";" : ":";
|
|
50
|
+
const execaArgs = {
|
|
51
|
+
...args.execa,
|
|
52
|
+
env: {
|
|
53
|
+
...args.execa.env || {},
|
|
54
|
+
PATH: this.pulumiFolder + PATH_SEPARATOR + process.env.PATH
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const flags = args.command && args.command.includes("preview") ? [] : [
|
|
58
|
+
FLAG_NON_INTERACTIVE
|
|
59
|
+
];
|
|
60
|
+
const pulumiProcess = execa(this.pulumiBinaryPath, [
|
|
61
|
+
...args.command,
|
|
62
|
+
...finalArgs,
|
|
63
|
+
...flags
|
|
64
|
+
], execaArgs);
|
|
65
|
+
const wrapped = pulumiProcess.then((result)=>result, (err)=>{
|
|
66
|
+
throw new PulumiError(err.stderr || err.stdout || err.message, {
|
|
67
|
+
cause: err
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
Object.assign(wrapped, pulumiProcess);
|
|
71
|
+
return wrapped;
|
|
125
72
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
73
|
+
async install(rawArgs) {
|
|
74
|
+
const args = merge({}, this.options, rawArgs);
|
|
75
|
+
return await downloadBinaries(this.pulumiDownloadFolder, args.beforePulumiInstall, args.afterPulumiInstall);
|
|
76
|
+
}
|
|
77
|
+
async ensureAwsPluginIsInstalled() {
|
|
78
|
+
let pulumiAwsVersion = "";
|
|
79
|
+
const { stdout } = execa.sync("yarn", [
|
|
80
|
+
"info",
|
|
81
|
+
"@pulumi/aws",
|
|
82
|
+
"-A",
|
|
83
|
+
"-R",
|
|
84
|
+
"--name-only",
|
|
85
|
+
"--json"
|
|
86
|
+
]);
|
|
87
|
+
const match = stdout.match(/npm:(.*?)"/);
|
|
88
|
+
if (match) pulumiAwsVersion = match[1];
|
|
89
|
+
if (!pulumiAwsVersion) throw new PulumiError("Could not determine the version of @pulumi/aws package. Please ensure it is installed.");
|
|
90
|
+
const pluginsDir = __rspack_external_path.join(this.pulumiFolder, "plugins");
|
|
91
|
+
const requiredPluginDir = `resource-aws-v${pulumiAwsVersion}`;
|
|
92
|
+
const pluginExists = fs_extra.pathExistsSync(__rspack_external_path.join(pluginsDir, requiredPluginDir, "pulumi-resource-aws"));
|
|
93
|
+
if (!pluginExists) execa.sync(this.pulumiBinaryPath, [
|
|
94
|
+
"plugin",
|
|
95
|
+
"install",
|
|
96
|
+
"resource",
|
|
97
|
+
"aws",
|
|
98
|
+
pulumiAwsVersion
|
|
99
|
+
], {
|
|
100
|
+
stdio: "inherit",
|
|
101
|
+
env: {
|
|
102
|
+
PULUMI_HOME: this.pulumiFolder,
|
|
103
|
+
PULUMI_SKIP_UPDATE_CHECK: "true"
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
if (fs_extra.pathExistsSync(pluginsDir)) for (const entry of fs_extra.readdirSync(pluginsDir)){
|
|
107
|
+
if (!entry.startsWith("resource-aws-") || entry === requiredPluginDir) continue;
|
|
108
|
+
const baseName = entry.endsWith(".lock") ? entry.slice(0, -5) : entry;
|
|
109
|
+
if (baseName !== requiredPluginDir) fs_extra.removeSync(__rspack_external_path.join(pluginsDir, entry));
|
|
138
110
|
}
|
|
139
|
-
}
|
|
140
111
|
}
|
|
141
|
-
}
|
|
142
112
|
}
|
|
113
|
+
export { FLAG_NON_INTERACTIVE, Pulumi, PulumiError };
|
|
143
114
|
|
|
144
115
|
//# sourceMappingURL=Pulumi.js.map
|
package/Pulumi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["os","execa","path","fs","merge","kebabCase","set","downloadBinaries","FLAG_NON_INTERACTIVE","PulumiError","Error","Pulumi","create","options","pulumi","install","ensureAwsPluginIsInstalled","constructor","pulumiDownloadFolder","join","pulumiFolder","process","cwd","platform","pulumiBinaryPath","run","rawArgs","args","Array","isArray","command","finalArgs","key","value","i","length","push","arch","PATH_SEPARATOR","execaArgs","env","PATH","flags","includes","pulumiProcess","wrapped","then","result","err","stderr","stdout","message","cause","Object","assign","beforePulumiInstall","afterPulumiInstall","pulumiAwsVersion","sync","match","pluginsDir","requiredPluginDir","pluginExists","pathExistsSync","stdio","PULUMI_HOME","PULUMI_SKIP_UPDATE_CHECK","entry","readdirSync","startsWith","baseName","endsWith","slice","removeSync"],"sources":["Pulumi.ts"],"sourcesContent":["import os from \"os\";\nimport execa, { ExecaChildProcess } from \"execa\";\nimport * as path from \"path\";\nimport fs from \"fs-extra\";\nimport merge from \"lodash/merge.js\";\nimport kebabCase from \"lodash/kebabCase.js\";\nimport set from \"lodash/set.js\";\nimport downloadBinaries from \"./downloadBinaries.js\";\n\ntype Command = string | string[];\n\nexport interface PulumiArgs {\n [key: string]: string | boolean | undefined | string[];\n}\n\nexport interface ExecaArgs {\n env?: {\n [key: string]: string | undefined;\n };\n\n [key: string]: any;\n}\n\nexport interface Options {\n args?: PulumiArgs;\n execa?: ExecaArgs;\n beforePulumiInstall?: () => any;\n afterPulumiInstall?: () => any;\n\n // A folder into which the Pulumi CLI, along with all of its meta data and config files, will be set up.\n // It's recommended this folder is not checked in into a code repository, since the Pulumi CLI can store\n // sensitive information here, for example - user's Pulumi Service credentials.\n pulumiFolder?: string;\n}\n\nexport interface RunArgs {\n command: Command;\n args?: PulumiArgs;\n execa?: ExecaArgs;\n beforePulumiInstall?: () => any;\n afterPulumiInstall?: () => any;\n}\n\nexport interface InstallArgs {\n beforePulumiInstall?: () => any;\n afterPulumiInstall?: () => any;\n}\n\nexport const FLAG_NON_INTERACTIVE = \"--non-interactive\";\n\nexport class PulumiError extends Error {}\n\nexport class Pulumi {\n options: Options;\n pulumiFolder: string;\n pulumiDownloadFolder: string;\n pulumiBinaryPath: string;\n\n static async create(options: Options = {}) {\n const pulumi = new Pulumi(options);\n // If not already installed, Pulumi binaries will be downloaded in this step.\n await pulumi.install();\n // No matter if it's a fresh installation or not, we make sure that Pulumi AWS plugin is installed.\n await pulumi.ensureAwsPluginIsInstalled();\n return pulumi;\n }\n\n private constructor(options: Options = {}) {\n this.options = options;\n\n this.pulumiDownloadFolder = path.join(\n options.pulumiFolder || process.cwd(),\n \"pulumi-cli\",\n os.platform()\n );\n\n this.pulumiFolder = path.join(this.pulumiDownloadFolder, \"pulumi\");\n this.pulumiBinaryPath = path.join(this.pulumiFolder, \"pulumi\");\n }\n\n run(rawArgs: RunArgs) {\n const args = merge({}, this.options, rawArgs);\n\n if (!Array.isArray(args.command)) {\n args.command = [args.command];\n }\n\n // 1. Prepare Pulumi args.\n const finalArgs = [];\n for (const key in args.args) {\n const value = args.args[key];\n if (!value) {\n continue;\n }\n\n if (Array.isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n finalArgs.push(`--${kebabCase(key)}`, value[i]);\n }\n continue;\n }\n\n if (typeof value === \"boolean\") {\n finalArgs.push(`--${kebabCase(key)}`);\n continue;\n }\n\n finalArgs.push(`--${kebabCase(key)}`, value);\n }\n\n // Prepare execa args.\n if (!args.execa) {\n args.execa = {};\n }\n\n set(args.execa, \"env.PULUMI_SKIP_UPDATE_CHECK\", \"true\");\n set(args.execa, \"env.PULUMI_HOME\", this.pulumiFolder);\n\n if (os.arch() === \"arm64\") {\n /**\n * This variable is an attempt to resolve this issue:\n * https://yaleman.org/post/2021/2021-01-01-apple-m1-terraform-and-golang/\n */\n set(args.execa, \"env.GODEBUG\", \"asyncpreemptoff=1\");\n }\n\n // Use \";\" when on Windows. For Mac and Linux, use \":\".\n const PATH_SEPARATOR = os.platform() === \"win32\" ? \";\" : \":\";\n\n const execaArgs = {\n ...args.execa,\n env: {\n ...(args.execa.env || {}),\n /**\n * Due to an issue with Pulumi https://github.com/pulumi/pulumi/issues/8374, and even though this\n * commit suggests it should already work like that https://github.com/pulumi/pulumi/commit/c878916901a997a9c0ffcbed23560e19e224a6f1,\n * we need to specify the exact location of our Pulumi binaries, using the PATH environment variable, so it can correctly resolve\n * plugins necessary for custom resources and dynamic providers to work.\n */\n PATH: this.pulumiFolder + PATH_SEPARATOR + process.env.PATH\n }\n };\n\n // We want to keep the \"interactive\" output format of the Pulumi command when `--preview` flag is passed in.\n const flags =\n args.command && args.command.includes(\"preview\") ? [] : [FLAG_NON_INTERACTIVE];\n\n const pulumiProcess = execa(\n this.pulumiBinaryPath,\n [...args.command, ...finalArgs, ...flags],\n execaArgs\n );\n\n // We want to throw an instance of PulumiError when the Pulumi command fails.\n // Makes it easier to catch and handle Pulumi errors in the code.\n // Note: this code definitely looks funky, but it is because how `execa` works.\n const wrapped = pulumiProcess.then(\n result => result,\n err => {\n throw new PulumiError(err.stderr || err.stdout || err.message, { cause: err });\n }\n );\n\n Object.assign(wrapped, pulumiProcess);\n\n return wrapped as ExecaChildProcess<string>;\n }\n\n private async install(rawArgs?: InstallArgs): Promise<boolean> {\n const args = merge({}, this.options, rawArgs);\n\n return await downloadBinaries(\n this.pulumiDownloadFolder,\n args.beforePulumiInstall,\n args.afterPulumiInstall\n );\n }\n\n private async ensureAwsPluginIsInstalled() {\n let pulumiAwsVersion = \"\";\n const { stdout } = execa.sync(\"yarn\", [\n \"info\",\n \"@pulumi/aws\",\n \"-A\",\n \"-R\",\n \"--name-only\",\n \"--json\"\n ]);\n\n const match = stdout.match(/npm:(.*?)\"/);\n if (match) {\n pulumiAwsVersion = match[1];\n }\n\n if (!pulumiAwsVersion) {\n throw new PulumiError(\n \"Could not determine the version of @pulumi/aws package. Please ensure it is installed.\"\n );\n }\n\n const pluginsDir = path.join(this.pulumiFolder, \"plugins\");\n // Pulumi names plugin directories with a \"v\" prefix (e.g. resource-aws-v7.25.0).\n const requiredPluginDir = `resource-aws-v${pulumiAwsVersion}`;\n\n const pluginExists = fs.pathExistsSync(\n path.join(pluginsDir, requiredPluginDir, \"pulumi-resource-aws\")\n );\n\n if (!pluginExists) {\n execa.sync(\n this.pulumiBinaryPath,\n [\"plugin\", \"install\", \"resource\", \"aws\", pulumiAwsVersion],\n {\n stdio: \"inherit\",\n env: {\n PULUMI_HOME: this.pulumiFolder,\n PULUMI_SKIP_UPDATE_CHECK: \"true\"\n }\n }\n );\n }\n\n // Remove stale resource-aws plugin versions to reclaim disk space.\n if (fs.pathExistsSync(pluginsDir)) {\n for (const entry of fs.readdirSync(pluginsDir)) {\n if (!entry.startsWith(\"resource-aws-\") || entry === requiredPluginDir) {\n continue;\n }\n // Strip the trailing \".lock\" suffix so both the directory and its\n // lock file are matched by the same prefix check.\n const baseName = entry.endsWith(\".lock\") ? entry.slice(0, -5) : entry;\n if (baseName !== requiredPluginDir) {\n fs.removeSync(path.join(pluginsDir, entry));\n }\n }\n }\n }\n}\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAOC,KAAK,MAA6B,OAAO;AAChD,OAAO,KAAKC,IAAI,MAAM,MAAM;AAC5B,OAAOC,EAAE,MAAM,UAAU;AACzB,OAAOC,KAAK,MAAM,iBAAiB;AACnC,OAAOC,SAAS,MAAM,qBAAqB;AAC3C,OAAOC,GAAG,MAAM,eAAe;AAC/B,OAAOC,gBAAgB;AAyCvB,OAAO,MAAMC,oBAAoB,GAAG,mBAAmB;AAEvD,OAAO,MAAMC,WAAW,SAASC,KAAK,CAAC;AAEvC,OAAO,MAAMC,MAAM,CAAC;EAMhB,aAAaC,MAAMA,CAACC,OAAgB,GAAG,CAAC,CAAC,EAAE;IACvC,MAAMC,MAAM,GAAG,IAAIH,MAAM,CAACE,OAAO,CAAC;IAClC;IACA,MAAMC,MAAM,CAACC,OAAO,CAAC,CAAC;IACtB;IACA,MAAMD,MAAM,CAACE,0BAA0B,CAAC,CAAC;IACzC,OAAOF,MAAM;EACjB;EAEQG,WAAWA,CAACJ,OAAgB,GAAG,CAAC,CAAC,EAAE;IACvC,IAAI,CAACA,OAAO,GAAGA,OAAO;IAEtB,IAAI,CAACK,oBAAoB,GAAGhB,IAAI,CAACiB,IAAI,CACjCN,O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IAAI,CAACiB,IAAI,CAACyC,UAAU,EAAEC,iBAAiB,EAAE,qBAAqB,CAClE,CAAC;IAED,IAAI,CAACC,YAAY,EAAE;MACf7D,KAAK,CAACyD,IAAI,CACN,IAAI,CAAClC,gBAAgB,EACrB,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAEiC,gBAAgB,CAAC,EAC1D;QACIO,KAAK,EAAE,SAAS;QAChBxB,GAAG,EAAE;UACDyB,WAAW,EAAE,IAAI,CAAC7C,YAAY;UAC9B8C,wBAAwB,EAAE;QAC9B;MACJ,CACJ,CAAC;IACL;;IAEA;IACA,IAAI/D,EAAE,CAAC4D,cAAc,CAACH,UAAU,CAAC,EAAE;MAC/B,KAAK,MAAMO,KAAK,IAAIhE,EAAE,CAACiE,WAAW,CAACR,UAAU,CAAC,EAAE;QAC5C,IAAI,CAACO,KAAK,CAACE,UAAU,CAAC,eAAe,CAAC,IAAIF,KAAK,KAAKN,iBAAiB,EAAE;UACnE;QACJ;QACA;QACA;QACA,MAAMS,QAAQ,GAAGH,KAAK,CAACI,QAAQ,CAAC,OAAO,CAAC,GAAGJ,KAAK,CAACK,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAGL,KAAK;QACrE,IAAIG,QAAQ,KAAKT,iBAAiB,EAAE;UAChC1D,EAAE,CAACsE,UAAU,CAACvE,IAAI,CAACiB,IAAI,CAACyC,UAAU,EAAEO,KAAK,CAAC,CAAC;QAC/C;MACJ;IACJ;EACJ;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Pulumi.js","sources":["../src/Pulumi.ts"],"sourcesContent":["import os from \"os\";\nimport execa, { ExecaChildProcess } from \"execa\";\nimport * as path from \"path\";\nimport fs from \"fs-extra\";\nimport merge from \"lodash/merge.js\";\nimport kebabCase from \"lodash/kebabCase.js\";\nimport set from \"lodash/set.js\";\nimport downloadBinaries from \"./downloadBinaries.js\";\n\ntype Command = string | string[];\n\nexport interface PulumiArgs {\n [key: string]: string | boolean | undefined | string[];\n}\n\nexport interface ExecaArgs {\n env?: {\n [key: string]: string | undefined;\n };\n\n [key: string]: any;\n}\n\nexport interface Options {\n args?: PulumiArgs;\n execa?: ExecaArgs;\n beforePulumiInstall?: () => any;\n afterPulumiInstall?: () => any;\n\n // A folder into which the Pulumi CLI, along with all of its meta data and config files, will be set up.\n // It's recommended this folder is not checked in into a code repository, since the Pulumi CLI can store\n // sensitive information here, for example - user's Pulumi Service credentials.\n pulumiFolder?: string;\n}\n\nexport interface RunArgs {\n command: Command;\n args?: PulumiArgs;\n execa?: ExecaArgs;\n beforePulumiInstall?: () => any;\n afterPulumiInstall?: () => any;\n}\n\nexport interface InstallArgs {\n beforePulumiInstall?: () => any;\n afterPulumiInstall?: () => any;\n}\n\nexport const FLAG_NON_INTERACTIVE = \"--non-interactive\";\n\nexport class PulumiError extends Error {}\n\nexport class Pulumi {\n options: Options;\n pulumiFolder: string;\n pulumiDownloadFolder: string;\n pulumiBinaryPath: string;\n\n static async create(options: Options = {}) {\n const pulumi = new Pulumi(options);\n // If not already installed, Pulumi binaries will be downloaded in this step.\n await pulumi.install();\n // No matter if it's a fresh installation or not, we make sure that Pulumi AWS plugin is installed.\n await pulumi.ensureAwsPluginIsInstalled();\n return pulumi;\n }\n\n private constructor(options: Options = {}) {\n this.options = options;\n\n this.pulumiDownloadFolder = path.join(\n options.pulumiFolder || process.cwd(),\n \"pulumi-cli\",\n os.platform()\n );\n\n this.pulumiFolder = path.join(this.pulumiDownloadFolder, \"pulumi\");\n this.pulumiBinaryPath = path.join(this.pulumiFolder, \"pulumi\");\n }\n\n run(rawArgs: RunArgs) {\n const args = merge({}, this.options, rawArgs);\n\n if (!Array.isArray(args.command)) {\n args.command = [args.command];\n }\n\n // 1. Prepare Pulumi args.\n const finalArgs = [];\n for (const key in args.args) {\n const value = args.args[key];\n if (!value) {\n continue;\n }\n\n if (Array.isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n finalArgs.push(`--${kebabCase(key)}`, value[i]);\n }\n continue;\n }\n\n if (typeof value === \"boolean\") {\n finalArgs.push(`--${kebabCase(key)}`);\n continue;\n }\n\n finalArgs.push(`--${kebabCase(key)}`, value);\n }\n\n // Prepare execa args.\n if (!args.execa) {\n args.execa = {};\n }\n\n set(args.execa, \"env.PULUMI_SKIP_UPDATE_CHECK\", \"true\");\n set(args.execa, \"env.PULUMI_HOME\", this.pulumiFolder);\n\n if (os.arch() === \"arm64\") {\n /**\n * This variable is an attempt to resolve this issue:\n * https://yaleman.org/post/2021/2021-01-01-apple-m1-terraform-and-golang/\n */\n set(args.execa, \"env.GODEBUG\", \"asyncpreemptoff=1\");\n }\n\n // Use \";\" when on Windows. For Mac and Linux, use \":\".\n const PATH_SEPARATOR = os.platform() === \"win32\" ? \";\" : \":\";\n\n const execaArgs = {\n ...args.execa,\n env: {\n ...(args.execa.env || {}),\n /**\n * Due to an issue with Pulumi https://github.com/pulumi/pulumi/issues/8374, and even though this\n * commit suggests it should already work like that https://github.com/pulumi/pulumi/commit/c878916901a997a9c0ffcbed23560e19e224a6f1,\n * we need to specify the exact location of our Pulumi binaries, using the PATH environment variable, so it can correctly resolve\n * plugins necessary for custom resources and dynamic providers to work.\n */\n PATH: this.pulumiFolder + PATH_SEPARATOR + process.env.PATH\n }\n };\n\n // We want to keep the \"interactive\" output format of the Pulumi command when `--preview` flag is passed in.\n const flags =\n args.command && args.command.includes(\"preview\") ? [] : [FLAG_NON_INTERACTIVE];\n\n const pulumiProcess = execa(\n this.pulumiBinaryPath,\n [...args.command, ...finalArgs, ...flags],\n execaArgs\n );\n\n // We want to throw an instance of PulumiError when the Pulumi command fails.\n // Makes it easier to catch and handle Pulumi errors in the code.\n // Note: this code definitely looks funky, but it is because how `execa` works.\n const wrapped = pulumiProcess.then(\n result => result,\n err => {\n throw new PulumiError(err.stderr || err.stdout || err.message, { cause: err });\n }\n );\n\n Object.assign(wrapped, pulumiProcess);\n\n return wrapped as ExecaChildProcess<string>;\n }\n\n private async install(rawArgs?: InstallArgs): Promise<boolean> {\n const args = merge({}, this.options, rawArgs);\n\n return await downloadBinaries(\n this.pulumiDownloadFolder,\n args.beforePulumiInstall,\n args.afterPulumiInstall\n );\n }\n\n private async ensureAwsPluginIsInstalled() {\n let pulumiAwsVersion = \"\";\n const { stdout } = execa.sync(\"yarn\", [\n \"info\",\n \"@pulumi/aws\",\n \"-A\",\n \"-R\",\n \"--name-only\",\n \"--json\"\n ]);\n\n const match = stdout.match(/npm:(.*?)\"/);\n if (match) {\n pulumiAwsVersion = match[1];\n }\n\n if (!pulumiAwsVersion) {\n throw new PulumiError(\n \"Could not determine the version of @pulumi/aws package. Please ensure it is installed.\"\n );\n }\n\n const pluginsDir = path.join(this.pulumiFolder, \"plugins\");\n // Pulumi names plugin directories with a \"v\" prefix (e.g. resource-aws-v7.25.0).\n const requiredPluginDir = `resource-aws-v${pulumiAwsVersion}`;\n\n const pluginExists = fs.pathExistsSync(\n path.join(pluginsDir, requiredPluginDir, \"pulumi-resource-aws\")\n );\n\n if (!pluginExists) {\n execa.sync(\n this.pulumiBinaryPath,\n [\"plugin\", \"install\", \"resource\", \"aws\", pulumiAwsVersion],\n {\n stdio: \"inherit\",\n env: {\n PULUMI_HOME: this.pulumiFolder,\n PULUMI_SKIP_UPDATE_CHECK: \"true\"\n }\n }\n );\n }\n\n // Remove stale resource-aws plugin versions to reclaim disk space.\n if (fs.pathExistsSync(pluginsDir)) {\n for (const entry of fs.readdirSync(pluginsDir)) {\n if (!entry.startsWith(\"resource-aws-\") || entry === requiredPluginDir) {\n continue;\n }\n // Strip the trailing \".lock\" suffix so both the directory and its\n // lock file are matched by the same prefix check.\n const baseName = entry.endsWith(\".lock\") ? entry.slice(0, -5) : entry;\n if (baseName !== requiredPluginDir) {\n fs.removeSync(path.join(pluginsDir, entry));\n }\n }\n }\n }\n}\n"],"names":["FLAG_NON_INTERACTIVE","PulumiError","Error","Pulumi","options","pulumi","path","process","os","rawArgs","args","merge","Array","finalArgs","key","value","i","kebabCase","set","PATH_SEPARATOR","execaArgs","flags","pulumiProcess","execa","wrapped","result","err","Object","downloadBinaries","pulumiAwsVersion","stdout","match","pluginsDir","requiredPluginDir","pluginExists","fs","entry","baseName"],"mappings":";;;;;;;;AAgDO,MAAMA,uBAAuB;AAE7B,MAAMC,oBAAoBC;AAAO;AAEjC,MAAMC;IAMT,aAAa,OAAOC,UAAmB,CAAC,CAAC,EAAE;QACvC,MAAMC,SAAS,IAAIF,OAAOC;QAE1B,MAAMC,OAAO,OAAO;QAEpB,MAAMA,OAAO,0BAA0B;QACvC,OAAOA;IACX;IAEA,YAAoBD,UAAmB,CAAC,CAAC,CAAE;QACvC,IAAI,CAAC,OAAO,GAAGA;QAEf,IAAI,CAAC,oBAAoB,GAAGE,uBAAAA,IAAS,CACjCF,QAAQ,YAAY,IAAIG,QAAQ,GAAG,IACnC,cACAC,GAAG,QAAQ;QAGf,IAAI,CAAC,YAAY,GAAGF,uBAAAA,IAAS,CAAC,IAAI,CAAC,oBAAoB,EAAE;QACzD,IAAI,CAAC,gBAAgB,GAAGA,uBAAAA,IAAS,CAAC,IAAI,CAAC,YAAY,EAAE;IACzD;IAEA,IAAIG,OAAgB,EAAE;QAClB,MAAMC,OAAOC,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,EAAEF;QAErC,IAAI,CAACG,MAAM,OAAO,CAACF,KAAK,OAAO,GAC3BA,KAAK,OAAO,GAAG;YAACA,KAAK,OAAO;SAAC;QAIjC,MAAMG,YAAY,EAAE;QACpB,IAAK,MAAMC,OAAOJ,KAAK,IAAI,CAAE;YACzB,MAAMK,QAAQL,KAAK,IAAI,CAACI,IAAI;YAC5B,IAAKC;gBAIL,IAAIH,MAAM,OAAO,CAACG,QAAQ;oBACtB,IAAK,IAAIC,IAAI,GAAGA,IAAID,MAAM,MAAM,EAAEC,IAC9BH,UAAU,IAAI,CAAC,CAAC,EAAE,EAAEI,UAAUH,MAAM,EAAEC,KAAK,CAACC,EAAE;oBAElD;gBAC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from "path";
|
|
5
|
-
// @ts-expect-error `tar` has no types.
|
|
6
4
|
import decompress from "decompress";
|
|
7
5
|
import semver from "semver";
|
|
8
6
|
import { findUpSync } from "find-up";
|
|
9
7
|
import { loadJsonFileSync } from "load-json-file";
|
|
10
8
|
import { downloadFile } from "./downloadFile.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
version
|
|
18
|
-
} = loadJsonFileSync(pkgJsonPath);
|
|
19
|
-
return semver.clean(version);
|
|
9
|
+
import * as __rspack_external_tar from "tar";
|
|
10
|
+
const getPulumiVersion = ()=>{
|
|
11
|
+
const pkgJsonPath = findUpSync("node_modules/@pulumi/pulumi/package.json");
|
|
12
|
+
const { version } = loadJsonFileSync(pkgJsonPath);
|
|
13
|
+
return semver.clean(version);
|
|
20
14
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
throw Error(`Cannot download Pulumi binaries - platform "${platform}" not supported. Supported ones are "darwin", "linux", and "win32"`);
|
|
41
|
-
}
|
|
42
|
-
if (typeof afterInstall === "function") {
|
|
43
|
-
await afterInstall();
|
|
44
|
-
}
|
|
45
|
-
return true;
|
|
15
|
+
const downloadBinaries = async (downloadFolder, beforeInstall, afterInstall)=>{
|
|
16
|
+
if (fs.existsSync(downloadFolder)) return false;
|
|
17
|
+
if ("function" == typeof beforeInstall) await beforeInstall();
|
|
18
|
+
const platform = os.platform();
|
|
19
|
+
switch(platform){
|
|
20
|
+
case "darwin":
|
|
21
|
+
await setupDarwin(downloadFolder);
|
|
22
|
+
break;
|
|
23
|
+
case "linux":
|
|
24
|
+
await setupLinux(downloadFolder);
|
|
25
|
+
break;
|
|
26
|
+
case "win32":
|
|
27
|
+
await setupWindows(downloadFolder);
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
throw Error(`Cannot download Pulumi binaries - platform "${platform}" not supported. Supported ones are "darwin", "linux", and "win32"`);
|
|
31
|
+
}
|
|
32
|
+
if ("function" == typeof afterInstall) await afterInstall();
|
|
33
|
+
return true;
|
|
46
34
|
};
|
|
47
|
-
const SUPPORTED_ARCHITECTURES = [
|
|
35
|
+
const SUPPORTED_ARCHITECTURES = [
|
|
36
|
+
"x64",
|
|
37
|
+
"arm64"
|
|
38
|
+
];
|
|
48
39
|
async function setupDarwin(downloadFolder) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
40
|
+
const version = getPulumiVersion();
|
|
41
|
+
const arch = SUPPORTED_ARCHITECTURES.includes(process.arch) ? process.arch : "x64";
|
|
42
|
+
const filename = `pulumi-v${version}-darwin-${arch}.tar.gz`;
|
|
43
|
+
const downloadUrl = "https://get.pulumi.com/releases/sdk/" + filename;
|
|
44
|
+
const absoluteFilename = path.join(downloadFolder, filename);
|
|
45
|
+
await downloadFile(downloadUrl, absoluteFilename);
|
|
46
|
+
await __rspack_external_tar.extract({
|
|
47
|
+
cwd: downloadFolder,
|
|
48
|
+
file: absoluteFilename
|
|
49
|
+
});
|
|
50
|
+
fs.unlinkSync(path.join(downloadFolder, filename));
|
|
60
51
|
}
|
|
61
52
|
async function setupWindows(downloadFolder) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
53
|
+
const version = getPulumiVersion();
|
|
54
|
+
const filename = `pulumi-v${version}-windows-x64.zip`;
|
|
55
|
+
const downloadUrl = "https://get.pulumi.com/releases/sdk/" + filename;
|
|
56
|
+
const absoluteFilename = path.join(downloadFolder, filename);
|
|
57
|
+
await downloadFile(downloadUrl, absoluteFilename);
|
|
58
|
+
const destination = path.join(downloadFolder, "pulumi");
|
|
59
|
+
await decompress(absoluteFilename, destination, {
|
|
60
|
+
strip: 2
|
|
61
|
+
});
|
|
62
|
+
fs.unlinkSync(path.join(downloadFolder, filename));
|
|
72
63
|
}
|
|
73
64
|
async function setupLinux(downloadFolder) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
65
|
+
const version = getPulumiVersion();
|
|
66
|
+
const filename = `pulumi-v${version}-linux-x64.tar.gz`;
|
|
67
|
+
const downloadUrl = "https://get.pulumi.com/releases/sdk/" + filename;
|
|
68
|
+
const absoluteFilename = path.join(downloadFolder, filename);
|
|
69
|
+
await downloadFile(downloadUrl, absoluteFilename);
|
|
70
|
+
await __rspack_external_tar.extract({
|
|
71
|
+
cwd: downloadFolder,
|
|
72
|
+
file: absoluteFilename
|
|
73
|
+
});
|
|
74
|
+
fs.unlinkSync(path.join(downloadFolder, filename));
|
|
84
75
|
}
|
|
76
|
+
export default downloadBinaries;
|
|
85
77
|
|
|
86
78
|
//# sourceMappingURL=downloadBinaries.js.map
|
package/downloadBinaries.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"downloadBinaries.js","sources":["../src/downloadBinaries.ts"],"sourcesContent":["import os from \"os\";\nimport * as tar from \"tar\";\nimport fs from \"fs\";\nimport path from \"path\";\n// @ts-expect-error `tar` has no types.\nimport decompress from \"decompress\";\nimport semver from \"semver\";\nimport { findUpSync } from \"find-up\";\nimport { loadJsonFileSync } from \"load-json-file\";\nimport { downloadFile } from \"./downloadFile.js\";\nimport { PackageJson } from \"type-fest\";\n\n// We need to sanitize the package version because, occasionally, we've noticed that the Pulumi version\n// can look like the following: \"2.25.2+dirty\". We want to ensure only \"2.25.2\" is returned.\n// @see https://github.com/pulumi/pulumi/issues/6847\nconst getPulumiVersion = () => {\n const pkgJsonPath = findUpSync(\"node_modules/@pulumi/pulumi/package.json\");\n const { version } = loadJsonFileSync<PackageJson>(pkgJsonPath!);\n return semver.clean(version!);\n};\n\nexport default async (\n downloadFolder: string,\n beforeInstall?: () => void,\n afterInstall?: () => void\n) => {\n if (fs.existsSync(downloadFolder)) {\n return false;\n }\n\n if (typeof beforeInstall === \"function\") {\n await beforeInstall();\n }\n\n const platform = os.platform();\n switch (platform) {\n case \"darwin\":\n await setupDarwin(downloadFolder);\n break;\n case \"linux\":\n await setupLinux(downloadFolder);\n break;\n case \"win32\":\n await setupWindows(downloadFolder);\n break;\n default:\n throw Error(\n `Cannot download Pulumi binaries - platform \"${platform}\" not supported. Supported ones are \"darwin\", \"linux\", and \"win32\"`\n );\n }\n\n if (typeof afterInstall === \"function\") {\n await afterInstall();\n }\n\n return true;\n};\n\nconst SUPPORTED_ARCHITECTURES = [\"x64\", \"arm64\"];\n\nasync function setupDarwin(downloadFolder: string) {\n const version = getPulumiVersion();\n const arch = SUPPORTED_ARCHITECTURES.includes(process.arch) ? process.arch : \"x64\";\n\n const filename = `pulumi-v${version}-darwin-${arch}.tar.gz`;\n const downloadUrl = \"https://get.pulumi.com/releases/sdk/\" + filename;\n\n const absoluteFilename = path.join(downloadFolder, filename);\n await downloadFile(downloadUrl, absoluteFilename);\n\n await tar.extract({\n cwd: downloadFolder,\n file: absoluteFilename\n });\n\n fs.unlinkSync(path.join(downloadFolder, filename));\n}\n\nasync function setupWindows(downloadFolder: string) {\n const version = getPulumiVersion();\n const filename = `pulumi-v${version}-windows-x64.zip`;\n const downloadUrl = \"https://get.pulumi.com/releases/sdk/\" + filename;\n\n const absoluteFilename = path.join(downloadFolder, filename);\n await downloadFile(downloadUrl, absoluteFilename);\n\n const destination = path.join(downloadFolder, \"pulumi\");\n await decompress(absoluteFilename, destination, { strip: 2 });\n\n fs.unlinkSync(path.join(downloadFolder, filename));\n}\n\nasync function setupLinux(downloadFolder: string) {\n const version = getPulumiVersion();\n const filename = `pulumi-v${version}-linux-x64.tar.gz`;\n const downloadUrl = \"https://get.pulumi.com/releases/sdk/\" + filename;\n\n const absoluteFilename = path.join(downloadFolder, filename);\n await downloadFile(downloadUrl, absoluteFilename);\n\n await tar.extract({\n cwd: downloadFolder,\n file: absoluteFilename\n });\n\n fs.unlinkSync(path.join(downloadFolder, filename));\n}\n"],"names":["getPulumiVersion","pkgJsonPath","findUpSync","version","loadJsonFileSync","semver","downloadFolder","beforeInstall","afterInstall","fs","platform","os","setupDarwin","setupLinux","setupWindows","Error","SUPPORTED_ARCHITECTURES","arch","process","filename","downloadUrl","absoluteFilename","path","downloadFile","tar","destination","decompress"],"mappings":";;;;;;;;;AAeA,MAAMA,mBAAmB;IACrB,MAAMC,cAAcC,WAAW;IAC/B,MAAM,EAAEC,OAAO,EAAE,GAAGC,iBAA8BH;IAClD,OAAOI,OAAO,KAAK,CAACF;AACxB;AAEA,yBAAe,OACXG,gBACAC,eACAC;IAEA,IAAIC,GAAG,UAAU,CAACH,iBACd,OAAO;IAGX,IAAI,AAAyB,cAAzB,OAAOC,eACP,MAAMA;IAGV,MAAMG,WAAWC,GAAG,QAAQ;IAC5B,OAAQD;QACJ,KAAK;YACD,MAAME,YAAYN;YAClB;QACJ,KAAK;YACD,MAAMO,WAAWP;YACjB;QACJ,KAAK;YACD,MAAMQ,aAAaR;YACnB;QACJ;YACI,MAAMS,MACF,CAAC,4CAA4C,EAAEL,SAAS,kEAAkE,CAAC;IAEvI;IAEA,IAAI,AAAwB,cAAxB,OAAOF,cACP,MAAMA;IAGV,OAAO;AACX;AAEA,MAAMQ,0BAA0B;IAAC;IAAO;CAAQ;AAEhD,eAAeJ,YAAYN,cAAsB;IAC7C,MAAMH,UAAUH;IAChB,MAAMiB,OAAOD,wBAA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ra";
|
|
3
3
|
import { Readable } from "stream";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
const downloadFile = async (url, file)=>{
|
|
5
|
+
const res = await fetch(url);
|
|
6
|
+
if (!res.body) throw new Error("Response body is null");
|
|
7
|
+
const nodeStream = Readable.fromWeb(res.body);
|
|
8
|
+
await fs_extra.ensureDir(dirname(file));
|
|
9
|
+
await new Promise((resolve, reject)=>{
|
|
10
|
+
const fileStream = fs_extra.createWriteStream(file);
|
|
11
|
+
nodeStream.pipe(fileStream);
|
|
12
|
+
nodeStream.on("error", (err)=>{
|
|
13
|
+
reject(err);
|
|
14
|
+
});
|
|
15
|
+
fileStream.on("finish", ()=>{
|
|
16
|
+
resolve();
|
|
17
|
+
});
|
|
16
18
|
});
|
|
17
|
-
fileStream.on("finish", () => {
|
|
18
|
-
resolve();
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
19
|
};
|
|
20
|
+
export { downloadFile };
|
|
22
21
|
|
|
23
22
|
//# sourceMappingURL=downloadFile.js.map
|
package/downloadFile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"downloadFile.js","sources":["../src/downloadFile.ts"],"sourcesContent":["import { dirname } from \"path\";\nimport fs from \"fs-extra\";\nimport { Readable } from \"stream\";\nimport type { ReadableStream as NodeReadableStream } from \"stream/web\";\n\nexport const downloadFile = async (url: string, file: string) => {\n const res = await fetch(url);\n\n if (!res.body) {\n throw new Error(\"Response body is null\");\n }\n\n const nodeStream = Readable.fromWeb(res.body as NodeReadableStream);\n\n await fs.ensureDir(dirname(file));\n\n await new Promise<void>((resolve, reject) => {\n const fileStream = fs.createWriteStream(file);\n nodeStream.pipe(fileStream);\n nodeStream.on(\"error\", (err: Error) => {\n reject(err);\n });\n fileStream.on(\"finish\", () => {\n resolve();\n });\n });\n};\n"],"names":["downloadFile","url","file","res","fetch","Error","nodeStream","Readable","fs","dirname","Promise","resolve","reject","fileStream","err"],"mappings":";;;AAKO,MAAMA,eAAe,OAAOC,KAAaC;IAC5C,MAAMC,MAAM,MAAMC,MAAMH;IAExB,IAAI,CAACE,IAAI,IAAI,EACT,MAAM,IAAIE,MAAM;IAGpB,MAAMC,aAAaC,SAAS,OAAO,CAACJ,IAAI,IAAI;IAE5C,MAAMK,SAAAA,SAAY,CAACC,QAAQP;IAE3B,MAAM,IAAIQ,QAAc,CAACC,SAASC;QAC9B,MAAMC,aAAaL,SAAAA,iBAAoB,CAACN;QACxCI,WAAW,IAAI,CAACO;QAChBP,WAAW,EAAE,CAAC,SAAS,CAACQ;YACpBF,OAAOE;QACX;QACAD,WAAW,EAAE,CAAC,UAAU;YACpBF;QACJ;IACJ;AACJ"}
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/pulumi-sdk",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -18,20 +18,20 @@
|
|
|
18
18
|
"directory": "dist"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@pulumi/aws": "^7.
|
|
22
|
-
"@pulumi/pulumi": "^3.
|
|
21
|
+
"@pulumi/aws": "^7.29.0",
|
|
22
|
+
"@pulumi/pulumi": "^3.237.0",
|
|
23
23
|
"decompress": "4.2.1",
|
|
24
24
|
"execa": "5.1.1",
|
|
25
25
|
"find-up": "8.0.0",
|
|
26
|
-
"fs-extra": "11.3.
|
|
26
|
+
"fs-extra": "11.3.5",
|
|
27
27
|
"load-json-file": "7.0.1",
|
|
28
28
|
"lodash": "4.18.1",
|
|
29
|
-
"semver": "7.
|
|
30
|
-
"tar": "7.5.
|
|
29
|
+
"semver": "7.8.0",
|
|
30
|
+
"tar": "7.5.15"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/lodash": "4.17.24",
|
|
34
|
-
"@webiny/build-tools": "6.
|
|
34
|
+
"@webiny/build-tools": "6.4.0-beta.0",
|
|
35
35
|
"rimraf": "6.1.3",
|
|
36
36
|
"type-fest": "5.6.0",
|
|
37
37
|
"typescript": "6.0.3"
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
]
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "a545d7529828af07d08d49c3da1bcb967483b9ce"
|
|
48
48
|
}
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Pulumi.js\";\n"],"mappings":"AAAA","ignoreList":[]}
|