Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folder names given .compiled instead of files #32

Open
PascalPixel opened this issue Nov 8, 2023 · 0 comments
Open

Folder names given .compiled instead of files #32

PascalPixel opened this issue Nov 8, 2023 · 0 comments

Comments

@PascalPixel
Copy link

PascalPixel commented Nov 8, 2023

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today I used patch-package to patch @herberttn/bytenode-webpack-plugin@2.3.1 for the project I'm working on.

/lib/plugin.js

To be more lazy in my forge config, I added a skip for web, since if nodeIntegration is enabled for a renderer, forge makes the target one of the electron- variants, whereas otherwise it's web. Forge's webpack plugin doesn't allow configuring different plugins for individual renderers, hence this takes advantage of that automatic target configuration by allowing everything to be passed in, only compiling the renderer that has nodeIntegration set to true.

/lib/utils.js

When nesting (multiple?) entry points the paths are resolved in a way that breaks the build; the folder name is given the .compiled extension instead of the file:

  • This: something/ui.compiled/index.jsc
  • Instead of: something/ui/index.compiled.jsc

Here is the diff that solved my problem:

diff --git a/node_modules/@herberttn/bytenode-webpack-plugin/lib/plugin.js b/node_modules/@herberttn/bytenode-webpack-plugin/lib/plugin.js
index c621dee..7acafbc 100644
--- a/node_modules/@herberttn/bytenode-webpack-plugin/lib/plugin.js
+++ b/node_modules/@herberttn/bytenode-webpack-plugin/lib/plugin.js
@@ -26,6 +26,16 @@ class BytenodeWebpackPlugin {
     apply(compiler) {
         const logger = compiler.getInfrastructureLogger(this.name);
         setupLifecycleLogging(compiler, this.name, this.options);
+        if (this.options.compileForElectron) {
+            const target = compiler.options.target;
+            if (target) {
+                const targets = Array.isArray(target) ? target : [target];
+                if (!targets.some((target) => target.startsWith('electron-'))) {
+                    logger.warn(`Not using bytenode because [${targets.join(', ')}] is marked as "compileForElectron: true" but has "target: 'web'".`);
+                    return;
+                }
+            }
+        }
         logger.debug('original webpack.options.entry', compiler.options.entry);
         const { entries: { ignored, loaders, targets }, modules } = prepare(compiler);
         logger.debug('prepared ignores', Object.fromEntries(ignored.entries()));
diff --git a/node_modules/@herberttn/bytenode-webpack-plugin/lib/utils.js b/node_modules/@herberttn/bytenode-webpack-plugin/lib/utils.js
index 79abcda..116ed0c 100644
--- a/node_modules/@herberttn/bytenode-webpack-plugin/lib/utils.js
+++ b/node_modules/@herberttn/bytenode-webpack-plugin/lib/utils.js
@@ -55,7 +55,12 @@ function fromCompiledToTargetExtension(file) {
 }
 exports.fromCompiledToTargetExtension = fromCompiledToTargetExtension;
 function fromTargetToCompiledExtension(file) {
-    return file.replace(TARGET_EXTENSION_REGEX, COMPILED_EXTENSION);
+    const dest = file.replace(TARGET_EXTENSION_REGEX, COMPILED_EXTENSION);
+    if (!dest.includes('.compiled.jsc')) {
+        const patchedDest = dest.replace('.compiled', '');
+        return patchedDest.replace('.jsc', '.compiled.jsc');
+    }
+    return dest;
 }
 exports.fromTargetToCompiledExtension = fromTargetToCompiledExtension;
 function isCompiledExtension(file) {

This issue body was partially generated by patch-package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant