typed-ember / glint

TypeScript powered tooling for Glimmer templates
https://typed-ember.gitbook.io/glint
MIT License
109 stars 51 forks source link

`glint --declaration` flattens and removes folders if there is no top-level module. #658

Closed NullVoxPopuli closed 9 months ago

NullVoxPopuli commented 9 months ago
❯ pnpm why typescript

@glint/core 1.2.1
└── typescript 5.3.2 peer
typescript 5.3.2

I observe an incorrect behavior: generating declarations[^dts-name] changes structure entirely based on the presence of a single file. This makes predictability hard with the package.json#exports:

  "exports": {
    ".": {
      "types": "./dist-types/index.d.ts",
      "default": "./dist/index.js"
    },
    "./*": {
      "types": "./dist-types/*.d.ts",
      "default": "./dist/*.js"
    },
    "./addon-main.js": "./addon-main.cjs"
  },

Before: https://stackblitz.com/edit/ember-cli-editor-output-6bfkuh?file=README.md With the following file structure:

src/
  components/
    foo.gts
    bar.ts
    bar.hbs

And this tsconfig.json:

{
  "extends": "@tsconfig/ember/tsconfig.json",
  "include": ["src/**/*", "unpublished-development-types/**/*"],
  "glint": {
    "environment": ["ember-loose", "ember-template-imports"]
  },
  "compilerOptions": {
    "skipLibCheck": true,
    "declarationDir": "dist-types",
    "emitDeclarationOnly": true,
    "noEmit": false
  }
}

the following declarations directory is created:

dist-types/
  foo.d.ts
  bar.d.ts

Real output from the above stackblitz: image

After: https://stackblitz.com/edit/ember-cli-editor-output-unnbr3 The only change:

now the dist-types directory is correct

dist-types/
  components/
    foo.d.ts
    bar.d.ts

Real output for the above stackblitz: image

[^dts-name]: Note that dist-types was an old name for the declarations directory for the v2 addon blueprint. This has no impact on any one's code, because the mapping is defined by the package.json#exports, but the v2 addon blueprint now using the declarations folder name.

NullVoxPopuli commented 9 months ago

looks like in tsconfig.json, setting rootDir: './src' creates behavior consistent with rollup and keeps the package.json#exports aligns.

Will PR to the v2 addon blueprint to add this.

NullVoxPopuli commented 9 months ago

PR: https://github.com/embroider-build/addon-blueprint/pull/233