提交 210dca8d 编写于 作者: T Tim Neutkens 提交者: Joe Haddad

Ensure we correctly decide on which packages need better interopt (#9327)

上级 b9c71d37
import findUp from 'find-up'
const EVENT_PLUGIN_PRESENT = 'NEXT_PACKAGE_DETECTED'
type EventPackageDetected = {
packageName: string
packageVersion: string
type NextPluginsEvent = {
eventName: string
payload: {
packageName: string
packageVersion: string
}
}
const plugins = [
// CSS-in-JS solutions
'styled-components',
'radium',
'aphrodite',
'emotion',
'glamorous',
'glamor',
'fela',
'react-jss',
'linaria',
'typestyle',
// Modern Plugins
'@next/bundle-analyzer',
'@next/mdx',
// Legacy Plugins
'@zeit/next-bundle-analyzer',
'@zeit/next-css',
'@zeit/next-less',
'@zeit/next-mdx',
'@zeit/next-preact',
'@zeit/next-sass',
'@zeit/next-source-maps',
'@zeit/next-stylus',
'@zeit/next-typescript',
'@zeit/next-workers',
// Community Plugins
'next-env',
'next-offline',
'next-optimized-images',
'next-runtime-dotenv',
'next-progressbar',
'next-transpile-modules',
'next-react-svg',
'@weco/next-plugin-transpile-modules',
'next-images',
'next-videos',
'next-compose-plugins',
'next-build-id',
'next-routes',
'next-router',
'next-mdx-enhanced',
'next-docify',
'next-i18next',
'next-redux-saga',
'nookies',
'next-aws-lambda',
'serverless-nextjs-plugin',
'next-plugin-styled-icons',
'@ematipico/terraform-nextjs-plugin',
'next-mui-helper',
'nextjs-mui-helper',
'next-router-events',
'@moxy/next-runtime-env',
'next-session',
'next-apollo',
'next-minimal-routes',
'next-router-components',
'next-page-loading-bar',
'next-flexible-routes',
'next-apollo-hoc',
'routex.js',
'nextron',
'next-ga',
'nextjs-redirect',
'next-mobx-wrapper',
'next-ym',
'next-contentful',
'f-next-ga',
'next-plugin-yaml',
'data-prefetch-link',
'next-helpers',
'next-plugin-modernizr',
'nextjs-wp',
'nextjs-middleware',
'nextscript',
'next-fbq',
'next-analytics',
'@engineerapart/nextscript',
'next-data-link',
'@blunck/next-alias',
'@blunck/next-html',
'next-universal-redirect',
'create-next-app-lite',
'next-babel-minify',
'@rpominov/reason-next',
'create-next-library',
'nextscriptnew',
'nextjs-sitemap-generator',
'@dmartss/with-nprogress',
'create-react-next-app',
'hapi-nextjs',
'@cotype/serverless-next',
'nextjs-auth-hoc',
'@preco21/next-fonts',
'@dmartss/next-hoc',
'@xiphe/serverless-nextjs-plugin',
'@yellowiki/next-nprogress',
'@hashicorp/next-prebuild',
'next-i18next2.0',
'@futpib/next-ga',
'next-url-prettifier',
'next-plugin-custom-babel-config',
'fastify-nextjs',
'@yolkai/next-routes',
'trovit-next-routes',
'next-routify',
'wtp-next-routes',
'@whatoplay/next-routes',
'@ninetynine/next-routes',
'electron-next',
'@palmabit/sacajawea',
'advanced-next-routes',
'next-useragent',
'next-routes-with-locale',
'next-cookie',
'next-i18n-routes',
'next-graphql-react',
'next-flash-messages',
'next-manifest',
'next-purgecss',
'next-theme-webpack-plugin',
'next-serverless',
'connected-next-router',
'cookies-next',
'bs-next-alt',
'bs-next',
'next-redux',
'next-awesome-typescript',
'next-applicationinsights',
'next-routes-2',
'next-spa',
'next-precache',
'next-dynamic-routes',
'next-lambda',
'next-workbox',
'next-inferno',
'next-isserver',
'@alicd/next-locale-provider',
'shower-next',
'next-md',
'@primer/next',
'next-pages',
'amplify-next',
'create-next-app',
'neutron',
'react-intl',
'react-intl-universal',
'@lingui/react',
'@apollo/react-ssr',
]
export async function eventNextPlugins(
dir: string
): Promise<Array<{ eventName: string; payload: EventPackageDetected }>> {
): Promise<Array<NextPluginsEvent>> {
try {
const packageJsonPath = await findUp('package.json', { cwd: dir })
if (!packageJsonPath) {
......@@ -168,23 +19,29 @@ export async function eventNextPlugins(
}
const { dependencies = {}, devDependencies = {} } = require(packageJsonPath)
return (plugins
.map(plugin => {
const version = dependencies[plugin] || devDependencies[plugin]
if (version) {
return { pluginName: plugin, pluginVersion: version }
const deps = { ...devDependencies, ...dependencies }
return Object.keys(deps).reduce(
(events: NextPluginsEvent[], plugin: string): NextPluginsEvent[] => {
const version = deps[plugin]
// Don't add deps without a version set
if (!version) {
return events
}
})
.filter(Boolean) as {
pluginName: string
pluginVersion: string
}[]).map(({ pluginName, pluginVersion }) => ({
eventName: EVENT_PLUGIN_PRESENT,
payload: {
packageName: pluginName,
packageVersion: pluginVersion,
} as EventPackageDetected,
}))
events.push({
eventName: EVENT_PLUGIN_PRESENT,
payload: {
packageName: plugin,
packageVersion: version,
},
})
return events
},
[]
)
} catch (_) {
return []
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册