Skip to content

Commit

Permalink
feat(exports): Setup module first
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseLion committed Jun 17, 2024
1 parent b89cf01 commit b67b9d8
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"extension": ["ts"],
"recursive": true,
"require": [
"tsx/cjs"
"tsx/esm"
]
}
8 changes: 6 additions & 2 deletions eslint.config.mjs → eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export default eslintTs.config(
"@stylistic/switch-colon-spacing": "error",
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/consistent-type-imports": ["error", { fixStyle: "inline-type-imports" }],
"@typescript-eslint/dot-notation": "error",
"@typescript-eslint/explicit-function-return-type": ["error", { allowExpressions: true }],
"@typescript-eslint/explicit-member-accessibility": "error",
Expand Down Expand Up @@ -185,7 +187,7 @@ export default eslintTs.config(
ignoreExternal: true,
maxDepth: 1,
}],
"import/no-duplicates": "error",
"import/no-duplicates": ["error", { "prefer-inline": true }],
"import/no-import-module-exports": "error",
"import/no-namespace": "error",
"import/no-relative-packages": "error",
Expand All @@ -195,8 +197,9 @@ export default eslintTs.config(
alphabetize: {
caseInsensitive: false,
order: "asc",
orderImportKind: "asc",
},
groups: ["external", "parent", "sibling"],
groups: ["external", "parent", "sibling", "type"],
"newlines-between": "always",
}],
"jsdoc/check-alignment": "error",
Expand Down Expand Up @@ -227,6 +230,7 @@ export default eslintTs.config(
"sonarjs/cognitive-complexity": "off",
"sonarjs/no-duplicate-string": "off",
"sonarjs/no-inverted-boolean-check": "error",
"sort-imports": ["error", { ignoreDeclarationSort: true }],
"sort-keys": "error",
},
},
Expand Down
22 changes: 20 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,24 @@
"typesafe",
"typescript"
],
"main": "./dist/index.js",
"type": "module",
"main": "./dist/cjs/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"sideEffects": false,
"exports": {
".": {
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
},
"default": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"./package.json": "./package.json"
},
"files": [
"dist/",
"src/"
Expand All @@ -27,7 +43,9 @@
"node": ">=18"
},
"scripts": {
"build": "tsc -p tsconfig.prod.json",
"build": "yarn build:esm && yarn build:cjs",
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{ \"type\": \"commonjs\" }' > ./dist/cjs/package.json",
"build:esm": "tsc -p tsconfig.esm.json",
"check": "yarn compile && yarn lint && yarn test --forbid-only",
"compile": "tsc -p tsconfig.json",
"lint": "eslint .",
Expand Down
16 changes: 5 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import { Routeway, RoutewaysBuilder } from "./lib/Routeways";
import { type Routeway, RoutewaysBuilder } from "./lib/Routeways";

export {
addCodec,
ArrayCodecOptions,
Codec,
Codecs,
CodecsType,
DecodeQuery,
} from "./lib/Codecs";
export type { ArrayCodecOptions, Codec, CodecsType, DecodeQuery } from "./lib/Codecs";
export { addCodec, Codecs } from "./lib/Codecs";
export { CodecDecodeError } from "./lib/errors/CodecDecodeError";
export { CodecEncodeError } from "./lib/errors/CodecEncodeError";
export { UrlParserError } from "./lib/errors/UrlParserError";
export {
export type {
CodecMap,
CodecsToRecord,
InferQueryParams,
PathLike,
RouteParams,
} from "./lib/helpers/common";
export { Routeway } from "./lib/Routeways";
export type { Routeway } from "./lib/Routeways";

/**
* Creates a `Routeways` builder instance. Use this instance to start defining
Expand Down
10 changes: 5 additions & 5 deletions src/lib/Routeways.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Codec } from "./Codecs";
import { type Codec } from "./Codecs";
import { UrlParserError } from "./errors/UrlParserError";
import {
CodecMap,
CodecsToRecord,
PathLike,
RouteParams,
type CodecMap,
type CodecsToRecord,
type PathLike,
type RouteParams,
safeKeys,
} from "./helpers/common";

Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/Codecs.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TypeFactories, expect } from "@assertive-ts/core";

import { addCodec, Codec, Codecs, CodecsType } from "../../../src/lib/Codecs";
import { type Codec, Codecs, type CodecsType, addCodec } from "../../../src/lib/Codecs";
import { CodecDecodeError } from "../../../src/lib/errors/CodecDecodeError";
import { CodecEncodeError } from "../../../src/lib/errors/CodecEncodeError";

Expand Down
9 changes: 7 additions & 2 deletions test/unit/lib/helpers/common.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { expect } from "@assertive-ts/core";

import { Codecs } from "../../../../src/lib/Codecs";
import { CodecsToRecord, InferQueryParams, PathLike, RouteParams } from "../../../../src/lib/helpers/common";
import { TestRoutes } from "../../../TestRoutes";
import {
type CodecsToRecord,
type InferQueryParams,
type PathLike,
type RouteParams,
} from "../../../../src/lib/helpers/common";
import { type TestRoutes } from "../../../TestRoutes";

describe("[Unit] Commons.types.test.ts", () => {
describe("PathLike", () => {
Expand Down
12 changes: 12 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"incremental": false,
"module": "CommonJS",
"moduleResolution": "Node",
"outDir": "./dist/cjs",
"target": "ES5",
"verbatimModuleSyntax": false
},
"include": ["src/**/*"]
}
File renamed without changes.
10 changes: 7 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"incremental": true,
"isolatedModules": true,
"lib": ["ES2022"],
"module": "CommonJS",
"moduleResolution": "Node",
"module": "ES2022",
"moduleResolution": "Bundler",
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
Expand All @@ -23,7 +24,10 @@
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "ES5"
"target": "ES2022",
"useDefineForClassFields": true,
"useUnknownInCatchVariables": true,
"verbatimModuleSyntax": true
},
"exclude": [
".yarn/*",
Expand Down

0 comments on commit b67b9d8

Please sign in to comment.