Skip to content

Commit f82082c

Browse files
committed
fix: migrate to esm module
In order to use dependencies that are esm modules (which `@actions/*` just did), we have to be an esm module ourselves. Note that this doesn't work yet; esm modules break jest's mocking. This'll be addressed in future commits.
1 parent 74b3a85 commit f82082c

18 files changed

Lines changed: 67 additions & 39 deletions

jest.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { createDefaultPreset } from "ts-jest";
2+
3+
const presetConfig = createDefaultPreset();
4+
5+
const jestConfig = {
6+
...presetConfig,
7+
resetMocks: true,
8+
testEnvironment: "node",
9+
extensionsToTreatAsEsm: [".ts"],
10+
moduleNameMapper: {
11+
"^(\\.{1,2}/.*)\\.js$": "$1",
12+
},
13+
transform: {
14+
"^.+\\.ts$": [
15+
"ts-jest",
16+
{
17+
useESM: true,
18+
},
19+
],
20+
},
21+
};
22+
23+
export default jestConfig;

jest.config.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "stack-action",
33
"version": "0.0.0",
4+
"type": "module",
45
"description": "Build and test stack-based Haskell projects",
56
"main": "lib/main.js",
67
"scripts": {
78
"build": "tsc && ncc build lib/main.js && sed -i 's/\\x0D$//' ./dist/index.js",
89
"format": "prettier --write \"**/*.ts\"",
910
"format-check": "prettier --check \"**/*.ts\"",
10-
"test": "jest",
11+
"test": "NODE_OPTIONS='--experimental-vm-modules' jest",
1112
"readme": "npx action-docs -u && prettier --write README.md"
1213
},
1314
"repository": {

src/dirty-files.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { parseGitStatus, isInterestingFile } from "./dirty-files";
1+
import { jest } from "@jest/globals";
2+
3+
import { parseGitStatus, isInterestingFile } from "./dirty-files.js";
24

35
describe("parseGitStatus", () => {
46
test("parse file name, and filters untracked", () => {

src/envsubst.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { envsubst } from "./envsubst";
1+
import { jest } from "@jest/globals";
2+
3+
import { envsubst } from "./envsubst.js";
24

35
const HOME = process.env.HOME;
46

src/get-cache-keys.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { getCacheKeys } from "./get-cache-keys";
1+
import { jest } from "@jest/globals";
2+
3+
import { getCacheKeys } from "./get-cache-keys.js";
24

35
test("getCacheKeys", () => {
46
const keys = getCacheKeys(["prefix-os-compiler", "package", "source"]);

src/hie.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from "fs";
22
import * as core from "@actions/core";
33

4-
import { StackCLI } from "./stack-cli";
4+
import { StackCLI } from "./stack-cli.js"
55

66
export const HIE_YAML: string = "hie.yaml";
77

src/inputs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as core from "@actions/core";
22
import * as Shellwords from "shellwords-ts";
3-
import { envsubst } from "./envsubst";
4-
import { type OnDirtyFiles, parseOnDirtyFiles } from "./dirty-files";
3+
import { envsubst } from "./envsubst.js"
4+
import { type OnDirtyFiles, parseOnDirtyFiles } from "./dirty-files.js"
55

66
export type Inputs = {
77
workingDirectory: string | null;

src/main.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as core from "@actions/core";
22

3-
import { checkDirtyFiles } from "./dirty-files";
4-
import { StackCLI } from "./stack-cli";
5-
import { getCacheKeys } from "./get-cache-keys";
6-
import { hashProject } from "./hash-project";
7-
import { getInputs } from "./inputs";
8-
import { readStackYamlSync, getStackDirectories } from "./stack-yaml";
9-
import { DEFAULT_CACHE_OPTIONS, withCache } from "./with-cache";
10-
import { GenHIE } from "./hie";
3+
import { checkDirtyFiles } from "./dirty-files.js"
4+
import { StackCLI } from "./stack-cli.js"
5+
import { getCacheKeys } from "./get-cache-keys.js"
6+
import { hashProject } from "./hash-project.js"
7+
import { getInputs } from "./inputs.js"
8+
import { readStackYamlSync, getStackDirectories } from "./stack-yaml.js"
9+
import { DEFAULT_CACHE_OPTIONS, withCache } from "./with-cache.js"
10+
import { GenHIE } from "./hie.js"
1111

1212
async function run() {
1313
try {

src/parse-stack-path.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { parseStackPath } from "./parse-stack-path";
1+
import { jest } from "@jest/globals";
2+
3+
import { parseStackPath } from "./parse-stack-path.js";
24

35
const EXAMPLE = [
46
"snapshot-doc-root: /home/patrick/.stack/snapshots/x86_64-linux-tinfo6/0dd02c1d8a380045321779c4567c2aa8873910743eac342f72d56f3d26881028/9.2.7/doc",

0 commit comments

Comments
 (0)