@jcoreio/toolchain 5.4.3 → 5.4.5

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": "@jcoreio/toolchain",
3
- "version": "5.4.3",
3
+ "version": "5.4.5",
4
4
  "description": "base JS build toolchain",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,6 +22,7 @@
22
22
  "@eslint/js": "^9.23.0",
23
23
  "@jcoreio/eslint-plugin-implicit-dependencies": "^1.1.1",
24
24
  "chalk": "^4.0.0",
25
+ "debug": "^4.4.0",
25
26
  "dedent-js": "^1.0.1",
26
27
  "eslint": "^9.17.0",
27
28
  "eslint-config-prettier": "^9.1.0",
@@ -61,22 +61,35 @@ module.exports = [
61
61
  }
62
62
  `
63
63
  },
64
+ 'prettier.config.cjs': async (existing) => {
65
+ if (existing) {
66
+ return existing.replace(
67
+ `${name}/prettier.config.cjs`,
68
+ `${name}/prettierConfig.cjs`
69
+ )
70
+ }
71
+ return dedent`
72
+ /* eslint-env node, es2018 */
73
+ const base = require('${name}/prettierConfig.cjs')
74
+ module.exports = {
75
+ ...base,
76
+ }
77
+ `
78
+ },
64
79
  }
65
80
  for (const file of [
66
81
  ...(isMonorepoSubpackage ? [] : ['githooks.cjs']),
67
82
  'lint-staged.config.cjs',
68
- 'prettier.config.cjs',
69
83
  ]) {
70
84
  files[file] = async (existing) =>
71
85
  existing && fromVersion ? existing : (
72
86
  dedent`
73
- /* eslint-env node, es2018 */
74
- const base = require('${name}/${file}')
75
- module.exports = {
76
- ...base,
77
- }
78
-
79
- `
87
+ /* eslint-env node, es2018 */
88
+ const base = require('${name}/${file}')
89
+ module.exports = {
90
+ ...base,
91
+ }
92
+ `
80
93
  )
81
94
  }
82
95
  const tasks =
package/util/findUps.cjs CHANGED
@@ -6,25 +6,81 @@ const merge = require('./merge.cjs')
6
6
  const once = require('./once.cjs')
7
7
  const { name } = require('../package.json')
8
8
  const configSchema = require('./configSchema.cjs')
9
+ const debug = require('debug')('@jcoreio/toolchain:findUps')
9
10
 
10
- const cwd = process.cwd().replace(/\/node_modules(\/.*|$)/, '')
11
+ // First see if the cwd is within a project dir
12
+ let dir = process
13
+ .cwd()
14
+ .replace(/\/node_modules(\/.*|$)|\\node_modules(\\.*|$)/, '')
11
15
 
12
- const packageJsonFile = (exports.packageJsonFile = findUp.sync('package.json', {
13
- cwd,
16
+ let packageJsonFile = findUp.sync('package.json', {
17
+ cwd: dir,
14
18
  type: 'file',
15
- }))
19
+ })
20
+ debug({ step: 0, cwd: process.cwd(), dir, packageJsonFile })
21
+
16
22
  if (!packageJsonFile) {
23
+ // When the cwd is not within a project dir, see if this file is within a project dir
24
+ dir = __dirname.replace(/\/node_modules(\/.*|$)|\\node_modules(\\.*|$)/, '')
25
+
26
+ packageJsonFile = findUp.sync('package.json', {
27
+ cwd: dir,
28
+ type: 'file',
29
+ })
30
+ }
31
+ debug({ step: 1, dir, packageJsonFile })
32
+
33
+ if (!packageJsonFile) {
34
+ debug(`failed to find project package.json in a parent directory of ${dir}`)
17
35
  throw new Error(
18
- `failed to find project package.json in a parent directory of ${cwd}`
36
+ `failed to find project package.json in a parent directory of ${dir}`
19
37
  )
20
38
  }
21
- const packageJson = (exports.packageJson = fs.readJsonSync(packageJsonFile))
39
+
40
+ // When this file is within the @jcoreio/toolchains monorepo, the above will find
41
+ // packages/base/package.json, but we want to get the monorepo root package.json instead
42
+ // if @jcoreio/toolchains is operating on itself. But if we're invoking the CLI from
43
+ // a working copy of the monorepo from a cwd outside of it, we want to error out
44
+ let packageJson = fs.readJsonSync(packageJsonFile)
45
+ debug({ step: 2, 'packageJson.name': packageJson.name })
46
+
47
+ if (packageJson.name === name) {
48
+ packageJsonFile = findUp.sync('package.json', {
49
+ cwd: Path.dirname(Path.dirname(packageJsonFile)),
50
+ type: 'file',
51
+ })
52
+ packageJson = packageJsonFile ? fs.readJsonSync(packageJsonFile) : undefined
53
+ debug({
54
+ step: 3,
55
+ packageJsonFile,
56
+ 'packageJson.name': packageJson.name,
57
+ })
58
+ if (
59
+ // When vscode-prettier is trying to format a file in this monorepo, the
60
+ // cwd may be outside the monorepo, which would make our logic decide
61
+ // no project is found...we work around this by setting this environment
62
+ // variable in the tool configs.
63
+ (!process.env.JCOREIO_TOOLCHAIN_SELF_TEST &&
64
+ Path.relative(Path.dirname(packageJsonFile), process.cwd()).startsWith(
65
+ '..'
66
+ )) ||
67
+ !packageJson ||
68
+ packageJson.name !== '@jcoreio/toolchains'
69
+ ) {
70
+ debug(`failed to find project package.json in a parent directory of ${dir}`)
71
+ throw new Error(
72
+ `failed to find project package.json in a parent directory of ${dir}`
73
+ )
74
+ }
75
+ }
76
+ exports.packageJsonFile = packageJsonFile
77
+ exports.packageJson = packageJson
22
78
  const projectDir = (exports.projectDir = Path.dirname(packageJsonFile))
23
79
 
24
80
  const pnpmWorkspaceFile = (exports.pnpmWorkspaceFile = findUp.sync(
25
81
  'pnpm-workspace.yaml',
26
82
  {
27
- cwd,
83
+ dir,
28
84
  type: 'file',
29
85
  }
30
86
  ))
@@ -141,7 +197,7 @@ try {
141
197
  } catch (error) {
142
198
  const toolchainConfigLocation =
143
199
  toolchainConfigFile ?
144
- Path.relative(cwd, toolchainConfigFile)
200
+ Path.relative(process.cwd(), toolchainConfigFile)
145
201
  : `packageJson[${JSON.stringify(name)}]`
146
202
 
147
203
  // eslint-disable-next-line no-console
@@ -185,3 +241,5 @@ for (const toolchainPkgJson of Object.values(toolchainPackageJsons)) {
185
241
  }
186
242
  }
187
243
  }
244
+
245
+ debug(exports)
@@ -1,6 +1,6 @@
1
1
  const { name } = require('../package.json')
2
2
  const { format } = require('prettier')
3
- const prettierConfig = require('../prettier.config.cjs')
3
+ const prettierConfig = require('../prettierConfig.cjs')
4
4
  const { statement, expression, default: template } = require('@babel/template')
5
5
  const { generate } = require('@babel/generator')
6
6
  const path = require('path')
File without changes