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
3 changes: 2 additions & 1 deletion workspaces/download-leetcode-submissions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "module",
"exports": "./src/main.ts",
"scripts": {
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack && chmod +x dist/download-leetcode-submissions.cjs",
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack",
"format": "prettier --color --write .",
"lint": "eslint --color --max-warnings=0 .",
"start": "tsx src/main.ts",
Expand All @@ -29,6 +29,7 @@
},
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@code-chronicles/webpack-make-output-executable-plugin": "workspace:*",
"@types/node": "22.7.4",
"cross-env": "7.0.3",
"eslint": "9.11.1",
Expand Down
4 changes: 4 additions & 0 deletions workspaces/download-leetcode-submissions/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from "webpack";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";

import { WebpackMakeOutputExecutablePlugin } from "@code-chronicles/webpack-make-output-executable-plugin";

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

Expand Down Expand Up @@ -60,6 +62,8 @@ const config: Configuration = {
entryOnly: true,
}),

new WebpackMakeOutputExecutablePlugin(),

new ForkTsCheckerWebpackPlugin(),
],
};
Expand Down
1 change: 1 addition & 0 deletions workspaces/fetch-leetcode-problem-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@code-chronicles/webpack-make-output-executable-plugin": "workspace:*",
"@types/node": "22.7.4",
"cross-env": "7.0.3",
"eslint": "9.11.1",
Expand Down
33 changes: 2 additions & 31 deletions workspaces/fetch-leetcode-problem-list/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,20 @@
import { chmod } from "node:fs/promises";
import { builtinModules } from "node:module";
import path from "node:path";

import {
BannerPlugin,
type Compiler,
type Configuration,
type ExternalItemFunctionData,
} from "webpack";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";

import { WebpackMakeOutputExecutablePlugin } from "@code-chronicles/webpack-make-output-executable-plugin";

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

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

class WebpackMakeOutputExecutablePlugin {
// eslint-disable-next-line class-methods-use-this -- This is the interface expected by webpack.
apply(compiler: Compiler): void {
compiler.hooks.afterEmit.tapPromise(
"WebpackMakeOutputExecutablePlugin",
async (compilation) => {
const promises: Promise<void>[] = [];

for (const chunk of compilation.chunks) {
if (!chunk.canBeInitial()) {
continue;
}

for (const file of chunk.files) {
promises.push(
chmod(
path.join(compilation.outputOptions.path ?? ".", file),
0o755,
),
);
}
}

await Promise.all(promises);
},
);
}
}

const config: Configuration = {
target: "node",
entry: path.resolve(__dirname, packageJson.exports),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "module",
"exports": "./src/main.ts",
"scripts": {
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack && chmod +x dist/fetch-recent-accepted-leetcode-submissions.cjs",
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack",
"format": "prettier --color --write .",
"lint": "eslint --color --max-warnings=0 .",
"start": "tsx src/main.ts",
Expand All @@ -27,6 +27,7 @@
},
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@code-chronicles/webpack-make-output-executable-plugin": "workspace:*",
"@types/node": "22.7.4",
"cross-env": "7.0.3",
"eslint": "9.11.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from "webpack";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";

import { WebpackMakeOutputExecutablePlugin } from "@code-chronicles/webpack-make-output-executable-plugin";

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

Expand Down Expand Up @@ -60,6 +62,8 @@ const config: Configuration = {
entryOnly: true,
}),

new WebpackMakeOutputExecutablePlugin(),

new ForkTsCheckerWebpackPlugin(),
],
};
Expand Down
3 changes: 2 additions & 1 deletion workspaces/post-leetcode-potd-to-discord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "module",
"exports": "./src/main.ts",
"scripts": {
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack && chmod +x dist/post-leetcode-potd-to-discord.cjs",
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack",
"format": "prettier --color --write .",
"lint": "eslint --color --max-warnings=0 .",
"start": "tsx src/main.ts",
Expand All @@ -33,6 +33,7 @@
},
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@code-chronicles/webpack-make-output-executable-plugin": "workspace:*",
"@types/invariant": "2.2.37",
"@types/node": "22.7.4",
"cross-env": "7.0.3",
Expand Down
4 changes: 4 additions & 0 deletions workspaces/post-leetcode-potd-to-discord/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from "webpack";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";

