@ivuorinen/prettier-config 2.0.11 → 2.0.13

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
@@ -24,24 +24,34 @@ npm install @ivuorinen/prettier-config --save-dev
24
24
  yarn add @ivuorinen/prettier-config --dev
25
25
  ```
26
26
 
27
- After installing it, a _`.prettierrc.json`_ file will be created automatically in the project's root folder with the following configuration:
27
+ Create a _`.prettierrc.json`_ in the project's root folder with the following configuration:
28
28
 
29
29
  ```json
30
30
  "@ivuorinen/prettier-config"
31
31
  ```
32
32
 
33
+ With npm, a `postinstall` script writes exactly this file when the project has no Prettier config yet (npm 11 warns
34
+ that the script is not covered by `allowScripts`). Yarn 4 does not run dependency install scripts, so no file is
35
+ written. pnpm refuses unapproved install scripts and fails the install until you allow this package with
36
+ `pnpm approve-builds`. In both cases create the file by hand as above — without it Prettier silently formats with its
37
+ own defaults.
38
+
33
39
  > Note: This method does **not** offer a way to _extend_ the configuration to
34
40
  > overwrite some properties from the shared configuration. If you need to do
35
- > that, import the file in a _`.prettierrc.js`_ file and export the
41
+ > that, import it in a _`prettier.config.mjs`_ file and export the
36
42
  > modifications, e.g:
37
43
  >
38
44
  > ```js
39
- > module.exports = {
40
- > ...require("@ivuorinen/prettier-config"),
45
+ > import ivuorinenConfig from '@ivuorinen/prettier-config'
46
+ >
47
+ > export default {
48
+ > ...ivuorinenConfig,
41
49
  > // Add custom options below:
42
- > semi: true,
43
- > };
50
+ > semi: true
51
+ > }
44
52
  > ```
53
+ >
54
+ > The `.mjs` extension keeps the file an ES module whether or not your `package.json` sets `"type": "module"`.
45
55
 
46
56
  ## Documentations
47
57
 
@@ -49,7 +59,7 @@ Read the [Prettier docs][prettier-docs-link] for more information.
49
59
 
50
60
  ## Contributing
51
61
 
52
- If you are interested in helping contribute, please take a look at our [contribution guidelines][contributing-link] and open an [issue][issue-link] or [pull request][pull-request-link].
62
+ If you are interested in helping contribute, please open an [issue][issue-link] or [pull request][pull-request-link].
53
63
 
54
64
  ## Changelog
55
65
 
@@ -62,10 +72,9 @@ Distributed under the MIT License. See [LICENSE][license-link] for more informat
62
72
  [changelog-link]: https://github.com/ivuorinen/base-configs-prettier/releases
63
73
  [prettier-docs-link]: https://prettier.io
64
74
  [prettier-link]: https://github.com/prettier/prettier
65
- [contributing-link]: https://github.com/ivuorinen/.github/blob/main/CONTRIBUTING.md
66
75
  [issue-link]: https://github.com/ivuorinen/base-configs-prettier/issues
67
76
  [license-badge]: https://img.shields.io/github/license/ivuorinen/base-configs-prettier?style=flat-square&labelColor=292a44&color=663399
68
- [license-link]: ./LICENSE
77
+ [license-link]: ./LICENSE.md
69
78
  [npm-badge]: https://img.shields.io/npm/v/@ivuorinen/prettier-config?style=flat-square&labelColor=292a44&color=663399
70
79
  [npm-link]: https://www.npmjs.com/package/@ivuorinen/prettier-config
71
80
  [pull-request-link]: https://github.com/ivuorinen/base-configs-prettier/pulls
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ivuorinen/prettier-config",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "type": "module",
5
5
  "description": "ivuorinen's shareable configuration for Prettier.",
6
6
  "author": {
@@ -40,7 +40,8 @@
40
40
  "url": "git+https://github.com/ivuorinen/base-configs-prettier.git"
41
41
  },
42
42
  "scripts": {
43
- "postinstall": "node scripts/postinstall.cjs"
43
+ "postinstall": "node scripts/postinstall.cjs",
44
+ "test": "node --test"
44
45
  },
45
46
  "dependencies": {
46
47
  "@ivuorinen/config-checker": "^2.2.1",
@@ -48,7 +49,7 @@
48
49
  },
49
50
  "packageManager": "yarn@4.18.0",
50
51
  "devDependencies": {
51
- "@ivuorinen/semantic-release-config": "^2.0.0"
52
+ "@ivuorinen/semantic-release-config": "^3.0.0"
52
53
  },
53
54
  "resolutions": {
54
55
  "brace-expansion": "^5.0.7",
@@ -7,7 +7,14 @@ const path = require('node:path')
7
7
  // noinspection NpmUsedModulesInstalled
8
8
  const process = require('node:process')
9
9
  const checkConfig = require('@ivuorinen/config-checker')
10
- const foundConfig = checkConfig('prettier')
10
+
11
+ // This runs on every consumer install, and a non-zero exit fails that whole
12
+ // install. The starter config is a convenience, so every step below degrades to
13
+ // a message instead of throwing.
14
+
15
+ // INIT_CWD is an npm/yarn convention, not a guarantee.
16
+ const cwd = process.env.INIT_CWD || process.cwd()
17
+ const foundConfig = checkConfig('prettier', cwd)
11
18
 
12
19
  if (foundConfig.length > 0) {
13
20
  console.log('prettier-config: Found existing prettier config file, skipping creation.')
@@ -16,9 +23,16 @@ if (foundConfig.length > 0) {
16
23
  process.exit(0)
17
24
  }
18
25
 
19
- const filePath = path.join(process.env.INIT_CWD, '.prettierrc.json')
26
+ const filePath = path.join(cwd, '.prettierrc.json')
20
27
  const fileConfigObject = '@ivuorinen/prettier-config'
21
28
 
22
- if (!fs.existsSync(filePath)) {
23
- fs.writeFileSync(filePath, JSON.stringify(fileConfigObject, undefined, 2))
29
+ // 'wx' makes "does it exist?" and "write it" one atomic step, so a concurrent
30
+ // install cannot create the file in between and have it overwritten.
31
+ try {
32
+ fs.writeFileSync(filePath, JSON.stringify(fileConfigObject, undefined, 2), { flag: 'wx' })
33
+ } catch (error) {
34
+ if (error.code !== 'EEXIST') {
35
+ console.log(`prettier-config: could not write ${filePath} (${error.code || error.message}).`)
36
+ console.log(`prettier-config: create it manually containing: "${fileConfigObject}"`)
37
+ }
24
38
  }