Skip to content

Commit 3ef5272

Browse files
committed
review updates second stage
1 parent 6aacde7 commit 3ef5272

File tree

6 files changed

+25
-83
lines changed

6 files changed

+25
-83
lines changed

__tests__/cache-restore.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('cache-restore', () => {
135135
await restoreCache(packageManager, '');
136136
expect(hashFilesSpy).toHaveBeenCalled();
137137
expect(infoSpy).toHaveBeenCalledWith(
138-
`Cache restored from key: node-cache-${platform}-${packageManager}-v2-${fileHash}`
138+
`Cache restored from key: node-cache-${platform}-${packageManager}-${fileHash}`
139139
);
140140
expect(infoSpy).not.toHaveBeenCalledWith(
141141
`${packageManager} cache is not found`

__tests__/cache-utils.test.ts

+10-17
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import {
66
PackageManagerInfo,
77
isCacheFeatureAvailable,
88
supportedPackageManagers,
9-
getCommandOutput,
10-
memoizedCacheDependencies
9+
getCommandOutput
1110
} from '../src/cache-utils';
1211
import fs from 'fs';
1312
import * as cacheUtils from '../src/cache-utils';
@@ -104,10 +103,6 @@ describe('cache-utils', () => {
104103
(pattern: string): Promise<Globber> =>
105104
MockGlobber.create(['/foo', '/bar'])
106105
);
107-
108-
Object.keys(memoizedCacheDependencies).forEach(
109-
key => delete memoizedCacheDependencies[key]
110-
);
111106
});
112107

113108
afterEach(() => {
@@ -175,25 +170,23 @@ describe('cache-utils', () => {
175170
);
176171

177172
it.each([
178-
[supportedPackageManagers.npm, ''],
179-
[supportedPackageManagers.npm, '/dir/file.lock'],
180-
[supportedPackageManagers.npm, '/**/file.lock'],
181-
[supportedPackageManagers.pnpm, ''],
182-
[supportedPackageManagers.pnpm, '/dir/file.lock'],
183-
[supportedPackageManagers.pnpm, '/**/file.lock'],
184-
[supportedPackageManagers.yarn, ''],
185173
[supportedPackageManagers.yarn, '/dir/file.lock'],
186174
[supportedPackageManagers.yarn, '/**/file.lock']
187175
])(
188-
'getCacheDirectoriesPaths should throw in case of having not directories',
176+
'getCacheDirectoriesPaths should nothrow in case of having not directories',
189177
async (packageManagerInfo, cacheDependency) => {
190178
lstatSpy.mockImplementation(arg => ({
191179
isDirectory: () => false
192180
}));
193181

194-
await expect(
195-
cacheUtils.getCacheDirectories(packageManagerInfo, cacheDependency)
196-
).rejects.toThrow(); //'Could not get cache folder path for /dir');
182+
await cacheUtils.getCacheDirectories(
183+
packageManagerInfo,
184+
cacheDependency
185+
);
186+
expect(warningSpy).toHaveBeenCalledTimes(1);
187+
expect(warningSpy).toHaveBeenCalledWith(
188+
`No existing directories found containing cache-dependency-path="${cacheDependency}"`
189+
);
197190
}
198191
);
199192

dist/cache-save/index.js

+4-21
Original file line numberDiff line numberDiff line change
@@ -60434,7 +60434,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6043460434
return (mod && mod.__esModule) ? mod : { "default": mod };
6043560435
};
6043660436
Object.defineProperty(exports, "__esModule", ({ value: true }));
60437-
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectories = exports.memoizedCacheDependencies = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
60437+
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectories = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
6043860438
const core = __importStar(__nccwpck_require__(2186));
6043960439
const exec = __importStar(__nccwpck_require__(1514));
6044060440
const cache = __importStar(__nccwpck_require__(7799));
@@ -60503,11 +60503,6 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
6050360503
}
6050460504
});
6050560505
exports.getPackageManagerInfo = getPackageManagerInfo;
60506-
/**
60507-
* glob expanding memoized because it involves potentially very deep
60508-
* traversing through the directories tree
60509-
*/
60510-
exports.memoizedCacheDependencies = {};
6051160506
/**
6051260507
* Expands (converts) the string input `cache-dependency-path` to list of directories that
6051360508
* may be project roots
@@ -60516,27 +60511,15 @@ exports.memoizedCacheDependencies = {};
6051660511
* @return list of directories and possible
6051760512
*/
6051860513
const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
60519-
let cacheDependenciesPaths;
60520-
// memoize unglobbed paths to avoid traversing FS
60521-
const memoized = exports.memoizedCacheDependencies[cacheDependencyPath];
60522-
if (memoized) {
60523-
cacheDependenciesPaths = memoized;
60524-
}
60525-
else {
60526-
const globber = yield glob.create(cacheDependencyPath);
60527-
cacheDependenciesPaths = yield globber.glob();
60528-
exports.memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths;
60529-
}
60514+
const globber = yield glob.create(cacheDependencyPath);
60515+
const cacheDependenciesPaths = yield globber.glob();
6053060516
const existingDirectories = cacheDependenciesPaths
6053160517
.map(path_1.default.dirname)
6053260518
.filter(util_1.unique())
6053360519
.filter(fs_1.default.existsSync)
6053460520
.filter(directory => fs_1.default.lstatSync(directory).isDirectory());
60535-
// if user explicitly pointed out some file, but it does not exist it is definitely
60536-
// not he wanted, thus we should throw an error not trying to workaround with unexpected
60537-
// result to the whole build
6053860521
if (!existingDirectories.length)
60539-
throw Error('No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"');
60522+
core.warning(`No existing directories found containing cache-dependency-path="${cacheDependencyPath}"`);
6054060523
return existingDirectories;
6054160524
});
6054260525
/**

dist/setup/index.js

+5-22
Original file line numberDiff line numberDiff line change
@@ -71153,7 +71153,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
7115371153
if (!fileHash) {
7115471154
throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
7115571155
}
71156-
const primaryKey = `node-cache-${platform}-${packageManager}-v2-${fileHash}`;
71156+
const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`;
7115771157
core.debug(`primary key is ${primaryKey}`);
7115871158
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
7115971159
const cacheKey = yield cache.restoreCache(cachePaths, primaryKey);
@@ -71217,7 +71217,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7121771217
return (mod && mod.__esModule) ? mod : { "default": mod };
7121871218
};
7121971219
Object.defineProperty(exports, "__esModule", ({ value: true }));
71220-
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectories = exports.memoizedCacheDependencies = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
71220+
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectories = exports.getPackageManagerInfo = exports.getCommandOutputNotEmpty = exports.getCommandOutput = exports.supportedPackageManagers = void 0;
7122171221
const core = __importStar(__nccwpck_require__(2186));
7122271222
const exec = __importStar(__nccwpck_require__(1514));
7122371223
const cache = __importStar(__nccwpck_require__(7799));
@@ -71286,11 +71286,6 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
7128671286
}
7128771287
});
7128871288
exports.getPackageManagerInfo = getPackageManagerInfo;
71289-
/**
71290-
* glob expanding memoized because it involves potentially very deep
71291-
* traversing through the directories tree
71292-
*/
71293-
exports.memoizedCacheDependencies = {};
7129471289
/**
7129571290
* Expands (converts) the string input `cache-dependency-path` to list of directories that
7129671291
* may be project roots
@@ -71299,27 +71294,15 @@ exports.memoizedCacheDependencies = {};
7129971294
* @return list of directories and possible
7130071295
*/
7130171296
const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
71302-
let cacheDependenciesPaths;
71303-
// memoize unglobbed paths to avoid traversing FS
71304-
const memoized = exports.memoizedCacheDependencies[cacheDependencyPath];
71305-
if (memoized) {
71306-
cacheDependenciesPaths = memoized;
71307-
}
71308-
else {
71309-
const globber = yield glob.create(cacheDependencyPath);
71310-
cacheDependenciesPaths = yield globber.glob();
71311-
exports.memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths;
71312-
}
71297+
const globber = yield glob.create(cacheDependencyPath);
71298+
const cacheDependenciesPaths = yield globber.glob();
7131371299
const existingDirectories = cacheDependenciesPaths
7131471300
.map(path_1.default.dirname)
7131571301
.filter(util_1.unique())
7131671302
.filter(fs_1.default.existsSync)
7131771303
.filter(directory => fs_1.default.lstatSync(directory).isDirectory());
71318-
// if user explicitly pointed out some file, but it does not exist it is definitely
71319-
// not he wanted, thus we should throw an error not trying to workaround with unexpected
71320-
// result to the whole build
7132171304
if (!existingDirectories.length)
71322-
throw Error('No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"');
71305+
core.warning(`No existing directories found containing cache-dependency-path="${cacheDependencyPath}"`);
7132371306
return existingDirectories;
7132471307
});
7132571308
/**

src/cache-restore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const restoreCache = async (
3737
);
3838
}
3939

40-
const primaryKey = `node-cache-${platform}-${packageManager}-v2-${fileHash}`;
40+
const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`;
4141
core.debug(`primary key is ${primaryKey}`);
4242

4343
core.saveState(State.CachePrimaryKey, primaryKey);

src/cache-utils.ts

+4-21
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ export const getPackageManagerInfo = async (packageManager: string) => {
110110
}
111111
};
112112

113-
/**
114-
* glob expanding memoized because it involves potentially very deep
115-
* traversing through the directories tree
116-
*/
117-
export const memoizedCacheDependencies: Record<string, string[]> = {};
118113
/**
119114
* Expands (converts) the string input `cache-dependency-path` to list of directories that
120115
* may be project roots
@@ -125,30 +120,18 @@ export const memoizedCacheDependencies: Record<string, string[]> = {};
125120
const getProjectDirectoriesFromCacheDependencyPath = async (
126121
cacheDependencyPath: string
127122
): Promise<string[]> => {
128-
let cacheDependenciesPaths: string[];
129-
130-
// memoize unglobbed paths to avoid traversing FS
131-
const memoized = memoizedCacheDependencies[cacheDependencyPath];
132-
if (memoized) {
133-
cacheDependenciesPaths = memoized;
134-
} else {
135-
const globber = await glob.create(cacheDependencyPath);
136-
cacheDependenciesPaths = await globber.glob();
137-
memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths;
138-
}
123+
const globber = await glob.create(cacheDependencyPath);
124+
const cacheDependenciesPaths = await globber.glob();
139125

140126
const existingDirectories: string[] = cacheDependenciesPaths
141127
.map(path.dirname)
142128
.filter(unique())
143129
.filter(fs.existsSync)
144130
.filter(directory => fs.lstatSync(directory).isDirectory());
145131

146-
// if user explicitly pointed out some file, but it does not exist it is definitely
147-
// not he wanted, thus we should throw an error not trying to workaround with unexpected
148-
// result to the whole build
149132
if (!existingDirectories.length)
150-
throw Error(
151-
'No existing directories found containing `cache-dependency-path`="${cacheDependencyPath}"'
133+
core.warning(
134+
`No existing directories found containing cache-dependency-path="${cacheDependencyPath}"`
152135
);
153136

154137
return existingDirectories;

0 commit comments

Comments
 (0)