Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move to esm with build supporting commonjs #35

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
lib
esm
cjs
@type
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.idea
lib
esm/*
!esm/package.json
cjs/*
!cjs/package.json
@type
coverage
/node_modules/
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no-install commitlint -g commitlint.config.js --edit "$1"
npx --no-install commitlint -g commitlint.config.cjs --edit "$1"
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
File renamed without changes.
3 changes: 3 additions & 0 deletions esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
8 changes: 6 additions & 2 deletions jest.config.js → jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
module.exports = {
extensionsToTreatAsEsm: ['.ts'],
globals: {
'ts-jest': {
diagnostics: false,
tsconfig: 'tsconfig.json',
tsconfig: 'tsconfig.cjs.json',
isolatedModules: true,
useESM: true,
},
},
moduleFileExtensions: ['js', 'ts', 'd.ts'],
moduleNameMapper: {
'@src/(.*)': '<rootDir>/src/$1',
'^(\\.{1,2}/.*)\\.js$': '$1',
},
preset: 'ts-jest',
rootDir: '.',
roots: ['<rootDir>/test'],
transform: { '^.+\\.ts$': 'ts-jest' },
verbose: true,
};
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
],
"scripts": {
"typecheck": "tsc --noEmit",
"build": "tsc --build --verbose tsconfig.build.json",
"build": "npm run build:esm && npm run build:cjs && npm run build:types",
"build:types": "tsc --build --verbose tsconfig.d.ts.json",
"build:esm": "tsc --build --verbose tsconfig.esm.json",
"build:cjs": "tsc --build --verbose tsconfig.cjs.json",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"test": "jest test",
Expand All @@ -35,13 +38,20 @@
},
"homepage": "https://github.com/rudi23/yup-to-openapi",
"files": [
"lib/**/*"
"esm/**/*",
"cjs/**/*",
"@type"
],
"publishConfig": {
"access": "public"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"exports": {
"require": "./cjs/index.js",
"import": "./esm/index.js"
},
"main": "./cjs/index.js",
"types": "./@type/index.d.ts",
"type": "module",
"lint-staged": {
"*.{js,ts}": "eslint --fix",
"*.{json,md}": "prettier --write"
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArraySchema, isSchema, ObjectSchema } from 'yup';
import type { ExtraParams, SchemaLike } from 'yup/lib/types';
import type { ExtraParams, SchemaLike } from 'yup/lib/types.d.js';
import type { AnySchema, AnyObjectSchema } from 'yup';
import type { SchemaObject } from 'openapi3-ts';
import type Lazy from 'yup/lib/Lazy.d.js';
Expand Down
2 changes: 1 addition & 1 deletion test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as yup from 'yup';
import type { SchemaObject } from 'openapi3-ts';
import yupToOpenAPI from '@src/index';
import yupToOpenAPI from '../src/index.js';

describe('yup-to-openapi', () => {
describe('yup lazy schema', () => {
Expand Down
4 changes: 0 additions & 4 deletions tsconfig.build.json

This file was deleted.

9 changes: 9 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./cjs",
"target": "es6",
"module": "commonjs",
"lib": ["ES2019"]
}
}
9 changes: 9 additions & 0 deletions tsconfig.d.ts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationDir": "./@type",
"removeComments": false,
"emitDeclarationOnly": true
}
}
3 changes: 3 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./tsconfig.json"
}
27 changes: 14 additions & 13 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"alwaysStrict": true,
"declaration": true,
"baseUrl": ".",
"esModuleInterop": true,
"importsNotUsedAsValues": "error",
"module": "commonjs",
"noUnusedLocals": true,
"noImplicitReturns": true,
"lib": ["esnext"],
"module": "es2022",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noFallthroughCasesInSwitch": true,
"outDir": "./lib",
"noUnusedLocals": true,
"outDir": "./esm",
"paths": {
"@src/*": ["src/*"]
},
"removeComments": true,
"rootDirs": ["src"],
"skipLibCheck": true,
"strict": true,
"strictNullChecks": true,
"target": "ES5",
"lib": ["es2020"],
"baseUrl": ".",
"paths": {
"@src/*": ["src/*"]
}
"target": "es2021"
},
"include": ["**/*"],
"exclude": ["node_modules", "lib"]
"exclude": ["node_modules", "esm", "cjs", "@type", "test"]
}