Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lage-run/hasher

Package Overview
Dependencies
Maintainers
0
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lage-run/hasher - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

lib/expandInputPatterns.d.ts

23

CHANGELOG.json

@@ -5,3 +5,24 @@ {

{
"date": "Wed, 25 Sep 2024 20:27:33 GMT",
"date": "Fri, 27 Sep 2024 20:03:27 GMT",
"version": "1.5.0",
"tag": "@lage-run/hasher_v1.5.0",
"comments": {
"minor": [
{
"author": "kchau@microsoft.com",
"package": "@lage-run/hasher",
"commit": "2919f9041f931dc6ef65017f7aedb9fef9dab66d",
"comment": "exposes getInputFiles, packageTrees"
},
{
"author": "beachball",
"package": "@lage-run/hasher",
"comment": "Bump @lage-run/globby to v14.1.0",
"commit": "not available"
}
]
}
},
{
"date": "Wed, 25 Sep 2024 20:28:10 GMT",
"version": "1.4.0",

@@ -8,0 +29,0 @@ "tag": "@lage-run/hasher_v1.4.0",

# Change Log - @lage-run/hasher
<!-- This log was last generated on Wed, 25 Sep 2024 20:27:33 GMT and should not be manually modified. -->
<!-- This log was last generated on Fri, 27 Sep 2024 20:03:27 GMT and should not be manually modified. -->
<!-- Start content -->
## 1.5.0
Fri, 27 Sep 2024 20:03:27 GMT
### Minor changes
- exposes getInputFiles, packageTrees (kchau@microsoft.com)
- Bump @lage-run/globby to v14.1.0
## 1.4.0
Wed, 25 Sep 2024 20:27:33 GMT
Wed, 25 Sep 2024 20:28:10 GMT

@@ -11,0 +20,0 @@ ### Minor changes

@@ -39,2 +39,21 @@ "use strict";

}
it("creates different hashes given different global environment glob", async ()=>{
const monorepo1 = await setupFixture("monorepo-with-global-files");
const hasher = new _index.TargetHasher({
root: monorepo1.root,
environmentGlob: [
"some-global.config.js"
]
});
const target = createTarget(monorepo1.root, "package-a", "build");
const hash = await getHash(hasher, target);
const hasher2 = new _index.TargetHasher({
root: monorepo1.root,
environmentGlob: []
});
const target2 = createTarget(monorepo1.root, "package-a", "build");
const hash2 = await getHash(hasher2, target2);
expect(hash).not.toEqual(hash2);
monorepo1.cleanup();
});
it("creates different hashes given different fixtures", async ()=>{

@@ -41,0 +60,0 @@ const monorepo1 = await setupFixture("monorepo");

export { TargetHasher } from "./TargetHasher.js";
export { PackageTree } from "./PackageTree.js";
export { getInputFiles } from "./getInputFiles.js";

@@ -5,8 +5,21 @@ "use strict";

});
Object.defineProperty(exports, "TargetHasher", {
enumerable: true,
get: function() {
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
TargetHasher: function() {
return _TargetHasher.TargetHasher;
},
PackageTree: function() {
return _PackageTree.PackageTree;
},
getInputFiles: function() {
return _getInputFiles.getInputFiles;
}
});
const _TargetHasher = require("./TargetHasher.js");
const _PackageTree = require("./PackageTree.js");
const _getInputFiles = require("./getInputFiles.js");

4

lib/TargetHasher.d.ts

@@ -48,6 +48,3 @@ import type { Target } from "@lage-run/target-graph";

dependencyMap: DependencyMap;
memoizedEnvGlobResults: Map<string, string[]>;
getMemorizedEnvGlobResults(envGlob: string[]): Promise<string[]>;
getPackageInfos(workspacePackages: WorkspaceInfo): PackageInfos;
expandInputPatterns(patterns: string[], target: Target): Record<string, string[]>;
constructor(options: TargetHasherOptions);

@@ -58,3 +55,4 @@ ensureInitialized(): void;

writeTargetHashesManifest(): void;
getEnvironmentGlobHashes(root: string, target: Target): Promise<Record<string, string>>;
cleanup(): Promise<void>;
}

@@ -12,3 +12,3 @@ "use strict";

const _globhasher = require("glob-hasher");
const _fastglob = /*#__PURE__*/ _interop_require_default(require("fast-glob"));
const _globby = require("@lage-run/globby");
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));

@@ -23,2 +23,3 @@ const _path = /*#__PURE__*/ _interop_require_default(require("path"));

const _PackageTree = require("./PackageTree.js");
const _getInputFiles = require("./getInputFiles.js");
function _define_property(obj, key, value) {

@@ -43,13 +44,2 @@ if (key in obj) {

class TargetHasher {
async getMemorizedEnvGlobResults(envGlob) {
const key = envGlob.join("\0ENV_GLOB\0");
const { root } = this.options;
if (!this.memoizedEnvGlobResults.has(key)) {
const files = await (0, _fastglob.default)(envGlob, {
cwd: root
});
this.memoizedEnvGlobResults.set(key, files);
}
return this.memoizedEnvGlobResults.get(key) ?? [];
}
getPackageInfos(workspacePackages) {

@@ -78,39 +68,2 @@ const { root } = this.options;

}
expandInputPatterns(patterns, target) {
const expandedPatterns = {};
for (const pattern of patterns){
if (pattern.startsWith("^") || pattern.startsWith("!^")) {
const matchPattern = pattern.replace("^", "");
// get all the packages that are transitive deps and add them to the list
const queue = [
target.packageName
];
const visited = new Set();
while(queue.length > 0){
const pkg = queue.pop();
if (visited.has(pkg)) {
continue;
}
visited.add(pkg);
if (pkg !== target.packageName) {
expandedPatterns[pkg] = expandedPatterns[pkg] ?? [];
expandedPatterns[pkg].push(matchPattern);
}
if (this.dependencyMap.dependencies.has(pkg)) {
const deps = this.dependencyMap.dependencies.get(pkg);
if (deps) {
for (const dep of deps){
queue.push(dep);
}
}
}
}
} else {
const pkg = target.packageName;
expandedPatterns[pkg] = expandedPatterns[pkg] ?? [];
expandedPatterns[pkg].push(pattern);
}
}
return expandedPatterns;
}
ensureInitialized() {

@@ -128,3 +81,5 @@ if (!this.initializedPromise) {

this.initializedPromise = Promise.all([
this.fileHasher.readManifest().then(()=>this.getMemorizedEnvGlobResults(environmentGlob)).then((files)=>this.fileHasher.hash(files)).then((hash)=>this.globalInputsHash = hash),
this.fileHasher.readManifest().then(()=>(0, _globby.globAsync)(environmentGlob, {
cwd: root
})).then((files)=>this.fileHasher.hash(files)).then((hash)=>this.globalInputsHash = hash),
(0, _workspacetools.getWorkspacesAsync)(root).then((workspaceInfo)=>this.workspaceInfo = workspaceInfo).then(()=>{

@@ -150,5 +105,2 @@ this.packageInfos = this.getPackageInfos(this.workspaceInfo);

this.logger.verbose(`Global inputs hash: ${globalInputsHash}`);
// Log global input hashs to log file
const globalInputsHashJson = JSON.stringify(this.globalInputsHash, null, 2);
this.logger.silly(globalInputsHashJson);
}

@@ -163,3 +115,3 @@ }

}
const files = await (0, _fastglob.default)(target.inputs, {
const files = await (0, _globby.globAsync)(target.inputs, {
cwd: root

@@ -188,15 +140,7 @@ });

].sort();
const inputs = target.inputs ?? [
"**/*"
];
const packagePatterns = this.expandInputPatterns(inputs, target);
const files = [];
for (const [pkg, patterns] of Object.entries(packagePatterns)){
const packageFiles = this.packageTree.getPackageFiles(pkg, patterns);
files.push(...packageFiles);
}
const files = (0, _getInputFiles.getInputFiles)(target, this.dependencyMap, this.packageTree);
const fileHashes = this.fileHasher.hash(files) ?? {}; // this list is sorted by file name
// get target hashes
const targetDepHashes = target.dependencies?.sort().map((targetDep)=>this.targetHashes[targetDep]);
const globalFileHashes = target.environmentGlob ? this.fileHasher.hash(await this.getMemorizedEnvGlobResults(target.environmentGlob)) : this.globalInputsHash ?? {};
const globalFileHashes = await this.getEnvironmentGlobHashes(root, target);
const combinedHashes = [

@@ -235,2 +179,8 @@ // Environmental hashes

}
async getEnvironmentGlobHashes(root, target) {
const globalFileHashes = target.environmentGlob ? this.fileHasher.hash(await (0, _globby.globAsync)(target.environmentGlob ?? [], {
cwd: root
})) : this.globalInputsHash ?? {};
return globalFileHashes;
}
async cleanup() {

@@ -254,3 +204,2 @@ this.writeTargetHashesManifest();

_define_property(this, "dependencyMap", void 0);
_define_property(this, "memoizedEnvGlobResults", void 0);
this.options = options;

@@ -264,3 +213,2 @@ this.targetHashesLog = {};

};
this.memoizedEnvGlobResults = new Map();
const { root , logger } = options;

@@ -267,0 +215,0 @@ this.logger = logger;

{
"name": "@lage-run/hasher",
"version": "1.4.0",
"version": "1.5.0",
"description": "Hasher for Lage Targets",

@@ -18,6 +18,6 @@ "repository": {

"dependencies": {
"@lage-run/globby": "^14.1.0",
"@lage-run/logger": "^1.3.1",
"@lage-run/target-graph": "^0.8.10",
"execa": "5.1.1",
"fast-glob": "3.3.2",
"glob-hasher": "^1.4.2",

@@ -24,0 +24,0 @@ "graceful-fs": "4.2.11",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc