From 21779ff59c9f4b321a2fd46519c410380cdcce86 Mon Sep 17 00:00:00 2001 From: Daniel Nalborczyk Date: Fri, 8 Jul 2022 20:40:43 -0400 Subject: [PATCH] refactor: remove serverless compat check --- package-lock.json | 11 +++- package.json | 1 - src/ServerlessOffline.js | 33 ----------- .../__tests__/satisfiesVersionRange.test.js | 55 ------------------- src/utils/index.js | 1 - src/utils/satisfiesVersionRange.js | 13 ----- 6 files changed, 8 insertions(+), 106 deletions(-) delete mode 100644 src/utils/__tests__/satisfiesVersionRange.test.js delete mode 100644 src/utils/satisfiesVersionRange.js diff --git a/package-lock.json b/package-lock.json index 74dc437b3..71c46a472 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,6 @@ "object.hasown": "^1.1.1", "p-memoize": "^7.1.0", "p-retry": "^5.1.1", - "semver": "^7.3.7", "velocityjs": "^2.0.6", "ws": "^8.8.0" }, @@ -6258,6 +6257,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, "dependencies": { "yallist": "^4.0.0" }, @@ -8174,6 +8174,7 @@ "version": "7.3.7", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, "dependencies": { "lru-cache": "^6.0.0" }, @@ -9562,7 +9563,8 @@ "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true }, "node_modules/yaml": { "version": "2.1.1", @@ -14669,6 +14671,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, "requires": { "yallist": "^4.0.0" } @@ -16011,6 +16014,7 @@ "version": "7.3.7", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, "requires": { "lru-cache": "^6.0.0" } @@ -17056,7 +17060,8 @@ "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true }, "yaml": { "version": "2.1.1", diff --git a/package.json b/package.json index 06f5a8914..8d42a7e32 100644 --- a/package.json +++ b/package.json @@ -211,7 +211,6 @@ "object.hasown": "^1.1.1", "p-memoize": "^7.1.0", "p-retry": "^5.1.1", - "semver": "^7.3.7", "velocityjs": "^2.0.6", "ws": "^8.8.0" }, diff --git a/src/ServerlessOffline.js b/src/ServerlessOffline.js index c2abb5bf9..47567e732 100644 --- a/src/ServerlessOffline.js +++ b/src/ServerlessOffline.js @@ -1,9 +1,6 @@ -import { createRequire } from 'node:module' import process, { env, exit } from 'node:process' import { log } from '@serverless/utils/log.js' import chalk from 'chalk' -import semver from 'semver' -import { satisfiesVersionRange } from './utils/index.js' import { commandOptions, CUSTOM_OPTION, @@ -11,9 +8,6 @@ import { SERVER_SHUTDOWN_TIMEOUT, } from './config/index.js' -const require = createRequire(import.meta.url) -const pkg = require('../package.json') - export default class ServerlessOffline { #cliOptions = null @@ -68,8 +62,6 @@ export default class ServerlessOffline { // Put here so available everywhere, not just in handlers env.IS_OFFLINE = true - this.#verifyServerlessVersionCompatibility() - this._mergeOptions() const { httpEvents, lambdas, scheduleEvents, webSocketEvents } = @@ -396,29 +388,4 @@ export default class ServerlessOffline { getApiGatewayServer() { return this.#http.getServer() } - - // TODO: missing tests - #verifyServerlessVersionCompatibility() { - const currentVersion = this.#serverless.version - const requiredVersionRange = pkg.peerDependencies.serverless - - if (semver.parse(currentVersion).prerelease.length) { - // Do not validate, if run against serverless pre-release - return - } - - const versionIsSatisfied = satisfiesVersionRange( - currentVersion, - requiredVersionRange, - ) - - if (!versionIsSatisfied) { - log.warning( - `'serverless-offline' requires 'serverless' version '${requiredVersionRange}' but found version '${currentVersion}'. - Be aware that functionality might be limited or contains bugs. - To avoid any issues update 'serverless' to a later version. - `, - ) - } - } } diff --git a/src/utils/__tests__/satisfiesVersionRange.test.js b/src/utils/__tests__/satisfiesVersionRange.test.js deleted file mode 100644 index 43c307fe6..000000000 --- a/src/utils/__tests__/satisfiesVersionRange.test.js +++ /dev/null @@ -1,55 +0,0 @@ -import assert from 'node:assert' -import satisfiesVersionRange from '../satisfiesVersionRange.js' - -describe('satisfiesVersionRange', () => { - const tests = [ - { - description: 'same as minimum', - expected: true, - range: '>=1.38', - version: '1.38.0', - }, - { - description: 'greather than minimum', - expected: true, - range: '>=1.38', - version: '1.40.0', - }, - { - description: 'less than minimum', - expected: false, - range: '>=1.38', - version: '1.37.11', - }, - ] - - tests.forEach(({ description, expected, range, version }) => { - it(description, () => { - const result = satisfiesVersionRange(version, range) - assert.strictEqual(result, expected) - }) - }) -}) - -describe('should throw when invalid parameters are passed', () => { - const tests = [ - { - description: 'invalid version', - message: 'Not a valid semver range: a.b.c', - range: '>=1.40', - version: 'a.b.c', - }, - { - description: 'invalid range', - message: 'Not a valid semver version: a.b.c', - range: 'a.b.c', - version: '1.40.0', - }, - ] - - tests.forEach(({ description, message, range, version }) => { - it(description, () => { - assert.throws(() => satisfiesVersionRange(version, range), message) - }) - }) -}) diff --git a/src/utils/index.js b/src/utils/index.js index c70d418a6..82f35b51c 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -9,7 +9,6 @@ export { default as parseHeaders } from './parseHeaders.js' export { default as parseMultiValueHeaders } from './parseMultiValueHeaders.js' export { default as parseMultiValueQueryStringParameters } from './parseMultiValueQueryStringParameters.js' export { default as parseQueryStringParameters } from './parseQueryStringParameters.js' -export { default as satisfiesVersionRange } from './satisfiesVersionRange.js' export { default as splitHandlerPathAndName } from './splitHandlerPathAndName.js' export { default as checkDockerDaemon } from './checkDockerDaemon.js' export { default as checkGoVersion } from './checkGoVersion.js' diff --git a/src/utils/satisfiesVersionRange.js b/src/utils/satisfiesVersionRange.js deleted file mode 100644 index 9fce96ec7..000000000 --- a/src/utils/satisfiesVersionRange.js +++ /dev/null @@ -1,13 +0,0 @@ -import semver from 'semver' - -export default function satisfiesVersionRange(version, range) { - if (semver.valid(version) == null) { - throw new Error(`Not a valid semver version: ${version}`) - } - - if (semver.validRange(range) == null) { - throw new Error(`Not a valid semver range: ${range}`) - } - - return semver.satisfies(version, range) -}