@n3rdw1z4rd/core 0.25.0 → 0.26.0
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/README.md +45 -0
- package/dist/desktop.d.ts +37 -0
- package/dist/desktop.js +14 -0
- package/dist/electron/after-pack.cjs +17 -0
- package/dist/electron/index.d.ts +110 -0
- package/dist/electron/index.js +257 -0
- package/dist/electron/preload.cjs +12 -0
- package/dist/electron/updater.d.ts +81 -0
- package/dist/electron/updater.js +133 -0
- package/dist/electron.cjs +416 -0
- package/dist/electron.d.cts +189 -0
- package/dist/index.cjs +14 -0
- package/dist/index.d.cts +37 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/vite.cjs +124 -0
- package/dist/vite.d.cts +53 -2
- package/dist/vite.d.ts +53 -2
- package/dist/vite.js +122 -1
- package/package.json +23 -3
package/dist/vite.js
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { join, relative, resolve, sep } from "node:path";
|
|
1
5
|
// src/vite.ts
|
|
6
|
+
/**
|
|
7
|
+
* Vite plugins: `decorators()` lowers standard (TC39) decorators such as `@field` / `@component`
|
|
8
|
+
* with esbuild; `buildManifest()` writes the `version.json` the desktop app
|
|
9
|
+
* (`@n3rdw1z4rd/core/electron`) updates itself from.
|
|
10
|
+
*
|
|
11
|
+
* Vite 8 compiles TypeScript with Oxc, which only lowers legacy `experimentalDecorators` and
|
|
12
|
+
* passes standard decorators through untouched — no browser can run that yet. This runs
|
|
13
|
+
* first on any source file that uses a decorator; Oxc then sees plain TS/JS.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* // vite.config.ts
|
|
17
|
+
* import { decorators } from '@n3rdw1z4rd/core/vite';
|
|
18
|
+
* export default defineConfig({ plugins: [decorators()] });
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Requires `esbuild` to be installed alongside Vite. Node-only: not exported from the
|
|
22
|
+
* package root.
|
|
23
|
+
*
|
|
24
|
+
* @packageDocumentation
|
|
25
|
+
* @module @n3rdw1z4rd/core/vite
|
|
26
|
+
*/
|
|
2
27
|
/** @category Build */
|
|
3
28
|
function decorators() {
|
|
4
29
|
const file = /\.[cm]?[jt]sx?$/;
|
|
@@ -35,4 +60,100 @@ function decorators() {
|
|
|
35
60
|
}
|
|
36
61
|
};
|
|
37
62
|
}
|
|
38
|
-
|
|
63
|
+
/**
|
|
64
|
+
* The commit a build is made from, 7 characters: from the environment (`GIT_COMMIT`,
|
|
65
|
+
* `SOURCE_COMMIT`, `COMMIT_SHA` or `GITHUB_SHA`, as Docker builds and CI pass it), else git, else
|
|
66
|
+
* the `.git` folder's own files. Without any of those, `local.HHMM` (UTC), so two builds on one
|
|
67
|
+
* day still differ.
|
|
68
|
+
*
|
|
69
|
+
* @category Build
|
|
70
|
+
*/
|
|
71
|
+
function buildCommit(cwd = process.cwd()) {
|
|
72
|
+
const env = process.env.GIT_COMMIT || process.env.SOURCE_COMMIT || process.env.COMMIT_SHA || process.env.GITHUB_SHA;
|
|
73
|
+
if (env) return env.slice(0, 7);
|
|
74
|
+
try {
|
|
75
|
+
return execSync("git rev-parse --short=7 HEAD", {
|
|
76
|
+
cwd,
|
|
77
|
+
stdio: [
|
|
78
|
+
"ignore",
|
|
79
|
+
"pipe",
|
|
80
|
+
"ignore"
|
|
81
|
+
]
|
|
82
|
+
}).toString().trim();
|
|
83
|
+
} catch {}
|
|
84
|
+
try {
|
|
85
|
+
const git = join(cwd, ".git");
|
|
86
|
+
const head = readFileSync(join(git, "HEAD"), "utf8").trim();
|
|
87
|
+
if (!head.startsWith("ref: ")) return head.slice(0, 7);
|
|
88
|
+
const ref = head.slice(5);
|
|
89
|
+
try {
|
|
90
|
+
return readFileSync(join(git, ref), "utf8").trim().slice(0, 7);
|
|
91
|
+
} catch {}
|
|
92
|
+
const line = readFileSync(join(git, "packed-refs"), "utf8").split("\n").find((l) => l.endsWith(` ${ref}`));
|
|
93
|
+
if (line) return line.slice(0, 7);
|
|
94
|
+
} catch {}
|
|
95
|
+
const now = /* @__PURE__ */ new Date();
|
|
96
|
+
return `local.${String(now.getUTCHours()).padStart(2, "0")}${String(now.getUTCMinutes()).padStart(2, "0")}`;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A build's id: package.json's version and the commit it's built from, e.g. "0.7.0-6ae4707"
|
|
100
|
+
* (letters, digits, dots and dashes only: the desktop app names a folder after it).
|
|
101
|
+
*
|
|
102
|
+
* ```ts
|
|
103
|
+
* // vite.config.ts: the page can show it, too
|
|
104
|
+
* export default defineConfig({ define: { __BUILD_ID__: JSON.stringify(buildId()) }, plugins: [buildManifest()] });
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @category Build
|
|
108
|
+
*/
|
|
109
|
+
function buildId(cwd = process.cwd()) {
|
|
110
|
+
return `${JSON.parse(readFileSync(join(cwd, "package.json"), "utf8")).version ?? "0.0.0"}-${buildCommit(cwd)}`.replace(/[^\w.-]/g, "-");
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Vite plugin: after a build, writes `version.json` into the output folder: the build's id, when
|
|
114
|
+
* it was built, the desktop API level it needs, and every file in it with its size and SHA-256.
|
|
115
|
+
* The desktop app (`@n3rdw1z4rd/core/electron`) reads its own copy to know what it's running, and
|
|
116
|
+
* the site's copy to update itself.
|
|
117
|
+
*
|
|
118
|
+
* @category Build
|
|
119
|
+
*/
|
|
120
|
+
function buildManifest(options = {}) {
|
|
121
|
+
let outDir = resolve("dist");
|
|
122
|
+
let root = process.cwd();
|
|
123
|
+
return {
|
|
124
|
+
name: "n3rdw1z4rd:build-manifest",
|
|
125
|
+
apply: "build",
|
|
126
|
+
configResolved(config) {
|
|
127
|
+
root = config.root;
|
|
128
|
+
outDir = resolve(config.root, config.build.outDir);
|
|
129
|
+
},
|
|
130
|
+
closeBundle(error) {
|
|
131
|
+
if (error || !existsSync(outDir)) return;
|
|
132
|
+
const files = [];
|
|
133
|
+
const walk = (dir) => {
|
|
134
|
+
for (const name of readdirSync(dir)) {
|
|
135
|
+
const full = join(dir, name);
|
|
136
|
+
if (statSync(full).isDirectory()) walk(full);
|
|
137
|
+
else if (full !== join(outDir, "version.json")) {
|
|
138
|
+
const data = readFileSync(full);
|
|
139
|
+
files.push({
|
|
140
|
+
path: relative(outDir, full).split(sep).join("/"),
|
|
141
|
+
size: data.length,
|
|
142
|
+
sha256: createHash("sha256").update(data).digest("hex")
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
walk(outDir);
|
|
148
|
+
files.sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
149
|
+
const manifest = {
|
|
150
|
+
version: options.version ?? buildId(root),
|
|
151
|
+
builtAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
152
|
+
needs: options.needs ?? 1,
|
|
153
|
+
files
|
|
154
|
+
};
|
|
155
|
+
writeFileSync(join(outDir, "version.json"), JSON.stringify(manifest, null, 1));
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export { buildCommit, buildId, buildManifest, decorators };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n3rdw1z4rd/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "core library",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -46,6 +46,18 @@
|
|
|
46
46
|
"default": "./dist/vite.cjs"
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
|
+
"./electron": {
|
|
50
|
+
"import": {
|
|
51
|
+
"types": "./dist/electron/index.d.ts",
|
|
52
|
+
"default": "./dist/electron/index.js"
|
|
53
|
+
},
|
|
54
|
+
"require": {
|
|
55
|
+
"types": "./dist/electron.d.cts",
|
|
56
|
+
"default": "./dist/electron.cjs"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"./electron/preload.cjs": "./dist/electron/preload.cjs",
|
|
60
|
+
"./electron/after-pack.cjs": "./dist/electron/after-pack.cjs",
|
|
49
61
|
"./css/*": "./dist/css/*",
|
|
50
62
|
"./dist/*": "./dist/*",
|
|
51
63
|
"./package.json": "./package.json"
|
|
@@ -63,6 +75,7 @@
|
|
|
63
75
|
"prepublishOnly": "npm test && npm run build",
|
|
64
76
|
"test:browser": "node scripts/test-browser.mjs",
|
|
65
77
|
"test:browser:headless": "node scripts/test-browser-headless.mjs",
|
|
78
|
+
"test:electron": "node scripts/test-electron.mjs",
|
|
66
79
|
"docs": "typedoc",
|
|
67
80
|
"docs:watch": "typedoc --watch"
|
|
68
81
|
},
|
|
@@ -85,7 +98,8 @@
|
|
|
85
98
|
"procedural-generation",
|
|
86
99
|
"pathfinding",
|
|
87
100
|
"voxel",
|
|
88
|
-
"particle-system"
|
|
101
|
+
"particle-system",
|
|
102
|
+
"electron"
|
|
89
103
|
],
|
|
90
104
|
"author": "",
|
|
91
105
|
"license": "MIT",
|
|
@@ -98,15 +112,21 @@
|
|
|
98
112
|
"heap-js": "^2.7.1"
|
|
99
113
|
},
|
|
100
114
|
"peerDependencies": {
|
|
101
|
-
"three": "^0.187.0"
|
|
115
|
+
"three": "^0.187.0",
|
|
116
|
+
"electron": ">=38"
|
|
102
117
|
},
|
|
103
118
|
"peerDependenciesMeta": {
|
|
104
119
|
"three": {
|
|
105
120
|
"optional": true
|
|
121
|
+
},
|
|
122
|
+
"electron": {
|
|
123
|
+
"optional": true
|
|
106
124
|
}
|
|
107
125
|
},
|
|
108
126
|
"devDependencies": {
|
|
127
|
+
"@types/node": "^24.19.4",
|
|
109
128
|
"@types/three": "^0.187.0",
|
|
129
|
+
"electron": "^45.5.0",
|
|
110
130
|
"esbuild": "^0.28.2",
|
|
111
131
|
"playwright-core": "^1.56.1",
|
|
112
132
|
"three": "^0.187.0",
|