antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
16.68k stars 3.23k forks source link

Add projects to test typescript support with different compiler options #4597

Open JesusTheHun opened 2 months ago

JesusTheHun commented 2 months ago

Following #4218, this PR adds three test projects that use ESM and CJS with npm and one that uses ESM with pnpm.

The projects are compiled with different typescript compiler options to ensure compatibility.

This PR focuses on testing that antlr4 can be imported in TS projects. This is why it does not include non-TS test projects.

ericvergnaud commented 2 months ago

Looks like the tests fail ? See for example https://github.com/antlr/antlr4/actions/runs/8723991967/job/23933679496?pr=4597

JesusTheHun commented 2 months ago

Looks like the tests fail ? See for example https://github.com/antlr/antlr4/actions/runs/8723991967/job/23933679496?pr=4597

I fail to run the tests locally using maven. I haven't touch to java in a while so I'm a bit rusty at identifying compilation chain issues 😅 In addition to the requested changes I've committed a fix, hopefully the one we need.

JesusTheHun commented 2 months ago

Fixes the failing tests, but not sure it satisfies the requirement to test against the built package (vs the source project)

I was hesitant to test against the build because that would require to compile every time you make a change, which is annoying during development. But I can make the change if you want. It is safer indeed.

EDIT : your build process bundle the javascript, but do not include the type definitions. So we would have to use npm pack, extract the archive, and use the directory at the package path. That being said, what is tested really is the declaration of types definition, which only targets the package.json really. Assuming the referenced files exist. Before my latest commits they did not, and the build failed. So I say the tests served their purpose 👍

JesusTheHun commented 2 months ago

@ericvergnaud just pinging in case you didn't see my edit above

ericvergnaud commented 2 months ago

@ericvergnaud just pinging in case you didn't see my edit above

Ah I see what you mean. But how can we be sure that your test samples are using the dist folder ?

JesusTheHun commented 2 months ago

Ah I see what you mean. But how can we be sure that your test samples are using the dist folder ?

The test uses the package.json. The package.json references the dist folder for the javascript, and the src for the type definitions.

EDIT : to clarify, npm pack is the command that create the archive that is published. It copies the package.json as-is, so our tests have the exact same conditions.

JesusTheHun commented 2 months ago

@ericvergnaud after migrating the project using this lib to pnpm, I noticed the types stopped to work altogether. After looking around I noticed that the imports inside the definition files did not include the file extension, which is required for modern node usage.

EDIT : for anyone following this topic, I've published a package that reflect the changes on this branch : https://www.npmjs.com/package/@cbjsdev/antlr4 . Install the latest version 4.13.2.