Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a6b8d2684 |
+1
-2
@@ -42,6 +42,5 @@ inputs:
|
||||
description: "A string of environment variable names, separated by newlines. These will be bound to your Worker using the values of matching environment variables declared in `env` of this workflow."
|
||||
required: false
|
||||
packageManager:
|
||||
description: "The package manager you'd like to use to install and run wrangler. If not specified, a value will be inferred based on the presence of a lockfile. Valid values: [npm, pnpm, yarn]"
|
||||
description: "The name of the package manager to install and run wrangler. If not provided, it will be detected via the lock file. Valid values: [npm, pnpm, yarn]"
|
||||
required: false
|
||||
default: npm
|
||||
|
||||
Vendored
+37
-41
@@ -2860,11 +2860,30 @@ function checkWorkingDirectory(workingDirectory = ".") {
|
||||
throw new Error(`Directory ${workingDirectory} does not exist.`);
|
||||
}
|
||||
}
|
||||
function detectPackageManager(workingDirectory = ".") {
|
||||
if ((0,external_node_fs_namespaceObject.existsSync)(external_node_path_namespaceObject.join(workingDirectory, "package-lock.json"))) {
|
||||
return "npm";
|
||||
}
|
||||
if ((0,external_node_fs_namespaceObject.existsSync)(external_node_path_namespaceObject.join(workingDirectory, "yarn.lock"))) {
|
||||
return "yarn";
|
||||
}
|
||||
if ((0,external_node_fs_namespaceObject.existsSync)(external_node_path_namespaceObject.join(workingDirectory, "pnpm-lock.yaml"))) {
|
||||
return "pnpm";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function isValidPackageManager(name) {
|
||||
return name === "npm" || name === "yarn" || name === "pnpm";
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./src/packageManagers.ts
|
||||
;// CONCATENATED MODULE: ./src/index.ts
|
||||
|
||||
|
||||
const PACKAGE_MANAGERS = {
|
||||
|
||||
|
||||
const execAsync = external_node_util_namespaceObject.promisify(external_node_child_process_namespaceObject.exec);
|
||||
const DEFAULT_WRANGLER_VERSION = "3.5.1";
|
||||
const PACKAGE_MANAGER_COMMANDS = {
|
||||
npm: {
|
||||
install: "npm i",
|
||||
exec: "npx",
|
||||
@@ -2878,37 +2897,6 @@ const PACKAGE_MANAGERS = {
|
||||
exec: "pnpm exec",
|
||||
},
|
||||
};
|
||||
function detectPackageManager(workingDirectory = ".") {
|
||||
if ((0,external_node_fs_namespaceObject.existsSync)(external_node_path_namespaceObject.join(workingDirectory, "package-lock.json"))) {
|
||||
return "npm";
|
||||
}
|
||||
if ((0,external_node_fs_namespaceObject.existsSync)(external_node_path_namespaceObject.join(workingDirectory, "yarn.lock"))) {
|
||||
return "yarn";
|
||||
}
|
||||
if ((0,external_node_fs_namespaceObject.existsSync)(external_node_path_namespaceObject.join(workingDirectory, "pnpm-lock.yaml"))) {
|
||||
return "pnpm";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function assertValidPackageManagerValue(name) {
|
||||
if (name && !Object.keys(PACKAGE_MANAGERS).includes(name)) {
|
||||
throw new TypeError(`invalid value provided for "packageManager": ${name}
|
||||
Value must be one of: [${Object.keys(PACKAGE_MANAGERS).join(", ")}]`);
|
||||
}
|
||||
}
|
||||
function getPackageManager(name, { workingDirectory = "." } = {}) {
|
||||
assertValidPackageManagerValue(name);
|
||||
return PACKAGE_MANAGERS[name || detectPackageManager(workingDirectory) || "npm"];
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./src/index.ts
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const execAsync = external_node_util_namespaceObject.promisify(external_node_child_process_namespaceObject.exec);
|
||||
const DEFAULT_WRANGLER_VERSION = "3.5.1";
|
||||
/**
|
||||
* A configuration object that contains all the inputs & immutable state for the action.
|
||||
*/
|
||||
@@ -2924,9 +2912,17 @@ const config = {
|
||||
QUIET_MODE: (0,core.getBooleanInput)("quiet"),
|
||||
PACKAGE_MANAGER: (0,core.getInput)("packageManager"),
|
||||
};
|
||||
const packageManager = getPackageManager(config.PACKAGE_MANAGER, {
|
||||
workingDirectory: config.workingDirectory,
|
||||
});
|
||||
function realPackageManager() {
|
||||
if (isValidPackageManager(config.PACKAGE_MANAGER)) {
|
||||
return config.PACKAGE_MANAGER;
|
||||
}
|
||||
const packageManager = detectPackageManager(config.workingDirectory);
|
||||
if (packageManager !== null) {
|
||||
return packageManager;
|
||||
}
|
||||
throw new Error("Package manager is not detected");
|
||||
}
|
||||
const pkgManagerCmd = PACKAGE_MANAGER_COMMANDS[realPackageManager()];
|
||||
function info(message, bypass) {
|
||||
if (!config.QUIET_MODE || bypass) {
|
||||
(0,core.info)(message);
|
||||
@@ -2980,7 +2976,7 @@ function installWrangler() {
|
||||
throw new Error(`Wrangler v1 is no longer supported by this action. Please use major version 2 or greater`);
|
||||
}
|
||||
startGroup("📥 Installing Wrangler");
|
||||
const command = `${packageManager.install} wrangler@${config["WRANGLER_VERSION"]}`;
|
||||
const command = `${pkgManagerCmd.install} wrangler@${config["WRANGLER_VERSION"]}`;
|
||||
info(`Running command: ${command}`);
|
||||
(0,external_node_child_process_namespaceObject.execSync)(command, { cwd: config["workingDirectory"], env: process.env });
|
||||
info(`✅ Wrangler installed`, true);
|
||||
@@ -2998,7 +2994,7 @@ async function execCommands(commands, cmdType) {
|
||||
try {
|
||||
const arrPromises = commands.map(async (command) => {
|
||||
const cmd = command.startsWith("wrangler")
|
||||
? `${packageManager.exec} ${command}`
|
||||
? `${pkgManagerCmd.exec} ${command}`
|
||||
: command;
|
||||
info(`🚀 Executing command: ${cmd}`);
|
||||
return await runProcess(cmd, {
|
||||
@@ -3028,7 +3024,7 @@ function getSecret(secret) {
|
||||
async function legacyUploadSecrets(secrets, environment, workingDirectory) {
|
||||
const arrPromises = secrets
|
||||
.map((secret) => {
|
||||
const command = `echo ${getSecret(secret)} | ${packageManager.exec} wrangler secret put ${secret}`;
|
||||
const command = `echo ${getSecret(secret)} | ${pkgManagerCmd.exec} wrangler secret put ${secret}`;
|
||||
return environment ? command.concat(` --env ${environment}`) : command;
|
||||
})
|
||||
.map(async (command) => await execAsync(command, {
|
||||
@@ -3055,7 +3051,7 @@ async function uploadSecrets() {
|
||||
const environmentSuffix = !environment.length
|
||||
? ""
|
||||
: ` --env ${environment}`;
|
||||
const secretCmd = `echo "${JSON.stringify(secretObj).replaceAll('"', '\\"')}" | ${packageManager.exec} wrangler secret:bulk ${environmentSuffix}`;
|
||||
const secretCmd = `echo "${JSON.stringify(secretObj).replaceAll('"', '\\"')}" | ${pkgManagerCmd.exec} wrangler secret:bulk ${environmentSuffix}`;
|
||||
(0,external_node_child_process_namespaceObject.execSync)(secretCmd, {
|
||||
cwd: workingDirectory,
|
||||
env: process.env,
|
||||
@@ -3099,7 +3095,7 @@ async function wranglerCommands() {
|
||||
if (environment.length > 0 && !command.includes(`--env`)) {
|
||||
command = command.concat(` --env ${environment}`);
|
||||
}
|
||||
const cmd = `${packageManager.exec} wrangler ${command} ${(command.startsWith("deploy") || command.startsWith("publish")) &&
|
||||
const cmd = `${pkgManagerCmd.exec} wrangler ${command} ${(command.startsWith("deploy") || command.startsWith("publish")) &&
|
||||
!command.includes(`--var`)
|
||||
? getVarArgs()
|
||||
: ""}`.trim();
|
||||
|
||||
Reference in New Issue
Block a user