Skip to content

Commit 60ec499

Browse files
committed
Fix type-checking errors
1 parent 2b1a310 commit 60ec499

23 files changed

+2354
-2139
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@ node_modules
33
tmp
44
*.log
55
test/**/yarn.lock
6+
test/**/*.js
7+
test/**/*.js.map
8+
transforms/**/*.js
9+
transforms/**/*.js.map
10+
helpers/**/*.js
11+
helpers/**/*.js.map
12+
!**/__testfixtures__/**/*

helpers/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** Type predicate. Checks if the given value is a `Record<string, unknown>`. */
2+
export function isRecord<R extends Record<string, unknown>>(
3+
value: unknown
4+
): value is R {
5+
return value !== null && typeof value === 'object';
6+
}

package.json

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@
1212
},
1313
"homepage": "https://github.com/ember-codemods/ember-no-implicit-this-codemod#readme",
1414
"author": "",
15+
"files": [
16+
"/bin",
17+
"/helpers/**/*.js",
18+
"/transforms/no-implicit-this/index.js",
19+
"/transforms/no-implicit-this/helpers/**/*.js"
20+
],
1521
"scripts": {
1622
"release": "release-it",
1723
"prepublishOnly": "yarn build",
18-
"postpublish": "yarn clean",
1924
"build": "tsc",
2025
"clean": "tsc --build --clean",
2126
"test": "jest",
27+
"pretest:integration": "yarn build",
2228
"test:integration": "ts-node ./test/run-test.ts",
2329
"update-docs": "codemod-cli update-docs",
2430
"coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls",
@@ -36,16 +42,21 @@
3642
"codemod-cli"
3743
],
3844
"dependencies": {
39-
"codemod-cli": "^2.1.0",
45+
"@babel/core": "^7.21.8",
46+
"@babel/preset-env": "^7.21.5",
47+
"codemod-cli": "^3.2.0",
4048
"debug": "^4.1.1",
4149
"ember-codemods-telemetry-helpers": "^2.1.0",
42-
"ember-template-recast": "^3.3.2"
50+
"ember-template-recast": "^6.1.4",
51+
"zod": "^3.21.4"
4352
},
4453
"devDependencies": {
4554
"@tsconfig/node16": "^1.0.4",
4655
"@tsconfig/strictest": "^2.0.1",
4756
"@types/chalk": "^2.2.0",
4857
"@types/common-tags": "^1.8.0",
58+
"@types/debug": "^4.1.8",
59+
"@types/jscodeshift": "^0.11.6",
4960
"@types/node": "^20.2.3",
5061
"@typescript-eslint/eslint-plugin": "^5.59.7",
5162
"@typescript-eslint/parser": "^5.59.7",
@@ -57,10 +68,11 @@
5768
"eslint-config-prettier": "^6.15.0",
5869
"eslint-plugin-prettier": "^3.4.0",
5970
"execa": "^3.4.0",
60-
"jest": "^26.6.3",
71+
"jest": "^29.1.0",
6172
"prettier": "^1.19.1",
6273
"release-it": "^14.6.2",
6374
"release-it-lerna-changelog": "^3.1.0",
75+
"ts-jest": "^29.1.0",
6476
"ts-node": "^10.9.1",
6577
"typescript": "~5.0.4"
6678
},
@@ -69,8 +81,9 @@
6981
},
7082
"jest": {
7183
"testEnvironment": "node",
84+
"preset": "ts-jest",
7285
"testMatch": [
73-
"<rootDir>/transforms/**/test.js"
86+
"<rootDir>/transforms/**/test.{js,ts}"
7487
]
7588
},
7689
"publishConfig": {

test/helpers/sequence.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ export async function runTestIntegrationSequence(version: string) {
2323

2424
log(`Comparing Results`);
2525
await runner.compare();
26+
log(`Success`);
2627
}

test/helpers/test-runner.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import path from 'path';
21
import execa, { CommonOptions } from 'execa';
3-
import { log, timeoutAfter, kill, error } from './utils';
2+
import path from 'node:path';
3+
import { kill, timeoutAfter } from './utils';
4+
import { isRecord } from '../../helpers/types';
45

56
const devServerTimeout = 60000;
67

@@ -37,13 +38,13 @@ export class TestRunner {
3738
},
3839
});
3940

