typed-ember / ember-cli-typescript

Use TypeScript in your Ember.js apps!
https://docs.ember-cli-typescript.com
MIT License
363 stars 99 forks source link

Remove rootDir option from precompile command #1272

Closed NullVoxPopuli closed 2 years ago

NullVoxPopuli commented 4 years ago

Please paste the output of ember -v here

ember-cli: 3.16.x node: 12.x os: linux x64

Please paste the output of tsc -v here

Version 3.9.7

Please paste the version of ember-cli-typescript and ember-cli-typescript-blueprints here

$ yarn list --pattern 'ember-cli-typescript'
yarn list v1.22.4
warning Resolution field "d3-selection@1.3.2" is incompatible with requested version "d3-selection@1.3.0"
├─ @glimmer/component@1.0.0
│  └─ ember-cli-typescript@3.0.0
├─ ember-cli-typescript-blueprints@3.0.0
├─ ember-cli-typescript@4.0.0-rc.1                <------------ this is the one used throughout all projects in our monorepo
├─ ember-concurrency-decorators@1.0.0
│  └─ ember-cli-typescript@2.0.2
├─ ember-fetch@7.0.1
│  └─ ember-cli-typescript@3.1.4
├─ ember-lifecycle-component@0.7.0
│  └─ ember-cli-typescript@3.1.4
├─ ember-load-initializers@2.1.1
│  └─ ember-cli-typescript@2.0.2
├─ ember-pattern-librarian@1.1.7
│  └─ ember-test-waiters@2.1.1
│     └─ ember-cli-typescript@3.1.4
└─ tracked-built-ins@1.0.2
   └─ ember-cli-typescript@3.1.4
Done in 2.75s.

Please paste your tsconfig.json and tslint.json or eslint.json (if applicable) below

Our tsconfig is in two parts:

root:

tsconfig.json at the root with shared options ``` // https://www.typescriptlang.org/v2/en/tsconfig { "compilerOptions": { // Babel handles transpiling, not tsc "target": "ESNext", "module": "ESNext", // Many npm modules are not distributed as actual modules "allowSyntheticDefaultImports": true, // Some of these overlap with @typescript-eslint a bit, but we can fail faster // be also having the type checker check these. // // -- cleanliness "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": false, // -- correctness "noImplicitAny": true, "noImplicitThis": true, "alwaysStrict": true, "strictNullChecks": true, "importsNotUsedAsValues": "error", // enforces type imports when imports are not used as values // -- footgun prevention "strictPropertyInitialization": true, "noFallthroughCasesInSwitch": true, // noEmitOnError will "break the build" like a traditional statically typed language "noEmitOnError": false, // default to not transpiling to js every save "noEmit": true, // forward source maps to babel "inlineSourceMap": true, "inlineSources": true, // allow JS but don't type check the JS // checkJs conflicts with noImplicitAny "allowJs": true, "checkJs": false, "moduleResolution": "node", "experimentalDecorators": true, // NOTE: specifying "paths" here is not inherited by TS projects // as the "extends" option does not resolve paths when the baseUrl changes. // // Each ts project will have some duplication with all the upward relative paths // referencing addons within the monorepo. // "paths": {}, }, "exclude": [ ".git", "bower_components", "dist", "node_modules", "tmp", "vendor", "**/node_modules/*", "**/tmp/*", "**/dist/*" ] } ```

a project:

tsconfig.json for an addon ``` { "extends": "../../../tsconfig.json", "compilerOptions": { "baseUrl": ".", "paths": { "dummy/tests/*": [ "tests/*" ], "dummy/*": [ "tests/dummy/app/*", "app/*" ], "my-addon": [ "addon" ], "my-addon/*": [ "addon/*" ], "my-addon/test-support": [ "addon-test-support" ], "my-addon/test-support/*": [ "addon-test-support/*" ], // Normally these are resolved in node_modules, but these packages are sym-linked "extra-types/*": ["../../../shared/packages/extra-types/*"], "browser-services": ["../../../shared/packages/browser-services/addon"], "browser-services/*": ["../../../shared/packages/browser-services/addon/*"], "ui": ["../ui/addon"], "ui/*": ["../ui/addon/*"], "*": [ "types/*" ] } }, "include": [ "app/**/*", "addon/**/*", "tests/**/*", "types/**/*", "test-support/**/*", "addon-test-support/**/*" ] } ```

What are instructions we can follow to reproduce the issue?

This isn't going to be easy.

  1. Create a yarn workspaces monorepo
  2. have a bunch of addons throughout the monorepo
  3. add those addons to the paths entry because typescript doesn't know how to resolve local addons in a monorepo
  4. run yarn prepublishOnly in an addon that references other ts addons -- you'll get an error about files from the other addons not being within the rootDir.

What I've had to do in the mean time is redefine the prepublish and postpublish commands:

    "prepublishOnly": "tsc --allowJs false --noEmit false --isolatedModules false --declaration --emitDeclarationOnly --pretty true",
    "postpublish": "cd ../../../ && git clean -f -d"

which isn't great :(

chriskrycho commented 3 years ago

Looking at this, I’m not sure this is a bug exactly or that the solution proposed is the right one, but there is a real thing to tackle here: we need to support workspaces well. I will probably be opening an issue tracking that shortly, and will link this to it (probably just closing in favor of it) when I have. Thanks!

chriskrycho commented 2 years ago

Per note above, I am closing this in favor of #1451.