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: add back cjs output #1964

Merged
merged 8 commits into from
May 23, 2024
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*.ts
coverage/
dist/
cjs/
node_modules/
!auto.config.ts
/.idea/
Expand All @@ -10,4 +11,4 @@ node_modules/

# Other package managers
pnpm-lock.yaml
package-lock.json
package-lock.json
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended"
/** @type {import('@types/eslint').Linter.FlatConfig[]} */
export default tseslint.config(
{
ignores: ["dist"],
ignores: ["dist", "cjs", "build"],
},
eslint.configs.recommended,
{
Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
"name": "ts-json-schema-generator",
"version": "2.0.0",
"description": "Generate JSON schema from your Typescript sources",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"bin": {
"ts-json-schema-generator": "./bin/ts-json-schema-generator.js"
},
"files": [
"dist",
"cjs",
"src",
"factory",
"index.*",
Expand Down Expand Up @@ -44,13 +45,18 @@
"engines": {
"node": ">=18.0.0"
},
"exports": {
"import": "./dist/index.js",
"require": "./cjs/index.js"
},
"dependencies": {
"@types/json-schema": "^7.0.15",
"commander": "^12.0.0",
"glob": "^10.3.12",
"json5": "^2.2.3",
"normalize-path": "^3.0.0",
"safe-stable-stringify": "^2.4.3",
"tslib": "^2.6.2",
"typescript": "^5.4.5"
},
"devDependencies": {
Expand Down Expand Up @@ -84,7 +90,9 @@
},
"scripts": {
"prepublishOnly": "yarn build",
"build": "tsc",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.json",
"watch": "tsc -w",
"lint": "eslint",
"format": "eslint --fix",
Expand Down
10 changes: 6 additions & 4 deletions ts-json-schema-generator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { mkdirSync, writeFileSync } from "node:fs";
import { dirname } from "node:path";
import { Command, Option } from "commander";
import stableStringify from "safe-stable-stringify";
import { createGenerator } from "./factory/generator.js";
import { Config } from "./src/Config.js";
import type { Config } from "./src/Config.js";
import { BaseError } from "./src/Error/BaseError.js";
import { formatError } from "./src/Utils/formatError.js";
import pkg from "./package.json" with { type: "json" };
import { dirname } from "path";
import { mkdirSync, writeFileSync } from "fs";
import fs from "node:fs";

const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));

const args = new Command()
.option("-p, --path <path>", "Source file path")
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": {
"target": "ES2022",
"module": "CommonJS",
"moduleResolution": "Node",
"outDir": "cjs"
},
"files": ["ts-json-schema-generator.ts", "index.ts"],
"include": ["src/**/*.ts", "factory/**/*.ts"],
"exclude": ["node_modules", "dist", "cjs"]
}
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
"pretty": true,
"typeRoots": ["node_modules/@types"],
"outDir": "dist",
"incremental": true
"incremental": true,
"importHelpers": true
},
"files": ["ts-json-schema-generator.ts", "index.ts"],
"include": ["src/**/*.ts", "factory/**/*.ts"],
"exclude": ["node_modules", "dist"]
"exclude": ["node_modules", "dist", "cjs"]
}
Loading