Skip to content

Commit 9c12675

Browse files
committed
add compile command
1 parent 63257a8 commit 9c12675

File tree

6 files changed

+61
-21
lines changed

6 files changed

+61
-21
lines changed

β€Žpackages/tester/ts/app.tsβ€Ž

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { compile } from 'handlebars'
33
import { parse } from 'json5'
44
import fs from 'node:fs'
55
import path from 'node:path'
6-
import { context } from 'type-plus'
6+
import { context, forEachKey } from 'type-plus'
77
import { getProjectPath, getTestSubjects, readPackageJson } from './logic/project'
8-
import { genTestResults, getTestResults } from './testResults'
8+
import { genTestResults, runCompile, runCompileAndRuntimeTests } from './testResults'
99

1010
export const app = cli({ name: 'tester', version: '0.0.1' })
1111
.default({
@@ -19,7 +19,7 @@ export const app = cli({ name: 'tester', version: '0.0.1' })
1919
.extend(readPackageJson)
2020
.extend(getTypeScriptInfo)
2121
.extend(getTestSubjects)
22-
.extend(getTestResults)
22+
.extend(runCompileAndRuntimeTests)
2323
.build()
2424

2525
fs.writeFileSync(
@@ -31,6 +31,37 @@ export const app = cli({ name: 'tester', version: '0.0.1' })
3131
)
3232
}
3333
})
34+
.command({
35+
name: 'compile',
36+
arguments: [{ name: 'project', description: 'project name', required: true }],
37+
async run({ project }) {
38+
const ctx = context({
39+
project,
40+
moduleTypes: ['commonjs', 'es2015', 'es2020', 'es2022', 'esnext', 'node16', 'nodenext']
41+
})
42+
.extend(getProjectPath)
43+
.extend(readPackageJson)
44+
.extend(getTypeScriptInfo)
45+
.extend(getTestSubjects)
46+
.extend(runCompile)
47+
.build()
48+
49+
const result = await ctx.compile
50+
51+
const lines: string[][] = []
52+
forEachKey(result, (moduleType) => {
53+
const moduleResults = result[moduleType]
54+
forEachKey(moduleResults, (subject) => {
55+
const compileResults = moduleResults[subject]
56+
compileResults.forEach(result => {
57+
lines.push([moduleType.padEnd(8), subject.padEnd(10), result.importType.padEnd(10), result.transient ? 'transient' : 'direct ', `TS${result.code}`, result.messageText])
58+
})
59+
})
60+
})
61+
lines.sort((a, b) => a[0] > b[0] ? 1 : (a[0] < b[0] ? -1 : (a[1] > b[1] ? 1 : -1)))
62+
lines.map(l => this.ui.error(l.join(' | ')))
63+
}
64+
})
3465

