@dotcom-tool-kit/prettier 1.1.0 → 1.2.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.
- package/.toolkitrc.yml +1 -4
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/tasks/prettier.d.ts +1 -1
- package/lib/tasks/prettier.d.ts.map +1 -1
- package/lib/tasks/prettier.js +15 -17
- package/package.json +4 -4
package/.toolkitrc.yml
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Prettier from './tasks/prettier';
|
|
2
1
|
import { PackageJsonHook } from '@dotcom-tool-kit/package-json-hook';
|
|
2
|
+
import Prettier from './tasks/prettier';
|
|
3
3
|
export declare const tasks: (typeof Prettier)[];
|
|
4
4
|
declare class FormatLocal extends PackageJsonHook {
|
|
5
5
|
static description: string;
|
|
6
|
-
|
|
6
|
+
key: string;
|
|
7
7
|
hook: string;
|
|
8
8
|
}
|
|
9
9
|
export declare const hooks: {
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AACpE,OAAO,QAAQ,MAAM,kBAAkB,CAAA;AAEvC,eAAO,MAAM,KAAK,qBAAa,CAAA;AAE/B,cAAM,WAAY,SAAQ,eAAe;IACvC,MAAM,CAAC,WAAW,SAAoB;IAEtC,GAAG,SAAW;IACd,IAAI,SAAiB;CACtB;AAED,eAAO,MAAM,KAAK;;CAEjB,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hooks = exports.tasks = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const prettier_1 = (0, tslib_1.__importDefault)(require("./tasks/prettier"));
|
|
6
5
|
const package_json_hook_1 = require("@dotcom-tool-kit/package-json-hook");
|
|
6
|
+
const prettier_1 = (0, tslib_1.__importDefault)(require("./tasks/prettier"));
|
|
7
7
|
exports.tasks = [prettier_1.default];
|
|
8
8
|
class FormatLocal extends package_json_hook_1.PackageJsonHook {
|
|
9
9
|
constructor() {
|
|
10
10
|
super(...arguments);
|
|
11
|
-
this.
|
|
11
|
+
this.key = 'format';
|
|
12
12
|
this.hook = `format:local`;
|
|
13
13
|
}
|
|
14
14
|
}
|
package/lib/tasks/prettier.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import { Task } from '@dotcom-tool-kit/task';
|
|
|
3
3
|
export default class Prettier extends Task<typeof PrettierSchema> {
|
|
4
4
|
static description: string;
|
|
5
5
|
static defaultOptions: PrettierOptions;
|
|
6
|
-
run(): Promise<void>;
|
|
6
|
+
run(files?: string[]): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=prettier.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prettier.d.ts","sourceRoot":"","sources":["../../src/tasks/prettier.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAA;AAG5F,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAG5C,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,IAAI,CAAC,OAAO,cAAc,CAAC;IAC/D,MAAM,CAAC,WAAW,SAAK;IAEvB,MAAM,CAAC,cAAc,EAAE,eAAe,CASrC;IAEK,GAAG,
|
|
1
|
+
{"version":3,"file":"prettier.d.ts","sourceRoot":"","sources":["../../src/tasks/prettier.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAA;AAG5F,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAG5C,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,IAAI,CAAC,OAAO,cAAc,CAAC;IAC/D,MAAM,CAAC,WAAW,SAAK;IAEvB,MAAM,CAAC,cAAc,EAAE,eAAe,CASrC;IAEK,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAiB3C"}
|
package/lib/tasks/prettier.js
CHANGED
|
@@ -7,11 +7,14 @@ const fast_glob_1 = (0, tslib_1.__importDefault)(require("fast-glob"));
|
|
|
7
7
|
const task_1 = require("@dotcom-tool-kit/task");
|
|
8
8
|
const error_1 = require("@dotcom-tool-kit/error");
|
|
9
9
|
class Prettier extends task_1.Task {
|
|
10
|
-
async run() {
|
|
10
|
+
async run(files) {
|
|
11
11
|
try {
|
|
12
|
-
const filepaths = await (0, fast_glob_1.default)(this.options.files);
|
|
12
|
+
const filepaths = await (0, fast_glob_1.default)(files !== null && files !== void 0 ? files : this.options.files);
|
|
13
13
|
for (const filepath of filepaths) {
|
|
14
|
-
await
|
|
14
|
+
const { ignored } = await prettier_1.default.getFileInfo(filepath);
|
|
15
|
+
if (!ignored) {
|
|
16
|
+
await formatFile(filepath, this.options);
|
|
17
|
+
}
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
catch (err) {
|
|
@@ -26,7 +29,7 @@ class Prettier extends task_1.Task {
|
|
|
26
29
|
exports.default = Prettier;
|
|
27
30
|
Prettier.description = '';
|
|
28
31
|
Prettier.defaultOptions = {
|
|
29
|
-
files: ['
|
|
32
|
+
files: ['**/*.js'],
|
|
30
33
|
configOptions: {
|
|
31
34
|
singleQuote: true,
|
|
32
35
|
useTabs: true,
|
|
@@ -38,21 +41,16 @@ Prettier.defaultOptions = {
|
|
|
38
41
|
const formatFile = async (filepath, options) => {
|
|
39
42
|
const fileContent = await fs_1.promises.readFile(filepath, 'utf8');
|
|
40
43
|
let prettierConfig;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
throw err;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (!prettierConfig) {
|
|
51
|
-
console.log(`prettier could not find the specified configFile (${options.configFile}), using configOptions instead`);
|
|
52
|
-
prettierConfig = options.configOptions;
|
|
44
|
+
try {
|
|
45
|
+
prettierConfig = await prettier_1.default.resolveConfig(filepath, { config: options.configFile });
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
if (err.code !== 'ENOENT') {
|
|
49
|
+
throw err;
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
|
-
|
|
52
|
+
if (!prettierConfig && options.configOptions) {
|
|
53
|
+
console.log(`prettier could not find the specified configFile (${options.configFile}), using configOptions instead`);
|
|
56
54
|
prettierConfig = options.configOptions;
|
|
57
55
|
}
|
|
58
56
|
await fs_1.promises.writeFile(filepath, prettier_1.default.format(fileContent, { ...prettierConfig, filepath }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcom-tool-kit/prettier",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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/error": "^1.
|
|
14
|
-
"@dotcom-tool-kit/task": "^1.
|
|
13
|
+
"@dotcom-tool-kit/error": "^1.2.0",
|
|
14
|
+
"@dotcom-tool-kit/task": "^1.2.0",
|
|
15
15
|
"fast-glob": "^3.2.7",
|
|
16
|
-
"prettier": "^2.
|
|
16
|
+
"prettier": "^2.2.1"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|