mirror of
https://github.com/actions/setup-node.git
synced 2025-04-22 09:21:00 +00:00
Changes requests
This commit is contained in:
parent
5de08eab2b
commit
7406bf5e76
4 changed files with 137 additions and 44 deletions
55
dist/cache-save/index.js
vendored
55
dist/cache-save/index.js
vendored
|
@ -60375,7 +60375,7 @@ const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, func
|
||||||
core.debug(`Caching for '${packageManager}' is not supported`);
|
core.debug(`Caching for '${packageManager}' is not supported`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: core.getInput has a bug - it can return undefined despite its definition
|
// TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?)
|
||||||
// export declare function getInput(name: string, options?: InputOptions): string;
|
// export declare function getInput(name: string, options?: InputOptions): string;
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path') || '';
|
const cacheDependencyPath = core.getInput('cache-dependency-path') || '';
|
||||||
const cachePaths = yield cache_utils_1.getCacheDirectoriesPaths(packageManagerInfo, cacheDependencyPath);
|
const cachePaths = yield cache_utils_1.getCacheDirectoriesPaths(packageManagerInfo, cacheDependencyPath);
|
||||||
|
@ -60507,6 +60507,10 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
exports.getPackageManagerInfo = getPackageManagerInfo;
|
exports.getPackageManagerInfo = getPackageManagerInfo;
|
||||||
|
/**
|
||||||
|
* glob expanding memoized because it involves potentially very deep
|
||||||
|
* traversing through the directories tree
|
||||||
|
*/
|
||||||
exports.expandedPatternsMemoized = {};
|
exports.expandedPatternsMemoized = {};
|
||||||
/**
|
/**
|
||||||
* Wrapper around `glob.create(pattern).glob()` with the memoization
|
* Wrapper around `glob.create(pattern).glob()` with the memoization
|
||||||
|
@ -60539,9 +60543,9 @@ const expandCacheDependencyPath = (cacheDependencyPath) => __awaiter(void 0, voi
|
||||||
});
|
});
|
||||||
exports.expandCacheDependencyPath = expandCacheDependencyPath;
|
exports.expandCacheDependencyPath = expandCacheDependencyPath;
|
||||||
/**
|
/**
|
||||||
* Converts dependency file to the directory it resides in and ensures the directory exists
|
* Converts dependency file path to the directory it resides in and ensures the directory exists
|
||||||
* @param cacheDependencyPath - file name
|
* @param cacheDependencyPath - a file name path
|
||||||
* @return either directory containing file or null
|
* @return either directory containing the file or null
|
||||||
*/
|
*/
|
||||||
const cacheDependencyPathToProjectDirectory = (cacheDependencyPath) => {
|
const cacheDependencyPathToProjectDirectory = (cacheDependencyPath) => {
|
||||||
const projectDirectory = path_1.default.dirname(cacheDependencyPath);
|
const projectDirectory = path_1.default.dirname(cacheDependencyPath);
|
||||||
|
@ -60558,7 +60562,8 @@ const cacheDependencyPathToProjectDirectory = (cacheDependencyPath) => {
|
||||||
/**
|
/**
|
||||||
* Expands (converts) the string input `cache-dependency-path` to list of directories that
|
* Expands (converts) the string input `cache-dependency-path` to list of directories that
|
||||||
* may be project roots
|
* may be project roots
|
||||||
* @param cacheDependencyPath
|
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
|
||||||
|
* expected to be the result of `core.getInput('cache-dependency-path')`
|
||||||
* @return list of directories and possible
|
* @return list of directories and possible
|
||||||
*/
|
*/
|
||||||
const cacheDependencyPathToProjectsDirectories = (cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
const cacheDependencyPathToProjectsDirectories = (cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
@ -60566,29 +60571,57 @@ const cacheDependencyPathToProjectsDirectories = (cacheDependencyPath) => __awai
|
||||||
const existingDirectories = cacheDependenciesPaths
|
const existingDirectories = cacheDependenciesPaths
|
||||||
.map(cacheDependencyPath => cacheDependencyPathToProjectDirectory(cacheDependencyPath))
|
.map(cacheDependencyPath => cacheDependencyPathToProjectDirectory(cacheDependencyPath))
|
||||||
.filter(path => path !== null);
|
.filter(path => path !== null);
|
||||||
|
// if user explicitly pointed out some file, but it does not exist it is definitely
|
||||||
|
// not he wanted, thus we should throw an error not trying to workaround with unexpected
|
||||||
|
// result to the whole build
|
||||||
if (existingDirectories.length === 0)
|
if (existingDirectories.length === 0)
|
||||||
throw Error('No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"');
|
throw Error('No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"');
|
||||||
// uniq
|
// uniq in order to do not traverse the same directories during the further processing
|
||||||
return existingDirectories.filter((cachePath, i, result) => cachePath != null && result.indexOf(cachePath) === i);
|
return existingDirectories.filter((cachePath, i, result) => cachePath != null && result.indexOf(cachePath) === i);
|
||||||
});
|
});
|
||||||
|
/**
|
||||||
|
* Utility function to be used from within `map`
|
||||||
|
* Finds the cache directories configured for the project directory
|
||||||
|
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
|
||||||
|
* @param projectDirectory - the string pointing out to a project dir (i.e. directory with its own .yarnrc)
|
||||||
|
* @return list of directories to be cached according to the project configuration in the directory
|
||||||
|
*/
|
||||||
const projectDirectoryToCacheFolderPath = (packageManagerInfo, projectDirectory) => __awaiter(void 0, void 0, void 0, function* () {
|
const projectDirectoryToCacheFolderPath = (packageManagerInfo, projectDirectory) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath(projectDirectory);
|
const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath(projectDirectory);
|
||||||
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`);
|
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`);
|
||||||
return cacheFolderPath;
|
return cacheFolderPath;
|
||||||
});
|
});
|
||||||
const projectDirectoriesToCacheFoldersPaths = (packageManagerInfo, projectDirectories) => __awaiter(void 0, void 0, void 0, function* () {
|
/**
|
||||||
const cacheFoldersPaths = yield Promise.all(projectDirectories.map(projectDirectory => projectDirectoryToCacheFolderPath(packageManagerInfo, projectDirectory)));
|
* Top-entry function to find the cache directories configured for the repo if cache-dependency-path is not empty
|
||||||
return cacheFoldersPaths.filter((cachePath, i, result) => result.indexOf(cachePath) === i);
|
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
|
||||||
});
|
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
|
||||||
|
* expected to be the result of `core.getInput('cache-dependency-path')`
|
||||||
|
* @return list of files on which the cache depends
|
||||||
|
*/
|
||||||
const cacheDependencyPathToCacheFoldersPaths = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
const cacheDependencyPathToCacheFoldersPaths = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const projectDirectories = yield cacheDependencyPathToProjectsDirectories(cacheDependencyPath);
|
const projectDirectories = yield cacheDependencyPathToProjectsDirectories(cacheDependencyPath);
|
||||||
return projectDirectoriesToCacheFoldersPaths(packageManagerInfo, projectDirectories);
|
const cacheFoldersPaths = yield Promise.all(projectDirectories.map(projectDirectory => projectDirectoryToCacheFolderPath(packageManagerInfo, projectDirectory)));
|
||||||
|
// uniq in order to do not cache the same directories twice
|
||||||
|
return cacheFoldersPaths.filter((cachePath, i, result) => result.indexOf(cachePath) === i);
|
||||||
});
|
});
|
||||||
|
/**
|
||||||
|
* Top-entry function to find the cache directories configured for the repo if cache-dependency-path is empty
|
||||||
|
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
|
||||||
|
* @return list of files on which the cache depends
|
||||||
|
*/
|
||||||
const cacheFoldersPathsForRoot = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
const cacheFoldersPathsForRoot = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath();
|
const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath();
|
||||||
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the root directory`);
|
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the root directory`);
|
||||||
return [cacheFolderPath];
|
return [cacheFolderPath];
|
||||||
});
|
});
|
||||||
|
/**
|
||||||
|
* Main function to find the cache directories configured for the repo
|
||||||
|
* currently it handles only the case of PM=yarn && cacheDependencyPath is not empty
|
||||||
|
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
|
||||||
|
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
|
||||||
|
* expected to be the result of `core.getInput('cache-dependency-path')`
|
||||||
|
* @return list of files on which the cache depends
|
||||||
|
*/
|
||||||
const getCacheDirectoriesPaths = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
const getCacheDirectoriesPaths = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
// TODO: multiple directories limited to yarn so far
|
// TODO: multiple directories limited to yarn so far
|
||||||
return packageManagerInfo === exports.supportedPackageManagers.yarn
|
return packageManagerInfo === exports.supportedPackageManagers.yarn
|
||||||
|
|
53
dist/setup/index.js
vendored
53
dist/setup/index.js
vendored
|
@ -71289,6 +71289,10 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
exports.getPackageManagerInfo = getPackageManagerInfo;
|
exports.getPackageManagerInfo = getPackageManagerInfo;
|
||||||
|
/**
|
||||||
|
* glob expanding memoized because it involves potentially very deep
|
||||||
|
* traversing through the directories tree
|
||||||
|
*/
|
||||||
exports.expandedPatternsMemoized = {};
|
exports.expandedPatternsMemoized = {};
|
||||||
/**
|
/**
|
||||||
* Wrapper around `glob.create(pattern).glob()` with the memoization
|
* Wrapper around `glob.create(pattern).glob()` with the memoization
|
||||||
|
@ -71321,9 +71325,9 @@ const expandCacheDependencyPath = (cacheDependencyPath) => __awaiter(void 0, voi
|
||||||
});
|
});
|
||||||
exports.expandCacheDependencyPath = expandCacheDependencyPath;
|
exports.expandCacheDependencyPath = expandCacheDependencyPath;
|
||||||
/**
|
/**
|
||||||
* Converts dependency file to the directory it resides in and ensures the directory exists
|
* Converts dependency file path to the directory it resides in and ensures the directory exists
|
||||||
* @param cacheDependencyPath - file name
|
* @param cacheDependencyPath - a file name path
|
||||||
* @return either directory containing file or null
|
* @return either directory containing the file or null
|
||||||
*/
|
*/
|
||||||
const cacheDependencyPathToProjectDirectory = (cacheDependencyPath) => {
|
const cacheDependencyPathToProjectDirectory = (cacheDependencyPath) => {
|
||||||
const projectDirectory = path_1.default.dirname(cacheDependencyPath);
|
const projectDirectory = path_1.default.dirname(cacheDependencyPath);
|
||||||
|
@ -71340,7 +71344,8 @@ const cacheDependencyPathToProjectDirectory = (cacheDependencyPath) => {
|
||||||
/**
|
/**
|
||||||
* Expands (converts) the string input `cache-dependency-path` to list of directories that
|
* Expands (converts) the string input `cache-dependency-path` to list of directories that
|
||||||
* may be project roots
|
* may be project roots
|
||||||
* @param cacheDependencyPath
|
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
|
||||||
|
* expected to be the result of `core.getInput('cache-dependency-path')`
|
||||||
* @return list of directories and possible
|
* @return list of directories and possible
|
||||||
*/
|
*/
|
||||||
const cacheDependencyPathToProjectsDirectories = (cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
const cacheDependencyPathToProjectsDirectories = (cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
@ -71348,29 +71353,57 @@ const cacheDependencyPathToProjectsDirectories = (cacheDependencyPath) => __awai
|
||||||
const existingDirectories = cacheDependenciesPaths
|
const existingDirectories = cacheDependenciesPaths
|
||||||
.map(cacheDependencyPath => cacheDependencyPathToProjectDirectory(cacheDependencyPath))
|
.map(cacheDependencyPath => cacheDependencyPathToProjectDirectory(cacheDependencyPath))
|
||||||
.filter(path => path !== null);
|
.filter(path => path !== null);
|
||||||
|
// if user explicitly pointed out some file, but it does not exist it is definitely
|
||||||
|
// not he wanted, thus we should throw an error not trying to workaround with unexpected
|
||||||
|
// result to the whole build
|
||||||
if (existingDirectories.length === 0)
|
if (existingDirectories.length === 0)
|
||||||
throw Error('No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"');
|
throw Error('No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"');
|
||||||
// uniq
|
// uniq in order to do not traverse the same directories during the further processing
|
||||||
return existingDirectories.filter((cachePath, i, result) => cachePath != null && result.indexOf(cachePath) === i);
|
return existingDirectories.filter((cachePath, i, result) => cachePath != null && result.indexOf(cachePath) === i);
|
||||||
});
|
});
|
||||||
|
/**
|
||||||
|
* Utility function to be used from within `map`
|
||||||
|
* Finds the cache directories configured for the project directory
|
||||||
|
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
|
||||||
|
* @param projectDirectory - the string pointing out to a project dir (i.e. directory with its own .yarnrc)
|
||||||
|
* @return list of directories to be cached according to the project configuration in the directory
|
||||||
|
*/
|
||||||
const projectDirectoryToCacheFolderPath = (packageManagerInfo, projectDirectory) => __awaiter(void 0, void 0, void 0, function* () {
|
const projectDirectoryToCacheFolderPath = (packageManagerInfo, projectDirectory) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath(projectDirectory);
|
const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath(projectDirectory);
|
||||||
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`);
|
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`);
|
||||||
return cacheFolderPath;
|
return cacheFolderPath;
|
||||||
});
|
});
|
||||||
const projectDirectoriesToCacheFoldersPaths = (packageManagerInfo, projectDirectories) => __awaiter(void 0, void 0, void 0, function* () {
|
/**
|
||||||
const cacheFoldersPaths = yield Promise.all(projectDirectories.map(projectDirectory => projectDirectoryToCacheFolderPath(packageManagerInfo, projectDirectory)));
|
* Top-entry function to find the cache directories configured for the repo if cache-dependency-path is not empty
|
||||||
return cacheFoldersPaths.filter((cachePath, i, result) => result.indexOf(cachePath) === i);
|
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
|
||||||
});
|
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
|
||||||
|
* expected to be the result of `core.getInput('cache-dependency-path')`
|
||||||
|
* @return list of files on which the cache depends
|
||||||
|
*/
|
||||||
const cacheDependencyPathToCacheFoldersPaths = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
const cacheDependencyPathToCacheFoldersPaths = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const projectDirectories = yield cacheDependencyPathToProjectsDirectories(cacheDependencyPath);
|
const projectDirectories = yield cacheDependencyPathToProjectsDirectories(cacheDependencyPath);
|
||||||
return projectDirectoriesToCacheFoldersPaths(packageManagerInfo, projectDirectories);
|
const cacheFoldersPaths = yield Promise.all(projectDirectories.map(projectDirectory => projectDirectoryToCacheFolderPath(packageManagerInfo, projectDirectory)));
|
||||||
|
// uniq in order to do not cache the same directories twice
|
||||||
|
return cacheFoldersPaths.filter((cachePath, i, result) => result.indexOf(cachePath) === i);
|
||||||
});
|
});
|
||||||
|
/**
|
||||||
|
* Top-entry function to find the cache directories configured for the repo if cache-dependency-path is empty
|
||||||
|
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
|
||||||
|
* @return list of files on which the cache depends
|
||||||
|
*/
|
||||||
const cacheFoldersPathsForRoot = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
const cacheFoldersPathsForRoot = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath();
|
const cacheFolderPath = yield packageManagerInfo.getCacheFolderPath();
|
||||||
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the root directory`);
|
core.debug(`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the root directory`);
|
||||||
return [cacheFolderPath];
|
return [cacheFolderPath];
|
||||||
});
|
});
|
||||||
|
/**
|
||||||
|
* Main function to find the cache directories configured for the repo
|
||||||
|
* currently it handles only the case of PM=yarn && cacheDependencyPath is not empty
|
||||||
|
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
|
||||||
|
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
|
||||||
|
* expected to be the result of `core.getInput('cache-dependency-path')`
|
||||||
|
* @return list of files on which the cache depends
|
||||||
|
*/
|
||||||
const getCacheDirectoriesPaths = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
const getCacheDirectoriesPaths = (packageManagerInfo, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
// TODO: multiple directories limited to yarn so far
|
// TODO: multiple directories limited to yarn so far
|
||||||
return packageManagerInfo === exports.supportedPackageManagers.yarn
|
return packageManagerInfo === exports.supportedPackageManagers.yarn
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import fs from 'fs';
|
|
||||||
import {State} from './constants';
|
import {State} from './constants';
|
||||||
import {getCacheDirectoriesPaths, getPackageManagerInfo} from './cache-utils';
|
import {getCacheDirectoriesPaths, getPackageManagerInfo} from './cache-utils';
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ const cachePackages = async (packageManager: string) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: core.getInput has a bug - it can return undefined despite its definition
|
// TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?)
|
||||||
// export declare function getInput(name: string, options?: InputOptions): string;
|
// export declare function getInput(name: string, options?: InputOptions): string;
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path') || '';
|
const cacheDependencyPath = core.getInput('cache-dependency-path') || '';
|
||||||
const cachePaths = await getCacheDirectoriesPaths(
|
const cachePaths = await getCacheDirectoriesPaths(
|
||||||
|
|
|
@ -112,6 +112,11 @@ export const getPackageManagerInfo = async (packageManager: string) => {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* glob expanding memoized because it involves potentially very deep
|
||||||
|
* traversing through the directories tree
|
||||||
|
*/
|
||||||
export const expandedPatternsMemoized: Record<string, string[]> = {};
|
export const expandedPatternsMemoized: Record<string, string[]> = {};
|
||||||
/**
|
/**
|
||||||
* Wrapper around `glob.create(pattern).glob()` with the memoization
|
* Wrapper around `glob.create(pattern).glob()` with the memoization
|
||||||
|
@ -148,9 +153,9 @@ export const expandCacheDependencyPath = async (
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts dependency file to the directory it resides in and ensures the directory exists
|
* Converts dependency file path to the directory it resides in and ensures the directory exists
|
||||||
* @param cacheDependencyPath - file name
|
* @param cacheDependencyPath - a file name path
|
||||||
* @return either directory containing file or null
|
* @return either directory containing the file or null
|
||||||
*/
|
*/
|
||||||
const cacheDependencyPathToProjectDirectory = (
|
const cacheDependencyPathToProjectDirectory = (
|
||||||
cacheDependencyPath: string
|
cacheDependencyPath: string
|
||||||
|
@ -175,7 +180,8 @@ const cacheDependencyPathToProjectDirectory = (
|
||||||
/**
|
/**
|
||||||
* Expands (converts) the string input `cache-dependency-path` to list of directories that
|
* Expands (converts) the string input `cache-dependency-path` to list of directories that
|
||||||
* may be project roots
|
* may be project roots
|
||||||
* @param cacheDependencyPath
|
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
|
||||||
|
* expected to be the result of `core.getInput('cache-dependency-path')`
|
||||||
* @return list of directories and possible
|
* @return list of directories and possible
|
||||||
*/
|
*/
|
||||||
const cacheDependencyPathToProjectsDirectories = async (
|
const cacheDependencyPathToProjectsDirectories = async (
|
||||||
|
@ -191,18 +197,28 @@ const cacheDependencyPathToProjectsDirectories = async (
|
||||||
)
|
)
|
||||||
.filter(path => path !== null) as string[];
|
.filter(path => path !== null) as string[];
|
||||||
|
|
||||||
|
// if user explicitly pointed out some file, but it does not exist it is definitely
|
||||||
|
// not he wanted, thus we should throw an error not trying to workaround with unexpected
|
||||||
|
// result to the whole build
|
||||||
if (existingDirectories.length === 0)
|
if (existingDirectories.length === 0)
|
||||||
throw Error(
|
throw Error(
|
||||||
'No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"'
|
'No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"'
|
||||||
);
|
);
|
||||||
|
|
||||||
// uniq
|
// uniq in order to do not traverse the same directories during the further processing
|
||||||
return existingDirectories.filter(
|
return existingDirectories.filter(
|
||||||
(cachePath, i, result) =>
|
(cachePath, i, result) =>
|
||||||
cachePath != null && result.indexOf(cachePath) === i
|
cachePath != null && result.indexOf(cachePath) === i
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility function to be used from within `map`
|
||||||
|
* Finds the cache directories configured for the project directory
|
||||||
|
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
|
||||||
|
* @param projectDirectory - the string pointing out to a project dir (i.e. directory with its own .yarnrc)
|
||||||
|
* @return list of directories to be cached according to the project configuration in the directory
|
||||||
|
*/
|
||||||
const projectDirectoryToCacheFolderPath = async (
|
const projectDirectoryToCacheFolderPath = async (
|
||||||
packageManagerInfo: PackageManagerInfo,
|
packageManagerInfo: PackageManagerInfo,
|
||||||
projectDirectory: string
|
projectDirectory: string
|
||||||
|
@ -216,19 +232,13 @@ const projectDirectoryToCacheFolderPath = async (
|
||||||
return cacheFolderPath;
|
return cacheFolderPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
const projectDirectoriesToCacheFoldersPaths = async (
|
/**
|
||||||
packageManagerInfo: PackageManagerInfo,
|
* Top-entry function to find the cache directories configured for the repo if cache-dependency-path is not empty
|
||||||
projectDirectories: string[]
|
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
|
||||||
): Promise<string[]> => {
|
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
|
||||||
const cacheFoldersPaths = await Promise.all(
|
* expected to be the result of `core.getInput('cache-dependency-path')`
|
||||||
projectDirectories.map(projectDirectory =>
|
* @return list of files on which the cache depends
|
||||||
projectDirectoryToCacheFolderPath(packageManagerInfo, projectDirectory)
|
*/
|
||||||
)
|
|
||||||
);
|
|
||||||
return cacheFoldersPaths.filter(
|
|
||||||
(cachePath, i, result) => result.indexOf(cachePath) === i
|
|
||||||
);
|
|
||||||
};
|
|
||||||
const cacheDependencyPathToCacheFoldersPaths = async (
|
const cacheDependencyPathToCacheFoldersPaths = async (
|
||||||
packageManagerInfo: PackageManagerInfo,
|
packageManagerInfo: PackageManagerInfo,
|
||||||
cacheDependencyPath: string
|
cacheDependencyPath: string
|
||||||
|
@ -236,12 +246,22 @@ const cacheDependencyPathToCacheFoldersPaths = async (
|
||||||
const projectDirectories = await cacheDependencyPathToProjectsDirectories(
|
const projectDirectories = await cacheDependencyPathToProjectsDirectories(
|
||||||
cacheDependencyPath
|
cacheDependencyPath
|
||||||
);
|
);
|
||||||
return projectDirectoriesToCacheFoldersPaths(
|
const cacheFoldersPaths = await Promise.all(
|
||||||
packageManagerInfo,
|
projectDirectories.map(projectDirectory =>
|
||||||
projectDirectories
|
projectDirectoryToCacheFolderPath(packageManagerInfo, projectDirectory)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
// uniq in order to do not cache the same directories twice
|
||||||
|
return cacheFoldersPaths.filter(
|
||||||
|
(cachePath, i, result) => result.indexOf(cachePath) === i
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Top-entry function to find the cache directories configured for the repo if cache-dependency-path is empty
|
||||||
|
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
|
||||||
|
* @return list of files on which the cache depends
|
||||||
|
*/
|
||||||
const cacheFoldersPathsForRoot = async (
|
const cacheFoldersPathsForRoot = async (
|
||||||
packageManagerInfo: PackageManagerInfo
|
packageManagerInfo: PackageManagerInfo
|
||||||
): Promise<string[]> => {
|
): Promise<string[]> => {
|
||||||
|
@ -252,6 +272,14 @@ const cacheFoldersPathsForRoot = async (
|
||||||
return [cacheFolderPath];
|
return [cacheFolderPath];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main function to find the cache directories configured for the repo
|
||||||
|
* currently it handles only the case of PM=yarn && cacheDependencyPath is not empty
|
||||||
|
* @param packageManagerInfo - an object having getCacheFolderPath method specific to given PM
|
||||||
|
* @param cacheDependencyPath - either a single string or multiline string with possible glob patterns
|
||||||
|
* expected to be the result of `core.getInput('cache-dependency-path')`
|
||||||
|
* @return list of files on which the cache depends
|
||||||
|
*/
|
||||||
export const getCacheDirectoriesPaths = async (
|
export const getCacheDirectoriesPaths = async (
|
||||||
packageManagerInfo: PackageManagerInfo,
|
packageManagerInfo: PackageManagerInfo,
|
||||||
cacheDependencyPath: string
|
cacheDependencyPath: string
|
||||||
|
|
Loading…
Add table
Reference in a new issue