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(app-extension): Allow the extension developer to specify the extension install flags, fix: #6352 #6405

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
47 changes: 43 additions & 4 deletions app/lib/app-extension/Extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,48 @@ module.exports = class Extension {
return prompts
}

// extracts extension params defined in its package.json file
params () {
try {
// reads package.json key: 'quasar.extension' if defined.
// execSync returns a buffer
const paramsBuffer = require('child_process').execSync(
`npm view --json ${this.packageFullName} quasar.extension`
)

// parse the buffer and return an object
return JSON.parse(paramsBuffer)
} catch (err) {
// when the extension is not published yet to npm, the above will result
// in an error.
return {}
}
}

getInstallFlags () {
const params = this.params()

// if install flags are not defined, we target devDependencies as default
const npmInstallFlags = 'npmInstallFlags' in params
? params.npmInstallFlags
: '--save-dev'
const yarnAddFlags = 'yarnAddFlags' in params
? params.yarnAddFlags
: '--dev'

return {
npm: npmInstallFlags,
yarn: yarnAddFlags
}
}

__installPackage () {
const flags = this.getInstallFlags()
const nodePackager = require('../helpers/node-packager')
// if flags are specified as empty strings, we don't concatenate
const cmdParam = nodePackager === 'npm'
? ['install', '--save-dev']
: ['add', '--dev']
? flags.npm === '' ? ['install'] : ['install'].concat(flags.npm)
: flags.yarn === '' ? ['add'] : ['add'].concat(flags.yarn)

log(`Retrieving "${this.packageFullName}"...`)
spawnSync(
Expand All @@ -265,10 +302,12 @@ module.exports = class Extension {
}

__uninstallPackage () {
const flags = this.getInstallFlags()
const nodePackager = require('../helpers/node-packager')
// if flags are specified as empty strings, we don't concatenate
const cmdParam = nodePackager === 'npm'
? ['uninstall', '--save-dev']
: ['remove']
? flags.npm === '' ? ['uninstall'] : ['uninstall'].concat(flags.npm)
: flags.yarn === '' ? ['remove'] : ['remove'].concat(flags.yarn)

log(`Uninstalling "${this.packageName}"...`)
spawnSync(
Expand Down