From c76f5e50ff1932986a0d1311708378612b4a8fe1 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 18 Nov 2020 11:59:26 +0800 Subject: [PATCH] fix: disable `esModuleInterop` & `allowSyntheticDefaultImports` for TS Otherwise the emitted type definitions may break downstream users who do not have these options enabled. Thanks @meteorlxy for spotting this issue. --- src/formatError.ts | 2 +- src/index.ts | 12 +++++++----- src/pitcher.ts | 8 ++++---- src/plugin.ts | 2 +- src/pluginWebpack4.ts | 4 ++-- src/pluginWebpack5.ts | 2 +- src/select.ts | 2 +- src/stylePostLoader.ts | 4 ++-- src/templateLoader.ts | 6 +++--- test/edgeCases.spec.ts | 2 +- test/utils.ts | 6 +++--- tsconfig.json | 2 -- 12 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/formatError.ts b/src/formatError.ts index 5b73bc73b..bd0b6e017 100644 --- a/src/formatError.ts +++ b/src/formatError.ts @@ -1,5 +1,5 @@ import { generateCodeFrame, CompilerError } from '@vue/compiler-sfc' -import chalk from 'chalk' +import chalk = require('chalk') export function formatError( err: SyntaxError | CompilerError, diff --git a/src/index.ts b/src/index.ts index cafbef86f..e237da912 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,11 +7,13 @@ try { ) } -import webpack from 'webpack' -import path from 'path' -import qs from 'querystring' -import hash from 'hash-sum' -import loaderUtils from 'loader-utils' +import webpack = require('webpack') +import * as path from 'path' +import * as qs from 'querystring' +import * as loaderUtils from 'loader-utils' + +import hash = require('hash-sum') + import { parse, compileScript, diff --git a/src/pitcher.ts b/src/pitcher.ts index c55aaf6ef..135e72e62 100644 --- a/src/pitcher.ts +++ b/src/pitcher.ts @@ -1,6 +1,6 @@ -import webpack from 'webpack' -import qs from 'querystring' -import loaderUtils from 'loader-utils' +import webpack = require('webpack') +import * as qs from 'querystring' +import * as loaderUtils from 'loader-utils' const selfPath = require.resolve('./index') // const templateLoaderPath = require.resolve('./templateLoader') @@ -69,7 +69,7 @@ export const pitch = function () { return genProxyModule( [...afterLoaders, stylePostLoaderPath, ...beforeLoaders], context, - !! query.module + !!query.module ) } } diff --git a/src/plugin.ts b/src/plugin.ts index 4fa11ca95..eeda1c0cc 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,4 +1,4 @@ -import webpack from 'webpack' +import webpack = require('webpack') declare class VueLoaderPlugin implements webpack.Plugin { static NS: string apply(compiler: webpack.Compiler): void diff --git a/src/pluginWebpack4.ts b/src/pluginWebpack4.ts index d015816c0..d398e5e3d 100644 --- a/src/pluginWebpack4.ts +++ b/src/pluginWebpack4.ts @@ -1,5 +1,5 @@ -import qs from 'querystring' -import webpack from 'webpack' +import * as qs from 'querystring' +import webpack = require('webpack') import { VueLoaderOptions } from './' const RuleSet = require('webpack/lib/RuleSet') diff --git a/src/pluginWebpack5.ts b/src/pluginWebpack5.ts index 21fe03799..cf9367a22 100644 --- a/src/pluginWebpack5.ts +++ b/src/pluginWebpack5.ts @@ -1,4 +1,4 @@ -import qs from 'querystring' +import * as qs from 'querystring' import { VueLoaderOptions } from './' import { RuleSetRule, Compiler, Plugin } from 'webpack' diff --git a/src/select.ts b/src/select.ts index 6273574fa..a1e18cb7a 100644 --- a/src/select.ts +++ b/src/select.ts @@ -1,4 +1,4 @@ -import webpack from 'webpack' +import webpack = require('webpack') import { SFCDescriptor } from '@vue/compiler-sfc' import { ParsedUrlQuery } from 'querystring' diff --git a/src/stylePostLoader.ts b/src/stylePostLoader.ts index 465ecf32a..3efdc6799 100644 --- a/src/stylePostLoader.ts +++ b/src/stylePostLoader.ts @@ -1,6 +1,6 @@ -import qs from 'querystring' +import * as qs from 'querystring' import { compileStyle } from '@vue/compiler-sfc' -import webpack from 'webpack' +import webpack = require('webpack') // This is a post loader that handles scoped CSS transforms. // Injected right before css-loader by the global pitcher (../pitch.js) diff --git a/src/templateLoader.ts b/src/templateLoader.ts index ed3119451..54a1a46de 100644 --- a/src/templateLoader.ts +++ b/src/templateLoader.ts @@ -1,6 +1,6 @@ -import webpack from 'webpack' -import qs from 'querystring' -import loaderUtils from 'loader-utils' +import webpack = require('webpack') +import * as qs from 'querystring' +import * as loaderUtils from 'loader-utils' import { VueLoaderOptions } from './' import { formatError } from './formatError' import { compileTemplate, TemplateCompiler } from '@vue/compiler-sfc' diff --git a/test/edgeCases.spec.ts b/test/edgeCases.spec.ts index d63e520f4..d233953ee 100644 --- a/test/edgeCases.spec.ts +++ b/test/edgeCases.spec.ts @@ -1,5 +1,5 @@ import * as path from 'path' -import HTMLPlugin from 'html-webpack-plugin' +import HTMLPlugin = require('html-webpack-plugin') import { mfs, bundle, mockBundleAndRun, normalizeNewline } from './utils' // @ts-ignore diff --git a/test/utils.ts b/test/utils.ts index 86de43b7f..14541205f 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -1,8 +1,8 @@ /* env jest */ -import path from 'path' -import webpack from 'webpack' +import * as path from 'path' +import webpack = require('webpack') import merge from 'webpack-merge' -import hash from 'hash-sum' +import hash = require('hash-sum') // import MiniCssExtractPlugin from 'mini-css-extract-plugin' import { fs as mfs } from 'memfs' diff --git a/tsconfig.json b/tsconfig.json index 2e1be3bf4..2f7f68029 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,10 +6,8 @@ "target": "es2015", "module": "commonjs", "moduleResolution": "node", - "esModuleInterop": true, "declaration": true, "allowJs": false, - "allowSyntheticDefaultImports": true, "noUnusedLocals": true, "strictNullChecks": true, "noImplicitAny": true,