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

Enable declaration files in all modules #5

Closed
wants to merge 39 commits into from

Conversation

RomainMuller
Copy link
Contributor

  • Upgraded bundled jsii packages to the latest build of 0.4.0
    • Includes "declaration": true in the generated tsconfig.json
  • Corrected package.json files to reference .d.ts files in the types field
  • Fixed manual tsconfig.json files to include "declaration": true
  • Added a standard .npmignore file to avoid npm using .gitignore for it
  • Fixed all issues that have been uncovered by the new compilation path

@@ -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",
Copy link
Contributor

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)

Copy link
Contributor Author

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...

Copy link
Contributor

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';
Copy link
Contributor

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?

Copy link
Contributor Author

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';
Copy link
Contributor

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?

Copy link
Contributor Author

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:

  1. If the .d.ts file hasn't been generated yet, compilation will fail on ENOENT.
  2. If the .d.ts file was produced by a previous compilation, compilation will fail because it becomes part of the source files, and tsc refuses to overwrite a source file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

@eladb
Copy link
Contributor

eladb commented May 31, 2018

Please confirm that you have a successful dry run.

@RomainMuller
Copy link
Contributor Author

Addressed commit from @eladb, and I have had a successful dry-run build of the latest changes against dev-rmuller at this point.

@eladb
Copy link
Contributor

eladb commented May 31, 2018

I will leave you to do the squashing and minting of the commit message

@aws aws deleted a comment from RomainMuller May 31, 2018
import { dynamodb } from 'aws-cdk-resources';

export { Token }; // Return type of Table#tableName
Copy link
Contributor

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?

Copy link
Contributor Author

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 :)

Copy link
Contributor

@rix0rrr rix0rrr left a 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 :)

RomainMuller added a commit that referenced this pull request May 31, 2018
- 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.
@RomainMuller
Copy link
Contributor Author

Merged by 13d8b7f

@RomainMuller RomainMuller deleted the rmuller/declaration-files branch May 31, 2018 11:16
eladb pushed a commit that referenced this pull request May 31, 2018
- 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.
@NGL321 NGL321 added the contribution/core This is a PR that came from AWS. label Sep 27, 2019
smguggen referenced this pull request in smguggen/aws-cdk Aug 24, 2021
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants