@aryaemami59/tsconfig 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Arya Emami
3
+ Copyright (c) 2026 Arya Emami
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -34,7 +34,7 @@ bun add --dev @aryaemami59/tsconfig
34
34
 
35
35
  ```json
36
36
  {
37
- "extends": "@aryaemami59/tsconfig/base",
37
+ "extends": "@aryaemami59/tsconfig/node",
38
38
  "compilerOptions": {
39
39
  "outDir": "./dist",
40
40
  "rootDir": "./src"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aryaemami59/tsconfig",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "TypeScript configuration",
5
5
  "keywords": [
6
6
  "config",
@@ -18,35 +18,228 @@
18
18
  "url": "git+https://github.com/aryaemami59/configs.git",
19
19
  "directory": "packages/typescript"
20
20
  },
21
+ "files": [
22
+ "src",
23
+ "scripts"
24
+ ],
21
25
  "license": "MIT",
22
26
  "author": "Arya Emami <aryaemami59@yahoo.com> (https://github.com/aryaemami59)",
23
27
  "sideEffects": false,
24
28
  "type": "module",
25
29
  "exports": {
26
- ".": "./base/tsconfig.json",
27
- "./base": "./base/tsconfig.json",
28
- "./bundler": "./bundler/esnext/tsconfig.json",
29
- "./bundler/esnext": "./bundler/esnext/tsconfig.json",
30
- "./bundler/preserve": "./bundler/preserve/tsconfig.json",
31
- "./cra": "./create-react-app/tsconfig.json",
32
- "./create-react-app": "./create-react-app/tsconfig.json",
33
- "./node": "./base/tsconfig.json",
34
- "./node-10": "./node-10/tsconfig.json",
35
- "./node-16": "./node-16/tsconfig.json",
36
- "./node-next": "./node-next/tsconfig.json",
30
+ ".": "./src/node/tsconfig.json",
31
+ "./tsconfig.json": "./src/node/tsconfig.json",
32
+ "./node": "./src/node/tsconfig.json",
33
+ "./node/tsconfig.json": "./src/node/tsconfig.json",
34
+ "./Node": "./src/node/tsconfig.json",
35
+ "./node/with-js": "./src/node/with-js/tsconfig.json",
36
+ "./Node/with-js": "./src/node/with-js/tsconfig.json",
37
+ "./bundler": "./src/bundler/esnext/tsconfig.json",
38
+ "./bundler/tsconfig.json": "./src/bundler/esnext/tsconfig.json",
39
+ "./Bundler": "./src/bundler/esnext/tsconfig.json",
40
+ "./bundler/with-js": "./src/bundler/esnext/with-js/tsconfig.json",
41
+ "./Bundler/with-js": "./src/bundler/esnext/with-js/tsconfig.json",
42
+ "./bundler/esnext": "./src/bundler/esnext/tsconfig.json",
43
+ "./Bundler/esnext": "./src/bundler/esnext/tsconfig.json",
44
+ "./Bundler/ESNext": "./src/bundler/esnext/tsconfig.json",
45
+ "./bundler/esnext/with-js": "./src/bundler/esnext/with-js/tsconfig.json",
46
+ "./Bundler/esnext/with-js": "./src/bundler/esnext/with-js/tsconfig.json",
47
+ "./Bundler/ESNext/with-js": "./src/bundler/esnext/with-js/tsconfig.json",
48
+ "./bundler/preserve": "./src/bundler/preserve/tsconfig.json",
49
+ "./Bundler/preserve": "./src/bundler/preserve/tsconfig.json",
50
+ "./Bundler/Preserve": "./src/bundler/preserve/tsconfig.json",
51
+ "./bundler/preserve/with-js": "./src/bundler/preserve/with-js/tsconfig.json",
52
+ "./Bundler/preserve/with-js": "./src/bundler/preserve/with-js/tsconfig.json",
53
+ "./Bundler/Preserve/with-js": "./src/bundler/preserve/with-js/tsconfig.json",
54
+ "./cra": "./src/create-react-app/tsconfig.json",
55
+ "./create-react-app": "./src/create-react-app/tsconfig.json",
56
+ "./node-10": "./src/node-10/tsconfig.json",
57
+ "./node10": "./src/node-10/tsconfig.json",
58
+ "./node10/tsconfig.json": "./src/node-10/tsconfig.json",
59
+ "./Node10": "./src/node-10/tsconfig.json",
60
+ "./node-10/with-js": "./src/node-10/with-js/tsconfig.json",
61
+ "./node10/with-js": "./src/node-10/with-js/tsconfig.json",
62
+ "./Node10/with-js": "./src/node-10/with-js/tsconfig.json",
63
+ "./node-16": "./src/node-16/tsconfig.json",
64
+ "./node16": "./src/node-16/tsconfig.json",
65
+ "./node16/tsconfig.json": "./src/node-16/tsconfig.json",
66
+ "./Node16": "./src/node-16/tsconfig.json",
67
+ "./node-16/with-js": "./src/node-16/with-js/tsconfig.json",
68
+ "./node16/with-js": "./src/node-16/with-js/tsconfig.json",
69
+ "./Node16/with-js": "./src/node-16/with-js/tsconfig.json",
70
+ "./node-next": "./src/node-next/tsconfig.json",
71
+ "./nodenext": "./src/node-next/tsconfig.json",
72
+ "./nodenext/tsconfig.json": "./src/node-next/tsconfig.json",
73
+ "./NodeNext": "./src/node-next/tsconfig.json",
74
+ "./node-next/with-js": "./src/node-next/with-js/tsconfig.json",
75
+ "./nodenext/with-js": "./src/node-next/with-js/tsconfig.json",
76
+ "./NodeNext/with-js": "./src/node-next/with-js/tsconfig.json",
37
77
  "./package.json": "./package.json"
38
78
  },
39
- "main": "base/tsconfig.json",
79
+ "main": "./src/node/tsconfig.json",
80
+ "types": "./src/node/tsconfig.json",
81
+ "typesVersions": {
82
+ "*": {
83
+ "tsconfig.json": [
84
+ "src/node/tsconfig.json"
85
+ ],
86
+ "node": [
87
+ "src/node/tsconfig.json"
88
+ ],
89
+ "node/tsconfig.json": [
90
+ "src/node/tsconfig.json"
91
+ ],
92
+ "node/with-js": [
93
+ "src/node/with-js/tsconfig.json"
94
+ ],
95
+ "Node": [
96
+ "src/node/tsconfig.json"
97
+ ],
98
+ "Node/with-js": [
99
+ "src/node/with-js/tsconfig.json"
100
+ ],
101
+ "bundler": [
102
+ "src/bundler/esnext/tsconfig.json"
103
+ ],
104
+ "bundler/tsconfig.json": [
105
+ "src/bundler/esnext/tsconfig.json"
106
+ ],
107
+ "bundler/esnext": [
108
+ "src/bundler/esnext/tsconfig.json"
109
+ ],
110
+ "bundler/esnext/with-js": [
111
+ "src/bundler/esnext/with-js/tsconfig.json"
112
+ ],
113
+ "bundler/with-js": [
114
+ "src/bundler/esnext/with-js/tsconfig.json"
115
+ ],
116
+ "bundler/preserve": [
117
+ "src/bundler/preserve/tsconfig.json"
118
+ ],
119
+ "bundler/preserve/with-js": [
120
+ "src/bundler/preserve/with-js/tsconfig.json"
121
+ ],
122
+ "Bundler": [
123
+ "src/bundler/esnext/tsconfig.json"
124
+ ],
125
+ "Bundler/esnext": [
126
+ "src/bundler/esnext/tsconfig.json"
127
+ ],
128
+ "Bundler/esnext/with-js": [
129
+ "src/bundler/esnext/with-js/tsconfig.json"
130
+ ],
131
+ "Bundler/ESNext": [
132
+ "src/bundler/esnext/tsconfig.json"
133
+ ],
134
+ "Bundler/ESNext/with-js": [
135
+ "src/bundler/esnext/with-js/tsconfig.json"
136
+ ],
137
+ "Bundler/with-js": [
138
+ "src/bundler/esnext/with-js/tsconfig.json"
139
+ ],
140
+ "Bundler/preserve": [
141
+ "src/bundler/preserve/tsconfig.json"
142
+ ],
143
+ "Bundler/Preserve": [
144
+ "src/bundler/preserve/tsconfig.json"
145
+ ],
146
+ "Bundler/preserve/with-js": [
147
+ "src/bundler/preserve/with-js/tsconfig.json"
148
+ ],
149
+ "Bundler/Preserve/with-js": [
150
+ "src/bundler/preserve/with-js/tsconfig.json"
151
+ ],
152
+ "cra": [
153
+ "src/create-react-app/tsconfig.json"
154
+ ],
155
+ "create-react-app": [
156
+ "src/create-react-app/tsconfig.json"
157
+ ],
158
+ "node-10": [
159
+ "src/node-10/tsconfig.json"
160
+ ],
161
+ "node-10/with-js": [
162
+ "src/node-10/with-js/tsconfig.json"
163
+ ],
164
+ "node10": [
165
+ "src/node-10/tsconfig.json"
166
+ ],
167
+ "node10/tsconfig.json": [
168
+ "src/node-10/tsconfig.json"
169
+ ],
170
+ "node10/with-js": [
171
+ "src/node-10/with-js/tsconfig.json"
172
+ ],
173
+ "Node10": [
174
+ "src/node-10/tsconfig.json"
175
+ ],
176
+ "Node10/with-js": [
177
+ "src/node-10/with-js/tsconfig.json"
178
+ ],
179
+ "node-16": [
180
+ "src/node-16/tsconfig.json"
181
+ ],
182
+ "node-16/with-js": [
183
+ "src/node-16/with-js/tsconfig.json"
184
+ ],
185
+ "node16": [
186
+ "src/node-16/tsconfig.json"
187
+ ],
188
+ "node16/tsconfig.json": [
189
+ "src/node-16/tsconfig.json"
190
+ ],
191
+ "node16/with-js": [
192
+ "src/node-16/with-js/tsconfig.json"
193
+ ],
194
+ "Node16": [
195
+ "src/node-16/tsconfig.json"
196
+ ],
197
+ "Node16/with-js": [
198
+ "src/node-16/with-js/tsconfig.json"
199
+ ],
200
+ "node-next": [
201
+ "src/node-next/tsconfig.json"
202
+ ],
203
+ "node-next/with-js": [
204
+ "src/node-next/with-js/tsconfig.json"
205
+ ],
206
+ "nodenext": [
207
+ "src/node-next/tsconfig.json"
208
+ ],
209
+ "nodenext/tsconfig.json": [
210
+ "src/node-next/tsconfig.json"
211
+ ],
212
+ "nodenext/with-js": [
213
+ "src/node-next/with-js/tsconfig.json"
214
+ ],
215
+ "NodeNext": [
216
+ "src/node-next/tsconfig.json"
217
+ ],
218
+ "NodeNext/with-js": [
219
+ "src/node-next/with-js/tsconfig.json"
220
+ ]
221
+ }
222
+ },
40
223
  "scripts": {
41
- "check-exports": "attw --pack",
42
- "check-package-json": "publint --strict ."
224
+ "build": "node scripts/build.ts",
225
+ "check-exports": "attw --pack $INIT_CWD",
226
+ "check-package-json": "publint --strict $INIT_CWD",
227
+ "format-check": "yarn run -T format-check",
228
+ "format": "yarn run -T format",
229
+ "lint-fix": "yarn run -T lint-fix",
230
+ "lint": "yarn run -T lint",
231
+ "prepack": "yarn run build",
232
+ "typecheck": "tsc -p ${INIT_CWD}/tsconfig.json"
43
233
  },
44
234
  "devDependencies": {
45
- "@arethetypeswrong/cli": "^0.17.0",
46
- "publint": "^0.2.12"
235
+ "@arethetypeswrong/cli": "^0.18.2",
236
+ "@types/node": "^25.2.1",
237
+ "prettier": "^3.8.1",
238
+ "publint": "^0.3.17",
239
+ "typescript": "^5.9.3"
47
240
  },
48
241
  "publishConfig": {
49
242
  "access": "public",
50
243
  "provenance": true
51
244
  }
52
- }
245
+ }
@@ -0,0 +1,264 @@
1
+ #!/usr/bin/env node
2
+
3
+ import * as fs from 'node:fs/promises'
4
+ import * as path from 'node:path'
5
+ import { format, resolveConfig } from 'prettier'
6
+ import ts from 'typescript'
7
+ import packageJson from '../package.json' with { type: 'json' }
8
+ import type {
9
+ ExcludeStrict,
10
+ ExtractCapitalized,
11
+ ExtractLowercase,
12
+ ExtractStrict,
13
+ KebabCase,
14
+ Simplify,
15
+ } from './typeHelpers.ts'
16
+ import type { Module, ModuleResolution, TsConfigJson } from './types.ts'
17
+
18
+ const { ModuleKind, ModuleResolutionKind } = ts.server.protocol
19
+
20
+ type ModuleResolutionKindType = typeof ModuleResolutionKind
21
+
22
+ type ModuleKindType = typeof ModuleKind
23
+
24
+ const ROOT_DIRECTORY = path.join(import.meta.dirname, '..')
25
+
26
+ type LowerCaseModuleResolutionKinds = ExcludeStrict<
27
+ ExtractLowercase<ModuleResolution>,
28
+ 'classic'
29
+ >
30
+
31
+ type CapitalizedModuleResolutionKinds = ExcludeStrict<
32
+ ExtractCapitalized<ModuleResolution>,
33
+ 'Classic'
34
+ >
35
+
36
+ type CapitalizedModuleKinds = ExcludeStrict<
37
+ ExtractCapitalized<Module>,
38
+ 'AMD' | 'None' | 'System' | 'UMD'
39
+ >
40
+
41
+ type LowerCaseModuleKinds = ExcludeStrict<
42
+ ExtractLowercase<Module>,
43
+ 'amd' | 'none' | 'system' | 'umd'
44
+ >
45
+
46
+ type CapitalizedToLowerCaseModuleResolutionKinds = {
47
+ readonly [K in CapitalizedModuleResolutionKinds]: Lowercase<K>
48
+ }
49
+
50
+ type LowerCaseToCapitalizedModuleResolutionKinds = {
51
+ readonly [K in CapitalizedModuleResolutionKinds as Lowercase<K>]: K
52
+ }
53
+
54
+ type PossibleModuleKinds = Simplify<{
55
+ readonly [K in CapitalizedModuleResolutionKinds]: {
56
+ readonly module: Lowercase<K> extends 'bundler'
57
+ ? readonly ['esnext', 'preserve']
58
+ : Lowercase<K> extends 'node' | 'node10'
59
+ ? readonly ['esnext']
60
+ : Lowercase<K> extends 'node16'
61
+ ? readonly ['node16']
62
+ : Lowercase<K> extends 'nodenext'
63
+ ? readonly ['nodenext']
64
+ : readonly ['esnext']
65
+ readonly moduleResolution: Lowercase<K>
66
+ }
67
+ }>
68
+
69
+ type BaseConfigs = {
70
+ readonly [K in CapitalizedModuleResolutionKinds as Lowercase<K>]: Simplify<{
71
+ readonly directory: KebabCase<K>
72
+ readonly module: PossibleModuleKinds[K]['module'][0]
73
+ readonly moduleResolution: Lowercase<K>
74
+ readonly subDirectory: [1] extends [
75
+ PossibleModuleKinds[K]['module']['length'],
76
+ ]
77
+ ? ''
78
+ : PossibleModuleKinds[K]['module'][0]
79
+ }>
80
+ }
81
+
82
+ const baseConfigs = {
83
+ bundler: {
84
+ directory: 'bundler',
85
+ module: 'esnext',
86
+ moduleResolution: 'bundler',
87
+ subDirectory: 'esnext',
88
+ },
89
+ node: {
90
+ directory: 'node',
91
+ module: 'esnext',
92
+ moduleResolution: 'node',
93
+ subDirectory: '',
94
+ },
95
+ node10: {
96
+ directory: 'node-10',
97
+ module: 'esnext',
98
+ moduleResolution: 'node10',
99
+ subDirectory: '',
100
+ },
101
+ node16: {
102
+ directory: 'node-16',
103
+ module: 'node16',
104
+ moduleResolution: 'node16',
105
+ subDirectory: '',
106
+ },
107
+ nodenext: {
108
+ directory: 'node-next',
109
+ module: 'nodenext',
110
+ moduleResolution: 'nodenext',
111
+ subDirectory: '',
112
+ },
113
+ } as const satisfies BaseConfigs
114
+
115
+ type AdditionalConfigs = {
116
+ readonly [K in keyof PossibleModuleKinds as [1] extends [
117
+ PossibleModuleKinds[K]['module']['length'],
118
+ ]
119
+ ? never
120
+ : [undefined] extends [PossibleModuleKinds[K]['module']['1']]
121
+ ? never
122
+ : Lowercase<K>]: {
123
+ readonly directory: KebabCase<K>
124
+ readonly moduleResolution: PossibleModuleKinds[K]['moduleResolution']
125
+ } & {
126
+ [P in PossibleModuleKinds[K]['module'][ExtractStrict<
127
+ keyof PossibleModuleKinds[K]['module'],
128
+ number
129
+ >]]: {
130
+ readonly module: P
131
+ readonly subDirectory: P
132
+ }
133
+ }[ExcludeStrict<
134
+ PossibleModuleKinds[K]['module'][ExtractStrict<
135
+ keyof PossibleModuleKinds[K]['module'],
136
+ number
137
+ >],
138
+ PossibleModuleKinds[K]['module'][0]
139
+ >]
140
+ }
141
+
142
+ const additionalConfigs = {
143
+ bundler: {
144
+ directory: 'bundler',
145
+ module: 'preserve',
146
+ moduleResolution: 'bundler',
147
+ subDirectory: 'preserve',
148
+ },
149
+ } as const satisfies AdditionalConfigs
150
+
151
+ const build = async () => {
152
+ await Promise.all(
153
+ [...Object.entries(baseConfigs), ...Object.entries(additionalConfigs)].map(
154
+ async ([
155
+ ,
156
+ { directory, module: moduleKind, moduleResolution, subDirectory },
157
+ ]) => {
158
+ const directoryPath = path.join(
159
+ ROOT_DIRECTORY,
160
+ 'src',
161
+ directory,
162
+ subDirectory,
163
+ )
164
+
165
+ const tsconfigJsonPath = path.join(directoryPath, 'tsconfig.json')
166
+
167
+ const withJsDirectoryPath = path.join(directoryPath, 'with-js')
168
+
169
+ const withJsTsConfigJsonPath = path.join(
170
+ withJsDirectoryPath,
171
+ 'tsconfig.json',
172
+ )
173
+
174
+ await fs.mkdir(directoryPath, {
175
+ recursive: true,
176
+ })
177
+
178
+ await fs.mkdir(withJsDirectoryPath, {
179
+ recursive: true,
180
+ })
181
+
182
+ const baseTsconfigJson = {
183
+ $schema: 'https://json.schemastore.org/tsconfig',
184
+ compilerOptions: {},
185
+ display: `TypeScript configuration with \`${moduleResolution}\` module resolution`,
186
+ } as const satisfies TsConfigJson
187
+
188
+ const withJsTsConfigJson = {
189
+ ...baseTsconfigJson,
190
+ compilerOptions: {
191
+ allowJs: true,
192
+ checkJs: true,
193
+ },
194
+ display: `TypeScript configuration with module set to \`${moduleKind}\`, module resolution set to \`${moduleResolution}\`, and JavaScript files support enabled`,
195
+ extends: [packageJson.name, directory, subDirectory]
196
+ .filter((e) => !!e)
197
+ .join('/'),
198
+ } as const satisfies TsConfigJson
199
+
200
+ const tsconfigJson = {
201
+ ...baseTsconfigJson,
202
+ compilerOptions: {
203
+ ...(moduleKind !== baseConfigs.node.module && {
204
+ module: moduleKind,
205
+ }),
206
+ ...(moduleResolution !== 'node' && { moduleResolution }),
207
+ ...(moduleResolution === 'node' && {
208
+ allowSyntheticDefaultImports: true,
209
+ declaration: true,
210
+ esModuleInterop: true,
211
+ forceConsistentCasingInFileNames: true,
212
+ isolatedModules: true,
213
+ jsx: 'react',
214
+ lib: ['DOM', 'ESNext'],
215
+ module: 'esnext',
216
+ moduleDetection: 'force',
217
+ moduleResolution,
218
+ noEmit: false,
219
+ noEmitOnError: true,
220
+ noErrorTruncation: true,
221
+ noFallthroughCasesInSwitch: true,
222
+ noImplicitOverride: true,
223
+ noImplicitReturns: true,
224
+ resolveJsonModule: true,
225
+ skipLibCheck: true,
226
+ sourceMap: true,
227
+ strict: true,
228
+ target: 'esnext',
229
+ types: ['node'],
230
+ useDefineForClassFields: true,
231
+ useUnknownInCatchVariables: true,
232
+ }),
233
+ },
234
+ display: `TypeScript configuration with module set to \`${moduleKind}\` and module resolution set to \`${moduleResolution}\`${moduleResolution === 'node' ? ', intended for TypeScript versions earlier than 5.0.' : moduleResolution === 'node10' ? '. It serves as a backwards compatible replacement for the deprecated `node` module resolution.' : ''}`,
235
+ ...(moduleResolution !== 'node' && {
236
+ extends: `${packageJson.name}/node`,
237
+ }),
238
+ } as const satisfies TsConfigJson
239
+
240
+ const prettierConfig = (await resolveConfig(tsconfigJsonPath)) ?? {}
241
+
242
+ fs.writeFile(
243
+ tsconfigJsonPath,
244
+ await format(JSON.stringify(tsconfigJson, null, 2), {
245
+ ...prettierConfig,
246
+ filepath: tsconfigJsonPath,
247
+ }),
248
+ { encoding: 'utf-8' },
249
+ )
250
+
251
+ fs.writeFile(
252
+ withJsTsConfigJsonPath,
253
+ await format(JSON.stringify(withJsTsConfigJson, null, 2), {
254
+ ...prettierConfig,
255
+ filepath: withJsTsConfigJsonPath,
256
+ }),
257
+ { encoding: 'utf-8' },
258
+ )
259
+ },
260
+ ),
261
+ )
262
+ }
263
+
264
+ void build()