Skip to content

Commit

Permalink
* Simplified buildConfig function a bit. (realized the fancy type-hel…
Browse files Browse the repository at this point in the history
…per is not really needed, since very few deep-path overrides are needed nowadays, making the ctrl+click benefits marginal)
  • Loading branch information
Venryx committed Aug 20, 2024
1 parent bf61f95 commit 9ae6adc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Packages/client/rspack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check

import {buildConfig} from "web-vcore/Scripts/RsPack/rspack.js";
import {buildConfig, NN} from "web-vcore/Scripts/RsPack/rspack.js";
import path from "path";
import {fileURLToPath} from "node:url";

Expand All @@ -14,7 +14,7 @@ const config = buildConfig({
entryFile: path.resolve(__dirname, "./Source/Main.ts"),
dotEnvFile: path.resolve(__dirname, "../../.env"),
});
config.resolve["alias"] = {
NN(config.resolve).alias = {
"wavesurfer.js": path.resolve(__dirname, "../../node_modules/wavesurfer.js/dist/wavesurfer.js"),
};
export default config;
10 changes: 0 additions & 10 deletions Packages/web-vcore/Scripts/RsPack/TypeHelpers.ts

This file was deleted.

40 changes: 9 additions & 31 deletions Packages/web-vcore/Scripts/RsPack/rspack.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const require = createRequire(import.meta.url);

/**
* @param {BuildConfigOptions} options
* @returns {RspackConfig}
**/
export const buildConfig = options=>{
/** @type {Partial<BuildConfigOptions>} */
Expand Down Expand Up @@ -49,11 +50,7 @@ export const buildConfig = options=>{
const DEV = ENV == "dev";
const TEST = false; //ENV == "test";

// Uncomment the jsdoc comment below ONLY when working on the config in this file. (for type-checking)
// The rest of the time, keep it commented ("// " before it), so that upstream config allows ctrl+click jumping to fields in this base config.
// /** @type {RspackConfig} */

const result = /** @type {const} */ ({
return {
mode: PROD && !QUICK ? "production" : "development",
target: "web",
devtool: PROD ? "source-map" : "cheap-source-map",
Expand Down Expand Up @@ -258,16 +255,7 @@ export const buildConfig = options=>{
})) ?? [],
}),
],
});

// we use the type-cast and type-assertion below to ensure that the structure above is still a valid RspackConfig structure
// (see comment in TypeHelpers.ts for more info)
const result_deepWriteable = toDeepWriteable(result);
/** @type {RspackConfig} */
// Note: If this type-assertion fails, uncomment the jsdoc comment just above the "const result = ..." line, for localized type-checking.
const result_typeCheck = result_deepWriteable;

return result_deepWriteable;
};
};

// helper functions
Expand All @@ -278,29 +266,19 @@ function S(obj) {
return JSON.stringify(obj);
}

/** @type {<T>(input: T)=>DeepWriteable<T>} */
const toDeepWriteable = obj=>{
return /** @type {any} */ (obj);
};

/*#*
* NN stands for "non-null".
* This is a helper function to enable easier modification of deep-paths, which rspack configs may leave null, but we know is non-null.
/**
* NN stands for "non-null". This is a helper function to enable easier modification of deep-paths that are
* nullable in the RspackConfig type, but which we know are non-null because they're always set in the base rspack.js.
* @type {<T>(obj: T)=>NonNullable<T>}
*#/
/*export function NN(obj) {
*/
export function NN(obj) {
if (obj == null) throw new Error(`Project rspack.config.js tried to modify a field that is null in base config.`);
return obj;
}*/
}

// type helpers
// ==========

/**
@typedef {import('@rspack/core').Configuration} RspackConfig
*/

/**
@template T
@typedef {import('./TypeHelpers.ts').DeepWriteable<T>} DeepWriteable<T>
*/

0 comments on commit 9ae6adc

Please sign in to comment.