Skip to content

Commit

Permalink
perf(core): prebundle enhanced-resolve to reduce dependencies (#6585)
Browse files Browse the repository at this point in the history
* perf(core): prebundle enhanced-resolve to reduce dependencies

* fix: api.md

* fix: lock file
  • Loading branch information
chenjiahan authored May 21, 2024
1 parent 5fbabcf commit 63110e3
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 7 deletions.
40 changes: 39 additions & 1 deletion packages/rspack/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import type { RawRelayConfig } from '@rspack/binding';
import { RawRuntimeChunkOptions } from '@rspack/binding';
import { RawSourceMapDevToolPluginOptions } from '@rspack/binding';
import { RawSwcJsMinimizerRspackPluginOptions } from '@rspack/binding';
import { ResolveRequest } from 'enhanced-resolve';
import ResolverFactory = require('./ResolverFactory');
import { RspackOptionsNormalized as RspackOptionsNormalized_2 } from '.';
import { Source } from 'webpack-sources';
Expand Down Expand Up @@ -646,6 +645,24 @@ const baseResolveOptions: z.ZodObject<{
roots?: string[] | undefined;
}>;

// @public (undocumented)
interface BaseResolveRequest {
// (undocumented)
descriptionFileData?: object;
// (undocumented)
descriptionFilePath?: string;
// (undocumented)
descriptionFileRoot?: string;
// (undocumented)
fullySpecified?: boolean;
// (undocumented)
ignoreSymlinks?: boolean;
// (undocumented)
path: string | false;
// (undocumented)
relativePath?: string;
}

// @public (undocumented)
const baseRuleSetCondition: z.ZodUnion<[z.ZodUnion<[z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodString]>, z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodBoolean>]>;

Expand Down Expand Up @@ -6974,6 +6991,24 @@ export interface OutputNormalized {
workerWasmLoading?: WasmLoading;
}

// @public (undocumented)
interface ParsedIdentifier {
// (undocumented)
directory: boolean;
// (undocumented)
file: boolean;
// (undocumented)
fragment: string;
// (undocumented)
internal: boolean;
// (undocumented)
module: boolean;
// (undocumented)
query: string;
// (undocumented)
request: string;
}

// @public (undocumented)
export type ParserOptionsByModuleType = z.infer<typeof parserOptionsByModuleType>;

Expand Down Expand Up @@ -7684,6 +7719,9 @@ export type ResolveOptions = z.infer<typeof baseResolveOptions> & {
byDependency?: Record<string, ResolveOptions>;
};

// @public (undocumented)
type ResolveRequest = BaseResolveRequest & Partial<ParsedIdentifier>;

// @public (undocumented)
export type ResolveTsconfig = z.infer<typeof resolveTsconfig>;

Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"copy-webpack-plugin": "5.1.2",
"cross-env": "^7.0.3",
"del": "^6.0.0",
"enhanced-resolve": "5.12.0",
"file-loader": "^6.2.0",
"glob": "^10.3.10",
"graceful-fs": "4.2.10",
Expand Down Expand Up @@ -86,7 +87,6 @@
"@module-federation/runtime-tools": "0.1.6",
"@rspack/binding": "workspace:*",
"caniuse-lite": "^1.0.30001616",
"enhanced-resolve": "5.12.0",
"tapable": "2.2.1",
"webpack-sources": "3.2.3"
},
Expand Down
28 changes: 27 additions & 1 deletion packages/rspack/prebundle.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// @ts-check
import { copyFileSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";

/** @type {import('prebundle').Config} */
export default {
Expand All @@ -11,7 +13,7 @@ export default {
{
name: "watchpack",
externals: {
"graceful-fs": "../graceful-fs"
"graceful-fs": "../graceful-fs/index.js"
}
},
{
Expand All @@ -21,6 +23,30 @@ export default {
"caniuse-lite": "caniuse-lite",
"/^caniuse-lite(/.*)/": "caniuse-lite$1"
}
},
{
name: "enhanced-resolve",
externals: {
tapable: "tapable",
"graceful-fs": "../graceful-fs/index.js"
},
afterBundle({ depPath, distPath }) {
copyFileSync(
join(depPath, "lib/CachedInputFileSystem.js"),
join(distPath, "CachedInputFileSystem.js")
);

// ResolveRequest type is used by Rspack but not exported
const dtsFile = join(distPath, "index.d.ts");
const content = readFileSync(dtsFile, "utf-8");
writeFileSync(
dtsFile,
content.replace(
"type ResolveRequest =",
"export type ResolveRequest ="
)
);
}
}
]
};
4 changes: 4 additions & 0 deletions packages/rspack/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"watchpack": ["../compiled/watchpack"],
"graceful-fs": ["../compiled/graceful-fs"],
"browserslist": ["../compiled/browserslist"],
"enhanced-resolve": ["../compiled/enhanced-resolve"],
"enhanced-resolve/lib/CachedInputFileSystem": [
"../compiled/enhanced-resolve/CachedInputFileSystem"
],
"zod-validation-error": ["../compiled/zod-validation-error"],
"json-parse-even-better-errors": [
"../compiled/json-parse-even-better-errors"
Expand Down
7 changes: 3 additions & 4 deletions pnpm-lock.yaml

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

2 comments on commit 63110e3

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Benchmark detail: Open

Name Base (2024-05-21 5fbabcf) Current Change
10000_development-mode + exec 2.65 s ± 33 ms 2.64 s ± 23 ms -0.15 %
10000_development-mode_hmr + exec 732 ms ± 11 ms 742 ms ± 3.8 ms +1.44 %
10000_production-mode + exec 2.55 s ± 24 ms 2.59 s ± 12 ms +1.36 %
arco-pro_development-mode + exec 2.54 s ± 87 ms 2.5 s ± 81 ms -1.48 %
arco-pro_development-mode_hmr + exec 436 ms ± 2.9 ms 437 ms ± 1.8 ms +0.18 %
arco-pro_development-mode_hmr_intercept-plugin + exec 445 ms ± 1.7 ms 447 ms ± 4.6 ms +0.38 %
arco-pro_development-mode_intercept-plugin + exec 3.31 s ± 76 ms 3.36 s ± 79 ms +1.46 %
arco-pro_production-mode + exec 4.06 s ± 134 ms 4.08 s ± 87 ms +0.42 %
arco-pro_production-mode_intercept-plugin + exec 4.9 s ± 54 ms 4.95 s ± 83 ms +0.97 %
threejs_development-mode_10x + exec 1.99 s ± 18 ms 2 s ± 26 ms +0.37 %
threejs_development-mode_10x_hmr + exec 768 ms ± 5.2 ms 765 ms ± 6.5 ms -0.44 %
threejs_production-mode_10x + exec 5.28 s ± 17 ms 5.31 s ± 28 ms +0.52 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

suite result

Please sign in to comment.