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

fix(gatsby-plugin-mdx): Hashing and pluginOptions (#36387) #36395

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,29 @@ export async function getSourcePluginsAsRemarkPlugins({

const userPlugins = userPluginsFiltered.map(plugin => {
const requiredPlugin = plugin.module
const wrappedGatsbyPlugin: Pluggable<Array<any>> =
function wrappedGatsbyPlugin() {
// eslint-disable-next-line @babel/no-invalid-this
const mdxNode = getNode(this.data(`mdxNodeId`) as string)
const wrappedGatsbyPlugin: Pluggable<any> = function wrappedGatsbyPlugin() {
// eslint-disable-next-line @babel/no-invalid-this
const mdxNode = getNode(this.data(`mdxNodeId`) as string)

return async function transformer(markdownAST): Promise<any> {
// Execute gatsby-remark-* plugin
await requiredPlugin(
{
markdownAST,
markdownNode: mdxNode,
getNode,
getNodesByType,
get files() {
return getNodesByType(`File`)
},
pathPrefix,
reporter,
cache,
return async function transformer(markdownAST): Promise<any> {
// Execute gatsby-remark-* plugin
await requiredPlugin(
{
markdownAST,
markdownNode: mdxNode,
getNode,
getNodesByType,
get files() {
return getNodesByType(`File`)
},
plugin.options || {}
)
}
pathPrefix,
reporter,
cache,
},
plugin.pluginOptions || {}
)
}
}

return wrappedGatsbyPlugin
})
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby-plugin-mdx/src/plugin-options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ProcessorOptions } from "@mdx-js/mdx"
import type { GatsbyCache, NodePluginArgs, PluginOptions, Store } from "gatsby"
import deepmerge from "deepmerge"
import type { IPluginRefObject } from "gatsby-plugin-utils/types"
import type { IPluginInfo } from "gatsby-plugin-utils/types"
import { getSourcePluginsAsRemarkPlugins } from "./get-source-plugins-as-remark-plugins"
import rehypeMdxMetadataExtractor from "./rehype-metadata-extractor"
import { remarkMdxHtmlPlugin } from "./remark-mdx-html-plugin"
Expand All @@ -10,7 +10,7 @@ import { remarkPathPlugin } from "./remark-path-prefix-plugin"
export interface IMdxPluginOptions {
extensions: [string]
mdxOptions: ProcessorOptions
gatsbyRemarkPlugins?: [IPluginRefObject]
gatsbyRemarkPlugins?: [IPluginInfo]
}
interface IHelpers {
getNode: NodePluginArgs["getNode"]
Expand Down Expand Up @@ -84,7 +84,7 @@ export const enhanceMdxOptions: EnhanceMdxOptions = async (

if (typeof requiredPlugin.setParserPlugins === `function`) {
for (const parserPlugin of requiredPlugin.setParserPlugins(
plugin.options || {}
plugin.pluginOptions || {}
)) {
if (Array.isArray(parserPlugin)) {
const [parser, parserPluginOptions] = parserPlugin
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export interface IPluginInfo {

/** Options passed to the plugin */
pluginOptions?: IPluginInfoOptions

module?: any
modulePath?: string
}

export interface IPluginInfoOptions {
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby/src/utils/js-chunk-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ export function generateComponentChunkName(componentPath: string): string {
* File names should not exceed 255 characters
* minus 12 for `component---`
* minus 7 for `.js.map`
* minus 20 for `-[hash].js`
*/
const maxLength = 236
const maxLength = 215
const shouldTruncate = name.length > maxLength

/**
Expand Down