@aryaemami59/tsconfig 0.0.5 → 0.0.7

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