diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab7e849c..afa6d23f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,6 @@ jobs: rm example.js - name: Verify TypeScript can consume the package run: | - echo "import osrmTextInstructions = require('./index'); const compiler = osrmTextInstructions('v5'); console.log('TypeScript import works!');" > test-import.ts + echo "import osrmTextInstructions from './index'; const compiler = osrmTextInstructions('v5'); console.log('TypeScript import works!');" > test-import.ts npx tsc --noEmit test-import.ts - rm test-import.ts \ No newline at end of file + rm test-import.ts diff --git a/.gitignore b/.gitignore index 5bf1e51f..c2f34d09 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules transifex.auth +dist +example.js diff --git a/README.md b/README.md index 13a94cca..c9a81364 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ response.legs.forEach(function(leg) { ### TypeScript Usage ```typescript -import osrmTextInstructions = require('osrm-text-instructions'); +import osrmTextInstructions from 'osrm-text-instructions'; const compiler = osrmTextInstructions('v5'); diff --git a/eslint.config.js b/eslint.config.js index 10a00f53..4a230f87 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -2,7 +2,7 @@ const js = require('@eslint/js'); module.exports = [ { - ignores: ['node_modules/**', 'eslint.config.js'], + ignores: ['node_modules/**', 'dist/**', 'example.js'] }, { files: ['**/*.js'], @@ -19,8 +19,8 @@ module.exports = [ global: 'readonly', module: 'writable', require: 'readonly', - fetch: 'readonly', - }, + fetch: 'readonly' + } }, rules: { ...js.configs.recommended.rules, @@ -32,12 +32,17 @@ module.exports = [ 'arrow-spacing': 'error', 'block-scoped-var': 'error', 'block-spacing': ['error', 'always'], - 'brace-style': ['error', '1tbs', {allowSingleLine: true}], + 'brace-style': ['error', '1tbs', { + allowSingleLine: true + }], 'callback-return': 'error', camelcase: 'error', 'class-methods-use-this': 'error', 'comma-dangle': 'error', - 'comma-spacing': ['error', {after: true, before: false}], + 'comma-spacing': ['error', { + after: true, + before: false + }], 'comma-style': 'error', complexity: 'off', 'computed-property-spacing': ['error', 'never'], @@ -60,7 +65,10 @@ module.exports = [ 'init-declarations': 'off', 'jsx-quotes': 'error', 'key-spacing': 'error', - 'keyword-spacing': ['error', {after: true, before: true}], + 'keyword-spacing': ['error', { + after: true, + before: true + }], 'linebreak-style': ['error', 'unix'], 'lines-around-comment': 'error', 'max-depth': 'error', diff --git a/example.ts b/example.ts index fb702884..5a3e146e 100644 --- a/example.ts +++ b/example.ts @@ -1,6 +1,6 @@ // Example usage of osrm-text-instructions with TypeScript -import osrmTextInstructions = require('./index'); +import osrmTextInstructions from './index.js'; // Initialize the compiler for OSRM v5 const compiler = osrmTextInstructions('v5'); diff --git a/package-lock.json b/package-lock.json index f89366f9..27e66bda 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "eslint": "^10.2.0", "mkdirp": "^3.0.1", "tape": "^5.9.0", - "typescript": "^5.0.0" + "typescript": "^6.0.3" } }, "node_modules/@eslint-community/eslint-utils": { @@ -2849,9 +2849,9 @@ } }, "node_modules/typescript": { - "version": "5.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", - "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/package.json b/package.json index a5c919c7..2e3d0d6a 100644 --- a/package.json +++ b/package.json @@ -21,14 +21,14 @@ "eslint": "^10.2.0", "mkdirp": "^3.0.1", "tape": "^5.9.0", - "typescript": "^5.0.0" + "typescript": "^6.0.3" }, "scripts": { - "lint": "eslint *.js test/*.js scripts/*.js", + "lint": "eslint eslint.config.js index.js languages.js test/*.js scripts/*.js", "pretest": "npm run lint", "test": "tape test/*_test.js", "transifex": "node scripts/transifex.js", - "type-check": "tsc --noEmit example.ts", - "validate-types": "tsc --noEmit index.d.ts" + "type-check": "tsc --noEmit --project tsconfig.example.json", + "validate-types": "tsc --noEmit --project tsconfig.types.json" } } diff --git a/tsconfig.json b/tsconfig.base.json similarity index 77% rename from tsconfig.json rename to tsconfig.base.json index b6344a72..78187c16 100644 --- a/tsconfig.json +++ b/tsconfig.base.json @@ -12,19 +12,10 @@ "strictFunctionTypes": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, - "moduleResolution": "node", + "moduleResolution": "bundler", "allowSyntheticDefaultImports": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true - }, - "include": [ - "*.ts", - "*.d.ts" - ], - "exclude": [ - "node_modules", - "dist", - "test" - ] -} \ No newline at end of file + } +} diff --git a/tsconfig.example.json b/tsconfig.example.json new file mode 100644 index 00000000..263913df --- /dev/null +++ b/tsconfig.example.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.base.json", + "files": [ + "example.ts" + ] +} diff --git a/tsconfig.types.json b/tsconfig.types.json new file mode 100644 index 00000000..591a02c3 --- /dev/null +++ b/tsconfig.types.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.base.json", + "files": [ + "index.d.ts" + ] +}