Skip to content

Commit

Permalink
Node warnings with better version formatting (#410)
Browse files Browse the repository at this point in the history
The node version range is now taken from the engines field of the package.json, which is more readable than seeing semver's representation (>=12.0.0 <13.0.0-0||>=14.0.0 <15.0.0-0).
  • Loading branch information
vmarta authored Mar 1, 2022
1 parent e4a5bff commit d396fd3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions packages/pwa-kit-create-app/scripts/create-mobify-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,15 @@ const extractTemplate = (templateName, outputDir) => {
sh.rm('-rf', tmp)
}

const userNode = process.versions.node
const requiredNode = new semver.Range(generatorPkg.engines.node)
const isUsingCompatibleNode = semver.satisfies(userNode, requiredNode)
const foundNode = process.versions.node
const requiredNode = generatorPkg.engines.node
const isUsingCompatibleNode = semver.satisfies(foundNode, new semver.Range(requiredNode))

const main = (opts) => {
if (!isUsingCompatibleNode) {
console.log('')
console.warn(
`Warning: You are using Node ${userNode}. ` +
`Warning: You are using Node ${foundNode}. ` +
`Your app may not work as expected when deployed to Managed ` +
`Runtime servers which are compatible with Node ${requiredNode}`
)
Expand Down
9 changes: 5 additions & 4 deletions packages/pwa-kit-react-sdk/src/ssr/server/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,18 @@ export const createApp = (options) => {
const validateConfiguration = (options) => {
// Check that we are running under a compatible version of node
/* istanbul ignore next */
const requiredNode = new semver.Range(pkg.engines.node)
const requiredNode = pkg.engines.node
const foundNode = process.versions.node
/* istanbul ignore next */
if (
!semver.satisfies(
process.versions.node, // A string like '8.10.0'
requiredNode
foundNode, // A string like '8.10.0'
new semver.Range(requiredNode)
)
) {
/* istanbul ignore next */
console.warn(
`Warning: You are using Node ${process.versions.node}. ` +
`Warning: You are using Node ${foundNode}. ` +
`Your app may not work as expected when deployed to Managed ` +
`Runtime servers which are compatible with Node ${requiredNode}`
)
Expand Down
8 changes: 4 additions & 4 deletions scripts/check-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ if (!fs.existsSync(path.join('node_modules', 'semver'))) {
}

const semver = require('semver')
const requiredNode = new semver.Range(pkg.engines.node)
const requiredNode = pkg.engines.node
const foundNode = process.version
const requiredNpm = new semver.Range(pkg.engines.npm)
const requiredNpm = pkg.engines.npm
const foundNpm = spawnSync(npm, ['-v']).stdout.toString().trim()

const warnings = []

if (!semver.satisfies(foundNode, requiredNode)) {
if (!semver.satisfies(foundNode, new semver.Range(requiredNode))) {
warnings.push(`- Node: ${foundNode} is installed, but we require ${requiredNode}`)
}

if (!semver.satisfies(foundNpm, requiredNpm)) {
if (!semver.satisfies(foundNpm, new semver.Range(requiredNpm))) {
warnings.push(`- NPM: ${foundNpm} is installed, but we require ${requiredNpm}`)
}

Expand Down

0 comments on commit d396fd3

Please sign in to comment.