You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

vite-plugin-mdx

Package Overview
Dependencies
Maintainers
4
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-mdx - npm Package Compare versions

Comparing version

to
3.5.11

5

dist/index.d.ts

@@ -0,9 +1,10 @@

import type { Plugin } from 'vite';
import { MdxOptions, MdxPlugin } from './types';
import { NamedImports } from './imports';
export { MdxOptions, MdxPlugin };
declare function viteMdx(mdxOptions?: MdxOptions | ((filename: string) => MdxOptions)): import("vite").Plugin[];
declare function viteMdx(mdxOptions?: MdxOptions | ((filename: string) => MdxOptions)): Plugin[];
declare namespace viteMdx {
var withImports: (namedImports: NamedImports) => (mdxOptions?: MdxOptions | ((filename: string) => MdxOptions) | undefined) => import("vite").Plugin[];
var withImports: (namedImports: NamedImports) => (mdxOptions?: MdxOptions | ((filename: string) => MdxOptions) | undefined) => Plugin[];
}
export default viteMdx;
//# sourceMappingURL=index.d.ts.map

40

dist/index.js

@@ -33,2 +33,4 @@ "use strict";

(_b = globalMdxOptions.rehypePlugins) !== null && _b !== void 0 ? _b : (globalMdxOptions.rehypePlugins = []);
let reactRefresh;
let transformMdx;
const mdxPlugin = {

@@ -46,18 +48,20 @@ name: 'vite-plugin-mdx',

|| p.name === 'vite:react-refresh' || p.name === 'vite:react-jsx');
const reactRefresh = reactRefreshPlugins.find(p => p.transform);
const transform = transform_1.createTransformer(root, namedImports);
this.transform = function (code, id, ssr) {
return __awaiter(this, void 0, void 0, function* () {
if (/\.mdx?$/.test(id)) {
const mdxOptions = mergeOptions(globalMdxOptions, getMdxOptions === null || getMdxOptions === void 0 ? void 0 : getMdxOptions(id));
mdxOptions.filepath = id;
code = yield transform(code, mdxOptions);
const refreshResult = yield (reactRefresh === null || reactRefresh === void 0 ? void 0 : reactRefresh.transform.call(this, code, id + '.js', ssr));
return (refreshResult || {
code,
map: { mappings: '' }
});
}
});
};
reactRefresh = reactRefreshPlugins.find(p => p.transform);
transformMdx = (0, transform_1.createTransformer)(root, namedImports);
},
transform(code, id, ssr) {
return __awaiter(this, void 0, void 0, function* () {
if (/\.mdx?$/.test(id)) {
if (!transformMdx)
throw new Error('vite-plugin-mdx: configResolved hook should be called before calling transform hook');
const mdxOptions = mergeOptions(globalMdxOptions, getMdxOptions === null || getMdxOptions === void 0 ? void 0 : getMdxOptions(id));
mdxOptions.filepath = id;
code = yield transformMdx(code, mdxOptions);
const refreshResult = yield (reactRefresh === null || reactRefresh === void 0 ? void 0 : reactRefresh.transform.call(this, code, id + '.js', ssr));
return (refreshResult || {
code,
map: { mappings: '' }
});
}
});
}

@@ -69,8 +73,8 @@ };

// specifier to automatically inline their content seamlessly.
viteMdxTransclusion_1.viteMdxTransclusion(globalMdxOptions, getMdxOptions)
(0, viteMdxTransclusion_1.viteMdxTransclusion)(globalMdxOptions, getMdxOptions)
];
}
function mergeOptions(globalOptions, localOptions) {
return Object.assign(Object.assign(Object.assign({}, globalOptions), localOptions), { remarkPlugins: common_1.mergeArrays(globalOptions.remarkPlugins, localOptions === null || localOptions === void 0 ? void 0 : localOptions.remarkPlugins), rehypePlugins: common_1.mergeArrays(globalOptions.rehypePlugins, localOptions === null || localOptions === void 0 ? void 0 : localOptions.rehypePlugins) });
return Object.assign(Object.assign(Object.assign({}, globalOptions), localOptions), { remarkPlugins: (0, common_1.mergeArrays)(globalOptions.remarkPlugins, localOptions === null || localOptions === void 0 ? void 0 : localOptions.remarkPlugins), rehypePlugins: (0, common_1.mergeArrays)(globalOptions.rehypePlugins, localOptions === null || localOptions === void 0 ? void 0 : localOptions.rehypePlugins) });
}
//# sourceMappingURL=index.js.map
import { MdxOptions } from './types';
export declare function createTransformer(root: string, namedImports?: import("./imports").NamedImports): (code_mdx: string, mdxOptions?: MdxOptions | undefined) => Promise<string>;
export declare function createTransformer(root: string, namedImports?: import("./imports").NamedImports): (code_mdx: string, mdxOptions?: MdxOptions) => Promise<string>;
//# sourceMappingURL=transform.d.ts.map

