Skip to content

Commit

Permalink
chore: modernize repo (#42)
Browse files Browse the repository at this point in the history
* chore: use peggy

* chore: swap TSLint with ESLint

* chore: address lint-staged warning

* chore: upgrade Jest & TypeScript

* build: set-up dual-packaging

BREAKING CHANGE: dropped support for Node <12

* chore: drop @stoplight/scripts

* chore: remove CodeClimate

* chore: do not use deprecated CircleCI images

* fix: swich module to commonjs for increased compatibility

* chore: broken lint.fix package.json script
  • Loading branch information
P0lip committed Feb 1, 2023
1 parent 3b5dc04 commit 4f1fa64
Show file tree
Hide file tree
Showing 38 changed files with 4,613 additions and 5,288 deletions.
19 changes: 3 additions & 16 deletions .circleci/config.yml
Expand Up @@ -3,37 +3,24 @@ version: 2
jobs:
test:
docker:
- image: circleci/node:8
- image: cimg/node:lts
steps:
- checkout
- run:
name: Download cc-test-reporter
command: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
- run: yarn
- run:
name: cc-before
command: |
./cc-test-reporter before-build
- run: yarn build
- run: yarn test.prod
- run:
name: cc-after
command: |
./cc-test-reporter after-build --coverage-input-type lcov --exit-code $?

build:
docker:
- image: circleci/node:8
- image: cimg/node:lts
steps:
- checkout
- run: yarn
- run: yarn build

release:
docker:
- image: circleci/node:8
- image: cimg/node:lts
steps:
- checkout
- run: yarn
Expand Down
32 changes: 0 additions & 32 deletions .codeclimate.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .eslintrc.cjs
@@ -0,0 +1,22 @@
module.exports = {
parser: '@typescript-eslint/parser',

extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],

plugins: ['jest', '@typescript-eslint'],

parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},

env: {
es6: true,
},

rules: {
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/consistent-test-it': 'error',
},
};
3 changes: 0 additions & 3 deletions jest.config.js

This file was deleted.

12 changes: 12 additions & 0 deletions jest.config.mjs
@@ -0,0 +1,12 @@
export default {
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.[tj]s$': [
'ts-jest',
],
},
testMatch: ['<rootDir>/src/**/__tests__/*.spec.ts'],
collectCoverageFrom: ['src/**/*.ts'],
};
76 changes: 47 additions & 29 deletions package.json
Expand Up @@ -12,51 +12,71 @@
"url": "https://github.com/stoplightio/path"
},
"license": "Apache-2.0",
"main": "src/index.ts",
"type": "commonjs",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
},
"files": [
"**/*"
"src",
"dist"
],
"engines": {
"node": ">=8"
"node": "^12.20 || >=14.13"
},
"scripts": {
"build": "yarn build.grammar && sl-scripts build",
"build.grammar": "pegjs --optimize speed src/grammar.pegjs",
"build": "rimraf dist && yarn build.grammar && yarn build.cjs && yarn build.esm",
"build.esm": "tsc -p tsconfig.build.json --outDir dist/esm --declarationDir dist/types",
"build.cjs": "tsc -p tsconfig.build.json --outDir dist/cjs --module commonjs --declarationDir dist/types",
"build.grammar": "peggy --format=es src/grammar.pegjs",
"commit": "git-cz",
"lint": "tslint -c tslint.json 'src/**/*.ts?'",
"lint.fix": "yarn lint --fix",
"release": "sl-scripts release",
"release.docs": "sl-scripts release:docs",
"release.dryRun": "sl-scripts release --dry-run --debug",
"lint": "eslint 'src/**/*.ts' && prettier --check 'src/**/*.ts'",
"lint.fix": "eslint 'src/**/*.ts' --fix && prettier --write 'src/**/*.ts'",
"release": "semantic-release",
"pretest": "yarn build.grammar",
"test": "jest",
"test.prod": "yarn lint && yarn test --coverage --maxWorkers=2",
"test.update": "yarn test --updateSnapshot",
"test.watch": "yarn test --watch",
"yalc": "yarn build && (cd dist && yalc push)",
"yalc": "yarn build && yalc push",
"yalc.watch": "nodemon --watch 'src/**/*' --exec 'yarn yalc'"
},
"peerDependencies": {},
"dependencies": {},
"devDependencies": {
"@stoplight/scripts": "7.0.0",
"@types/jest": "24.x.x",
"jest": "24.x.x",
"@commitlint/cli": "^17.4.2",
"@commitlint/config-conventional": "^17.4.2",
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.7",
"@semantic-release/npm": "^9.0.2",
"@semantic-release/release-notes-generator": "^10.0.3",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^4.3.8",
"jest": "^29.4.1",
"lint-staged": "^13.1.0",
"nodemon": "1.x.x",
"pegjs": "^0.10.0",
"prettier": "1.x.x",
"rollup-plugin-commonjs": "^10.0.1",
"ts-jest": "24.x.x",
"tslint": "5.17.0",
"tslint-config-prettier": "1.18.x",
"tslint-config-stoplight": "1.3.0",
"tslint-plugin-prettier": "2.0.x",
"typescript": "3.5.2"
"peggy": "^2.0.1",
"prettier": "^2.8.3",
"rimraf": "^4.1.2",
"semantic-release": "^19.0.5",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5"
},
"lint-staged": {
"*.{ts,tsx}$": [
"yarn lint.fix",
"git add"
"yarn lint.fix"
]
},
"husky": {
Expand All @@ -76,11 +96,9 @@
]
},
"prettier": {
"arrowParens": "avoid",
"printWidth": 120,
"singleQuote": true,
"trailingComma": "all"
},
"release": {
"extends": "@stoplight/scripts/release"
}
}
8 changes: 0 additions & 8 deletions rollup.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/__tests__/basename.spec.ts
@@ -1,4 +1,4 @@
import { basename } from '../basename';
import { basename } from '../basename.js';

