From 1d100dea88905c2a8b319fd886b867e40c8734b4 Mon Sep 17 00:00:00 2001 From: Oleksandr Fediashov Date: Tue, 3 Oct 2023 17:07:33 +0200 Subject: [PATCH 1/2] chore: enable aliases for TS --- configs/ts/base.json | 6 +++--- configs/ts/node.json | 10 +++------- packages/processor-utils/package.json | 2 +- packages/processor-utils/tsconfig.eslint.json | 2 +- packages/processor-utils/tsconfig.json | 19 +++++++++--------- packages/processor-utils/tsconfig.lib.json | 8 ++++++++ packages/processor-utils/tsconfig.spec.json | 6 ++++-- packages/shared/package.json | 2 +- packages/shared/tsconfig.eslint.json | 2 +- packages/shared/tsconfig.json | 20 +++++++++---------- packages/shared/tsconfig.lib.json | 8 ++++++++ packages/shared/tsconfig.spec.json | 6 ++++-- packages/transform/package.json | 2 +- .../transform/src/options/buildOptions.ts | 3 +++ packages/transform/src/types.ts | 3 ++- packages/transform/src/utils/isTypedNode.ts | 15 +++++++++++--- packages/transform/tsconfig.eslint.json | 2 +- packages/transform/tsconfig.json | 20 +++++++++---------- packages/transform/tsconfig.lib.json | 8 ++++++++ packages/transform/tsconfig.spec.json | 6 ++++-- packages/webpack-loader/package.json | 2 +- packages/webpack-loader/tsconfig.eslint.json | 2 +- packages/webpack-loader/tsconfig.json | 20 +++++++++---------- packages/webpack-loader/tsconfig.lib.json | 8 ++++++++ packages/webpack-loader/tsconfig.spec.json | 7 +++++++ tsconfig.aliases.json | 14 +++++++++++++ tsconfig.json | 16 --------------- 27 files changed, 136 insertions(+), 83 deletions(-) create mode 100644 packages/processor-utils/tsconfig.lib.json create mode 100644 packages/shared/tsconfig.lib.json create mode 100644 packages/transform/tsconfig.lib.json create mode 100644 packages/webpack-loader/tsconfig.lib.json create mode 100644 packages/webpack-loader/tsconfig.spec.json create mode 100644 tsconfig.aliases.json delete mode 100644 tsconfig.json diff --git a/configs/ts/base.json b/configs/ts/base.json index b7acdc44..6254e912 100644 --- a/configs/ts/base.json +++ b/configs/ts/base.json @@ -2,10 +2,8 @@ "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { "allowSyntheticDefaultImports": true, - "composite": true, "declaration": true, "esModuleInterop": true, - "emitDeclarationOnly": true, "forceConsistentCasingInFileNames": true, "jsx": "react", "lib": [ @@ -25,5 +23,7 @@ "strict": true, "target": "es2022" }, - "display": "Base config" + "exclude": ["node_modules"], + "display": "Base config", + "extends": "../../tsconfig.aliases.json" } diff --git a/configs/ts/node.json b/configs/ts/node.json index 8d0368ce..daf97a10 100644 --- a/configs/ts/node.json +++ b/configs/ts/node.json @@ -1,13 +1,9 @@ { "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { - "lib": [ - "DOM", - "ESNext", - "esnext.disposable" - ], - "module": "NodeNext", - "moduleResolution": "NodeNext", + "lib": ["DOM", "ESNext", "esnext.disposable"], + "module": "CommonJS", + "moduleResolution": "Node", "target": "es2022" }, "display": "Node Next", diff --git a/packages/processor-utils/package.json b/packages/processor-utils/package.json index 52d49aac..106c91dd 100644 --- a/packages/processor-utils/package.json +++ b/packages/processor-utils/package.json @@ -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" }, diff --git a/packages/processor-utils/tsconfig.eslint.json b/packages/processor-utils/tsconfig.eslint.json index a8d4317b..b139ef3a 100644 --- a/packages/processor-utils/tsconfig.eslint.json +++ b/packages/processor-utils/tsconfig.eslint.json @@ -1,4 +1,4 @@ { "extends": "./tsconfig.json", - "exclude": [] + "include": ["./src/**/*.ts"] } diff --git a/packages/processor-utils/tsconfig.json b/packages/processor-utils/tsconfig.json index f760c3c6..1053d7a8 100644 --- a/packages/processor-utils/tsconfig.json +++ b/packages/processor-utils/tsconfig.json @@ -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" + } + ] } diff --git a/packages/processor-utils/tsconfig.lib.json b/packages/processor-utils/tsconfig.lib.json new file mode 100644 index 00000000..177fdab8 --- /dev/null +++ b/packages/processor-utils/tsconfig.lib.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./types" + }, + "exclude": ["**/__tests__/*"], + "include": ["./src/**/*.ts"] +} diff --git a/packages/processor-utils/tsconfig.spec.json b/packages/processor-utils/tsconfig.spec.json index f79471af..2ba71dfb 100644 --- a/packages/processor-utils/tsconfig.spec.json +++ b/packages/processor-utils/tsconfig.spec.json @@ -1,5 +1,7 @@ { "extends": "./tsconfig.json", - "include": ["src/**/*.ts"], - "exclude": [] + "compilerOptions": { + "noEmit": true + }, + "include": ["**/__tests__/*"] } diff --git a/packages/shared/package.json b/packages/shared/package.json index 1262fea6..07cb8cf7 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -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" }, diff --git a/packages/shared/tsconfig.eslint.json b/packages/shared/tsconfig.eslint.json index a8d4317b..b139ef3a 100644 --- a/packages/shared/tsconfig.eslint.json +++ b/packages/shared/tsconfig.eslint.json @@ -1,4 +1,4 @@ { "extends": "./tsconfig.json", - "exclude": [] + "include": ["./src/**/*.ts"] } diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index f1983aee..1053d7a8 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -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" + } + ] } diff --git a/packages/shared/tsconfig.lib.json b/packages/shared/tsconfig.lib.json new file mode 100644 index 00000000..177fdab8 --- /dev/null +++ b/packages/shared/tsconfig.lib.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./types" + }, + "exclude": ["**/__tests__/*"], + "include": ["./src/**/*.ts"] +} diff --git a/packages/shared/tsconfig.spec.json b/packages/shared/tsconfig.spec.json index f79471af..2ba71dfb 100644 --- a/packages/shared/tsconfig.spec.json +++ b/packages/shared/tsconfig.spec.json @@ -1,5 +1,7 @@ { "extends": "./tsconfig.json", - "include": ["src/**/*.ts"], - "exclude": [] + "compilerOptions": { + "noEmit": true + }, + "include": ["**/__tests__/*"] } diff --git a/packages/transform/package.json b/packages/transform/package.json index b3109bf5..b5bae428 100644 --- a/packages/transform/package.json +++ b/packages/transform/package.json @@ -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" }, diff --git a/packages/transform/src/options/buildOptions.ts b/packages/transform/src/options/buildOptions.ts index a318c7f1..34d1d97f 100644 --- a/packages/transform/src/options/buildOptions.ts +++ b/packages/transform/src/options/buildOptions.ts @@ -1,3 +1,6 @@ +// eslint-disable-next-line @typescript-eslint/triple-slash-reference +/// + import type { TransformOptions } from '@babel/core'; import babelMerge from 'babel-merge'; diff --git a/packages/transform/src/types.ts b/packages/transform/src/types.ts index bd597805..af182078 100644 --- a/packages/transform/src/types.ts +++ b/packages/transform/src/types.ts @@ -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 { @@ -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; diff --git a/packages/transform/src/utils/isTypedNode.ts b/packages/transform/src/utils/isTypedNode.ts index 525256c8..3a0723aa 100644 --- a/packages/transform/src/utils/isTypedNode.ts +++ b/packages/transform/src/utils/isTypedNode.ts @@ -1,8 +1,17 @@ import type { NodePath } from '@babel/traverse'; import type { Node } from '@babel/types'; -export const isTypedNode = - (type: T) => - (p: NodePath): p is NodePath> => { +export const isTypedNode: ( + type: T +) => (p: NodePath) => p is NodePath< + Extract< + Node, + { + type: T; + } + > +> = (type: T) => { + return (p: NodePath): p is NodePath> => { return p.type === type; }; +}; diff --git a/packages/transform/tsconfig.eslint.json b/packages/transform/tsconfig.eslint.json index a8d4317b..b139ef3a 100644 --- a/packages/transform/tsconfig.eslint.json +++ b/packages/transform/tsconfig.eslint.json @@ -1,4 +1,4 @@ { "extends": "./tsconfig.json", - "exclude": [] + "include": ["./src/**/*.ts"] } diff --git a/packages/transform/tsconfig.json b/packages/transform/tsconfig.json index 79f84eaa..1053d7a8 100644 --- a/packages/transform/tsconfig.json +++ b/packages/transform/tsconfig.json @@ -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" + } + ] } diff --git a/packages/transform/tsconfig.lib.json b/packages/transform/tsconfig.lib.json new file mode 100644 index 00000000..177fdab8 --- /dev/null +++ b/packages/transform/tsconfig.lib.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./types" + }, + "exclude": ["**/__tests__/*"], + "include": ["./src/**/*.ts"] +} diff --git a/packages/transform/tsconfig.spec.json b/packages/transform/tsconfig.spec.json index f79471af..2ba71dfb 100644 --- a/packages/transform/tsconfig.spec.json +++ b/packages/transform/tsconfig.spec.json @@ -1,5 +1,7 @@ { "extends": "./tsconfig.json", - "include": ["src/**/*.ts"], - "exclude": [] + "compilerOptions": { + "noEmit": true + }, + "include": ["**/__tests__/*"] } diff --git a/packages/webpack-loader/package.json b/packages/webpack-loader/package.json index f7681b57..3e37ae78 100644 --- a/packages/webpack-loader/package.json +++ b/packages/webpack-loader/package.json @@ -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" diff --git a/packages/webpack-loader/tsconfig.eslint.json b/packages/webpack-loader/tsconfig.eslint.json index a8d4317b..b139ef3a 100644 --- a/packages/webpack-loader/tsconfig.eslint.json +++ b/packages/webpack-loader/tsconfig.eslint.json @@ -1,4 +1,4 @@ { "extends": "./tsconfig.json", - "exclude": [] + "include": ["./src/**/*.ts"] } diff --git a/packages/webpack-loader/tsconfig.json b/packages/webpack-loader/tsconfig.json index 79f84eaa..1053d7a8 100644 --- a/packages/webpack-loader/tsconfig.json +++ b/packages/webpack-loader/tsconfig.json @@ -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" + } + ] } diff --git a/packages/webpack-loader/tsconfig.lib.json b/packages/webpack-loader/tsconfig.lib.json new file mode 100644 index 00000000..177fdab8 --- /dev/null +++ b/packages/webpack-loader/tsconfig.lib.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./types" + }, + "exclude": ["**/__tests__/*"], + "include": ["./src/**/*.ts"] +} diff --git a/packages/webpack-loader/tsconfig.spec.json b/packages/webpack-loader/tsconfig.spec.json new file mode 100644 index 00000000..2ba71dfb --- /dev/null +++ b/packages/webpack-loader/tsconfig.spec.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": true + }, + "include": ["**/__tests__/*"] +} diff --git a/tsconfig.aliases.json b/tsconfig.aliases.json new file mode 100644 index 00000000..dcf811cf --- /dev/null +++ b/tsconfig.aliases.json @@ -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" +} diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 01269729..00000000 --- a/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "@wyw-in-js/ts-config/node.json", - "files": [], - "compilerOptions": { - "emitDeclarationOnly": true, - "incremental": true - }, - "references": [ - { - "path": "./packages/processor-utils" - }, - { - "path": "./packages/shared" - } - ] -} From effafc523d054280c1e639ad524c14dc19167f62 Mon Sep 17 00:00:00 2001 From: Oleksandr Fediashov Date: Tue, 3 Oct 2023 17:29:50 +0200 Subject: [PATCH 2/2] changes to template-tag-syntax --- examples/template-tag-syntax/package.json | 3 ++- .../template-tag-syntax/tsconfig.eslint.json | 2 +- examples/template-tag-syntax/tsconfig.json | 20 +++++++++---------- .../template-tag-syntax/tsconfig.lib.json | 8 ++++++++ .../template-tag-syntax/tsconfig.spec.json | 6 ++++-- tsconfig.aliases.json | 3 +++ 6 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 examples/template-tag-syntax/tsconfig.lib.json diff --git a/examples/template-tag-syntax/package.json b/examples/template-tag-syntax/package.json index 76c4aa12..85c4df15 100644 --- a/examples/template-tag-syntax/package.json +++ b/examples/template-tag-syntax/package.json @@ -1,5 +1,6 @@ { "name": "@wyw-in-js/template-tag-syntax", + "private": true, "version": "0.0.1", "dependencies": { "@wyw-in-js/processor-utils": "workspace:*" @@ -54,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" }, diff --git a/examples/template-tag-syntax/tsconfig.eslint.json b/examples/template-tag-syntax/tsconfig.eslint.json index a8d4317b..b139ef3a 100644 --- a/examples/template-tag-syntax/tsconfig.eslint.json +++ b/examples/template-tag-syntax/tsconfig.eslint.json @@ -1,4 +1,4 @@ { "extends": "./tsconfig.json", - "exclude": [] + "include": ["./src/**/*.ts"] } diff --git a/examples/template-tag-syntax/tsconfig.json b/examples/template-tag-syntax/tsconfig.json index 79f84eaa..1053d7a8 100644 --- a/examples/template-tag-syntax/tsconfig.json +++ b/examples/template-tag-syntax/tsconfig.json @@ -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" + } + ] } diff --git a/examples/template-tag-syntax/tsconfig.lib.json b/examples/template-tag-syntax/tsconfig.lib.json new file mode 100644 index 00000000..177fdab8 --- /dev/null +++ b/examples/template-tag-syntax/tsconfig.lib.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./types" + }, + "exclude": ["**/__tests__/*"], + "include": ["./src/**/*.ts"] +} diff --git a/examples/template-tag-syntax/tsconfig.spec.json b/examples/template-tag-syntax/tsconfig.spec.json index f79471af..2ba71dfb 100644 --- a/examples/template-tag-syntax/tsconfig.spec.json +++ b/examples/template-tag-syntax/tsconfig.spec.json @@ -1,5 +1,7 @@ { "extends": "./tsconfig.json", - "include": ["src/**/*.ts"], - "exclude": [] + "compilerOptions": { + "noEmit": true + }, + "include": ["**/__tests__/*"] } diff --git a/tsconfig.aliases.json b/tsconfig.aliases.json index dcf811cf..f880760e 100644 --- a/tsconfig.aliases.json +++ b/tsconfig.aliases.json @@ -7,6 +7,9 @@ "@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/template-tag-syntax": [ + "examples/template-tag-syntax/src/index.ts" + ], "@wyw-in-js/webpack-loader": ["packages/webpack-loader/src/index.ts"] } },