Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,187 changes: 2,187 additions & 0 deletions nodejs/default/nodejs.bzl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"long": "~4.0.0",
"node-fetch": "^2.0.0",
"npm-registry-fetch": "~14.0.2",
"prettier": "^3",
"prettier": "^3.4.2",
"prettier-plugin-organize-imports": "^3",
"protobufjs": "~6.11.2",
"reflect-metadata": "0.1.13",
Expand Down
8 changes: 3 additions & 5 deletions prettier/format/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { workerMain } from "@better-rules-javascript/bazel-worker";
import { ArgumentParser } from "argparse";
import { dirname } from "node:path";
import { pathToFileURL } from "node:url";
import { Options } from "prettier";
import { Options, resolveConfig } from "prettier";
import { load, resolve } from "./import";
import { PrettierWorker } from "./worker";

interface Args {
config?: string;
Expand All @@ -14,9 +15,6 @@ workerMain(async (a) => {
parser.add_argument("--config", { help: "Configuration path" });
const args: Args = parser.parse_args(a);

const { resolveConfig } = await import("prettier");
const { PrettierWorker } = await import("./worker");

const options: Options | undefined =
args.config === undefined
? undefined
Expand All @@ -37,7 +35,7 @@ workerMain(async (a) => {
}),
);
}
const worker = new PrettierWorker(options);
const worker = new PrettierWorker(args.config, options?.plugins);

return async (a) => {
try {
Expand Down
19 changes: 16 additions & 3 deletions prettier/format/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import { ArgumentParser } from "argparse";
import { readFile, writeFile } from "node:fs/promises";
import { Options, format } from "prettier";
import { resolve } from "node:path";
import { Options, format, resolveConfig } from "prettier";

export class PrettierWorker {
constructor(private readonly options: Options | undefined) {}
constructor(
readonly configPath: string | undefined,
readonly plugins: any[] | undefined,
) {}

async run(a: string[]) {
const parser = new ArgumentParser();
parser.add_argument("input");
parser.add_argument("output");
const args = parser.parse_args(a);

const resolvedConfig = await resolveConfig(resolve(args.input), {
config: this.configPath,
});
const options: Options = {
...resolvedConfig,
plugins: this.plugins,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to call resolveConfig per file so Prettier will apply overrides


const input = await readFile(args.input, "utf8");
const output = await format(input, {
...this.options,
...options,
filepath: args.input,
});
await writeFile(args.output, output, "utf8");
Expand Down
8 changes: 4 additions & 4 deletions rules/npm_data.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11153,14 +11153,14 @@ PACKAGES = {
"name": "prelude-ls",
"url": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
},
"prettier@3.1.1": {
"prettier@3.4.2": {
"deps": [
],
"extra_deps": {
},
"integrity": "sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==",
"integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==",
"name": "prettier",
"url": "https://registry.npmjs.org/prettier/-/prettier-3.1.1.tgz",
"url": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz",
},
"[email protected]": {
"deps": [
Expand Down Expand Up @@ -14147,7 +14147,7 @@ ROOTS = [
"name": "npm",
},
{
"id": "prettier@3.1.1",
"id": "prettier@3.4.2",
"name": "prettier",
},
{
Expand Down
2 changes: 1 addition & 1 deletion rules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"long": "~4.0.0",
"node-fetch": "^2.0.0",
"npm": "^9",
"prettier": "^3",
"prettier": "^3.4.2",
"protobufjs": "~7.1.0",
"rollup": "~3.21.0",
"rxjs": "~7.5.0",
Expand Down
10 changes: 5 additions & 5 deletions rules/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5790,12 +5790,12 @@ __metadata:
languageName: node
linkType: hard

"prettier@npm:^3":
version: 3.1.1
resolution: "prettier@npm:3.1.1"
"prettier@npm:^3.4.2":
version: 3.4.2
resolution: "prettier@npm:3.4.2"
bin:
prettier: bin/prettier.cjs
checksum: e386855e3a1af86a748e16953f168be555ce66d6233f4ba54eb6449b88eb0c6b2ca79441b11eae6d28a7f9a5c96440ce50864b9d5f6356d331d39d6bb66c648e
checksum: 061c84513db62d3944c8dc8df36584dad82883ce4e49efcdbedd8703dce5b173c33fd9d2a4e1725d642a3b713c932b55418342eaa347479bc4a9cca114a04cd0
languageName: node
linkType: hard

Expand Down Expand Up @@ -6282,7 +6282,7 @@ __metadata:
long: ~4.0.0
node-fetch: ^2.0.0
npm: ^9
prettier: ^3
prettier: ^3.4.2
protobufjs: ~7.1.0
rollup: ~3.21.0
rxjs: ~7.5.0
Expand Down
6 changes: 3 additions & 3 deletions util/starlark/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class StarlarkFile {
constructor(readonly statements: StarlarkStatement[]) {}
}

function printArray(value: StarlarkArray, indent: string | undefined): string {
function printArray(value: StarlarkArray, indent?: string | undefined): string {
let output = "";
output += "[";
output += indent === undefined ? " " : "\n";
Expand All @@ -56,7 +56,7 @@ function printArray(value: StarlarkArray, indent: string | undefined): string {
return output;
}

function printDict(value: StarlarkDict, indent: string | undefined): string {
function printDict(value: StarlarkDict, indent?: string | undefined): string {
let output = "";
output += "{";
output += indent === undefined ? " " : "\n";
Expand Down Expand Up @@ -85,7 +85,7 @@ function printString(value: StarlarkString): string {
return JSON.stringify(value.value);
}

function printValue(value: StarlarkValue, indent: string | undefined): string {
function printValue(value: StarlarkValue, indent?: string | undefined): string {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes squiggle due to line 67 printValue(k) with one arg

if (value instanceof StarlarkArray) {
return printArray(value, indent);
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7846,9 +7846,9 @@ __metadata:
languageName: node
linkType: hard

"prettier@npm:^3":
version: 3.1.1
resolution: "prettier@npm:3.1.1"
"prettier@npm:^3.4.2":
version: 3.4.2
resolution: "prettier@npm:3.4.2"
bin:
prettier: bin/prettier.cjs
checksum: e386855e3a1af86a748e16953f168be555ce66d6233f4ba54eb6449b88eb0c6b2ca79441b11eae6d28a7f9a5c96440ce50864b9d5f6356d331d39d6bb66c648e
Expand Down Expand Up @@ -8375,7 +8375,7 @@ __metadata:
long: ~4.0.0
node-fetch: ^2.0.0
npm-registry-fetch: ~14.0.2
prettier: ^3
prettier: ^3.4.2
prettier-plugin-organize-imports: ^3
protobufjs: ~6.11.2
reflect-metadata: 0.1.13
Expand Down
Loading