skuba 3.16.1 → 3.16.2
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.
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
import { Logger } from '../../utils/logging';
|
|
2
|
+
/**
|
|
3
|
+
* Infers a parser for the specified filepath.
|
|
4
|
+
*
|
|
5
|
+
* This is a cut-down version of Prettier's built-in function of the same name;
|
|
6
|
+
* ours operates purely on the `filepath` string and does not perform file I/O.
|
|
7
|
+
* Prettier's internal `getInterpreter` function can open a file to read the
|
|
8
|
+
* shebang, and its file descriptor usage can throw warnings on worker threads:
|
|
9
|
+
*
|
|
10
|
+
* ```console
|
|
11
|
+
* Warning: File descriptor 123 closed but not opened in unmanaged mode
|
|
12
|
+
* at Object.closeSync (node:fs:530:11)
|
|
13
|
+
* at Object.closeSync (node_modules/graceful-fs/graceful-fs.js:74:20)
|
|
14
|
+
* ...
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* References:
|
|
18
|
+
*
|
|
19
|
+
* - https://github.com/prettier/prettier/blob/2.4.1/src/main/options.js#L167
|
|
20
|
+
* - seek-oss/skuba#659
|
|
21
|
+
*/
|
|
22
|
+
export declare const inferParser: (filepath: string) => string | undefined;
|
|
2
23
|
interface Result {
|
|
3
24
|
count: number;
|
|
4
25
|
errored: Array<{
|
|
@@ -12,20 +12,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.runPrettier = void 0;
|
|
15
|
+
exports.runPrettier = exports.inferParser = void 0;
|
|
16
16
|
const path_1 = __importDefault(require("path"));
|
|
17
17
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
18
|
const prettier_1 = require("prettier");
|
|
19
19
|
const dir_1 = require("../../utils/dir");
|
|
20
20
|
const logging_1 = require("../../utils/logging");
|
|
21
21
|
const manifest_1 = require("../../utils/manifest");
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
let languages;
|
|
23
|
+
/**
|
|
24
|
+
* Infers a parser for the specified filepath.
|
|
25
|
+
*
|
|
26
|
+
* This is a cut-down version of Prettier's built-in function of the same name;
|
|
27
|
+
* ours operates purely on the `filepath` string and does not perform file I/O.
|
|
28
|
+
* Prettier's internal `getInterpreter` function can open a file to read the
|
|
29
|
+
* shebang, and its file descriptor usage can throw warnings on worker threads:
|
|
30
|
+
*
|
|
31
|
+
* ```console
|
|
32
|
+
* Warning: File descriptor 123 closed but not opened in unmanaged mode
|
|
33
|
+
* at Object.closeSync (node:fs:530:11)
|
|
34
|
+
* at Object.closeSync (node_modules/graceful-fs/graceful-fs.js:74:20)
|
|
35
|
+
* ...
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* References:
|
|
39
|
+
*
|
|
40
|
+
* - https://github.com/prettier/prettier/blob/2.4.1/src/main/options.js#L167
|
|
41
|
+
* - seek-oss/skuba#659
|
|
42
|
+
*/
|
|
43
|
+
const inferParser = (filepath) => {
|
|
44
|
+
const filename = path_1.default.basename(filepath).toLowerCase();
|
|
45
|
+
languages !== null && languages !== void 0 ? languages : (languages = (0, prettier_1.getSupportInfo)().languages.filter((language) => language.since));
|
|
46
|
+
const firstLanguage = languages.find((language) => {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
return ((_a = language.extensions) === null || _a === void 0 ? void 0 : _a.some((extension) => filename.endsWith(extension))) ||
|
|
49
|
+
((_b = language.filenames) === null || _b === void 0 ? void 0 : _b.some((name) => name.toLowerCase() === filename));
|
|
50
|
+
});
|
|
51
|
+
return firstLanguage === null || firstLanguage === void 0 ? void 0 : firstLanguage.parsers[0];
|
|
52
|
+
};
|
|
53
|
+
exports.inferParser = inferParser;
|
|
54
|
+
const formatOrLintFile = ({ data, filepath, options }, mode, result) => {
|
|
29
55
|
if (mode === 'lint') {
|
|
30
56
|
let ok;
|
|
31
57
|
try {
|
|
@@ -85,19 +111,24 @@ const runPrettier = (mode, logger) => __awaiter(void 0, void 0, void 0, function
|
|
|
85
111
|
};
|
|
86
112
|
logger.debug(mode === 'format' ? 'Formatting' : 'Linting', 'files...');
|
|
87
113
|
for (const filepath of filepaths) {
|
|
88
|
-
|
|
114
|
+
// Infer parser upfront so we can skip unsupported files.
|
|
115
|
+
const parser = (0, exports.inferParser)(filepath);
|
|
116
|
+
logger.debug(filepath);
|
|
117
|
+
logger.debug(' parser:', parser !== null && parser !== void 0 ? parser : '-');
|
|
118
|
+
if (!parser) {
|
|
119
|
+
result.unparsed.push(filepath);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const [config, data] = yield Promise.all([
|
|
89
123
|
(0, prettier_1.resolveConfig)(filepath),
|
|
90
124
|
fs_extra_1.default.promises.readFile(filepath, 'utf-8'),
|
|
91
|
-
// Infer parser upfront so we can know to ignore unsupported file types.
|
|
92
|
-
(0, prettier_1.getFileInfo)(filepath, { resolveConfig: false }),
|
|
93
125
|
]);
|
|
94
126
|
const file = {
|
|
95
127
|
data,
|
|
96
128
|
filepath,
|
|
97
129
|
options: Object.assign(Object.assign({}, config), { filepath }),
|
|
98
|
-
parser: fileInfo.inferredParser,
|
|
99
130
|
};
|
|
100
|
-
const formatted = formatOrLintFile(file,
|
|
131
|
+
const formatted = formatOrLintFile(file, mode, result);
|
|
101
132
|
if (typeof formatted === 'string') {
|
|
102
133
|
yield fs_extra_1.default.promises.writeFile(filepath, formatted);
|
|
103
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prettier.js","sourceRoot":"","sources":["../../../src/cli/adapter/prettier.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gDAAwB;AAExB,wDAA0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"prettier.js","sourceRoot":"","sources":["../../../src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AAE,CAAC;AACrD,CAAC,CAAA,CAAC;AA5FW,QAAA,WAAW,eA4FtB"}
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=12"
|
|
9
9
|
},
|
|
10
|
-
"version": "3.16.
|
|
10
|
+
"version": "3.16.2",
|
|
11
11
|
"main": "lib/index.js",
|
|
12
12
|
"typings": "lib/index.d.ts",
|
|
13
13
|
"files": [
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"@types/picomatch": "2.3.0",
|
|
53
53
|
"@types/supertest": "2.0.11",
|
|
54
54
|
"express": "4.17.1",
|
|
55
|
+
"jsonfile": "6.1.0",
|
|
55
56
|
"koa": "2.13.4",
|
|
56
57
|
"semver": "7.3.5",
|
|
57
58
|
"supertest": "6.1.6",
|