pulumi 0.0.1 → 0.0.2

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/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # pulumi
2
+
3
+ Lazily install the [Pulumi CLI](https://www.pulumi.com) via npx.
4
+
5
+ ```sh
6
+ npx pulumi up
7
+ ```
8
+
9
+ > **Note:** This is NOT the Pulumi SDK. If you're writing a Pulumi program you
10
+ > want [`@pulumi/pulumi`](https://www.npmjs.com/package/@pulumi/pulumi)
11
+ > instead. See the [language SDK
12
+ > docs](https://www.pulumi.com/docs/iac/languages-sdks/) for all supported
13
+ > runtimes.
14
+
15
+ ## How it works
16
+
17
+ On first use, the package downloads the Pulumi CLI binary for your platform from
18
+ [get.pulumi.com](https://get.pulumi.com) and caches it in npm's cache directory
19
+ (`~/.npm/_pulumi/` by default). The download is checksum-verified to detect
20
+ corruption in transit. Subsequent invocations use the cached binary directly.
21
+
22
+ If a `pulumi` binary is already on your `PATH` (e.g. installed via Homebrew or
23
+ the [install script](https://www.pulumi.com/docs/install/)), that installation
24
+ is used instead of downloading a new one.
25
+
26
+ ## Version pinning
27
+
28
+ The npm package version matches the Pulumi CLI version exactly. Pin to a
29
+ specific release by specifying the version:
30
+
31
+ ```sh
32
+ npx pulumi@3.323.0 up
33
+ ```
34
+
35
+ ## Cache location
36
+
37
+ Binaries are cached at `_pulumi/<version>/` inside npm's configured cache
38
+ directory. To change the location, set `npm_config_cache`:
39
+
40
+ ```sh
41
+ npm_config_cache=/path/to/cache npx pulumi up
42
+ ```
package/lib/cache.js ADDED
@@ -0,0 +1,31 @@
1
+ // Copyright 2026, Pulumi Corporation. All rights reserved.
2
+
3
+ "use strict";
4
+
5
+ const os = require("os");
6
+ const path = require("path");
7
+
8
+ // npmDefaultCache returns npm's default cache directory when npm_config_cache
9
+ // is not set in the environment. These are npm's own documented defaults:
10
+ // https://docs.npmjs.com/cli/v11/using-npm/config#cache
11
+ function npmDefaultCache() {
12
+ if (process.platform === "win32") {
13
+ return path.join(process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"), "npm-cache");
14
+ }
15
+ return path.join(os.homedir(), ".npm");
16
+ }
17
+
18
+ // cacheDir returns the directory where the pulumi binaries for a specific
19
+ // version should be cached. Follows npm's _subdirectory naming convention
20
+ // (e.g. _npx, _cacache, _prebuilds) so binaries live alongside other
21
+ // npm-managed caches.
22
+ //
23
+ // When invoked via npx or an npm script, npm injects npm_config_cache into
24
+ // the environment — that is the authoritative cache path. Otherwise we fall
25
+ // back to npm's documented default so the cache location is consistent.
26
+ function cacheDir(version) {
27
+ const base = process.env.npm_config_cache || npmDefaultCache();
28
+ return path.join(base, "_pulumi", version);
29
+ }
30
+
31
+ module.exports = { cacheDir };
@@ -0,0 +1,64 @@
1
+ // Copyright 2026, Pulumi Corporation. All rights reserved.
2
+
3
+ "use strict";
4
+
5
+ const fs = require("fs");
6
+ const os = require("os");
7
+ const path = require("path");
8
+ const { execFileSync } = require("child_process");
9
+
10
+ const INSTALL_SH_URL = "https://get.pulumi.com/install.sh";
11
+ const INSTALL_PS1_URL = "https://get.pulumi.com/install.ps1";
12
+
13
+ async function defaultFetchText(url) {
14
+ const res = await fetch(url);
15
+ if (!res.ok) throw new Error(`HTTP ${res.status} fetching ${url}`);
16
+ return res.text();
17
+ }
18
+
19
+ function defaultExecScript(scriptPath, args) {
20
+ if (process.platform === "win32") {
21
+ const ps = process.env.SystemRoot
22
+ ? path.join(process.env.SystemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe")
23
+ : "powershell.exe";
24
+ execFileSync(ps, ["-NoProfile", "-InputFormat", "None", "-ExecutionPolicy", "Bypass", "-File", scriptPath, ...args], {
25
+ stdio: "inherit",
26
+ });
27
+ } else {
28
+ execFileSync("/bin/sh", [scriptPath, ...args], { stdio: "inherit" });
29
+ }
30
+ }
31
+
32
+ // installCLI downloads and runs the official Pulumi install script, installing
33
+ // the CLI and all language hosts into {root}/bin/. Mirrors the approach used
34
+ // by the Automation API (sdk/nodejs/automation/cmd.ts installPosix/installWindows).
35
+ // IO functions are injectable for testing.
36
+ async function installCLI(
37
+ version,
38
+ root,
39
+ { fetchText = defaultFetchText, execScript = defaultExecScript } = {},
40
+ ) {
41
+ const isWindows = process.platform === "win32";
42
+ const scriptContent = await fetchText(isWindows ? INSTALL_PS1_URL : INSTALL_SH_URL);
43
+
44
+ const ext = isWindows ? ".ps1" : ".sh";
45
+ const scriptPath = path.join(os.tmpdir(), `pulumi-install-${process.pid}${ext}`);
46
+ try {
47
+ fs.writeFileSync(scriptPath, scriptContent, { mode: 0o700 });
48
+ const args = isWindows
49
+ ? ["-NoEditPath", "-InstallRoot", root, "-Version", version]
50
+ : ["--no-edit-path", "--install-root", root, "--version", version];
51
+ execScript(scriptPath, args);
52
+ } finally {
53
+ fs.rmSync(scriptPath, { force: true });
54
+ }
55
+ }
56
+
57
+ // fetchLatestVersion returns the latest stable Pulumi release version string.
58
+ async function fetchLatestVersion(fetchText = defaultFetchText) {
59
+ const text = await fetchText("https://api.github.com/repos/pulumi/pulumi/releases/latest");
60
+ const { tag_name } = JSON.parse(text);
61
+ return tag_name.replace(/^v/, "");
62
+ }
63
+
64
+ module.exports = { installCLI, fetchLatestVersion };
package/lib/resolve.js ADDED
@@ -0,0 +1,72 @@
1
+ // Copyright 2026, Pulumi Corporation. All rights reserved.
2
+
3
+ "use strict";
4
+
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+ const { cacheDir } = require("./cache");
8
+ const { installCLI, fetchLatestVersion } = require("./download");
9
+
10
+ const pkg = require("../package.json");
11
+
12
+ // Canonical path of this package's entry point. Used by isExecutable to skip
13
+ // our own wrapper when a global `npm install` symlinks it onto PATH, which
14
+ // would otherwise cause infinite recursion.
15
+ const SELF = fs.realpathSync(path.resolve(__dirname, "..", "run.js"));
16
+
17
+ // isExecutable returns true if filePath is a non-empty executable that does
18
+ // not resolve to this package's own entry point.
19
+ function isExecutable(filePath) {
20
+ try {
21
+ fs.accessSync(filePath, fs.constants.X_OK);
22
+ return fs.realpathSync(filePath) !== SELF && fs.statSync(filePath).size > 0;
23
+ } catch {
24
+ return false;
25
+ }
26
+ }
27
+
28
+ // findSystemPulumi searches PATH for a native pulumi binary, skipping any
29
+ // path component that contains "node_modules" to avoid calling ourselves.
30
+ // pathEnv defaults to process.env.PATH and is injectable for testing.
31
+ function findSystemPulumi(pathEnv) {
32
+ const search = pathEnv !== undefined ? pathEnv : process.env.PATH || "";
33
+ const exe = process.platform === "win32" ? "pulumi.exe" : "pulumi";
34
+ for (const dir of search.split(path.delimiter)) {
35
+ if (!dir || dir.includes("node_modules")) continue;
36
+ const candidate = path.join(dir, exe);
37
+ if (isExecutable(candidate)) return candidate;
38
+ }
39
+ return null;
40
+ }
41
+
42
+ // resolve returns the path to the pulumi binary to invoke, using the
43
+ // following priority:
44
+ // 1. A native pulumi binary found on PATH (defers to existing installs).
45
+ // 2. A version-pinned binary in the local cache.
46
+ // 3. A freshly installed binary (cached for future invocations).
47
+ //
48
+ // IO functions are injectable for testing.
49
+ async function resolve({
50
+ pathEnv,
51
+ version = process.env.PULUMI_VERSION || pkg.version,
52
+ install = installCLI,
53
+ getLatestVersion = fetchLatestVersion,
54
+ } = {}) {
55
+ const system = findSystemPulumi(pathEnv);
56
+ if (system) return system;
57
+
58
+ if (!version) {
59
+ version = await getLatestVersion();
60
+ }
61
+
62
+ const exe = process.platform === "win32" ? "pulumi.exe" : "pulumi";
63
+ const root = cacheDir(version);
64
+ const dest = path.join(root, "bin", exe);
65
+ if (isExecutable(dest)) return dest;
66
+
67
+ process.stderr.write(`Downloading pulumi v${version}...\n`);
68
+ await install(version, root);
69
+ return dest;
70
+ }
71
+
72
+ module.exports = { resolve, findSystemPulumi, isExecutable };
package/package.json CHANGED
@@ -1,7 +1,24 @@
1
1
  {
2
- "name": "pulumi",
3
- "version": "0.0.1",
4
- "description": "",
5
- "main": "index.js",
6
- "author": ""
2
+ "name": "pulumi",
3
+ "version": "0.0.2",
4
+ "description": "Pulumi Infrastructure as Code CLI",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/pulumi/pulumi.git",
9
+ "directory": "npm"
10
+ },
11
+ "bin": {
12
+ "pulumi": "run.js"
13
+ },
14
+ "scripts": {
15
+ "test": "node --test test/cache.test.js test/download.test.js test/resolve.test.js",
16
+ "test:integration": "node --test test/integration.test.js"
17
+ },
18
+ "devDependencies": {
19
+ "@biomejs/biome": "1.8.3"
20
+ },
21
+ "engines": {
22
+ "node": ">=18"
23
+ }
7
24
  }
Binary file
package/run.js ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ // Copyright 2026, Pulumi Corporation. All rights reserved.
3
+
4
+ "use strict";
5
+
6
+ const path = require("path");
7
+ const { spawn } = require("child_process");
8
+ const { resolve } = require("./lib/resolve");
9
+
10
+ resolve()
11
+ .then((bin) => {
12
+ // Prepend the directory containing the CLI to PATH so that language
13
+ // hosts (pulumi-language-nodejs, etc.) installed alongside it are found.
14
+ const env = { ...process.env, PATH: path.dirname(bin) + path.delimiter + (process.env.PATH || "") };
15
+ const child = spawn(bin, process.argv.slice(2), { stdio: "inherit", env });
16
+ child.on("exit", (code, signal) => {
17
+ if (signal) {
18
+ // Propagate signal to the parent process.
19
+ process.kill(process.pid, signal);
20
+ } else {
21
+ process.exit(code ?? 0);
22
+ }
23
+ });
24
+ child.on("error", (err) => {
25
+ process.stderr.write(`pulumi: failed to start: ${err.message}\n`);
26
+ process.exit(1);
27
+ });
28
+ })
29
+ .catch((err) => {
30
+ process.stderr.write(`pulumi: ${err.message}\n`);
31
+ process.exit(1);
32
+ });