import { WebpackMakeOutputExecutablePlugin } from "@code-chronicles/webpack-make-output-executable-plugin";

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

Expand Down Expand Up @@ -66,6 +68,8 @@ const config: Configuration = {
entryOnly: true,
}),

new WebpackMakeOutputExecutablePlugin(),

new ForkTsCheckerWebpackPlugin(),
],
};
Expand Down
11 changes: 11 additions & 0 deletions workspaces/webpack-make-output-executable-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @code-chronicles/webpack-make-output-executable-plugin

A [webpack](https://webpack.js.org/) plugin that `chmod`s entry points to be executable files.

## 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.

See also the repository's general [development guide](../../DEVELOPMENT.md).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@code-chronicles/eslint-config";
31 changes: 31 additions & 0 deletions workspaces/webpack-make-output-executable-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@code-chronicles/webpack-make-output-executable-plugin",
"version": "0.0.1",
"license": "MIT",
"private": false,
"repository": {
"type": "git",
"url": "https://github.com/code-chronicles-code/leetcode-curriculum.git",
"directory": "workspaces/webpack-make-output-executable-plugin"
},
"author": {
"name": "Miorel-Lucian Palii",
"url": "https://github.com/miorel"
},
"type": "module",
"exports": {
".": "./src/WebpackMakeOutputExecutablePlugin.ts"
},
"scripts": {
"format": "prettier --color --write .",
"lint": "eslint --color --max-warnings=0 .",
"typecheck": "tsc --pretty --project ."
},
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@types/node": "22.7.4",
"eslint": "9.11.1",
"prettier": "3.3.3",
"typescript": "5.6.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { chmod } from "node:fs/promises";
import path from "node:path";

import type { Compiler } from "webpack";

export class WebpackMakeOutputExecutablePlugin {
// eslint-disable-next-line class-methods-use-this -- This is the interface expected by webpack.
apply(compiler: Compiler): void {
compiler.hooks.afterEmit.tapPromise(
"WebpackMakeOutputExecutablePlugin",
async (compilation) => {
const promises: Promise<void>[] = [];

for (const chunk of compilation.chunks) {
if (!chunk.canBeInitial()) {
continue;
}

for (const file of chunk.files) {
promises.push(
chmod(
path.join(compilation.outputOptions.path ?? ".", file),
0o755,
),
);
}
}

await Promise.all(promises);
},
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig-base.json"
}
12 changes: 6 additions & 6 deletions yarn.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { defineConfig } = require("@yarnpkg/types");

const NAME_PREFIX = "@code-chronicles/";
const CWD_PREFIX = "workspaces/";

module.exports = defineConfig({
async constraints({ Yarn }) {
Expand All @@ -14,13 +15,12 @@ module.exports = defineConfig({
for (const workspace of Yarn.workspaces()) {
if (workspace.cwd === ".") {
workspace.unset("name");
} else if (!workspace.cwd.startsWith(CWD_PREFIX)) {
workspace.error(
`Workspace directory didn't start with the prefix ${JSON.stringify(CWD_PREFIX)}`,
);
} else {
const { name } = workspace.manifest;
if (typeof name !== "string" || !name.startsWith(NAME_PREFIX)) {
workspace.error(
`Repository name didn't start with the prefix ${JSON.stringify(NAME_PREFIX)}`,
);
}
workspace.set(NAME_PREFIX + workspace.cwd.slice(CWD_PREFIX.length));
}
}

Expand Down
16 changes: 16 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading