🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@mooljs/plugin-store

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mooljs/plugin-store - npm Package Compare versions

Comparing version
0.1.2
to
1.0.0
+47
dist/store.mjs
import { effectScope as o } from "vue";
function u(s) {
let e = !1, t;
const r = o(!0);
return (...l) => (e || (t = r.run(() => s(...l)), e = !0), t);
}
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
const f = Symbol("global-store");
class i {
constructor() {
this.modules = {};
}
static getInstance() {
return i.instance || (i.instance = new i()), i.instance;
}
/**
* 初始化全局 Store
*/
async initialize(e, t) {
Object.entries(/* @__PURE__ */ Object.assign({})).forEach(([l, c]) => {
var a;
const n = (a = l.match(/([^/]+)\.ts$/)) == null ? void 0 : a[1];
n && this.register(n, c.default);
}), t != null && t.namespace && t.initialState && this.register(t.namespace, () => t.initialState), e.provide(f, this.modules);
}
/**
* 注册新模块
*/
register(e, t) {
this.modules[e] && console.warn(`[StoreManager] 模块 ${e} 已存在,将被覆盖`), this.modules[e] = u(t);
}
/**
* 获取所有模块
*/
getModules() {
return this.modules;
}
}
const m = (s) => {
const e = i.getInstance();
return e.initialize(s), e;
};
export {
f as STORE_KEY,
i as StoreManager,
m as setupStore
};
+25
-6

@@ -1,9 +0,28 @@

const StorePlugin = require("./plugins/store");
const { readFileSync, existsSync } = require("node:fs");
module.exports = (api, options) => {
api.chainVite((config) => {
config.plugins.push(
StorePlugin(api,options)
);
api.applyPlugins((config) => {
// 检查 @mooljs/plugin-layout 插件是否存在,且 @mooljs/plugin-access 插件尚未添加
config.plugins.push({
name: "@mooljs/plugin-store",
after: [],
injectImports: (opt) => {
return [`import { setupStore } from 'virtual:store';`];
},
// 运行时逻辑
runtime: (ctx) => `
app.use(setupStore);
`,
// 虚拟模块定义
virtualModule: () => ({
id: "virtual:store",
content: readFileSync(
api.resolve("node_modules/@mooljs/plugin-store/dist/store.mjs"),
"utf-8",
),
}),
injectMool: () => {
return [`import { STORE_KEY } from 'virtual:store';`];
},
});
});
};
+7
-4
{
"name": "@mooljs/plugin-store",
"version": "0.1.2",
"version": "1.0.0",
"description": " global data store for mooljs",

@@ -16,2 +16,5 @@ "main": "index.js",

],
"files": [
"dist"
],
"author": "Merlin Hong",

@@ -31,8 +34,8 @@ "license": "MIT",

"devDependencies": {
"vite": "^5.3.4"
"vite": "^5.3.4",
"@vueuse/core": "^13.0.0"
},
"peerDependencies": {
"vue": "^3.2.25",
"vue-router": "^4.0.3"
"vue": "^3.2.25"
}
}
module.exports = (api, { config, lintOn = [] }, rootOptions, invoking) => {
// api.extendPackage({
// dependencies: {
// mooljs: "^0.8.0",
// },
// });
api.render("./template");
};
module.exports = function virtual(api, options) {
const virtualModuleIds = ['virturl:store'];
return {
name: "vite-mooljs-virturl-store",
enforce: "pre",
configureServer(server) {
server.middlewares.use(async (req, res, next) => {
// 页面刷新时触发
if (req.url == "/@vite/client") {
// 重新加载虚拟模块
virtualModuleIds.forEach((vm) => {
const mod = server.moduleGraph.getModuleById(`\0${vm}`);
if (mod) {
server.moduleGraph.invalidateModule(mod);
}
});
}
next();
});
},
resolveId(id) {
if (virtualModuleIds.includes(id)) {
return "\0" + id;
}
},
async load(id) {
if(id=="\0virturl:store"){
return readFileSync('../dist/store.mjs','utf-8');
}
},
};
}