describe('posix basename', () => {
it.each`
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/dirname.spec.ts
@@ -1,4 +1,4 @@
import { dirname } from '../dirname';
import { dirname } from '../dirname.js';

describe('posix dirname', () => {
it.each`
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/extname.spec.ts
@@ -1,4 +1,4 @@
import { extname } from '../extname';
import { extname } from '../extname.js';

describe('extname', () => {
it.each`
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/isAbsolute.spec.ts
@@ -1,4 +1,4 @@
import { isAbsolute } from '../isAbsolute';
import { isAbsolute } from '../isAbsolute.js';

describe('isAbsolute', () => {
it.each([
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/join.spec.ts
@@ -1,4 +1,4 @@
import { join } from '../';
import { join } from '../join.js';

describe('join', () => {
it('does some basic resolving', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/normalize.spec.ts
@@ -1,4 +1,4 @@
import { normalize } from '../';
import { normalize } from '../normalize.js';

describe('normalize', () => {
describe('replaces Windows-like slashes with POSIX-compatible ones', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/relative.spec.ts
@@ -1,4 +1,4 @@
import { relative } from '../relative';
import { relative } from '../relative.js';

describe('relative', () => {
describe('handles POSIX paths', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/resolve.spec.ts
@@ -1,4 +1,4 @@
import { resolve } from '../resolve';
import { resolve } from '../resolve.js';

describe('resolve', () => {
describe('handles POSIX paths', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/srn.spec.ts
@@ -1,4 +1,4 @@
import { deserializeSrn, serializeSrn } from '../srn';
import { deserializeSrn, serializeSrn } from '../srn.js';

describe('deserializeSrn', () => {
it('should work deserialize org srn', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/startsWithWindowsDrive.spec.ts
@@ -1,4 +1,4 @@
import { startsWithWindowsDrive } from '../';
import { startsWithWindowsDrive } from '../startsWithWindowsDrive.js';

describe('startsWithWindowsDrive', () => {
it.each(['c:\\foo\\bar.json', 'c:\\', 'c:/', 'c:/', '/C:/', '/C:\\', 'c:/foo/bar.json', 'c:\\', 'Z:\\', 'A:/'])(
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/stripRoot.spec.ts
@@ -1,7 +1,7 @@
import { stripRoot } from '../stripRoot';
import { stripRoot } from '../stripRoot.js';

describe('stripRoot', () => {
it.each(['foo', 'test/a', 'a/b'])('does not alter "%s" path', (path) => {
it.each(['foo', 'test/a', 'a/b'])('does not alter "%s" path', path => {
expect(stripRoot(path)).toEqual(path);
});

Expand Down
6 changes: 3 additions & 3 deletions src/basename.ts
@@ -1,6 +1,6 @@
import { normalizeParsed } from './normalize';
import { parse } from './parse';
import { parseBase } from './parseBase';
import { normalizeParsed } from './normalize.js';
import { parse } from './parse.js';
import { parseBase } from './parseBase.js';

export const basename = (path: string, removeExtension?: string | boolean) => {
const parsed = normalizeParsed(parse(path));
Expand Down
6 changes: 3 additions & 3 deletions src/dirname.ts
@@ -1,6 +1,6 @@
import { format } from './format';
import { normalizeParsed } from './normalize';
import { parse } from './parse';
import { format } from './format.js';
import { normalizeParsed } from './normalize.js';
import { parse } from './parse.js';

export const dirname = (path: string) => {
const parsed = normalizeParsed(parse(path));
Expand Down
6 changes: 3 additions & 3 deletions src/extname.ts
@@ -1,6 +1,6 @@
import { normalizeParsed } from './normalize';
import { parse } from './parse';
import { parseBase } from './parseBase';
import { normalizeParsed } from './normalize.js';
import { parse } from './parse.js';
import { parseBase } from './parseBase.js';

export const extname = (path: string) => {
const parsed = normalizeParsed(parse(path));
Expand Down
2 changes: 1 addition & 1 deletion src/format.ts
@@ -1,4 +1,4 @@
import { IPath } from './types';
import { IPath } from './types.js';

export function format(parsed: IPath): string {
let path = '';
Expand Down
34 changes: 17 additions & 17 deletions src/index.ts
@@ -1,17 +1,17 @@
export * from './basename';
export * from './dirname';
export * from './extname';
export * from './format';
export * from './isAbsolute';
export * from './isURL';
export * from './join';
export { normalize } from './normalize';
export { parse } from './parse';
export * from './relative';
export * from './resolve';
export * from './sep';
export * from './startsWithWindowsDrive';
export * from './stripRoot';
export * from './toFSPath';
export * from './types';
export * from './srn';
export * from './basename.js';
export * from './dirname.js';
export * from './extname.js';
export * from './format.js';
export * from './isAbsolute.js';
export * from './isURL.js';
export * from './join.js';
export { normalize } from './normalize.js';
export { parse } from './parse.js';
export * from './relative.js';
export * from './resolve.js';
export * from './sep.js';
export * from './startsWithWindowsDrive.js';
export * from './stripRoot.js';
export * from './toFSPath.js';
export * from './types.js';
export * from './srn.js';
2 changes: 1 addition & 1 deletion src/isAbsolute.ts
@@ -1,4 +1,4 @@
import { parse } from './parse';
import { parse } from './parse.js';

export function isAbsolute(filepath: string) {
const parsed = parse(filepath);
Expand Down
2 changes: 1 addition & 1 deletion src/isURL.ts
@@ -1,4 +1,4 @@
import { parse } from './parse';
import { parse } from './parse.js';

export function isURL(filepath: string) {
const parsed = parse(filepath);
Expand Down
8 changes: 4 additions & 4 deletions src/join.ts
@@ -1,7 +1,7 @@
import { format } from './format';
import { normalizeParsed } from './normalize';
import { parse } from './parse';
import { IPath } from './types';
import { format } from './format.js';
import { normalizeParsed } from './normalize.js';
import { parse } from './parse.js';
import { IPath } from './types.js';

export const join = (...parts: string[]) => {
// edge case
Expand Down

0 comments on commit 4f1fa64

Please sign in to comment.