Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable aliases for TS #4

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions configs/ts/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"composite": true,
Anber marked this conversation as resolved.
Show resolved Hide resolved
"declaration": true,
"esModuleInterop": true,
"emitDeclarationOnly": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": [
Expand All @@ -25,5 +23,7 @@
"strict": true,
"target": "es2022"
},
"display": "Base config"
"exclude": ["node_modules"],
"display": "Base config",
"extends": "../../tsconfig.aliases.json"
Anber marked this conversation as resolved.
Show resolved Hide resolved
}
10 changes: 3 additions & 7 deletions configs/ts/node.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"lib": [
"DOM",
"ESNext",
"esnext.disposable"
],
"module": "NodeNext",
"moduleResolution": "NodeNext",
Anber marked this conversation as resolved.
Show resolved Hide resolved
"lib": ["DOM", "ESNext", "esnext.disposable"],
"module": "CommonJS",
"moduleResolution": "Node",
"target": "es2022"
},
"display": "Node Next",
Expand Down
2 changes: 1 addition & 1 deletion packages/processor-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"scripts": {
"build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
"build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
"build:types": "tsc",
"build:types": "tsc --project ./tsconfig.lib.json --baseUrl . --rootDir ./src",
"lint": "eslint --ext .js,.ts .",
"test": "jest --config ./jest.config.js --rootDir src"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/processor-utils/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": []
"include": ["./src/**/*.ts"]
}
19 changes: 10 additions & 9 deletions packages/processor-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"extends": "@wyw-in-js/ts-config/node.json",
"include": ["src/**/*"],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"baseUrl": "src/",
"module": "CommonJS",
"moduleResolution": "node",
"outDir": "types",
"rootDir": "src/"
}
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
8 changes: 8 additions & 0 deletions packages/processor-utils/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./types"
},
"exclude": ["**/__tests__/*"],
"include": ["./src/**/*.ts"]
}
6 changes: 4 additions & 2 deletions packages/processor-utils/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts"],
"exclude": []
"compilerOptions": {
"noEmit": true
},
"include": ["**/__tests__/*"]
}
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"scripts": {
"build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
"build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
"build:types": "tsc",
"build:types": "tsc --project ./tsconfig.lib.json --baseUrl . --rootDir ./src",
"lint": "eslint --ext .js,.ts .",
"test": "jest --config ./jest.config.js --rootDir src"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": []
"include": ["./src/**/*.ts"]
}
20 changes: 10 additions & 10 deletions packages/shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"extends": "@wyw-in-js/ts-config/node.json",
"include": ["src/**/*"],
"exclude": ["src/**/__tests__/*"],
"compileOnSave": true,
"compilerOptions": {
"baseUrl": "src/",
"module": "CommonJS",
"moduleResolution": "node",
"outDir": "types",
"rootDir": "src/"
}
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
8 changes: 8 additions & 0 deletions packages/shared/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./types"
},
"exclude": ["**/__tests__/*"],
"include": ["./src/**/*.ts"]
}
6 changes: 4 additions & 2 deletions packages/shared/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts"],
"exclude": []
"compilerOptions": {
"noEmit": true
},
"include": ["**/__tests__/*"]
}
2 changes: 1 addition & 1 deletion packages/transform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"scripts": {
"build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
"build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
"build:types": "tsc",
"build:types": "tsc --project ./tsconfig.lib.json --baseUrl . --rootDir ./src",
"lint": "eslint --ext .js,.ts .",
"test": "jest --config ./jest.config.js --rootDir src"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/transform/src/options/buildOptions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="./babel-merge.d.ts" />
Anber marked this conversation as resolved.
Show resolved Hide resolved

import type { TransformOptions } from '@babel/core';
import babelMerge from 'babel-merge';

Expand Down
3 changes: 2 additions & 1 deletion packages/transform/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { BabelFile, PluginPass } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { File, Program } from '@babel/types';
import type { RawSourceMap } from 'source-map';
import type { WYWTransformMetadata } from 'utils/TransformMetadata';

import type { BaseProcessor } from '@wyw-in-js/processor-utils';
import type {
Expand All @@ -12,6 +11,8 @@ import type {
StrictOptions,
} from '@wyw-in-js/shared';

import type { WYWTransformMetadata } from './utils/TransformMetadata';

export type PluginOptions = StrictOptions & {
configFile?: string | false;
stage?: Stage;
Expand Down
15 changes: 12 additions & 3 deletions packages/transform/src/utils/isTypedNode.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import type { NodePath } from '@babel/traverse';
import type { Node } from '@babel/types';

export const isTypedNode =
<T extends NodePath['type']>(type: T) =>
(p: NodePath): p is NodePath<Extract<Node, { type: T }>> => {
export const isTypedNode: <T extends NodePath['type']>(
type: T
) => (p: NodePath) => p is NodePath<
Extract<
Node,
{
type: T;
}
>
> = <T extends NodePath['type']>(type: T) => {
return (p: NodePath): p is NodePath<Extract<Node, { type: T }>> => {
return p.type === type;
};
};
2 changes: 1 addition & 1 deletion packages/transform/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": []
"include": ["./src/**/*.ts"]
}
20 changes: 10 additions & 10 deletions packages/transform/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"extends": "@wyw-in-js/ts-config/node.json",
"include": ["src/**/*"],
"exclude": ["src/__tests__/*", "src/**/__tests__/*"],
"compileOnSave": true,
"compilerOptions": {
"baseUrl": "src/",
"module": "CommonJS",
"moduleResolution": "node",
"outDir": "types",
"rootDir": "src/"
}
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
8 changes: 8 additions & 0 deletions packages/transform/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./types"
},
"exclude": ["**/__tests__/*"],
"include": ["./src/**/*.ts"]
}
6 changes: 4 additions & 2 deletions packages/transform/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts"],
"exclude": []
"compilerOptions": {
"noEmit": true
},
"include": ["**/__tests__/*"]
}
2 changes: 1 addition & 1 deletion packages/webpack-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"scripts": {
"build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
"build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
"build:types": "tsc",
"build:types": "tsc --project ./tsconfig.lib.json --baseUrl . --rootDir ./src",
"lint": "eslint --ext .js,.ts ."
},
"types": "types/index.d.ts"
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-loader/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": []
"include": ["./src/**/*.ts"]
}
20 changes: 10 additions & 10 deletions packages/webpack-loader/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"extends": "@wyw-in-js/ts-config/node.json",
"include": ["src/**/*"],
"exclude": ["src/__tests__/*", "src/**/__tests__/*"],
"compileOnSave": true,
"compilerOptions": {
"baseUrl": "src/",
"module": "CommonJS",
"moduleResolution": "node",
"outDir": "types",
"rootDir": "src/"
}
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
8 changes: 8 additions & 0 deletions packages/webpack-loader/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./types"
},
"exclude": ["**/__tests__/*"],
"include": ["./src/**/*.ts"]
}
7 changes: 7 additions & 0 deletions packages/webpack-loader/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["**/__tests__/*"]
}
14 changes: 14 additions & 0 deletions tsconfig.aliases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"rootDir": ".",
"baseUrl": ".",
"paths": {
"@wyw-in-js/processor-utils": ["packages/processor-utils/src/index.ts"],
"@wyw-in-js/shared": ["packages/shared/src/index.ts"],
"@wyw-in-js/transform": ["packages/transform/src/index.ts"],
"@wyw-in-js/webpack-loader": ["packages/webpack-loader/src/index.ts"]
}
},
"display": "Aliases configuration"
}
16 changes: 0 additions & 16 deletions tsconfig.json

This file was deleted.

Loading