Skip to content

Commit 49b76fb

Browse files
committed
Add unique
1 parent 885f6b5 commit 49b76fb

File tree

4 files changed

+148
-16
lines changed

4 files changed

+148
-16
lines changed

dist/cache-save/index.js

Lines changed: 116 additions & 4 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',
@@ -60528,9 +60529,10 @@ const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __
6052860529
}
6052960530
const existingDirectories = cacheDependenciesPaths
6053060531
.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());
60532+
.filter(path => path != null)
60533+
.filter(util_1.unique())
60534+
.filter(fs_1.default.existsSync)
60535+
.filter(directory => fs_1.default.lstatSync(directory).isDirectory());
6053460536
// if user explicitly pointed out some file, but it does not exist it is definitely
6053560537
// not he wanted, thus we should throw an error not trying to workaround with unexpected
6053660538
// result to the whole build
@@ -60554,7 +60556,7 @@ const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDep
6055460556
return cacheFolderPath;
6055560557
})));
6055660558
// uniq in order to do not cache the same directories twice
60557-
return cacheFoldersPaths.filter((item, i, src) => src.indexOf(item) === i);
60559+
return cacheFoldersPaths.filter(util_1.unique());
6055860560
});
6055960561
/**
6056060562
* Finds the cache directories configured for the repo ignoring cache-dependency-path
@@ -60627,6 +60629,116 @@ var Outputs;
6062760629
})(Outputs = exports.Outputs || (exports.Outputs = {}));
6062860630

6062960631

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

6063260744
/***/ 2877:

dist/setup/index.js

Lines changed: 17 additions & 5 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',
@@ -71310,9 +71311,10 @@ const getProjectDirectoriesFromCacheDependencyPath = (cacheDependencyPath) => __
7131071311
}
7131171312
const existingDirectories = cacheDependenciesPaths
7131271313
.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());
71314+
.filter(path => path != null)
71315+
.filter(util_1.unique())
71316+
.filter(fs_1.default.existsSync)
71317+
.filter(directory => fs_1.default.lstatSync(directory).isDirectory());
7131671318
// if user explicitly pointed out some file, but it does not exist it is definitely
7131771319
// not he wanted, thus we should throw an error not trying to workaround with unexpected
7131871320
// result to the whole build
@@ -71336,7 +71338,7 @@ const getCacheDirectoriesFromCacheDependencyPath = (packageManagerInfo, cacheDep
7133671338
return cacheFolderPath;
7133771339
})));
7133871340
// uniq in order to do not cache the same directories twice
71339-
return cacheFoldersPaths.filter((item, i, src) => src.indexOf(item) === i);
71341+
return cacheFoldersPaths.filter(util_1.unique());
7134071342
});
7134171343
/**
7134271344
* Finds the cache directories configured for the repo ignoring cache-dependency-path
@@ -72240,7 +72242,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7224072242
});
7224172243
};
7224272244
Object.defineProperty(exports, "__esModule", ({ value: true }));
72243-
exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
72245+
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
7224472246
const core = __importStar(__nccwpck_require__(2186));
7224572247
const exec = __importStar(__nccwpck_require__(1514));
7224672248
function parseNodeVersionFile(contents) {
@@ -72302,6 +72304,16 @@ function getToolVersion(tool, options) {
7230272304
}
7230372305
});
7230472306
}
72307+
const unique = () => {
72308+
const encountered = new Set();
72309+
return (value) => {
72310+
if (encountered.has(value))
72311+
return false;
72312+
encountered.add(value);
72313+
return true;
72314+
};
72315+
};
72316+
exports.unique = unique;
7230572317

7230672318

7230772319
/***/ }),

src/cache-utils.ts

Lines changed: 6 additions & 7 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 {unique} from './util';
78

89
export interface PackageManagerInfo {
910
name: string;
@@ -138,12 +139,10 @@ const getProjectDirectoriesFromCacheDependencyPath = async (
138139

139140
const existingDirectories: string[] = cacheDependenciesPaths
140141
.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[];
142+
.filter(path => path != null)
143+
.filter(unique())
144+
.filter(fs.existsSync)
145+
.filter(directory => fs.lstatSync(directory).isDirectory());
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 cacheFoldersPaths.filter(unique());
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 unique: <T>() => (T) => Boolean = () => {
66+
const encountered = new Set();
67+
return <T>(value: T): Boolean => {
68+
if (encountered.has(value)) return false;
69+
encountered.add(value);
70+
return true;
71+
};
72+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy