-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app-webpack): ensure latest appPkg is always up to date
- Loading branch information
1 parent
b6a2a3e
commit 548a2fc
Showing
3 changed files
with
24 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |