From 61514a3d9372ea4795ed4f56828fcb734800f54a Mon Sep 17 00:00:00 2001 From: chocolateboy Date: Mon, 27 Apr 2020 19:55:20 +0100 Subject: [PATCH] fix the rollup-plugin-typescript2 objectHashIgnoreUnknownHack warning 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. --- package.json | 1 + src/index.ts | 19 ++++++++++++++++++- yarn.lock | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a60e0713..21d10cac 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index 908b8be0..fd0f1698 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 && @@ -227,7 +244,7 @@ export class Bundler { (source.hasTs || config.plugins.typescript2) && merge( { - objectHashIgnoreUnknownHack: true, + objectHashIgnoreUnknownHack: getObjectHashIgnoreUnknownHack(), tsconfigOverride: { compilerOptions: { module: 'esnext' diff --git a/yarn.lock b/yarn.lock index fdd60166..b4635774 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8432,6 +8432,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"