-
Notifications
You must be signed in to change notification settings - Fork 216
Added back CommonsJS output under /cjs #1956
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
Changes from 4 commits
c077e49
f877ec4
1292823
a7c86f2
d3069c8
89f0b4a
ac31feb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
/*.ts | ||
coverage/ | ||
dist/ | ||
cjs/ | ||
node_modules/ | ||
!auto.config.ts | ||
/.idea/ | ||
|
||
# local config for auto | ||
.env | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Having the same source code to work with Node16's ESM and Node's CJS is a pain. | ||
// this script simply copies the packageJson version inside the main ts-json-schema-generator.js file | ||
|
||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import pkg from "../package.json" with { type: "json" }; | ||
|
||
function replaceVersion(source, version) { | ||
return source.replace(/const pkgVersion = "0.0.0";/, `const pkgVersion = "${version}";`); | ||
} | ||
|
||
function replaceFile(path) { | ||
const source = fs.readFileSync(path, "utf-8"); | ||
fs.writeFileSync(path, replaceVersion(source, pkg.version)); | ||
} | ||
|
||
replaceFile(path.resolve("cjs/ts-json-schema-generator.js")); | ||
replaceFile(path.resolve("dist/ts-json-schema-generator.js")); |
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"; | ||
|
||
// This constant gets replaced by the build script | ||
const pkgVersion = "0.0.0"; /* __VERSION__ */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like this as it makes it harder to watch build. The cjs version used to work so can you try to make the import version work here as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried a lot but ran out of choices.
I'm not sure if there's any other way to fix it without replacing the dist code. Also, as it gets built on CI before publishing, all official releases should work just as fine. |
||
|
||
const args = new Command() | ||
.option("-p, --path <path>", "Source file path") | ||
|
@@ -49,7 +51,7 @@ const args = new Command() | |
[], | ||
) | ||
.option("--additional-properties", "Allow additional properties for objects with no index signature", false) | ||
.version(pkg.version) | ||
.version(pkgVersion) | ||
.parse(process.argv) | ||
.opts(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "CommonJS", | ||
"moduleResolution": "Node", | ||
"outDir": "cjs", | ||
"importHelpers": true | ||
}, | ||
"files": ["ts-json-schema-generator.ts", "index.ts"], | ||
"include": ["src/**/*.ts", "factory/**/*.ts"], | ||
"exclude": ["node_modules", "dist", "cjs"] | ||
} |
Uh oh!
There was an error while loading. Please reload this page.