Skip to content
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

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

Closed
NullVoxPopuli opened this issue Dec 6, 2023 · 2 comments · Fixed by embroider-build/addon-blueprint#233

Comments

@NullVoxPopuli
Copy link
Contributor

NullVoxPopuli commented Dec 6, 2023

❯ pnpm why typescript

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

I observe an incorrect behavior: generating declarations1 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:

  • adding a src/index.ts

now the dist-types directory is correct

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

Real output for the above stackblitz:
image

Footnotes

  1. 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
Copy link
Contributor Author

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
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant