Skip to content

Commit

Permalink
chore: add rspack.config.ts to ESLint targets (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robot-Inventor authored Nov 7, 2024
1 parent 7b74df6 commit a1384b3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"watch": "cross-env NODE_OPTIONS=--experimental-transform-types NODE_ENV=development rspack build --watch",
"format": "prettier --write ./src/**/*",
"format:check": "prettier --check ./src/**/*",
"lint": "eslint ./src/**/*.ts",
"lint": "eslint ./src/**/*.ts ./rspack.config.ts",
"package": "tsx ./script/package.ts",
"version": "npm run build && git add ."
},
Expand Down
42 changes: 24 additions & 18 deletions rspack.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { exec } from "child_process";
import chokidar from "chokidar";
import { CopyRspackPlugin, type Compiler } from "@rspack/core";
import { type Compiler, CopyRspackPlugin } from "@rspack/core";
import { defineConfig } from "@rspack/cli";
import { exec } from "child_process";
import { watch } from "chokidar";

class RunCommandsPlugin {
private static copyManifest(callback?: () => void) {
private static copyManifest(callback?: () => void): void {
exec("npx tsx ./script/copyManifest.ts", (err, stdout) => {
if (err) {
console.error(`Error: ${err}`);
// eslint-disable-next-line no-console
console.error(`Error: ${err.message}`);
} else {
// eslint-disable-next-line no-console
console.log(stdout);
if (callback) {
callback();
Expand All @@ -17,34 +19,36 @@ class RunCommandsPlugin {
});
}

public apply(compiler: Compiler) {
let manifestWatcher;
let isWatchMode = false;
// eslint-disable-next-line class-methods-use-this
public apply(compiler: Compiler): void {
let manifestWatcher: ReturnType<typeof watch> | null = null;

compiler.hooks.watchRun.tapAsync("RunCommandsPlugin", (_params, callback) => {
isWatchMode = true;
if (!manifestWatcher) {
manifestWatcher = chokidar.watch("src/manifest/", {
if (manifestWatcher) {
callback();
} else {
manifestWatcher = watch("src/manifest/", {
ignored: (pathString, stats) => Boolean(stats && stats.isFile() && !pathString.endsWith(".json"))
});
manifestWatcher.on("change", (path) => {
console.log(`Manifest file changed: ${path}`);
manifestWatcher.on("change", (pathString: string) => {
// eslint-disable-next-line no-console
console.log(`Manifest file changed: ${pathString}`);
RunCommandsPlugin.copyManifest();
});

RunCommandsPlugin.copyManifest(callback);
} else {
callback();
}
});

compiler.hooks.afterEmit.tapAsync("RunCommandsPlugin", (_compilation, callback) => {
RunCommandsPlugin.copyManifest();

exec("npx tsx ./script/addUserScriptComment.ts", (err, stdout, stderr) => {
exec("npx tsx ./script/addUserScriptComment.ts", (err, stdout) => {
if (err) {
console.error(`Error: ${err}`);
// eslint-disable-next-line no-console
console.error(`Error: ${err.message}`);
} else {
// eslint-disable-next-line no-console
console.log(stdout);
}
callback();
Expand All @@ -54,6 +58,7 @@ class RunCommandsPlugin {
}

const isProduction = process.env.NODE_ENV === "production";
/* eslint-disable sort-keys */
const config = defineConfig({
mode: isProduction ? "production" : "development",
devtool: isProduction ? false : "source-map",
Expand All @@ -69,7 +74,7 @@ const config = defineConfig({
module: {
rules: [
{
test: /\.ts$/,
test: /\.ts$/u,
use: "ts-loader"
}
]
Expand Down Expand Up @@ -105,5 +110,6 @@ const config = defineConfig({
})
]
});
/* eslint-enable sort-keys */

export default config;
9 changes: 7 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"extends": "@robot-inventor/tsconfig-base/bundler.json",
"compilerOptions": {
"declaration": false
}
"declaration": false,
"rootDir": "."
},
"include": [
"./src/**/*.ts",
"./rspack.config.ts"
]
}

0 comments on commit a1384b3

Please sign in to comment.