@lage-run/hasher 0.2.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +37 -1
- package/CHANGELOG.md +11 -2
- package/lib/FileHasher.d.ts +13 -0
- package/lib/FileHasher.js +181 -0
- package/lib/PackageTree.d.ts +20 -0
- package/lib/PackageTree.js +178 -0
- package/lib/TargetHasher.d.ts +47 -0
- package/lib/TargetHasher.js +218 -0
- package/lib/__tests__/TargetHasher.test.js +128 -0
- package/lib/__tests__/getPackageDeps.test.js +70 -67
- package/lib/__tests__/resolveDependenciesHelper.js +19 -13
- package/lib/__tests__/resolveExternalDependencies.test.js +16 -16
- package/lib/__tests__/resolveInternalDependencies.test.js +12 -12
- package/lib/getPackageDeps.js +25 -15
- package/lib/hashStrings.d.ts +1 -0
- package/lib/hashStrings.js +28 -0
- package/lib/index.d.ts +1 -14
- package/lib/index.js +6 -70
- package/lib/nameAtVersion.d.ts +1 -0
- package/lib/nameAtVersion.js +13 -0
- package/lib/resolveExternalDependencies.js +18 -12
- package/lib/resolveInternalDependencies.js +8 -4
- package/package.json +9 -5
- package/lib/__tests__/createPackageHashes.test.js +0 -44
- package/lib/__tests__/getRepoDeps.test.d.ts +0 -1
- package/lib/__tests__/getRepoDeps.test.js +0 -253
- package/lib/__tests__/getRepoState.test.d.ts +0 -1
- package/lib/__tests__/getRepoState.test.js +0 -104
- package/lib/__tests__/hashOfFiles.test.d.ts +0 -1
- package/lib/__tests__/hashOfFiles.test.js +0 -103
- package/lib/__tests__/helpers.test.d.ts +0 -1
- package/lib/__tests__/helpers.test.js +0 -28
- package/lib/__tests__/index.test.d.ts +0 -1
- package/lib/__tests__/index.test.js +0 -99
- package/lib/createPackageHashes.d.ts +0 -4
- package/lib/createPackageHashes.js +0 -48
- package/lib/getRepoState.d.ts +0 -76
- package/lib/getRepoState.js +0 -256
- package/lib/hashOfFiles.d.ts +0 -14
- package/lib/hashOfFiles.js +0 -71
- package/lib/hashOfPackage.d.ts +0 -9
- package/lib/hashOfPackage.js +0 -65
- package/lib/helpers.d.ts +0 -3
- package/lib/helpers.js +0 -47
- package/lib/repoInfo.d.ts +0 -26
- package/lib/repoInfo.js +0 -65
- /package/lib/__tests__/{createPackageHashes.test.d.ts → TargetHasher.test.d.ts} +0 -0
|
@@ -9,24 +9,30 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
filterDependenciesInYarnFixture: ()
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
filterDependenciesInYarnFixture: function() {
|
|
13
|
+
return filterDependenciesInYarnFixture;
|
|
14
|
+
},
|
|
15
|
+
filterDependenciesInPnpmFixture: function() {
|
|
16
|
+
return filterDependenciesInPnpmFixture;
|
|
17
|
+
},
|
|
18
|
+
filterDependenciesInRushFixture: function() {
|
|
19
|
+
return filterDependenciesInRushFixture;
|
|
20
|
+
}
|
|
15
21
|
});
|
|
16
|
-
const _path = /*#__PURE__*/
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
function
|
|
22
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
23
|
+
const _monorepofixture = require("@lage-run/monorepo-fixture");
|
|
24
|
+
const _workspacetools = require("workspace-tools");
|
|
25
|
+
function _interop_require_default(obj) {
|
|
20
26
|
return obj && obj.__esModule ? obj : {
|
|
21
27
|
default: obj
|
|
22
28
|
};
|
|
23
29
|
}
|
|
24
30
|
const fixturesPath = _path.default.join(__dirname, "..", "__fixtures__");
|
|
25
31
|
async function filterDependenciesInYarnFixture(fixture, filterFunction) {
|
|
26
|
-
const monorepo = new
|
|
32
|
+
const monorepo = new _monorepofixture.Monorepo("monorepo");
|
|
27
33
|
await monorepo.init(_path.default.join(fixturesPath, fixture));
|
|
28
34
|
const packageRoot = monorepo.root;
|
|
29
|
-
const workspacesPackageInfo = (0,
|
|
35
|
+
const workspacesPackageInfo = (0, _workspacetools.getYarnWorkspaces)(packageRoot);
|
|
30
36
|
const dependencies = {
|
|
31
37
|
"package-a": "1.0.0",
|
|
32
38
|
foo: "1.0.0"
|
|
@@ -35,10 +41,10 @@ async function filterDependenciesInYarnFixture(fixture, filterFunction) {
|
|
|
35
41
|
return filteredDependencies;
|
|
36
42
|
}
|
|
37
43
|
async function filterDependenciesInPnpmFixture(fixture, filterFunction) {
|
|
38
|
-
const monorepo = new
|
|
44
|
+
const monorepo = new _monorepofixture.Monorepo("monorepo");
|
|
39
45
|
await monorepo.init(_path.default.join(fixturesPath, fixture));
|
|
40
46
|
const packageRoot = monorepo.root;
|
|
41
|
-
const workspacesPackageInfo = (0,
|
|
47
|
+
const workspacesPackageInfo = (0, _workspacetools.getPnpmWorkspaces)(packageRoot);
|
|
42
48
|
const dependencies = {
|
|
43
49
|
"package-a": "1.0.0",
|
|
44
50
|
foo: "1.0.0"
|
|
@@ -47,10 +53,10 @@ async function filterDependenciesInPnpmFixture(fixture, filterFunction) {
|
|
|
47
53
|
return filteredDependencies;
|
|
48
54
|
}
|
|
49
55
|
async function filterDependenciesInRushFixture(fixture, filterFunction) {
|
|
50
|
-
const monorepo = new
|
|
56
|
+
const monorepo = new _monorepofixture.Monorepo("monorepo");
|
|
51
57
|
await monorepo.init(_path.default.join(fixturesPath, fixture));
|
|
52
58
|
const packageRoot = monorepo.root;
|
|
53
|
-
const workspacesPackageInfo = (0,
|
|
59
|
+
const workspacesPackageInfo = (0, _workspacetools.getRushWorkspaces)(packageRoot);
|
|
54
60
|
const dependencies = {
|
|
55
61
|
"package-a": "1.0.0",
|
|
56
62
|
foo: "1.0.0"
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
const
|
|
5
|
+
const _workspacetools = require("workspace-tools");
|
|
6
6
|
const _resolveExternalDependencies = require("../resolveExternalDependencies");
|
|
7
7
|
const _resolveDependenciesHelper = require("./resolveDependenciesHelper");
|
|
8
|
-
const _path = /*#__PURE__*/
|
|
9
|
-
const
|
|
10
|
-
function
|
|
8
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
9
|
+
const _monorepofixture = require("@lage-run/monorepo-fixture");
|
|
10
|
+
function _interop_require_default(obj) {
|
|
11
11
|
return obj && obj.__esModule ? obj : {
|
|
12
12
|
default: obj
|
|
13
13
|
};
|
|
@@ -78,15 +78,15 @@ describe("addToQueue()", ()=>{
|
|
|
78
78
|
});
|
|
79
79
|
describe("resolveExternalDependencies() - yarn", ()=>{
|
|
80
80
|
it("given a list of external dependencies and a parsed Lock file, add all dependencies, transitively", async ()=>{
|
|
81
|
-
const monorepo = new
|
|
81
|
+
const monorepo = new _monorepofixture.Monorepo("monorepo");
|
|
82
82
|
await monorepo.init(_path.default.join(fixturesPath, "monorepo"));
|
|
83
83
|
const packageRoot = monorepo.root;
|
|
84
|
-
const workspaces = (0,
|
|
84
|
+
const workspaces = (0, _workspacetools.getYarnWorkspaces)(packageRoot);
|
|
85
85
|
const allDependencies = {
|
|
86
86
|
"package-a": "1.0.0",
|
|
87
87
|
foo: "1.0.0"
|
|
88
88
|
};
|
|
89
|
-
const parsedLockFile = await (0,
|
|
89
|
+
const parsedLockFile = await (0, _workspacetools.parseLockFile)(packageRoot);
|
|
90
90
|
const resolvedDependencies = (0, _resolveExternalDependencies.resolveExternalDependencies)(allDependencies, workspaces, parsedLockFile);
|
|
91
91
|
expect(resolvedDependencies).toEqual([
|
|
92
92
|
"foo@1.0.0",
|
|
@@ -97,15 +97,15 @@ describe("resolveExternalDependencies() - yarn", ()=>{
|
|
|
97
97
|
});
|
|
98
98
|
describe("resolveExternalDependencies() - pnpm", ()=>{
|
|
99
99
|
it("given a list of external dependencies and a parsed Lock file, add all dependencies, transitively", async ()=>{
|
|
100
|
-
const monorepo = new
|
|
100
|
+
const monorepo = new _monorepofixture.Monorepo("monorepo");
|
|
101
101
|
await monorepo.init(_path.default.join(fixturesPath, "monorepo-pnpm"));
|
|
102
102
|
const packageRoot = monorepo.root;
|
|
103
|
-
const workspaces = (0,
|
|
103
|
+
const workspaces = (0, _workspacetools.getPnpmWorkspaces)(packageRoot);
|
|
104
104
|
const allDependencies = {
|
|
105
105
|
"package-a": "1.0.0",
|
|
106
106
|
once: "1.4.0"
|
|
107
107
|
};
|
|
108
|
-
const parsedLockFile = await (0,
|
|
108
|
+
const parsedLockFile = await (0, _workspacetools.parseLockFile)(packageRoot);
|
|
109
109
|
const resolvedDependencies = (0, _resolveExternalDependencies.resolveExternalDependencies)(allDependencies, workspaces, parsedLockFile);
|
|
110
110
|
expect(resolvedDependencies).toEqual([
|
|
111
111
|
"once@1.4.0",
|
|
@@ -116,15 +116,15 @@ describe("resolveExternalDependencies() - pnpm", ()=>{
|
|
|
116
116
|
});
|
|
117
117
|
describe("resolveExternalDependencies() - rush+pnpm", ()=>{
|
|
118
118
|
it("given a list of external dependencies and a parsed Lock file, add all dependencies, transitively", async ()=>{
|
|
119
|
-
const monorepo = new
|
|
119
|
+
const monorepo = new _monorepofixture.Monorepo("monorepo");
|
|
120
120
|
await monorepo.init(_path.default.join(fixturesPath, "monorepo-rush-pnpm"));
|
|
121
121
|
const packageRoot = monorepo.root;
|
|
122
|
-
const workspaces = (0,
|
|
122
|
+
const workspaces = (0, _workspacetools.getRushWorkspaces)(packageRoot);
|
|
123
123
|
const allDependencies = {
|
|
124
124
|
"package-a": "1.0.0",
|
|
125
125
|
once: "1.4.0"
|
|
126
126
|
};
|
|
127
|
-
const parsedLockFile = await (0,
|
|
127
|
+
const parsedLockFile = await (0, _workspacetools.parseLockFile)(packageRoot);
|
|
128
128
|
const resolvedDependencies = (0, _resolveExternalDependencies.resolveExternalDependencies)(allDependencies, workspaces, parsedLockFile);
|
|
129
129
|
expect(resolvedDependencies).toEqual([
|
|
130
130
|
"once@1.4.0",
|
|
@@ -135,15 +135,15 @@ describe("resolveExternalDependencies() - rush+pnpm", ()=>{
|
|
|
135
135
|
});
|
|
136
136
|
describe("resolveExternalDependencies() - rush+yarn", ()=>{
|
|
137
137
|
it("given a list of external dependencies and a parsed Lock file, add all dependencies, transitively", async ()=>{
|
|
138
|
-
const monorepo = new
|
|
138
|
+
const monorepo = new _monorepofixture.Monorepo("monorepo");
|
|
139
139
|
await monorepo.init(_path.default.join(fixturesPath, "monorepo-rush-yarn"));
|
|
140
140
|
const packageRoot = monorepo.root;
|
|
141
|
-
const workspaces = (0,
|
|
141
|
+
const workspaces = (0, _workspacetools.getRushWorkspaces)(packageRoot);
|
|
142
142
|
const allDependencies = {
|
|
143
143
|
"package-a": "1.0.0",
|
|
144
144
|
once: "1.4.0"
|
|
145
145
|
};
|
|
146
|
-
const parsedLockFile = await (0,
|
|
146
|
+
const parsedLockFile = await (0, _workspacetools.parseLockFile)(packageRoot);
|
|
147
147
|
const resolvedDependencies = (0, _resolveExternalDependencies.resolveExternalDependencies)(allDependencies, workspaces, parsedLockFile);
|
|
148
148
|
expect(resolvedDependencies).toEqual([
|
|
149
149
|
"once@1.4.0",
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
const
|
|
5
|
+
const _workspacetools = require("workspace-tools");
|
|
6
6
|
const _resolveInternalDependencies = require("../resolveInternalDependencies");
|
|
7
7
|
const _resolveDependenciesHelper = require("./resolveDependenciesHelper");
|
|
8
|
-
const _path = /*#__PURE__*/
|
|
9
|
-
const
|
|
10
|
-
function
|
|
8
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
9
|
+
const _monorepofixture = require("@lage-run/monorepo-fixture");
|
|
10
|
+
function _interop_require_default(obj) {
|
|
11
11
|
return obj && obj.__esModule ? obj : {
|
|
12
12
|
default: obj
|
|
13
13
|
};
|
|
@@ -27,10 +27,10 @@ describe("filterInternalDependencies() for yarn", ()=>{
|
|
|
27
27
|
});
|
|
28
28
|
describe("resolveInternalDependencies() for yarn", ()=>{
|
|
29
29
|
it("adds internal dependency names to the processedPackages list", async ()=>{
|
|
30
|
-
const monorepo = new
|
|
30
|
+
const monorepo = new _monorepofixture.Monorepo("monorepo");
|
|
31
31
|
await monorepo.init(_path.default.join(fixturesPath, "monorepo"));
|
|
32
32
|
const packageRoot = monorepo.root;
|
|
33
|
-
const workspaces = (0,
|
|
33
|
+
const workspaces = (0, _workspacetools.getYarnWorkspaces)(packageRoot);
|
|
34
34
|
const dependencies = {
|
|
35
35
|
"package-a": "1.0.0",
|
|
36
36
|
foo: "1.0.0"
|
|
@@ -56,10 +56,10 @@ describe("filterInternalDependencies() for pnpm", ()=>{
|
|
|
56
56
|
});
|
|
57
57
|
describe("resolveInternalDependencies() for pnpm", ()=>{
|
|
58
58
|
it("adds internal dependency names to the processedPackages list", async ()=>{
|
|
59
|
-
const monorepo = new
|
|
59
|
+
const monorepo = new _monorepofixture.Monorepo("monorepo");
|
|
60
60
|
await monorepo.init(_path.default.join(fixturesPath, "monorepo-pnpm"));
|
|
61
61
|
const packageRoot = monorepo.root;
|
|
62
|
-
const workspaces = (0,
|
|
62
|
+
const workspaces = (0, _workspacetools.getPnpmWorkspaces)(packageRoot);
|
|
63
63
|
const dependencies = {
|
|
64
64
|
"package-a": "1.0.0",
|
|
65
65
|
foo: "1.0.0"
|
|
@@ -85,10 +85,10 @@ describe("filterInternalDependencies() for rush+pnpm", ()=>{
|
|
|
85
85
|
});
|
|
86
86
|
describe("resolveInternalDependencies() for rush+pnpm", ()=>{
|
|
87
87
|
it("adds internal dependency names to the processedPackages list", async ()=>{
|
|
88
|
-
const monorepo = new
|
|
88
|
+
const monorepo = new _monorepofixture.Monorepo("monorepo");
|
|
89
89
|
await monorepo.init(_path.default.join(fixturesPath, "monorepo-rush-pnpm"));
|
|
90
90
|
const packageRoot = monorepo.root;
|
|
91
|
-
const workspaces = (0,
|
|
91
|
+
const workspaces = (0, _workspacetools.getRushWorkspaces)(packageRoot);
|
|
92
92
|
const dependencies = {
|
|
93
93
|
"package-a": "1.0.0",
|
|
94
94
|
foo: "1.0.0"
|
|
@@ -114,10 +114,10 @@ describe("filterInternalDependencies() for rush+yarn", ()=>{
|
|
|
114
114
|
});
|
|
115
115
|
describe("resolveInternalDependencies() for rush+yarn", ()=>{
|
|
116
116
|
it("adds internal dependency names to the processedPackages list", async ()=>{
|
|
117
|
-
const monorepo = new
|
|
117
|
+
const monorepo = new _monorepofixture.Monorepo("monorepo");
|
|
118
118
|
await monorepo.init(_path.default.join(fixturesPath, "monorepo-rush-yarn"));
|
|
119
119
|
const packageRoot = monorepo.root;
|
|
120
|
-
const workspaces = (0,
|
|
120
|
+
const workspaces = (0, _workspacetools.getRushWorkspaces)(packageRoot);
|
|
121
121
|
const dependencies = {
|
|
122
122
|
"package-a": "1.0.0",
|
|
123
123
|
foo: "1.0.0"
|
package/lib/getPackageDeps.js
CHANGED
|
@@ -9,18 +9,31 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
parseGitFilename: ()
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
parseGitFilename: function() {
|
|
13
|
+
return parseGitFilename;
|
|
14
|
+
},
|
|
15
|
+
parseGitLsTree: function() {
|
|
16
|
+
return parseGitLsTree;
|
|
17
|
+
},
|
|
18
|
+
parseGitStatus: function() {
|
|
19
|
+
return parseGitStatus;
|
|
20
|
+
},
|
|
21
|
+
getGitHashForFiles: function() {
|
|
22
|
+
return getGitHashForFiles;
|
|
23
|
+
},
|
|
24
|
+
gitLsTree: function() {
|
|
25
|
+
return gitLsTree;
|
|
26
|
+
},
|
|
27
|
+
gitStatus: function() {
|
|
28
|
+
return gitStatus;
|
|
29
|
+
},
|
|
30
|
+
getPackageDeps: function() {
|
|
31
|
+
return getPackageDeps;
|
|
32
|
+
}
|
|
19
33
|
});
|
|
20
|
-
const _path = /*#__PURE__*/
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
function _interopRequireDefault(obj) {
|
|
34
|
+
const _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
|
|
35
|
+
const _execa = /*#__PURE__*/ _interop_require_default(require("execa"));
|
|
36
|
+
function _interop_require_default(obj) {
|
|
24
37
|
return obj && obj.__esModule ? obj : {
|
|
25
38
|
default: obj
|
|
26
39
|
};
|
|
@@ -33,7 +46,7 @@ function _getRequireWildcardCache(nodeInterop) {
|
|
|
33
46
|
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
34
47
|
})(nodeInterop);
|
|
35
48
|
}
|
|
36
|
-
function
|
|
49
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
37
50
|
if (!nodeInterop && obj && obj.__esModule) {
|
|
38
51
|
return obj;
|
|
39
52
|
}
|
|
@@ -161,7 +174,6 @@ function getGitHashForFiles(filesToHash, packagePath, gitPath) {
|
|
|
161
174
|
input: filesToHash.map((x)=>_path.resolve(packagePath, x)).join("\n")
|
|
162
175
|
});
|
|
163
176
|
if (result.exitCode !== 0) {
|
|
164
|
-
(0, _getRepoStateJs.ensureGitMinimumVersion)(gitPath);
|
|
165
177
|
throw new Error(`git hash-object exited with status ${result.exitCode}: ${result.stderr}`);
|
|
166
178
|
}
|
|
167
179
|
const hashStdout = result.stdout.trim();
|
|
@@ -187,7 +199,6 @@ function gitLsTree(path, gitPath) {
|
|
|
187
199
|
cwd: path
|
|
188
200
|
});
|
|
189
201
|
if (result.exitCode !== 0) {
|
|
190
|
-
(0, _getRepoStateJs.ensureGitMinimumVersion)(gitPath);
|
|
191
202
|
throw new Error(`git ls-tree exited with status ${result.exitCode}: ${result.stderr}`);
|
|
192
203
|
}
|
|
193
204
|
return result.stdout;
|
|
@@ -209,7 +220,6 @@ function gitStatus(path, gitPath) {
|
|
|
209
220
|
cwd: path
|
|
210
221
|
});
|
|
211
222
|
if (result.exitCode !== 0) {
|
|
212
|
-
(0, _getRepoStateJs.ensureGitMinimumVersion)(gitPath);
|
|
213
223
|
throw new Error(`git status exited with status ${result.exitCode}: ${result.stderr}`);
|
|
214
224
|
}
|
|
215
225
|
return result.stdout;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hashStrings(strings: string | string[]): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "hashStrings", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return hashStrings;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _crypto = /*#__PURE__*/ _interop_require_default(require("crypto"));
|
|
12
|
+
function _interop_require_default(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function hashStrings(strings) {
|
|
18
|
+
const hasher = _crypto.default.createHash("sha1");
|
|
19
|
+
const anArray = typeof strings === "string" ? [
|
|
20
|
+
strings
|
|
21
|
+
] : strings;
|
|
22
|
+
const elements = [
|
|
23
|
+
...anArray
|
|
24
|
+
];
|
|
25
|
+
elements.sort((a, b)=>a.localeCompare(b));
|
|
26
|
+
elements.forEach((element)=>hasher.update(element));
|
|
27
|
+
return hasher.digest("hex");
|
|
28
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,14 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { PackageHashInfo } from "./hashOfPackage.js";
|
|
3
|
-
import type { RepoInfo } from "./repoInfo.js";
|
|
4
|
-
export interface IHasher {
|
|
5
|
-
createPackageHash: (salt: string) => Promise<string>;
|
|
6
|
-
}
|
|
7
|
-
export declare function addToQueue(dependencyNames: string[], queue: string[], done: PackageHashInfo[], workspaces: WorkspaceInfo): void;
|
|
8
|
-
export declare class Hasher implements IHasher {
|
|
9
|
-
private packageRoot;
|
|
10
|
-
private repoInfo;
|
|
11
|
-
constructor(packageRoot: string, repoInfo: RepoInfo);
|
|
12
|
-
createPackageHash(salt: string): Promise<string>;
|
|
13
|
-
}
|
|
14
|
-
export * from "./repoInfo.js";
|
|
1
|
+
export { TargetHasher } from "./TargetHasher.js";
|
package/lib/index.js
CHANGED
|
@@ -2,74 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
addToQueue: ()=>addToQueue,
|
|
13
|
-
Hasher: ()=>Hasher
|
|
14
|
-
});
|
|
15
|
-
const _workspaceTools = require("workspace-tools");
|
|
16
|
-
const _hashOfPackageJs = require("./hashOfPackage.js");
|
|
17
|
-
const _helpersJs = require("./helpers.js");
|
|
18
|
-
_exportStar(require("./repoInfo.js"), exports);
|
|
19
|
-
function _exportStar(from, to) {
|
|
20
|
-
Object.keys(from).forEach(function(k) {
|
|
21
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function() {
|
|
24
|
-
return from[k];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
return from;
|
|
29
|
-
}
|
|
30
|
-
function isDone(done, packageName) {
|
|
31
|
-
return Boolean(done.find(({ name })=>name === packageName));
|
|
32
|
-
}
|
|
33
|
-
function isInQueue(queue, packagePath) {
|
|
34
|
-
return queue.indexOf(packagePath) >= 0;
|
|
35
|
-
}
|
|
36
|
-
function addToQueue(dependencyNames, queue, done, workspaces) {
|
|
37
|
-
dependencyNames.forEach((name)=>{
|
|
38
|
-
const dependencyPath = (0, _workspaceTools.findWorkspacePath)(workspaces, name);
|
|
39
|
-
if (dependencyPath) {
|
|
40
|
-
if (!isDone(done, name) && !isInQueue(queue, dependencyPath)) {
|
|
41
|
-
queue.push(dependencyPath);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
class Hasher {
|
|
47
|
-
async createPackageHash(salt) {
|
|
48
|
-
const packageRoot = this.packageRoot;
|
|
49
|
-
const { workspaceInfo } = this.repoInfo;
|
|
50
|
-
const queue = [
|
|
51
|
-
packageRoot
|
|
52
|
-
];
|
|
53
|
-
const done = [];
|
|
54
|
-
while(queue.length > 0){
|
|
55
|
-
const packageRoot = queue.shift();
|
|
56
|
-
if (!packageRoot) {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
const packageHash = await (0, _hashOfPackageJs.getPackageHash)(packageRoot, this.repoInfo);
|
|
60
|
-
addToQueue(packageHash.internalDependencies, queue, done, workspaceInfo);
|
|
61
|
-
done.push(packageHash);
|
|
62
|
-
}
|
|
63
|
-
const internalPackagesHash = (0, _hashOfPackageJs.generateHashOfInternalPackages)(done);
|
|
64
|
-
const buildCommandHash = (0, _helpersJs.hashStrings)(salt);
|
|
65
|
-
const combinedHash = (0, _helpersJs.hashStrings)([
|
|
66
|
-
internalPackagesHash,
|
|
67
|
-
buildCommandHash
|
|
68
|
-
]);
|
|
69
|
-
return combinedHash;
|
|
70
|
-
}
|
|
71
|
-
constructor(packageRoot, repoInfo){
|
|
72
|
-
this.packageRoot = packageRoot;
|
|
73
|
-
this.repoInfo = repoInfo;
|
|
5
|
+
Object.defineProperty(exports, "TargetHasher", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _TargetHasher.TargetHasher;
|
|
74
9
|
}
|
|
75
|
-
}
|
|
10
|
+
});
|
|
11
|
+
const _TargetHasher = require("./TargetHasher.js");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function nameAtVersion(name: string, version: string): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "nameAtVersion", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return nameAtVersion;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function nameAtVersion(name, version) {
|
|
12
|
+
return `${name}@${version}`;
|
|
13
|
+
}
|
|
@@ -9,14 +9,20 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
filterExternalDependencies: ()
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
filterExternalDependencies: function() {
|
|
13
|
+
return filterExternalDependencies;
|
|
14
|
+
},
|
|
15
|
+
addToQueue: function() {
|
|
16
|
+
return addToQueue;
|
|
17
|
+
},
|
|
18
|
+
resolveExternalDependencies: function() {
|
|
19
|
+
return resolveExternalDependencies;
|
|
20
|
+
}
|
|
15
21
|
});
|
|
16
|
-
const
|
|
17
|
-
const
|
|
22
|
+
const _workspacetools = require("workspace-tools");
|
|
23
|
+
const _nameAtVersion = require("./nameAtVersion.js");
|
|
18
24
|
function filterExternalDependencies(dependencies, workspaces) {
|
|
19
|
-
const workspacePackageNames = (0,
|
|
25
|
+
const workspacePackageNames = (0, _workspacetools.listOfWorkspacePackageNames)(workspaces);
|
|
20
26
|
const externalDependencies = {};
|
|
21
27
|
Object.entries(dependencies).forEach(([name, versionRange])=>{
|
|
22
28
|
if (workspacePackageNames.indexOf(name) < 0) {
|
|
@@ -29,12 +35,12 @@ function isDone(done, key) {
|
|
|
29
35
|
return done.indexOf(key) >= 0;
|
|
30
36
|
}
|
|
31
37
|
function isInQueue(queue, key) {
|
|
32
|
-
return Boolean(queue.find(([name, versionRange])=>(0,
|
|
38
|
+
return Boolean(queue.find(([name, versionRange])=>(0, _nameAtVersion.nameAtVersion)(name, versionRange) === key));
|
|
33
39
|
}
|
|
34
40
|
function addToQueue(dependencies, done, queue) {
|
|
35
41
|
if (dependencies) {
|
|
36
42
|
Object.entries(dependencies).forEach(([name, versionRange])=>{
|
|
37
|
-
const versionRangeSignature = (0,
|
|
43
|
+
const versionRangeSignature = (0, _nameAtVersion.nameAtVersion)(name, versionRange);
|
|
38
44
|
if (!isDone(done, versionRangeSignature) && !isInQueue(queue, versionRangeSignature)) {
|
|
39
45
|
queue.push([
|
|
40
46
|
name,
|
|
@@ -55,14 +61,14 @@ function resolveExternalDependencies(allDependencies, workspaces, lockInfo) {
|
|
|
55
61
|
continue;
|
|
56
62
|
}
|
|
57
63
|
const [name, versionRange] = next;
|
|
58
|
-
doneRange.push((0,
|
|
59
|
-
const lockFileResult = (0,
|
|
64
|
+
doneRange.push((0, _nameAtVersion.nameAtVersion)(name, versionRange));
|
|
65
|
+
const lockFileResult = (0, _workspacetools.queryLockFile)(name, versionRange, lockInfo);
|
|
60
66
|
if (lockFileResult) {
|
|
61
67
|
const { version , dependencies } = lockFileResult;
|
|
62
68
|
addToQueue(dependencies, doneRange, queue);
|
|
63
|
-
done.push((0,
|
|
69
|
+
done.push((0, _nameAtVersion.nameAtVersion)(name, version));
|
|
64
70
|
} else {
|
|
65
|
-
done.push((0,
|
|
71
|
+
done.push((0, _nameAtVersion.nameAtVersion)(name, versionRange));
|
|
66
72
|
}
|
|
67
73
|
}
|
|
68
74
|
return done;
|
|
@@ -9,12 +9,16 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
filterInternalDependencies: ()
|
|
13
|
-
|
|
12
|
+
filterInternalDependencies: function() {
|
|
13
|
+
return filterInternalDependencies;
|
|
14
|
+
},
|
|
15
|
+
resolveInternalDependencies: function() {
|
|
16
|
+
return resolveInternalDependencies;
|
|
17
|
+
}
|
|
14
18
|
});
|
|
15
|
-
const
|
|
19
|
+
const _workspacetools = require("workspace-tools");
|
|
16
20
|
function filterInternalDependencies(dependencies, workspaces) {
|
|
17
|
-
const workspacePackageNames = (0,
|
|
21
|
+
const workspacePackageNames = (0, _workspacetools.listOfWorkspacePackageNames)(workspaces);
|
|
18
22
|
return Object.keys(dependencies).filter((dependency)=>workspacePackageNames.indexOf(dependency) >= 0);
|
|
19
23
|
}
|
|
20
24
|
function resolveInternalDependencies(allDependencies, workspaces) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lage-run/hasher",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Hasher for Lage Targets",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://github.com/microsoft/lage"
|
|
@@ -11,18 +11,22 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "tsc",
|
|
13
13
|
"start": "tsc -w --preserveWatchOutput",
|
|
14
|
-
"test": "jest",
|
|
14
|
+
"test": "monorepo-scripts jest",
|
|
15
15
|
"lint": "monorepo-scripts lint"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"@lage-run/target-graph": "^0.8.6",
|
|
18
19
|
"execa": "5.1.1",
|
|
19
20
|
"workspace-tools": "0.30.0",
|
|
20
|
-
"
|
|
21
|
+
"fast-glob": "3.2.12",
|
|
22
|
+
"glob-hasher": "^1.3.0",
|
|
23
|
+
"graceful-fs": "^4.2.11",
|
|
24
|
+
"micromatch": "^4.0.5"
|
|
21
25
|
},
|
|
22
26
|
"devDependencies": {
|
|
27
|
+
"@types/graceful-fs": "^4.1.6",
|
|
23
28
|
"@lage-run/monorepo-fixture": "^0.1.0",
|
|
24
|
-
"monorepo-scripts": "*"
|
|
25
|
-
"fs-extra": "10.1.0"
|
|
29
|
+
"monorepo-scripts": "*"
|
|
26
30
|
},
|
|
27
31
|
"publishConfig": {
|
|
28
32
|
"access": "public"
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _createPackageHashes = require("../createPackageHashes");
|
|
6
|
-
describe("createPackageHashes", ()=>{
|
|
7
|
-
it("creates packages hashes for repo hashes", ()=>{
|
|
8
|
-
const packageHashes = (0, _createPackageHashes.createPackageHashes)("/repo", [
|
|
9
|
-
{
|
|
10
|
-
path: "/repo/packages/package-a",
|
|
11
|
-
name: "package-a",
|
|
12
|
-
packageJson: {
|
|
13
|
-
name: "package-a",
|
|
14
|
-
packageJsonPath: "/packages/package-a/package.json",
|
|
15
|
-
version: "1.0.0"
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
path: "/repo/packages/package-b",
|
|
20
|
-
name: "package-b",
|
|
21
|
-
packageJson: {
|
|
22
|
-
name: "package-b",
|
|
23
|
-
packageJsonPath: "/packages/package-b/package.json",
|
|
24
|
-
version: "1.0.0"
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
], {
|
|
28
|
-
"packages/package-a/foo.ts": "hash-a-foo.ts",
|
|
29
|
-
"packages/package-a/package.json": "hash-a-package.json",
|
|
30
|
-
"packages/package-b/1.ts": "hash-b-1.ts",
|
|
31
|
-
"packages/package-b/2.ts": "hash-b-2.ts",
|
|
32
|
-
"packages/package-b/3.ts": "hash-b-3.ts"
|
|
33
|
-
});
|
|
34
|
-
expect(packageHashes["packages/package-a"].length).toEqual(2);
|
|
35
|
-
// packageHashes["packageName"] is an array of tuples of the form [filePath, hash]
|
|
36
|
-
expect(packageHashes["packages/package-a"][0][1]).toEqual("hash-a-foo.ts");
|
|
37
|
-
expect(packageHashes["packages/package-a"][1][1]).toEqual("hash-a-package.json");
|
|
38
|
-
expect(packageHashes["packages/package-b"].length).toEqual(3);
|
|
39
|
-
// packageHashes["packageName"] is an array of tuples of the form [filePath, hash]
|
|
40
|
-
expect(packageHashes["packages/package-b"][0][1]).toEqual("hash-b-1.ts");
|
|
41
|
-
expect(packageHashes["packages/package-b"][1][1]).toEqual("hash-b-2.ts");
|
|
42
|
-
expect(packageHashes["packages/package-b"][2][1]).toEqual("hash-b-3.ts");
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|