Skip to content

Commit

Permalink
fix(app-webpack): ensure latest appPkg is always up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Apr 26, 2024
1 parent b6a2a3e commit 548a2fc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
3 changes: 0 additions & 3 deletions app-webpack/lib/app-extension/api-classes/InstallAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ module.exports.InstallAPI = class InstallAPI extends BaseAPI {
'utf-8'
)

// we mingled with it, time to notify there's a need to update it
this.ctx.pkg.updateAppPackageJson()

if (
extPkg.dependencies
|| extPkg.devDependencies
Expand Down
2 changes: 0 additions & 2 deletions app-webpack/lib/quasar-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ module.exports.QuasarConfigFile = class QuasarConfigFile {
let firstBuildIsDone

const { appPaths } = this.#ctx
const { updateAppPackageJson } = this.#ctx.pkg
const tempFile = this.#tempFile

esbuildConfig.plugins.push({
Expand All @@ -319,7 +318,6 @@ module.exports.QuasarConfigFile = class QuasarConfigFile {
if (isFirst === false) {
log()
log('The quasar.config file (or its dependencies) changed. Reading it again...')
updateAppPackageJson()
}
})

Expand Down
33 changes: 24 additions & 9 deletions app-webpack/lib/utils/get-pkg.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
const { readFileSync } = require('node:fs')
const { readFileSync, statSync } = require('node:fs')

const { warning } = require('./logger.js')
const { getPackageJson } = require('../utils/get-package-json.js')

module.exports.getPkg = function getPkg (appPaths) {
const { appDir, cliDir } = appPaths
const appPkgPath = appPaths.resolve.app('package.json')

function readAppPackageJson () {
return JSON.parse(
readFileSync(appPkgPath, 'utf-8')
)
let appPkg = {}
let lastAppPkgModifiedTime = 0

function getAppPackageJson () {
const { mtime } = statSync(appPkgPath)

if (mtime !== lastAppPkgModifiedTime) {
lastAppPkgModifiedTime = mtime
try {
appPkg = JSON.parse(
readFileSync(appPkgPath, 'utf-8')
)
}
catch (err) {
warning('Could not parse app\'s package.json. The file is malformed:')
console.error(err)
}
}

return appPkg
}

const acc = {
appPkg: readAppPackageJson(),
updateAppPackageJson () {
acc.appPkg = readAppPackageJson()
},
quasarPkg: getPackageJson('quasar', appDir),
webpackPkg: (
getPackageJson('webpack', appDir)
|| getPackageJson('webpack', cliDir)
)
}

Object.defineProperty(acc, 'appPkg', { get: getAppPackageJson })

return acc
}

0 comments on commit 548a2fc

Please sign in to comment.