MCPcopy
hub / github.com/webpack/webpack / apply

Function apply

test/Compiler-filesystem-caching.test.js:65–177  ·  view source on GitHub ↗
(compiler)

Source from the content-addressed store, hash-verified

63 options.plugins = [
64 {
65 apply(compiler) {
66 const name = "TestCachePlugin";
67
68 compiler.hooks.thisCompilation.tap(name, (compilation) => {
69 compilation.hooks.processAssets.tapPromise(
70 {
71 name,
72 stage:
73 compiler.webpack.Compilation
74 .PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE
75 },
76 async () => {
77 const cache = compilation.getCache(name);
78 const ident = "test.ext";
79 const cacheItem_ = cache.getItemCache(ident, null);
80 const cacheItem =
81 /** @type {{ getPromise(id: string): Promise<unknown>, storePromise(v: unknown): Promise<void> }} */ (
82 /** @type {unknown} */ (cacheItem_)
83 );
84
85 const result_ = await cacheItem.getPromise(ident);
86 const result =
87 /** @type {Record<string, Record<string, Record<string, unknown>> & Iterable<unknown>>} */ (
88 result_
89 );
90
91 if (result) {
92 expect(result.number).toBe(42);
93 expect(result.number1).toBe(3.14);
94 expect(result.number2).toBe(6.2);
95 expect(result.string).toBe("string");
96
97 if (isErrorCaseSupported) {
98 expect(result.error.cause.message).toBe("cause");
99 expect(result.error1.cause.string).toBe("string");
100 expect(result.error1.cause.number).toBe(42);
101 }
102
103 if (isAggregateErrorSupported) {
104 expect(result.aggregateError.errors).toEqual([
105 new Error("first", { cause: "nested cause" }),
106 "second"
107 ]);
108 expect(result.aggregateError.message).toBe(
109 "aggregate error"
110 );
111 expect(result.aggregateError.cause.message).toBe("cause");
112 }
113
114 if (isBigIntSupported) {
115 expect(result.bigint).toBe(BigInt(5));
116 expect(result.bigint1).toBe(BigInt(124));
117 expect(result.bigint2).toBe(BigInt(125));
118 expect(result.bigint3).toBe(BigInt("12345678901234567890"));
119 expect(result.bigint4).toBe(BigInt(5));
120 expect(result.bigint5).toBe(BigInt(1000000));
121 expect(result.bigint6).toBe(BigInt(128));
122 expect(result.bigint7).toBe(BigInt(2147483647));

Callers

nothing calls this directly

Calls 5

tapMethod · 0.80
getItemCacheMethod · 0.80
getCacheMethod · 0.45
getPromiseMethod · 0.45
storePromiseMethod · 0.45

Tested by

no test coverage detected