Skip to content

Commit 3da25a0

Browse files
committed
fix: export types as d.ts instead of d.{cts,mts}
The esm / export map support in TS is still experimental and doesn't seem to work at all. https://www.typescriptlang.org/docs/handbook/esm-node.html#new-file-extensions
1 parent ea4dff2 commit 3da25a0

File tree

9 files changed

+65
-42
lines changed

9 files changed

+65
-42
lines changed

.github/workflows/push.yml

+27-11
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,53 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v3
10-
- uses: actions/setup-go@v3
11-
- uses: actions/setup-node@v3
12-
- run: yarn install
13-
- run: make build
14-
- run: yarn test
10+
11+
- name: Setup Go
12+
uses: actions/setup-go@v3
13+
14+
- name: Setup Node
15+
uses: actions/setup-node@v3
16+
17+
- name: Install dependencies
18+
run: yarn install
19+
20+
- name: Build
21+
run: make build
22+
23+
- name: Test
24+
run: yarn test
25+
1526
- name: Integration test
1627
run: |
1728
dir=$(pwd)
1829
tmp=$(mktemp -d)
1930
2031
yarn pack
21-
cd $tmp
32+
cd "$tmp" || exit 1
2233
yarn init -y
23-
yarn add "$dir/actionlint-v0.0.0.tgz"
34+
yarn add "$dir/actionlint-v0.0.0.tgz" typescript @types/node
2435
2536
# verify package exports
2637
ls -la "node_modules/actionlint/$(jq ".exports.types" -r node_modules/actionlint/package.json)"
2738
ls -la "node_modules/actionlint/$(jq ".exports.node.import" -r node_modules/actionlint/package.json)"
2839
ls -la "node_modules/actionlint/$(jq ".exports.node.require" -r node_modules/actionlint/package.json)"
2940
ls -la "node_modules/actionlint/$(jq ".exports.browser" -r node_modules/actionlint/package.json)"
3041
31-
cat << EOF > test.js
32-
const linter = require('actionlint').createLinter();
33-
linter('on: psuh', 'push.yml').then(
42+
cat << EOF > test.mjs
43+
import { createLinter } from 'actionlint';
44+
createLinter()('on: psuh', 'push.yml').then(
3445
(results) => process.exit(results.length > 0 ? 0 : 1),
3546
(err) => { console.error(err); process.exit(1); }
3647
);
3748
EOF
3849
3950
# test that the linter works
40-
node test.js
51+
node test.mjs
52+
53+
# test that the types are correctly included
54+
mv test.mjs test.ts
55+
yarn tsc --noEmit --strict ./test.ts
56+
4157
- name: release
4258
if: github.ref == 'refs/heads/main'
4359
run: npx --yes semantic-release --branches main

.npmignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.github/
2+
.vscode/
3+
go.mod
4+
go.sum
5+
globals.d.ts
6+
main.go
7+
Makefile
8+
renovate.json
9+
test.mjs
10+
tsconfig.json
11+
yarn.lock

actionlint.cjs

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ require("./wasm_exec.js");
22

33
/**
44
* @typedef {(go: Go) => Promise<WebAssembly.WebAssemblyInstantiatedSource>} WasmLoader
5-
* @typedef {(source: string, path: string) => Promise<LintResult[]>} RunActionlint
6-
*
7-
* @typedef {Object} LintResult
8-
* @property {string} Message
9-
* @property {string} Filepath
10-
* @property {number} Line
11-
* @property {number} Column
12-
* @property {string} Kind
5+
* @typedef {import("./types").RunActionlint} RunActionlint
6+
* @typedef {import("./types").LintResult} LintResult
137
*/
148

159
/**

browser.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { createActionlint } from "./actionlint.cjs";
22

33
/**
4-
* @typedef {import("./actionlint.cjs").LintResult} LintResult
5-
* @typedef {import("./actionlint.cjs").WasmLoader} WasmLoader
6-
* @typedef {import("./actionlint.cjs").RunActionlint} RunActionlint
4+
* @typedef {(go: Go) => Promise<WebAssembly.WebAssemblyInstantiatedSource>} WasmLoader
5+
* @typedef {import("./types").RunActionlint} RunActionlint
6+
* @typedef {import("./types").LintResult} LintResult
77
*/
88

99
/** @type {RunActionlint | undefined} */

node.cjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const { readFile } = require("node:fs/promises");
44
const { createActionlint } = require("./actionlint.cjs");
55

66
/**
7-
* @typedef {import("./actionlint.cjs").LintResult} LintResult
8-
* @typedef {import("./actionlint.cjs").WasmLoader} WasmLoader
9-
* @typedef {import("./actionlint.cjs").RunActionlint} RunActionlint
7+
* @typedef {(go: Go) => Promise<WebAssembly.WebAssemblyInstantiatedSource>} WasmLoader
8+
* @typedef {import("./types").RunActionlint} RunActionlint
9+
* @typedef {import("./types").LintResult} LintResult
1010
*/
1111

1212
/** @type {RunActionlint | undefined} */

node.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { readFile } from "node:fs/promises";
22
import { createActionlint } from "./actionlint.cjs";
33

44
/**
5-
* @typedef {import("./actionlint.cjs").LintResult} LintResult
6-
* @typedef {import("./actionlint.cjs").WasmLoader} WasmLoader
7-
* @typedef {import("./actionlint.cjs").RunActionlint} RunActionlint
5+
* @typedef {(go: Go) => Promise<WebAssembly.WebAssemblyInstantiatedSource>} WasmLoader
6+
* @typedef {import("./types").RunActionlint} RunActionlint
7+
* @typedef {import("./types").LintResult} LintResult
88
*/
99

1010
/** @type {RunActionlint | undefined} */

package.json

+2-10
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,15 @@
77
"test": "tape test.mjs | tap-spec"
88
},
99
"main": "./node.cjs",
10+
"types": "./types.d.ts",
1011
"exports": {
11-
"types": "./types/node.d.mts",
12+
"types": "./types.d.ts",
1213
"node": {
1314
"import": "./node.mjs",
1415
"require": "./node.cjs"
1516
},
1617
"browser": "./browser.mjs"
1718
},
18-
"files": [
19-
"actionlint.cjs",
20-
"browser.mjs",
21-
"main.wasm",
22-
"node.cjs",
23-
"node.mjs",
24-
"types/node.d.mts",
25-
"wasm_exec.js"
26-
],
2719
"devDependencies": {
2820
"@types/golang-wasm-exec": "^1.15.0",
2921
"@types/node": "^17.0.21",

tsconfig.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99
"moduleResolution": "node",
1010
"allowJs": true,
1111
"checkJs": true,
12-
"declaration": true,
13-
"emitDeclarationOnly": true,
12+
"noEmit": true,
1413
"esModuleInterop": true,
1514
"forceConsistentCasingInFileNames": true,
1615
"strict": true,
17-
"skipLibCheck": true,
18-
"outDir": "./types"
16+
"skipLibCheck": true
1917
}
2018
}

types.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export type RunActionlint = (
2+
source: string,
3+
path: string
4+
) => Promise<LintResult[]>;
5+
export type LintResult = {
6+
Message: string;
7+
Filepath: string;
8+
Line: number;
9+
Column: number;
10+
Kind: string;
11+
};
12+
export function createLinter(url?: URL): RunActionlint;

0 commit comments

Comments
 (0)