From b34c6b4969e411ac087f0805437c55ca1c5ce871 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Mon, 6 Nov 2023 14:38:01 +0530 Subject: [PATCH] refactor: bundle code using tsup and reformat internals --- index.ts | 12 +++++--- package.json | 29 ++++++++++++++------ src/{assert/main.ts => assert.ts} | 2 +- src/{types/main.ts => types.ts} | 0 src/types/extended.ts | 16 ----------- src/{assert => }/utils.ts | 0 {test => tests}/assert/assert.spec.ts | 4 +-- {test => tests}/assert/assert_subset.spec.ts | 4 +-- {test => tests}/assert/openapi.spec.ts | 4 +-- {test => tests}/plugin.spec.ts | 4 +-- {test_helpers => tests_helpers}/index.ts | 0 11 files changed, 37 insertions(+), 38 deletions(-) rename src/{assert/main.ts => assert.ts} (99%) rename src/{types/main.ts => types.ts} (100%) delete mode 100644 src/types/extended.ts rename src/{assert => }/utils.ts (100%) rename {test => tests}/assert/assert.spec.ts (99%) rename {test => tests}/assert/assert_subset.spec.ts (98%) rename {test => tests}/assert/openapi.spec.ts (95%) rename {test => tests}/plugin.spec.ts (97%) rename {test_helpers => tests_helpers}/index.ts (100%) diff --git a/index.ts b/index.ts index 9aca871..4348170 100644 --- a/index.ts +++ b/index.ts @@ -7,13 +7,17 @@ * file that was distributed with this source code. */ -import './src/types/extended.js' - import type { PluginFn } from '@japa/runner/types' import { Test, TestContext } from '@japa/runner/core' -import { Assert } from './src/assert/main.js' -import type { PluginConfig } from './src/types/main.js' +import { Assert } from './src/assert.js' +import type { PluginConfig } from './src/types.js' + +declare module '@japa/runner/core' { + interface TestContext { + assert: Assert + } +} /** * Plugin for "@japa/runner" diff --git a/package.json b/package.json index 5607776..0880c9a 100644 --- a/package.json +++ b/package.json @@ -8,25 +8,23 @@ "main": "./build/index.js", "type": "module", "files": [ - "index.ts", - "src", - "build/src", - "build/index.d.ts", - "build/index.js", - "build/index.d.ts.map" + "build", + "!build/tests", + "!build/tests_helpers" ], "exports": { ".": "./build/index.js", - "./types": "./build/src/types/main.js" + "./types": "./build/src/types.js" }, "scripts": { "pretest": "npm run lint && npm run typecheck", "test": "c8 npm run quick:test", "quick:test": "cross-env NODE_NO_WARNINGS=1 glob -c \"node --enable-source-maps --loader=ts-node/esm --test\" \"test/**/*.spec.ts\"", "clean": "del-cli build", - "compile": "npm run lint && npm run clean && tsc", + "precompile": "npm run lint && npm run clean", + "compile": "tsup-node && tsc --emitDeclarationOnly --declaration", "build": "npm run compile", - "release": "np --message=\"chore(release): %s\"", + "release": "np", "version": "npm run build", "prepublishOnly": "npm run build", "lint": "eslint . --ext=.ts", @@ -56,6 +54,7 @@ "np": "^8.0.4", "prettier": "^3.0.3", "ts-node": "^10.9.1", + "tsup": "^7.2.0", "typescript": "^5.2.2" }, "dependencies": { @@ -113,5 +112,17 @@ }, "directories": { "test": "tests" + }, + "tsup": { + "entry": [ + "./index.ts", + "./src/types.ts" + ], + "outDir": "./build", + "clean": true, + "format": "esm", + "dts": false, + "sourcemap": true, + "target": "esnext" } } diff --git a/src/assert/main.ts b/src/assert.ts similarity index 99% rename from src/assert/main.ts rename to src/assert.ts index b3050bd..42c5fc6 100644 --- a/src/assert/main.ts +++ b/src/assert.ts @@ -13,7 +13,7 @@ import { chaiPlugin } from 'api-contract-validator' import { assert, Assertion, AssertionError, use, expect } from 'chai' import { subsetCompare } from './utils.js' -import type { AssertContract, ChaiAssert } from '../types/main.js' +import type { AssertContract, ChaiAssert } from './types.js' /** * The Assert class is derived from chai.assert to allow support diff --git a/src/types/main.ts b/src/types.ts similarity index 100% rename from src/types/main.ts rename to src/types.ts diff --git a/src/types/extended.ts b/src/types/extended.ts deleted file mode 100644 index aa07745..0000000 --- a/src/types/extended.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * @japa/assert - * - * (c) Japa.dev - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -import { Assert } from '../assert/main.js' - -declare module '@japa/runner/core' { - interface TestContext { - assert: Assert - } -} diff --git a/src/assert/utils.ts b/src/utils.ts similarity index 100% rename from src/assert/utils.ts rename to src/utils.ts diff --git a/test/assert/assert.spec.ts b/tests/assert/assert.spec.ts similarity index 99% rename from test/assert/assert.spec.ts rename to tests/assert/assert.spec.ts index 9ca95f1..f1c403b 100644 --- a/test/assert/assert.spec.ts +++ b/tests/assert/assert.spec.ts @@ -11,8 +11,8 @@ import { test } from 'node:test' import { DateTime } from 'luxon' -import { Assert } from '../../src/assert/main.js' -import { expectError, expectAsyncError } from '../../test_helpers/index.js' +import { Assert } from '../../src/assert.js' +import { expectError, expectAsyncError } from '../../tests_helpers/index.js' /** * Tests in this file is a copy of diff --git a/test/assert/assert_subset.spec.ts b/tests/assert/assert_subset.spec.ts similarity index 98% rename from test/assert/assert_subset.spec.ts rename to tests/assert/assert_subset.spec.ts index 03943dd..447ade3 100644 --- a/test/assert/assert_subset.spec.ts +++ b/tests/assert/assert_subset.spec.ts @@ -8,8 +8,8 @@ */ import { before, test } from 'node:test' -import { Assert } from '../../src/assert/main.js' -import { expectError } from '../../test_helpers/index.js' +import { Assert } from '../../src/assert.js' +import { expectError } from '../../tests_helpers/index.js' /** * Tests are copied from https://raw.githubusercontent.com/debitoor/chai-subset/master/test/unit/chai-subset.spec.js. diff --git a/test/assert/openapi.spec.ts b/tests/assert/openapi.spec.ts similarity index 95% rename from test/assert/openapi.spec.ts rename to tests/assert/openapi.spec.ts index d4e8aa4..51b8d27 100644 --- a/test/assert/openapi.spec.ts +++ b/tests/assert/openapi.spec.ts @@ -8,8 +8,8 @@ */ import { test } from 'node:test' -import { Assert } from '../../src/assert/main.js' -import { expectError } from '../../test_helpers/index.js' +import { Assert } from '../../src/assert.js' +import { expectError } from '../../tests_helpers/index.js' Assert.registerApiSpecs([new URL('../../api-spec.json', import.meta.url)]) diff --git a/test/plugin.spec.ts b/tests/plugin.spec.ts similarity index 97% rename from test/plugin.spec.ts rename to tests/plugin.spec.ts index 7c24b06..7aa0dcb 100644 --- a/test/plugin.spec.ts +++ b/tests/plugin.spec.ts @@ -12,8 +12,8 @@ import { assert as chaiAssert } from 'chai' import { TestContext, Test, Emitter, Refiner } from '@japa/runner/core' import { assert } from '../index.js' -import { Assert } from '../src/assert/main.js' -import { wrapAssertions } from '../test_helpers/index.js' +import { Assert } from '../src/assert.js' +import { wrapAssertions } from '../tests_helpers/index.js' test.describe('Plugin', () => { test('add assert property to test context', async () => { diff --git a/test_helpers/index.ts b/tests_helpers/index.ts similarity index 100% rename from test_helpers/index.ts rename to tests_helpers/index.ts