Skip to content

Commit

Permalink
Merge pull request #1313 from remotestorage/chore/node-20
Browse files Browse the repository at this point in the history
Support node.js 18, 20
  • Loading branch information
raucao authored Jun 17, 2024
2 parents 1e0cccc + 9b12647 commit 9999f23
Show file tree
Hide file tree
Showing 12 changed files with 981 additions and 6,682 deletions.
1 change: 0 additions & 1 deletion .browserslistrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

cover 99.5%
ie >= 11
maintained node versions
not dead
6 changes: 3 additions & 3 deletions .github/workflows/test-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
strategy:
matrix:
# Support LTS versions based on https://nodejs.org/en/about/releases/
node-version: ['14', '16']
node-version: ['18', '20']
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
7,190 changes: 821 additions & 6,369 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@
"ts-node": "^10.9.1",
"typedoc": "^0.19.2",
"typescript": "^4.8.3",
"webpack": "^4.46.0",
"webpack-cli": "^4.10.0"
"webpack": "^5.92.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@types/node": "16.11.59",
"@types/node": "20.14.0",
"@types/tv4": "^1.2.29",
"esm": "^3.2.25",
"tv4": "^1.3.0",
Expand Down
8 changes: 4 additions & 4 deletions src/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import log from './log';
import { globalContext, localStorageAvailable } from './util';

// feature detection flags
let haveXMLHttpRequest, hasLocalStorage;
let hasLocalStorage;

// used to store settings in localStorage
const SETTINGS_KEY = 'remotestorage:discover';
Expand Down Expand Up @@ -66,7 +66,7 @@ const Discover = function Discover(userAddress: string): Promise<StorageInfo> {
};

if (hasLocalStorage) {
localStorage[SETTINGS_KEY] = JSON.stringify({ cache: cachedInfo });
localStorage.setItem(SETTINGS_KEY, JSON.stringify({ cache: cachedInfo }));
}

return resolve(cachedInfo[userAddress]);
Expand Down Expand Up @@ -95,8 +95,8 @@ Discover._rs_init = function (/*remoteStorage*/): void {
};

Discover._rs_supported = function (): boolean {
haveXMLHttpRequest = Object.prototype.hasOwnProperty.call(globalContext, 'XMLHttpRequest');
return haveXMLHttpRequest;
return Object.prototype.hasOwnProperty.call(globalContext, 'fetch') ||
Object.prototype.hasOwnProperty.call(globalContext, 'XMLHttpRequest');
};

Discover._rs_cleanup = function (): void {
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export const shouldBeTreatedAsBinary = (content: string | ArrayBuffer, mimeType:
*/
export const getTextFromArrayBuffer = (arrayBuffer: ArrayBuffer, encoding): Promise<string | ArrayBuffer> => {
return new Promise((resolve/*, reject*/) => {
if (typeof Blob === 'undefined') {
if (typeof Blob === 'undefined' || typeof FileReader === 'undefined') {
const buffer = Buffer.from(arrayBuffer);
resolve(buffer.toString(encoding));
} else {
Expand Down
7 changes: 3 additions & 4 deletions test/helpers/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ class MockLocation {
}
}


export default function locationFactory(url) {
if (!('document' in global)) {
global["document"] = {} as Document;
if (!('document' in globalThis)) {
globalThis["document"] = {} as Document;
}
global.document.location = new MockLocation(url) as unknown as Location;
globalThis.document.location = new MockLocation(url) as unknown as Location;
}
6 changes: 3 additions & 3 deletions test/unit/authorize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class MockRemote extends RemoteBase implements Remote {
}

locationFactory('https://foo/bar');
global.localStorageAvailable = localStorageAvailable;
global["sessionStorage"] = sessionStorage;
globalThis.localStorageAvailable = localStorageAvailable;
globalThis["sessionStorage"] = sessionStorage;

describe("authorization", () => {
const sandbox = sinon.createSandbox();
Expand All @@ -54,7 +54,7 @@ describe("authorization", () => {
sessionStorage.removeItem('remotestorage:codeVerifier');
sessionStorage.removeItem('remotestorage:state');

global.document.location.href = 'https://foo/bar';
globalThis.document.location.href = 'https://foo/bar';
});

afterEach(() => {
Expand Down
Loading

0 comments on commit 9999f23

Please sign in to comment.