electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.33k stars 493 forks source link

DevDependencies are not removed when running electron-forge make #3465

Closed alinmateutdev closed 5 months ago

alinmateutdev commented 5 months ago

Pre-flight checklist

Electron Forge version

7.2.0

Electron version

28.1.3

Operating system

Windows 11

Last known working Electron Forge version

-

Expected behavior

According to electron-packager, devDependencies should not be included in the final app.

Actual behavior

They are included in the final app, and it has nothing to do with this issue. It happens even on the hello-world app.

Note: For simplicity, below I didn't set packagerConfig: {asar: true}. However, even if you generate an asar, when you inspect the content of that asar by using asar list app.asar, you see the exact same content like without using it.

Steps to reproduce

Create a main.js file with containing:

const { app, BrowserWindow } = require('electron/main')
const path = require('node:path')

function createWindow () {
    const win = new BrowserWindow({
        width: 800, height: 600, webPreferences: {
            preload: path.join(__dirname, 'preload.js')
        }
    })
    win.loadFile('index.html')
}

app.whenReady().then(() => { createWindow() })

Create a preload.js file with containing:

window.addEventListener('DOMContentLoaded', () => {
    const replaceText = (selector, text) => {
        const element = document.getElementById(selector)
        if (element) element.innerText = text
    }

    for (const type of ['chrome', 'node', 'electron']) {
        replaceText(`${type}-version`, process.versions[type])
    }
})

Create a index.html file containing:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Hello World!</title>
    <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
<body>
<h1>Hello World!</h1>
<p>
    We are using Node.js <span id="node-version"></span>,
    Chromium <span id="chrome-version"></span>,
    and Electron <span id="electron-version"></span>.
</p>
</body>
</html>

Create a package.json file containing:

{
  "name": "my-electron-app",
  "version": "1.0.0",
  "description": "Hello World!",
  "main": "main.js",
  "author": "Jane Doe",
  "license": "MIT",
  "scripts": {
    "start": "electron .",
    "build": "electron-forge make"
  },
  "devDependencies": {
    "@electron-forge/cli": "7.2.0",
    "@electron-forge/maker-appx": "^7.2.0",
    "electron": "28.1.3"
  }
}

Create a forge.config.js file containing:

module.exports = {
    rebuildConfig: {},
    makers: [
        {
            name: '@electron-forge/maker-appx',
            config: {
                publisher: 'CN=hey',
                packageDisplayName: 'hey',
                packageName: 'hey'
            }
        },
    ]
};

After running electron-forge make, in the output directory you can see node_modules, even if I didn't declare any dependencies, but only devDependencies: image

Additional information

No response

justgo97 commented 5 months ago

These folders in node_modules are empty? I tried to reproduce this and that's the result I got.

alinmateutdev commented 5 months ago

@justgo97 Yes, seems that they are empty. Sorry, I didn't mentioned that

erikian commented 5 months ago

This is working as expected, I think the empty folders are a consequence of how the Galactus module that we use to do the pruning handles @scoped packages, but it does remove all module files despite leaving the empty folder behind.