Skip to content

Commit 001e87e

Browse files
committed
Add unique
1 parent 885f6b5 commit 001e87e

File tree

4 files changed

+146
-22
lines changed

4 files changed

+146
-22
lines changed

dist/cache-save/index.js

Lines changed: 114 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60441,6 +60441,7 @@ const cache = __importStar(__nccwpck_require__(7799));
6044160441
const glob = __importStar(__nccwpck_require__(8090));
6044260442
const path_1 = __importDefault(__nccwpck_require__(1017));
6044360443
const fs_1 = __importDefault(__nccwpck_require__(7147));
60444+
const util_1 = __nccwpck_require__(2629);
6044460445
exports.supportedPackageManagers = {
6044560446
npm: {
6044660447
name: 'npm',
@@ -60526,11 +60527,7 @@ const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __
6052660527
cacheDependenciesPaths = (yield globber.glob()) || [''];
6052760528
exports.memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths;
6052860529
}
60529-
const existingDirectories = cacheDependenciesPaths
60530-
.map(path_1.default.dirname)
60531-
// uniq in order to do not traverse the same directories during the further processing
60532-
.filter((item, i, src) => item != null && src.indexOf(item) === i)
60533-
.filter(directory => fs_1.default.existsSync(directory) && fs_1.default.lstatSync(directory).isDirectory());
60530+
const existingDirectories = util_1.arrayUniqNotNull(cacheDependenciesPaths.map(path_1.default.dirname)).filter(directory => fs_1.default.existsSync(directory) && fs_1.default.lstatSync(directory).isDirectory());
6053460531
// if user explicitly pointed out some file, but it does not exist it is definitely
6053560532
// not he wanted, thus we should throw an error not trying to workaround with unexpected
6053660533
// result to the whole build
@@ -60554,7 +60551,7 @@ const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDep
6055460551
return cacheFolderPath;
6055560552
})));
6055660553
// uniq in order to do not cache the same directories twice
60557-
return cacheFoldersPaths.filter((item, i, src) => src.indexOf(item) === i);
60554+
return util_1.arrayUniq(cacheFoldersPaths);
6055860555
});
6055960556
/**
6056060557
* Finds the cache directories configured for the repo ignoring cache-dependency-path
@@ -60627,6 +60624,117 @@ var Outputs;
6062760624
})(Outputs = exports.Outputs || (exports.Outputs = {}));
6062860625

6062960626

60627+
/***/ }),
60628+
60629+
/***/ 2629:
60630+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
60631+
60632+
"use strict";
60633+
60634+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
60635+
if (k2 === undefined) k2 = k;
60636+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
60637+
}) : (function(o, m, k, k2) {
60638+
if (k2 === undefined) k2 = k;
60639+
o[k2] = m[k];
60640+
}));
60641+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
60642+
Object.defineProperty(o, "default", { enumerable: true, value: v });
60643+
}) : function(o, v) {
60644+
o["default"] = v;
60645+
});
60646+
var __importStar = (this && this.__importStar) || function (mod) {
60647+
if (mod && mod.__esModule) return mod;
60648+
var result = {};
60649+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
60650+
__setModuleDefault(result, mod);
60651+
return result;
60652+
};
60653+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
60654+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
60655+
return new (P || (P = Promise))(function (resolve, reject) {
60656+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
60657+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
60658+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
60659+
step((generator = generator.apply(thisArg, _arguments || [])).next());
60660+
});
60661+
};
60662+
Object.defineProperty(exports, "__esModule", ({ value: true }));
60663+
exports.arrayUniqNotNull = exports.arrayUniq = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
60664+
const core = __importStar(__nccwpck_require__(2186));
60665+
const exec = __importStar(__nccwpck_require__(1514));
60666+
function parseNodeVersionFile(contents) {
60667+
var _a, _b, _c;
60668+
let nodeVersion;
60669+
// Try parsing the file as an NPM `package.json` file.
60670+
try {
60671+
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
60672+
if (!nodeVersion)
60673+
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
60674+
}
60675+
catch (_d) {
60676+
core.info('Node version file is not JSON file');
60677+
}
60678+
if (!nodeVersion) {
60679+
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
60680+
nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version;
60681+
}
60682+
// In the case of an unknown format,
60683+
// return as is and evaluate the version separately.
60684+
if (!nodeVersion)
60685+
nodeVersion = contents.trim();
60686+
return nodeVersion;
60687+
}
60688+
exports.parseNodeVersionFile = parseNodeVersionFile;
60689+
function printEnvDetailsAndSetOutput() {
60690+
return __awaiter(this, void 0, void 0, function* () {
60691+
core.startGroup('Environment details');
60692+
const promises = ['node', 'npm', 'yarn'].map((tool) => __awaiter(this, void 0, void 0, function* () {
60693+
const output = yield getToolVersion(tool, ['--version']);
60694+
return { tool, output };
60695+
}));
60696+
const tools = yield Promise.all(promises);
60697+
tools.forEach(({ tool, output }) => {
60698+
if (tool === 'node') {
60699+
core.setOutput(`${tool}-version`, output);
60700+
}
60701+
core.info(`${tool}: ${output}`);
60702+
});
60703+
core.endGroup();
60704+
});
60705+
}
60706+
exports.printEnvDetailsAndSetOutput = printEnvDetailsAndSetOutput;
60707+
function getToolVersion(tool, options) {
60708+
return __awaiter(this, void 0, void 0, function* () {
60709+
try {
60710+
const { stdout, stderr, exitCode } = yield exec.getExecOutput(tool, options, {
60711+
ignoreReturnCode: true,
60712+
silent: true
60713+
});
60714+
if (exitCode > 0) {
60715+
core.info(`[warning]${stderr}`);
60716+
return '';
60717+
}
60718+
return stdout.trim();
60719+
}
60720+
catch (err) {
60721+
return '';
60722+
}
60723+
});
60724+
}
60725+
const arrayUniq = (src) => [...new Set(src)];
60726+
exports.arrayUniq = arrayUniq;
60727+
const arrayUniqNotNull = (src) => {
60728+
const set = new Set();
60729+
src.forEach(item => {
60730+
if (item !== null)
60731+
set.add(item);
60732+
});
60733+
return [...set];
60734+
};
60735+
exports.arrayUniqNotNull = arrayUniqNotNull;
60736+
60737+
6063060738
/***/ }),
6063160739

6063260740
/***/ 2877:

dist/setup/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71223,6 +71223,7 @@ const cache = __importStar(__nccwpck_require__(7799));
7122371223
const glob = __importStar(__nccwpck_require__(8090));
7122471224
const path_1 = __importDefault(__nccwpck_require__(1017));
7122571225
const fs_1 = __importDefault(__nccwpck_require__(7147));
71226+
const util_1 = __nccwpck_require__(2629);
7122671227
exports.supportedPackageManagers = {
7122771228
npm: {
7122871229
name: 'npm',
@@ -71308,11 +71309,7 @@ const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __
7130871309
cacheDependenciesPaths = (yield globber.glob()) || [''];
7130971310
exports.memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths;
7131071311
}
71311-
const existingDirectories = cacheDependenciesPaths
71312-
.map(path_1.default.dirname)
71313-
// uniq in order to do not traverse the same directories during the further processing
71314-
.filter((item, i, src) => item != null && src.indexOf(item) === i)
71315-
.filter(directory => fs_1.default.existsSync(directory) && fs_1.default.lstatSync(directory).isDirectory());
71312+
const existingDirectories = util_1.arrayUniqNotNull(cacheDependenciesPaths.map(path_1.default.dirname)).filter(directory => fs_1.default.existsSync(directory) && fs_1.default.lstatSync(directory).isDirectory());
7131671313
// if user explicitly pointed out some file, but it does not exist it is definitely
7131771314
// not he wanted, thus we should throw an error not trying to workaround with unexpected
7131871315
// result to the whole build
@@ -71336,7 +71333,7 @@ const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDep
7133671333
return cacheFolderPath;
7133771334
})));
7133871335
// uniq in order to do not cache the same directories twice
71339-
return cacheFoldersPaths.filter((item, i, src) => src.indexOf(item) === i);
71336+
return util_1.arrayUniq(cacheFoldersPaths);
7134071337
});
7134171338
/**
7134271339
* Finds the cache directories configured for the repo ignoring cache-dependency-path
@@ -72240,7 +72237,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7224072237
});
7224172238
};
7224272239
Object.defineProperty(exports, "__esModule", ({ value: true }));
72243-
exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
72240+
exports.arrayUniqNotNull = exports.arrayUniq = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
7224472241
const core = __importStar(__nccwpck_require__(2186));
7224572242
const exec = __importStar(__nccwpck_require__(1514));
7224672243
function parseNodeVersionFile(contents) {
@@ -72302,6 +72299,17 @@ function getToolVersion(tool, options) {
7230272299
}
7230372300
});
7230472301
}
72302+
const arrayUniq = (src) => [...new Set(src)];
72303+
exports.arrayUniq = arrayUniq;
72304+
const arrayUniqNotNull = (src) => {
72305+
const set = new Set();
72306+
src.forEach(item => {
72307+
if (item !== null)
72308+
set.add(item);
72309+
});
72310+
return [...set];
72311+
};
72312+
exports.arrayUniqNotNull = arrayUniqNotNull;
7230572313

7230672314

7230772315
/***/ }),

