From 941396cbe6f749dcaf06f6f34eaf949b001703cc Mon Sep 17 00:00:00 2001 From: Volodymyr Agafonkin Date: Wed, 26 Jun 2024 17:09:42 +0300 Subject: [PATCH] Switch to ESM entry point, modernize dependencies for v4 (#51) * switch to ESM entry point, modernize deps * remove leftover deps --- .gitignore | 2 +- cheap-ruler.d.ts => index.d.ts | 0 index.js | 1 - package.json | 47 +++++++++++++++------------------- rollup.config.js | 18 ------------- test/test.js | 4 ++- test/types.ts | 2 +- tsconfig.json | 17 ++++-------- 8 files changed, 31 insertions(+), 60 deletions(-) rename cheap-ruler.d.ts => index.d.ts (100%) delete mode 100644 rollup.config.js diff --git a/.gitignore b/.gitignore index e3d91c8..d5285ef 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ coverage .nyc_output *.log cheap-ruler.js -cheap-ruler.min.js test/types.js +pnpm-lock.yaml diff --git a/cheap-ruler.d.ts b/index.d.ts similarity index 100% rename from cheap-ruler.d.ts rename to index.d.ts diff --git a/index.js b/index.js index 0244528..43ab311 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,3 @@ -'use strict'; /* @flow */ const factors = { kilometers: 1, diff --git a/package.json b/package.json index ca6c97a..dca024f 100644 --- a/package.json +++ b/package.json @@ -2,35 +2,33 @@ "name": "cheap-ruler", "version": "3.0.2", "description": "A collection of fast approximations to common geographic measurements.", + "author": "Vladimir Agafonkin", + "license": "ISC", + "type": "module", "main": "cheap-ruler.js", "module": "index.js", - "jsdelivr": "cheap-ruler.min.js", - "unpkg": "cheap-ruler.min.js", "types": "cheap-ruler.d.ts", - "dependencies": {}, "devDependencies": { - "@rollup/plugin-buble": "^0.21.3", "@turf/turf": "^6.5.0", + "@types/node": "^17.0.23", "benchmark": "^2.1.4", - "eslint": "^8.2.0", + "c8": "^7.11.0", + "eslint": "^8.12.0", "eslint-config-mourner": "^3.0.0", - "esm": "^3.2.25", "node-vincenty": "0.0.6", - "nyc": "^15.1.0", - "rollup": "^2.60.0", - "rollup-plugin-terser": "^7.0.2", - "tape": "^5.3.2", - "ts-node": "^10.4.0", - "typescript": "^4.4.4" + "rollup": "^2.70.1", + "tape": "^5.5.2", + "ts-node": "^10.7.0", + "typescript": "^4.6.3" }, "scripts": { "pretest": "eslint index.js bench test/*.js", - "test": "tape -r esm test/test.js", - "posttest": "npm run build && npm run types", - "types": "ts-node test/types.ts", - "build": "rollup -c", - "prepublishOnly": "npm test", - "cov": "nyc tape test/test.js" + "test": "tape test/test.js", + "posttest": "npm run types", + "types": "ts-node --esm test/types.ts", + "build": "rollup index.js -o cheap-ruler.js -n CheapRuler -f umd", + "prepublishOnly": "npm test && npm run build", + "cov": "c8 tape test/test.js" }, "files": [ "index.js", @@ -39,7 +37,10 @@ "cheap-ruler.d.ts" ], "eslintConfig": { - "extends": "mourner" + "extends": "mourner", + "parserOptions": { + "ecmaVersion": 2020 + } }, "repository": { "type": "git", @@ -50,11 +51,5 @@ "measurement", "approximation", "distance" - ], - "author": "Vladimir Agafonkin", - "license": "ISC", - "bugs": { - "url": "https://github.com/mapbox/cheap-ruler/issues" - }, - "homepage": "https://github.com/mapbox/cheap-ruler#readme" + ] } diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index 8095492..0000000 --- a/rollup.config.js +++ /dev/null @@ -1,18 +0,0 @@ -import buble from '@rollup/plugin-buble'; -import {terser} from 'rollup-plugin-terser' - -const output = (file, plugins) => ({ - input: 'index.js', - output: { - name: 'CheapRuler', - format: 'umd', - indent: false, - file - }, - plugins -}); - -export default [ - output('cheap-ruler.js', [buble()]), - output('cheap-ruler.min.js', [terser(), buble()]) -]; diff --git a/test/test.js b/test/test.js index 56ce812..8324cd2 100644 --- a/test/test.js +++ b/test/test.js @@ -1,7 +1,9 @@ import {test} from 'tape'; import CheapRuler from '../index.js'; import * as turf from '@turf/turf'; -import lines from './fixtures/lines.json'; +import {readFileSync} from 'fs'; + +const lines = JSON.parse(readFileSync(new URL('fixtures/lines.json', import.meta.url))); const points = Array.prototype.concat.apply([], lines); diff --git a/test/types.ts b/test/types.ts index c8c3b37..25813a0 100644 --- a/test/types.ts +++ b/test/types.ts @@ -1,4 +1,4 @@ -import CheapRuler, { Point, Line, Polygon } from '../cheap-ruler.js' +import CheapRuler, { Point, Line, Polygon } from '../index.js' /** * Declare variables diff --git a/tsconfig.json b/tsconfig.json index a8d1af9..ce7ec03 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,9 @@ { "compilerOptions": { - /* Basic Options */ - "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - - /* Strict Type-Checking Options */ - "strict": true, /* Enable all strict type-checking options. */ - - /* Module Resolution Options */ - "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - - /* Advanced Options */ - "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + "target": "es5", + "module": "es6", + "strict": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true } }