@awsless/ts-file-cache 0.0.10 → 0.0.12

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 CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # File hash for js & ts files.
2
+ # @awsless/ts-file-cache
3
3
 
4
4
  Attempt to create a hash from an js/ts file and all it's dependecies.
5
5
  The goal is to generate a new hash when ever the file or it's dependecies change.
@@ -10,3 +10,14 @@ const workspace = await loadWorkspace('.')
10
10
  const hash = await generateFileHash(workspace, "./file.ts")
11
11
 
12
12
  ```
13
+
14
+ ```ts
15
+
16
+ const workspace = await loadWorkspace('.')
17
+ const hash = await generateFolderHash(workspace, "./src")
18
+
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
@@ -42,31 +42,39 @@ var findImports = async (file, code) => {
42
42
  syntax: "typescript"
43
43
  });
44
44
  const importing = /* @__PURE__ */ new Set();
45
- (0, import_swc_walk.simple)(ast, {
46
- ImportDeclaration(node) {
47
- importing.add(node.source.value);
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
- CallExpression(node) {
58
- if (node.callee.type === "Import") {
59
- const first = node.arguments.at(0);
60
- if (first && first.expression.type === "StringLiteral") {
61
- importing.add(first.expression.value);
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);
69
73
  }
74
+ const parts = importee.split("/");
75
+ if (parts.length > 2) {
76
+ return parts.slice(0, 2).join("/");
77
+ }
70
78
  return importee;
71
79
  });
72
80
  };
package/dist/index.js CHANGED
@@ -16,31 +16,39 @@ var findImports = async (file, code) => {
16
16
  syntax: "typescript"
17
17
  });
18
18
  const importing = /* @__PURE__ */ new Set();
19
- simple(ast, {
20
- ImportDeclaration(node) {
21
- importing.add(node.source.value);
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
- CallExpression(node) {
32
- if (node.callee.type === "Import") {
33
- const first = node.arguments.at(0);
34
- if (first && first.expression.type === "StringLiteral") {
35
- importing.add(first.expression.value);
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);
43
47
  }
48
+ const parts = importee.split("/");
49
+ if (parts.length > 2) {
50
+ return parts.slice(0, 2).join("/");
51
+ }
44
52
  return importee;
45
53
  });
46
54
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/ts-file-cache",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -24,7 +24,7 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "@swc/core": "^1.3.70",
27
+ "@swc/core": "^1.10.18",
28
28
  "swc-walk": "1.0.0-rc.2",
29
29
  "yaml": "^2.5.0"
30
30
  },