-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Enable declaration files in all modules #5
Conversation
…ems that uncovered
@@ -3,7 +3,7 @@ | |||
"version": "0.6.0", | |||
"description": "CDK Constructs for AWS ACM", | |||
"main": "lib/index.js", | |||
"types": "lib/index.ts", | |||
"types": "lib/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.
Can we add a pkglint rule to enforce this? (maybe just open new issue)
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.
JSII won't compile if types doesn't reference .d.ts
file... So you wouldn't even get to pkglint
...
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.
Good enough
@@ -0,0 +1,8 @@ | |||
import { Test } from 'nodeunit'; |
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.
Probably should not be checked in....
Missing .gitignore entry somewhere?
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 yes, good catch!
@@ -1,6 +1,6 @@ | |||
import { App, Stack, StackProps } from 'aws-cdk'; | |||
import { InlineJavaScriptLambda } from 'aws-cdk-lambda'; | |||
import { Topic } from '..'; | |||
import { Topic } from '../lib'; |
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.
BTW, why is this not good?
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.
If you import { foo } from '..'
, and it happens ..
is the directory where you have package.json
, then tsc
will read the package.json
file and use the types
field as the required file. This causes two problems:
- If the
.d.ts
file hasn't been generated yet, compilation will fail onENOENT
. - If the
.d.ts
file was produced by a previous compilation, compilation will fail because it becomes part of the source files, andtsc
refuses to overwrite a source file.
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.
got it
Please confirm that you have a successful dry run. |
Addressed commit from @eladb, and I have had a successful dry-run build of the latest changes against |
I will leave you to do the squashing and minting of the commit message |
import { dynamodb } from 'aws-cdk-resources'; | ||
|
||
export { Token }; // Return type of Table#tableName |
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.
Can't you just fix that?
Also, why wasn't this an error before?
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.
Wasn't an error before, because tsc
didn't have to write a .d.ts
file that is coherent using only exported entities. When using the .ts
file as the source, the compiler is able to reach any private
declaration and make type inference work. I think it's a smell :)
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.
The use of a getter is actually still against other guidelines, but at least we fixed the type problem :)
- Upgrade local-npm packages with latest version of JSII (that enables declaration files) - Correct `package.json` files (the `types` field points to the `.d.ts` file now) - Correct `tsconfig.json` files for non-JSII packages, so they enable declaration files. - Add a `.npmignore` file to prevent `npm` from using `.gitignore` instead + Don't pack `.ts` files, but pack `.d.ts` files instead - The change uncovered a bunch of "poor practices", that were fixed as well: + Importing from the package's root (where `package.json` is) cannot work with `.d.ts` files, this was particularly frequent in tests.
Merged by 13d8b7f |
- Upgrade local-npm packages with latest version of JSII (that enables declaration files) - Correct `package.json` files (the `types` field points to the `.d.ts` file now) - Correct `tsconfig.json` files for non-JSII packages, so they enable declaration files. - Add a `.npmignore` file to prevent `npm` from using `.gitignore` instead + Don't pack `.ts` files, but pack `.d.ts` files instead - The change uncovered a bunch of "poor practices", that were fixed as well: + Importing from the package's root (where `package.json` is) cannot work with `.d.ts` files, this was particularly frequent in tests.
# This is the 1st commit message: Add Identity Pool construct # This is the commit message #2: Bug fixes # This is the commit message #3: Bug fixes # This is the commit message #4: Formatting # This is the commit message #5: Add construct methods # This is the commit message #6: Remove flat # This is the commit message #7: Fix issues
jsii
packages to the latest build of 0.4.0"declaration": true
in the generatedtsconfig.json
package.json
files to reference.d.ts
files in thetypes
fieldtsconfig.json
files to include"declaration": true
.npmignore
file to avoidnpm
using.gitignore
for it