@awsless/ts-file-cache 0.0.11 → 0.0.13
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/README.MD +4 -0
- package/dist/index.cjs +31 -23
- package/dist/index.js +29 -21
- package/package.json +4 -4
package/README.MD
CHANGED
|
@@ -17,3 +17,7 @@ const workspace = await loadWorkspace('.')
|
|
|
17
17
|
const hash = await generateFolderHash(workspace, "./src")
|
|
18
18
|
|
|
19
19
|
```
|
|
20
|
+
|
|
21
|
+
## Known issue's
|
|
22
|
+
|
|
23
|
+
- When we walk the AST tree with the "swc-walk" package it could fail in some code bases. Right now we just silently fail which could lead to an incorrect cache key.
|
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
|
|
@@ -42,27 +42,31 @@ var findImports = async (file, code) => {
|
|
|
42
42
|
syntax: "typescript"
|
|
43
43
|
});
|
|
44
44
|
const importing = /* @__PURE__ */ new Set();
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
ExportAllDeclaration(node) {
|
|
50
|
-
importing.add(node.source.value);
|
|
51
|
-
},
|
|
52
|
-
ExportNamedDeclaration(node) {
|
|
53
|
-
if (node.source) {
|
|
45
|
+
try {
|
|
46
|
+
(0, import_swc_walk.simple)(ast, {
|
|
47
|
+
ImportDeclaration(node) {
|
|
54
48
|
importing.add(node.source.value);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (
|
|
61
|
-
importing.add(
|
|
49
|
+
},
|
|
50
|
+
ExportAllDeclaration(node) {
|
|
51
|
+
importing.add(node.source.value);
|
|
52
|
+
},
|
|
53
|
+
ExportNamedDeclaration(node) {
|
|
54
|
+
if (node.source) {
|
|
55
|
+
importing.add(node.source.value);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
CallExpression(node) {
|
|
59
|
+
if (node.callee.type === "Import") {
|
|
60
|
+
const first = node.arguments.at(0);
|
|
61
|
+
if (first && first.expression.type === "StringLiteral") {
|
|
62
|
+
importing.add(first.expression.value);
|
|
63
|
+
}
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
+
});
|
|
67
|
+
} catch (_) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
66
70
|
return [...importing].map((importee) => {
|
|
67
71
|
if (importee.startsWith(".")) {
|
|
68
72
|
return (0, import_path.resolve)((0, import_path.dirname)(file), importee);
|
|
@@ -127,9 +131,13 @@ var generateRecursiveFileHashes = async (workspace, file, sourceFile, allowedExt
|
|
|
127
131
|
return;
|
|
128
132
|
}
|
|
129
133
|
const code = await (0, import_promises2.readFile)(file, "utf8");
|
|
130
|
-
const
|
|
134
|
+
const ext = file.split(".").pop();
|
|
131
135
|
const hash = (0, import_crypto.createHash)("sha1").update(code).digest();
|
|
132
136
|
hashes.set(relFile, hash);
|
|
137
|
+
if (!ext || !allowedExtensions.includes(ext)) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const deps = await findImports(file, code);
|
|
133
141
|
for (const dep of deps) {
|
|
134
142
|
await generateRecursiveFileHashes(workspace, dep, file, allowedExtensions, hashes);
|
|
135
143
|
}
|
|
@@ -267,7 +275,7 @@ var generateFolderHash = async (workspace, folder, opts = {}) => {
|
|
|
267
275
|
const files = await (0, import_promises4.readdir)(folder, { recursive: true, withFileTypes: true });
|
|
268
276
|
for (const file of files) {
|
|
269
277
|
if (file.isFile() && options.extensions.includes((0, import_path5.extname)(file.name).substring(1))) {
|
|
270
|
-
const f = (0, import_path5.resolve)(file.
|
|
278
|
+
const f = (0, import_path5.resolve)(file.parentPath, file.name);
|
|
271
279
|
await generateRecursiveFileHashes(workspace, f, f, options.extensions, hashes);
|
|
272
280
|
}
|
|
273
281
|
}
|
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
|
|
@@ -16,27 +16,31 @@ var findImports = async (file, code) => {
|
|
|
16
16
|
syntax: "typescript"
|
|
17
17
|
});
|
|
18
18
|
const importing = /* @__PURE__ */ new Set();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
ExportAllDeclaration(node) {
|
|
24
|
-
importing.add(node.source.value);
|
|
25
|
-
},
|
|
26
|
-
ExportNamedDeclaration(node) {
|
|
27
|
-
if (node.source) {
|
|
19
|
+
try {
|
|
20
|
+
simple(ast, {
|
|
21
|
+
ImportDeclaration(node) {
|
|
28
22
|
importing.add(node.source.value);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
importing.add(
|
|
23
|
+
},
|
|
24
|
+
ExportAllDeclaration(node) {
|
|
25
|
+
importing.add(node.source.value);
|
|
26
|
+
},
|
|
27
|
+
ExportNamedDeclaration(node) {
|
|
28
|
+
if (node.source) {
|
|
29
|
+
importing.add(node.source.value);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
CallExpression(node) {
|
|
33
|
+
if (node.callee.type === "Import") {
|
|
34
|
+
const first = node.arguments.at(0);
|
|
35
|
+
if (first && first.expression.type === "StringLiteral") {
|
|
36
|
+
importing.add(first.expression.value);
|
|
37
|
+
}
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
|
+
});
|
|
41
|
+
} catch (_) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
40
44
|
return [...importing].map((importee) => {
|
|
41
45
|
if (importee.startsWith(".")) {
|
|
42
46
|
return resolve(dirname(file), importee);
|
|
@@ -101,9 +105,13 @@ var generateRecursiveFileHashes = async (workspace, file, sourceFile, allowedExt
|
|
|
101
105
|
return;
|
|
102
106
|
}
|
|
103
107
|
const code = await readFile(file, "utf8");
|
|
104
|
-
const
|
|
108
|
+
const ext = file.split(".").pop();
|
|
105
109
|
const hash = createHash("sha1").update(code).digest();
|
|
106
110
|
hashes.set(relFile, hash);
|
|
111
|
+
if (!ext || !allowedExtensions.includes(ext)) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const deps = await findImports(file, code);
|
|
107
115
|
for (const dep of deps) {
|
|
108
116
|
await generateRecursiveFileHashes(workspace, dep, file, allowedExtensions, hashes);
|
|
109
117
|
}
|
|
@@ -241,7 +249,7 @@ var generateFolderHash = async (workspace, folder, opts = {}) => {
|
|
|
241
249
|
const files = await readdir(folder, { recursive: true, withFileTypes: true });
|
|
242
250
|
for (const file of files) {
|
|
243
251
|
if (file.isFile() && options.extensions.includes(extname(file.name).substring(1))) {
|
|
244
|
-
const f = resolve2(file.
|
|
252
|
+
const f = resolve2(file.parentPath, file.name);
|
|
245
253
|
await generateRecursiveFileHashes(workspace, f, f, options.extensions, hashes);
|
|
246
254
|
}
|
|
247
255
|
}
|
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.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -18,13 +18,13 @@
|
|
|
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": {
|
|
27
|
-
"@swc/core": "^1.
|
|
27
|
+
"@swc/core": "^1.10.18",
|
|
28
28
|
"swc-walk": "1.0.0-rc.2",
|
|
29
29
|
"yaml": "^2.5.0"
|
|
30
30
|
},
|