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

feat(typescript): better error when tslib is not installed #793

Merged
merged 2 commits into from
Feb 5, 2021

Conversation

shellscape
Copy link
Collaborator

Rollup Plugin Name: typescript

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers: Fixes #598

Description

This PR adds a meaningful error for users that addresses #598. Of note, this switches the use of the async resolve method to resolve.sync. It was just too problematic dealing with promises and getting the error out of the promise chain and back out to the user properly blocking the build. That may actually be an issue with plugin architecture, but we have an easy workaround for it now. Testing tslib being completely missing was a challenge, and I ultimately resorted to a janky envar for simulating that (notes in code comments) after trying a dozen or so methods for removing it (or simulating it being gone) from local node_modules.

packages/typescript/src/options/plugin.ts Show resolved Hide resolved
tsconfig.base.json Outdated Show resolved Hide resolved
}

/** Properties of `CompilerOptions` that are normally enums */
export type EnumCompilerOptions = 'module' | 'moduleResolution' | 'newLine' | 'jsx' | 'target';

/** JSON representation of Typescript compiler options */
export type JsonCompilerOptions = Omit<CompilerOptions, EnumCompilerOptions> &
export type JsonCompilerOptions = Omit<FlexibleCompilerOptions, EnumCompilerOptions> &
Copy link
Member

Choose a reason for hiding this comment

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

The type changes here appear unnecessary, and throws out a lot of type-checking for typos. I'd rather leave it as is.

Copy link
Collaborator Author

@shellscape shellscape Feb 5, 2021

Choose a reason for hiding this comment

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

Unfortunately it necessary for everything to play nicely together. The tests weren't written in TypeScript, and as soon as I started passing tslib as an option in a TypeScript test, it started throwing typing errors. Going to have to overrule you on this one, unless you can get the types playing nice in a more visually pleasing manner.

At issue is the way you typed the tslib option in the plugin options, and the way that CompilerOptions exposes the same property through the [options: string] index. They're incompatible.

Copy link
Member

Choose a reason for hiding this comment

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

OK, I can always try taking a look at this again in a future PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry for laying that out tersely, super tired over here. The blame is not yours, so didn't mean to imply that. Just how the types ended up, we got that funky collision. We'd probably have to use an alternate option name like tslibPath or something.

packages/typescript/src/tslib.ts Show resolved Hide resolved
@shellscape shellscape force-pushed the feat/typescript/error-no-tslib branch from fc3e53b to 8dfbf7f Compare February 5, 2021 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clearer error if tslib is not installed
2 participants