Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #836 from anselm94/feat/adapt-compare-versions
Browse files Browse the repository at this point in the history
[Fix] Replace `semver` (uses node builtin libs) with `compare-versions` (pure javascript)
  • Loading branch information
mkevinosullivan authored Apr 25, 2023
2 parents 06616c4 + a5ea1cf commit 332b2fb
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-gorillas-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/shopify-api': patch
---

Replace `semver` with `compare-versions` lib to reduce dependency on nodejs builtin-libs
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {Config} from 'jest';
import semver from 'semver';
import {compare} from 'compare-versions';

const projects = [
'./lib/__tests__/jest_projects/library.jest.config.ts',
Expand All @@ -11,7 +11,7 @@ const projects = [

// eslint-disable-next-line no-warning-comments
// TODO Make all projects permanent after support for version 14 is dropped
if (semver.gte(process.version, '15.0.0')) {
if (compare(process.version, '15.0.0', '>=')) {
projects.push(
'./lib/__tests__/jest_projects/adapters.cf-worker.jest.config.ts',
);
Expand Down
4 changes: 2 additions & 2 deletions lib/__tests__/test-helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as jose from 'jose';
import semver from 'semver';
import {compare} from 'compare-versions';

import {shopifyApi, Shopify} from '..';
import {LATEST_API_VERSION, LogSeverity} from '../types';
Expand Down Expand Up @@ -165,7 +165,7 @@ export function testIfLibraryVersionIsAtLeast(
testFn: jest.ProvidesCallback,
) {
describe(`when library version is at least ${version}`, () => {
if (semver.gte(SHOPIFY_API_LIBRARY_VERSION, version)) {
if (compare(SHOPIFY_API_LIBRARY_VERSION, version, '>=')) {
test(testName, testFn);
} else {
test.skip(`- '${testName}' requires library version ${version} or higher`, () => {});
Expand Down
4 changes: 2 additions & 2 deletions lib/logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import semver from 'semver';
import {compare} from 'compare-versions';

import {LogSeverity} from '../types';
import {ConfigInterface} from '../base-types';
Expand Down Expand Up @@ -29,7 +29,7 @@ export type ShopifyLogger = ReturnType<typeof logger>;

function deprecated(logFunction: LoggerFunction) {
return function (version: string, message: string): void {
if (semver.gte(SHOPIFY_API_LIBRARY_VERSION, version)) {
if (compare(SHOPIFY_API_LIBRARY_VERSION, version, '>=')) {
throw new FeatureDeprecatedError(
`Feature was deprecated in version ${version}`,
);
Expand Down
4 changes: 2 additions & 2 deletions lib/setup-jest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import semver from 'semver';
import {compare} from 'compare-versions';

import '../adapters/mock';
import {mockTestRequests} from '../adapters/mock/mock_test_requests';
Expand Down Expand Up @@ -131,7 +131,7 @@ expect.extend({
return {
message: () =>
`Found deprecation limited to version ${version}, please update or remove it.`,
pass: semver.lt(SHOPIFY_API_LIBRARY_VERSION, version),
pass: compare(SHOPIFY_API_LIBRARY_VERSION, version, '<'),
};
},
});
4 changes: 2 additions & 2 deletions lib/utils/versioned-codeblocks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import semver from 'semver';
import {compare} from 'compare-versions';

import {SHOPIFY_API_LIBRARY_VERSION} from '../version';

export function enableCodeAfterVersion(version: string, fn: () => void): void {
if (semver.gte(SHOPIFY_API_LIBRARY_VERSION, version)) {
if (compare(SHOPIFY_API_LIBRARY_VERSION, version, '>=')) {
fn();
}
}
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@
},
"dependencies": {
"@shopify/network": "^3.2.1",
"@types/node-fetch": "^2.5.7",
"@types/supertest": "^2.0.10",
"compare-versions": "^5.0.3",
"jose": "^4.9.1",
"node-fetch": "^2.6.1",
"semver": "^7.3.8",
"tslib": "^2.0.3",
"uuid": "^9.0.0"
},
Expand All @@ -94,7 +92,8 @@
"@types/express": "^4.17.13",
"@types/jest": "^29.5.0",
"@types/node": "^14.18.12",
"@types/semver": "^7.3.12",
"@types/node-fetch": "^2.5.7",
"@types/supertest": "^2.0.10",
"@types/uuid": "^9.0.0",
"eslint": "^7.30.0",
"express": "^4.17.13",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1799,11 +1799,6 @@
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-6.2.3.tgz#5798ecf1bec94eaa64db39ee52808ec0693315aa"
integrity sha512-KQf+QAMWKMrtBMsB8/24w53tEsxllMj6TuA80TT/5igJalLI/zm0L3oXRbIAl4Ohfc85gyHX/jhMwsVkmhLU4A==

"@types/semver@^7.3.12":
version "7.3.13"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.13.tgz#da4bfd73f49bd541d28920ab0e2bf0ee80f71c91"
integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==

"@types/serve-static@*":
version "1.15.0"
resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.15.0.tgz#c7930ff61afb334e121a9da780aac0d9b8f34155"
Expand Down Expand Up @@ -2531,6 +2526,11 @@ commondir@^1.0.1:
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
integrity sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==

compare-versions@^5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-5.0.3.tgz#a9b34fea217472650ef4a2651d905f42c28ebfd7"
integrity sha512-4UZlZP8Z99MGEY+Ovg/uJxJuvoXuN4M6B3hKaiackiHrgzQFEe3diJi1mf1PNHbFujM7FvLrK2bpgIaImbtZ1A==

component-emitter@^1.3.0:
version "1.3.0"
resolved "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz"
Expand Down

0 comments on commit 332b2fb

Please sign in to comment.