@alessiofrittoli/package-configs 1.8.0 → 1.9.0

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/README.md CHANGED
@@ -186,10 +186,30 @@ This file is intended for `base` processes and it mainly contains all the requir
186
186
 
187
187
  ---
188
188
 
189
+ <details>
190
+
191
+ <summary style="cursor:pointer">Next.JS bundler configuration file</summary>
192
+
193
+ ```json
194
+ {
195
+ "extends": "@alessiofrittoli/package-configs/tsconfig/nextjs-bundler.json"
196
+ }
197
+ ```
198
+
199
+ </details>
200
+
201
+ ---
202
+
189
203
  ##### TypeScript utility functions
190
204
 
191
205
  ###### `parseTsConfig()`
192
206
 
207
+ > [!WARNING]
208
+ >
209
+ > @deprecated
210
+ >
211
+ > This function has been moved to [`@alessiofrittoli/tsconfig`](https://npmjs.org/package/@alessiofrittoli/tsconfig) package.
212
+
193
213
  Parse TypeScript configuration file.
194
214
 
195
215
  <details>
@@ -243,6 +263,12 @@ const parsedTsConfig = parseTsConfig({ filepath: './tsconfig.build.json' })
243
263
 
244
264
  ###### `getTSConfigCompilerTarget()`
245
265
 
266
+ > [!WARNING]
267
+ >
268
+ > @deprecated
269
+ >
270
+ > This function has been moved to [`@alessiofrittoli/tsconfig`](https://npmjs.org/package/@alessiofrittoli/tsconfig) package.
271
+
246
272
  Get TypeScript compiler target from resolved configuration file.
247
273
 
248
274
  <details>
@@ -1,4 +1,7 @@
1
1
  import { ParsedCommandLine } from "typescript";
2
+ /**
3
+ * @deprecated This interface has been moved to [`@alessiofrittoli/tsconfig`](https://npmjs.org/package/@alessiofrittoli/tsconfig) package.
4
+ */
2
5
  export interface ParseTsConfigOptions {
3
6
  /**
4
7
  * The TypeScript configuration file path.
@@ -7,6 +10,9 @@ export interface ParseTsConfigOptions {
7
10
  */
8
11
  filepath?: string;
9
12
  }
13
+ /**
14
+ * @deprecated This interface has been moved to [`@alessiofrittoli/tsconfig`](https://npmjs.org/package/@alessiofrittoli/tsconfig) package.
15
+ */
10
16
  export interface GetTSConfigCompilerTargetOptions extends ParseTsConfigOptions {
11
17
  /**
12
18
  * The already parsed TS config.
@@ -22,6 +28,8 @@ export interface GetTSConfigCompilerTargetOptions extends ParseTsConfigOptions {
22
28
  * @returns The parsed TypeScript configuration file.
23
29
  *
24
30
  * @throws {Error} if the resolved `filepath` does not exists.
31
+ *
32
+ * @deprecated This function has been moved to [`@alessiofrittoli/tsconfig`](https://npmjs.org/package/@alessiofrittoli/tsconfig) package.
25
33
  */
26
34
  export declare const parseTsConfig: (options?: ParseTsConfigOptions) => ParsedCommandLine;
27
35
  /**
@@ -30,5 +38,7 @@ export declare const parseTsConfig: (options?: ParseTsConfigOptions) => ParsedCo
30
38
  * @param options An object defining required parameters. See {@link GetTSConfigCompilerTargetOptions} for more info.
31
39
  *
32
40
  * @returns The resolved TypeScript compiler target if any, `undefined` otherwise.
41
+ *
42
+ * @deprecated This function has been moved to [`@alessiofrittoli/tsconfig`](https://npmjs.org/package/@alessiofrittoli/tsconfig) package.
33
43
  */
34
44
  export declare const getTSConfigCompilerTarget: (options?: GetTSConfigCompilerTargetOptions) => string | undefined;
@@ -1,4 +1,7 @@
1
1
  import { ParsedCommandLine } from "typescript";
2
+ /**
3
+ * @deprecated This interface has been moved to [`@alessiofrittoli/tsconfig`](https://npmjs.org/package/@alessiofrittoli/tsconfig) package.
4
+ */
2
5
  export interface ParseTsConfigOptions {
3
6
  /**
4
7
  * The TypeScript configuration file path.
@@ -7,6 +10,9 @@ export interface ParseTsConfigOptions {
7
10
  */
8
11
  filepath?: string;
9
12
  }
13
+ /**
14
+ * @deprecated This interface has been moved to [`@alessiofrittoli/tsconfig`](https://npmjs.org/package/@alessiofrittoli/tsconfig) package.
15
+ */
10
16
  export interface GetTSConfigCompilerTargetOptions extends ParseTsConfigOptions {
11
17
  /**
12
18
  * The already parsed TS config.
@@ -22,6 +28,8 @@ export interface GetTSConfigCompilerTargetOptions extends ParseTsConfigOptions {
22
28
  * @returns The parsed TypeScript configuration file.
23
29
  *
24
30
  * @throws {Error} if the resolved `filepath` does not exists.
31
+ *
32
+ * @deprecated This function has been moved to [`@alessiofrittoli/tsconfig`](https://npmjs.org/package/@alessiofrittoli/tsconfig) package.
25
33
  */
26
34
  export declare const parseTsConfig: (options?: ParseTsConfigOptions) => ParsedCommandLine;
27
35
  /**
@@ -30,5 +38,7 @@ export declare const parseTsConfig: (options?: ParseTsConfigOptions) => ParsedCo
30
38
  * @param options An object defining required parameters. See {@link GetTSConfigCompilerTargetOptions} for more info.
31
39
  *
32
40
  * @returns The resolved TypeScript compiler target if any, `undefined` otherwise.
41
+ *
42
+ * @deprecated This function has been moved to [`@alessiofrittoli/tsconfig`](https://npmjs.org/package/@alessiofrittoli/tsconfig) package.
33
43
  */
34
44
  export declare const getTSConfigCompilerTarget: (options?: GetTSConfigCompilerTargetOptions) => string | undefined;
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../tsconfig/index.cjs");let t=require("tsdown");const n=(n={})=>(0,t.defineConfig)(async(t,r)=>{let{target:i,watch:a,tsconfig:o,deps:s,clean:c,outDir:l,parsedTsConfig:u,...d}=typeof n==`function`?await n(t,r):n,{target:f=i,watch:p=a,tsconfig:m=o,deps:h=s,clean:g=c??!p,outDir:_=l}=t,v=u||m||typeof m==`string`?e.parseTsConfig({filepath:typeof m==`string`?m:void 0}):void 0,y=_||v?.options.outDir||`dist`,b=f||v&&e.getTSConfigCompilerTarget({parsedTsConfig:v});return{entry:[`src/**/index.ts`],format:[`cjs`,`esm`],outDir:y,dts:!0,shims:!0,clean:g,treeshake:!0,minify:!p,sourcemap:!!p,tsconfig:m,target:b,watch:p,deps:h,...d}});exports.tsdownConfig=n;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@alessiofrittoli/tsconfig"),t=require("tsdown");const n=(n={})=>(0,t.defineConfig)(async(t,r)=>{let{target:i,watch:a,tsconfig:o,deps:s,clean:c,outDir:l,parsedTsConfig:u,...d}=typeof n==`function`?await n(t,r):n,{target:f=i,watch:p=a,tsconfig:m=o,deps:h=s,clean:g=c??!p,outDir:_=l}=t,v=u||m||typeof m==`string`?(0,e.parseTsConfig)({filepath:typeof m==`string`?m:void 0}):void 0,y=_||v?.options.outDir||`dist`,b=f||v&&(0,e.getTSConfigCompilerTarget)({parsedTsConfig:v});return{entry:[`src/**/index.ts`],format:[`cjs`,`esm`],outDir:y,dts:!0,shims:!0,clean:g,treeshake:!0,minify:!p,sourcemap:!!p,tsconfig:m,target:b,watch:p,deps:h,...d}});exports.tsdownConfig=n;
@@ -1,5 +1,5 @@
1
- import { ParsedCommandLine } from "typescript";
2
1
  import { InlineConfig, UserConfig, UserConfigFn as UserConfigFn$1, UserConfigFnContext } from "tsdown";
2
+ import { ParsedCommandLine } from "typescript";
3
3
  export interface UserTsdownConfig extends UserConfig {
4
4
  /**
5
5
  * The already parsed TS config.
@@ -1 +1 @@
1
- import{getTSConfigCompilerTarget as e,parseTsConfig as t}from"../tsconfig/index.mjs";import{defineConfig as n}from"tsdown";const r=(r={})=>n(async(n,i)=>{let{target:a,watch:o,tsconfig:s,deps:c,clean:l,outDir:u,parsedTsConfig:d,...f}=typeof r==`function`?await r(n,i):r,{target:p=a,watch:m=o,tsconfig:h=s,deps:g=c,clean:_=l??!m,outDir:v=u}=n,y=d||h||typeof h==`string`?t({filepath:typeof h==`string`?h:void 0}):void 0,b=v||y?.options.outDir||`dist`,x=p||y&&e({parsedTsConfig:y});return{entry:[`src/**/index.ts`],format:[`cjs`,`esm`],outDir:b,dts:!0,shims:!0,clean:_,treeshake:!0,minify:!m,sourcemap:!!m,tsconfig:h,target:x,watch:m,deps:g,...f}});export{r as tsdownConfig};
1
+ import{getTSConfigCompilerTarget as e,parseTsConfig as t}from"@alessiofrittoli/tsconfig";import{defineConfig as n}from"tsdown";const r=(r={})=>n(async(n,i)=>{let{target:a,watch:o,tsconfig:s,deps:c,clean:l,outDir:u,parsedTsConfig:d,...f}=typeof r==`function`?await r(n,i):r,{target:p=a,watch:m=o,tsconfig:h=s,deps:g=c,clean:_=l??!m,outDir:v=u}=n,y=d||h||typeof h==`string`?t({filepath:typeof h==`string`?h:void 0}):void 0,b=v||y?.options.outDir||`dist`,x=p||y&&e({parsedTsConfig:y});return{entry:[`src/**/index.ts`],format:[`cjs`,`esm`],outDir:b,dts:!0,shims:!0,clean:_,treeshake:!0,minify:!m,sourcemap:!!m,tsconfig:h,target:x,watch:m,deps:g,...f}});export{r as tsdownConfig};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alessiofrittoli/package-configs",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Utility library that offers base configurations for your packages.",
5
5
  "type": "module",
6
6
  "author": {
@@ -40,7 +40,7 @@
40
40
  "types": "./dist/index.d.mts",
41
41
  "files": [
42
42
  "dist",
43
- "scripts/postinstall"
43
+ "scripts/install-dependencies.cjs"
44
44
  ],
45
45
  "exports": {
46
46
  ".": {
@@ -73,6 +73,7 @@
73
73
  }
74
74
  },
75
75
  "peerDependencies": {
76
+ "@alessiofrittoli/tsconfig": "^1.0.0",
76
77
  "@eslint/compat": "^2.1.1",
77
78
  "@eslint/eslintrc": "^3.3.7",
78
79
  "@eslint/js": "^10.0.1",
@@ -91,6 +92,9 @@
91
92
  "vitest": "^5.0.1"
92
93
  },
93
94
  "peerDependenciesMeta": {
95
+ "@alessiofrittoli/tsconfig": {
96
+ "optional": true
97
+ },
94
98
  "@eslint/compat": {
95
99
  "optional": true
96
100
  },
@@ -141,7 +145,8 @@
141
145
  }
142
146
  },
143
147
  "devDependencies": {
144
- "@alessiofrittoli/node-scripts": "^4.1.0",
148
+ "@alessiofrittoli/node-scripts": "^4.2.0",
149
+ "@alessiofrittoli/tsconfig": "^1.0.0",
145
150
  "@eslint/compat": "^2.1.1",
146
151
  "@eslint/eslintrc": "^3.3.7",
147
152
  "@eslint/js": "^10.0.1",
@@ -149,23 +154,22 @@
149
154
  "@types/prompts": "^2.4.9",
150
155
  "@vitest/coverage-v8": "5.0.5",
151
156
  "concurrently": "^10.0.6",
152
- "eslint": "^10.11.0",
153
- "eslint-config-next": "^16.4.2",
157
+ "eslint": "^10.13.0",
158
+ "eslint-config-next": "^16.4.3",
154
159
  "eslint-plugin-react-server-components": "^1.2.0",
155
160
  "globals": "^17.13.0",
156
161
  "http-server": "^14.1.1",
157
162
  "oxlint": "^1.89.0",
158
- "oxlint-tsgolint": "^7.0.2004",
163
+ "oxlint-tsgolint": "^7.0.2005",
159
164
  "prettier": "^3.9.10",
160
165
  "prettier-plugin-sort-imports": "^1.8.11",
161
- "tsdown": "^0.23.1",
166
+ "tsdown": "^0.23.2",
162
167
  "typescript": "6.0.3",
163
168
  "typescript-eslint": "^8.72.0",
164
169
  "vite": "^8.3.5",
165
170
  "vitest": "^5.0.5"
166
171
  },
167
172
  "dependencies": {
168
- "@alessiofrittoli/chain-functions": "^2.7.0",
169
173
  "prompts": "^2.4.2"
170
174
  },
171
175
  "scripts": {
@@ -189,10 +193,6 @@
189
193
  "test:coverage": "pnpm test:watch --coverage",
190
194
  "test:coverage:ci": "pnpm test:ci --coverage",
191
195
  "test:serve-coverage": "http-server ./coverage --gzip true -p 0 -o /index.html --silent",
192
- "test:coverage:serve": "concurrently --prefix none --kill-others \"pnpm test:coverage\" \"pnpm test:serve-coverage\"",
193
- "//4a": "*********************************************************************",
194
- "//4b": "******************************* OTHER *******************************",
195
- "//4c": "*********************************************************************",
196
- "postinstall": "node scripts/postinstall/index.cjs"
196
+ "test:coverage:serve": "concurrently --prefix none --kill-others \"pnpm test:coverage\" \"pnpm test:serve-coverage\""
197
197
  }
198
198
  }
@@ -1,8 +1,7 @@
1
- const { openSync, existsSync, readFileSync, writeFileSync } = require('fs')
2
1
  const { ReadStream, WriteStream } = require('tty')
3
2
  const { execSync } = require('child_process')
4
3
  const prompts = require('prompts')
5
- const path = require('path')
4
+ const { openSync } = require('fs')
6
5
 
7
6
  // // example writing user input data to stdout
8
7
 
@@ -49,31 +48,21 @@ const isCIEnv = () =>
49
48
  const arrayUnique = array => (array.length <= 0 ? array : [...new Set(array)])
50
49
 
51
50
  /**
52
- * @type import('@alessiofrittoli/chain-functions/types').ChainLink<( params: { cwd: string; scriptsDir: string } ) => void | Promise<void>>
51
+ * Retrieves the root directory of the current process.
52
+ *
53
+ * @returns {string} The root directory of the current process, determined by the `INIT_CWD` environment variable if set,
54
+ * otherwise the current working directory.
53
55
  */
54
- const installDependencies = next => async params => {
56
+ const getProcessRoot = () => process.env.INIT_CWD || process.cwd()
57
+
58
+ const installDependencies = async () => {
55
59
  if (isCIEnv()) {
56
- return next(params)
60
+ return process.exit(0)
57
61
  }
58
62
 
59
- const { cwd, scriptsDir } = params
63
+ const cwd = getProcessRoot()
60
64
 
61
65
  try {
62
- const stateFilePath = path.resolve(scriptsDir, 'post-install-data.json')
63
-
64
- if (existsSync(stateFilePath)) {
65
- try {
66
- const file = JSON.parse(
67
- readFileSync(path.resolve(scriptsDir, 'post-install-data.json'), 'utf-8'),
68
- )
69
- if (file.installDependencies.done) {
70
- return next(params)
71
- }
72
- } catch {
73
- return next(params)
74
- }
75
- }
76
-
77
66
  const inputPath = process.platform === 'win32' ? 'CONIN$' : '/dev/tty'
78
67
  const outputPath = process.platform === 'win32' ? 'CONOUT$' : '/dev/tty'
79
68
  const stdin = !process.stdin.isTTY ? new ReadStream(openSync(inputPath, 'r')) : undefined
@@ -91,7 +80,7 @@ const installDependencies = next => async params => {
91
80
  ])
92
81
 
93
82
  if (!installDeps) {
94
- return next(params)
83
+ return process.exit(0)
95
84
  }
96
85
 
97
86
  const { _dependenciesChoice } = await prompts([
@@ -104,7 +93,7 @@ const installDependencies = next => async params => {
104
93
  choices: [
105
94
  {
106
95
  title: 'Vite',
107
- selected: true,
96
+ selected: false,
108
97
  description: 'Will install Vite',
109
98
  value: ['vite'],
110
99
  },
@@ -112,7 +101,7 @@ const installDependencies = next => async params => {
112
101
  title: 'Vitest',
113
102
  selected: true,
114
103
  description: 'Will install Vitest',
115
- value: ['vitest', '@vitest/coverage-v8'],
104
+ value: ['vitest', 'jsdom', '@vitest/coverage-v8'],
116
105
  },
117
106
  {
118
107
  title: 'Oxlint',
@@ -156,6 +145,8 @@ const installDependencies = next => async params => {
156
145
  '@eslint/js',
157
146
  'globals',
158
147
  'typescript-eslint',
148
+ 'eslint-config-next',
149
+ 'eslint-plugin-react-server-components',
159
150
  ],
160
151
  },
161
152
  ],
@@ -163,13 +154,13 @@ const installDependencies = next => async params => {
163
154
  ])
164
155
 
165
156
  if (!_dependenciesChoice) {
166
- return next(params)
157
+ return process.exit(0)
167
158
  }
168
159
 
169
160
  const dependenciesChoice = arrayUnique(_dependenciesChoice.flatMap(choice => choice))
170
161
 
171
162
  if (dependenciesChoice.length <= 0) {
172
- return next(params)
163
+ return process.exit(0)
173
164
  }
174
165
 
175
166
  let engine = 'npm'
@@ -183,14 +174,13 @@ const installDependencies = next => async params => {
183
174
 
184
175
  const installCommand = engine === 'npm' ? 'npm install --save-dev' : 'pnpm add --save-dev'
185
176
 
186
- execSync(`${installCommand} ${dependenciesChoice.join(' ')}`, { cwd, stdio: 'ignore' })
187
-
188
- writeFileSync(stateFilePath, JSON.stringify({ installDependencies: { done: true } }))
177
+ execSync(`${installCommand} ${dependenciesChoice.join(' ')}`, { cwd, stdio: 'inherit' })
189
178
 
190
- return next(params)
179
+ return process.exit(0)
191
180
  } catch {
192
- return next(params)
181
+ return process.exit(0)
193
182
  }
194
183
  }
195
184
 
196
- module.exports = installDependencies
185
+ // oxlint-disable-next-line typescript/no-floating-promises
186
+ installDependencies()
@@ -1,74 +0,0 @@
1
- const installDependencies = require('./install-dependencies.cjs')
2
- const { Chain } = require('@alessiofrittoli/chain-functions')
3
- const project = require('../../package.json')
4
- const { readFileSync } = require('fs')
5
- const path = require('path')
6
-
7
- /**
8
- * Reads and parses the `package.json` file from the specified root directory.
9
- *
10
- * @param {string} root The root directory where the `package.json` file is located.
11
- *
12
- * @throws Will throw an error if the file cannot be read or parsed.
13
- *
14
- * @returns {Record<string, string | Record<string, string>> & { name: string }} The parsed contents of the `package.json` file as an object.
15
- */
16
- const getPackageJson = root => JSON.parse(readFileSync(path.resolve(root, 'package.json')).toString())
17
-
18
- /**
19
- * Determines if the script is running in an external project.
20
- *
21
- * @param {{ root: string; name: string }} project - The options object excluding the 'outputFile' property.
22
- * @returns {boolean} A boolean indicating whether the script is running in an external project.
23
- * @throws Will throw an error if `INIT_CWD` is not set or if the script cannot determine the project status.
24
- */
25
- const isExternalPackage = ({ root, name }) => {
26
- try {
27
- const project = getPackageJson(root)
28
-
29
- if (project.name.endsWith(name)) {
30
- return false
31
- }
32
- return true
33
- } catch (cause) {
34
- throw new Error("Couldn't check if script is running in an external project.", { cause })
35
- }
36
- }
37
-
38
- /**
39
- * Retrieves the root directory of the current process.
40
- *
41
- * @returns {string} The root directory of the current process, determined by the `INIT_CWD` environment variable if set,
42
- * otherwise the current working directory.
43
- */
44
- const getProcessRoot = () => process.env.INIT_CWD || process.cwd()
45
-
46
- /**
47
- * @type import('@alessiofrittoli/chain-functions/types').LastChainLink<() => void | Promise<void>>
48
- */
49
- const lastChainLink = () => () => {
50
- console.log({
51
- package: project.name,
52
- message: `Post-Install done. Thank you for installing ${project.name}!`,
53
- })
54
-
55
- process.exit(0)
56
- }
57
-
58
- /**
59
- * @type import('@alessiofrittoli/chain-functions/types').ChainFactory<( params: { cwd: string; scriptsDir: string } ) => void | Promise<void>>
60
- */
61
- const postInstallChain = [installDependencies, lastChainLink]
62
-
63
- const runChain = async () => {
64
- const cwd = getProcessRoot()
65
-
66
- if (!isExternalPackage({ name: project.name, root: cwd })) {
67
- return process.exit(0)
68
- }
69
-
70
- await Chain.functions(postInstallChain)({ cwd, scriptsDir: path.resolve(__dirname, '../') })
71
- }
72
-
73
- // oxlint-disable-next-line typescript/no-floating-promises
74
- runChain()