@alessiofrittoli/type-utils 1.2.0 → 1.4.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 +7 -5
- package/package.json +47 -40
- package/scripts/postinstall/index.js +11 -9
- package/scripts/postinstall/ts-setup.js +9 -34
- package/scripts/publish.js +2 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Type Utils ❇️
|
|
2
2
|
|
|
3
|
-
Version 1.
|
|
3
|
+
Version 1.4.0
|
|
4
4
|
|
|
5
5
|
## Lightweight TypeScript types utilities
|
|
6
6
|
|
|
@@ -41,21 +41,23 @@ pnpm i @alessiofrittoli/type-utils
|
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
This tiny library defines some global types which are not imported in your IDE by default.\
|
|
44
|
-
After installation a `postinstall` script is executed to create the `
|
|
45
|
-
|
|
44
|
+
After installation a `postinstall` script is executed to create the `alessiofrittoli-env.d.ts` file at the root of your project.
|
|
45
|
+
This script will try to update your `tsconfig.json` file.
|
|
46
|
+
|
|
47
|
+
If that fail, please, make sure to add `alessiofrittoli-env.d.ts` in the array of the "include" property in your `tsconfig.json`.
|
|
46
48
|
|
|
47
49
|
```json
|
|
48
50
|
{
|
|
49
51
|
"compilerOptions": {
|
|
50
52
|
...
|
|
51
53
|
},
|
|
52
|
-
"include": [ ..., "
|
|
54
|
+
"include": [ ..., "alessiofrittoli-env.d.ts" ],
|
|
53
55
|
}
|
|
54
56
|
```
|
|
55
57
|
|
|
56
58
|
You can skip this process if `*.ts` is already in your "include" array.
|
|
57
59
|
|
|
58
|
-
⚠️ If the `
|
|
60
|
+
⚠️ If the `alessiofrittoli-env.d.ts` file creation fails you can run the following command to manually execute the script:
|
|
59
61
|
|
|
60
62
|
```bash
|
|
61
63
|
node node_modules/@alessiofrittoli/type-utils/scripts/postinstall/index.js
|
package/package.json
CHANGED
|
@@ -1,42 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
2
|
+
"name": "@alessiofrittoli/type-utils",
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "Lightweight TypeScript types utilities",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Alessio Frittoli",
|
|
7
|
+
"email": "info@alessiofrittoli.it",
|
|
8
|
+
"url": "https://alessiofrittoli.it"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"typescript"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/alessiofrittoli/type-utils#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/alessiofrittoli/type-utils/issues",
|
|
17
|
+
"email": "info@alessiofrittoli.it"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/alessiofrittoli/type-utils.git"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"scripts"
|
|
28
|
+
],
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@eslint/js": "^9.17.0",
|
|
31
|
+
"@types/node": "^22.10.2",
|
|
32
|
+
"eslint": "^9.17.0",
|
|
33
|
+
"globals": "^15.14.0",
|
|
34
|
+
"tsup": "^8.3.5",
|
|
35
|
+
"typescript": "^5.7.2",
|
|
36
|
+
"typescript-eslint": "^8.18.2"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@alessiofrittoli/chain-functions": "^2.0.0",
|
|
40
|
+
"@alessiofrittoli/node-scripts": "2.1.0"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "pnpm lint && tsup",
|
|
44
|
+
"build:watch": "tsup --watch",
|
|
45
|
+
"lint": "eslint",
|
|
46
|
+
"release": "node scripts/publish.js --verbose --npm",
|
|
47
|
+
"postinstall": "node scripts/postinstall/index.js"
|
|
48
|
+
}
|
|
42
49
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { Chain } = require( '@alessiofrittoli/chain-functions' )
|
|
2
|
+
const tsSetup = require( './ts-setup.js' )
|
|
2
3
|
|
|
3
|
-
/** @type {(() => void | Promise<void
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const executePostInstall = async () => {
|
|
7
|
-
await Promise.all( scripts.map( async script => {
|
|
8
|
-
await script()
|
|
9
|
-
} ) )
|
|
4
|
+
/** @type {import( '@alessiofrittoli/chain-functions/types' ).LastChainLink<() => void | Promise<void>>} */
|
|
5
|
+
const lastChainLink = () => () => {
|
|
6
|
+
console.log( 'Post-install done.' )
|
|
10
7
|
}
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
/** @type {import( '@alessiofrittoli/chain-functions/types' ).ChainFactory<() => void | Promise<void>>} */
|
|
10
|
+
const chain = [ tsSetup, lastChainLink ]
|
|
11
|
+
|
|
12
|
+
;( async () => {
|
|
13
|
+
await Chain.functions( chain )()
|
|
14
|
+
} )()
|
|
@@ -1,39 +1,14 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const project = require( '../../package.json' )
|
|
1
|
+
const { addTypesReference } = require( '@alessiofrittoli/node-scripts/postinstall' )
|
|
2
|
+
const project = require( '../../package.json' )
|
|
4
3
|
|
|
4
|
+
/** @type {import( '@alessiofrittoli/chain-functions/types' ).ChainLink<() => void | Promise<void>>} */
|
|
5
|
+
const tsSetup = next => () => {
|
|
6
|
+
|
|
7
|
+
addTypesReference( {
|
|
8
|
+
name: project.name,
|
|
9
|
+
} )
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const projectName = project.name.replace( '@alessiofrittoli/', '' )
|
|
9
|
-
const projectRoot = process.env.INIT_CWD || process.cwd()
|
|
10
|
-
const typesFilename = `${ projectName }.d.ts`
|
|
11
|
-
|
|
12
|
-
if ( projectRoot.endsWith( projectName ) ) {
|
|
13
|
-
console.log( `Skip "postinstall" script. Running in ${ project.name }` )
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
if ( ! projectRoot ) {
|
|
17
|
-
console.error( 'INIT_CWD is not set. This script must be run during pnpm install.' )
|
|
18
|
-
process.exit( 1 )
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const tsconfigPath = path.resolve( projectRoot, typesFilename )
|
|
22
|
-
|
|
23
|
-
const data = [
|
|
24
|
-
`/// <reference types="${ project.name }" />`,
|
|
25
|
-
'// NOTE: This file should not be edited'
|
|
26
|
-
].join( '\n\n' )
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
fs.writeFileSync( tsconfigPath, data )
|
|
30
|
-
console.log( `"${ typesFilename }" has been created at the root of your project.` )
|
|
31
|
-
console.log( 'Please update your tsconfig.json to add this file in your "include" property of your tsconfig.json file.' )
|
|
32
|
-
} catch ( error ) {
|
|
33
|
-
console.error( `An error occured while creating "${ typesFilename }" at the root of your project. Some global types may not working as expect.`, error )
|
|
34
|
-
process.exit( 1 )
|
|
35
|
-
}
|
|
36
|
-
|
|
11
|
+
return next()
|
|
37
12
|
}
|
|
38
13
|
|
|
39
14
|
module.exports = tsSetup
|