obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
173 lines (159 loc) • 8.49 kB
JavaScript
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
(function initCjs() {
const globalThisRecord = globalThis;
globalThisRecord['__name'] ??= name;
const originalRequire = require;
if (originalRequire && !originalRequire.__isPatched) {
// eslint-disable-next-line no-global-assign, no-implicit-globals -- We need to patch the `require()` function.
require = Object.assign(
(id) => requirePatched(id),
originalRequire,
{
__isPatched: true
}
);
}
const newFuncs = {
__extractDefault() {
return extractDefault;
},
process() {
const browserProcess = {
browser: true,
cwd() {
return '/';
},
env: {},
platform: 'android'
};
return browserProcess;
}
};
for (const key of Object.keys(newFuncs)) {
globalThisRecord[key] ??= newFuncs[key]?.();
}
function name(obj) {
return obj;
}
function extractDefault(module) {
return module && module.__esModule && 'default' in module ? module.default : module;
}
const OBSIDIAN_BUILT_IN_MODULE_NAMES = [
'obsidian',
'@codemirror/autocomplete',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/search',
'@codemirror/state',
'@codemirror/text',
'@codemirror/view',
'@lezer/common',
'@lezer/lr',
'@lezer/highlight'];
const DEPRECATED_OBSIDIAN_BUILT_IN_MODULE_NAMES = [
'@codemirror/closebrackets',
'@codemirror/comment',
'@codemirror/fold',
'@codemirror/gutter',
'@codemirror/highlight',
'@codemirror/history',
'@codemirror/matchbrackets',
'@codemirror/panel',
'@codemirror/rangeset',
'@codemirror/rectangular-selection',
'@codemirror/stream-parser',
'@codemirror/tooltip'];
function requirePatched(id) {
if (OBSIDIAN_BUILT_IN_MODULE_NAMES.includes(id) || DEPRECATED_OBSIDIAN_BUILT_IN_MODULE_NAMES.includes(id)) {
return originalRequire?.(id);
}
// eslint-disable-next-line @typescript-eslint/no-deprecated, @typescript-eslint/no-unnecessary-condition -- We need access to app here which might not be available yet.
if (globalThis?.app?.isMobile) {
if (id === 'process' || id === 'node:process') {
console.debug(`The most likely you can safely ignore this error. Module not found: ${id}. Fake process object is returned instead.`);
return globalThis.process;
}
} else {
const module = originalRequire?.(id);
if (module) {
return extractDefault(module);
}
}
console.debug(`The most likely you can safely ignore this error. Module not found: ${id}. Empty object is returned instead.`);
return {};
}
})();
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var svelteWrapperPlugin_exports = {};
__export(svelteWrapperPlugin_exports, {
svelteWrapperPlugin: () => svelteWrapperPlugin
});
module.exports = __toCommonJS(svelteWrapperPlugin_exports);
var import_esbuild_svelte = __toESM(__extractDefault(require('esbuild-svelte')), 1);
var import_svelte_preprocess = require('svelte-preprocess');
var import_ObjectUtils = require('../../ObjectUtils.cjs');
var import_Npm = require('../Npm.cjs');
const esbuildSvelte = (0, import_ObjectUtils.extractDefaultExportInterop)(import_esbuild_svelte.default);
function svelteWrapperPlugin(isProductionBuild) {
const esbuildSveltePlugin = esbuildSvelte({
compilerOptions: {
css: "injected",
dev: !isProductionBuild
},
moduleCompilerOptions: {
dev: !isProductionBuild
},
preprocess: (0, import_svelte_preprocess.sveltePreprocess)()
});
return {
name: "svelte-wrapper",
async setup(build) {
const packageJson = await (0, import_Npm.readPackageJson)();
const format = packageJson.type === "module" ? "esm" : "cjs";
await esbuildSveltePlugin.setup({
...build,
initialOptions: {
...build.initialOptions,
format
}
});
}
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
svelteWrapperPlugin
});
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vLi4vLi4vLi4vc3JjL1NjcmlwdFV0aWxzL2VzYnVpbGQvc3ZlbHRlV3JhcHBlclBsdWdpbi50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiLyoqXG4gKiBAcGFja2FnZURvY3VtZW50YXRpb25cbiAqXG4gKiBTdmVsdGUgd3JhcHBlciBlc2J1aWxkIHBsdWdpbi5cbiAqL1xuXG5pbXBvcnQgdHlwZSB7IFBsdWdpbiB9IGZyb20gJ2VzYnVpbGQnO1xuXG5pbXBvcnQgZXNidWlsZFN2ZWx0ZV8gZnJvbSAnZXNidWlsZC1zdmVsdGUnO1xuaW1wb3J0IHsgc3ZlbHRlUHJlcHJvY2VzcyB9IGZyb20gJ3N2ZWx0ZS1wcmVwcm9jZXNzJztcblxuaW1wb3J0IHsgZXh0cmFjdERlZmF1bHRFeHBvcnRJbnRlcm9wIH0gZnJvbSAnLi4vLi4vT2JqZWN0VXRpbHMudHMnO1xuaW1wb3J0IHsgcmVhZFBhY2thZ2VKc29uIH0gZnJvbSAnLi4vTnBtLnRzJztcblxuY29uc3QgZXNidWlsZFN2ZWx0ZSA9IGV4dHJhY3REZWZhdWx0RXhwb3J0SW50ZXJvcChlc2J1aWxkU3ZlbHRlXyk7XG5cbi8qKlxuICogV3JhcHMgdGhlIGVzYnVpbGQtc3ZlbHRlIHBsdWdpbiB0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