3566
function getTypeScriptInfo(ctx: { packageJson: any, projectPath: string }) {
3667
const tsconfigPath = path.join(ctx.projectPath, 'tsconfig.base.json')

β€Žpackages/tester/ts/logic/project.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function toImportMapEntry(results: Array<{
103103
value?: string,
104104
transient?: boolean
105105
}> | undefined, importType: string) {
106-
const entry = results?.find(r => r.importType === importType)
106+
const entry = results?.find(r => r.importType === importType || r.importType === 'all')
107107
if (entry) {
108108
if (entry.notApply) {
109109
return {

β€Žpackages/tester/ts/testResults.tsβ€Ž

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ import { getTestSubjects, toImportMap } from './logic/project'
77
import { RuntimeResult, runProject } from './logic/runtime'
88
import { reduceFlatMessage } from './logic/utils'
99

10-
export function getTestResults(ctx: {
10+
export function runCompile(ctx: {
11+
project: string,
12+
projectPath: string,
13+
}) {
14+
return {
15+
compile: compileProject(ctx)
16+
}
17+
}
18+
19+
export function runCompileAndRuntimeTests(ctx: {
1120
project: string,
1221
moduleTypes: string[],
1322
projectPath: string,
@@ -27,7 +36,7 @@ export function getTestResults(ctx: {
2736
}
2837

2938
type TestSubjectsContext = ReturnType<typeof getTestSubjects>
30-
type TestResultsContext = AwaitedProp<ReturnType<typeof getTestResults>, 'results'>
39+
type TestResultsContext = AwaitedProp<ReturnType<typeof runCompileAndRuntimeTests>, 'results'>
3140

3241
export function genTestResults(
3342
ctx: TestSubjectsContext & TestResultsContext) {

β€Žtests/node/README.mdβ€Ž

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ m.default(1)
8989
```
9090

9191
## Legends
92-
:green
92+
9393
- 🟒: both compile and runtime are working correctly
9494
- 🟑: for compile, it means there is an error, but can be suppressed (e.g. with `skipLibCheck`)\
9595
for runtime, it means the compile fails, but runtime is working
@@ -111,8 +111,6 @@ Import Syntax:
111111
| | | πŸƒ Runtime | πŸ”΄ not-fn | πŸ”΄ not-fn | 🟒 |
112112
| | assertron | πŸ’» Compile | 🟑 TS1259-t | 🟑 TS1259-t | 🟑 TS1259-t |
113113
| | | πŸƒ Runtime | 🟑 | 🟑 | 🟑 |
114-
| | param-case | πŸ’» Compile | πŸ”΄ TS1259-e | πŸ”΄ TS1259-e | πŸ”΄ TS2497-e TS2339 |
115-
| | | πŸƒ Runtime | πŸ”΄ not-fn | πŸ”΄ not-fn | πŸ”΄ not-fn |
116114
| | cjs | πŸ’» Compile | 🟒 | 🟒 | 🟒 |
117115
| | | πŸƒ Runtime | 🟒 | 🟒 | 🟒 |
118116
| | es-cjs | πŸ’» Compile | 🟒 | 🟒 | 🟒 |
@@ -121,12 +119,12 @@ Import Syntax:
121119
| | | πŸƒ Runtime | βž– | βž– | βž– |
122120
| | esm-cjs | πŸ’» Compile | 🟒 | 🟒 | 🟒 |
123121
| | | πŸƒ Runtime | 🟒 | 🟒 | 🟒 |
122+
| | param-case | πŸ’» Compile | πŸ”΄ TS1259-e | πŸ”΄ TS1259-e | πŸ”΄ TS2497-e TS2339 |
123+
| | | πŸƒ Runtime | πŸ”΄ not-fn | πŸ”΄ not-fn | πŸ”΄ not-fn |
124124
| ES* | assert | πŸ’» Compile | πŸ”΄ TS1259-a | πŸ”΄ TS1259-a | 🟒 |
125125
| | | πŸƒ Runtime | 🟑 | 🟑 | ❌ not-fn |
126126
| | assertron | πŸ’» Compile | 🟑 TS1259-t | 🟑 TS1259-t | 🟑 TS1259-t |
127127
| | | πŸƒ Runtime | ❌ not-fn | ❌ not-fn | ❌ not-fn |
128-
| | param-case | πŸ’» Compile | πŸ”΄ TS1259-a | πŸ”΄ TS1259-a | πŸ”΄ TS2497-a TS2339 |
129-
| | | πŸƒ Runtime | 🟑 | 🟑 | 🟑 |
130128
| | cjs | πŸ’» Compile | 🟒 | 🟒 | 🟒 |
131129
| | | πŸƒ Runtime | ❌ not-fn | ❌ not-fn | ❌ not-fn |
132130
| | es-cjs | πŸ’» Compile | 🟒 | 🟒 | 🟒 |
@@ -135,12 +133,12 @@ Import Syntax:
135133
| | | πŸƒ Runtime | βž– | βž– | βž– |
136134
| | esm-cjs | πŸ’» Compile | 🟒 | 🟒 | 🟒 |
137135
| | | πŸƒ Runtime | 🟒 | 🟒 | 🟒 |
136+
| | param-case | πŸ’» Compile | πŸ”΄ TS1259-a | πŸ”΄ TS1259-a | πŸ”΄ TS2497-a TS2339 |
137+
| | | πŸƒ Runtime | 🟑 | 🟑 | 🟑 |
138138
| Node* | assert | πŸ’» Compile | ❌ to-cjs | ❌ to-cjs | ❌ to-cjs |
139139
| | | πŸƒ Runtime | ❌ ref-err | ❌ ref-err | ❌ ref-err |
140140
| | assertron | πŸ’» Compile | ❌ to-cjs TS1259-t | ❌ to-cjs TS1259-t | ❌ to-cjs TS1259-t |
141141
| | | πŸƒ Runtime | ❌ ref-err | ❌ ref-err | ❌ ref-err |
142-
| | param-case | πŸ’» Compile | ❌ to-cjs | ❌ to-cjs | ❌ to-cjs |
143-
| | | πŸƒ Runtime | ❌ ref-err | ❌ ref-err | ❌ ref-err |
144142
| | cjs | πŸ’» Compile | ❌ to-cjs | ❌ to-cjs | ❌ to-cjs |
145143
| | | πŸƒ Runtime | ❌ ref-err | ❌ ref-err | ❌ ref-err |
146144
| | es-cjs | πŸ’» Compile | ❌ to-cjs | ❌ to-cjs | ❌ to-cjs |
@@ -149,6 +147,8 @@ Import Syntax:
149147
| | | πŸƒ Runtime | βž– | βž– | βž– |
150148
| | esm-cjs | πŸ’» Compile | ❌ to-cjs | ❌ to-cjs | ❌ to-cjs |
151149
| | | πŸƒ Runtime | ❌ ref-err | ❌ ref-err | ❌ ref-err |
150+
| | param-case | πŸ’» Compile | ❌ to-cjs | ❌ to-cjs | ❌ to-cjs |
151+
| | | πŸƒ Runtime | ❌ ref-err | ❌ ref-err | ❌ ref-err |
152152

153153
- to-cjs: Code are compiled to CJS incorrectly
154154
- TS1259-e: `TS1259: needs esModuleInterop`

β€Žtests/node/test-result.5.0.0-dev.20230103.mdβ€Ž

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Import Syntax:
214214
| -------- | ---------- | --------- | ------------------ | ----------------- | ----------------- |
215215
| commonjs | assert | πŸ’» compile | πŸ”΄ TS1259-e | 🟒 | 🟒 |
216216
| | | πŸƒ runtime | πŸ”΄ type-not-fn | πŸ”΄ type-not-fn | 🟒 |
217-
| | assertron | πŸ’» compile | 🟒 | 🟒 | πŸ”΄ TS2339 |
217+
| | assertron | πŸ’» compile | 🟑 TS1259-e-t | 🟑 TS1259-e-t | 🟑 TS1259-e-t |
218218
| | | πŸƒ runtime | 🟒 | 🟒 | πŸ”΄ type-not-fn-1 |
219219
| | cjs | πŸ’» compile | 🟒 | 🟒 | 🟒 |
220220
| | | πŸƒ runtime | 🟒 | 🟒 | 🟒 |
@@ -228,7 +228,7 @@ Import Syntax:
228228
| | | πŸƒ runtime | πŸ”΄ type-not-fn-2 | πŸ”΄ type-not-fn-2 | πŸ”΄ type-not-fn-3 |
229229
| es2015 | assert | πŸ’» compile | πŸ”΄ TS1259-a | 🟒 | 🟒 |
230230
| | | πŸƒ runtime | 🟒 | 🟒 | πŸ”΄ type-not-fn-4 |
231-
| | assertron | πŸ’» compile | 🟒 | 🟒 | πŸ”΄ TS2339 |
231+
| | assertron | πŸ’» compile | 🟑 TS1259-a-t | 🟑 TS1259-a-t | 🟑 TS1259-a-t |
232232
| | | πŸƒ runtime | πŸ”΄ type-not-fn-1 | πŸ”΄ type-not-fn-1 | πŸ”΄ type-not-fn-1 |
233233
| | cjs | πŸ’» compile | 🟒 | 🟒 | 🟒 |
234234
| | | πŸƒ runtime | πŸ”΄ type-not-fn-5 | πŸ”΄ type-not-fn-5 | πŸ”΄ type-not-fn-6 |
@@ -242,7 +242,7 @@ Import Syntax:
242242
| | | πŸƒ runtime | 🟒 | 🟒 | 🟒 |
243243
| es2020 | assert | πŸ’» compile | πŸ”΄ TS1259-a | 🟒 | 🟒 |
244244
| | | πŸƒ runtime | 🟒 | 🟒 | πŸ”΄ type-not-fn-4 |
245-
| | assertron | πŸ’» compile | 🟒 | 🟒 | πŸ”΄ TS2339 |
245+
| | assertron | πŸ’» compile | 🟑 TS1259-a-t | 🟑 TS1259-a-t | 🟑 TS1259-a-t |
246246
| | | πŸƒ runtime | πŸ”΄ type-not-fn-1 | πŸ”΄ type-not-fn-1 | πŸ”΄ type-not-fn-1 |
247247
| | cjs | πŸ’» compile | 🟒 | 🟒 | 🟒 |
248248
| | | πŸƒ runtime | πŸ”΄ type-not-fn-5 | πŸ”΄ type-not-fn-5 | πŸ”΄ type-not-fn-6 |
@@ -256,7 +256,7 @@ Import Syntax:
256256
| | | πŸƒ runtime | 🟒 | 🟒 | 🟒 |
257257
| es2022 | assert | πŸ’» compile | πŸ”΄ TS1259-a | 🟒 | 🟒 |
258258
| | | πŸƒ runtime | 🟒 | 🟒 | πŸ”΄ type-not-fn-4 |
259-
| | assertron | πŸ’» compile | 🟒 | 🟒 | πŸ”΄ TS2339 |
259+
| | assertron | πŸ’» compile | 🟑 TS1259-a-t | 🟑 TS1259-a-t | 🟑 TS1259-a-t |
260260
| | | πŸƒ runtime | πŸ”΄ type-not-fn-1 | πŸ”΄ type-not-fn-1 | πŸ”΄ type-not-fn-1 |
261261
| | cjs | πŸ’» compile | 🟒 | 🟒 | 🟒 |
262262
| | | πŸƒ runtime | πŸ”΄ type-not-fn-5 | πŸ”΄ type-not-fn-5 | πŸ”΄ type-not-fn-6 |
@@ -270,7 +270,7 @@ Import Syntax:
270270
| | | πŸƒ runtime | 🟒 | 🟒 | 🟒 |
271271
| esnext | assert | πŸ’» compile | πŸ”΄ TS1259-a | 🟒 | 🟒 |
272272
| | | πŸƒ runtime | 🟒 | 🟒 | πŸ”΄ type-not-fn-4 |
273-
| | assertron | πŸ’» compile | 🟒 | 🟒 | πŸ”΄ TS2339 |
273+
| | assertron | πŸ’» compile | 🟑 TS1259-a-t | 🟑 TS1259-a-t | 🟑 TS1259-a-t |
274274
| | | πŸƒ runtime | πŸ”΄ type-not-fn-1 | πŸ”΄ type-not-fn-1 | πŸ”΄ type-not-fn-1 |
275275
| | cjs | πŸ’» compile | 🟒 | 🟒 | 🟒 |
276276
| | | πŸƒ runtime | πŸ”΄ type-not-fn-5 | πŸ”΄ type-not-fn-5 | πŸ”΄ type-not-fn-6 |
@@ -284,7 +284,7 @@ Import Syntax:
284284
| | | πŸƒ runtime | 🟒 | 🟒 | 🟒 |
285285
| node16 | assert | πŸ’» compile | πŸ”΄ TS1259-a | 🟒 | 🟒 |
286286
| | | πŸƒ runtime | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined |
287-
| | assertron | πŸ’» compile | 🟒 | 🟒 | πŸ”΄ TS2339 |
287+
| | assertron | πŸ’» compile | 🟑 TS1259-a-t | 🟑 TS1259-a-t | 🟑 TS1259-a-t |
288288
| | | πŸƒ runtime | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined |
289289
| | cjs | πŸ’» compile | 🟒 | 🟒 | 🟒 |
290290
| | | πŸƒ runtime | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined |
@@ -298,7 +298,7 @@ Import Syntax:
298298
| | | πŸƒ runtime | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined |
299299
| nodenext | assert | πŸ’» compile | πŸ”΄ TS1259-a | 🟒 | 🟒 |
300300
| | | πŸƒ runtime | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined |
301-
| | assertron | πŸ’» compile | 🟒 | 🟒 | πŸ”΄ TS2339 |
301+
| | assertron | πŸ’» compile | 🟑 TS1259-a-t | 🟑 TS1259-a-t | 🟑 TS1259-a-t |
302302
| | | πŸƒ runtime | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined |
303303
| | cjs | πŸ’» compile | 🟒 | 🟒 | 🟒 |
304304
| | | πŸƒ runtime | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined | πŸ”΄ ref-not-defined |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import * as assertron from 'assertron'
22

3-
assertron.truthy(true)
3+
assertron.default.truthy(true)

0 commit comments

Comments
Β (0)