@@ -15,6 +15,6 @@ "use strict";

const imports_1 = require("./imports");
function createTransformer(root, namedImports = imports_1.inferNamedImports(root)) {
const mdx = imports_1.requireMdx(root);
function createTransformer(root, namedImports = (0, imports_1.inferNamedImports)(root)) {
const mdx = (0, imports_1.requireMdx)(root);
const imports = Object.entries(namedImports).map(([packageName, imported]) => {
imports_1.assertImportExists(packageName, root);
(0, imports_1.assertImportExists)(packageName, root);
return Array.isArray(imported)

@@ -44,3 +44,3 @@ ? `import { ${imported.join(', ')} } from '${packageName}'`

//*/
let { code: code_es2019 } = yield esbuild_1.transform(code_jsx, {
let { code: code_es2019 } = yield (0, esbuild_1.transform)(code_jsx, {
loader: 'jsx',

@@ -47,0 +47,0 @@ jsxFactory: 'mdx',

@@ -16,7 +16,7 @@ "use strict";

// package installed by the user.
const mdxRoot = imports_1.resolveMdxImport(cwd);
const unified = imports_1.requireFrom('unified', mdxRoot);
const remarkParse = imports_1.requireFrom('remark-parse', mdxRoot);
const remarkMdx = imports_1.requireFrom('remark-mdx', mdxRoot);
const squeeze = imports_1.requireFrom('remark-squeeze-paragraphs', mdxRoot);
const mdxRoot = (0, imports_1.resolveMdxImport)(cwd);
const unified = (0, imports_1.requireFrom)('unified', mdxRoot);
const remarkParse = (0, imports_1.requireFrom)('remark-parse', mdxRoot);
const remarkMdx = (0, imports_1.requireFrom)('remark-mdx', mdxRoot);
const squeeze = (0, imports_1.requireFrom)('remark-squeeze-paragraphs', mdxRoot);
return unified()

@@ -23,0 +23,0 @@ .use(remarkParse)

@@ -47,54 +47,60 @@ "use strict";

let astCache;
return {
let resolvedConfig;
let watcher;
const plugin = {
name: 'mdx:transclusion',
configResolved({ root, logger }) {
let watcher;
this.configureServer = (server) => {
watcher = server.watcher;
importMap = new ImportMap_1.ImportMap();
astCache = new quick_lru_1.default({
maxAge: 30 * 6e4,
maxSize: 100
});
// When a transcluded file changes, recompile its importers.
// Also, clean up the import map when an importer is deleted.
watcher.on('all', (event, filePath) => {
if (/\.mdx?$/.test(filePath)) {
if (event === 'unlink') {
importMap.deleteImporter(filePath);
configResolved(config) {
resolvedConfig = config;
},
configureServer(server) {
watcher = server.watcher;
importMap = new ImportMap_1.ImportMap();
astCache = new quick_lru_1.default({
maxAge: 30 * 6e4,
maxSize: 100
});
// When a transcluded file changes, recompile its importers.
// Also, clean up the import map when an importer is deleted.
watcher.on('all', (event, filePath) => {
if (/\.mdx?$/.test(filePath)) {
if (event === 'unlink') {
importMap.deleteImporter(filePath);
}
const importers = importMap.importers.get(filePath);
if (importers) {
astCache.delete(filePath);
importers.forEach((importer) => {
watcher.emit('change', importer);
});
}
}
});
},
buildStart() {
if (!resolvedConfig)
throw new Error('vite-plugin-mdx: configResolved hook should be called before calling buildStart hook');
const { root, logger } = resolvedConfig;
globalMdxOptions.remarkPlugins.push((0, remarkTransclusion_1.remarkTransclusion)({
astCache,
importMap,
resolve: (id, importer) => __awaiter(this, void 0, void 0, function* () {
const resolved = yield this.resolve(id, importer);
if (resolved) {
id = (0, vite_1.normalizePath)(resolved.id);
// Ensure files outside the Vite project root are watched.
if (watcher && (0, path_1.isAbsolute)(id) && !id.startsWith(root + '/')) {
watcher.add(id);
}
const importers = importMap.importers.get(filePath);
if (importers) {
astCache.delete(filePath);
importers.forEach((importer) => {
watcher.emit('change', importer);
});
}
return id;
}
});
};
this.buildStart = function () {
globalMdxOptions.remarkPlugins.push(remarkTransclusion_1.remarkTransclusion({
astCache,
importMap,
resolve: (id, importer) => __awaiter(this, void 0, void 0, function* () {
const resolved = yield this.resolve(id, importer);
if (resolved) {
id = vite_1.normalizePath(resolved.id);
// Ensure files outside the Vite project root are watched.
if (watcher && path_1.isAbsolute(id) && !id.startsWith(root + '/')) {
watcher.add(id);
}
return id;
}
logger.warn(`Failed to resolve "${id}" imported by "${importer}"`);
}),
readFile: (filePath) => fs_1.default.promises.readFile(filePath, 'utf8'),
getCompiler: (filePath) => createMdxAstCompiler_1.createMdxAstCompiler(root, common_1.mergeArrays(globalMdxOptions.remarkPlugins, getMdxOptions === null || getMdxOptions === void 0 ? void 0 : getMdxOptions(filePath).remarkPlugins))
}));
};
logger.warn(`Failed to resolve "${id}" imported by "${importer}"`);
}),
readFile: (filePath) => fs_1.default.promises.readFile(filePath, 'utf8'),
getCompiler: (filePath) => (0, createMdxAstCompiler_1.createMdxAstCompiler)(root, (0, common_1.mergeArrays)(globalMdxOptions.remarkPlugins, getMdxOptions === null || getMdxOptions === void 0 ? void 0 : getMdxOptions(filePath).remarkPlugins))
}));
}
};
return plugin;
}
exports.viteMdxTransclusion = viteMdxTransclusion;
//# sourceMappingURL=index.js.map

@@ -62,2 +62,5 @@ "use strict";

if (node.type === 'mdxjsEsm' || node.type === 'import') {
// mdx ast nodes indeed have a value prop:
// https://github.com/mdx-js/specification#import
// but @types/unist doesn't declare it
const id = (_a = importRE.exec(node.value)) === null || _a === void 0 ? void 0 : _a[1];

@@ -64,0 +67,0 @@ if (id && mdxRE.test(id)) {

{
"name": "vite-plugin-mdx",
"version": "3.5.10",
"version": "3.5.11",
"scripts": {
"// User Scripts": "",
"dev": "yarn tsc:watch",
"build": "yarn install && yarn tsc:once",
"dev": "pnpm run tsc:watch",
"build": "pnpm run tsc:once",
"// TypeScript": "",

@@ -12,3 +12,4 @@ "tsc:watch": "tsc --build --watch",

"// Release": "",
"prepublishOnly": "yarn clean && yarn install && yarn tsc:once",
"prepublishOnly": "pnpm run build",
"release": "npm version patch && npm publish && git push && git push --tags",
"// Remove caches": "",

@@ -32,6 +33,8 @@ "clean": "git clean -Xdff"

"devDependencies": {
"@mdx-js/mdx": "^2.0.0-next.9",
"@mdx-js/mdx": "2.0.0-next.9",
"@types/es-module-lexer": "^0.3.0",
"@types/mdast": "^3.0.10",
"@types/node": "^14.14.22",
"@types/resolve": "^1.20.0",
"@types/unist": "^2.0.6",
"typescript": "^4.1.3",

@@ -38,0 +41,0 @@ "vite": "^2.0.4"

====================== [**WE ARE LOOKING FOR A NEW MAINTAINER**](https://github.com/brillout/vite-plugin-mdx/issues/42) ====================
# Vite Plugin MDX
Vite plugin to use MDX with your Vite app.
Vite plugin to use MDX v1 with your Vite app. For MDX v2 use [`@mdx-js/rollup`](https://www.npmjs.com/package/@mdx-js/rollup) instead, [this comment](https://github.com/brillout/vite-plugin-mdx/issues/44#issuecomment-974540152) explains how to implement it.
Features:
- Works with MDX v1 and MDX v2.
- Works with React and Preact.

@@ -11,0 +10,0 @@ - Works with Vue [**[WIP]**](https://github.com/brillout/vite-plugin-mdx/issues/3).

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet