dumi
Version:
📖 Documentation Generator of React Component
86 lines (84 loc) • 3.35 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/features/compile/utils.ts
var utils_exports = {};
__export(utils_exports, {
getCodeBlockBabelPlugins: () => getCodeBlockBabelPlugins,
shouldDisabledLiveDemo: () => shouldDisabledLiveDemo
});
module.exports = __toCommonJS(utils_exports);
var import_utils = require("@umijs/utils");
var import_lodash = require("@umijs/utils/compiled/lodash");
var shouldDisabledLiveDemo = (api) => {
const extraBabelPlugins = api.userConfig.extraBabelPlugins;
const disableFlag = (0, import_lodash.isArray)(extraBabelPlugins) && extraBabelPlugins.some(
(p) => /^import$|babel-plugin-import/.test(p[0])
);
if (disableFlag) {
import_utils.logger.warn(
"live demo feature has been automatically disabled since babel-plugin-import be registered, if you want to enable live demo feature, checkout: https://d.umijs.org/guide/faq"
);
}
return disableFlag;
};
var IMPORT_SENSITIVE_BABEL_PLUGINS = {
"@emotion": "@emotion/babel-plugin",
"@emotion/babel-plugin": "@emotion/babel-plugin"
};
var warnedMissingPlugins = /* @__PURE__ */ new Set();
function getImportSensitivePluginTarget(name) {
if (name in IMPORT_SENSITIVE_BABEL_PLUGINS) {
return IMPORT_SENSITIVE_BABEL_PLUGINS[name];
}
const normalized = name.replace(/\\/g, "/");
const isPluginPath = Object.values(IMPORT_SENSITIVE_BABEL_PLUGINS).some(
(pkg) => normalized.endsWith(`/${pkg}`) || normalized.includes(`/${pkg}/`)
);
return isPluginPath ? name : void 0;
}
function getCodeBlockBabelPlugins(extraBabelPlugins, cwd) {
if (!(0, import_lodash.isArray)(extraBabelPlugins))
return [];
return extraBabelPlugins.reduce((ret, item) => {
const [name, options] = (0, import_lodash.isArray)(item) ? item : [item];
if (typeof name !== "string")
return ret;
const target = getImportSensitivePluginTarget(name);
if (!target)
return ret;
let pluginPath;
try {
pluginPath = require.resolve(target, { paths: [cwd] });
} catch {
if (!warnedMissingPlugins.has(target)) {
warnedMissingPlugins.add(target);
import_utils.logger.warn(
`\`${target}\` cannot be resolved, it will be skipped for code-block demos in markdown, install it if you need the transform result (e.g. auto label of emotion) for those demos.`
);
}
return ret;
}
ret.push(options === void 0 ? pluginPath : [pluginPath, options]);
return ret;
}, []);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getCodeBlockBabelPlugins,
shouldDisabledLiveDemo
});