40-
if (process.env.DEBUG) {
41-
emberServe.stdout.pipe(process.stdout);
42-
emberServe.stderr.pipe(process.stderr);
41+
if (process.env['DEBUG']) {
42+
emberServe.stdout?.pipe(process.stdout);
43+
emberServe.stderr?.pipe(process.stderr);
4344
}
4445

45-
const serverWaiter = new Promise(resolve => {
46-
emberServe.stdout.on('data', data => {
46+
const serverWaiter = new Promise<void>(resolve => {
47+
emberServe.stdout?.on('data', data => {
4748
if (data.toString().includes('Build successful')) {
4849
resolve();
4950
}
@@ -61,7 +62,10 @@ export class TestRunner {
6162
}
6263

6364
async stopEmber(): Promise<void> {
64-
await timeoutAfter(devServerTimeout, kill(this.emberProcess));
65+
const { emberProcess } = this;
66+
if (emberProcess) {
67+
await timeoutAfter(devServerTimeout, kill(emberProcess));
68+
}
6569
}
6670

6771
async compare() {
@@ -71,7 +75,7 @@ export class TestRunner {
7175

7276
await execa('diff', ['-rq', actual, expectedApp], { cwd: this.inputDir, stdio: 'inherit' });
7377
} catch (e) {
74-
console.log(e.stdout);
78+
console.log(isRecord(e) ? e['stdout']: 'codemod did not run successfully');
7579

7680
throw new Error('codemod did not run successfully');
7781
}

test/helpers/utils.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import chalk from 'chalk';
22
import execa from 'execa';
3+
import { isRecord } from '../../helpers/types';
34

4-
export function log(msg: string): void {
5+
export function log(msg: unknown): void {
56
console.log(chalk.yellowBright(msg));
67
}
78

8-
export function error(msg: string): void {
9+
export function error(msg: unknown): void {
910
console.error(chalk.redBright(msg));
1011
}
1112

@@ -20,8 +21,8 @@ export function timeoutAfter<T>(ms: number, promise: Promise<T>) {
2021
return Promise.race([promise, timeout]);
2122
}
2223

23-
export async function kill(subprocess: execa.ExecaChildProcess) {
24-
if (!subprocess) {
24+
export async function kill(subprocess: execa.ExecaChildProcess): Promise<void> {
25+
if (!subprocess || !subprocess.pid) {
2526
throw new Error('Cannot kill non-running process');
2627
}
2728

@@ -32,7 +33,7 @@ export async function kill(subprocess: execa.ExecaChildProcess) {
3233
} catch (e) {
3334
console.log(`PID ${subprocess.pid} has stopped.`);
3435
console.log(`\tKilled: ${subprocess.killed}`);
35-
console.log(`\tCancelled: ${e.isCanceled}`);
36+
console.log(`\tCancelled: ${isRecord(e) ? e['isCanceled']: 'unknown'}`);
3637
}
3738

3839
return new Promise(resolve => {

test/run-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { runTestIntegrationSequence } from './helpers/sequence';
88
const allVersions = ['3.10', '3.13'];
99

1010
(async (): Promise<void> => {
11-
const emberVersion = process.env.EMBER_VERSION;
11+
const emberVersion = process.env['EMBER_VERSION'];
1212

1313
if (!emberVersion) {
1414
console.error(`No EMBER_VERSION set. No scenarios to run.`);
@@ -23,7 +23,7 @@ const allVersions = ['3.10', '3.13'];
2323
let didSucceed = false;
2424

2525
try {
26-
process.env.DEBUG = 'true'; // hacks for now
26+
process.env['DEBUG'] = 'true'; // hacks for now
2727
await runTestIntegrationSequence(emberVersion);
2828
didSucceed = true;
2929
} catch (e) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type Telemetry = Record<string, Record<string, unknown>>;
2+
3+
declare const telemetry: Telemetry;
4+
5+
export default telemetry;

transforms/no-implicit-this/babel-config.ts

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

transforms/no-implicit-this/helpers/known-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ const KNOWN_HELPERS = [
4040
'-get-dynamic-var', // glimmer internal helper
4141
];
4242

43-
module.exports = KNOWN_HELPERS;
43+
export default KNOWN_HELPERS;

0 commit comments

Comments
 (0)