vite-plugin-react18-pages
Version:
<p> <a href="https://www.npmjs.com/package/vite-plugin-react-pages" target="_blank" rel="noopener"><img src="https://img.shields.io/npm/v/vite-plugin-react-pages.svg" alt="npm package" /></a> </p>
67 lines • 2.73 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TsInfoModuleManager = void 0;
const virtual_module_1 = require("../../utils/virtual-module");
const extract_1 = require("./extract");
const PROXY_PREFIX = '/@react-pages/tsInfo';
/**
* TODO:
* currently we only watch one sourceFilePath for each virtule module(proxyModule).
* but if the sourceFilePath import other modules, and when that module has updated,
* TsInfoModuleManager won't notice that.
* we need a way to create virtule modules with dependencies.
*
* currently it is ok to tell users to write a whole type doc in a single file.
* so supporting virtule modules with dependencies is not needed.
* but supporting that feature would make our virtule module system more powerful.
*
* the same goes for DemoModuleManager.
*/
class TsInfoModuleManager {
constructor() {
this.pmm = new virtual_module_1.ProxyModulesManager(PROXY_PREFIX);
}
registerProxyModule(sourcePath, exportName) {
return this.pmm.registerProxyModule(sourcePath, async (file) => {
const tsInfo = (0, extract_1.collectInterfaceInfo)(sourcePath, exportName);
return {
sourcePath,
exportName,
tsInfo,
};
}, exportName);
}
isProxyModuleId(id) {
return this.pmm.isProxyModuleId(id);
}
async loadProxyModule(proxyModuleId) {
const data = await this.pmm.getProxyModuleData(proxyModuleId);
const { sourcePath, exportName, tsInfo } = data !== null && data !== void 0 ? data : {};
if (!sourcePath || !exportName || !tsInfo)
throw new Error(`assertion fail: invalid data: ${proxyModuleId}`);
return `export const data = ${JSON.stringify(tsInfo)};`;
}
onUpdate(cb) {
this.pmm.onProxyModuleUpdate(cb);
}
close() {
this.pmm.close();
}
}
exports.TsInfoModuleManager = TsInfoModuleManager;
__exportStar(require("./mdx-plugin"), exports);
//# sourceMappingURL=index.js.map