@alessiofrittoli/package-configs 1.8.0-alpha.9 → 1.8.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alessiofrittoli/package-configs",
3
- "version": "1.8.0-alpha.9",
3
+ "version": "1.8.1",
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
  ".": {
@@ -165,7 +165,6 @@
165
165
  "vitest": "^5.0.5"
166
166
  },
167
167
  "dependencies": {
168
- "@alessiofrittoli/chain-functions": "^2.7.0",
169
168
  "prompts": "^2.4.2"
170
169
  },
171
170
  "scripts": {
@@ -189,10 +188,6 @@
189
188
  "test:coverage": "pnpm test:watch --coverage",
190
189
  "test:coverage:ci": "pnpm test:ci --coverage",
191
190
  "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"
191
+ "test:coverage:serve": "concurrently --prefix none --kill-others \"pnpm test:coverage\" \"pnpm test:serve-coverage\""
197
192
  }
198
193
  }
@@ -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([
@@ -163,13 +152,13 @@ const installDependencies = next => async params => {
163
152
  ])
164
153
 
165
154
  if (!_dependenciesChoice) {
166
- return next(params)
155
+ return process.exit(0)
167
156
  }
168
157
 
169
158
  const dependenciesChoice = arrayUnique(_dependenciesChoice.flatMap(choice => choice))
170
159
 
171
160
  if (dependenciesChoice.length <= 0) {
172
- return next(params)
161
+ return process.exit(0)
173
162
  }
174
163
 
175
164
  let engine = 'npm'
@@ -185,12 +174,11 @@ const installDependencies = next => async params => {
185
174
 
186
175
  execSync(`${installCommand} ${dependenciesChoice.join(' ')}`, { cwd, stdio: 'ignore' })
187
176
 
188
- writeFileSync(stateFilePath, JSON.stringify({ installDependencies: { done: true } }))
189
-
190
- return next(params)
177
+ return process.exit(0)
191
178
  } catch {
192
- return next(params)
179
+ return process.exit(0)
193
180
  }
194
181
  }
195
182
 
196
- module.exports = installDependencies
183
+ // oxlint-disable-next-line typescript/no-floating-promises
184
+ 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: __dirname })
71
- }
72
-
73
- // oxlint-disable-next-line typescript/no-floating-promises
74
- runChain()
@@ -1 +0,0 @@
1
- {"installDependencies":{"done":true}}