mirror of
				https://gitea.com/actions/setup-node.git
				synced 2025-11-04 05:39:04 +08:00 
			
		
		
		
	Add project-dir
This commit is contained in:
		@@ -25,6 +25,8 @@ inputs:
 | 
				
			|||||||
    description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
 | 
					    description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
 | 
				
			||||||
  cache-dependency-path:
 | 
					  cache-dependency-path:
 | 
				
			||||||
    description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
 | 
					    description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
 | 
				
			||||||
 | 
					  project-dir:
 | 
				
			||||||
 | 
					    description: 'Optional path used as a current working directory during executing package manager commands. Important if project directory is not the same as root.'
 | 
				
			||||||
# TODO: add input to control forcing to pull from cloud or dist.
 | 
					# TODO: add input to control forcing to pull from cloud or dist.
 | 
				
			||||||
#       escape valve for someone having issues or needing the absolute latest which isn't cached yet
 | 
					#       escape valve for someone having issues or needing the absolute latest which isn't cached yet
 | 
				
			||||||
outputs:
 | 
					outputs:
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								dist/cache-save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										24
									
								
								dist/cache-save/index.js
									
									
									
									
										vendored
									
									
								
							@@ -59244,11 +59244,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
 | 
				
			|||||||
        step((generator = generator.apply(thisArg, _arguments || [])).next());
 | 
					        step((generator = generator.apply(thisArg, _arguments || [])).next());
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					var __importDefault = (this && this.__importDefault) || function (mod) {
 | 
				
			||||||
 | 
					    return (mod && mod.__esModule) ? mod : { "default": mod };
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
 | 
					Object.defineProperty(exports, "__esModule", ({ value: true }));
 | 
				
			||||||
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
 | 
					exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
 | 
				
			||||||
const core = __importStar(__nccwpck_require__(2186));
 | 
					const core = __importStar(__nccwpck_require__(2186));
 | 
				
			||||||
const exec = __importStar(__nccwpck_require__(1514));
 | 
					const exec = __importStar(__nccwpck_require__(1514));
 | 
				
			||||||
const cache = __importStar(__nccwpck_require__(7799));
 | 
					const cache = __importStar(__nccwpck_require__(7799));
 | 
				
			||||||
 | 
					const path_1 = __importDefault(__nccwpck_require__(1017));
 | 
				
			||||||
exports.supportedPackageManagers = {
 | 
					exports.supportedPackageManagers = {
 | 
				
			||||||
    npm: {
 | 
					    npm: {
 | 
				
			||||||
        lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'],
 | 
					        lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'],
 | 
				
			||||||
@@ -59267,8 +59271,8 @@ exports.supportedPackageManagers = {
 | 
				
			|||||||
        getCacheFolderCommand: 'yarn config get cacheFolder'
 | 
					        getCacheFolderCommand: 'yarn config get cacheFolder'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
 | 
					const getCommandOutput = (toolCommand, cwd) => __awaiter(void 0, void 0, void 0, function* () {
 | 
				
			||||||
    let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
 | 
					    let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, Object.assign({ ignoreReturnCode: true }, (cwd !== null && { cwd })));
 | 
				
			||||||
    if (exitCode) {
 | 
					    if (exitCode) {
 | 
				
			||||||
        stderr = !stderr.trim()
 | 
					        stderr = !stderr.trim()
 | 
				
			||||||
            ? `The '${toolCommand}' command failed with exit code: ${exitCode}`
 | 
					            ? `The '${toolCommand}' command failed with exit code: ${exitCode}`
 | 
				
			||||||
@@ -59278,8 +59282,20 @@ const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, func
 | 
				
			|||||||
    return stdout.trim();
 | 
					    return stdout.trim();
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
exports.getCommandOutput = getCommandOutput;
 | 
					exports.getCommandOutput = getCommandOutput;
 | 
				
			||||||
 | 
					const getPackageManagerWorkingDir = () => {
 | 
				
			||||||
 | 
					    const projectDir = core.getInput('project-dir');
 | 
				
			||||||
 | 
					    if (projectDir) {
 | 
				
			||||||
 | 
					        return projectDir;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const cache = core.getInput('cache');
 | 
				
			||||||
 | 
					    if (cache !== 'yarn') {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const cacheDependencyPath = core.getInput('cache-dependency-path');
 | 
				
			||||||
 | 
					    return cacheDependencyPath ? path_1.default.dirname(cacheDependencyPath) : null;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
const getPackageManagerVersion = (packageManager, command) => __awaiter(void 0, void 0, void 0, function* () {
 | 
					const getPackageManagerVersion = (packageManager, command) => __awaiter(void 0, void 0, void 0, function* () {
 | 
				
			||||||
    const stdOut = yield exports.getCommandOutput(`${packageManager} ${command}`);
 | 
					    const stdOut = yield exports.getCommandOutput(`${packageManager} ${command}`, getPackageManagerWorkingDir());
 | 
				
			||||||
    if (!stdOut) {
 | 
					    if (!stdOut) {
 | 
				
			||||||
        throw new Error(`Could not retrieve version of ${packageManager}`);
 | 
					        throw new Error(`Could not retrieve version of ${packageManager}`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -59308,7 +59324,7 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
exports.getPackageManagerInfo = getPackageManagerInfo;
 | 
					exports.getPackageManagerInfo = getPackageManagerInfo;
 | 
				
			||||||
const getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaiter(void 0, void 0, void 0, function* () {
 | 
					const getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaiter(void 0, void 0, void 0, function* () {
 | 
				
			||||||
    const stdOut = yield exports.getCommandOutput(packageManagerInfo.getCacheFolderCommand);
 | 
					    const stdOut = yield exports.getCommandOutput(packageManagerInfo.getCacheFolderCommand, getPackageManagerWorkingDir());
 | 
				
			||||||
    if (!stdOut) {
 | 
					    if (!stdOut) {
 | 
				
			||||||
        throw new Error(`Could not get cache folder path for ${packageManager}`);
 | 
					        throw new Error(`Could not get cache folder path for ${packageManager}`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										24
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							@@ -71212,11 +71212,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
 | 
				
			|||||||
        step((generator = generator.apply(thisArg, _arguments || [])).next());
 | 
					        step((generator = generator.apply(thisArg, _arguments || [])).next());
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					var __importDefault = (this && this.__importDefault) || function (mod) {
 | 
				
			||||||
 | 
					    return (mod && mod.__esModule) ? mod : { "default": mod };
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
 | 
					Object.defineProperty(exports, "__esModule", ({ value: true }));
 | 
				
			||||||
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
 | 
					exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
 | 
				
			||||||
const core = __importStar(__nccwpck_require__(2186));
 | 
					const core = __importStar(__nccwpck_require__(2186));
 | 
				
			||||||
const exec = __importStar(__nccwpck_require__(1514));
 | 
					const exec = __importStar(__nccwpck_require__(1514));
 | 
				
			||||||
const cache = __importStar(__nccwpck_require__(7799));
 | 
					const cache = __importStar(__nccwpck_require__(7799));
 | 
				
			||||||
 | 
					const path_1 = __importDefault(__nccwpck_require__(1017));
 | 
				
			||||||
exports.supportedPackageManagers = {
 | 
					exports.supportedPackageManagers = {
 | 
				
			||||||
    npm: {
 | 
					    npm: {
 | 
				
			||||||
        lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'],
 | 
					        lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'],
 | 
				
			||||||
@@ -71235,8 +71239,8 @@ exports.supportedPackageManagers = {
 | 
				
			|||||||
        getCacheFolderCommand: 'yarn config get cacheFolder'
 | 
					        getCacheFolderCommand: 'yarn config get cacheFolder'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
 | 
					const getCommandOutput = (toolCommand, cwd) => __awaiter(void 0, void 0, void 0, function* () {
 | 
				
			||||||
    let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
 | 
					    let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, Object.assign({ ignoreReturnCode: true }, (cwd !== null && { cwd })));
 | 
				
			||||||
    if (exitCode) {
 | 
					    if (exitCode) {
 | 
				
			||||||
        stderr = !stderr.trim()
 | 
					        stderr = !stderr.trim()
 | 
				
			||||||
            ? `The '${toolCommand}' command failed with exit code: ${exitCode}`
 | 
					            ? `The '${toolCommand}' command failed with exit code: ${exitCode}`
 | 
				
			||||||
@@ -71246,8 +71250,20 @@ const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, func
 | 
				
			|||||||
    return stdout.trim();
 | 
					    return stdout.trim();
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
exports.getCommandOutput = getCommandOutput;
 | 
					exports.getCommandOutput = getCommandOutput;
 | 
				
			||||||
 | 
					const getPackageManagerWorkingDir = () => {
 | 
				
			||||||
 | 
					    const projectDir = core.getInput('project-dir');
 | 
				
			||||||
 | 
					    if (projectDir) {
 | 
				
			||||||
 | 
					        return projectDir;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const cache = core.getInput('cache');
 | 
				
			||||||
 | 
					    if (cache !== 'yarn') {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const cacheDependencyPath = core.getInput('cache-dependency-path');
 | 
				
			||||||
 | 
					    return cacheDependencyPath ? path_1.default.dirname(cacheDependencyPath) : null;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
const getPackageManagerVersion = (packageManager, command) => __awaiter(void 0, void 0, void 0, function* () {
 | 
					const getPackageManagerVersion = (packageManager, command) => __awaiter(void 0, void 0, void 0, function* () {
 | 
				
			||||||
    const stdOut = yield exports.getCommandOutput(`${packageManager} ${command}`);
 | 
					    const stdOut = yield exports.getCommandOutput(`${packageManager} ${command}`, getPackageManagerWorkingDir());
 | 
				
			||||||
    if (!stdOut) {
 | 
					    if (!stdOut) {
 | 
				
			||||||
        throw new Error(`Could not retrieve version of ${packageManager}`);
 | 
					        throw new Error(`Could not retrieve version of ${packageManager}`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -71276,7 +71292,7 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
exports.getPackageManagerInfo = getPackageManagerInfo;
 | 
					exports.getPackageManagerInfo = getPackageManagerInfo;
 | 
				
			||||||
const getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaiter(void 0, void 0, void 0, function* () {
 | 
					const getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaiter(void 0, void 0, void 0, function* () {
 | 
				
			||||||
    const stdOut = yield exports.getCommandOutput(packageManagerInfo.getCacheFolderCommand);
 | 
					    const stdOut = yield exports.getCommandOutput(packageManagerInfo.getCacheFolderCommand, getPackageManagerWorkingDir());
 | 
				
			||||||
    if (!stdOut) {
 | 
					    if (!stdOut) {
 | 
				
			||||||
        throw new Error(`Could not get cache folder path for ${packageManager}`);
 | 
					        throw new Error(`Could not get cache folder path for ${packageManager}`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
import * as core from '@actions/core';
 | 
					import * as core from '@actions/core';
 | 
				
			||||||
import * as exec from '@actions/exec';
 | 
					import * as exec from '@actions/exec';
 | 
				
			||||||
import * as cache from '@actions/cache';
 | 
					import * as cache from '@actions/cache';
 | 
				
			||||||
 | 
					import path from 'path';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type SupportedPackageManagers = {
 | 
					type SupportedPackageManagers = {
 | 
				
			||||||
  [prop: string]: PackageManagerInfo;
 | 
					  [prop: string]: PackageManagerInfo;
 | 
				
			||||||
@@ -30,11 +31,14 @@ export const supportedPackageManagers: SupportedPackageManagers = {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const getCommandOutput = async (toolCommand: string) => {
 | 
					export const getCommandOutput = async (
 | 
				
			||||||
 | 
					  toolCommand: string,
 | 
				
			||||||
 | 
					  cwd: string | null
 | 
				
			||||||
 | 
					) => {
 | 
				
			||||||
  let {stdout, stderr, exitCode} = await exec.getExecOutput(
 | 
					  let {stdout, stderr, exitCode} = await exec.getExecOutput(
 | 
				
			||||||
    toolCommand,
 | 
					    toolCommand,
 | 
				
			||||||
    undefined,
 | 
					    undefined,
 | 
				
			||||||
    {ignoreReturnCode: true}
 | 
					    {ignoreReturnCode: true, ...(cwd !== null && {cwd})}
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (exitCode) {
 | 
					  if (exitCode) {
 | 
				
			||||||
@@ -47,11 +51,29 @@ export const getCommandOutput = async (toolCommand: string) => {
 | 
				
			|||||||
  return stdout.trim();
 | 
					  return stdout.trim();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getPackageManagerWorkingDir = (): string | null => {
 | 
				
			||||||
 | 
					  const projectDir = core.getInput('project-dir');
 | 
				
			||||||
 | 
					  if (projectDir) {
 | 
				
			||||||
 | 
					    return projectDir;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const cache = core.getInput('cache');
 | 
				
			||||||
 | 
					  if (cache !== 'yarn') {
 | 
				
			||||||
 | 
					    return null;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const cacheDependencyPath = core.getInput('cache-dependency-path');
 | 
				
			||||||
 | 
					  return cacheDependencyPath ? path.dirname(cacheDependencyPath) : null;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getPackageManagerVersion = async (
 | 
					const getPackageManagerVersion = async (
 | 
				
			||||||
  packageManager: string,
 | 
					  packageManager: string,
 | 
				
			||||||
  command: string
 | 
					  command: string
 | 
				
			||||||
) => {
 | 
					) => {
 | 
				
			||||||
  const stdOut = await getCommandOutput(`${packageManager} ${command}`);
 | 
					  const stdOut = await getCommandOutput(
 | 
				
			||||||
 | 
					    `${packageManager} ${command}`,
 | 
				
			||||||
 | 
					    getPackageManagerWorkingDir()
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!stdOut) {
 | 
					  if (!stdOut) {
 | 
				
			||||||
    throw new Error(`Could not retrieve version of ${packageManager}`);
 | 
					    throw new Error(`Could not retrieve version of ${packageManager}`);
 | 
				
			||||||
@@ -85,7 +107,8 @@ export const getCacheDirectoryPath = async (
 | 
				
			|||||||
  packageManager: string
 | 
					  packageManager: string
 | 
				
			||||||
) => {
 | 
					) => {
 | 
				
			||||||
  const stdOut = await getCommandOutput(
 | 
					  const stdOut = await getCommandOutput(
 | 
				
			||||||
    packageManagerInfo.getCacheFolderCommand
 | 
					    packageManagerInfo.getCacheFolderCommand,
 | 
				
			||||||
 | 
					    getPackageManagerWorkingDir()
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!stdOut) {
 | 
					  if (!stdOut) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user