Skip to content

Commit fb74ce4

Browse files
committed
make parses fully async
1 parent 4863f74 commit fb74ce4

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

jest.config.cjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,19 @@ module.exports = {
1414
"@swc-node/jest",
1515
{
1616
module: "commonjs",
17-
swc: { minify: false, sourceMaps: "inline" },
17+
swc: {
18+
jsc: {
19+
target: "es2020",
20+
parser: {
21+
syntax: "typescript",
22+
tsx: false,
23+
},
24+
},
25+
sourceMaps: "inline",
26+
minify: false,
27+
},
1828
},
1929
],
2030
},
2131
transformIgnorePatterns: ["/node_modules/", "\\.pnp\\.[^\\/]+$"],
22-
};
32+
};

src/main/libs/ParseFlows.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1+
import { promises as fs } from "fs";
12
import * as p from "path";
2-
import { Flow } from "../models/Flow";
3-
import fs from "fs";
43
import { convert } from "xmlbuilder2";
4+
5+
import { Flow } from "../models/Flow";
56
import { ParsedFlow } from "../models/ParsedFlow";
67

78
export async function parse(selectedUris: string[]): Promise<ParsedFlow[]> {
89
const parseResults: ParsedFlow[] = [];
10+
911
for (const uri of selectedUris) {
1012
try {
1113
const normalizedURI = p.normalize(uri);
12-
const content = await fs.readFileSync(normalizedURI);
13-
const xmlString = content.toString();
14-
const flowObj = convert(xmlString, { format: "object" });
14+
const content = await fs.readFile(normalizedURI, "utf8");
15+
const flowObj = convert(content, { format: "object" });
1516
parseResults.push(new ParsedFlow(uri, new Flow(uri, flowObj)));
16-
} catch (e) {
17-
parseResults.push(new ParsedFlow(uri, undefined, e.errorMessage));
17+
} catch (e: any) {
18+
parseResults.push(
19+
new ParsedFlow(uri, undefined, e.message ?? e.toString())
20+
);
1821
}
1922
}
23+
2024
return parseResults;
2125
}

tests/SanityTest.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as core from "../src";
2+
3+
test("core exports sanity", () => {
4+
console.log(Object.keys(core));
5+
expect(core.scan).toBeDefined();
6+
expect(core.parse).toBeDefined();
7+
});

0 commit comments

Comments
 (0)