@dongmingzhixiu/vuexir 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +8 -1
- package/dist/shims.d.ts +9 -0
- package/dist/shims.js +75 -0
- package/package.json +3 -3
package/dist/bundle.js
CHANGED
|
@@ -11,11 +11,18 @@
|
|
|
11
11
|
import { existsSync, readdirSync } from 'node:fs';
|
|
12
12
|
import { join } from 'node:path';
|
|
13
13
|
import { buildSync } from 'esbuild';
|
|
14
|
+
import { mkdtempSync, writeFileSync } from 'node:fs';
|
|
15
|
+
import { tmpdir } from 'node:os';
|
|
16
|
+
import { DEXIE_SHIM_SOURCE } from './shims.js';
|
|
14
17
|
/** 打包 src/utils 下可独立运行的 util(`@/types` 等纯类型导入会被 esbuild 擦除) */
|
|
15
18
|
export function bundleProjectUtils(projectRoot) {
|
|
16
19
|
const utilsDir = join(projectRoot, 'src', 'utils');
|
|
17
20
|
if (!existsSync(utilsDir))
|
|
18
21
|
return { code: '', included: [], skipped: [] };
|
|
22
|
+
// 把 dexie shim 落到临时文件,打包时用 alias 顶替真实的 dexie 依赖
|
|
23
|
+
const shimDir = mkdtempSync(join(tmpdir(), 'vrn-shim-'));
|
|
24
|
+
const dexieShim = join(shimDir, 'dexie-shim.js');
|
|
25
|
+
writeFileSync(dexieShim, DEXIE_SHIM_SOURCE);
|
|
19
26
|
const included = [];
|
|
20
27
|
const skipped = [];
|
|
21
28
|
const chunks = [];
|
|
@@ -35,7 +42,7 @@ export function bundleProjectUtils(projectRoot) {
|
|
|
35
42
|
// 纯类型导入会被擦除;若确实依赖运行期外部包(dexie 等)则整包失败 → 跳过该文件
|
|
36
43
|
external: [],
|
|
37
44
|
logLevel: 'silent',
|
|
38
|
-
alias: { '@': join(projectRoot, 'src') },
|
|
45
|
+
alias: { '@': join(projectRoot, 'src'), dexie: dexieShim },
|
|
39
46
|
});
|
|
40
47
|
const code = out.outputFiles?.[0]?.text ?? '';
|
|
41
48
|
if (code) {
|
package/dist/shims.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* R99 P4:原生端没有 IndexedDB/Dexie,这里提供一个**最小可用 shim**,
|
|
3
|
+
* 在 esbuild 打包时把 `dexie` 别名到它——于是 `utils/db.ts` 可以进 bundle。
|
|
4
|
+
*
|
|
5
|
+
* 行为:内存表 + 落盘到 localStorage(iOS→UserDefaults / Android→SharedPreferences,
|
|
6
|
+
* 由运行时 localStorage shim 提供),API 覆盖 app 实际用到的子集:
|
|
7
|
+
* db.version(n).stores({...}) / table.get / put / bulkPut / toArray / delete / clear / count
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEXIE_SHIM_SOURCE = "\nfunction __vrnDbKey(db, table) { return \"vrn.db:\" + db + \":\" + table; }\n\nclass Table {\n constructor(dbName, name) { this.dbName = dbName; this.name = name; }\n _read() {\n try {\n var raw = localStorage.getItem(__vrnDbKey(this.dbName, this.name));\n return raw ? JSON.parse(raw) : [];\n } catch (e) { return []; }\n }\n _write(rows) {\n try { localStorage.setItem(__vrnDbKey(this.dbName, this.name), JSON.stringify(rows)); } catch (e) {}\n }\n async toArray() { return this._read(); }\n async count() { return this._read().length; }\n async get(key) {\n var keyName = this.keyPath || \"id\";\n return this._read().find(function (r) { return r && r[keyName] === key; });\n }\n async put(row) {\n var keyName = this.keyPath || \"id\";\n var rows = this._read();\n var i = rows.findIndex(function (r) { return r && r[keyName] === row[keyName]; });\n if (i >= 0) rows[i] = row; else rows.push(row);\n this._write(rows);\n return row[keyName];\n }\n async bulkPut(list) {\n var self = this;\n var rows = self._read();\n var keyName = self.keyPath || \"id\";\n (list || []).forEach(function (row) {\n var i = rows.findIndex(function (r) { return r && r[keyName] === row[keyName]; });\n if (i >= 0) rows[i] = row; else rows.push(row);\n });\n self._write(rows);\n return (list || []).length;\n }\n async delete(key) {\n var keyName = this.keyPath || \"id\";\n this._write(this._read().filter(function (r) { return !r || r[keyName] !== key; }));\n }\n async clear() { this._write([]); }\n where() { throw new Error(\"vrn dexie shim: where() \u6682\u4E0D\u652F\u6301\"); }\n orderBy() { throw new Error(\"vrn dexie shim: orderBy() \u6682\u4E0D\u652F\u6301\"); }\n}\n\nclass Version {\n constructor(db) { this._db = db; }\n stores(spec) {\n var db = this._db;\n Object.keys(spec || {}).forEach(function (tableName) {\n var keyPath = String(spec[tableName]).split(\",\")[0].trim();\n var t = new Table(db.name, tableName);\n t.keyPath = keyPath;\n db[tableName] = t;\n });\n return this;\n }\n}\n\nexport default class Dexie {\n constructor(name) { this.name = name; }\n version() { return new Version(this); }\n}\n";
|
package/dist/shims.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* R99 P4:原生端没有 IndexedDB/Dexie,这里提供一个**最小可用 shim**,
|
|
3
|
+
* 在 esbuild 打包时把 `dexie` 别名到它——于是 `utils/db.ts` 可以进 bundle。
|
|
4
|
+
*
|
|
5
|
+
* 行为:内存表 + 落盘到 localStorage(iOS→UserDefaults / Android→SharedPreferences,
|
|
6
|
+
* 由运行时 localStorage shim 提供),API 覆盖 app 实际用到的子集:
|
|
7
|
+
* db.version(n).stores({...}) / table.get / put / bulkPut / toArray / delete / clear / count
|
|
8
|
+
*/
|
|
9
|
+
export const DEXIE_SHIM_SOURCE = `
|
|
10
|
+
function __vrnDbKey(db, table) { return "vrn.db:" + db + ":" + table; }
|
|
11
|
+
|
|
12
|
+
class Table {
|
|
13
|
+
constructor(dbName, name) { this.dbName = dbName; this.name = name; }
|
|
14
|
+
_read() {
|
|
15
|
+
try {
|
|
16
|
+
var raw = localStorage.getItem(__vrnDbKey(this.dbName, this.name));
|
|
17
|
+
return raw ? JSON.parse(raw) : [];
|
|
18
|
+
} catch (e) { return []; }
|
|
19
|
+
}
|
|
20
|
+
_write(rows) {
|
|
21
|
+
try { localStorage.setItem(__vrnDbKey(this.dbName, this.name), JSON.stringify(rows)); } catch (e) {}
|
|
22
|
+
}
|
|
23
|
+
async toArray() { return this._read(); }
|
|
24
|
+
async count() { return this._read().length; }
|
|
25
|
+
async get(key) {
|
|
26
|
+
var keyName = this.keyPath || "id";
|
|
27
|
+
return this._read().find(function (r) { return r && r[keyName] === key; });
|
|
28
|
+
}
|
|
29
|
+
async put(row) {
|
|
30
|
+
var keyName = this.keyPath || "id";
|
|
31
|
+
var rows = this._read();
|
|
32
|
+
var i = rows.findIndex(function (r) { return r && r[keyName] === row[keyName]; });
|
|
33
|
+
if (i >= 0) rows[i] = row; else rows.push(row);
|
|
34
|
+
this._write(rows);
|
|
35
|
+
return row[keyName];
|
|
36
|
+
}
|
|
37
|
+
async bulkPut(list) {
|
|
38
|
+
var self = this;
|
|
39
|
+
var rows = self._read();
|
|
40
|
+
var keyName = self.keyPath || "id";
|
|
41
|
+
(list || []).forEach(function (row) {
|
|
42
|
+
var i = rows.findIndex(function (r) { return r && r[keyName] === row[keyName]; });
|
|
43
|
+
if (i >= 0) rows[i] = row; else rows.push(row);
|
|
44
|
+
});
|
|
45
|
+
self._write(rows);
|
|
46
|
+
return (list || []).length;
|
|
47
|
+
}
|
|
48
|
+
async delete(key) {
|
|
49
|
+
var keyName = this.keyPath || "id";
|
|
50
|
+
this._write(this._read().filter(function (r) { return !r || r[keyName] !== key; }));
|
|
51
|
+
}
|
|
52
|
+
async clear() { this._write([]); }
|
|
53
|
+
where() { throw new Error("vrn dexie shim: where() 暂不支持"); }
|
|
54
|
+
orderBy() { throw new Error("vrn dexie shim: orderBy() 暂不支持"); }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
class Version {
|
|
58
|
+
constructor(db) { this._db = db; }
|
|
59
|
+
stores(spec) {
|
|
60
|
+
var db = this._db;
|
|
61
|
+
Object.keys(spec || {}).forEach(function (tableName) {
|
|
62
|
+
var keyPath = String(spec[tableName]).split(",")[0].trim();
|
|
63
|
+
var t = new Table(db.name, tableName);
|
|
64
|
+
t.keyPath = keyPath;
|
|
65
|
+
db[tableName] = t;
|
|
66
|
+
});
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default class Dexie {
|
|
72
|
+
constructor(name) { this.name = name; }
|
|
73
|
+
version() { return new Version(this); }
|
|
74
|
+
}
|
|
75
|
+
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dongmingzhixiu/vuexir",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "vrn 命令行:build ios|android、preview、doctor",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"LICENSE"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@dongmingzhixiu/vuexir-compiler": "^0.3.
|
|
25
|
-
"@dongmingzhixiu/vuexir-templates": "^0.3.
|
|
24
|
+
"@dongmingzhixiu/vuexir-compiler": "^0.3.5",
|
|
25
|
+
"@dongmingzhixiu/vuexir-templates": "^0.3.5"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
28
|
"node": ">=18"
|