Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Commit

Permalink
ESM build (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
webcarrot authored Sep 30, 2022
1 parent 0b76156 commit ae2344b
Show file tree
Hide file tree
Showing 11 changed files with 1,822 additions and 2,070 deletions.
16 changes: 0 additions & 16 deletions jest.config.js

This file was deleted.

12 changes: 12 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { JestConfigWithTsJest } from "ts-jest";

const configuration: JestConfigWithTsJest = {
preset: "ts-jest",
testEnvironment: "node",
// collectCoverage: true,
detectOpenHandles: true,
collectCoverageFrom: ["src/**/*.ts"],
testTimeout: 5 * 1000,
};

export default configuration;
3,760 changes: 1,746 additions & 2,014 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 26 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
"name": "@webcarrot/parse",
"version": "1.4.1",
"description": "Typed parser",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"type": "module",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"build:cjs": "tsc --build ./tsconfig.cjs.json && copy-declaration-ts ./src ./dist/cjs",
"build:esm": "tsc --build ./tsconfig.esm.json && copy-declaration-ts ./src ./dist/esm",
"build": "rimraf ./dist && npm run build:cjs && npm run build:esm",
"clean": "rm -rf ./dist",
"prepack": "npm run build",
"postpack": "rimraf ./dist",
"postpack": "npm run clean",
"build:ts": "rollup -c ./rollup.config.mjs",
"build:cjs": "rollup --format=cjs --file=dist/index.cjs -p typescript -m -- src/index.ts",
"build:mjs": "rollup --format=es --file=dist/index.mjs -p typescript -m -- src/index.ts",
"build": "npm run clean && npm run build:ts && npm run build:cjs && npm run build:mjs",
"test": "tsc --noEmit && jest"
},
"repository": {
Expand Down Expand Up @@ -38,11 +49,14 @@
"registry": "https://registry.npmjs.org"
},
"devDependencies": {
"@types/jest": "^27.5.1",
"@webcarrot/copy-declaration-ts": "^1.0.0",
"jest": "^28.1.0",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.2",
"typescript": "^4.6.4"
"@rollup/plugin-typescript": "^8.5.0",
"@types/jest": "^29.1.1",
"jest": "^29.1.2",
"rollup": "^2.79.1",
"rollup-plugin-dts": "^4.2.2",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"typescript": "^4.8.4"
}
}
11 changes: 11 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import dts from 'rollup-plugin-dts';

const config = [
{
input: './src/index.ts',
output: [{ file: 'dist/index.d.ts', format: 'es' }],
plugins: [dts()],
},
];

export default config;
2 changes: 1 addition & 1 deletion src/async/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default <
): typeof fn =>
(payload, path, options) => {
if (options.nullable && payload === null) {
return Promise.resolve(null);
return Promise.resolve(null as any);
}
if (payload === undefined || payload === null) {
if ("default" in options) {
Expand Down
2 changes: 1 addition & 1 deletion src/sync/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default <
): typeof fn =>
(payload, path, options) => {
if (options.nullable && payload === null) {
return null;
return null as any;
}
if (payload === undefined || payload === null) {
if ("default" in options) {
Expand Down
2 changes: 2 additions & 0 deletions src/sync/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const handleNumber: ParserFunction<number, any, NumberParseFunctionOptions> = (
/^-?\d+(\.\d+)?$/.test(payload)
) {
value = parseFloat(payload);
} else {
throw error("Expected numeric value", path, payload);
}
if (isNaN(value)) {
throw error("Expected numeric value", path, payload);
Expand Down
8 changes: 0 additions & 8 deletions tsconfig.cjs.json

This file was deleted.

8 changes: 0 additions & 8 deletions tsconfig.esm.json

This file was deleted.

33 changes: 23 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
{
"compilerOptions": {
"module": "esnext",
"target": "ES2022",
"sourceMap": true,
"declaration": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"removeComments": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"allowUmdGlobalAccess": false,
"module": "ES2020",
"moduleResolution": "node",
"lib": ["es7", "es2017", "dom"]
"sourceMap": false,
"inlineSources": false,
"declaration": false,
"declarationMap": false,
"allowJs": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"target": "ES2022",
"removeComments": false,
"outDir": "./dist"
},
"include": ["./src/**/*"],
"exclude": ["./dist/**/*"],
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
"include": ["./src/**/*"]
}

0 comments on commit ae2344b

Please sign in to comment.