-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
chore: add script to build typescript project references #1636
Conversation
b060100
to
9afd744
Compare
bin/update-project-refs.js
Outdated
rootRefs.push({ | ||
path: path.join( | ||
path.relative(project.rootPath, pkgLocation), | ||
'tsconfig.build.json', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we switch our monrepo to use project references, we should be able to get rid of tsconfig.build.json
files and use regular per-package tsconfig.json
file instead.
We are using tsconfig.build.json
files to prevent VS Code from recognizing individual packages as individual TypeScript projects, and force it to treat our entire monorepo as a single TypeScript project. This is needed to make cross-package navigation and refactoring working.
With the new feature of project references, supported by VS Code too (now? in a near future?), there is no need to use a different configuration for VS Code and the compiler. We can rename per-package tsconfig.build.json
files to regular tsconfig.json
files.
We may be able to remove the repository-level tsconfig.json
file too, but that requires changes in the way how tslint
is executed. I am not sure if running tslint on per-package basis is something we actually want to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, we cannot get rid of the top-level tsconfig.json
file because this file must contain a list of references to all projects included in the monorepo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably remove tsconfig
files from git and generate them as part of the build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can try that.
For now, I am fine with keeping the top-level tsconfig file in git. I think it may be easier for our users, as they don't have to run build before opening VS Code.
I am looking forward to see this work finished and the pull request landed ❤️ |
There are a few challenges to reach a working build:
I'm playing with |
Ouch. I see why I don't see why
Note that package-level I guess the fix is to dynamically modify these package-level Considering all these troubles and how little is Node.js 10.x adding in terms of JavaScript features, maybe we should simply abandon multi-target build and always transpile for Node.js 8.x only? |
I tried with both Node 8 and 10 to make sure
It complains about |
ee3cf82
to
1e6dd21
Compare
+1 if necessary. |
I'll try to run your changes on my machine later this week. From what I remember, TypeScript in build mode uses I don't know if the missing |
See microsoft/TypeScript#26689. I created a very simple project to reproduce the problem at https://github.com/raymondfeng/learn-a/. |
47d11a1
to
729be0a
Compare
3c811ae
to
63a0cca
Compare
I finally make it working with the following changes:
Now we can run |
9e41fbf
to
9866136
Compare
I have rebased this PR against latest master. PTAL. |
@@ -129,7 +129,7 @@ helper method; for example: | |||
{% include code-caption.html content="src/__tests__/helpers/database.helpers.ts" %} | |||
|
|||
```ts | |||
import {ProductRepository, CategoryRepository} from '../../src/repositories'; | |||
import {ProductRepository, CategoryRepository} from '../../repositories'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's land these documentation fixes in a standalone pull request please.
======== | ||
|
||
Usage: | ||
node ./bin/copy-resources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's land this new build helper in a new pull request. Should we include any documentation for this new helper, e.g. a new section in @loopback/build
's README?
Also, shouldn't the usage line mention the actual script name used by npm, which is lb-copy-resources
?
@@ -16,17 +16,17 @@ | |||
"strictNullChecks": true, | |||
"resolveJsonModule": true, | |||
|
|||
"lib": ["es2018", "dom", "esnext.asynciterable"], | |||
"lib": ["es2017", "dom", "esnext.asynciterable"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to keep using ES2018 features in our codebase, even if they are transpiled down to ES2017. Please revert this line.
benchmark/package.json
Outdated
@@ -8,12 +8,13 @@ | |||
"performance", | |||
"benchmark" | |||
], | |||
"main": "index.js", | |||
"types": "./dist/index.d.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to make the change in types
configuration in a standalone pull request because it requires changes in other places too. See #2613
9866136
to
86dddfe
Compare
06df8fc
to
e08f02e
Compare
686efa7
to
fbdf3be
Compare
This pull request is pretty much blocked by microsoft/TypeScript#30823 :(
|
fbdf3be
to
7b50297
Compare
Configure TSC to emit declaration maps, providing information needed by IDEs like VSCode to jump from usage of a symbol to its definition in the original source code. Simplify layout of all packages, remove top-level `index.ts` and `index.d.ts` files in favor of a package.json entry "types": "dist/index.d.ts" Simplify layout of module packages (excluding example applications) and remove the top-level `index.js` file in favor of a package.json entry "main": "dist/index.js" Update developer documentation and project templates accordingly. Benefits of these changes: - It's a preparation step for TypeScript Project References - Build is consuming less CPU cycles now. User time used to be 5m21 before, it's 1m48s now. Real time went down from 0m49s to 0m37s. - Simpler project setup in our packages, we no longer need to maintain dummy index files at the top level. Drawbacks: - Refactor-rename does not work across packagas. I believe this is a limitation of TypeScript, hopefully it will be eventually fixed. - Navigation across packages may not work until the monorepo is built.
7b50297
to
f3639df
Compare
- add script to build typescript project references - reorg project layout for better typescript refs - switch to tsconfig.json - add copy-resources script
f3639df
to
9bb6296
Compare
Start to add support for TypeScript project references.
Checklist
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated