@next/mdx 15.0.4 → 15.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,29 +1,50 @@
1
1
  module.exports =
2
2
  (pluginOptions = {}) =>
3
- (nextConfig = {}) => {
3
+ (inputConfig = {}) => {
4
4
  const extension = pluginOptions.extension || /\.mdx$/
5
+ const userProvidedMdxOptions = pluginOptions.options
5
6
 
6
- const mdxRsOptions = nextConfig?.experimental?.mdxRs
7
+ const mdxRsOptions = inputConfig?.experimental?.mdxRs
7
8
  const loader = mdxRsOptions
8
9
  ? {
9
10
  loader: require.resolve('./mdx-rs-loader'),
10
11
  options: {
11
12
  providerImportSource: 'next-mdx-import-source-file',
12
- ...pluginOptions.options,
13
+ ...userProvidedMdxOptions,
13
14
  // mdxRsOptions is a union of boolean and object type of MdxTransformOptions
14
15
  ...(mdxRsOptions === true ? {} : mdxRsOptions),
15
16
  },
16
17
  }
17
18
  : {
18
- loader: require.resolve('@mdx-js/loader'),
19
+ loader: require.resolve('./mdx-js-loader'),
19
20
  options: {
20
21
  providerImportSource: 'next-mdx-import-source-file',
21
- ...pluginOptions.options,
22
+ ...userProvidedMdxOptions,
22
23
  },
23
24
  }
24
25
 
25
- return Object.assign({}, nextConfig, {
26
- experimental: Object.assign({}, nextConfig?.experimental, {
26
+ let nextConfig = Object.assign({}, inputConfig, {
27
+ webpack(config, options) {
28
+ config.resolve.alias['next-mdx-import-source-file'] = [
29
+ 'private-next-root-dir/src/mdx-components',
30
+ 'private-next-root-dir/mdx-components',
31
+ '@mdx-js/react',
32
+ ]
33
+ config.module.rules.push({
34
+ test: extension,
35
+ use: [options.defaultLoaders.babel, loader],
36
+ })
37
+
38
+ if (typeof inputConfig.webpack === 'function') {
39
+ return inputConfig.webpack(config, options)
40
+ }
41
+
42
+ return config
43
+ },
44
+ })
45
+
46
+ if (process.env.TURBOPACK) {
47
+ nextConfig.experimental = Object.assign({}, nextConfig?.experimental, {
27
48
  turbo: Object.assign({}, nextConfig?.experimental?.turbo, {
28
49
  rules: Object.assign({}, nextConfig?.experimental?.turbo?.rules, {
29
50
  '*.mdx': {
@@ -40,23 +61,8 @@ module.exports =
40
61
  }
41
62
  ),
42
63
  }),
43
- }),
44
- webpack(config, options) {
45
- config.resolve.alias['next-mdx-import-source-file'] = [
46
- 'private-next-root-dir/src/mdx-components',
47
- 'private-next-root-dir/mdx-components',
48
- '@mdx-js/react',
49
- ]
50
- config.module.rules.push({
51
- test: extension,
52
- use: [options.defaultLoaders.babel, loader],
53
- })
54
-
55
- if (typeof nextConfig.webpack === 'function') {
56
- return nextConfig.webpack(config, options)
57
- }
64
+ })
65
+ }
58
66
 
59
- return config
60
- },
61
- })
67
+ return nextConfig
62
68
  }
@@ -0,0 +1,66 @@
1
+ const mdxLoader = require('@mdx-js/loader')
2
+
3
+ function interopDefault(mod) {
4
+ return mod.default || mod
5
+ }
6
+
7
+ async function importPlugin(plugin, projectRoot) {
8
+ if (Array.isArray(plugin) && typeof plugin[0] === 'string') {
9
+ plugin[0] = interopDefault(
10
+ await import(require.resolve(plugin[0], { paths: [projectRoot] }))
11
+ )
12
+ }
13
+ return plugin
14
+ }
15
+
16
+ async function getOptions(options, projectRoot) {
17
+ const {
18
+ recmaPlugins = [],
19
+ rehypePlugins = [],
20
+ remarkPlugins = [],
21
+ ...rest
22
+ } = options
23
+
24
+ const [updatedRecma, updatedRehype, updatedRemark] = await Promise.all([
25
+ Promise.all(
26
+ recmaPlugins.map((plugin) => importPlugin(plugin, projectRoot))
27
+ ),
28
+ Promise.all(
29
+ rehypePlugins.map((plugin) => importPlugin(plugin, projectRoot))
30
+ ),
31
+ Promise.all(
32
+ remarkPlugins.map((plugin) => importPlugin(plugin, projectRoot))
33
+ ),
34
+ ])
35
+
36
+ return {
37
+ ...rest,
38
+ recmaPlugins: updatedRecma,
39
+ rehypePlugins: updatedRehype,
40
+ remarkPlugins: updatedRemark,
41
+ }
42
+ }
43
+
44
+ module.exports = function nextMdxLoader(...args) {
45
+ const options = this.getOptions()
46
+ const callback = this.async().bind(this)
47
+ const loaderContext = this
48
+
49
+ getOptions(options, this.context).then((userProvidedMdxOptions) => {
50
+ const proxy = new Proxy(loaderContext, {
51
+ get(target, prop, receiver) {
52
+ if (prop === 'getOptions') {
53
+ return () => userProvidedMdxOptions
54
+ }
55
+
56
+ if (prop === 'async') {
57
+ return () => callback
58
+ }
59
+
60
+ return Reflect.get(target, prop, receiver)
61
+ },
62
+ })
63
+
64
+ mdxLoader.call(proxy, ...args)
65
+ })
66
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/mdx",
3
- "version": "15.0.4",
3
+ "version": "15.1.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "repository": {