gulp-prettier 6.0.0 → 7.0.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.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/index.js +42 -39
  3. package/package.json +16 -11
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ## Install
8
8
 
9
- ```
9
+ ```sh
10
10
  npm install gulp-prettier --save-dev
11
11
  ```
12
12
 
@@ -41,7 +41,7 @@ export default validate;
41
41
 
42
42
  ## API
43
43
 
44
- ### prettier([options])
44
+ ### prettier(?options)
45
45
 
46
46
  Formats your files using Prettier.
47
47
 
@@ -53,7 +53,7 @@ Consult the Prettier [options](https://prettier.io/docs/en/options.html).
53
53
 
54
54
  `editorconfig: true` can also be passed to enable [EditorConfig support](https://prettier.io/docs/en/api.html#prettierresolveconfigfilepath--options).
55
55
 
56
- ### prettier.check([options])
56
+ ### prettier.check(?options)
57
57
 
58
58
  Checks if your files have been formatted with Prettier and, if not, throws an error with a list of unformatted files. This is useful for running Prettier in CI scenarios.
59
59
 
package/index.js CHANGED
@@ -8,21 +8,25 @@ import prettier from 'prettier';
8
8
  export default function plugin(options = {}) {
9
9
  return new Transform({
10
10
  objectMode: true,
11
- async transform(file, encoding, callback) {
11
+
12
+ async transform(file, _, callback) {
12
13
  if (file.isNull()) {
13
- return callback(null, file);
14
- }
14
+ callback(null, file);
15
15
 
16
- if (file.isStream()) {
17
- return callback(new PluginError('gulp-prettier', 'Streaming not supported'));
16
+ return;
18
17
  }
19
18
 
20
- const config = await prettier.resolveConfig(file.path, options);
21
- const fileOptions = {...config, ...options, filepath: file.path};
19
+ if (file.isStream()) {
20
+ callback(new PluginError('gulp-prettier', 'Streaming not supported'));
22
21
 
23
- const unformattedCode = file.contents.toString('utf8');
22
+ return;
23
+ }
24
24
 
25
25
  try {
26
+ const config = await prettier.resolveConfig(file.path, options);
27
+ const fileOptions = {...config, ...options, filepath: file.path};
28
+
29
+ const unformattedCode = file.contents.toString('utf8');
26
30
  const formattedCode = await prettier.format(unformattedCode, fileOptions);
27
31
 
28
32
  if (formattedCode !== unformattedCode) {
@@ -30,69 +34,68 @@ export default function plugin(options = {}) {
30
34
  file.contents = Buffer.from(formattedCode);
31
35
  }
32
36
 
33
- this.push(file);
37
+ callback(null, file);
34
38
  } catch (error) {
35
- this.emit(
36
- 'error',
37
- new PluginError('gulp-prettier', error, {fileName: file.path}),
38
- );
39
+ callback(new PluginError('gulp-prettier', error, {fileName: file.path}));
39
40
  }
40
-
41
- callback();
42
41
  },
43
42
  });
44
43
  }
45
44
 
46
45
  plugin.check = function (options = {}) {
47
- const unformattedFiles = [];
48
-
49
46
  return new Transform({
50
47
  objectMode: true,
51
- async transform(file, encoding, callback) {
48
+
49
+ construct(callback) {
50
+ this.unformattedFiles = [];
51
+
52
+ callback();
53
+ },
54
+
55
+ async transform(file, _, callback) {
52
56
  if (file.isNull()) {
53
- return callback(null, file);
54
- }
57
+ callback(null, file);
55
58
 
56
- if (file.isStream()) {
57
- return callback(
58
- new PluginError('gulp-prettier', 'Streaming not supported'),
59
- );
59
+ return;
60
60
  }
61
61
 
62
- const config = await prettier.resolveConfig(file.path, options);
63
- const fileOptions = {...config, ...options, filepath: file.path};
62
+ if (file.isStream()) {
63
+ callback(new PluginError('gulp-prettier', 'Streaming not supported'));
64
64
 
65
- const unformattedCode = file.contents.toString('utf8');
65
+ return;
66
+ }
66
67
 
67
68
  try {
69
+ const config = await prettier.resolveConfig(file.path, options);
70
+ const fileOptions = {...config, ...options, filepath: file.path};
71
+
72
+ const unformattedCode = file.contents.toString('utf8');
68
73
  const isFormatted = await prettier.check(unformattedCode, fileOptions);
69
74
 
70
75
  if (!isFormatted) {
71
76
  const filename = path
72
77
  .relative(process.cwd(), file.path)
73
78
  .replaceAll('\\', '/');
74
- unformattedFiles.push(filename);
79
+ this.unformattedFiles.push(filename);
75
80
  }
76
81
 
77
- this.push(file);
82
+ callback(null, file);
78
83
  } catch (error) {
79
- this.emit(
80
- 'error',
81
- new PluginError('gulp-prettier', error, {fileName: file.path}),
82
- );
84
+ callback(new PluginError('gulp-prettier', error, {fileName: file.path}));
83
85
  }
84
-
85
- callback();
86
86
  },
87
+
87
88
  flush(callback) {
88
- if (unformattedFiles.length > 0) {
89
+ if (this.unformattedFiles.length > 0) {
89
90
  const header
90
- = 'Code style issues found in the following file(s). Forgot to run Prettier?';
91
- const body = unformattedFiles.join('\n');
91
+ = 'Code style issues found in the following file(s). Forgot to run Prettier?';
92
+ const body = this.unformattedFiles.join('\n');
92
93
 
93
94
  const message = `${header}\n${body}`;
94
95
 
95
- this.emit('error', new PluginError('gulp-prettier', message));
96
+ callback(new PluginError('gulp-prettier', message));
97
+
98
+ return;
96
99
  }
97
100
 
98
101
  callback();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gulp-prettier",
3
- "version": "6.0.0",
3
+ "version": "7.0.0",
4
4
  "description": "Format files with Prettier",
5
5
  "license": "MIT",
6
6
  "repository": "thomasvantuycom/gulp-prettier",
@@ -12,7 +12,7 @@
12
12
  "type": "module",
13
13
  "exports": "./index.js",
14
14
  "engines": {
15
- "node": ">=18"
15
+ "node": ">=24"
16
16
  },
17
17
  "scripts": {
18
18
  "test": "xo && ava"
@@ -27,17 +27,17 @@
27
27
  "gulpplugin"
28
28
  ],
29
29
  "dependencies": {
30
- "plugin-error": "^2.0.0",
31
- "prettier": "^3.0.0"
30
+ "plugin-error": "^2.0.1",
31
+ "prettier": "^3.9.5"
32
32
  },
33
33
  "devDependencies": {
34
- "@semantic-release/changelog": "^6.0.0",
35
- "@semantic-release/git": "^10.0.0",
36
- "ava": "^5.1.0",
37
- "p-event": "^6.0.0",
38
- "semantic-release": "^22.0.0",
39
- "vinyl": "^3.0.0",
40
- "xo": "^0.56.0"
34
+ "@semantic-release/changelog": "^6.0.3",
35
+ "@semantic-release/git": "^10.0.1",
36
+ "ava": "^8.0.1",
37
+ "p-event": "^7.1.0",
38
+ "semantic-release": "^25.0.7",
39
+ "vinyl": "^3.0.1",
40
+ "xo": "^4.0.0"
41
41
  },
42
42
  "release": {
43
43
  "plugins": [
@@ -53,5 +53,10 @@
53
53
  ],
54
54
  "@semantic-release/github"
55
55
  ]
56
+ },
57
+ "xo": {
58
+ "rules": {
59
+ "markdown/no-multiple-h1": "off"
60
+ }
56
61
  }
57
62
  }