Skip to content

Commit ae8092e

Browse files
committed
chore: update build script
There were some necessary changes to make the code compatible with tsdown bundling: 1. Replace CJS require with ESM import 2. Replace CJS export with ESM default export 3. Type all node-type guards explicitly to avoid "This is likely not portable. A type annotation is necessary" errors
1 parent 3901286 commit ae8092e

File tree

11 files changed

+95
-176
lines changed

11 files changed

+95
-176
lines changed

lib/configs/angular.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import type { Linter } from 'eslint';
66

7-
export = {
7+
export default {
88
plugins: ['testing-library'],
99
rules: {
1010
'testing-library/await-async-events': [

lib/configs/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import type { Linter } from 'eslint';
66

7-
export = {
7+
export default {
88
plugins: ['testing-library'],
99
rules: {
1010
'testing-library/await-async-events': [

lib/configs/marko.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import type { Linter } from 'eslint';
66

7-
export = {
7+
export default {
88
plugins: ['testing-library'],
99
rules: {
1010
'testing-library/await-async-events': [

lib/configs/react.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import type { Linter } from 'eslint';
66

7-
export = {
7+
export default {
88
plugins: ['testing-library'],
99
rules: {
1010
'testing-library/await-async-events': [

lib/configs/svelte.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import type { Linter } from 'eslint';
66

7-
export = {
7+
export default {
88
plugins: ['testing-library'],
99
rules: {
1010
'testing-library/await-async-events': [

lib/configs/vue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import type { Linter } from 'eslint';
66

7-
export = {
7+
export default {
88
plugins: ['testing-library'],
99
rules: {
1010
'testing-library/await-async-events': [

lib/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { legacyConfigs } from './configs';
22
import rules from './rules';
3+
import {
4+
name as packageName,
5+
version as packageVersion,
6+
} from '../package.json';
37

48
import type { SupportedTestingFramework } from './utils';
59
import type { TSESLint } from '@typescript-eslint/utils';
610

7-
const {
8-
name: packageName,
9-
version: packageVersion,
10-
// we can't natively import package.json as tsc will copy it into dist/
11-
// eslint-disable-next-line @typescript-eslint/no-require-imports
12-
} = require('../package.json') as { name: string; version: string };
13-
1411
type FinalConfigs = Record<
1512
SupportedTestingFramework | `flat/${SupportedTestingFramework}`,
1613
TSESLint.ClassicConfig.Config | TSESLint.FlatConfig.Config

lib/node-utils/is-node-of-type.ts

Lines changed: 83 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,87 @@
11
import { AST_NODE_TYPES, ASTUtils } from '@typescript-eslint/utils';
22

3-
export const isArrayExpression = ASTUtils.isNodeOfType(
4-
AST_NODE_TYPES.ArrayExpression
5-
);
6-
export const isArrowFunctionExpression = ASTUtils.isNodeOfType(
7-
AST_NODE_TYPES.ArrowFunctionExpression
8-
);
9-
export const isBlockStatement = ASTUtils.isNodeOfType(
10-
AST_NODE_TYPES.BlockStatement
11-
);
12-
export const isCallExpression = ASTUtils.isNodeOfType(
13-
AST_NODE_TYPES.CallExpression
14-
);
15-
export const isExpressionStatement = ASTUtils.isNodeOfType(
16-
AST_NODE_TYPES.ExpressionStatement
17-
);
18-
export const isVariableDeclaration = ASTUtils.isNodeOfType(
19-
AST_NODE_TYPES.VariableDeclaration
20-
);
21-
export const isAssignmentExpression = ASTUtils.isNodeOfType(
22-
AST_NODE_TYPES.AssignmentExpression
23-
);
24-
export const isChainExpression = ASTUtils.isNodeOfType(
25-
AST_NODE_TYPES.ChainExpression
26-
);
27-
export const isSequenceExpression = ASTUtils.isNodeOfType(
28-
AST_NODE_TYPES.SequenceExpression
29-
);
30-
export const isImportDeclaration = ASTUtils.isNodeOfType(
31-
AST_NODE_TYPES.ImportDeclaration
32-
);
33-
export const isImportDefaultSpecifier = ASTUtils.isNodeOfType(
34-
AST_NODE_TYPES.ImportDefaultSpecifier
35-
);
36-
export const isTSImportEqualsDeclaration = ASTUtils.isNodeOfType(
37-
AST_NODE_TYPES.TSImportEqualsDeclaration
38-
);
39-
export const isImportExpression = ASTUtils.isNodeOfType(
40-
AST_NODE_TYPES.ImportExpression
41-
);
42-
export const isImportNamespaceSpecifier = ASTUtils.isNodeOfType(
43-
AST_NODE_TYPES.ImportNamespaceSpecifier
44-
);
45-
export const isImportSpecifier = ASTUtils.isNodeOfType(
46-
AST_NODE_TYPES.ImportSpecifier
47-
);
48-
export const isJSXAttribute = ASTUtils.isNodeOfType(
49-
AST_NODE_TYPES.JSXAttribute
50-
);
51-
export const isLiteral = ASTUtils.isNodeOfType(AST_NODE_TYPES.Literal);
52-
export const isTemplateLiteral = ASTUtils.isNodeOfType(
53-
AST_NODE_TYPES.TemplateLiteral
54-
);
55-
export const isMemberExpression = ASTUtils.isNodeOfType(
56-
AST_NODE_TYPES.MemberExpression
57-
);
58-
export const isNewExpression = ASTUtils.isNodeOfType(
59-
AST_NODE_TYPES.NewExpression
60-
);
61-
export const isObjectExpression = ASTUtils.isNodeOfType(
62-
AST_NODE_TYPES.ObjectExpression
63-
);
64-
export const isObjectPattern = ASTUtils.isNodeOfType(
65-
AST_NODE_TYPES.ObjectPattern
66-
);
67-
export const isProperty = ASTUtils.isNodeOfType(AST_NODE_TYPES.Property);
68-
export const isReturnStatement = ASTUtils.isNodeOfType(
69-
AST_NODE_TYPES.ReturnStatement
70-
);
71-
export const isFunctionExpression = ASTUtils.isNodeOfType(
72-
AST_NODE_TYPES.FunctionExpression
3+
import type { TSESTree } from '@typescript-eslint/utils';
4+
5+
// Explicit type for all node-type guards to avoid leaking non-portable inferred types
6+
type NodeGuard<T extends TSESTree.Node> = (
7+
node: TSESTree.Node | null | undefined
8+
) => node is T;
9+
10+
export const isArrayExpression: NodeGuard<TSESTree.ArrayExpression> =
11+
ASTUtils.isNodeOfType(AST_NODE_TYPES.ArrayExpression);
12+
13+
export const isArrowFunctionExpression: NodeGuard<TSESTree.ArrowFunctionExpression> =
14+
ASTUtils.isNodeOfType(AST_NODE_TYPES.ArrowFunctionExpression);
15+
16+
export const isBlockStatement: NodeGuard<TSESTree.BlockStatement> =
17+
ASTUtils.isNodeOfType(AST_NODE_TYPES.BlockStatement);
18+
19+
export const isCallExpression: NodeGuard<TSESTree.CallExpression> =
20+
ASTUtils.isNodeOfType(AST_NODE_TYPES.CallExpression);
21+
22+
export const isExpressionStatement: NodeGuard<TSESTree.ExpressionStatement> =
23+
ASTUtils.isNodeOfType(AST_NODE_TYPES.ExpressionStatement);
24+
25+
export const isVariableDeclaration: NodeGuard<TSESTree.VariableDeclaration> =
26+
ASTUtils.isNodeOfType(AST_NODE_TYPES.VariableDeclaration);
27+
28+
export const isAssignmentExpression: NodeGuard<TSESTree.AssignmentExpression> =
29+
ASTUtils.isNodeOfType(AST_NODE_TYPES.AssignmentExpression);
30+
31+
export const isChainExpression: NodeGuard<TSESTree.ChainExpression> =
32+
ASTUtils.isNodeOfType(AST_NODE_TYPES.ChainExpression);
33+
34+
export const isSequenceExpression: NodeGuard<TSESTree.SequenceExpression> =
35+
ASTUtils.isNodeOfType(AST_NODE_TYPES.SequenceExpression);
36+
37+
export const isImportDeclaration: NodeGuard<TSESTree.ImportDeclaration> =
38+
ASTUtils.isNodeOfType(AST_NODE_TYPES.ImportDeclaration);
39+
40+
export const isImportDefaultSpecifier: NodeGuard<TSESTree.ImportDefaultSpecifier> =
41+
ASTUtils.isNodeOfType(AST_NODE_TYPES.ImportDefaultSpecifier);
42+
43+
export const isTSImportEqualsDeclaration: NodeGuard<TSESTree.TSImportEqualsDeclaration> =
44+
ASTUtils.isNodeOfType(AST_NODE_TYPES.TSImportEqualsDeclaration);
45+
46+
export const isImportExpression: NodeGuard<TSESTree.ImportExpression> =
47+
ASTUtils.isNodeOfType(AST_NODE_TYPES.ImportExpression);
48+
49+
export const isImportNamespaceSpecifier: NodeGuard<TSESTree.ImportNamespaceSpecifier> =
50+
ASTUtils.isNodeOfType(AST_NODE_TYPES.ImportNamespaceSpecifier);
51+
52+
export const isImportSpecifier: NodeGuard<TSESTree.ImportSpecifier> =
53+
ASTUtils.isNodeOfType(AST_NODE_TYPES.ImportSpecifier);
54+
55+
export const isJSXAttribute: NodeGuard<TSESTree.JSXAttribute> =
56+
ASTUtils.isNodeOfType(AST_NODE_TYPES.JSXAttribute);
57+
58+
export const isLiteral: NodeGuard<TSESTree.Literal> = ASTUtils.isNodeOfType(
59+
AST_NODE_TYPES.Literal
7360
);
74-
export const isFunctionDeclaration = ASTUtils.isNodeOfType(
75-
AST_NODE_TYPES.FunctionDeclaration
61+
export const isTemplateLiteral: NodeGuard<TSESTree.TemplateLiteral> =
62+
ASTUtils.isNodeOfType(AST_NODE_TYPES.TemplateLiteral);
63+
64+
export const isMemberExpression: NodeGuard<TSESTree.MemberExpression> =
65+
ASTUtils.isNodeOfType(AST_NODE_TYPES.MemberExpression);
66+
67+
export const isNewExpression: NodeGuard<TSESTree.NewExpression> =
68+
ASTUtils.isNodeOfType(AST_NODE_TYPES.NewExpression);
69+
70+
export const isObjectExpression: NodeGuard<TSESTree.ObjectExpression> =
71+
ASTUtils.isNodeOfType(AST_NODE_TYPES.ObjectExpression);
72+
73+
export const isObjectPattern: NodeGuard<TSESTree.ObjectPattern> =
74+
ASTUtils.isNodeOfType(AST_NODE_TYPES.ObjectPattern);
75+
76+
export const isProperty: NodeGuard<TSESTree.Property> = ASTUtils.isNodeOfType(
77+
AST_NODE_TYPES.Property
7678
);
79+
80+
export const isReturnStatement: NodeGuard<TSESTree.ReturnStatement> =
81+
ASTUtils.isNodeOfType(AST_NODE_TYPES.ReturnStatement);
82+
83+
export const isFunctionExpression: NodeGuard<TSESTree.FunctionExpression> =
84+
ASTUtils.isNodeOfType(AST_NODE_TYPES.FunctionExpression);
85+
86+
export const isFunctionDeclaration: NodeGuard<TSESTree.FunctionDeclaration> =
87+
ASTUtils.isNodeOfType(AST_NODE_TYPES.FunctionDeclaration);

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
"main": "./dist/index.js",
3434
"types": "index.d.ts",
3535
"scripts": {
36-
"prebuild": "del-cli dist",
37-
"build": "tsc -p ./tsconfig.build.json",
36+
"build": "tsdown lib/index.ts --format esm --format cjs",
3837
"generate-all": "pnpm run --parallel \"/^generate:.*/\"",
3938
"generate-all:check": "pnpm run generate-all && git diff --exit-code",
4039
"generate:configs": "ts-node tools/generate-configs",
@@ -68,7 +67,6 @@
6867
"@vitest/coverage-v8": "^3.2.4",
6968
"@vitest/eslint-plugin": "^1.5.2",
7069
"@vitest/ui": "3.2.4",
71-
"del-cli": "^6.0.0",
7270
"eslint": "^9.35.0",
7371
"eslint-config-prettier": "^10.1.8",
7472
"eslint-doc-generator": "^2.2.2",

0 commit comments

Comments
 (0)