@jcoreio/toolchain 5.4.2 → 5.4.4

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.2",
3
+ "version": "5.4.4",
4
4
  "description": "base JS build toolchain",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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
@@ -7,27 +7,66 @@ const once = require('./once.cjs')
7
7
  const { name } = require('../package.json')
8
8
  const configSchema = require('./configSchema.cjs')
9
9
 
10
- const cwd = (
11
- fs.pathExistsSync(Path.join(process.cwd(), 'package.json')) ?
12
- process.cwd()
13
- : __filename).replace(/\/node_modules(\/.*|$)/, '')
14
-
15
- const packageJsonFile = (exports.packageJsonFile = findUp.sync('package.json', {
16
- cwd,
10
+ // First see if the cwd is within a project dir
11
+ let dir = process
12
+ .cwd()
13
+ .replace(/\/node_modules(\/.*|$)|\\node_modules(\\.*|$)/, '')
14
+ let packageJsonFile = findUp.sync('package.json', {
15
+ cwd: dir,
17
16
  type: 'file',
18
- }))
17
+ })
18
+
19
+ if (!packageJsonFile) {
20
+ // When the cwd is not within a project dir, see if this file is within a project dir
21
+ dir = __dirname.replace(/\/node_modules(\/.*|$)|\\node_modules(\\.*|$)/, '')
22
+
23
+ packageJsonFile = findUp.sync('package.json', {
24
+ cwd: dir,
25
+ type: 'file',
26
+ })
27
+ }
19
28
  if (!packageJsonFile) {
20
29
  throw new Error(
21
- `failed to find project package.json in a parent directory of ${cwd}`
30
+ `failed to find project package.json in a parent directory of ${dir}`
22
31
  )
23
32
  }
24
- const packageJson = (exports.packageJson = fs.readJsonSync(packageJsonFile))
33
+
34
+ // When this file is within the @jcoreio/toolchains monorepo, the above will find
35
+ // packages/base/package.json, but we want to get the monorepo root package.json instead
36
+ // if @jcoreio/toolchains is operating on itself. But if we're invoking the CLI from
37
+ // a working copy of the monorepo from a cwd outside of it, we want to error out
38
+ let packageJson = fs.readJsonSync(packageJsonFile)
39
+ if (packageJson.name === name) {
40
+ packageJsonFile = findUp.sync('package.json', {
41
+ cwd: Path.dirname(Path.dirname(packageJsonFile)),
42
+ type: 'file',
43
+ })
44
+ packageJson = packageJsonFile ? fs.readJsonSync(packageJsonFile) : undefined
45
+ if (
46
+ // When vscode-prettier is trying to format a file in this monorepo, the
47
+ // cwd may be outside the monorepo, which would make our logic decide
48
+ // no project is found...we work around this by setting this environment
49
+ // variable in the tool configs.
50
+ (!process.env.JCOREIO_TOOLCHAIN_SELF_TEST &&
51
+ Path.relative(Path.dirname(packageJsonFile), process.cwd()).startsWith(
52
+ '..'
53
+ )) ||
54
+ !packageJson ||
55
+ packageJson.name !== '@jcoreio/toolchains'
56
+ ) {
57
+ throw new Error(
58
+ `failed to find project package.json in a parent directory of ${dir}`
59
+ )
60
+ }
61
+ }
62
+ exports.packageJsonFile = packageJsonFile
63
+ exports.packageJson = packageJson
25
64
  const projectDir = (exports.projectDir = Path.dirname(packageJsonFile))
26
65
 
27
66
  const pnpmWorkspaceFile = (exports.pnpmWorkspaceFile = findUp.sync(
28
67
  'pnpm-workspace.yaml',
29
68
  {
30
- cwd,
69
+ dir,
31
70
  type: 'file',
32
71
  }
33
72
  ))
@@ -144,7 +183,7 @@ try {
144
183
  } catch (error) {
145
184
  const toolchainConfigLocation =
146
185
  toolchainConfigFile ?
147
- Path.relative(cwd, toolchainConfigFile)
186
+ Path.relative(process.cwd(), toolchainConfigFile)
148
187
  : `packageJson[${JSON.stringify(name)}]`
149
188
 
150
189
  // eslint-disable-next-line no-console
@@ -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