Skip to content

Commit

Permalink
fix: rollup-plugin-typescript2 objectHashIgnoreUnknownHack warning (fix
Browse files Browse the repository at this point in the history
#305) (#339)

rollup-plugin-typescript2 < v0.26 needs the `objectHashIgnoreUnknownHack`
option to be enabled to correctly handle async plugins, but it's no
longer needed (and causes a warning) if the user has a more recent
version installed.

this PR detects the version of the plugin, if installed, and enables/disables the option accordingly.
  • Loading branch information
chocolateboy committed Apr 28, 2020
1 parent 9388b17 commit 3621d65
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"resolve-from": "^5.0.0",
"rollup-plugin-typescript2": "^0.19.2",
"semantic-release": "^15.13.3",
"semver": "^7.3.2",
"slash": "^2.0.0",
"string-width": "^3.0.0",
"stringify-author": "^0.1.3",
Expand Down
19 changes: 18 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ export class Bundler {
rollupFormat === 'iife' ||
config.bundleNodeModules

// rollup-plugin-typescript2 < v0.26 needs the `objectHashIgnoreUnknownHack`
// option to be enabled to correctly handle async plugins, but it's no
// longer needed (and causes a warning) if the user has a more recent
// version installed. [1] if the plugin is installed, detect the version
// and enable/disable the option accordingly.
//
// [1] https://github.com/egoist/bili/issues/305
const getObjectHashIgnoreUnknownHack = (): boolean => {
try {
const { version } = this.localRequire('rollup-plugin-typescript2/package.json')
const semver = require('semver')
return semver.lt(version, '0.26.0')
} catch (e) {
return true
}
}

const pluginsOptions: { [key: string]: any } = {
progress:
config.plugins.progress !== false &&
Expand Down Expand Up @@ -227,7 +244,7 @@ export class Bundler {
(source.hasTs || config.plugins.typescript2) &&
merge(
{
objectHashIgnoreUnknownHack: true,
objectHashIgnoreUnknownHack: getObjectHashIgnoreUnknownHack(),
tsconfigOverride: {
compilerOptions: {
module: 'esnext'
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8437,6 +8437,11 @@ semver@7.0.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-7.0.0.tgz#5f3ca35761e47e05b206c6daff2cf814f0316b8e"
integrity sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==

semver@^7.3.2:
version "7.3.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==

semver@~5.3.0:
version "5.3.0"
resolved "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
Expand Down

1 comment on commit 3621d65

@vercel
Copy link

@vercel vercel bot commented on 3621d65 Apr 28, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.