Use dprint package for dtsBundler formatting rather than dprint CLI (#58625)
This commit is contained in:
Родитель
e02af8e36d
Коммит
f2aebff7a3
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
// If updating this, also update the config in dtsBundler.mjs.
|
||||
"indentWidth": 4,
|
||||
"lineWidth": 1000,
|
||||
"newLineKind": "auto",
|
||||
|
@ -56,6 +57,7 @@
|
|||
"**/_namespaces/**"
|
||||
],
|
||||
// Note: if adding new languages, make sure settings.template.json is updated too.
|
||||
// Also, if updating typescript, update the one in package.json.
|
||||
"plugins": [
|
||||
"https://plugins.dprint.dev/typescript-0.90.5.wasm",
|
||||
"https://plugins.dprint.dev/json-0.19.2.wasm",
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@dprint/formatter": "^0.3.0",
|
||||
"@dprint/typescript": "0.90.5",
|
||||
"@esfx/canceltoken": "^1.0.0",
|
||||
"@octokit/rest": "^20.1.1",
|
||||
"@types/chai": "^4.3.16",
|
||||
|
@ -88,6 +90,12 @@
|
|||
"darwin"
|
||||
]
|
||||
},
|
||||
"node_modules/@dprint/formatter": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@dprint/formatter/-/formatter-0.3.0.tgz",
|
||||
"integrity": "sha512-N9fxCxbaBOrDkteSOzaCqwWjso5iAe+WJPsHC021JfHNj2ThInPNEF13ORDKta3llq5D1TlclODCvOvipH7bWQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@dprint/linux-arm64-glibc": {
|
||||
"version": "0.45.1",
|
||||
"resolved": "https://registry.npmjs.org/@dprint/linux-arm64-glibc/-/linux-arm64-glibc-0.45.1.tgz",
|
||||
|
@ -140,6 +148,12 @@
|
|||
"linux"
|
||||
]
|
||||
},
|
||||
"node_modules/@dprint/typescript": {
|
||||
"version": "0.90.5",
|
||||
"resolved": "https://registry.npmjs.org/@dprint/typescript/-/typescript-0.90.5.tgz",
|
||||
"integrity": "sha512-/1aP6saonFvJyQN3l2is6eTOec3GnLGyW+opid/eDm8pnlhwzYl8A9p36pI6WO5jLl/a9Ghod+LWpvSOuXFGUw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@dprint/win32-x64": {
|
||||
"version": "0.45.1",
|
||||
"resolved": "https://registry.npmjs.org/@dprint/win32-x64/-/win32-x64-0.45.1.tgz",
|
||||
|
@ -4445,6 +4459,12 @@
|
|||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@dprint/formatter": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@dprint/formatter/-/formatter-0.3.0.tgz",
|
||||
"integrity": "sha512-N9fxCxbaBOrDkteSOzaCqwWjso5iAe+WJPsHC021JfHNj2ThInPNEF13ORDKta3llq5D1TlclODCvOvipH7bWQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@dprint/linux-arm64-glibc": {
|
||||
"version": "0.45.1",
|
||||
"resolved": "https://registry.npmjs.org/@dprint/linux-arm64-glibc/-/linux-arm64-glibc-0.45.1.tgz",
|
||||
|
@ -4473,6 +4493,12 @@
|
|||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@dprint/typescript": {
|
||||
"version": "0.90.5",
|
||||
"resolved": "https://registry.npmjs.org/@dprint/typescript/-/typescript-0.90.5.tgz",
|
||||
"integrity": "sha512-/1aP6saonFvJyQN3l2is6eTOec3GnLGyW+opid/eDm8pnlhwzYl8A9p36pI6WO5jLl/a9Ghod+LWpvSOuXFGUw==",
|
||||
"dev": true
|
||||
},
|
||||
"@dprint/win32-x64": {
|
||||
"version": "0.45.1",
|
||||
"resolved": "https://registry.npmjs.org/@dprint/win32-x64/-/win32-x64-0.45.1.tgz",
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
"!**/.gitattributes"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@dprint/formatter": "^0.3.0",
|
||||
"@dprint/typescript": "0.90.5",
|
||||
"@esfx/canceltoken": "^1.0.0",
|
||||
"@octokit/rest": "^20.1.1",
|
||||
"@types/chai": "^4.3.16",
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
* bundle as namespaces again, even though the project is modules.
|
||||
*/
|
||||
|
||||
import * as dprintFormatter from "@dprint/formatter";
|
||||
import * as dprintTypeScript from "@dprint/typescript";
|
||||
import assert, { fail } from "assert";
|
||||
import cp from "child_process";
|
||||
import fs from "fs";
|
||||
import minimist from "minimist";
|
||||
import path from "path";
|
||||
|
@ -475,23 +476,23 @@ if (publicContents.includes("@internal")) {
|
|||
console.error("Output includes untrimmed @internal nodes!");
|
||||
}
|
||||
|
||||
const dprintPath = path.resolve(__dirname, "..", "node_modules", "dprint", "bin.js");
|
||||
const buffer = fs.readFileSync(dprintTypeScript.getPath());
|
||||
const formatter = dprintFormatter.createFromBuffer(buffer);
|
||||
formatter.setConfig({
|
||||
indentWidth: 4,
|
||||
lineWidth: 1000,
|
||||
newLineKind: "auto",
|
||||
useTabs: false,
|
||||
}, {
|
||||
quoteStyle: "preferDouble",
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {string} contents
|
||||
* @returns {string}
|
||||
*/
|
||||
function dprint(contents) {
|
||||
const result = cp.execFileSync(
|
||||
process.execPath,
|
||||
[dprintPath, "fmt", "--stdin", "ts"],
|
||||
{
|
||||
stdio: ["pipe", "pipe", "inherit"],
|
||||
encoding: "utf-8",
|
||||
input: contents,
|
||||
maxBuffer: 100 * 1024 * 1024, // 100 MB "ought to be enough for anyone"; https://github.com/nodejs/node/issues/9829
|
||||
},
|
||||
);
|
||||
const result = formatter.formatText("dummy.d.ts", contents);
|
||||
return result.replace(/\r\n/g, "\n");
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче