Skip to content

Commit

Permalink
fix: format js
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed May 9, 2024
1 parent c1cea74 commit 390745f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 40 deletions.
65 changes: 43 additions & 22 deletions packages/rspack/src/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ import { assertNotNill } from "./util/assertNotNil";
import { FileSystemInfoEntry } from "./FileSystemInfo";
import { RuntimeGlobals } from "./RuntimeGlobals";
import { tryRunOrWebpackError } from "./lib/HookWebpackError";
import { CodeGenerationResult, ContextModuleFactoryBeforeResolveResult, ContextModuleFactoryAfterResolveResult, Module, ResolveData } from "./Module";
import {
CodeGenerationResult,
ContextModuleFactoryAfterResolveResult,
Module,
ResolveData
} from "./Module";
import { canInherentFromParent } from "./builtin-plugin/base";
import ExecuteModulePlugin from "./ExecuteModulePlugin";
import { Chunk } from "./Chunk";
Expand Down Expand Up @@ -530,32 +535,48 @@ class Compiler {
binding.RegisterJsTapKind.ContextModuleFactoryBeforeResolve,
() =>
this.compilationParams!.contextModuleFactory.hooks.beforeResolve,
queried => async (bindingData: false | binding.JsContextModuleFactoryBeforeResolveData) => {
return queried.promise(bindingData);
}
queried =>
async (
bindingData:
| false
| binding.JsContextModuleFactoryBeforeResolveData
) => {
return queried.promise(bindingData);
}
),
registerContextModuleFactoryAfterResolveTaps:
this.#createHookRegisterTaps(
binding.RegisterJsTapKind.ContextModuleFactoryAfterResolve,
() => this.compilationParams!.contextModuleFactory.hooks.afterResolve,
queried => async (bindingData: false | binding.JsContextModuleFactoryAfterResolveData) => {
const data = bindingData ? {
resource: bindingData.resource,
regExp: bindingData.regExp ? new RegExp(bindingData.regExp) : undefined,
request: bindingData.request,
context: bindingData.context,
// TODO: Dependencies are not fully supported yet; this is a placeholder to prevent errors in moment-locales-webpack-plugin.
dependencies: [],
} satisfies ContextModuleFactoryAfterResolveResult : false;
const ret = await queried.promise(data);
const result = ret ? {
resource: ret.resource,
context: ret.context,
request: ret.request,
regExp: ret.regExp?.toString(),
} satisfies binding.JsContextModuleFactoryAfterResolveData : undefined;
return result;
}
queried =>
async (
bindingData:
| false
| binding.JsContextModuleFactoryAfterResolveData
) => {
const data = bindingData
? ({
resource: bindingData.resource,
regExp: bindingData.regExp
? new RegExp(bindingData.regExp)
: undefined,
request: bindingData.request,
context: bindingData.context,
// TODO: Dependencies are not fully supported yet; this is a placeholder to prevent errors in moment-locales-webpack-plugin.
dependencies: []
} satisfies ContextModuleFactoryAfterResolveResult)
: false;
const ret = await queried.promise(data);
const result = ret
? ({
resource: ret.resource,
context: ret.context,
request: ret.request,
regExp: ret.regExp?.toString()
} satisfies binding.JsContextModuleFactoryAfterResolveData)
: undefined;
return result;
}
)
};

Expand Down
15 changes: 12 additions & 3 deletions packages/rspack/src/ContextModuleFactory.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import * as liteTapable from "./lite-tapable";
import { ContextModuleFactoryAfterResolveResult, ContextModuleFactoryBeforeResolveResult } from "./Module";
import {
ContextModuleFactoryAfterResolveResult,
ContextModuleFactoryBeforeResolveResult
} from "./Module";

export class ContextModuleFactory {
hooks: {
// TODO: second param resolveData
// resolveForScheme: HookMap<
// AsyncSeriesBailHook<[ResourceDataWithData], true | void>
// >;
beforeResolve: liteTapable.AsyncSeriesWaterfallHook<[ContextModuleFactoryBeforeResolveResult], ContextModuleFactoryBeforeResolveResult | void>;
afterResolve: liteTapable.AsyncSeriesWaterfallHook<[ContextModuleFactoryAfterResolveResult], ContextModuleFactoryAfterResolveResult | void>;
beforeResolve: liteTapable.AsyncSeriesWaterfallHook<
[ContextModuleFactoryBeforeResolveResult],
ContextModuleFactoryBeforeResolveResult | void
>;
afterResolve: liteTapable.AsyncSeriesWaterfallHook<
[ContextModuleFactoryAfterResolveResult],
ContextModuleFactoryAfterResolveResult | void
>;
};
constructor() {
this.hooks = {
Expand Down
28 changes: 16 additions & 12 deletions packages/rspack/src/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ export type ResolveData = {
createData?: CreateData;
};

export type ContextModuleFactoryBeforeResolveResult = false | {
context: string;
request?: string;
}

export type ContextModuleFactoryAfterResolveResult = false | {
resource: string;
context: string
request: string
regExp?: RegExp;
dependencies: Array<any>;
}
export type ContextModuleFactoryBeforeResolveResult =
| false
| {
context: string;
request?: string;
};

export type ContextModuleFactoryAfterResolveResult =
| false
| {
resource: string;
context: string;
request: string;
regExp?: RegExp;
dependencies: Array<any>;
};

export class Module {
#inner: JsModule;
Expand Down
6 changes: 3 additions & 3 deletions packages/rspack/src/lite-tapable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ export class AsyncSeriesWaterfallHook<
(r: R) => {
index += 1;
if (r !== undefined) {
data = r
data = r;
}
if (index === tapsInRange.length) {
done();
Expand All @@ -843,7 +843,7 @@ export class AsyncSeriesWaterfallHook<
} else {
index += 1;
if (r !== undefined) {
data = r
data = r;
}
if (index === tapsInRange.length) {
done();
Expand All @@ -857,7 +857,7 @@ export class AsyncSeriesWaterfallHook<
try {
const r = tap.fn(data);
if (r !== undefined) {
data = r
data = r;
}
} catch (e) {
hasError = true;
Expand Down

0 comments on commit 390745f

Please sign in to comment.