Skip to content
Open
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
2 changes: 1 addition & 1 deletion typescript-json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export { Program, CompilerOptions, Symbol } from "typescript";

const vm = require("vm");

const REGEX_FILE_NAME_OR_SPACE = /(\bimport\(".*?"\)|".*?")\.| /g;
const REGEX_FILE_NAME_OR_SPACE = /(\bimport\(".*?"(, \{ assert: \{ "resolution-mode": "(import|require)" \} \})?\)|".*?")\.| /g;
Copy link

@derdeka derdeka Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @FoxxMD,
thank you for pointing in the right direction. I had to use a different regex when using [email protected] and [email protected] with esm modules:

Suggested change
const REGEX_FILE_NAME_OR_SPACE = /(\bimport\(".*?"(, \{ assert: \{ "resolution-mode": "(import|require)" \} \})?\)|".*?")\.| /g;
const REGEX_FILE_NAME_OR_SPACE = /(\bimport\(.*?\)|".*?")\.| /g;

I'm patching this line with the help of patch-package into typescript-json-schema to make it working again.

@YousefED Thank you for this great package! I would like to politely ask if this regular expression could be updated to work with ESM packages.

edit:
as just discovered @puckey suggests this change:

Suggested change
const REGEX_FILE_NAME_OR_SPACE = /(\bimport\(".*?"(, \{ assert: \{ "resolution-mode": "(import|require)" \} \})?\)|".*?")\.| /g;
const REGEX_FILE_NAME_OR_SPACE = /(\bimport\(".*?"(, [^)]+)?\)|".*?")\.| /g;

const REGEX_TSCONFIG_NAME = /^.*\.json$/;
const REGEX_TJS_JSDOC = /^-([\w]+)\s+(\S|\S[\s\S]*\S)\s*$/g;
const REGEX_GROUP_JSDOC = /^[.]?([\w]+)\s+(\S|\S[\s\S]*\S)\s*$/g;
Expand Down