New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More โ†’
Socket
Sign inDemoInstall
Socket

mdx-bundler

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdx-bundler - npm Package Compare versions

Comparing version 5.2.1 to 6.0.0

18

dist/index.d.ts

@@ -7,3 +7,3 @@ /**

*/
export function bundleMDX(mdxSource: string, { files, xdmOptions, esbuildOptions, globals, cwd, grayMatterOptions }?: import('./types').BundleMDXOptions): Promise<{
export function bundleMDX(mdxSource: string, { files, xdmOptions, esbuildOptions, globals, cwd, grayMatterOptions, }?: import('./types').BundleMDXOptions): Promise<{
code: string;

@@ -14,5 +14,19 @@ frontmatter: {

errors: esbuild.Message[];
matter: grayMatter.GrayMatterFile<string>;
matter: grayMatter.GrayMatterFile<any>;
}>;
/**
*
* @param {string} mdxPath - The file path to bundle.
* @param {import('./types').BundleMDXOptions} options
* @returns
*/
export function bundleMDXFile(mdxPath: string, { files, xdmOptions, esbuildOptions, globals, cwd, grayMatterOptions, }?: import('./types').BundleMDXOptions): Promise<{
code: string;
frontmatter: {
[key: string]: any;
};
errors: esbuild.Message[];
matter: grayMatter.GrayMatterFile<any>;
}>;
import * as esbuild from "esbuild";
import grayMatter from "gray-matter";

@@ -9,2 +9,3 @@ "use strict";

exports.bundleMDX = bundleMDX;
exports.bundleMDXFile = bundleMDXFile;

@@ -67,6 +68,4 @@ var _fs = _interopRequireDefault(require("fs"));

default: xdmESBuild
}] = await Promise.all([await import('xdm/esbuild.js')]); // extract the frontmatter
}] = await Promise.all([await import('xdm/esbuild.js')]);
const matter = (0, _grayMatter.default)(mdxSource, grayMatterOptions({}));
const entryPath = _path.default.join(cwd, `./_mdx_bundler_entry_point-${(0, _uuid.v4)()}.mdx`);

@@ -203,3 +202,15 @@ /** @type Record<string, string> */

minify: true
});
}); // Extract the front matter from the source or the entry point
/** @type grayMatter.GrayMatterFile<any> */
let matter; // We have to be a bit specific here to ensure type safety
if (buildOptions.entryPoints && Array.isArray(buildOptions.entryPoints) && buildOptions.entryPoints[0] !== entryPath) {
//The user has replaced the entrypoint, we can assume this means `mdxSource` is empty
matter = _grayMatter.default.read(buildOptions.entryPoints[0], grayMatterOptions({}));
} else {
matter = (0, _grayMatter.default)(mdxSource, grayMatterOptions({}));
}
const bundled = await esbuild.build(buildOptions);

@@ -237,2 +248,30 @@

throw new Error("You must either specify `write: false` or `write: true` and `outdir: '/path'` in your esbuild options");
}
/**
*
* @param {string} mdxPath - The file path to bundle.
* @param {import('./types').BundleMDXOptions} options
* @returns
*/
async function bundleMDXFile(mdxPath, {
files = {},
xdmOptions = options => options,
esbuildOptions = options => options,
globals = {},
cwd,
grayMatterOptions = options => options
} = {}) {
return bundleMDX('', {
files,
xdmOptions,
esbuildOptions: options => {
options.entryPoints = [mdxPath];
return esbuildOptions(options);
},
globals,
cwd: cwd ? cwd : _path.default.dirname(mdxPath),
grayMatterOptions
});
}

16

package.json
{
"name": "mdx-bundler",
"version": "5.2.1",
"version": "6.0.0",
"description": "Compile and bundle your MDX files and their dependencies. FAST.",

@@ -43,10 +43,10 @@ "main": "dist/index.js",

"dependencies": {
"@babel/runtime": "^7.14.6",
"@babel/runtime": "^7.15.3",
"@esbuild-plugins/node-resolve": "^0.1.4",
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
"gray-matter": "^4.0.3",
"remark-frontmatter": "^3.0.0",
"remark-frontmatter": "^4.0.0",
"remark-mdx-frontmatter": "^1.0.1",
"uuid": "^8.3.2",
"xdm": "^1.12.2"
"xdm": "^2.0.0"
},

@@ -59,3 +59,3 @@ "peerDependencies": {

"@types/jsdom": "^16.2.13",
"@types/react": "^17.0.14",
"@types/react": "^17.0.17",
"@types/react-dom": "^17.0.9",

@@ -65,5 +65,5 @@ "@types/uuid": "^8.3.1",

"cross-env": "^7.0.3",
"esbuild": "^0.12.15",
"jsdom": "^16.6.0",
"kcd-scripts": "^11.1.0",
"esbuild": "^0.12.20",
"jsdom": "^16.7.0",
"kcd-scripts": "^11.2.0",
"left-pad": "^1.3.0",

@@ -70,0 +70,0 @@ "mdx-test-data": "^1.0.1",

@@ -596,19 +596,20 @@ <div align="center">

### Replacing the entry point
### bundleMDXFile
If your MDX file is on your disk you can save some time and code by having
`esbuild` read the file for you. To do this you can override the `entryPoints`
settings in `esbuildOptions` with the path to your mdx source.
`esbuild` read the file for you. To do this mdx-bundler provides the function
`bundleMDXFile` which works the same as `bundleMDX` except it's first option is
the path to the mdx file instead of the mdx source.
```js
const {code, frontmatter} = await bundleMDX('', {
cwd: '/users/you/site/_content/pages',
esbuildOptions: options => {
options.entryPoints = ['/users/you/site/_content/pages/file.mdx']
import {bundleMDXFile} from 'mdx-bundler'
return options
},
})
const {code, frontmatter} = await bundleMDXFile(
'/users/you/site/content/file.mdx',
)
```
`cwd` will be automatically set to the `dirname` of the given file path, you can
still override this. All other options work the same as they do for `bundleMDX`.
### Known Issues

@@ -615,0 +616,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc