Skip to content

Commit 5c94b56

Browse files
authored
chore(loader): remove dependency on sucrase (#68)
1 parent 6d59723 commit 5c94b56

File tree

12 files changed

+47
-129
lines changed

12 files changed

+47
-129
lines changed

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,19 @@
1414
"@types/js-yaml": "^4.0.5",
1515
"@types/node": "^20.0.0",
1616
"eslint": "^9.2.0",
17-
"typescript": "^5.1.3",
17+
"typescript": "^5.8.3",
1818
"typescript-eslint": "^8.34.0"
1919
},
20+
"devEngines": {
21+
"packageManager": {
22+
"name": "yarn",
23+
"version": "4.9.2"
24+
},
25+
"runtime": {
26+
"name": "nodejs",
27+
"version": ">=22.6.0"
28+
}
29+
},
2030
"imports": {
2131
"#ts-loader": "./packages/ts-loader/loader.js"
2232
},

packages/core/src/countBallotsFromGit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import decryptData from "@node-core/caritat-crypto/decrypt";
1212
import reconstructSplitKey from "@node-core/caritat-crypto/reconstructSplitKey";
1313
import type { VoteCommit } from "./vote.js";
1414
import Vote from "./vote.js";
15-
import { DiscardedCommit } from "./summary/electionSummary.js";
15+
import type { DiscardedCommit } from "./summary/electionSummary.js";
1616
import type VoteResult from "./votingMethods/VoteResult.js";
1717
import { getGPGSignGitFlag } from "./utils/gpgSign.js";
1818

packages/core/src/generateNewVoteFolder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { env } from "node:process";
99
import * as yaml from "js-yaml";
1010

1111
import { generateAndSplitKeyPair } from "@node-core/caritat-crypto/generateSplitKeyPair";
12-
import { loadYmlString, templateBallot, VoteFileFormat } from "./parser.js";
12+
import { loadYmlString, templateBallot, type VoteFileFormat } from "./parser.js";
1313
import runChildProcessAsync from "./utils/runChildProcessAsync.js";
1414
import type { VoteMethod } from "./vote.js";
1515

packages/core/src/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as yaml from "js-yaml";
22
import * as fs from "fs";
33
import * as crypto from "crypto";
4-
import { VoteMethod } from "./vote.js";
4+
import type { VoteMethod } from "./vote.js";
55

66
export interface VoteFileFormat {
77
candidates: string[];

packages/core/src/summary/condorcetSummary.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Ballot, VoteCandidate } from "../vote";
1+
import type { Ballot, VoteCandidate } from "../vote";
22
import cleanMarkdown from "../utils/cleanMarkdown.js";
33
import ElectionSummary from "./electionSummary.js";
44

packages/core/src/vote.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import {
2-
BallotFileFormat,
2+
type BallotFileFormat,
33
checkBallot,
44
loadYmlFile,
55
loadYmlString,
66
parseYml,
7-
VoteFileFormat,
7+
type VoteFileFormat,
88
} from "./parser.js";
99
import type { PathOrFileDescriptor } from "fs";
1010
import type { CandidateScores } from "./votingMethods/VotingMethodImplementation.js";
1111
import VoteResult from "./votingMethods/VoteResult.js";
1212
import CondorcetResult from "./votingMethods/CondorcetResult.js";
1313
import SingleRoundResult from "./votingMethods/SingleRoundResult.js";
14-
import { ElectionSummaryOptions } from "./summary/electionSummary.js";
14+
import type { ElectionSummaryOptions } from "./summary/electionSummary.js";
1515

1616
export interface Actor {
1717
id: string;
@@ -85,13 +85,13 @@ export default class Vote {
8585
public loadFromFile(voteFilePath: PathOrFileDescriptor): void {
8686
const voteData: VoteFileFormat = loadYmlFile<VoteFileFormat>(voteFilePath);
8787
this.voteFromVoteData(voteData);
88-
}
88+
}
8989

9090
public loadFromString(voteFileContents: string): void {
9191
const voteData: VoteFileFormat
9292
= loadYmlString<VoteFileFormat>(voteFileContents);
9393
this.voteFromVoteData(voteData);
94-
}
94+
}
9595

9696
private voteFromVoteData(voteData: VoteFileFormat) {
9797
this.voteFileData = voteData;

packages/core/src/voteUsingGit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import { getGPGSignGitFlag } from "./utils/gpgSign.js";
1010

1111
import encryptData from "@node-core/caritat-crypto/encrypt";
1212
import {
13-
BallotFileFormat,
13+
type BallotFileFormat,
1414
loadYmlFile,
1515
parseYml,
1616
templateBallot,
17-
VoteFileFormat,
17+
type VoteFileFormat,
1818
} from "./parser.js";
1919
import {
2020
getSummarizedBallot,

packages/core/test/winner.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import it from "node:test";
22
import { strict as assert } from "node:assert";
33

4-
import { VoteCandidate } from "../src/vote.js";
4+
import type { VoteCandidate } from "../src/vote.js";
55
import VoteResult from "../src/votingMethods/VoteResult.js";
66
import type { CandidateScores } from "../src/votingMethods/VoteResult";
77

packages/ts-loader/loader.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { readFile, opendir } from "node:fs/promises";
2-
import { URL, fileURLToPath } from "node:url";
3-
4-
import { transform } from "sucrase";
2+
import process from "node:process";
3+
import { URL } from "node:url";
54

65
/**
76
* Maps all the possible import specifier to the absolute URL of the source file.
@@ -95,18 +94,11 @@ export async function resolve(urlStr, context, next) {
9594
}
9695

9796
export async function load(urlStr, context, next) {
98-
const url = new URL(urlStr);
99-
if (url.pathname.endsWith(".ts")) {
100-
const { source } = await next(urlStr, { ...context, format: "module" });
101-
return {
102-
source: transform(source.toString("utf-8"), {
103-
transforms: ["typescript"],
104-
disableESTransforms: true,
105-
filePath: fileURLToPath(url),
106-
}).code,
107-
format: "module",
108-
};
109-
} else {
110-
return next(urlStr, context);
97+
if (!process.features.typescript) {
98+
const url = new URL(urlStr);
99+
if (url.pathname.endsWith(".ts")) {
100+
context = { ...context, format: "module-typescript" };
101+
}
111102
}
103+
return next(urlStr, context);
112104
}

packages/ts-loader/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@
22
"name": "@node-core/caritat-ts-loader",
33
"private": true,
44
"version": "0.0.0",
5-
"type": "module",
6-
"dependencies": {
7-
"sucrase": "^3.0.0"
8-
}
5+
"type": "module"
96
}

0 commit comments

Comments
 (0)