+ )}
+ >
+
+
+
+
+ >
+ );
+ }
});
diff --git a/src/plugins/viewIcons/index.tsx b/src/plugins/viewIcons/index.tsx
index 6eb773c28..f71777ad7 100644
--- a/src/plugins/viewIcons/index.tsx
+++ b/src/plugins/viewIcons/index.tsx
@@ -174,7 +174,7 @@ export default definePlugin({
find: ".NITRO_BANNER,",
replacement: {
// style: { backgroundImage: shouldShowBanner ? "url(".concat(bannerUrl,
- match: /style:\{(?=backgroundImage:(\i)\?"url\("\.concat\((\i),)/,
+ match: /style:\{(?=backgroundImage:(null!=\i)\?"url\("\.concat\((\i),)/,
replace:
// onClick: () => shouldShowBanner && ev.target.style.backgroundImage && openImage(bannerUrl), style: { cursor: shouldShowBanner ? "pointer" : void 0,
'onClick:ev=>$1&&ev.target.style.backgroundImage&&$self.openImage($2),style:{cursor:$1?"pointer":void 0,'
diff --git a/src/utils/types.ts b/src/utils/types.ts
index fc34b96de..bec7cb0b3 100644
--- a/src/utils/types.ts
+++ b/src/utils/types.ts
@@ -36,7 +36,7 @@ export interface PatchReplacement {
export interface Patch {
plugin: string;
- find: string | string[];
+ find: string;
replacement: PatchReplacement | PatchReplacement[];
/** Whether this patch should apply to multiple modules */
all?: boolean;
diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts
index 2ce4939b6..db47c875a 100644
--- a/src/webpack/patchWebpack.ts
+++ b/src/webpack/patchWebpack.ts
@@ -186,8 +186,7 @@ function patchFactories(factories: Record code.replace(match, replace));
if (patch.predicate && !patch.predicate()) continue;
- // we change all patch.find to array in plugins/index
- if ((patch.find as string[]).every(f => code.includes(f))) {
+ if (code.includes(patch.find)) {
patchedBy.add(patch.plugin);
const previousMod = mod;
diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts
index 0790e8bf1..10c7d7ee1 100644
--- a/src/webpack/webpack.ts
+++ b/src/webpack/webpack.ts
@@ -406,13 +406,15 @@ export function findExportedComponentLazy(...props: stri
});
}
+const DefaultExtractAndLoadChunksRegex = /(?:Promise\.all\((\[\i\.\i\(".+?"\).+?\])\)|Promise\.resolve\(\)).then\(\i\.bind\(\i,"(.+?)"\)\)/;
+
/**
* Extract and load chunks using their entry point
* @param code An array of all the code the module factory containing the lazy chunk loading must include
* @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the lazy chunk loading found in the module factory
* @returns A promise that resolves when the chunks were loaded
*/
-export async function extractAndLoadChunks(code: string[], matcher: RegExp = /Promise\.all\((\[\i\.\i\(".+?"\).+?\])\).then\(\i\.bind\(\i,"(.+?)"\)\)/) {
+export async function extractAndLoadChunks(code: string[], matcher: RegExp = DefaultExtractAndLoadChunksRegex) {
const module = findModuleFactory(...code);
if (!module) {
const err = new Error("extractAndLoadChunks: Couldn't find module factory");
@@ -434,7 +436,7 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = /Pr
}
const [, rawChunkIds, entryPointId] = match;
- if (!rawChunkIds || Number.isNaN(entryPointId)) {
+ if (Number.isNaN(entryPointId)) {
const err = new Error("extractAndLoadChunks: Matcher didn't return a capturing group with the chunk ids array, or the entry point id returned as the second group wasn't a number");
logger.warn(err, "Code:", code, "Matcher:", matcher);
@@ -445,9 +447,11 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = /Pr
return;
}
- const chunkIds = Array.from(rawChunkIds.matchAll(/\("(.+?)"\)/g)).map((m: any) => m[1]);
+ if (rawChunkIds) {
+ const chunkIds = Array.from(rawChunkIds.matchAll(/\("(.+?)"\)/g)).map((m: any) => m[1]);
+ await Promise.all(chunkIds.map(id => wreq.e(id)));
+ }
- await Promise.all(chunkIds.map(id => wreq.e(id)));
wreq(entryPointId);
}
@@ -459,7 +463,7 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = /Pr
* @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the lazy chunk loading found in the module factory
* @returns A function that returns a promise that resolves when the chunks were loaded, on first call
*/
-export function extractAndLoadChunksLazy(code: string[], matcher: RegExp = /Promise\.all\((\[\i\.\i\(".+?"\).+?\])\).then\(\i\.bind\(\i,"(.+?)"\)\)/) {
+export function extractAndLoadChunksLazy(code: string[], matcher = DefaultExtractAndLoadChunksRegex) {
if (IS_DEV) lazyWebpackSearchHistory.push(["extractAndLoadChunks", [code, matcher]]);
return () => extractAndLoadChunks(code, matcher);