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
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defaultSemverRangePrefix: ""
enableColors: true
enableConstraintsChecks: true
enableInlineBuilds: true
enableTelemetry: false
Expand Down
2 changes: 1 addition & 1 deletion workspaces/adventure-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@code-chronicles/eslint-config": "workspace:*",
"@code-chronicles/util": "workspace:*",
"@jest/globals": "29.7.0",
"@types/node": "22.7.5",
"@types/node": "22.7.6",
"@types/react": "18.3.11",
"@types/react-dom": "18.3.1",
"@types/react-syntax-highlighter": "15.5.13",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/download-leetcode-submissions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@code-chronicles/webpack-make-output-executable-plugin": "workspace:*",
"@types/node": "22.7.5",
"@types/node": "22.7.6",
"cross-env": "7.0.3",
"eslint": "9.12.0",
"fork-ts-checker-webpack-plugin": "9.0.2",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/fetch-leetcode-problem-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@code-chronicles/webpack-make-output-executable-plugin": "workspace:*",
"@types/node": "22.7.5",
"@types/node": "22.7.6",
"cross-env": "7.0.3",
"eslint": "9.12.0",
"fork-ts-checker-webpack-plugin": "9.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@code-chronicles/webpack-make-output-executable-plugin": "workspace:*",
"@types/node": "22.7.5",
"@types/node": "22.7.6",
"cross-env": "7.0.3",
"eslint": "9.12.0",
"fork-ts-checker-webpack-plugin": "9.0.2",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/generate-health-report/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@types/node": "22.7.5",
"@types/node": "22.7.6",
"eslint": "9.12.0",
"prettier": "3.3.3",
"typescript": "5.6.3"
Expand Down
2 changes: 1 addition & 1 deletion workspaces/javascript-leetcode-month/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@code-chronicles/eslint-config": "workspace:*",
"@code-chronicles/util": "workspace:*",
"@types/mdast": "4.0.4",
"@types/node": "22.7.5",
"@types/node": "22.7.6",
"eslint": "9.12.0",
"mdast": "3.0.0",
"prettier": "3.3.3",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/leetcode-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@graphql-codegen/add": "5.0.3",
"@graphql-codegen/cli": "5.0.3",
"@graphql-codegen/near-operation-file-preset": "3.0.0",
"@types/node": "22.7.5",
"@types/node": "22.7.6",
"cross-env": "7.0.3",
"dedent": "1.5.3",
"eslint": "9.12.0",
Expand Down
1 change: 1 addition & 0 deletions workspaces/leetcode-prettier-extension/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
32 changes: 32 additions & 0 deletions workspaces/leetcode-prettier-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# @code-chronicles/leetcode-prettier-extension

Chrome extension to replace LeetCode's code formatter with Prettier.

To use:

1. **Build the extension:**

```sh
# It's easiest to do this from the package's directory:
cd workspaces/leetcode-prettier-extension

# Install dependencies, if you haven't already:
yarn

# Build the extension:
yarn build
```

2. **Load the extension into Chrome.** The built extension will be in a directory named `dist`. You will have to load it as an "unpacked extension", using Developer mode. See [the official tutorial](https://developer.chrome.com/docs/extensions/get-started/tutorial/hello-world#load-unpacked).

## Development

Like the rest of the [Code Chronicles Leetcode ecosystem](../../), this package is structured as a Node module, using [Yarn](https://yarnpkg.com/) as the package manager.

You can install dependencies by running `yarn`, either in this package's directory, or in the repository root. The usual `yarn format`, `yarn lint`, and `yarn typecheck` scripts are available to aid in development and occasionally to annoy. Read more in the repository's general [development guide](../../DEVELOPMENT.md).

This package supports an additional `package.json` script:

### `yarn build`

Builds (an unpacked version of) the extension, in a `dist` directory within the package's workspace.
3 changes: 3 additions & 0 deletions workspaces/leetcode-prettier-extension/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from "@code-chronicles/eslint-config";

export default [...config, { ignores: ["dist/"] }];
41 changes: 41 additions & 0 deletions workspaces/leetcode-prettier-extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@code-chronicles/leetcode-prettier-extension",
"description": "TODO: add a nice description",
"version": "0.0.1",
"license": "MIT",
"private": false,
"repository": {
"type": "git",
"url": "https://github.com/code-chronicles-code/leetcode-curriculum.git",
"directory": "workspaces/leetcode-prettier-extension"
},
"author": {
"name": "Miorel-Lucian Palii",
"url": "https://github.com/miorel"
},
"type": "module",
"exports": "./src/extension/main.ts",
"scripts": {
"build": "tsx src/scripts/writeManifest.ts && cross-env NODE_OPTIONS=\"--import tsx\" webpack",
"format": "prettier --color --write .",
"lint": "eslint --color --max-warnings=0 .",
"typecheck": "tsc --pretty --project ."
},
"dependencies": {
"prettier": "3.3.3"
},
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@code-chronicles/util": "workspace:*",
"@types/node": "22.7.6",
"cross-env": "7.0.3",
"eslint": "9.12.0",
"fork-ts-checker-webpack-plugin": "9.0.2",
"ts-loader": "9.5.1",
"tsx": "4.19.1",
"type-fest": "4.26.1",
"typescript": "5.6.3",
"webpack": "5.95.0",
"webpack-cli": "5.1.4"
}
}
36 changes: 36 additions & 0 deletions workspaces/leetcode-prettier-extension/src/extension/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { format } from "prettier/standalone";
import estreePlugin from "prettier/plugins/estree";
import tsPlugin from "prettier/plugins/typescript";

