From 6360c15b3bb2820f6ff0531e5496cb23568cf837 Mon Sep 17 00:00:00 2001 From: Julien Date: Fri, 23 Jun 2023 22:32:06 +0200 Subject: [PATCH] refactor: migrate to esm --- .github/workflows/test.yml | 45 +++---------- .gitignore | 1 + bin/japa_types.ts | 12 +--- bin/test.ts | 3 +- package.json | 127 +++++++++++++++++-------------------- tsconfig.json | 24 +------ 6 files changed, 76 insertions(+), 136 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1168ffb..7daa494 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,39 +1,14 @@ -name: test +name: checks on: - push - pull_request + jobs: - linux: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: - - 16.15.1 - - 18.x - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: Install - run: npm install - - name: Run tests - run: npm test - windows: - runs-on: windows-latest - strategy: - matrix: - node-version: - - 16.15.1 - - 18.x - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: Install - run: npm install - - name: Run tests - run: npm test + test: + uses: japa/.github/.github/workflows/test.yml@main + + lint: + uses: japa/.github/.github/workflows/lint.yml@main + + typecheck: + uses: japa/.github/.github/workflows/typecheck.yml@main diff --git a/.gitignore b/.gitignore index dd87e2d..1d2a37f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules build +coverage diff --git a/bin/japa_types.ts b/bin/japa_types.ts index 78cc527..98a696e 100644 --- a/bin/japa_types.ts +++ b/bin/japa_types.ts @@ -1,11 +1 @@ -import '@japa/runner' - -declare module '@japa/runner' { - interface TestContext { - // notify TypeScript about custom context properties - } - - interface Test { - // notify TypeScript about custom test properties - } -} +declare module '@japa/runner' {} diff --git a/bin/test.ts b/bin/test.ts index 30bf0cc..87610bd 100644 --- a/bin/test.ts +++ b/bin/test.ts @@ -2,6 +2,7 @@ import { assert } from '@japa/assert' import { specReporter } from '@japa/spec-reporter' import { runFailedTests } from '@japa/run-failed-tests' import { processCliArgs, configure, run } from '@japa/runner' +import { pathToFileURL } from 'node:url' /* |-------------------------------------------------------------------------- @@ -22,7 +23,7 @@ configure({ files: ['tests/**/*.spec.ts'], plugins: [assert(), runFailedTests()], reporters: [specReporter()], - importer: (filePath) => import(filePath), + importer: (filePath) => import(pathToFileURL(filePath).href), }, }) diff --git a/package.json b/package.json index 29f0ffb..ffe7436 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,23 @@ { "name": "@japa/expect-type", - "version": "1.0.3", "description": "Write assertions for TypeScript types", + "version": "1.0.3", "main": "./build/index.js", + "type": "module", "files": [ + "index.ts", + "src", + "build/src", + "build/index.d.ts", "build/index.js", - "build/index.d.ts" + "build/index.d.ts.map" ], "exports": { ".": "./build/index.js" }, - "type": "commonjs", "scripts": { - "pretest": "npm run lint", - "test": "node --require=@adonisjs/require-ts/build/register bin/test.ts", + "pretest": "npm run lint && npm run typecheck", + "test": "c8 npm run quick:test", "clean": "del-cli build", "compile": "npm run lint && npm run clean && tsc", "build": "npm run compile", @@ -21,92 +25,79 @@ "version": "npm run build", "prepublishOnly": "npm run build", "lint": "eslint . --ext=.ts", + "typecheck": "tsc --noEmit", "format": "prettier --write .", - "sync-labels": "github-label-sync --labels .github/labels.json japa/expect-type" - }, - "publishConfig": { - "access": "public", - "tag": "latest" + "quick:test": "node --loader ts-node/esm bin/test.ts", + "sync-labels": "github-label-sync --labels .github/labels.json japa/file-system" }, - "keywords": [], - "author": "virk,japa", - "license": "MIT", "devDependencies": { - "@adonisjs/require-ts": "^2.0.13", - "@commitlint/cli": "^17.4.2", - "@commitlint/config-conventional": "^17.4.2", - "@japa/assert": "^1.3.7", + "@adonisjs/eslint-config": "^1.1.5", + "@adonisjs/prettier-config": "^1.1.5", + "@adonisjs/tsconfig": "^1.1.5", + "@commitlint/cli": "^17.6.5", + "@commitlint/config-conventional": "^17.6.5", + "@japa/assert": "^1.4.1", "@japa/run-failed-tests": "^1.1.1", - "@japa/runner": "^2.2.3", - "@japa/spec-reporter": "^1.3.2", - "@types/node": "^18.13.0", + "@japa/runner": "^2.5.1", + "@japa/spec-reporter": "^1.3.3", + "@swc/core": "^1.3.66", + "@types/node": "^20.3.1", + "c8": "^8.0.0", "del-cli": "^5.0.0", - "eslint": "^8.33.0", - "eslint-config-prettier": "^8.6.0", - "eslint-plugin-adonis": "^3.0.3", - "eslint-plugin-prettier": "^4.0.0", - "github-label-sync": "^2.2.0", + "eslint": "^8.43.0", + "github-label-sync": "^2.3.1", "husky": "^8.0.3", - "np": "^7.6.3", - "prettier": "^2.8.3", - "typescript": "^4.9.5" + "np": "^8.0.4", + "prettier": "^2.8.8", + "ts-node": "^10.9.1", + "typescript": "^5.1.3" + }, + "dependencies": { + "expect-type": "^0.16.0" }, "peerDependencies": { "@japa/runner": "^2.2.3" }, - "dependencies": { - "expect-type": "^0.15.0" + "author": "virk,japa", + "license": "MIT", + "homepage": "https://github.com/japa/expect-type#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/japa/expect-type.git" }, - "eslintConfig": { - "extends": [ - "plugin:adonis/typescriptPackage", - "prettier" - ], - "plugins": [ - "prettier" - ], - "rules": { - "prettier/prettier": [ - "error", - { - "endOfLine": "auto" - } - ] - } + "bugs": { + "url": "https://github.com/japa/expect-type/issues" }, - "eslintIgnore": [ - "build" - ], - "prettier": { - "trailingComma": "es5", - "semi": false, - "singleQuote": true, - "useTabs": false, - "quoteProps": "consistent", - "bracketSpacing": true, - "arrowParens": "always", - "printWidth": 100 + "keywords": [], + "eslintConfig": { + "extends": "@adonisjs/eslint-config/package" }, + "prettier": "@adonisjs/prettier-config", "commitlint": { "extends": [ "@commitlint/config-conventional" ] }, + "publishConfig": { + "access": "public", + "tag": "next" + }, "np": { "message": "chore(release): %s", - "tag": "latest", + "tag": "next", "branch": "main", "anyBranch": false }, + "c8": { + "reporter": [ + "text", + "html" + ], + "exclude": [ + "tests/**" + ] + }, "directories": { "test": "tests" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/japa/expect-type.git" - }, - "bugs": { - "url": "https://github.com/japa/expect-type/issues" - }, - "homepage": "https://github.com/japa/expect-type#readme" + } } diff --git a/tsconfig.json b/tsconfig.json index 512efe7..ad0cc44 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,25 +1,7 @@ { + "extends": "@adonisjs/tsconfig/tsconfig.package.json", "compilerOptions": { - "target": "ES2022", - "module": "CommonJS", - "lib": ["ES2022"], - "noUnusedLocals": true, - "noUnusedParameters": true, - "isolatedModules": true, - "removeComments": true, - "declaration": true, "rootDir": "./", - "outDir": "./build", - "strictNullChecks": true, - "allowSyntheticDefaultImports": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "noImplicitAny": true, - "strictFunctionTypes": true, - "noImplicitThis": true, - "skipLibCheck": true, - "types": ["@types/node"] - }, - "include": ["./**/*"], - "exclude": ["./node_modules", "./build"] + "outDir": "./build" + } }