Skip to content

Commit

Permalink
fix(app-vite/app-webpack): Electron build + pnpm installs with symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Apr 26, 2024
1 parent 3655daa commit 69a3427
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
28 changes: 24 additions & 4 deletions app-vite/lib/modes/electron/electron-builder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join } from 'node:path'
import fse from 'fs-extra'
import { merge } from 'webpack-merge'

import { log, warn, progress } from '../../utils/logger.js'
Expand All @@ -11,7 +12,7 @@ export class QuasarModeBuilder extends AppBuilder {
async build () {
await this.#buildFiles()
await this.#writePackageJson()
await this.#copyElectronFiles()
this.#copyElectronFiles()

this.printSummary(join(this.quasarConf.build.distDir, 'UnPackaged'))

Expand Down Expand Up @@ -62,14 +63,13 @@ export class QuasarModeBuilder extends AppBuilder {
)
}

async #copyElectronFiles () {
#copyElectronFiles () {
const patterns = [
'.npmrc',
'.yarnrc',
'package-lock.json',
'yarn.lock',
'pnpm-lock.yaml'
// bun.lockb should be ignored since it error out with devDeps in package.json
// bun.lockb should be ignored since it errors out with devDeps in package.json
// (error: lockfile has changes, but lockfile is frozen)
].map(filename => ({
from: filename,
Expand All @@ -82,6 +82,26 @@ export class QuasarModeBuilder extends AppBuilder {
})

this.copyFiles(patterns)

// handle .npmrc separately
const npmrc = this.ctx.appPaths.resolve.app('.npmrc')
if (fse.existsSync(npmrc)) {
let content = this.readFile(npmrc)

if (content.indexOf('shamefully-hoist') === -1) {
content += '\nshamefully-hoist=true'
}
// very important, otherwise PNPM creates symlinks which is NOT
// what we want for an Electron app that should run cross-platform
if (content.indexOf('node-linker') === -1) {
content += '\nnode-linker=hoisted'
}

this.writeFile(
join(this.quasarConf.build.distDir, 'UnPackaged/.npmrc'),
content
)
}
}

async #packageFiles () {
Expand Down
28 changes: 24 additions & 4 deletions app-webpack/lib/modes/electron/electron-builder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { join } = require('node:path')
const { existsSync } = require('fs-extra')
const { merge } = require('webpack-merge')

const { log, warn, progress } = require('../../utils/logger.js')
Expand All @@ -11,7 +12,7 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder {
async build () {
await this.#buildFiles()
await this.#writePackageJson()
await this.#copyElectronFiles()
this.#copyElectronFiles()

this.printSummary(join(this.quasarConf.build.distDir, 'UnPackaged'))

Expand Down Expand Up @@ -63,14 +64,13 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder {
)
}

async #copyElectronFiles () {
#copyElectronFiles () {
const patterns = [
'.npmrc',
'.yarnrc',
'package-lock.json',
'yarn.lock',
'pnpm-lock.yaml'
// bun.lockb should be ignored since it error out with devDeps in package.json
// bun.lockb should be ignored since it errors out with devDeps in package.json
// (error: lockfile has changes, but lockfile is frozen)
].map(filename => ({
from: filename,
Expand All @@ -83,6 +83,26 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder {
})

this.copyFiles(patterns)

// handle .npmrc separately
const npmrc = this.ctx.appPaths.resolve.app('.npmrc')
if (existsSync(npmrc)) {
let content = this.readFile(npmrc)

if (content.indexOf('shamefully-hoist') === -1) {
content += '\nshamefully-hoist=true'
}
// very important, otherwise PNPM creates symlinks which is NOT
// what we want for an Electron app that should run cross-platform
if (content.indexOf('node-linker') === -1) {
content += '\nnode-linker=hoisted'
}

this.writeFile(
join(this.quasarConf.build.distDir, 'UnPackaged/.npmrc'),
content
)
}
}

async #packageFiles () {
Expand Down

0 comments on commit 69a3427

Please sign in to comment.