Skip to content

Commit

Permalink
chore: update required node version (#268)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drops `node@12`
  • Loading branch information
wtgtybhertgeghgtwtg authored Jun 1, 2022
1 parent f8038a7 commit 3eb32ff
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 43 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
jobs:
lint:
docker:
- image: circleci/node:12
- image: circleci/node:14
steps:
- checkout
- restore_cache:
Expand All @@ -18,7 +18,7 @@ jobs:

release:
docker:
- image: circleci/node:12
- image: circleci/node:14
steps:
- checkout
- restore_cache:
Expand All @@ -31,11 +31,11 @@ jobs:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run: yarn build
- run: npx semantic-release@17
- run: npx semantic-release

test:
docker:
- image: circleci/node:12
- image: circleci/node:14
steps:
- checkout
- restore_cache:
Expand All @@ -52,7 +52,7 @@ jobs:

test-distribution:
docker:
- image: circleci/node:12
- image: circleci/node:14
steps:
- checkout
- restore_cache:
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
},
},
{
files: ['__mocks__/*.ts', 'scripts/jest/*.js', '.eslintrc.js'],
files: ['__mocks__/**/*.ts', 'scripts/jest/*.js', '.eslintrc.js'],
rules: {
// Mocks and some configuration files cannot be modules.
'unicorn/prefer-module': 'off',
Expand Down
20 changes: 0 additions & 20 deletions __mocks__/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@ function _setFiles(newFiles: {[path: string]: Buffer}): void {
files = mapToMap(newFiles);
}

const readFile = jest.fn(
(
path: string,
encoding: BufferEncoding,
// eslint-disable-next-line @rushstack/no-new-null
callback: (error: Error | null, value?: string) => void,
) => {
const file = files.get(path);
if (file && Buffer.isBuffer(file)) {
const decodedFile = file.toString(encoding);
// eslint-disable-next-line unicorn/no-null
callback(null, decodedFile);
} else {
const error = new Error('File not found.');
callback(error);
}
},
);

const readFileSync = jest.fn((path: string, encoding: BufferEncoding) => {
const file = files.get(path);
if (file && Buffer.isBuffer(file)) {
Expand All @@ -35,6 +16,5 @@ const readFileSync = jest.fn((path: string, encoding: BufferEncoding) => {

module.exports = {
_setFiles,
readFile,
readFileSync,
};
20 changes: 20 additions & 0 deletions __mocks__/fs/promises.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import mapToMap from 'map-to-map';

let files: Map<string, Buffer> = new Map();

function _setFiles(newFiles: {[path: string]: Buffer}): void {
files = mapToMap(newFiles);
}

const readFile = jest.fn(async (path: string, encoding: BufferEncoding) => {
const file = files.get(path);
if (file && Buffer.isBuffer(file)) {
return file.toString(encoding);
}
throw new Error('File not found.');
});

module.exports = {
_setFiles,
readFile,
};
4 changes: 2 additions & 2 deletions __tests__/load-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jest.mock('fs');
jest.mock('fs/promises');

import fs from 'fs';
import fs from 'fs/promises';
import {ConfigError, loadConfig} from '../source';

describe('loadConfig', () => {
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
"@babel/core": "^7.15.0",
"@babel/preset-env": "^7.15.0",
"@babel/preset-typescript": "^7.15.0",
"@commitlint/cli": "^16.0.0",
"@commitlint/config-conventional": "^16.0.0",
"@commitlint/cli": "^17.0.1",
"@commitlint/config-conventional": "^17.0.0",
"@rushstack/eslint-config": "^2.5.0",
"@types/jest": "^27.4.1",
"@types/node": "^16.6.1",
"babel-jest": "^28.0.2",
"builtin-modules": "^3.2.0",
"eslint": "^8.4.1",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-unicorn": "^42.0.0",
Expand All @@ -25,11 +24,11 @@
"prettier": "2.6.2",
"rimraf": "^3.0.2",
"rollup": "^2.56.0",
"rollup-plugin-ts": "^2.0.0",
"typescript": "~4.6.0"
"rollup-plugin-ts": "^3.0.1",
"typescript": "~4.7.2"
},
"engines": {
"node": ">=12"
"node": ">=14"
},
"files": [
"distribution",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import builtinModules from 'builtin-modules';
import {builtinModules} from 'module';
import ts from 'rollup-plugin-ts';
import {fileURLToPath} from 'url';
import packageJson from './package.json';
Expand Down
22 changes: 14 additions & 8 deletions source/load-file-property.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import {readFile} from 'fs';
import {readFile} from 'fs/promises';
import formatProperty from './format-property';
import {FileConfig, PropertyResult} from './types';

export default function loadFileProperty<Value>(
async function tryToReadFile(
propertyConfig: FileConfig<unknown>,
): Promise<PropertyResult<string>> {
const {encoding = 'utf8', filePath} = propertyConfig;
try {
return {error: false, value: await readFile(filePath, encoding)};
} catch (error) {
return {error: error as Error, value: undefined};
}
}

export default async function loadFileProperty<Value>(
propertyConfig: FileConfig<Value>,
): Promise<PropertyResult<string | Value>> {
const {encoding = 'utf8', filePath} = propertyConfig;
return new Promise((resolve) => {
readFile(filePath, encoding, (error, value) => {
resolve(formatProperty({error: error ?? false, value}, propertyConfig));
});
});
return formatProperty(await tryToReadFile(propertyConfig), propertyConfig);
}

0 comments on commit 3eb32ff

Please sign in to comment.