tact-lang / tact

Tact compiler main repository
https://tact-lang.org
MIT License
394 stars 110 forks source link

Finalize `index.ts` and export it in package.json #776

Open jubnzv opened 2 months ago

jubnzv commented 2 months ago

Currently, Tact API users must write imports in the following format:

import { SrcInfo } from "@tact-lang/compiler/dist/grammar/ast";

It would be more convenient if they could write one of the following:

import { SrcInfo } from "@tact-lang/compiler";
import { SrcInfo } from "@tact-lang/compiler/grammar";

To achieve this, we should finalize the exports in the index.ts files and add them to package.json. Here is an example:

  "exports": {
    ".": {
      "import": "./dist/src/index.js",
      "require": "./dist/src/index.js"
    },
    "./*": "./dist/src/*"
  },

Related: https://github.com/tact-lang/tact/issues/740 and https://github.com/tact-lang/tact/issues/543

anton-trunov commented 2 months ago

and add them to package.json.

Somehow @ton/ton-core works without this step:

jubnzv commented 2 months ago

They somehow put index.js and index.d.js to the dist folder instead dist/src: https://www.npmjs.com/package/@ton/core?activeTab=code

jubnzv commented 1 month ago

In Tact, everything will work as expected. npm will place src/index.ts in dist/index.ts, with no additional actions required.

I encountered issues in Misti and Souffle.js because I included more than just src in my tsconfig.ts:

  "include": [
    "src/**/*",
    "test/**/*",
    "examples/**/*"
  ],

As a result, npm had to maintain that directory structure in dist, creating dist/{src,test,examples} directories.

Additionally, the TypeScript compiler checks if you import package.json in your code. If you do, it will generate the following structure: dist/{package.json,src}.