src/cache-utils.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as cache from '@actions/cache';
44
import * as glob from '@actions/glob';
55
import path from 'path';
66
import fs from 'fs';
7+
import {arrayUniq, arrayUniqNotNull} from './util';
78

89
export interface PackageManagerInfo {
910
name: string;
@@ -136,14 +137,12 @@ const getProjectDirectoriesFromCacheDependencyPath = async (
136137
memoizedCacheDependencies[cacheDependencyPath] = cacheDependenciesPaths;
137138
}
138139

139-
const existingDirectories: string[] = cacheDependenciesPaths
140-
.map(path.dirname)
141-
// uniq in order to do not traverse the same directories during the further processing
142-
.filter((item, i, src) => item != null && src.indexOf(item) === i)
143-
.filter(
144-
directory =>
145-
fs.existsSync(directory) && fs.lstatSync(directory).isDirectory()
146-
) as string[];
140+
const existingDirectories: string[] = arrayUniqNotNull(
141+
cacheDependenciesPaths.map(path.dirname)
142+
).filter(
143+
directory =>
144+
fs.existsSync(directory) && fs.lstatSync(directory).isDirectory()
145+
) as string[];
147146

148147
// if user explicitly pointed out some file, but it does not exist it is definitely
149148
// not he wanted, thus we should throw an error not trying to workaround with unexpected
@@ -183,7 +182,7 @@ const getCacheDirectoriesFromCacheDependencyPath = async (
183182
)
184183
);
185184
// uniq in order to do not cache the same directories twice
186-
return cacheFoldersPaths.filter((item, i, src) => src.indexOf(item) === i);
185+
return arrayUniq(cacheFoldersPaths);
187186
};
188187

189188
/**

src/util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,12 @@ async function getToolVersion(tool: string, options: string[]) {
6161
return '';
6262
}
6363
}
64+
65+
export const arrayUniq = <T>(src: Array<T>): Array<T> => [...new Set(src)];
66+
export const arrayUniqNotNull = <T>(src: Array<T | null>): Array<T> => {
67+
const set = new Set<T>();
68+
src.forEach(item => {
69+
if (item !== null) set.add(item);
70+
});
71+
return [...set];
72+
};

0 commit comments

Comments
 (0)