@awsless/ts-file-cache 0.0.19 → 0.0.20

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 CHANGED
@@ -3,65 +3,21 @@ let fs_promises = require("fs/promises");
3
3
  let path = require("path");
4
4
  let crypto = require("crypto");
5
5
  let node_module = require("node:module");
6
- let _swc_core = require("@swc/core");
7
- let swc_walk = require("swc-walk");
8
- let swc_walk_baseVisitor = require("swc-walk/baseVisitor");
6
+ let estree_walker = require("estree-walker");
7
+ let oxc_parser = require("oxc-parser");
9
8
  let yaml = require("yaml");
10
9
  //#region src/import.ts
11
- var PatchedBaseVisitor = class extends swc_walk_baseVisitor.BaseVisitor {
12
- FunctionBody(node, state, callback) {
13
- for (const statement of node.stmts) callback(statement, state);
14
- }
15
- };
16
- const baseVisitor = new PatchedBaseVisitor();
17
- const parseOptions = (file) => {
18
- if (file.endsWith(".tsx")) return {
19
- syntax: "typescript",
20
- tsx: true,
21
- decorators: true
22
- };
23
- if (file.endsWith(".ts") || file.endsWith(".mts") || file.endsWith(".cts")) return {
24
- syntax: "typescript",
25
- decorators: true
26
- };
27
- return {
28
- syntax: "ecmascript",
29
- jsx: true,
30
- decorators: true
31
- };
32
- };
33
10
  const findImports = async (file, code) => {
34
- let ast;
35
- try {
36
- ast = await (0, _swc_core.parse)(code, parseOptions(file));
37
- } catch (error) {
38
- throw new Error(`Failed to parse: ${file}`, { cause: error });
39
- }
11
+ const ast = (0, oxc_parser.parseSync)(file, code);
12
+ if (ast.errors.length > 0) throw new Error(`Failed to parse: ${file}`, { cause: ast.errors[0] });
40
13
  const importing = /* @__PURE__ */ new Set();
41
- try {
42
- (0, swc_walk.simple)(ast, {
43
- ImportDeclaration(node) {
44
- importing.add(node.source.value);
45
- },
46
- ExportAllDeclaration(node) {
47
- importing.add(node.source.value);
48
- },
49
- ExportNamedDeclaration(node) {
50
- if (node.source) importing.add(node.source.value);
51
- },
52
- CallExpression(node) {
53
- if (node.callee.type === "Import") {
54
- const first = node.arguments.at(0);
55
- if (first && first.expression.type === "StringLiteral") importing.add(first.expression.value);
56
- }
57
- },
58
- TsImportEqualsDeclaration(node) {
59
- if (node.moduleRef.type === "TsExternalModuleReference") importing.add(node.moduleRef.expression.value);
60
- }
61
- }, baseVisitor);
62
- } catch (error) {
63
- throw new Error(`Failed to walk the AST of: ${file}`, { cause: error });
64
- }
14
+ (0, estree_walker.walk)(ast.program, { enter(node) {
15
+ if (node.type === "ImportDeclaration" || node.type === "ExportAllDeclaration") importing.add(node.source.value);
16
+ if (node.type === "ExportNamedDeclaration" && node.source) importing.add(node.source.value);
17
+ if (node.type === "ImportExpression" && node.source.type === "Literal") importing.add(node.source.value);
18
+ const importEquals = node;
19
+ if (importEquals.type === "TSImportEqualsDeclaration" && importEquals.moduleReference.type === "TSExternalModuleReference") importing.add(importEquals.moduleReference.expression.value);
20
+ } });
65
21
  return [...importing].map((importee) => {
66
22
  if (importee.startsWith(".")) return (0, path.resolve)((0, path.dirname)(file), importee);
67
23
  const parts = importee.split("/");
package/dist/index.js CHANGED
@@ -2,65 +2,21 @@ import { builtinModules } from "node:module";
2
2
  import { lstat, readFile, readdir, stat } from "fs/promises";
3
3
  import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve, sep } from "path";
4
4
  import { createHash } from "crypto";
5
- import { parse } from "@swc/core";
6
- import { simple } from "swc-walk";
7
- import { BaseVisitor } from "swc-walk/baseVisitor";
8
- import { parse as parse$1 } from "yaml";
5
+ import { walk } from "estree-walker";
6
+ import { parseSync } from "oxc-parser";
7
+ import { parse } from "yaml";
9
8
  //#region src/import.ts
10
- var PatchedBaseVisitor = class extends BaseVisitor {
11
- FunctionBody(node, state, callback) {
12
- for (const statement of node.stmts) callback(statement, state);
13
- }
14
- };
15
- const baseVisitor = new PatchedBaseVisitor();
16
- const parseOptions = (file) => {
17
- if (file.endsWith(".tsx")) return {
18
- syntax: "typescript",
19
- tsx: true,
20
- decorators: true
21
- };
22
- if (file.endsWith(".ts") || file.endsWith(".mts") || file.endsWith(".cts")) return {
23
- syntax: "typescript",
24
- decorators: true
25
- };
26
- return {
27
- syntax: "ecmascript",
28
- jsx: true,
29
- decorators: true
30
- };
31
- };
32
9
  const findImports = async (file, code) => {
33
- let ast;
34
- try {
35
- ast = await parse(code, parseOptions(file));
36
- } catch (error) {
37
- throw new Error(`Failed to parse: ${file}`, { cause: error });
38
- }
10
+ const ast = parseSync(file, code);
11
+ if (ast.errors.length > 0) throw new Error(`Failed to parse: ${file}`, { cause: ast.errors[0] });
39
12
  const importing = /* @__PURE__ */ new Set();
40
- try {
41
- simple(ast, {
42
- ImportDeclaration(node) {
43
- importing.add(node.source.value);
44
- },
45
- ExportAllDeclaration(node) {
46
- importing.add(node.source.value);
47
- },
48
- ExportNamedDeclaration(node) {
49
- if (node.source) importing.add(node.source.value);
50
- },
51
- CallExpression(node) {
52
- if (node.callee.type === "Import") {
53
- const first = node.arguments.at(0);
54
- if (first && first.expression.type === "StringLiteral") importing.add(first.expression.value);
55
- }
56
- },
57
- TsImportEqualsDeclaration(node) {
58
- if (node.moduleRef.type === "TsExternalModuleReference") importing.add(node.moduleRef.expression.value);
59
- }
60
- }, baseVisitor);
61
- } catch (error) {
62
- throw new Error(`Failed to walk the AST of: ${file}`, { cause: error });
63
- }
13
+ walk(ast.program, { enter(node) {
14
+ if (node.type === "ImportDeclaration" || node.type === "ExportAllDeclaration") importing.add(node.source.value);
15
+ if (node.type === "ExportNamedDeclaration" && node.source) importing.add(node.source.value);
16
+ if (node.type === "ImportExpression" && node.source.type === "Literal") importing.add(node.source.value);
17
+ const importEquals = node;
18
+ if (importEquals.type === "TSImportEqualsDeclaration" && importEquals.moduleReference.type === "TSExternalModuleReference") importing.add(importEquals.moduleReference.expression.value);
19
+ } });
64
20
  return [...importing].map((importee) => {
65
21
  if (importee.startsWith(".")) return resolve(dirname(file), importee);
66
22
  const parts = importee.split("/");
@@ -269,7 +225,7 @@ const stripJsoncSyntax = (text) => {
269
225
  //#endregion
270
226
  //#region src/package-manager/pnpm.ts
271
227
  const pnpm = async (cwd, lockFile) => {
272
- const data = parse$1(lockFile);
228
+ const data = parse(lockFile);
273
229
  const importers = {};
274
230
  for (const [path, importee] of Object.entries(data.importers)) {
275
231
  const deps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/ts-file-cache",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "bugs": {
5
5
  "url": "https://github.com/awsless/awsless/issues"
6
6
  },
@@ -24,8 +24,8 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "@swc/core": "1.16.1",
28
- "swc-walk": "3.0.0-rc.0",
27
+ "estree-walker": "3.0.3",
28
+ "oxc-parser": "0.146.0",
29
29
  "yaml": "2.9.0"
30
30
  },
31
31
  "scripts": {