function main(): void {
// TODO: improve types
let monaco: any = undefined;

Object.defineProperty(globalThis, "monaco", {
get() {
return monaco;
},

set(newMonaco) {
monaco = newMonaco;
monaco.editor.onDidCreateEditor((ed: any) => {
const { getAction } = ed;
ed.getAction = function (this: unknown) {
const action = getAction.apply(this, arguments);
action.run = function () {
format(ed.getValue(), {
parser: "typescript",
plugins: [estreePlugin, tsPlugin],
}).then((text) =>
// TODO: switch to https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.ITextModel.html#pushEditOperations.pushEditOperations-1 in the future
ed.setValue(text),
);
};
return action;
};
});
},
});
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const DIST_DIRECTORY = "dist";

export const SCRIPT_FILENAME = "main.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { JsonObject } from "type-fest";

import { SCRIPT_FILENAME } from "./constants.ts";
import packageJson from "../../package.json" with { type: "json" };

export function getManifest(): JsonObject {
return {
name: "LeetCode Prettier",
description: packageJson.description,
version: packageJson.version,

// eslint-disable-next-line camelcase
manifest_version: 3,
// eslint-disable-next-line camelcase
content_scripts: [
{
matches: ["https://*.leetcode.com/*"],
js: [SCRIPT_FILENAME],
// eslint-disable-next-line camelcase
run_at: "document_start",
world: "MAIN",
},
],
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { mkdir, writeFile } from "node:fs/promises";
import path from "node:path";

import { jsonStringifyPrettyInDev } from "@code-chronicles/util/jsonStringifyPrettyInDev";

import { DIST_DIRECTORY } from "./constants.ts";
import { getManifest } from "./getManifest.ts";

async function main(): Promise<void> {
await mkdir(DIST_DIRECTORY, { recursive: true });

const manifest = getManifest();

await writeFile(
path.join(DIST_DIRECTORY, "manifest.json"),
jsonStringifyPrettyInDev(manifest),
{ encoding: "utf8" },
);
}

main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
3 changes: 3 additions & 0 deletions workspaces/leetcode-prettier-extension/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig-base.json"
}
40 changes: 40 additions & 0 deletions workspaces/leetcode-prettier-extension/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import path from "node:path";

import type { Configuration } from "webpack";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";

import packageJson from "./package.json" with { type: "json" };

const config: Configuration = {
target: "web",
entry: path.resolve(__dirname, packageJson.exports),
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist"),
},

module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: "ts-loader",
options: {
transpileOnly: true,
},
},
],
exclude: /\bnode_modules\b/,
},
],
},

resolve: {
conditionNames: ["import"],
},

plugins: [new ForkTsCheckerWebpackPlugin()],
};

export default config;
2 changes: 1 addition & 1 deletion workspaces/leetcode-zen-mode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@types/node": "22.7.5",
"@types/node": "22.7.6",
"cross-env": "7.0.3",
"eslint": "9.12.0",
"fork-ts-checker-webpack-plugin": "9.0.2",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/post-leetcode-potd-to-discord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@code-chronicles/eslint-config": "workspace:*",
"@code-chronicles/webpack-make-output-executable-plugin": "workspace:*",
"@types/invariant": "2.2.37",
"@types/node": "22.7.5",
"@types/node": "22.7.6",
"cross-env": "7.0.3",
"eslint": "9.12.0",
"fork-ts-checker-webpack-plugin": "9.0.2",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/repository-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@types/node": "22.7.5",
"@types/node": "22.7.6",
"eslint": "9.12.0",
"prettier": "3.3.3",
"type-fest": "4.26.1",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@code-chronicles/eslint-config": "workspace:*",
"@code-chronicles/util": "workspace:*",
"@jest/globals": "29.7.0",
"@types/node": "22.7.5",
"@types/node": "22.7.6",
"eslint": "9.12.0",
"jest": "29.7.0",
"prettier": "3.3.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@types/node": "22.7.5",
"@types/node": "22.7.6",
"eslint": "9.12.0",
"prettier": "3.3.3",
"typescript": "5.6.3"
Expand Down
Loading
Loading