Skip to content

Commit a28dce9

Browse files
liangmiQwQfengmk2
andauthored
feat: add package-manager environment configuration (#148)
Add `package-manager` for GitHub and GitLab, and `packageManager` for Azure. Accept a boolean or a mapping of npm, pnpm, yarn, and bun to booleans. `false` runs `vp env off pm`; individual false entries run commands such as `vp env off pnpm`. True and omitted entries leave the installer default unchanged, without explicit enable commands. Any explicit configuration requires Vite+ 0.3.1+; older versions remain supported when the input is unset. 🤖 Generated with Codex --------- Co-authored-by: MK (fengmk2) <fengmk2@gmail.com>
1 parent 9accff0 commit a28dce9

20 files changed

Lines changed: 563 additions & 82 deletions

.github/workflows/test.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,55 @@ jobs:
235235
exit 1
236236
fi
237237
238+
test-package-manager:
239+
strategy:
240+
fail-fast: false
241+
matrix:
242+
os: [ubuntu-latest, macos-latest, windows-latest]
243+
config:
244+
- input: "true"
245+
modes: '["managed", "managed", "managed", "managed"]'
246+
- input: "false"
247+
modes: '["system_first", "system_first", "system_first", "system_first"]'
248+
- input: "{npm: false, pnpm: true, yarn: false}"
249+
modes: '["system_first", "managed", "system_first", "managed"]'
250+
runs-on: ${{ matrix.os }}
251+
steps:
252+
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
253+
254+
- name: Setup Vite+ with package-manager configuration
255+
uses: ./
256+
with:
257+
package-manager: ${{ matrix.config.input }}
258+
run-install: false
259+
cache: false
260+
261+
# Query the real CLI so this covers input parsing, installation, and mode
262+
# changes, including true and omitted entries in a partial mapping.
263+
- name: Verify package-manager modes and independent Node.js management
264+
shell: bash
265+
env:
266+
EXPECTED_MODES: ${{ matrix.config.modes }}
267+
run: |
268+
node --input-type=module <<'NODE'
269+
import assert from 'node:assert/strict';
270+
import { execFileSync } from 'node:child_process';
271+
272+
const managers = ['npm', 'pnpm', 'yarn', 'bun'];
273+
const modes = JSON.parse(process.env.EXPECTED_MODES);
274+
for (const [index, manager] of managers.entries()) {
275+
const { package_manager: current } = JSON.parse(
276+
execFileSync('vp', ['env', 'current', manager, '--json'], { encoding: 'utf8' }),
277+
);
278+
console.log(`${manager}: ${current.mode}`);
279+
assert.equal(current.mode, modes[index], `${manager} mode`);
280+
}
281+
const { node } = JSON.parse(
282+
execFileSync('vp', ['env', 'current', 'node', '--json'], { encoding: 'utf8' }),
283+
);
284+
assert.equal(node.mode, 'managed', 'Node.js management must remain enabled');
285+
NODE
286+
238287
test-default-version:
239288
# End-to-end check of the default version-resolution logic: with no `version`
240289
# or `version-file` input, the action auto-detects the vite-plus version from

README.md

Lines changed: 56 additions & 38 deletions
Large diffs are not rendered by default.

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ inputs:
3030
node-manager:
3131
description: "Control Vite+'s Node.js version manager. When unset, the Vite+ installer decides (enabled on CI). Set to `false` to keep the Node.js already on the runner (e.g. from actions/setup-node or the runner image): after installation, vp commands prefer the system Node.js. Set to `true` to leave the installer default unchanged. Cannot be `false` together with node-version or node-version-file."
3232
required: false
33+
package-manager:
34+
description: "Control Vite+ package-manager management (0.3.1+). Accepts true, false, or a YAML mapping of npm, pnpm, yarn, and bun to booleans. Unspecified managers keep the installer default (enabled on CI). Any explicit configuration requires 0.3.1+. False prefers the system package manager. Independent of node-manager."
35+
required: false
36+
default: ""
3337
working-directory:
3438
description: "Project directory to use for relative paths, lockfile auto-detection, environment checks, and default `vp install` execution."
3539
required: false

azure/setup-vp.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ parameters:
2323
- name: nodeVersion
2424
type: string
2525
default: 24.x
26+
- name: packageManager
27+
type: object
28+
default: ""
2629
- name: nodeManager
2730
type: string
2831
default: ""
@@ -53,6 +56,7 @@ steps:
5356
SETUP_VP_WORKING_DIRECTORY: ${{ parameters.workingDirectory }}
5457
SETUP_VP_RUN_INSTALL: ${{ convertToJson(parameters.runInstall) }}
5558
SETUP_VP_SFW: ${{ iif(eq(parameters.sfw, true), 'true', 'false') }}
59+
SETUP_VP_PACKAGE_MANAGER: ${{ convertToJson(parameters.packageManager) }}
5660
SETUP_VP_NODE_MANAGER: ${{ parameters.nodeManager }}
5761
SETUP_VP_REGISTRY_URL: ${{ parameters.registryUrl }}
5862
SETUP_VP_SCOPE: ${{ parameters.scope }}
@@ -75,6 +79,7 @@ steps:
7579
SETUP_VP_WORKING_DIRECTORY: ${{ parameters.workingDirectory }}
7680
SETUP_VP_RUN_INSTALL: ${{ convertToJson(parameters.runInstall) }}
7781
SETUP_VP_SFW: ${{ iif(eq(parameters.sfw, true), 'true', 'false') }}
82+
SETUP_VP_PACKAGE_MANAGER: ${{ convertToJson(parameters.packageManager) }}
7883
SETUP_VP_NODE_MANAGER: ${{ parameters.nodeManager }}
7984
SETUP_VP_REGISTRY_URL: ${{ parameters.registryUrl }}
8085
SETUP_VP_SCOPE: ${{ parameters.scope }}

dist/azure/index.mjs

Lines changed: 123 additions & 9 deletions
Large diffs are not rendered by default.

dist/gitlab/index.mjs

Lines changed: 115 additions & 1 deletion
Large diffs are not rendered by default.

dist/index.mjs

Lines changed: 21 additions & 21 deletions
Large diffs are not rendered by default.

gitlab/setup-vp.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ spec:
1313
description: "Wrap `vp install` with Socket Firewall Free (`sfw`) to block malicious dependency fetches."
1414
type: boolean
1515
default: false
16+
package-manager:
17+
description: 'Control Vite+ package-manager management (0.3.1+). Use "true", "false", or a YAML mapping of npm, pnpm, yarn, and bun to booleans. Unspecified managers keep the installer default (enabled on CI). Any explicit configuration requires 0.3.1+.'
18+
default: ""
1619
node-manager:
1720
description: 'Control Vite+''s Node.js version manager. This is a string input: empty (default) lets the Vite+ installer decide (enabled on CI); "false" keeps the runner image''s Node.js (makes vp commands prefer the system Node.js after installation); "true" leaves the installer default unchanged.'
1821
default: ""
@@ -49,6 +52,7 @@ spec:
4952
export SETUP_VP_WORKING_DIRECTORY="${SETUP_VP_WORKING_DIRECTORY:-.}"
5053
export SETUP_VP_RUN_INSTALL="${SETUP_VP_RUN_INSTALL:-true}"
5154
export SETUP_VP_SFW="${SETUP_VP_SFW:-false}"
55+
export SETUP_VP_PACKAGE_MANAGER="${SETUP_VP_PACKAGE_MANAGER:-}"
5256
export SETUP_VP_NODE_MANAGER="${SETUP_VP_NODE_MANAGER:-}"
5357
export SETUP_VP_REGISTRY_URL="${SETUP_VP_REGISTRY_URL:-}"
5458
export SETUP_VP_SCOPE="${SETUP_VP_SCOPE:-}"
@@ -87,6 +91,11 @@ spec:
8791
SETUP_VP_SFW_EOF
8892
)"
8993
export SETUP_VP_SFW
94+
SETUP_VP_PACKAGE_MANAGER="$(cat <<'SETUP_VP_PACKAGE_MANAGER_EOF'
95+
$[[ inputs.package-manager ]]
96+
SETUP_VP_PACKAGE_MANAGER_EOF
97+
)"
98+
export SETUP_VP_PACKAGE_MANAGER
9099
SETUP_VP_NODE_MANAGER="$(cat <<'SETUP_VP_NODE_MANAGER_EOF'
91100
$[[ inputs.node-manager ]]
92101
SETUP_VP_NODE_MANAGER_EOF

src/azure/index.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ describe("Azure lifecycle", () => {
8282
{
8383
SETUP_VP_VERSION: "latest",
8484
SETUP_VP_NODE_MANAGER: "false",
85+
SETUP_VP_PACKAGE_MANAGER: version === "0.3.1" ? '{"pnpm":true,"bun":false}' : "",
8586
SYSTEM_DEFAULTWORKINGDIRECTORY: process.cwd(),
8687
},
8788
{
@@ -105,6 +106,10 @@ describe("Azure lifecycle", () => {
105106
"vp",
106107
version === "0.3.0" ? ["env", "off"] : ["env", "off", "node"],
107108
);
109+
if (version === "0.3.1") {
110+
expect(run).not.toHaveBeenCalledWith("vp", ["env", "on", "pm"]);
111+
expect(run).toHaveBeenCalledWith("vp", ["env", "off", "bun"]);
112+
}
108113
});
109114

110115
it("prepare leaves the node manager alone when nodeManager is unset", async () => {

src/azure/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from "node:path";
22
import { pathToFileURL } from "node:url";
3+
import { packageManagerArgs } from "../ci/package-manager.js";
34
import { nodeManagerOffArgs } from "../ci/node-manager.js";
45
import { configureAuth } from "../ci/auth.js";
56
import { prepareCacheMetadata } from "../ci/cache.js";
@@ -66,9 +67,19 @@ export async function runPrepare(
6667
logWarningFn: ports.logWarning,
6768
});
6869

70+
const versionOutput =
71+
inputs.nodeManager === false || inputs.packageManager !== undefined
72+
? ports.getCommandOutput("vp", ["--version"]) || ""
73+
: "";
74+
const packageManagerCommands = packageManagerArgs(inputs.packageManager, versionOutput);
75+
6976
// Switch to the agent's Node.js after installation, preserving package-manager management.
7077
if (inputs.nodeManager === false) {
71-
ports.run("vp", nodeManagerOffArgs(ports.getCommandOutput("vp", ["--version"]) || ""));
78+
ports.run("vp", nodeManagerOffArgs(versionOutput));
79+
}
80+
81+
for (const args of packageManagerCommands) {
82+
ports.run("vp", args);
7283
}
7384

7485
const runtimePath = path.resolve(process.argv[1] || "");

0 commit comments

Comments
 (0)