Skip to content

Commit

Permalink
feat: add back cjs output (#1964)
Browse files Browse the repository at this point in the history
* initial config

* fix: lint

* fix

* fixed esm/cjs fuckery

* fix: removed unused comment

* feat: importHelpers for esm

* remove build script and just read package.json file

---------

Co-authored-by: Arthur Fiorette <me@arthur.place>
Co-authored-by: Arthur Fiorette <47537704+arthurfiorette@users.noreply.github.com>
  • Loading branch information
3 people committed May 23, 2024
1 parent 1b27258 commit 4ac21b2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
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"]
}

0 comments on commit 4ac21b2

Please sign in to comment.