@webiny/pulumi-sdk 5.44.1-beta.0 → 5.45.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.d.ts +8 -5
- package/Pulumi.js +56 -42
- package/Pulumi.js.map +1 -1
- package/README.md +6 -71
- package/downloadBinaries.js +28 -35
- package/downloadBinaries.js.map +1 -1
- package/downloadFile.js +14 -18
- package/downloadFile.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -16
- package/index.js.map +1 -1
- package/package.json +15 -17
package/Pulumi.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExecaChildProcess } from "execa";
|
|
2
2
|
type Command = string | string[];
|
|
3
3
|
export interface PulumiArgs {
|
|
4
4
|
[key: string]: string | boolean | undefined | string[];
|
|
@@ -28,14 +28,17 @@ export interface InstallArgs {
|
|
|
28
28
|
afterPulumiInstall?: () => any;
|
|
29
29
|
}
|
|
30
30
|
export declare const FLAG_NON_INTERACTIVE = "--non-interactive";
|
|
31
|
+
export declare class PulumiError extends Error {
|
|
32
|
+
}
|
|
31
33
|
export declare class Pulumi {
|
|
32
34
|
options: Options;
|
|
33
35
|
pulumiFolder: string;
|
|
34
36
|
pulumiDownloadFolder: string;
|
|
35
37
|
pulumiBinaryPath: string;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
static create(options?: Options): Promise<Pulumi>;
|
|
39
|
+
private constructor();
|
|
40
|
+
run(rawArgs: RunArgs): ExecaChildProcess<string>;
|
|
41
|
+
private install;
|
|
42
|
+
private ensureAwsPluginIsInstalled;
|
|
40
43
|
}
|
|
41
44
|
export {};
|
package/Pulumi.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import os from "os";
|
|
2
|
+
import execa from "execa";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import fs from "fs-extra";
|
|
5
|
+
import merge from "lodash/merge.js";
|
|
6
|
+
import kebabCase from "lodash/kebabCase.js";
|
|
7
|
+
import set from "lodash/set.js";
|
|
8
|
+
import downloadBinaries from "./downloadBinaries.js";
|
|
9
|
+
export const FLAG_NON_INTERACTIVE = "--non-interactive";
|
|
10
|
+
export class PulumiError extends Error {}
|
|
11
|
+
export class Pulumi {
|
|
12
|
+
static async create(options = {}) {
|
|
13
|
+
const pulumi = new Pulumi(options);
|
|
14
|
+
// If not already installed, Pulumi binaries will be downloaded in this step.
|
|
15
|
+
await pulumi.install();
|
|
16
|
+
// No matter if it's a fresh installation or not, we make sure that Pulumi AWS plugin is installed.
|
|
17
|
+
await pulumi.ensureAwsPluginIsInstalled();
|
|
18
|
+
return pulumi;
|
|
19
|
+
}
|
|
19
20
|
constructor(options = {}) {
|
|
20
21
|
this.options = options;
|
|
21
|
-
this.pulumiDownloadFolder = path.join(options.pulumiFolder || process.cwd(), "pulumi-cli",
|
|
22
|
+
this.pulumiDownloadFolder = path.join(options.pulumiFolder || process.cwd(), "pulumi-cli", os.platform());
|
|
22
23
|
this.pulumiFolder = path.join(this.pulumiDownloadFolder, "pulumi");
|
|
23
24
|
this.pulumiBinaryPath = path.join(this.pulumiFolder, "pulumi");
|
|
24
25
|
}
|
|
25
26
|
run(rawArgs) {
|
|
26
|
-
this.
|
|
27
|
-
const args = (0, _merge.default)({}, this.options, rawArgs);
|
|
27
|
+
const args = merge({}, this.options, rawArgs);
|
|
28
28
|
if (!Array.isArray(args.command)) {
|
|
29
29
|
args.command = [args.command];
|
|
30
30
|
}
|
|
@@ -38,33 +38,33 @@ class Pulumi {
|
|
|
38
38
|
}
|
|
39
39
|
if (Array.isArray(value)) {
|
|
40
40
|
for (let i = 0; i < value.length; i++) {
|
|
41
|
-
finalArgs.push(`--${(
|
|
41
|
+
finalArgs.push(`--${kebabCase(key)}`, value[i]);
|
|
42
42
|
}
|
|
43
43
|
continue;
|
|
44
44
|
}
|
|
45
45
|
if (typeof value === "boolean") {
|
|
46
|
-
finalArgs.push(`--${(
|
|
46
|
+
finalArgs.push(`--${kebabCase(key)}`);
|
|
47
47
|
continue;
|
|
48
48
|
}
|
|
49
|
-
finalArgs.push(`--${(
|
|
49
|
+
finalArgs.push(`--${kebabCase(key)}`, value);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// Prepare execa args.
|
|
53
53
|
if (!args.execa) {
|
|
54
54
|
args.execa = {};
|
|
55
55
|
}
|
|
56
|
-
(
|
|
57
|
-
(
|
|
58
|
-
if (
|
|
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
59
|
/**
|
|
60
60
|
* This variable is an attempt to resolve this issue:
|
|
61
61
|
* https://yaleman.org/post/2021/2021-01-01-apple-m1-terraform-and-golang/
|
|
62
62
|
*/
|
|
63
|
-
(
|
|
63
|
+
set(args.execa, "env.GODEBUG", "asyncpreemptoff=1");
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
// Use ";" when on Windows. For Mac and Linux, use ":".
|
|
67
|
-
const PATH_SEPARATOR =
|
|
67
|
+
const PATH_SEPARATOR = os.platform() === "win32" ? ";" : ":";
|
|
68
68
|
const execaArgs = {
|
|
69
69
|
...args.execa,
|
|
70
70
|
env: {
|
|
@@ -81,25 +81,40 @@ class Pulumi {
|
|
|
81
81
|
|
|
82
82
|
// We want to keep the "interactive" output format of the Pulumi command when `--preview` flag is passed in.
|
|
83
83
|
const flags = args.command && args.command.includes("preview") ? [] : [FLAG_NON_INTERACTIVE];
|
|
84
|
-
|
|
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;
|
|
85
96
|
}
|
|
86
97
|
async install(rawArgs) {
|
|
87
|
-
const args = (
|
|
88
|
-
|
|
89
|
-
if (installed) {
|
|
90
|
-
this.ensureAwsPluginIsInstalled();
|
|
91
|
-
}
|
|
92
|
-
return installed;
|
|
98
|
+
const args = merge({}, this.options, rawArgs);
|
|
99
|
+
return await downloadBinaries(this.pulumiDownloadFolder, args.beforePulumiInstall, args.afterPulumiInstall);
|
|
93
100
|
}
|
|
94
|
-
ensureAwsPluginIsInstalled() {
|
|
101
|
+
async ensureAwsPluginIsInstalled() {
|
|
102
|
+
let pulumiAwsVersion = "";
|
|
95
103
|
const {
|
|
96
|
-
|
|
97
|
-
} =
|
|
98
|
-
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];
|
|
109
|
+
}
|
|
110
|
+
if (!pulumiAwsVersion) {
|
|
111
|
+
throw new PulumiError("Could not determine the version of @pulumi/aws package. Please ensure it is installed.");
|
|
112
|
+
}
|
|
113
|
+
const pluginExists = fs.pathExistsSync(path.join(this.pulumiFolder, "plugins", `resource-aws-${pulumiAwsVersion}`, "pulumi-resource-aws"));
|
|
99
114
|
if (pluginExists) {
|
|
100
115
|
return;
|
|
101
116
|
}
|
|
102
|
-
return
|
|
117
|
+
return execa.sync(this.pulumiBinaryPath, ["plugin", "install", "resource", "aws", pulumiAwsVersion], {
|
|
103
118
|
stdio: "inherit",
|
|
104
119
|
env: {
|
|
105
120
|
PULUMI_HOME: this.pulumiFolder,
|
|
@@ -108,6 +123,5 @@ class Pulumi {
|
|
|
108
123
|
});
|
|
109
124
|
}
|
|
110
125
|
}
|
|
111
|
-
exports.Pulumi = Pulumi;
|
|
112
126
|
|
|
113
127
|
//# sourceMappingURL=Pulumi.js.map
|
package/Pulumi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_os","_interopRequireDefault","require","_execa","path","_interopRequireWildcard","_fsExtra","_merge","_kebabCase","_set","_downloadBinaries","FLAG_NON_INTERACTIVE","exports","Pulumi","constructor","options","pulumiDownloadFolder","join","pulumiFolder","process","cwd","os","platform","pulumiBinaryPath","run","rawArgs","ensureAwsPluginIsInstalled","args","merge","Array","isArray","command","finalArgs","key","value","i","length","push","kebabCase","execa","set","arch","PATH_SEPARATOR","execaArgs","env","PATH","flags","includes","install","installed","downloadBinaries","beforePulumiInstall","afterPulumiInstall","version","pluginExists","fs","pathExistsSync","sync","stdio","PULUMI_HOME","PULUMI_SKIP_UPDATE_CHECK"],"sources":["Pulumi.ts"],"sourcesContent":["import os from \"os\";\nimport execa from \"execa\";\nimport * as path from \"path\";\nimport fs from \"fs-extra\";\nimport merge from \"lodash/merge\";\nimport kebabCase from \"lodash/kebabCase\";\nimport set from \"lodash/set\";\nimport downloadBinaries from \"./downloadBinaries\";\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\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 Pulumi {\n options: Options;\n pulumiFolder: string;\n pulumiDownloadFolder: string;\n pulumiBinaryPath: string;\n\n 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 this.ensureAwsPluginIsInstalled();\n\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 return execa(this.pulumiBinaryPath, [...args.command, ...finalArgs, ...flags], execaArgs);\n }\n\n async install(rawArgs?: InstallArgs): Promise<boolean> {\n const args = merge({}, this.options, rawArgs);\n\n const installed = await downloadBinaries(\n this.pulumiDownloadFolder,\n args.beforePulumiInstall,\n args.afterPulumiInstall\n );\n\n if (installed) {\n this.ensureAwsPluginIsInstalled();\n }\n\n return installed;\n }\n\n ensureAwsPluginIsInstalled() {\n const { version } = require(\"@pulumi/aws/package.json\");\n\n const pluginExists = fs.pathExistsSync(\n path.join(\n this.pulumiFolder,\n \"plugins\",\n `resource-aws-${version}`,\n \"pulumi-resource-aws\"\n )\n );\n\n if (pluginExists) {\n return;\n }\n\n return execa.sync(\n this.pulumiBinaryPath,\n [\"plugin\", \"install\", \"resource\", \"aws\", version],\n {\n stdio: \"inherit\",\n env: {\n PULUMI_HOME: this.pulumiFolder,\n PULUMI_SKIP_UPDATE_CHECK: \"true\"\n }\n }\n );\n }\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,GAAA,GAAAC,sB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AAIC,YAAY,EAAE;MACd;IACJ;IAEA,OAAOf,cAAK,CAACkB,IAAI,CACb,IAAI,CAAClC,gBAAgB,EACrB,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE8B,OAAO,CAAC,EACjD;MACIK,KAAK,EAAE,SAAS;MAChBd,GAAG,EAAE;QACDe,WAAW,EAAE,IAAI,CAACzC,YAAY;QAC9B0C,wBAAwB,EAAE;MAC9B;IACJ,CACJ,CAAC;EACL;AACJ;AAAChD,OAAA,CAAAC,MAAA,GAAAA,MAAA","ignoreList":[]}
|
|
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","pluginExists","pathExistsSync","stdio","PULUMI_HOME","PULUMI_SKIP_UPDATE_CHECK"],"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 pluginExists = fs.pathExistsSync(\n path.join(\n this.pulumiFolder,\n \"plugins\",\n `resource-aws-${pulumiAwsVersion}`,\n \"pulumi-resource-aws\"\n )\n );\n\n if (pluginExists) {\n return;\n }\n\n return 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"],"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,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AAgBqC,gBAAgB,EAAE,EAClC,qBACJ,CACJ,CAAC;IAED,IAAIG,YAAY,EAAE;MACd;IACJ;IAEA,OAAO3D,KAAK,CAACyD,IAAI,CACb,IAAI,CAAClC,gBAAgB,EACrB,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAEiC,gBAAgB,CAAC,EAC1D;MACIK,KAAK,EAAE,SAAS;MAChBtB,GAAG,EAAE;QACDuB,WAAW,EAAE,IAAI,CAAC3C,YAAY;QAC9B4C,wBAAwB,EAAE;MAC9B;IACJ,CACJ,CAAC;EACL;AACJ","ignoreList":[]}
|
package/README.md
CHANGED
|
@@ -1,76 +1,11 @@
|
|
|
1
1
|
# @webiny/pulumi-sdk
|
|
2
|
-
[](https://www.npmjs.com/package/@webiny/pulumi-sdk)
|
|
3
|
-
[](https://www.npmjs.com/package/@webiny/pulumi-sdk)
|
|
4
|
-
[](https://github.com/prettier/prettier)
|
|
5
|
-
[](http://makeapullrequest.com)
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
const { Pulumi } = require("@webiny/pulumi-sdk");
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
// Note that Pulumi will be installed automatically on first use, you don't need to install it
|
|
16
|
-
// manually first. That's why the `beforePulumiInstall` and `afterPulumiInstall` are exposed.
|
|
17
|
-
const pulumi = new Pulumi({
|
|
18
|
-
execa: {
|
|
19
|
-
cwd: stacksDir,
|
|
20
|
-
env: { PULUMI_CONFIG_PASSPHRASE: process.env.PULUMI_CONFIG_PASSPHRASE }
|
|
21
|
-
},
|
|
22
|
-
args: {
|
|
23
|
-
secretsProvider: "passphrase"
|
|
24
|
-
},
|
|
25
|
-
beforePulumiInstall: () => {
|
|
26
|
-
console.log(
|
|
27
|
-
`💡 It looks like this is your first time using ${green(
|
|
28
|
-
"@webiny/pulumi-sdk"
|
|
29
|
-
)}.`
|
|
30
|
-
);
|
|
31
|
-
spinner.start(`Downloading Pulumi...`);
|
|
32
|
-
},
|
|
33
|
-
afterPulumiInstall: () => {
|
|
34
|
-
spinner.stopAndPersist({
|
|
35
|
-
symbol: green("✔"),
|
|
36
|
-
text: `Pulumi downloaded, continuing...`
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
});
|
|
9
|
+
---
|
|
40
10
|
|
|
41
|
-
|
|
42
|
-
let stackExists = true;
|
|
43
|
-
try {
|
|
44
|
-
const { process } = await pulumi.run({ command: ["stack", "select", env] });
|
|
45
|
-
await process;
|
|
46
|
-
} catch (e) {
|
|
47
|
-
stackExists = false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (!stackExists) {
|
|
51
|
-
const { process } = await pulumi.run({ command: ["stack", "init", env] });
|
|
52
|
-
await process;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// If isPreview was set to true in our script, then run `preview` command, otherwise `up`.
|
|
56
|
-
if (isPreview) {
|
|
57
|
-
const pulumi = new Pulumi();
|
|
58
|
-
const { toConsole } = await pulumi.run({
|
|
59
|
-
command: "preview",
|
|
60
|
-
execa: {
|
|
61
|
-
cwd: stacksDir,
|
|
62
|
-
env: { PULUMI_CONFIG_PASSPHRASE: process.env.PULUMI_CONFIG_PASSPHRASE }
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
await toConsole();
|
|
66
|
-
} else {
|
|
67
|
-
const { toConsole } = await pulumi.run({
|
|
68
|
-
command: "up",
|
|
69
|
-
args: {
|
|
70
|
-
yes: true,
|
|
71
|
-
skipPreview: true
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
await toConsole();
|
|
75
|
-
}
|
|
76
|
-
```
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
package/downloadBinaries.js
CHANGED
|
@@ -1,38 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _os = _interopRequireDefault(require("os"));
|
|
9
|
-
var _tar = _interopRequireDefault(require("tar"));
|
|
10
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
-
var _path = _interopRequireDefault(require("path"));
|
|
12
|
-
var _decompress = _interopRequireDefault(require("decompress"));
|
|
13
|
-
var _semver = _interopRequireDefault(require("semver"));
|
|
14
|
-
var _downloadFile = require("./downloadFile");
|
|
15
|
-
// @ts-expect-error `tar` has no types.
|
|
16
|
-
|
|
1
|
+
import os from "os";
|
|
2
|
+
import * as tar from "tar";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
17
5
|
// @ts-expect-error `tar` has no types.
|
|
6
|
+
import decompress from "decompress";
|
|
7
|
+
import semver from "semver";
|
|
8
|
+
import findUp from "find-up";
|
|
9
|
+
import readJsonSync from "read-json-sync";
|
|
10
|
+
import { downloadFile } from "./downloadFile.js";
|
|
18
11
|
|
|
19
12
|
// We need to sanitize the package version because, occasionally, we've noticed that the Pulumi version
|
|
20
13
|
// can look like the following: "2.25.2+dirty". We want to ensure only "2.25.2" is returned.
|
|
21
14
|
// @see https://github.com/pulumi/pulumi/issues/6847
|
|
22
15
|
const getPulumiVersion = () => {
|
|
16
|
+
const pkgJsonPath = findUp.sync("node_modules/@pulumi/pulumi/package.json");
|
|
23
17
|
const {
|
|
24
18
|
version
|
|
25
|
-
} =
|
|
26
|
-
return
|
|
19
|
+
} = readJsonSync(pkgJsonPath);
|
|
20
|
+
return semver.clean(version);
|
|
27
21
|
};
|
|
28
|
-
|
|
29
|
-
if (
|
|
22
|
+
export default async (downloadFolder, beforeInstall, afterInstall) => {
|
|
23
|
+
if (fs.existsSync(downloadFolder)) {
|
|
30
24
|
return false;
|
|
31
25
|
}
|
|
32
26
|
if (typeof beforeInstall === "function") {
|
|
33
27
|
await beforeInstall();
|
|
34
28
|
}
|
|
35
|
-
const platform =
|
|
29
|
+
const platform = os.platform();
|
|
36
30
|
switch (platform) {
|
|
37
31
|
case "darwin":
|
|
38
32
|
await setupDarwin(downloadFolder);
|
|
@@ -51,44 +45,43 @@ var _default = async (downloadFolder, beforeInstall, afterInstall) => {
|
|
|
51
45
|
}
|
|
52
46
|
return true;
|
|
53
47
|
};
|
|
54
|
-
exports.default = _default;
|
|
55
48
|
const SUPPORTED_ARCHITECTURES = ["x64", "arm64"];
|
|
56
49
|
async function setupDarwin(downloadFolder) {
|
|
57
50
|
const version = getPulumiVersion();
|
|
58
51
|
const arch = SUPPORTED_ARCHITECTURES.includes(process.arch) ? process.arch : "x64";
|
|
59
52
|
const filename = `pulumi-v${version}-darwin-${arch}.tar.gz`;
|
|
60
53
|
const downloadUrl = "https://get.pulumi.com/releases/sdk/" + filename;
|
|
61
|
-
const absoluteFilename =
|
|
62
|
-
await
|
|
63
|
-
await
|
|
54
|
+
const absoluteFilename = path.join(downloadFolder, filename);
|
|
55
|
+
await downloadFile(downloadUrl, absoluteFilename);
|
|
56
|
+
await tar.extract({
|
|
64
57
|
cwd: downloadFolder,
|
|
65
58
|
file: absoluteFilename
|
|
66
59
|
});
|
|
67
|
-
|
|
60
|
+
fs.unlinkSync(path.join(downloadFolder, filename));
|
|
68
61
|
}
|
|
69
62
|
async function setupWindows(downloadFolder) {
|
|
70
63
|
const version = getPulumiVersion();
|
|
71
64
|
const filename = `pulumi-v${version}-windows-x64.zip`;
|
|
72
65
|
const downloadUrl = "https://get.pulumi.com/releases/sdk/" + filename;
|
|
73
|
-
const absoluteFilename =
|
|
74
|
-
await
|
|
75
|
-
const destination =
|
|
76
|
-
await (
|
|
66
|
+
const absoluteFilename = path.join(downloadFolder, filename);
|
|
67
|
+
await downloadFile(downloadUrl, absoluteFilename);
|
|
68
|
+
const destination = path.join(downloadFolder, "pulumi");
|
|
69
|
+
await decompress(absoluteFilename, destination, {
|
|
77
70
|
strip: 2
|
|
78
71
|
});
|
|
79
|
-
|
|
72
|
+
fs.unlinkSync(path.join(downloadFolder, filename));
|
|
80
73
|
}
|
|
81
74
|
async function setupLinux(downloadFolder) {
|
|
82
75
|
const version = getPulumiVersion();
|
|
83
76
|
const filename = `pulumi-v${version}-linux-x64.tar.gz`;
|
|
84
77
|
const downloadUrl = "https://get.pulumi.com/releases/sdk/" + filename;
|
|
85
|
-
const absoluteFilename =
|
|
86
|
-
await
|
|
87
|
-
await
|
|
78
|
+
const absoluteFilename = path.join(downloadFolder, filename);
|
|
79
|
+
await downloadFile(downloadUrl, absoluteFilename);
|
|
80
|
+
await tar.extract({
|
|
88
81
|
cwd: downloadFolder,
|
|
89
82
|
file: absoluteFilename
|
|
90
83
|
});
|
|
91
|
-
|
|
84
|
+
fs.unlinkSync(path.join(downloadFolder, filename));
|
|
92
85
|
}
|
|
93
86
|
|
|
94
87
|
//# sourceMappingURL=downloadBinaries.js.map
|
package/downloadBinaries.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["os","tar","fs","path","decompress","semver","findUp","readJsonSync","downloadFile","getPulumiVersion","pkgJsonPath","sync","version","clean","downloadFolder","beforeInstall","afterInstall","existsSync","platform","setupDarwin","setupLinux","setupWindows","Error","SUPPORTED_ARCHITECTURES","arch","includes","process","filename","downloadUrl","absoluteFilename","join","extract","cwd","file","unlinkSync","destination","strip"],"sources":["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 findUp from \"find-up\";\nimport readJsonSync from \"read-json-sync\";\nimport { downloadFile } from \"./downloadFile.js\";\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 = findUp.sync(\"node_modules/@pulumi/pulumi/package.json\");\n const { version } = readJsonSync(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"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAO,KAAKC,GAAG,MAAM,KAAK;AAC1B,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,IAAI,MAAM,MAAM;AACvB;AACA,OAAOC,UAAU,MAAM,YAAY;AACnC,OAAOC,MAAM,MAAM,QAAQ;AAC3B,OAAOC,MAAM,MAAM,SAAS;AAC5B,OAAOC,YAAY,MAAM,gBAAgB;AACzC,SAASC,YAAY;;AAErB;AACA;AACA;AACA,MAAMC,gBAAgB,GAAGA,CAAA,KAAM;EAC3B,MAAMC,WAAW,GAAGJ,MAAM,CAACK,IAAI,CAAC,0CAA0C,CAAC;EAC3E,MAAM;IAAEC;EAAQ,CAAC,GAAGL,YAAY,CAACG,WAAY,CAAC;EAC9C,OAAOL,MAAM,CAACQ,KAAK,CAACD,OAAO,CAAC;AAChC,CAAC;AAED,eAAe,OACXE,cAAsB,EACtBC,aAA0B,EAC1BC,YAAyB,KACxB;EACD,IAAId,EAAE,CAACe,UAAU,CAACH,cAAc,CAAC,EAAE;IAC/B,OAAO,KAAK;EAChB;EAEA,IAAI,OAAOC,aAAa,KAAK,UAAU,EAAE;IACrC,MAAMA,aAAa,CAAC,CAAC;EACzB;EAEA,MAAMG,QAAQ,GAAGlB,EAAE,CAACkB,QAAQ,CAAC,CAAC;EAC9B,QAAQA,QAAQ;IACZ,KAAK,QAAQ;MACT,MAAMC,WAAW,CAACL,cAAc,CAAC;MACjC;IACJ,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on("error", err => {
|
|
1
|
+
import { dirname } from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import { Readable } from "stream";
|
|
4
|
+
export const downloadFile = async (url, file) => {
|
|
5
|
+
const res = await fetch(url);
|
|
6
|
+
if (!res.body) {
|
|
7
|
+
throw new Error("Response body is null");
|
|
8
|
+
}
|
|
9
|
+
const nodeStream = Readable.fromWeb(res.body);
|
|
10
|
+
await fs.ensureDir(dirname(file));
|
|
11
|
+
await new Promise((resolve, reject) => {
|
|
12
|
+
const fileStream = fs.createWriteStream(file);
|
|
13
|
+
nodeStream.pipe(fileStream);
|
|
14
|
+
nodeStream.on("error", err => {
|
|
18
15
|
reject(err);
|
|
19
16
|
});
|
|
20
17
|
fileStream.on("finish", () => {
|
|
@@ -22,6 +19,5 @@ const downloadFile = async (url, file) => {
|
|
|
22
19
|
});
|
|
23
20
|
});
|
|
24
21
|
};
|
|
25
|
-
exports.downloadFile = downloadFile;
|
|
26
22
|
|
|
27
23
|
//# sourceMappingURL=downloadFile.js.map
|
package/downloadFile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["dirname","fs","Readable","downloadFile","url","file","res","fetch","body","Error","nodeStream","fromWeb","ensureDir","Promise","resolve","reject","fileStream","createWriteStream","pipe","on","err"],"sources":["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"],"mappings":"AAAA,SAASA,OAAO,QAAQ,MAAM;AAC9B,OAAOC,EAAE,MAAM,UAAU;AACzB,SAASC,QAAQ,QAAQ,QAAQ;AAGjC,OAAO,MAAMC,YAAY,GAAG,MAAAA,CAAOC,GAAW,EAAEC,IAAY,KAAK;EAC7D,MAAMC,GAAG,GAAG,MAAMC,KAAK,CAACH,GAAG,CAAC;EAE5B,IAAI,CAACE,GAAG,CAACE,IAAI,EAAE;IACX,MAAM,IAAIC,KAAK,CAAC,uBAAuB,CAAC;EAC5C;EAEA,MAAMC,UAAU,GAAGR,QAAQ,CAACS,OAAO,CAACL,GAAG,CAACE,IAA0B,CAAC;EAEnE,MAAMP,EAAE,CAACW,SAAS,CAACZ,OAAO,CAACK,IAAI,CAAC,CAAC;EAEjC,MAAM,IAAIQ,OAAO,CAAO,CAACC,OAAO,EAAEC,MAAM,KAAK;IACzC,MAAMC,UAAU,GAAGf,EAAE,CAACgB,iBAAiB,CAACZ,IAAI,CAAC;IAC7CK,UAAU,CAACQ,IAAI,CAACF,UAAU,CAAC;IAC3BN,UAAU,CAACS,EAAE,CAAC,OAAO,EAAGC,GAAU,IAAK;MACnCL,MAAM,CAACK,GAAG,CAAC;IACf,CAAC,CAAC;IACFJ,UAAU,CAACG,EAAE,CAAC,QAAQ,EAAE,MAAM;MAC1BL,OAAO,CAAC,CAAC;IACb,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
package/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./Pulumi";
|
|
1
|
+
export * from "./Pulumi.js";
|
package/index.js
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _Pulumi = require("./Pulumi");
|
|
7
|
-
Object.keys(_Pulumi).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _Pulumi[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _Pulumi[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
1
|
+
export * from "./Pulumi.js";
|
|
17
2
|
|
|
18
3
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Pulumi.js\";\n"],"mappings":"AAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/pulumi-sdk",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.45.0-beta.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "index.js",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
@@ -14,21 +15,22 @@
|
|
|
14
15
|
"directory": "dist"
|
|
15
16
|
},
|
|
16
17
|
"dependencies": {
|
|
17
|
-
"@pulumi/aws": "
|
|
18
|
-
"@pulumi/pulumi": "3.
|
|
18
|
+
"@pulumi/aws": "^7.20.0",
|
|
19
|
+
"@pulumi/pulumi": "^3.223.0",
|
|
19
20
|
"decompress": "4.2.1",
|
|
20
21
|
"execa": "5.1.1",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
22
|
+
"find-up": "5.0.0",
|
|
23
|
+
"fs-extra": "11.3.3",
|
|
24
|
+
"lodash": "4.17.23",
|
|
25
|
+
"read-json-sync": "2.0.1",
|
|
26
|
+
"semver": "7.7.4",
|
|
27
|
+
"tar": "7.5.9"
|
|
26
28
|
},
|
|
27
29
|
"devDependencies": {
|
|
28
|
-
"@types/lodash": "4.17.
|
|
29
|
-
"@webiny/
|
|
30
|
-
"rimraf": "6.
|
|
31
|
-
"typescript": "5.
|
|
30
|
+
"@types/lodash": "4.17.23",
|
|
31
|
+
"@webiny/build-tools": "5.45.0-beta.0",
|
|
32
|
+
"rimraf": "6.1.3",
|
|
33
|
+
"typescript": "5.9.3"
|
|
32
34
|
},
|
|
33
35
|
"adio": {
|
|
34
36
|
"ignore": {
|
|
@@ -38,9 +40,5 @@
|
|
|
38
40
|
]
|
|
39
41
|
}
|
|
40
42
|
},
|
|
41
|
-
"
|
|
42
|
-
"build": "node ../cli/bin.js run build",
|
|
43
|
-
"watch": "node ../cli/bin.js run watch"
|
|
44
|
-
},
|
|
45
|
-
"gitHead": "c80e6d88501ac84229f6577dee7b30163a906379"
|
|
43
|
+
"gitHead": "b85c33cfbe7c02c130445c918d913ef4b2c09cb2"
|
|
46
44
|
}
|