develar / app-builder

Generic helper tool to build app in a distributable format
MIT License
122 stars 62 forks source link

fix: fix tar node module #134

Closed beyondkmp closed 2 months ago

beyondkmp commented 2 months ago

fix https://github.com/electron-userland/electron-builder/issues/8431

package.json

{
  "name": "TestApp",
  "productName": "Test App ßW",
  "description": "My Electron application description",
  "keywords": [],
  "main": "./main.js",
  "version": "1.0.0",
  "author": "beyondkmp",
  "scripts": {
    "start": "electron .",
    "dist": "electron-builder"
  },
  "license": "MIT",
  "build": {
    "appId": "electron-blog-example",
    "win": {
      "target": "nsis"
    }
  },
  "devDependencies": {
    "electron": "32.0.1",
    "electron-builder": "25.0.6"
  },
  "dependencies": {
    "tar": "^7.4.3"
  }
}

main.js

// Modules to control application life and create native browser window
const { app, BrowserWindow,ipcMain } = require('electron')
const path = require('node:path')
const { create } = require('tar')

function createWindow () {
  // Create the browser window.
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  })

  // and load the index.html of the app.
  //mainWindow.loadFile('index.html?file=https://1234567.beyondkmp.com/2356625133021.pdf')
  mainWindow.loadFile('index.html')
  //mainWindow.loadURL(`file://${pdfViewer}?file=${fileUrl}`);

  // Open the DevTools.
  // mainWindow.webContents.openDevTools()
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
  createWindow()

   ipcMain.on('send-render-completed', (event) => {
    console.log('send-render-completed xxxxx');
   })

  app.on('activate', function () {
    // On macOS it's common to re-create a window in the app when the
    // dock icon is clicked and there are no other windows open.
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })
})

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') app.quit()
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

error

Uncaught Exception:
TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (/Applications/Podman Desktop.app/Contents/Resources/app.asar/node_modules/minizlib/dist/commonjs/index.js:138:6)
at Module._compile (node:internal/modules/cjs/loader:1373:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1432:10)
at Module.load (node:internal/modules/cjs/loader:1215:32)
at Module._load (node:internal/modules/cjs/loader:1031:12)
at c._load (node:electron/js2c/node_init:2:17025)
at Module.require (node:internal/modules/cjs/loader:1240:19)
at require (node:internal/modules/helpers:179:18)
at Object.<anonymous> (/Applications/Podman Desktop.app/Contents/Resources/app.asar/node_modules/tar/dist/commonjs/parse.js:24:20)
at Module._compile (node:internal/modules/cjs/loader:1373:14)

root cause

{
        "name": "minizlib",
        "version": "3.0.1",
        "dir": "C:\\Users\\beyon\\Code\\hello\\node_modules\\tar\\node_modules\\minizlib",
        "conflictDependency": [
            {
                "name": "minipass",
                "version": "3.3.6",
                "dir": "C:\\Users\\beyon\\Code\\hello\\node_modules\\minipass",
                "conflictDependency": [
                    {
                        "name": "yallist",
                        "version": "4.0.0",
                        "dir": "C:\\Users\\beyon\\Code\\hello\\node_modules\\yallist"
                    }
                ]
            }
        ]
    },

The version of minipass in the minizlib dependency is incorrect; it shouldn't be 3.3.6.

Currently, there's no record of the parent-child tree relationship, and it doesn't search for the highest parent node. If it's already found, it directly returns nil, causing it to revert to an older version.

How to fix

Perform a fixed-order loop search on the NodeModuleDirToDependencyMap. If the dependency is in the hoistedDependMap and the version number is different, place that dependency in the conflictDependencyMap of the highest parent node. If it's not in the hoistedDependMap, just set it directly.

The current approach is to implement a hoistedDependMap, so it's no longer necessary to set node-linker=hoisted in pnpm's configuration.

changeset-bot[bot] commented 2 months ago

🦋 Changeset detected

Latest commit: ce78ac6f455bcf46504ae4c62d2a4e0e9ade2447

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | --------------- | ----- | | app-builder-bin | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR