@awsless/ts-file-cache 0.0.12 → 0.0.14
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/dist/index.cjs +21 -9
- package/dist/index.js +19 -7
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -18,13 +18,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
generateFileHash: () => generateFileHash,
|
|
24
24
|
generateFolderHash: () => generateFolderHash,
|
|
25
25
|
loadWorkspace: () => loadWorkspace
|
|
26
26
|
});
|
|
27
|
-
module.exports = __toCommonJS(
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
var import_promises4 = require("fs/promises");
|
|
29
29
|
|
|
30
30
|
// src/hash.ts
|
|
@@ -139,15 +139,16 @@ var generateRecursiveFileHashes = async (workspace, file, sourceFile, allowedExt
|
|
|
139
139
|
}
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
|
-
|
|
142
|
+
const module2 = getPackageName(file);
|
|
143
|
+
if (hashes.has(module2)) {
|
|
143
144
|
return;
|
|
144
145
|
}
|
|
145
|
-
const dependency = findDependency(workspace,
|
|
146
|
+
const dependency = findDependency(workspace, module2, sourceFile);
|
|
146
147
|
if (dependency) {
|
|
147
148
|
if (dependency.type === "package") {
|
|
148
|
-
hashes.set(
|
|
149
|
+
hashes.set(module2, Buffer.from(`${module2}:${dependency.version}`, "utf8"));
|
|
149
150
|
} else {
|
|
150
|
-
const localPackage = workspace.packages[
|
|
151
|
+
const localPackage = workspace.packages[module2];
|
|
151
152
|
if (!localPackage) {
|
|
152
153
|
throw new Error(`Can't find the local workspace package for: ${file}`);
|
|
153
154
|
}
|
|
@@ -164,7 +165,7 @@ var generateRecursiveFileHashes = async (workspace, file, sourceFile, allowedExt
|
|
|
164
165
|
}
|
|
165
166
|
return;
|
|
166
167
|
}
|
|
167
|
-
if (import_node_module.builtinModules.includes(
|
|
168
|
+
if (import_node_module.builtinModules.includes(module2.replace(/^node\:/, ""))) {
|
|
168
169
|
return;
|
|
169
170
|
}
|
|
170
171
|
throw new Error(`Can't find the dependency version for: ${file} inside the source: ${sourceFile}`);
|
|
@@ -173,6 +174,17 @@ var mergeHashes = (hashes) => {
|
|
|
173
174
|
const merge = Buffer.concat(Array.from(hashes.values()).sort());
|
|
174
175
|
return (0, import_crypto.createHash)("sha1").update(merge).digest("hex");
|
|
175
176
|
};
|
|
177
|
+
var getPackageName = (importee) => {
|
|
178
|
+
const parts = importee.split("/");
|
|
179
|
+
if (importee.startsWith("@")) {
|
|
180
|
+
if (parts.length >= 2) {
|
|
181
|
+
return `${parts[0]}/${parts[1]}`;
|
|
182
|
+
}
|
|
183
|
+
} else if (parts.length >= 1) {
|
|
184
|
+
return parts[0];
|
|
185
|
+
}
|
|
186
|
+
throw new Error(`Malformed importee: ${importee}`);
|
|
187
|
+
};
|
|
176
188
|
var findDependency = (workspace, module2, source) => {
|
|
177
189
|
const pkg = Object.values(workspace.packages).filter((p) => source.startsWith(p.path)).sort((a, b) => b.path.split("/").length - a.path.split("/").length).find((p) => p.dependencies[module2]);
|
|
178
190
|
if (!pkg) {
|
|
@@ -271,7 +283,7 @@ var generateFolderHash = async (workspace, folder, opts = {}) => {
|
|
|
271
283
|
const files = await (0, import_promises4.readdir)(folder, { recursive: true, withFileTypes: true });
|
|
272
284
|
for (const file of files) {
|
|
273
285
|
if (file.isFile() && options.extensions.includes((0, import_path5.extname)(file.name).substring(1))) {
|
|
274
|
-
const f = (0, import_path5.resolve)(file.
|
|
286
|
+
const f = (0, import_path5.resolve)(file.parentPath, file.name);
|
|
275
287
|
await generateRecursiveFileHashes(workspace, f, f, options.extensions, hashes);
|
|
276
288
|
}
|
|
277
289
|
}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { readdir } from "fs/promises";
|
|
|
4
4
|
// src/hash.ts
|
|
5
5
|
import { createHash } from "crypto";
|
|
6
6
|
import { readFile } from "fs/promises";
|
|
7
|
-
import { builtinModules } from "
|
|
7
|
+
import { builtinModules } from "module";
|
|
8
8
|
import { relative } from "path";
|
|
9
9
|
|
|
10
10
|
// src/import.ts
|
|
@@ -113,15 +113,16 @@ var generateRecursiveFileHashes = async (workspace, file, sourceFile, allowedExt
|
|
|
113
113
|
}
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
const module = getPackageName(file);
|
|
117
|
+
if (hashes.has(module)) {
|
|
117
118
|
return;
|
|
118
119
|
}
|
|
119
|
-
const dependency = findDependency(workspace,
|
|
120
|
+
const dependency = findDependency(workspace, module, sourceFile);
|
|
120
121
|
if (dependency) {
|
|
121
122
|
if (dependency.type === "package") {
|
|
122
|
-
hashes.set(
|
|
123
|
+
hashes.set(module, Buffer.from(`${module}:${dependency.version}`, "utf8"));
|
|
123
124
|
} else {
|
|
124
|
-
const localPackage = workspace.packages[
|
|
125
|
+
const localPackage = workspace.packages[module];
|
|
125
126
|
if (!localPackage) {
|
|
126
127
|
throw new Error(`Can't find the local workspace package for: ${file}`);
|
|
127
128
|
}
|
|
@@ -138,7 +139,7 @@ var generateRecursiveFileHashes = async (workspace, file, sourceFile, allowedExt
|
|
|
138
139
|
}
|
|
139
140
|
return;
|
|
140
141
|
}
|
|
141
|
-
if (builtinModules.includes(
|
|
142
|
+
if (builtinModules.includes(module.replace(/^node\:/, ""))) {
|
|
142
143
|
return;
|
|
143
144
|
}
|
|
144
145
|
throw new Error(`Can't find the dependency version for: ${file} inside the source: ${sourceFile}`);
|
|
@@ -147,6 +148,17 @@ var mergeHashes = (hashes) => {
|
|
|
147
148
|
const merge = Buffer.concat(Array.from(hashes.values()).sort());
|
|
148
149
|
return createHash("sha1").update(merge).digest("hex");
|
|
149
150
|
};
|
|
151
|
+
var getPackageName = (importee) => {
|
|
152
|
+
const parts = importee.split("/");
|
|
153
|
+
if (importee.startsWith("@")) {
|
|
154
|
+
if (parts.length >= 2) {
|
|
155
|
+
return `${parts[0]}/${parts[1]}`;
|
|
156
|
+
}
|
|
157
|
+
} else if (parts.length >= 1) {
|
|
158
|
+
return parts[0];
|
|
159
|
+
}
|
|
160
|
+
throw new Error(`Malformed importee: ${importee}`);
|
|
161
|
+
};
|
|
150
162
|
var findDependency = (workspace, module, source) => {
|
|
151
163
|
const pkg = Object.values(workspace.packages).filter((p) => source.startsWith(p.path)).sort((a, b) => b.path.split("/").length - a.path.split("/").length).find((p) => p.dependencies[module]);
|
|
152
164
|
if (!pkg) {
|
|
@@ -245,7 +257,7 @@ var generateFolderHash = async (workspace, folder, opts = {}) => {
|
|
|
245
257
|
const files = await readdir(folder, { recursive: true, withFileTypes: true });
|
|
246
258
|
for (const file of files) {
|
|
247
259
|
if (file.isFile() && options.extensions.includes(extname(file.name).substring(1))) {
|
|
248
|
-
const f = resolve2(file.
|
|
260
|
+
const f = resolve2(file.parentPath, file.name);
|
|
249
261
|
await generateRecursiveFileHashes(workspace, f, f, options.extensions, hashes);
|
|
250
262
|
}
|
|
251
263
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/ts-file-cache",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
21
22
|
"require": "./dist/index.cjs",
|
|
22
|
-
"import": "./dist/index.js"
|
|
23
|
-
"types": "./dist/index.d.ts"
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|