Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Mar 1, 2024
1 parent 60d6ef4 commit 51cc578
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions vike/node/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type { ConfigVikeUserProvided as UserConfig }
export { PROJECT_VERSION as version } from './utils.js'

import { version, type Plugin } from 'vite'
import { assertNodeEnv_onVikePluginLoad, assertUsage, isVersionOrAbove, markEnvAsVikePluginLoaded } from './utils.js'
import { assertNodeEnv_onVikePluginLoad, assertUsage, assertVersion, markEnvAsVikePluginLoaded } from './utils.js'
import { buildConfig } from './plugins/buildConfig.js'
import { previewConfig } from './plugins/previewConfig.js'
import { autoFullBuild } from './plugins/autoFullBuild.js'
Expand Down Expand Up @@ -80,5 +80,5 @@ Object.defineProperty(plugin, 'apply', {

// node_modules/vike/package.json#peerDependencies.vite isn't enough as users can ignore it
function assertViteVersion() {
assertUsage(isVersionOrAbove(version, '4.4.0'), `Vite ${version} isn't supported, use Vite >= 4.4.0 instead.`)
assertVersion('Vite', version, '4.4.0')
}
2 changes: 1 addition & 1 deletion vike/node/plugin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ export * from '../../utils/assertKeys.js'
export * from '../../utils/injectRollupInputs.js'
export * from '../../utils/humanizeTime.js'
export * from '../../utils/pLimit.js'
export * from '../../utils/isVersionOrAbove.js'
export * from '../../utils/assertVersion.js'
7 changes: 3 additions & 4 deletions vike/utils/assertNodeVersion.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
export { assertNodeVersion }

import { assertUsage } from './assert.js'
import { isNodeJS } from './isNodeJS.js'
import { isVersionOrAbove } from './isVersionOrAbove.js'
import { assertVersion } from './assertVersion.js'

// package.json#engines.node isn't enough as users can ignore it
// node_modules/vike/package.json#engines.node isn't enough as users can ignore it
function assertNodeVersion() {
if (!isNodeJS()) return
const version = process.versions.node
assertUsage(isVersionOrAbove(version, '16.0.0'), `Node.js ${version} isn't supported, use Node.js >=16.0.0 instead.`)
assertVersion('Node.js', version, '16.0.0')
}
14 changes: 13 additions & 1 deletion vike/utils/isVersionOrAbove.ts → vike/utils/assertVersion.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
export { assertVersion }
export { isVersionOrAbove }

import { assert } from './assert.js'
import { assert, assertUsage } from './assert.js'

function assertVersion(
dependencyName: 'Vite' | 'Node.js',
versionActual: string,
versionExpected: `${number}.${number}.${number}`
) {
assertUsage(
isVersionOrAbove(versionActual, versionExpected),
`${dependencyName} ${versionActual} isn't supported, use ${dependencyName} >= ${versionExpected} instead.`
)
}

function isVersionOrAbove(versionActual: string, versionExpected: `${number}.${number}.${number}`): boolean {
const p1 = parseVersion(versionActual)
Expand Down

0 comments on commit 51cc578

Please sign in to comment.