@dotcom-tool-kit/prettier 4.1.1 → 4.2.1

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.
@@ -8,36 +8,6 @@ const logger_1 = require("@dotcom-tool-kit/logger");
8
8
  const base_1 = require("@dotcom-tool-kit/base");
9
9
  const error_1 = require("@dotcom-tool-kit/error");
10
10
  class Prettier extends base_1.Task {
11
- constructor() {
12
- super(...arguments);
13
- this.formatFile = async (filepath, options) => {
14
- const fileContent = await fs_1.promises.readFile(filepath, 'utf8');
15
- let prettierConfig;
16
- try {
17
- prettierConfig = await prettier_1.default.resolveConfig(filepath, { config: options.configFile });
18
- }
19
- catch (err) {
20
- if (err.code !== 'ENOENT') {
21
- const error = new error_1.ToolKitError('there was an error when resolving the prettier config');
22
- if (err instanceof Error) {
23
- error.details = err.message;
24
- }
25
- throw error;
26
- }
27
- }
28
- const { ignored } = await prettier_1.default.getFileInfo(filepath, { ignorePath: this.options.ignoreFile });
29
- if (ignored) {
30
- return;
31
- }
32
- const unhook = (0, logger_1.hookConsole)(this.logger, 'prettier');
33
- try {
34
- await fs_1.promises.writeFile(filepath, prettier_1.default.format(fileContent, { ...prettierConfig, filepath }));
35
- }
36
- finally {
37
- unhook();
38
- }
39
- };
40
- }
41
11
  async run({ files, cwd }) {
42
12
  try {
43
13
  const filepaths = await (0, fast_glob_1.default)(files ?? this.options.files, { cwd });
@@ -56,5 +26,32 @@ class Prettier extends base_1.Task {
56
26
  throw error;
57
27
  }
58
28
  }
29
+ formatFile = async (filepath, options) => {
30
+ const fileContent = await fs_1.promises.readFile(filepath, 'utf8');
31
+ let prettierConfig;
32
+ try {
33
+ prettierConfig = await prettier_1.default.resolveConfig(filepath, { config: options.configFile });
34
+ }
35
+ catch (err) {
36
+ if (err.code !== 'ENOENT') {
37
+ const error = new error_1.ToolKitError('there was an error when resolving the prettier config');
38
+ if (err instanceof Error) {
39
+ error.details = err.message;
40
+ }
41
+ throw error;
42
+ }
43
+ }
44
+ const { ignored } = await prettier_1.default.getFileInfo(filepath, { ignorePath: this.options.ignoreFile });
45
+ if (ignored) {
46
+ return;
47
+ }
48
+ const unhook = (0, logger_1.hookConsole)(this.logger, 'prettier');
49
+ try {
50
+ await fs_1.promises.writeFile(filepath, prettier_1.default.format(fileContent, { ...prettierConfig, filepath }));
51
+ }
52
+ finally {
53
+ unhook();
54
+ }
55
+ };
59
56
  }
60
57
  exports.default = Prettier;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcom-tool-kit/prettier",
3
- "version": "4.1.1",
3
+ "version": "4.2.1",
4
4
  "description": "",
5
5
  "main": "lib",
6
6
  "scripts": {
@@ -10,10 +10,10 @@
10
10
  "author": "FT.com Platforms Team <platforms-team.customer-products@ft.com>",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@dotcom-tool-kit/base": "^1.1.1",
14
- "@dotcom-tool-kit/error": "^4.0.1",
15
- "@dotcom-tool-kit/logger": "^4.0.1",
16
- "@dotcom-tool-kit/package-json-hook": "^5.0.4",
13
+ "@dotcom-tool-kit/base": "^1.1.3",
14
+ "@dotcom-tool-kit/error": "^4.1.0",
15
+ "@dotcom-tool-kit/logger": "^4.1.0",
16
+ "@dotcom-tool-kit/package-json-hook": "^5.1.1",
17
17
  "fast-glob": "^3.2.7",
18
18
  "hook-std": "^2.0.0",
19
19
  "prettier": "^2.2.1",
@@ -41,7 +41,6 @@
41
41
  "dotcom-tool-kit": "4.x"
42
42
  },
43
43
  "engines": {
44
- "node": "18.x || 20.x",
45
- "npm": "7.x || 8.x || 9.x || 10.x"
44
+ "node": "18.x || 20.x || 22.x"
46
45
  }
47
46
  }