gulp-prettier 5.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 (4) hide show
  1. package/LICENSE +0 -1
  2. package/README.md +16 -14
  3. package/index.js +92 -90
  4. package/package.json +27 -20
package/LICENSE CHANGED
@@ -1,6 +1,5 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2016-2020 Patel, Bhargav R.
4
3
  Copyright (c) 2020 Thomas Vantuycom
5
4
 
6
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
package/README.md CHANGED
@@ -1,45 +1,47 @@
1
- # gulp-prettier ![GitHub Workflow Status](https://github.com/TheDancingCode/gulp-prettier/actions/workflows/ci.yml/badge.svg) [![npm version](https://img.shields.io/npm/v/gulp-prettier.svg)](https://www.npmjs.com/package/gulp-prettier) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
1
+ # gulp-prettier
2
2
 
3
3
  > Format files with [Prettier](https://github.com/prettier/prettier)
4
4
 
5
+ [![GitHub Workflow Status](https://github.com/TheDancingCode/gulp-prettier/actions/workflows/ci.yml/badge.svg)](https://github.com/thomasvantuycom/gulp-prettier/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/gulp-prettier.svg)](https://www.npmjs.com/package/gulp-prettier) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
6
+
5
7
  ## Install
6
8
 
7
- ```
9
+ ```sh
8
10
  npm install gulp-prettier --save-dev
9
11
  ```
10
12
 
11
13
  ## Usage
12
14
 
13
15
  ```js
14
- const { src, dest } = require('gulp');
15
- const prettier = require('gulp-prettier');
16
+ import gulp from 'gulp';
17
+ import prettier from 'gulp-prettier';
16
18
 
17
19
  function format() {
18
- return src('src/*.js')
20
+ return gulp.src('src/*.js')
19
21
  .pipe(prettier({ singleQuote: true }))
20
- .pipe(dest('dist'));
22
+ .pipe(gulp.dest('dist'));
21
23
  }
22
24
 
23
- exports.default = format;
25
+ export default format;
24
26
  ```
25
27
 
26
28
  To check whether or not your files adhere to Prettier's formatting, use `prettier.check`. This can be used as a validation step in CI scenarios.
27
29
 
28
30
  ```js
29
- const { src, dest } = require('gulp');
30
- const prettier = require('gulp-prettier');
31
+ import gulp from 'gulp';
32
+ import prettier from 'gulp-prettier';
31
33
 
32
34
  function validate() {
33
- return src('dist/*.js')
35
+ return gulp.src('dist/*.js')
34
36
  .pipe(prettier.check({ singleQuote: true }));
35
37
  }
36
38
 
37
- exports.default = validate;
39
+ export default validate;
38
40
  ```
39
41
 
40
42
  ## API
41
43
 
42
- ### prettier([options])
44
+ ### prettier(?options)
43
45
 
44
46
  Formats your files using Prettier.
45
47
 
@@ -51,7 +53,7 @@ Consult the Prettier [options](https://prettier.io/docs/en/options.html).
51
53
 
52
54
  `editorconfig: true` can also be passed to enable [EditorConfig support](https://prettier.io/docs/en/api.html#prettierresolveconfigfilepath--options).
53
55
 
54
- ### prettier.check([options])
56
+ ### prettier.check(?options)
55
57
 
56
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.
57
59
 
@@ -65,4 +67,4 @@ Consult the Prettier [options](https://prettier.io/docs/en/options.html).
65
67
 
66
68
  ## License
67
69
 
68
- MIT © [Bhargav R. Patel](https://github.com/bhargavrpatel), [Thomas Vantuycom](https://github.com/TheDancingCode)
70
+ MIT © [Thomas Vantuycom](https://github.com/thomasvantuycom)
package/index.js CHANGED
@@ -1,102 +1,104 @@
1
- 'use strict';
2
- const path = require('path');
3
- const through = require('through2');
4
- const PluginError = require('plugin-error');
5
- const prettier = require('prettier');
1
+ import path from 'node:path';
2
+ import {Transform} from 'node:stream';
3
+ import {Buffer} from 'node:buffer';
4
+ import process from 'node:process';
5
+ import PluginError from 'plugin-error';
6
+ import prettier from 'prettier';
6
7
 
7
- const PLUGIN_NAME = 'gulp-prettier';
8
+ export default function plugin(options = {}) {
9
+ return new Transform({
10
+ objectMode: true,
8
11
 
9
- module.exports = function (options) {
10
- options = options || {};
12
+ async transform(file, _, callback) {
13
+ if (file.isNull()) {
14
+ callback(null, file);
11
15
 
12
- return through.obj(async function (file, encoding, callback) {
13
- if (file.isNull()) {
14
- return callback(null, file);
15
- }
16
+ return;
17
+ }
16
18
 
17
- if (file.isStream()) {
18
- return callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
19
- }
19
+ if (file.isStream()) {
20
+ callback(new PluginError('gulp-prettier', 'Streaming not supported'));
20
21
 
21
- const config = await prettier.resolveConfig(file.path, options);
22
- const fileOptions = { ...config, ...options, filepath: file.path };
22
+ return;
23
+ }
23
24
 
24
- const unformattedCode = file.contents.toString('utf8');
25
+ try {
26
+ const config = await prettier.resolveConfig(file.path, options);
27
+ const fileOptions = {...config, ...options, filepath: file.path};
25
28
 
26
- try {
27
- const formattedCode = await prettier.format(unformattedCode, fileOptions);
29
+ const unformattedCode = file.contents.toString('utf8');
30
+ const formattedCode = await prettier.format(unformattedCode, fileOptions);
28
31
 
29
- if (formattedCode !== unformattedCode) {
30
- file.isPrettier = true;
31
- file.contents = Buffer.from(formattedCode);
32
- }
32
+ if (formattedCode !== unformattedCode) {
33
+ file.isPrettier = true;
34
+ file.contents = Buffer.from(formattedCode);
35
+ }
33
36
 
34
- this.push(file);
35
- } catch (error) {
36
- this.emit(
37
- 'error',
38
- new PluginError(PLUGIN_NAME, error, { fileName: file.path })
39
- );
40
- }
37
+ callback(null, file);
38
+ } catch (error) {
39
+ callback(new PluginError('gulp-prettier', error, {fileName: file.path}));
40
+ }
41
+ },
42
+ });
43
+ }
41
44
 
42
- callback();
43
- });
44
- };
45
+ plugin.check = function (options = {}) {
46
+ return new Transform({
47
+ objectMode: true,
48
+
49
+ construct(callback) {
50
+ this.unformattedFiles = [];
51
+
52
+ callback();
53
+ },
54
+
55
+ async transform(file, _, callback) {
56
+ if (file.isNull()) {
57
+ callback(null, file);
58
+
59
+ return;
60
+ }
61
+
62
+ if (file.isStream()) {
63
+ callback(new PluginError('gulp-prettier', 'Streaming not supported'));
64
+
65
+ return;
66
+ }
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');
73
+ const isFormatted = await prettier.check(unformattedCode, fileOptions);
74
+
75
+ if (!isFormatted) {
76
+ const filename = path
77
+ .relative(process.cwd(), file.path)
78
+ .replaceAll('\\', '/');
79
+ this.unformattedFiles.push(filename);
80
+ }
81
+
82
+ callback(null, file);
83
+ } catch (error) {
84
+ callback(new PluginError('gulp-prettier', error, {fileName: file.path}));
85
+ }
86
+ },
87
+
88
+ flush(callback) {
89
+ if (this.unformattedFiles.length > 0) {
90
+ const header
91
+ = 'Code style issues found in the following file(s). Forgot to run Prettier?';
92
+ const body = this.unformattedFiles.join('\n');
93
+
94
+ const message = `${header}\n${body}`;
95
+
96
+ callback(new PluginError('gulp-prettier', message));
97
+
98
+ return;
99
+ }
45
100
 
46
- module.exports.check = function (options) {
47
- options = options || {};
48
-
49
- const unformattedFiles = [];
50
-
51
- return through.obj(
52
- async function (file, encoding, callback) {
53
- if (file.isNull()) {
54
- return callback(null, file);
55
- }
56
-
57
- if (file.isStream()) {
58
- return callback(
59
- new PluginError(PLUGIN_NAME, 'Streaming not supported')
60
- );
61
- }
62
-
63
- const config = await prettier.resolveConfig(file.path, options);
64
- const fileOptions = { ...config, ...options, filepath: file.path };
65
-
66
- const unformattedCode = file.contents.toString('utf8');
67
-
68
- try {
69
- const isFormatted = await prettier.check(unformattedCode, fileOptions);
70
-
71
- if (!isFormatted) {
72
- const filename = path
73
- .relative(process.cwd(), file.path)
74
- .replace(/\\/g, '/');
75
- unformattedFiles.push(filename);
76
- }
77
-
78
- this.push(file);
79
- } catch (error) {
80
- this.emit(
81
- 'error',
82
- new PluginError(PLUGIN_NAME, error, { fileName: file.path })
83
- );
84
- }
85
-
86
- callback();
87
- },
88
- function (callback) {
89
- if (unformattedFiles.length > 0) {
90
- const header =
91
- 'Code style issues found in the following file(s). Forgot to run Prettier?';
92
- const body = unformattedFiles.join('\n');
93
-
94
- const message = `${header}\n${body}`;
95
-
96
- this.emit('error', new PluginError(PLUGIN_NAME, message));
97
- }
98
-
99
- callback();
100
- }
101
- );
101
+ callback();
102
+ },
103
+ });
102
104
  };
package/package.json CHANGED
@@ -1,14 +1,21 @@
1
1
  {
2
2
  "name": "gulp-prettier",
3
+ "version": "7.0.0",
3
4
  "description": "Format files with Prettier",
4
- "version": "5.0.0",
5
- "main": "index.js",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/TheDancingCode/gulp-prettier.git"
5
+ "license": "MIT",
6
+ "repository": "thomasvantuycom/gulp-prettier",
7
+ "author": {
8
+ "name": "Thomas Vantuycom",
9
+ "email": "thomasvantuycom@proton.me",
10
+ "url": "https://www.thomasvantuycom.com"
11
+ },
12
+ "type": "module",
13
+ "exports": "./index.js",
14
+ "engines": {
15
+ "node": ">=24"
9
16
  },
10
17
  "scripts": {
11
- "test": "ava"
18
+ "test": "xo && ava"
12
19
  },
13
20
  "files": [
14
21
  "index.js"
@@ -19,23 +26,18 @@
19
26
  "gulp-prettier",
20
27
  "gulpplugin"
21
28
  ],
22
- "engines": {
23
- "node": ">=16"
24
- },
25
- "author": "Thomas Vantuycom",
26
- "license": "MIT",
27
29
  "dependencies": {
28
- "plugin-error": "^2.0.0",
29
- "prettier": "^3.0.0",
30
- "through2": "^4.0.2"
30
+ "plugin-error": "^2.0.1",
31
+ "prettier": "^3.9.5"
31
32
  },
32
33
  "devDependencies": {
33
- "@semantic-release/changelog": "^5.0.0",
34
- "@semantic-release/git": "^9.0.0",
35
- "ava": "^5.1.0",
36
- "p-event": "4.2.0",
37
- "semantic-release": "^17.2.3",
38
- "vinyl": "^3.0.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"
39
41
  },
40
42
  "release": {
41
43
  "plugins": [
@@ -51,5 +53,10 @@
51
53
  ],
52
54
  "@semantic-release/github"
53
55
  ]
56
+ },
57
+ "xo": {
58
+ "rules": {
59
+ "markdown/no-multiple-h1": "off"
60
+ }
54
61
  }
55
62
  }