vite-plugin-fvtt 0.2.10 → 0.2.12
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/CHANGELOG.md +24 -1
- package/dist/index.mjs +113 -119
- package/package.json +17 -16
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.2.12]
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Switch to oxc for minification when using Vite 8+, falling back to esbuild for older versions.
|
|
10
|
+
- Bump @foundryvtt/foundryvtt-cli to version 3.0.4
|
|
11
|
+
|
|
12
|
+
## [0.2.11]
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Bump @foundryvtt/foundryvtt-cli to version 3.0.3
|
|
17
|
+
- Updated `package.json` for dependencies, for the correct semver ranges.
|
|
18
|
+
|
|
19
|
+
## [0.2.10] - 2026-01-01
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- Bump socket.io to 4.8.3
|
|
24
|
+
|
|
5
25
|
### Fixed
|
|
6
26
|
|
|
7
27
|
- Middleware now returns an empty CSS asset instead of a 404, when Vite handles style injection.
|
|
@@ -151,7 +171,10 @@
|
|
|
151
171
|
|
|
152
172
|
- Initial Release
|
|
153
173
|
|
|
154
|
-
[unreleased]: https://github.com/MatyeusM/vite-plugin-fvtt/compare/v0.2.
|
|
174
|
+
[unreleased]: https://github.com/MatyeusM/vite-plugin-fvtt/compare/v0.2.11...HEAD
|
|
175
|
+
[0.2.12]: https://github.com/MatyeusM/vite-plugin-fvtt/compare/v0.2.11...v0.2.12
|
|
176
|
+
[0.2.11]: https://github.com/MatyeusM/vite-plugin-fvtt/compare/v0.2.10...v0.2.11
|
|
177
|
+
[0.2.10]: https://github.com/MatyeusM/vite-plugin-fvtt/compare/v0.2.9...v0.2.10
|
|
155
178
|
[0.2.9]: https://github.com/MatyeusM/vite-plugin-fvtt/compare/v0.2.8...v0.2.9
|
|
156
179
|
[0.2.8]: https://github.com/MatyeusM/vite-plugin-fvtt/compare/v0.2.7...v0.2.8
|
|
157
180
|
[0.2.7]: https://github.com/MatyeusM/vite-plugin-fvtt/compare/v0.2.6...v0.2.7
|
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { glob } from "tinyglobby";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
|
+
import { mergeConfig, version } from "vite";
|
|
4
5
|
import { compilePack } from "@foundryvtt/foundryvtt-cli";
|
|
5
6
|
import { Server } from "socket.io";
|
|
6
7
|
import { io } from "socket.io-client";
|
|
7
|
-
|
|
8
8
|
//#region src/context.ts
|
|
9
9
|
const context = {};
|
|
10
|
-
|
|
11
10
|
//#endregion
|
|
12
11
|
//#region src/utils/fs-utilities.ts
|
|
13
|
-
async function checkType(p,
|
|
12
|
+
async function checkType(p, isMatching) {
|
|
14
13
|
try {
|
|
15
|
-
return
|
|
14
|
+
return isMatching(await fs.stat(p));
|
|
16
15
|
} catch {
|
|
17
16
|
return false;
|
|
18
17
|
}
|
|
@@ -34,7 +33,6 @@ async function readJson(filePath) {
|
|
|
34
33
|
return;
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
|
-
|
|
38
36
|
//#endregion
|
|
39
37
|
//#region src/config/environment.ts
|
|
40
38
|
function parseEnvironment(content) {
|
|
@@ -62,13 +60,12 @@ async function loadEnvironment() {
|
|
|
62
60
|
}
|
|
63
61
|
return {
|
|
64
62
|
foundryUrl: merged.FOUNDRY_URL,
|
|
65
|
-
foundryPort: Number
|
|
63
|
+
foundryPort: Number(merged.FOUNDRY_PORT)
|
|
66
64
|
};
|
|
67
65
|
}
|
|
68
|
-
|
|
69
66
|
//#endregion
|
|
70
67
|
//#region src/utils/logger.ts
|
|
71
|
-
|
|
68
|
+
const config = { loggerNamespace: "vite-plugin-fvtt" };
|
|
72
69
|
const colors = {
|
|
73
70
|
info: "\x1B[36m",
|
|
74
71
|
warn: "\x1B[33m",
|
|
@@ -76,7 +73,7 @@ const colors = {
|
|
|
76
73
|
};
|
|
77
74
|
const reset = "\x1B[0m";
|
|
78
75
|
function format(level, message) {
|
|
79
|
-
return `${colors[level] ?? ""}[${loggerNamespace}] [${level.toUpperCase()}]${reset} ${message}`;
|
|
76
|
+
return `${colors[level] ?? ""}[${config.loggerNamespace}] [${level.toUpperCase()}]${reset} ${message}`;
|
|
80
77
|
}
|
|
81
78
|
function info(message) {
|
|
82
79
|
console.log(format("info", message));
|
|
@@ -96,7 +93,6 @@ function stringify(message) {
|
|
|
96
93
|
if (message instanceof Error) return message.stack ?? message.message;
|
|
97
94
|
return typeof message === "string" ? message : JSON.stringify(message, void 0, 2);
|
|
98
95
|
}
|
|
99
|
-
|
|
100
96
|
//#endregion
|
|
101
97
|
//#region src/config/foundryvtt-manifest.ts
|
|
102
98
|
async function resolveManifestPath(publicDirectory) {
|
|
@@ -142,20 +138,43 @@ async function loadManifest(config) {
|
|
|
142
138
|
if (!foundPath) fail(`Could not find a manifest file (system.json or module.json) in project root or ${publicDirectory}/.`);
|
|
143
139
|
try {
|
|
144
140
|
return validateManifest(await readJson(foundPath), foundPath);
|
|
145
|
-
} catch (error
|
|
146
|
-
if (error
|
|
147
|
-
fail(`Failed to read manifest at ${foundPath}: ${String(error
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (error instanceof Error) fail(`Failed to read manifest at ${foundPath}: ${error.message}`);
|
|
143
|
+
fail(`Failed to read manifest at ${foundPath}: ${String(error)}`);
|
|
148
144
|
}
|
|
149
145
|
}
|
|
150
|
-
|
|
151
146
|
//#endregion
|
|
152
147
|
//#region src/config/vite-options.ts
|
|
148
|
+
function getViteMajorVersion() {
|
|
149
|
+
try {
|
|
150
|
+
return Number(version.split(".", 1)[0]);
|
|
151
|
+
} catch {
|
|
152
|
+
return 8;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const oxcMinifyOptions = { build: {
|
|
156
|
+
minify: "oxc",
|
|
157
|
+
rollupOptions: { output: { minify: {
|
|
158
|
+
compress: true,
|
|
159
|
+
mangle: false
|
|
160
|
+
} } }
|
|
161
|
+
} };
|
|
162
|
+
const esbuildMinifyOptions = (config) => ({
|
|
163
|
+
build: { minify: "esbuild" },
|
|
164
|
+
esbuild: config.esbuild ?? {
|
|
165
|
+
minifyIdentifiers: false,
|
|
166
|
+
minifySyntax: true,
|
|
167
|
+
minifyWhitespace: true,
|
|
168
|
+
keepNames: true
|
|
169
|
+
}
|
|
170
|
+
});
|
|
153
171
|
function createPartialViteConfig(config) {
|
|
154
172
|
const base = config.base ?? `/${context.manifest?.manifestType}s/${context.manifest?.id}/`;
|
|
155
|
-
const
|
|
156
|
-
const formats =
|
|
157
|
-
const
|
|
158
|
-
|
|
173
|
+
const isUseEsModules = context.manifest?.esmodules.length === 1;
|
|
174
|
+
const formats = isUseEsModules ? ["es"] : ["umd"];
|
|
175
|
+
const isVite8OrAbove = getViteMajorVersion() >= 8;
|
|
176
|
+
const fileName = (isUseEsModules ? context.manifest?.esmodules[0] : context.manifest?.scripts?.[0]) ?? "scripts/bundle.js";
|
|
177
|
+
if (!(isUseEsModules || context.manifest?.scripts?.[0])) warn("No output file specified in manifest, using default \"bundle\" in the \"scripts/\" folder");
|
|
159
178
|
if (!context.manifest?.styles?.length) warn("No CSS file found in manifest");
|
|
160
179
|
const cssFileName = context.manifest?.styles[0] ?? "styles/bundle.css";
|
|
161
180
|
if (!context.manifest?.styles[0]) warn("No output css file specified in manifest, using default \"bundle\" in the \"styles/\" folder");
|
|
@@ -167,7 +186,7 @@ function createPartialViteConfig(config) {
|
|
|
167
186
|
if (!entry) fail("Entry must be specified in lib");
|
|
168
187
|
if (typeof entry !== "string") fail("Only a singular string entry is supported for build.lib.entry");
|
|
169
188
|
const isWatch = process.argv.includes("--watch") || !!config.build?.watch;
|
|
170
|
-
return {
|
|
189
|
+
return mergeConfig({
|
|
171
190
|
base,
|
|
172
191
|
build: {
|
|
173
192
|
emptyOutDir: config.build?.emptyOutDir ?? !isWatch,
|
|
@@ -177,7 +196,6 @@ function createPartialViteConfig(config) {
|
|
|
177
196
|
name: context.manifest?.id ?? "bundle",
|
|
178
197
|
cssFileName: "bundle"
|
|
179
198
|
},
|
|
180
|
-
minify: "esbuild",
|
|
181
199
|
rollupOptions: { output: {
|
|
182
200
|
entryFileNames: fileName,
|
|
183
201
|
assetFileNames: (assetInfo) => {
|
|
@@ -190,19 +208,12 @@ function createPartialViteConfig(config) {
|
|
|
190
208
|
id: context.manifest?.id,
|
|
191
209
|
isSystem: context.manifest?.manifestType === "system"
|
|
192
210
|
} },
|
|
193
|
-
esbuild: config.esbuild ?? {
|
|
194
|
-
minifyIdentifiers: false,
|
|
195
|
-
minifySyntax: true,
|
|
196
|
-
minifyWhitespace: true,
|
|
197
|
-
keepNames: true
|
|
198
|
-
},
|
|
199
211
|
server: {
|
|
200
212
|
port: foundryPort + 1,
|
|
201
213
|
proxy: { [`^(?!${base})`]: `http://${foundryUrl}:${foundryPort}` }
|
|
202
214
|
}
|
|
203
|
-
};
|
|
215
|
+
}, isVite8OrAbove ? oxcMinifyOptions : esbuildMinifyOptions(config));
|
|
204
216
|
}
|
|
205
|
-
|
|
206
217
|
//#endregion
|
|
207
218
|
//#region src/server/trackers/abstract-file-tracker.ts
|
|
208
219
|
var AbstractFileTracker = class {
|
|
@@ -237,7 +248,6 @@ var AbstractFileTracker = class {
|
|
|
237
248
|
}
|
|
238
249
|
}
|
|
239
250
|
};
|
|
240
|
-
|
|
241
251
|
//#endregion
|
|
242
252
|
//#region src/server/trackers/language-tracker.ts
|
|
243
253
|
var LanguageTracker = class extends AbstractFileTracker {
|
|
@@ -250,59 +260,53 @@ var LanguageTracker = class extends AbstractFileTracker {
|
|
|
250
260
|
}
|
|
251
261
|
};
|
|
252
262
|
const languageTracker = new LanguageTracker();
|
|
253
|
-
|
|
254
263
|
//#endregion
|
|
255
264
|
//#region src/utils/path-utilities.ts
|
|
256
|
-
|
|
257
|
-
let _sourceDirectory;
|
|
258
|
-
let _decodedBase;
|
|
259
|
-
let _publicDirectory;
|
|
260
|
-
let _outDirectory;
|
|
261
|
-
let _root;
|
|
265
|
+
const cache = {};
|
|
262
266
|
function getConfig() {
|
|
263
|
-
if (!
|
|
267
|
+
if (!cache.config) {
|
|
264
268
|
const config = context.config;
|
|
265
269
|
if (!config) fail("Path utils can only be called after vite has resolved the config");
|
|
266
|
-
|
|
270
|
+
cache.config = config;
|
|
267
271
|
}
|
|
268
|
-
return
|
|
272
|
+
return cache.config;
|
|
269
273
|
}
|
|
270
274
|
function getDecodedBase() {
|
|
271
|
-
if (!
|
|
275
|
+
if (!cache.decodedBase) {
|
|
272
276
|
const config = getConfig();
|
|
273
|
-
|
|
277
|
+
cache.decodedBase = path.posix.normalize(decodeURI(config.base));
|
|
274
278
|
}
|
|
275
|
-
return
|
|
279
|
+
return cache.decodedBase;
|
|
276
280
|
}
|
|
277
281
|
function getSourceDirectory() {
|
|
278
|
-
if (!
|
|
282
|
+
if (!cache.sourceDirectory) {
|
|
279
283
|
const config = getConfig();
|
|
280
284
|
const segments = path.normalize(config.build.lib.entry.toString()).split(path.sep).filter(Boolean).filter((s) => s !== ".");
|
|
281
285
|
const firstFolder = segments.length > 0 ? segments[0] : ".";
|
|
282
|
-
|
|
286
|
+
cache.sourceDirectory = path.join(config.root, firstFolder);
|
|
283
287
|
}
|
|
284
|
-
return
|
|
288
|
+
return cache.sourceDirectory;
|
|
285
289
|
}
|
|
286
290
|
function getPublicDirectory() {
|
|
287
|
-
if (!
|
|
291
|
+
if (!cache.publicDirectory) {
|
|
288
292
|
const config = getConfig();
|
|
289
|
-
|
|
293
|
+
cache.publicDirectory = path.resolve(config.publicDir);
|
|
290
294
|
}
|
|
291
|
-
return
|
|
295
|
+
return cache.publicDirectory;
|
|
292
296
|
}
|
|
293
297
|
function getOutDirectory() {
|
|
294
|
-
if (!
|
|
298
|
+
if (!cache.outDirectory) {
|
|
295
299
|
const config = getConfig();
|
|
296
|
-
|
|
300
|
+
cache.outDirectory = path.resolve(config.build.outDir);
|
|
297
301
|
}
|
|
298
|
-
return
|
|
302
|
+
return cache.outDirectory;
|
|
299
303
|
}
|
|
300
304
|
function getRoot() {
|
|
301
|
-
if (!
|
|
305
|
+
if (!cache.root) {
|
|
302
306
|
const config = getConfig();
|
|
303
|
-
|
|
307
|
+
cache.root = path.resolve(config.root);
|
|
304
308
|
}
|
|
305
|
-
return
|
|
309
|
+
return cache.root;
|
|
306
310
|
}
|
|
307
311
|
async function getOutDirectoryFile(p) {
|
|
308
312
|
const file = path.join(getOutDirectory(), p);
|
|
@@ -347,14 +351,16 @@ function getLanguageSourcePath(p, lang) {
|
|
|
347
351
|
const finalSegments = path.basename(directory) === lang ? directory : path.join(directory, lang);
|
|
348
352
|
return path.join(getSourceDirectory(), finalSegments);
|
|
349
353
|
}
|
|
350
|
-
|
|
354
|
+
async function findFirstExistingDirectory(directories) {
|
|
355
|
+
for (const directory of directories) if (await directoryExists(directory)) return directory;
|
|
356
|
+
}
|
|
351
357
|
//#endregion
|
|
352
358
|
//#region src/language/loader.ts
|
|
353
|
-
async function getLocalLanguageFiles(lang,
|
|
359
|
+
async function getLocalLanguageFiles(lang, isInOutDirectory = false) {
|
|
354
360
|
const language = context.manifest.languages.find((l) => l.lang === lang);
|
|
355
361
|
if (!language) fail(`Cannot find language "${lang}"`);
|
|
356
362
|
const langPath = language?.path ?? "";
|
|
357
|
-
if (
|
|
363
|
+
if (isInOutDirectory) return [await getOutDirectoryFile(langPath)];
|
|
358
364
|
const publicDirectoryFile = await getPublicDirectoryFile(langPath);
|
|
359
365
|
if (publicDirectoryFile !== "") return [publicDirectoryFile];
|
|
360
366
|
const sourcePath = getLanguageSourcePath(langPath, lang);
|
|
@@ -362,8 +368,8 @@ async function getLocalLanguageFiles(lang, inOutDirectory = false) {
|
|
|
362
368
|
warn(`No language folder found at: ${sourcePath}`);
|
|
363
369
|
return [];
|
|
364
370
|
}
|
|
365
|
-
async function loadLanguage(lang,
|
|
366
|
-
const files = await getLocalLanguageFiles(lang,
|
|
371
|
+
async function loadLanguage(lang, isInOutDirectory = false) {
|
|
372
|
+
const files = await getLocalLanguageFiles(lang, isInOutDirectory);
|
|
367
373
|
const result = /* @__PURE__ */ new Map();
|
|
368
374
|
const reads = files.map(async (file) => {
|
|
369
375
|
try {
|
|
@@ -371,8 +377,8 @@ async function loadLanguage(lang, inOutDirectory = false) {
|
|
|
371
377
|
if (typeof json !== "object" || json === null) throw new Error(`Language file ${file} is not a valid JSON object`);
|
|
372
378
|
languageTracker.addFile(lang, file);
|
|
373
379
|
return [file, json];
|
|
374
|
-
} catch (error
|
|
375
|
-
warn(error
|
|
380
|
+
} catch (error) {
|
|
381
|
+
warn(error);
|
|
376
382
|
return;
|
|
377
383
|
}
|
|
378
384
|
});
|
|
@@ -380,7 +386,6 @@ async function loadLanguage(lang, inOutDirectory = false) {
|
|
|
380
386
|
for (const entry of results) if (entry) result.set(entry[0], entry[1]);
|
|
381
387
|
return result;
|
|
382
388
|
}
|
|
383
|
-
|
|
384
389
|
//#endregion
|
|
385
390
|
//#region src/language/transformer.ts
|
|
386
391
|
function flattenKeys(object, prefix = "") {
|
|
@@ -400,10 +405,10 @@ function expandDotNotationKeys(target, source, depth = 0) {
|
|
|
400
405
|
const parts = key.split(".");
|
|
401
406
|
const lastKey = parts.pop();
|
|
402
407
|
for (const part of parts) {
|
|
403
|
-
if (!(part
|
|
408
|
+
if (!Object.hasOwn(current, part)) current[part] = {};
|
|
404
409
|
current = current[part];
|
|
405
410
|
}
|
|
406
|
-
if (lastKey
|
|
411
|
+
if (Object.hasOwn(current, lastKey)) console.warn(`Warning: Overwriting key "${lastKey}" during transformation.`);
|
|
407
412
|
current[lastKey] = expandDotNotationKeys({}, value, depth + 1);
|
|
408
413
|
}
|
|
409
414
|
return target;
|
|
@@ -413,7 +418,6 @@ function transform(dataMap) {
|
|
|
413
418
|
for (const data of dataMap.values()) expandDotNotationKeys(mergedData, data);
|
|
414
419
|
return mergedData;
|
|
415
420
|
}
|
|
416
|
-
|
|
417
421
|
//#endregion
|
|
418
422
|
//#region src/language/validator.ts
|
|
419
423
|
function getFirstMapValueOrWarn(map, contextDescription) {
|
|
@@ -441,15 +445,14 @@ async function validator() {
|
|
|
441
445
|
const current = getFirstMapValueOrWarn(await loadLanguage(lang.lang, true), `Language "${lang.lang}"`);
|
|
442
446
|
if (!current) continue;
|
|
443
447
|
const currentFlattened = flattenKeys(current);
|
|
444
|
-
const missing = Object.keys(baseFlattened).filter((key) => !(key
|
|
445
|
-
const extra = Object.keys(currentFlattened).filter((key) => !(key
|
|
448
|
+
const missing = Object.keys(baseFlattened).filter((key) => !Object.hasOwn(currentFlattened, key));
|
|
449
|
+
const extra = Object.keys(currentFlattened).filter((key) => !Object.hasOwn(baseFlattened, key));
|
|
446
450
|
info(`Summary for language [${lang.lang}]:`);
|
|
447
451
|
if (missing.length > 0) console.warn(`Missing keys: ${missing.length}`, missing.slice(0, 5));
|
|
448
452
|
if (extra.length > 0) console.warn(`Extra keys: ${extra.length}`, extra.slice(0, 5));
|
|
449
453
|
if (missing.length === 0 && extra.length === 0) console.log(" ✅ All keys match.");
|
|
450
454
|
}
|
|
451
455
|
}
|
|
452
|
-
|
|
453
456
|
//#endregion
|
|
454
457
|
//#region src/packs/compile-packs.ts
|
|
455
458
|
async function compileManifestPacks() {
|
|
@@ -457,11 +460,7 @@ async function compileManifestPacks() {
|
|
|
457
460
|
for (const pack of context.manifest.packs) {
|
|
458
461
|
const sourceCandidates = [path.resolve(getSourceDirectory(), pack.path), path.resolve(getRoot(), pack.path)];
|
|
459
462
|
const destination = path.resolve(getOutDirectory(), pack.path);
|
|
460
|
-
|
|
461
|
-
for (const candidate of sourceCandidates) if (await directoryExists(candidate)) {
|
|
462
|
-
chosenSource = candidate;
|
|
463
|
-
break;
|
|
464
|
-
}
|
|
463
|
+
const chosenSource = await findFirstExistingDirectory(sourceCandidates);
|
|
465
464
|
if (!chosenSource) {
|
|
466
465
|
warn(`Pack path not found for ${pack.path}, skipped.`);
|
|
467
466
|
continue;
|
|
@@ -477,7 +476,6 @@ async function compileManifestPacks() {
|
|
|
477
476
|
info(`Compiled pack ${pack.path} (${hasYaml ? "YAML" : "JSON"}) from ${chosenSource}`);
|
|
478
477
|
}
|
|
479
478
|
}
|
|
480
|
-
|
|
481
479
|
//#endregion
|
|
482
480
|
//#region src/server/trackers/handlebars-tracker.ts
|
|
483
481
|
var HandlebarsTracker = class extends AbstractFileTracker {
|
|
@@ -490,20 +488,18 @@ var HandlebarsTracker = class extends AbstractFileTracker {
|
|
|
490
488
|
}
|
|
491
489
|
};
|
|
492
490
|
const handlebarsTracker = new HandlebarsTracker();
|
|
493
|
-
|
|
494
491
|
//#endregion
|
|
495
492
|
//#region src/server/http-middleware.ts
|
|
496
493
|
function httpMiddlewareHook(server) {
|
|
497
494
|
server.middlewares.use(async (request, response, next) => {
|
|
498
|
-
const config = context.config;
|
|
499
495
|
if (!isFoundryVTTUrl(request.url ?? "")) {
|
|
500
496
|
next();
|
|
501
497
|
return;
|
|
502
498
|
}
|
|
503
|
-
const cssEntryName = config.build.lib.cssFileName;
|
|
499
|
+
const cssEntryName = context.config.build.lib.cssFileName;
|
|
504
500
|
const cssEntry = cssEntryName ? localToFoundryVTTUrl(`${cssEntryName}.css`) : void 0;
|
|
505
501
|
const cssFileName = context.manifest?.styles[0] ?? "styles/bundle.css";
|
|
506
|
-
const cssFile = cssFileName ? localToFoundryVTTUrl(
|
|
502
|
+
const cssFile = cssFileName ? localToFoundryVTTUrl(cssFileName) : void 0;
|
|
507
503
|
const normalizedPath = path.posix.normalize(request.url ?? "");
|
|
508
504
|
if (normalizedPath === cssEntry || normalizedPath == cssFile) {
|
|
509
505
|
info(`Blocking CSS entry to ${request.url}`);
|
|
@@ -522,7 +518,6 @@ function httpMiddlewareHook(server) {
|
|
|
522
518
|
next();
|
|
523
519
|
});
|
|
524
520
|
}
|
|
525
|
-
|
|
526
521
|
//#endregion
|
|
527
522
|
//#region src/server/socket-proxy.ts
|
|
528
523
|
function socketProxy(server) {
|
|
@@ -559,7 +554,6 @@ function socketProxy(server) {
|
|
|
559
554
|
});
|
|
560
555
|
});
|
|
561
556
|
}
|
|
562
|
-
|
|
563
557
|
//#endregion
|
|
564
558
|
//#region src/server/index.ts
|
|
565
559
|
function setupDevelopmentServer(server) {
|
|
@@ -568,7 +562,6 @@ function setupDevelopmentServer(server) {
|
|
|
568
562
|
httpMiddlewareHook(server);
|
|
569
563
|
socketProxy(server);
|
|
570
564
|
}
|
|
571
|
-
|
|
572
565
|
//#endregion
|
|
573
566
|
//#region src/server/hmr-client.ts
|
|
574
567
|
var hmr_client_default = `
|
|
@@ -657,53 +650,55 @@ if (import.meta.hot) {
|
|
|
657
650
|
})
|
|
658
651
|
} else console.error('Vite | HMR is disabled')
|
|
659
652
|
//`;
|
|
660
|
-
|
|
661
653
|
//#endregion
|
|
662
654
|
//#region src/index.ts
|
|
655
|
+
async function generateBundleImpl(pluginContext) {
|
|
656
|
+
for (const file of ["system.json", "module.json"]) {
|
|
657
|
+
const source = path.resolve(file);
|
|
658
|
+
if (!await getPublicDirectoryFile(file) && await fileExists(source)) {
|
|
659
|
+
pluginContext.addWatchFile(source);
|
|
660
|
+
const manifest = await readJson(source);
|
|
661
|
+
pluginContext.emitFile({
|
|
662
|
+
type: "asset",
|
|
663
|
+
fileName: file,
|
|
664
|
+
source: JSON.stringify(manifest, void 0, 2)
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
const languages = context.manifest?.languages ?? [];
|
|
669
|
+
if (languages.length > 0) for (const language of languages) {
|
|
670
|
+
if (await getPublicDirectoryFile(language.path)) continue;
|
|
671
|
+
const langFiles = await getLocalLanguageFiles(language.lang);
|
|
672
|
+
for (const file of langFiles) pluginContext.addWatchFile(file);
|
|
673
|
+
const languageData = transform(await loadLanguage(language.lang));
|
|
674
|
+
pluginContext.emitFile({
|
|
675
|
+
type: "asset",
|
|
676
|
+
fileName: path.join(language.path),
|
|
677
|
+
source: JSON.stringify(languageData, void 0, 2)
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
}
|
|
663
681
|
async function foundryVTTPlugin({ buildPacks = true } = {}) {
|
|
664
682
|
context.env = await loadEnvironment();
|
|
665
|
-
|
|
666
|
-
name
|
|
683
|
+
class FoundryVTTPluginInstance {
|
|
684
|
+
name = "vite-plugin-fvtt";
|
|
685
|
+
configureServer = setupDevelopmentServer;
|
|
667
686
|
async config(config) {
|
|
668
687
|
context.manifest = await loadManifest(config) ?? void 0;
|
|
669
688
|
return createPartialViteConfig(config);
|
|
670
|
-
}
|
|
689
|
+
}
|
|
671
690
|
configResolved(config) {
|
|
672
691
|
context.config = config;
|
|
673
|
-
}
|
|
692
|
+
}
|
|
674
693
|
async generateBundle() {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
if (!await getPublicDirectoryFile(file) && await fileExists(source)) {
|
|
678
|
-
this.addWatchFile(source);
|
|
679
|
-
const manifest = await readJson(source);
|
|
680
|
-
this.emitFile({
|
|
681
|
-
type: "asset",
|
|
682
|
-
fileName: file,
|
|
683
|
-
source: JSON.stringify(manifest, void 0, 2)
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
const languages = context.manifest?.languages ?? [];
|
|
688
|
-
if (languages.length > 0) for (const language of languages) {
|
|
689
|
-
if (await getPublicDirectoryFile(language.path)) continue;
|
|
690
|
-
getLocalLanguageFiles(language.lang).then((langFiles) => {
|
|
691
|
-
for (const file of langFiles) this.addWatchFile(file);
|
|
692
|
-
});
|
|
693
|
-
const languageData = transform(await loadLanguage(language.lang));
|
|
694
|
-
this.emitFile({
|
|
695
|
-
type: "asset",
|
|
696
|
-
fileName: path.join(language.path),
|
|
697
|
-
source: JSON.stringify(languageData, void 0, 2)
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
},
|
|
694
|
+
await generateBundleImpl(this);
|
|
695
|
+
}
|
|
701
696
|
async writeBundle() {
|
|
702
697
|
if (buildPacks) await compileManifestPacks();
|
|
703
|
-
}
|
|
698
|
+
}
|
|
704
699
|
closeBundle() {
|
|
705
700
|
if ((context.manifest?.languages ?? []).length > 0 && context.config?.command === "build") validator();
|
|
706
|
-
}
|
|
701
|
+
}
|
|
707
702
|
load(id) {
|
|
708
703
|
const config = context.config;
|
|
709
704
|
const output = config.build.rollupOptions?.output;
|
|
@@ -711,10 +706,9 @@ async function foundryVTTPlugin({ buildPacks = true } = {}) {
|
|
|
711
706
|
if (Array.isArray(output)) jsFileName = String(output[0].entryFileNames);
|
|
712
707
|
else if (output) jsFileName = String(output.entryFileNames);
|
|
713
708
|
if (id === jsFileName || id === `/${jsFileName}`) return `import '${`/@fs/${path.resolve(config.build.lib.entry)}`}';\n${hmr_client_default}`;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
return new FoundryVTTPluginInstance();
|
|
717
712
|
}
|
|
718
|
-
|
|
719
713
|
//#endregion
|
|
720
|
-
export { foundryVTTPlugin as default };
|
|
714
|
+
export { foundryVTTPlugin as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-fvtt",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "A Vite plugin for module and system development for Foundry VTT",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -35,23 +35,24 @@
|
|
|
35
35
|
"test": "vitest"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@eslint/js": "^
|
|
39
|
-
"@types/node": "^
|
|
40
|
-
"eslint": "^
|
|
41
|
-
"eslint-plugin-sonarjs": "^
|
|
42
|
-
"eslint-plugin-unicorn": "^
|
|
43
|
-
"prettier": "^3.
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"typescript
|
|
47
|
-
"
|
|
48
|
-
"
|
|
38
|
+
"@eslint/js": "^10.0.1",
|
|
39
|
+
"@types/node": "^26.1.0",
|
|
40
|
+
"eslint": "^10.6.0",
|
|
41
|
+
"eslint-plugin-sonarjs": "^4.1.0",
|
|
42
|
+
"eslint-plugin-unicorn": "^70.0.0",
|
|
43
|
+
"prettier": "^3.9.4",
|
|
44
|
+
"rolldown": "^1.1.4",
|
|
45
|
+
"tsdown": "^0.22.3",
|
|
46
|
+
"typescript": "^6.0.3",
|
|
47
|
+
"typescript-eslint": "^8.62.1",
|
|
48
|
+
"vite": "^8.1.3",
|
|
49
|
+
"vitest": "^4.1.10"
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
51
|
-
"@foundryvtt/foundryvtt-cli": "^3.0.
|
|
52
|
-
"socket.io": "^4.8.
|
|
53
|
-
"socket.io-client": "^4.8.
|
|
54
|
-
"tinyglobby": "^0.2.
|
|
52
|
+
"@foundryvtt/foundryvtt-cli": "^3.0.4",
|
|
53
|
+
"socket.io": "^4.8.3",
|
|
54
|
+
"socket.io-client": "^4.8.3",
|
|
55
|
+
"tinyglobby": "^0.2.17"
|
|
55
56
|
},
|
|
56
57
|
"peerDependencies": {
|
|
57
58
|
"vite": "^7.0.0"
|