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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix tar node module #134

Merged
merged 14 commits into from
Sep 15, 2024
Merged

fix: fix tar node module #134

merged 14 commits into from
Sep 15, 2024

Conversation

beyondkmp
Copy link
Contributor

@beyondkmp beyondkmp commented Sep 13, 2024

fix electron-userland/electron-builder#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.

Copy link

changeset-bot bot commented Sep 13, 2024

🦋 Changeset detected

Latest commit: ce78ac6

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

for k := range *list {
names = append(names, k)
}
sort.Strings(names)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The electron-builder pipeline(https://github.com/electron-userland/electron-builder/actions/runs/10856416053/job/30131018855) occasionally failed, and I finally found the root cause. The map in Golang doesn't maintain a fixed order, so sometimes it returns [foo, ms], and other times it returns [ms, foo]. If the order is incorrect, it leads to different results. Now that we've fixed the order, it won't fail anymore.

image

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

Successfully merging this pull request may close these issues.

25.0.5 builds broken due to missing native binaries
2 participants