-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts.timestamp-1718123043801-c8212ac45b906.mjs
1281 lines (1260 loc) · 183 KB
/
vite.config.ts.timestamp-1718123043801-c8212ac45b906.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// vite.generated.ts
import path from "path";
import { existsSync as existsSync5, mkdirSync as mkdirSync2, readdirSync as readdirSync2, readFileSync as readFileSync4, writeFileSync as writeFileSync2 } from "fs";
import { createHash } from "crypto";
import * as net from "net";
// target/plugins/application-theme-plugin/theme-handle.js
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
import { resolve as resolve3 } from "path";
// target/plugins/application-theme-plugin/theme-generator.js
import { globSync as globSync2 } from "file:///C:/Users/Druglord/Documents/web%20apps/attendance/node_modules/glob/dist/mjs/index.js";
import { resolve as resolve2, basename as basename2 } from "path";
import { existsSync as existsSync2, readFileSync, writeFileSync } from "fs";
// target/plugins/application-theme-plugin/theme-copy.js
import { readdirSync, statSync, mkdirSync, existsSync, copyFileSync } from "fs";
import { resolve, basename, relative, extname } from "path";
import { globSync } from "file:///C:/Users/Druglord/Documents/web%20apps/attendance/node_modules/glob/dist/mjs/index.js";
var ignoredFileExtensions = [".css", ".js", ".json"];
function copyThemeResources(themeFolder2, projectStaticAssetsOutputFolder, logger) {
const staticAssetsThemeFolder = resolve(projectStaticAssetsOutputFolder, "themes", basename(themeFolder2));
const collection = collectFolders(themeFolder2, logger);
if (collection.files.length > 0) {
mkdirSync(staticAssetsThemeFolder, { recursive: true });
collection.directories.forEach((directory) => {
const relativeDirectory = relative(themeFolder2, directory);
const targetDirectory = resolve(staticAssetsThemeFolder, relativeDirectory);
mkdirSync(targetDirectory, { recursive: true });
});
collection.files.forEach((file) => {
const relativeFile = relative(themeFolder2, file);
const targetFile = resolve(staticAssetsThemeFolder, relativeFile);
copyFileIfAbsentOrNewer(file, targetFile, logger);
});
}
}
function collectFolders(folderToCopy, logger) {
const collection = { directories: [], files: [] };
logger.trace("files in directory", readdirSync(folderToCopy));
readdirSync(folderToCopy).forEach((file) => {
const fileToCopy = resolve(folderToCopy, file);
try {
if (statSync(fileToCopy).isDirectory()) {
logger.debug("Going through directory", fileToCopy);
const result = collectFolders(fileToCopy, logger);
if (result.files.length > 0) {
collection.directories.push(fileToCopy);
logger.debug("Adding directory", fileToCopy);
collection.directories.push.apply(collection.directories, result.directories);
collection.files.push.apply(collection.files, result.files);
}
} else if (!ignoredFileExtensions.includes(extname(fileToCopy))) {
logger.debug("Adding file", fileToCopy);
collection.files.push(fileToCopy);
}
} catch (error) {
handleNoSuchFileError(fileToCopy, error, logger);
}
});
return collection;
}
function copyStaticAssets(themeName, themeProperties, projectStaticAssetsOutputFolder, logger) {
const assets = themeProperties["assets"];
if (!assets) {
logger.debug("no assets to handle no static assets were copied");
return;
}
mkdirSync(projectStaticAssetsOutputFolder, {
recursive: true
});
const missingModules = checkModules(Object.keys(assets));
if (missingModules.length > 0) {
throw Error(
"Missing npm modules '" + missingModules.join("', '") + "' for assets marked in 'theme.json'.\nInstall package(s) by adding a @NpmPackage annotation or install it using 'npm/pnpm/bun i'"
);
}
Object.keys(assets).forEach((module) => {
const copyRules = assets[module];
Object.keys(copyRules).forEach((copyRule) => {
const nodeSources = resolve("node_modules/", module, copyRule);
const files = globSync(nodeSources, { nodir: true });
const targetFolder = resolve(projectStaticAssetsOutputFolder, "themes", themeName, copyRules[copyRule]);
mkdirSync(targetFolder, {
recursive: true
});
files.forEach((file) => {
const copyTarget = resolve(targetFolder, basename(file));
copyFileIfAbsentOrNewer(file, copyTarget, logger);
});
});
});
}
function checkModules(modules) {
const missing = [];
modules.forEach((module) => {
if (!existsSync(resolve("node_modules/", module))) {
missing.push(module);
}
});
return missing;
}
function copyFileIfAbsentOrNewer(fileToCopy, copyTarget, logger) {
try {
if (!existsSync(copyTarget) || statSync(copyTarget).mtime < statSync(fileToCopy).mtime) {
logger.trace("Copying: ", fileToCopy, "=>", copyTarget);
copyFileSync(fileToCopy, copyTarget);
}
} catch (error) {
handleNoSuchFileError(fileToCopy, error, logger);
}
}
function handleNoSuchFileError(file, error, logger) {
if (error.code === "ENOENT") {
logger.warn("Ignoring not existing file " + file + ". File may have been deleted during theme processing.");
} else {
throw error;
}
}
// target/plugins/application-theme-plugin/theme-generator.js
var themeComponentsFolder = "components";
var documentCssFilename = "document.css";
var stylesCssFilename = "styles.css";
var CSSIMPORT_COMMENT = "CSSImport end";
var headerImport = `import 'construct-style-sheets-polyfill';
`;
function writeThemeFiles(themeFolder2, themeName, themeProperties, options) {
const productionMode = !options.devMode;
const useDevServerOrInProductionMode = !options.useDevBundle;
const outputFolder = options.frontendGeneratedFolder;
const styles = resolve2(themeFolder2, stylesCssFilename);
const documentCssFile = resolve2(themeFolder2, documentCssFilename);
const autoInjectComponents = themeProperties.autoInjectComponents ?? true;
const globalFilename = "theme-" + themeName + ".global.generated.js";
const componentsFilename = "theme-" + themeName + ".components.generated.js";
const themeFilename = "theme-" + themeName + ".generated.js";
let themeFileContent = headerImport;
let globalImportContent = "// When this file is imported, global styles are automatically applied\n";
let componentsFileContent = "";
var componentsFiles;
if (autoInjectComponents) {
componentsFiles = globSync2("*.css", {
cwd: resolve2(themeFolder2, themeComponentsFolder),
nodir: true
});
if (componentsFiles.length > 0) {
componentsFileContent += "import { unsafeCSS, registerStyles } from '@vaadin/vaadin-themable-mixin/register-styles';\n";
}
}
if (themeProperties.parent) {
themeFileContent += `import { applyTheme as applyBaseTheme } from './theme-${themeProperties.parent}.generated.js';
`;
}
themeFileContent += `import { injectGlobalCss } from 'Frontend/generated/jar-resources/theme-util.js';
`;
themeFileContent += `import './${componentsFilename}';
`;
themeFileContent += `let needsReloadOnChanges = false;
`;
const imports = [];
const componentCssImports = [];
const globalFileContent = [];
const globalCssCode = [];
const shadowOnlyCss = [];
const componentCssCode = [];
const parentTheme = themeProperties.parent ? "applyBaseTheme(target);\n" : "";
const parentThemeGlobalImport = themeProperties.parent ? `import './theme-${themeProperties.parent}.global.generated.js';
` : "";
const themeIdentifier = "_vaadintheme_" + themeName + "_";
const lumoCssFlag = "_vaadinthemelumoimports_";
const globalCssFlag = themeIdentifier + "globalCss";
const componentCssFlag = themeIdentifier + "componentCss";
if (!existsSync2(styles)) {
if (productionMode) {
throw new Error(`styles.css file is missing and is needed for '${themeName}' in folder '${themeFolder2}'`);
}
writeFileSync(
styles,
"/* Import your application global css files here or add the styles directly to this file */",
"utf8"
);
}
let filename = basename2(styles);
let variable = camelCase(filename);
const lumoImports = themeProperties.lumoImports || ["color", "typography"];
if (lumoImports) {
lumoImports.forEach((lumoImport) => {
imports.push(`import { ${lumoImport} } from '@vaadin/vaadin-lumo-styles/${lumoImport}.js';
`);
if (lumoImport === "utility" || lumoImport === "badge" || lumoImport === "typography" || lumoImport === "color") {
imports.push(`import '@vaadin/vaadin-lumo-styles/${lumoImport}-global.js';
`);
}
});
lumoImports.forEach((lumoImport) => {
shadowOnlyCss.push(`removers.push(injectGlobalCss(${lumoImport}.cssText, '', target, true));
`);
});
}
if (useDevServerOrInProductionMode) {
globalFileContent.push(parentThemeGlobalImport);
globalFileContent.push(`import 'themes/${themeName}/${filename}';
`);
imports.push(`import ${variable} from 'themes/${themeName}/${filename}?inline';
`);
shadowOnlyCss.push(`removers.push(injectGlobalCss(${variable}.toString(), '', target));
`);
}
if (existsSync2(documentCssFile)) {
filename = basename2(documentCssFile);
variable = camelCase(filename);
if (useDevServerOrInProductionMode) {
globalFileContent.push(`import 'themes/${themeName}/${filename}';
`);
imports.push(`import ${variable} from 'themes/${themeName}/${filename}?inline';
`);
shadowOnlyCss.push(`removers.push(injectGlobalCss(${variable}.toString(),'', document));
`);
}
}
let i = 0;
if (themeProperties.documentCss) {
const missingModules = checkModules(themeProperties.documentCss);
if (missingModules.length > 0) {
throw Error(
"Missing npm modules or files '" + missingModules.join("', '") + "' for documentCss marked in 'theme.json'.\nInstall or update package(s) by adding a @NpmPackage annotation or install it using 'npm/pnpm/bun i'"
);
}
themeProperties.documentCss.forEach((cssImport) => {
const variable2 = "module" + i++;
imports.push(`import ${variable2} from '${cssImport}?inline';
`);
globalCssCode.push(`if(target !== document) {
removers.push(injectGlobalCss(${variable2}.toString(), '', target));
}
`);
globalCssCode.push(
`removers.push(injectGlobalCss(${variable2}.toString(), '${CSSIMPORT_COMMENT}', document));
`
);
});
}
if (themeProperties.importCss) {
const missingModules = checkModules(themeProperties.importCss);
if (missingModules.length > 0) {
throw Error(
"Missing npm modules or files '" + missingModules.join("', '") + "' for importCss marked in 'theme.json'.\nInstall or update package(s) by adding a @NpmPackage annotation or install it using 'npm/pnpm/bun i'"
);
}
themeProperties.importCss.forEach((cssPath) => {
const variable2 = "module" + i++;
globalFileContent.push(`import '${cssPath}';
`);
imports.push(`import ${variable2} from '${cssPath}?inline';
`);
shadowOnlyCss.push(`removers.push(injectGlobalCss(${variable2}.toString(), '${CSSIMPORT_COMMENT}', target));
`);
});
}
if (autoInjectComponents) {
componentsFiles.forEach((componentCss) => {
const filename2 = basename2(componentCss);
const tag = filename2.replace(".css", "");
const variable2 = camelCase(filename2);
componentCssImports.push(
`import ${variable2} from 'themes/${themeName}/${themeComponentsFolder}/${filename2}?inline';
`
);
const componentString = `registerStyles(
'${tag}',
unsafeCSS(${variable2}.toString())
);
`;
componentCssCode.push(componentString);
});
}
themeFileContent += imports.join("");
const themeFileApply = `
let themeRemovers = new WeakMap();
let targets = [];
export const applyTheme = (target) => {
const removers = [];
if (target !== document) {
${shadowOnlyCss.join("")}
}
${parentTheme}
${globalCssCode.join("")}
if (import.meta.hot) {
targets.push(new WeakRef(target));
themeRemovers.set(target, removers);
}
}
`;
componentsFileContent += `
${componentCssImports.join("")}
if (!document['${componentCssFlag}']) {
${componentCssCode.join("")}
document['${componentCssFlag}'] = true;
}
if (import.meta.hot) {
import.meta.hot.accept((module) => {
window.location.reload();
});
}
`;
themeFileContent += themeFileApply;
themeFileContent += `
if (import.meta.hot) {
import.meta.hot.accept((module) => {
if (needsReloadOnChanges) {
window.location.reload();
} else {
targets.forEach(targetRef => {
const target = targetRef.deref();
if (target) {
themeRemovers.get(target).forEach(remover => remover())
module.applyTheme(target);
}
})
}
});
import.meta.hot.on('vite:afterUpdate', (update) => {
document.dispatchEvent(new CustomEvent('vaadin-theme-updated', { detail: update }));
});
}
`;
globalImportContent += `
${globalFileContent.join("")}
`;
writeIfChanged(resolve2(outputFolder, globalFilename), globalImportContent);
writeIfChanged(resolve2(outputFolder, themeFilename), themeFileContent);
writeIfChanged(resolve2(outputFolder, componentsFilename), componentsFileContent);
}
function writeIfChanged(file, data) {
if (!existsSync2(file) || readFileSync(file, { encoding: "utf-8" }) !== data) {
writeFileSync(file, data);
}
}
function camelCase(str) {
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
return index === 0 ? word.toLowerCase() : word.toUpperCase();
}).replace(/\s+/g, "").replace(/\.|\-/g, "");
}
// target/plugins/application-theme-plugin/theme-handle.js
var nameRegex = /theme-(.*)\.generated\.js/;
var prevThemeName = void 0;
var firstThemeName = void 0;
function processThemeResources(options, logger) {
const themeName = extractThemeName(options.frontendGeneratedFolder);
if (themeName) {
if (!prevThemeName && !firstThemeName) {
firstThemeName = themeName;
} else if (prevThemeName && prevThemeName !== themeName && firstThemeName !== themeName || !prevThemeName && firstThemeName !== themeName) {
const warning = `Attention: Active theme is switched to '${themeName}'.`;
const description = `
Note that adding new style sheet files to '/themes/${themeName}/components',
may not be taken into effect until the next application restart.
Changes to already existing style sheet files are being reloaded as before.`;
logger.warn("*******************************************************************");
logger.warn(warning);
logger.warn(description);
logger.warn("*******************************************************************");
}
prevThemeName = themeName;
findThemeFolderAndHandleTheme(themeName, options, logger);
} else {
prevThemeName = void 0;
logger.debug("Skipping Vaadin application theme handling.");
logger.trace("Most likely no @Theme annotation for application or only themeClass used.");
}
}
function findThemeFolderAndHandleTheme(themeName, options, logger) {
let themeFound = false;
for (let i = 0; i < options.themeProjectFolders.length; i++) {
const themeProjectFolder = options.themeProjectFolders[i];
if (existsSync3(themeProjectFolder)) {
logger.debug("Searching themes folder '" + themeProjectFolder + "' for theme '" + themeName + "'");
const handled = handleThemes(themeName, themeProjectFolder, options, logger);
if (handled) {
if (themeFound) {
throw new Error(
"Found theme files in '" + themeProjectFolder + "' and '" + themeFound + "'. Theme should only be available in one folder"
);
}
logger.debug("Found theme files from '" + themeProjectFolder + "'");
themeFound = themeProjectFolder;
}
}
}
if (existsSync3(options.themeResourceFolder)) {
if (themeFound && existsSync3(resolve3(options.themeResourceFolder, themeName))) {
throw new Error(
"Theme '" + themeName + `'should not exist inside a jar and in the project at the same time
Extending another theme is possible by adding { "parent": "my-parent-theme" } entry to the theme.json file inside your theme folder.`
);
}
logger.debug(
"Searching theme jar resource folder '" + options.themeResourceFolder + "' for theme '" + themeName + "'"
);
handleThemes(themeName, options.themeResourceFolder, options, logger);
themeFound = true;
}
return themeFound;
}
function handleThemes(themeName, themesFolder, options, logger) {
const themeFolder2 = resolve3(themesFolder, themeName);
if (existsSync3(themeFolder2)) {
logger.debug("Found theme ", themeName, " in folder ", themeFolder2);
const themeProperties = getThemeProperties(themeFolder2);
if (themeProperties.parent) {
const found = findThemeFolderAndHandleTheme(themeProperties.parent, options, logger);
if (!found) {
throw new Error(
"Could not locate files for defined parent theme '" + themeProperties.parent + "'.\nPlease verify that dependency is added or theme folder exists."
);
}
}
copyStaticAssets(themeName, themeProperties, options.projectStaticAssetsOutputFolder, logger);
copyThemeResources(themeFolder2, options.projectStaticAssetsOutputFolder, logger);
writeThemeFiles(themeFolder2, themeName, themeProperties, options);
return true;
}
return false;
}
function getThemeProperties(themeFolder2) {
const themePropertyFile = resolve3(themeFolder2, "theme.json");
if (!existsSync3(themePropertyFile)) {
return {};
}
const themePropertyFileAsString = readFileSync2(themePropertyFile);
if (themePropertyFileAsString.length === 0) {
return {};
}
return JSON.parse(themePropertyFileAsString);
}
function extractThemeName(frontendGeneratedFolder) {
if (!frontendGeneratedFolder) {
throw new Error(
"Couldn't extract theme name from 'theme.js', because the path to folder containing this file is empty. Please set the a correct folder path in ApplicationThemePlugin constructor parameters."
);
}
const generatedThemeFile = resolve3(frontendGeneratedFolder, "theme.js");
if (existsSync3(generatedThemeFile)) {
const themeName = nameRegex.exec(readFileSync2(generatedThemeFile, { encoding: "utf8" }))[1];
if (!themeName) {
throw new Error("Couldn't parse theme name from '" + generatedThemeFile + "'.");
}
return themeName;
} else {
return "";
}
}
// target/plugins/theme-loader/theme-loader-utils.js
import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
import { resolve as resolve4, basename as basename3 } from "path";
import { globSync as globSync3 } from "file:///C:/Users/Druglord/Documents/web%20apps/attendance/node_modules/glob/dist/mjs/index.js";
var urlMatcher = /(url\(\s*)(\'|\")?(\.\/|\.\.\/)(\S*)(\2\s*\))/g;
function assetsContains(fileUrl, themeFolder2, logger) {
const themeProperties = getThemeProperties2(themeFolder2);
if (!themeProperties) {
logger.debug("No theme properties found.");
return false;
}
const assets = themeProperties["assets"];
if (!assets) {
logger.debug("No defined assets in theme properties");
return false;
}
for (let module of Object.keys(assets)) {
const copyRules = assets[module];
for (let copyRule of Object.keys(copyRules)) {
if (fileUrl.startsWith(copyRules[copyRule])) {
const targetFile = fileUrl.replace(copyRules[copyRule], "");
const files = globSync3(resolve4("node_modules/", module, copyRule), { nodir: true });
for (let file of files) {
if (file.endsWith(targetFile))
return true;
}
}
}
}
return false;
}
function getThemeProperties2(themeFolder2) {
const themePropertyFile = resolve4(themeFolder2, "theme.json");
if (!existsSync4(themePropertyFile)) {
return {};
}
const themePropertyFileAsString = readFileSync3(themePropertyFile);
if (themePropertyFileAsString.length === 0) {
return {};
}
return JSON.parse(themePropertyFileAsString);
}
function rewriteCssUrls(source, handledResourceFolder, themeFolder2, logger, options) {
source = source.replace(urlMatcher, function(match, url, quoteMark, replace2, fileUrl, endString) {
let absolutePath = resolve4(handledResourceFolder, replace2, fileUrl);
const existingThemeResource = absolutePath.startsWith(themeFolder2) && existsSync4(absolutePath);
if (existingThemeResource || assetsContains(fileUrl, themeFolder2, logger)) {
const replacement = options.devMode ? "./" : "../static/";
const skipLoader = existingThemeResource ? "" : replacement;
const frontendThemeFolder = skipLoader + "themes/" + basename3(themeFolder2);
logger.debug(
"Updating url for file",
"'" + replace2 + fileUrl + "'",
"to use",
"'" + frontendThemeFolder + "/" + fileUrl + "'"
);
const pathResolved = absolutePath.substring(themeFolder2.length).replace(/\\/g, "/");
return url + (quoteMark ?? "") + frontendThemeFolder + pathResolved + endString;
} else if (options.devMode) {
logger.log("No rewrite for '", match, "' as the file was not found.");
} else {
return url + (quoteMark ?? "") + "../../" + fileUrl + endString;
}
return match;
});
return source;
}
// target/vaadin-dev-server-settings.json
var vaadin_dev_server_settings_default = {
frontendFolder: "C:/Users/Druglord/Documents/web apps/attendance/frontend",
themeFolder: "themes",
themeResourceFolder: "C:/Users/Druglord/Documents/web apps/attendance/frontend/generated/jar-resources",
staticOutput: "C:/Users/Druglord/Documents/web apps/attendance/target/classes/META-INF/VAADIN/webapp/VAADIN/static",
generatedFolder: "generated",
statsOutput: "C:\\Users\\Druglord\\Documents\\web apps\\attendance\\target\\classes\\META-INF\\VAADIN\\config",
frontendBundleOutput: "C:\\Users\\Druglord\\Documents\\web apps\\attendance\\target\\classes\\META-INF\\VAADIN\\webapp",
devBundleOutput: "C:/Users/Druglord/Documents/web apps/attendance/target/dev-bundle/webapp",
devBundleStatsOutput: "C:/Users/Druglord/Documents/web apps/attendance/target/dev-bundle/config",
jarResourcesFolder: "C:/Users/Druglord/Documents/web apps/attendance/frontend/generated/jar-resources",
themeName: "attendance",
clientServiceWorkerSource: "C:\\Users\\Druglord\\Documents\\web apps\\attendance\\target\\sw.ts",
pwaEnabled: true,
offlineEnabled: true,
offlinePath: "'offline.html'"
};
// vite.generated.ts
import {
defineConfig,
mergeConfig
} from "file:///C:/Users/Druglord/Documents/web%20apps/attendance/node_modules/vite/dist/node/index.js";
import { getManifest } from "file:///C:/Users/Druglord/Documents/web%20apps/attendance/node_modules/workbox-build/build/index.js";
import * as rollup from "file:///C:/Users/Druglord/Documents/web%20apps/attendance/node_modules/rollup/dist/es/rollup.js";
import brotli from "file:///C:/Users/Druglord/Documents/web%20apps/attendance/node_modules/rollup-plugin-brotli/lib/index.cjs.js";
import replace from "file:///C:/Users/Druglord/Documents/web%20apps/attendance/node_modules/@rollup/plugin-replace/dist/es/index.js";
import checker from "file:///C:/Users/Druglord/Documents/web%20apps/attendance/node_modules/vite-plugin-checker/dist/esm/main.js";
// target/plugins/rollup-plugin-postcss-lit-custom/rollup-plugin-postcss-lit.js
import { createFilter } from "file:///C:/Users/Druglord/Documents/web%20apps/attendance/node_modules/@rollup/pluginutils/dist/es/index.js";
import transformAst from "file:///C:/Users/Druglord/Documents/web%20apps/attendance/node_modules/transform-ast/index.js";
var assetUrlRE = /__VITE_ASSET__([\w$]+)__(?:\$_(.*?)__)?/g;
var escape = (str) => str.replace(assetUrlRE, '${unsafeCSSTag("__VITE_ASSET__$1__$2")}').replace(/`/g, "\\`").replace(/\\(?!`)/g, "\\\\");
function postcssLit(options = {}) {
const defaultOptions = {
include: "**/*.{css,sss,pcss,styl,stylus,sass,scss,less}",
exclude: null,
importPackage: "lit"
};
const opts = { ...defaultOptions, ...options };
const filter = createFilter(opts.include, opts.exclude);
return {
name: "postcss-lit",
enforce: "post",
transform(code, id) {
if (!filter(id))
return;
const ast = this.parse(code, {});
let defaultExportName;
let isDeclarationLiteral = false;
const magicString = transformAst(code, { ast }, (node) => {
if (node.type === "ExportDefaultDeclaration") {
defaultExportName = node.declaration.name;
isDeclarationLiteral = node.declaration.type === "Literal";
}
});
if (!defaultExportName && !isDeclarationLiteral) {
return;
}
magicString.walk((node) => {
if (defaultExportName && node.type === "VariableDeclaration") {
const exportedVar = node.declarations.find((d) => d.id.name === defaultExportName);
if (exportedVar) {
exportedVar.init.edit.update(`cssTag\`${escape(exportedVar.init.value)}\``);
}
}
if (isDeclarationLiteral && node.type === "ExportDefaultDeclaration") {
node.declaration.edit.update(`cssTag\`${escape(node.declaration.value)}\``);
}
});
magicString.prepend(`import {css as cssTag, unsafeCSS as unsafeCSSTag} from '${opts.importPackage}';
`);
return {
code: magicString.toString(),
map: magicString.generateMap({
hires: true
})
};
}
};
}
// vite.generated.ts
import { createRequire } from "module";
import { visualizer } from "file:///C:/Users/Druglord/Documents/web%20apps/attendance/node_modules/rollup-plugin-visualizer/dist/plugin/index.js";
var __vite_injected_original_dirname = "C:\\Users\\Druglord\\Documents\\web apps\\attendance";
var __vite_injected_original_import_meta_url = "file:///C:/Users/Druglord/Documents/web%20apps/attendance/vite.generated.ts";
var require2 = createRequire(__vite_injected_original_import_meta_url);
var appShellUrl = ".";
var frontendFolder = path.resolve(__vite_injected_original_dirname, vaadin_dev_server_settings_default.frontendFolder);
var themeFolder = path.resolve(frontendFolder, vaadin_dev_server_settings_default.themeFolder);
var frontendBundleFolder = path.resolve(__vite_injected_original_dirname, vaadin_dev_server_settings_default.frontendBundleOutput);
var devBundleFolder = path.resolve(__vite_injected_original_dirname, vaadin_dev_server_settings_default.devBundleOutput);
var devBundle = !!process.env.devBundle;
var jarResourcesFolder = path.resolve(__vite_injected_original_dirname, vaadin_dev_server_settings_default.jarResourcesFolder);
var themeResourceFolder = path.resolve(__vite_injected_original_dirname, vaadin_dev_server_settings_default.themeResourceFolder);
var projectPackageJsonFile = path.resolve(__vite_injected_original_dirname, "package.json");
var buildOutputFolder = devBundle ? devBundleFolder : frontendBundleFolder;
var statsFolder = path.resolve(__vite_injected_original_dirname, devBundle ? vaadin_dev_server_settings_default.devBundleStatsOutput : vaadin_dev_server_settings_default.statsOutput);
var statsFile = path.resolve(statsFolder, "stats.json");
var bundleSizeFile = path.resolve(statsFolder, "bundle-size.html");
var nodeModulesFolder = path.resolve(__vite_injected_original_dirname, "node_modules");
var webComponentTags = "";
var projectIndexHtml = path.resolve(frontendFolder, "index.html");
var projectStaticAssetsFolders = [
path.resolve(__vite_injected_original_dirname, "src", "main", "resources", "META-INF", "resources"),
path.resolve(__vite_injected_original_dirname, "src", "main", "resources", "static"),
frontendFolder
];
var themeProjectFolders = projectStaticAssetsFolders.map((folder) => path.resolve(folder, vaadin_dev_server_settings_default.themeFolder));
var themeOptions = {
devMode: false,
useDevBundle: devBundle,
// The following matches folder 'frontend/generated/themes/'
// (not 'frontend/themes') for theme in JAR that is copied there
themeResourceFolder: path.resolve(themeResourceFolder, vaadin_dev_server_settings_default.themeFolder),
themeProjectFolders,
projectStaticAssetsOutputFolder: devBundle ? path.resolve(devBundleFolder, "../assets") : path.resolve(__vite_injected_original_dirname, vaadin_dev_server_settings_default.staticOutput),
frontendGeneratedFolder: path.resolve(frontendFolder, vaadin_dev_server_settings_default.generatedFolder)
};
var hasExportedWebComponents = existsSync5(path.resolve(frontendFolder, "web-component.html"));
console.trace = () => {
};
console.debug = () => {
};
function injectManifestToSWPlugin() {
const rewriteManifestIndexHtmlUrl = (manifest) => {
const indexEntry = manifest.find((entry) => entry.url === "index.html");
if (indexEntry) {
indexEntry.url = appShellUrl;
}
return { manifest, warnings: [] };
};
return {
name: "vaadin:inject-manifest-to-sw",
async transform(code, id) {
if (/sw\.(ts|js)$/.test(id)) {
const { manifestEntries } = await getManifest({
globDirectory: buildOutputFolder,
globPatterns: ["**/*"],
globIgnores: ["**/*.br"],
manifestTransforms: [rewriteManifestIndexHtmlUrl],
maximumFileSizeToCacheInBytes: 100 * 1024 * 1024
// 100mb,
});
return code.replace("self.__WB_MANIFEST", JSON.stringify(manifestEntries));
}
}
};
}
function buildSWPlugin(opts) {
let config;
const devMode = opts.devMode;
const swObj = {};
async function build(action, additionalPlugins = []) {
const includedPluginNames = [
"vite:esbuild",
"rollup-plugin-dynamic-import-variables",
"vite:esbuild-transpile",
"vite:terser"
];
const plugins = config.plugins.filter((p) => {
return includedPluginNames.includes(p.name);
});
const resolver = config.createResolver();
const resolvePlugin = {
name: "resolver",
resolveId(source, importer, _options) {
return resolver(source, importer);
}
};
plugins.unshift(resolvePlugin);
plugins.push(
replace({
values: {
"process.env.NODE_ENV": JSON.stringify(config.mode),
...config.define
},
preventAssignment: true
})
);
if (additionalPlugins) {
plugins.push(...additionalPlugins);
}
const bundle = await rollup.rollup({
input: path.resolve(vaadin_dev_server_settings_default.clientServiceWorkerSource),
plugins
});
try {
return await bundle[action]({
file: path.resolve(buildOutputFolder, "sw.js"),
format: "es",
exports: "none",
sourcemap: config.command === "serve" || config.build.sourcemap,
inlineDynamicImports: true
});
} finally {
await bundle.close();
}
}
return {
name: "vaadin:build-sw",
enforce: "post",
async configResolved(resolvedConfig) {
config = resolvedConfig;
},
async buildStart() {
if (devMode) {
const { output } = await build("generate");
swObj.code = output[0].code;
swObj.map = output[0].map;
}
},
async load(id) {
if (id.endsWith("sw.js")) {
return "";
}
},
async transform(_code, id) {
if (id.endsWith("sw.js")) {
return swObj;
}
},
async closeBundle() {
if (!devMode) {
await build("write", [injectManifestToSWPlugin(), brotli()]);
}
}
};
}
function statsExtracterPlugin() {
function collectThemeJsonsInFrontend(themeJsonContents, themeName) {
const themeJson = path.resolve(frontendFolder, vaadin_dev_server_settings_default.themeFolder, themeName, "theme.json");
if (existsSync5(themeJson)) {
const themeJsonContent = readFileSync4(themeJson, { encoding: "utf-8" }).replace(/\r\n/g, "\n");
themeJsonContents[themeName] = themeJsonContent;
const themeJsonObject = JSON.parse(themeJsonContent);
if (themeJsonObject.parent) {
collectThemeJsonsInFrontend(themeJsonContents, themeJsonObject.parent);
}
}
}
return {
name: "vaadin:stats",
enforce: "post",
async writeBundle(options, bundle) {
const modules = Object.values(bundle).flatMap((b) => b.modules ? Object.keys(b.modules) : []);
const nodeModulesFolders = modules.map((id) => id.replace(/\\/g, "/")).filter((id) => id.startsWith(nodeModulesFolder.replace(/\\/g, "/"))).map((id) => id.substring(nodeModulesFolder.length + 1));
const npmModules = nodeModulesFolders.map((id) => id.replace(/\\/g, "/")).map((id) => {
const parts = id.split("/");
if (id.startsWith("@")) {
return parts[0] + "/" + parts[1];
} else {
return parts[0];
}
}).sort().filter((value, index, self) => self.indexOf(value) === index);
const npmModuleAndVersion = Object.fromEntries(npmModules.map((module) => [module, getVersion(module)]));
const cvdls = Object.fromEntries(
npmModules.filter((module) => getCvdlName(module) != null).map((module) => [module, { name: getCvdlName(module), version: getVersion(module) }])
);
mkdirSync2(path.dirname(statsFile), { recursive: true });
const projectPackageJson = JSON.parse(readFileSync4(projectPackageJsonFile, { encoding: "utf-8" }));
const entryScripts = Object.values(bundle).filter((bundle2) => bundle2.isEntry).map((bundle2) => bundle2.fileName);
const generatedIndexHtml = path.resolve(buildOutputFolder, "index.html");
const customIndexData = readFileSync4(projectIndexHtml, { encoding: "utf-8" });
const generatedIndexData = readFileSync4(generatedIndexHtml, {
encoding: "utf-8"
});
const customIndexRows = new Set(customIndexData.split(/[\r\n]/).filter((row) => row.trim() !== ""));
const generatedIndexRows = generatedIndexData.split(/[\r\n]/).filter((row) => row.trim() !== "");
const rowsGenerated = [];
generatedIndexRows.forEach((row) => {
if (!customIndexRows.has(row)) {
rowsGenerated.push(row);
}
});
const parseImports = (filename, result) => {
const content = readFileSync4(filename, { encoding: "utf-8" });
const lines = content.split("\n");
const staticImports = lines.filter((line) => line.startsWith("import ")).map((line) => line.substring(line.indexOf("'") + 1, line.lastIndexOf("'"))).map((line) => line.includes("?") ? line.substring(0, line.lastIndexOf("?")) : line);
const dynamicImports = lines.filter((line) => line.includes("import(")).map((line) => line.replace(/.*import\(/, "")).map((line) => line.split(/'/)[1]).map((line) => line.includes("?") ? line.substring(0, line.lastIndexOf("?")) : line);
staticImports.forEach((staticImport) => result.add(staticImport));
dynamicImports.map((dynamicImport) => {
const importedFile = path.resolve(path.dirname(filename), dynamicImport);
parseImports(importedFile, result);
});
};
const generatedImportsSet = /* @__PURE__ */ new Set();
parseImports(
path.resolve(themeOptions.frontendGeneratedFolder, "flow", "generated-flow-imports.js"),
generatedImportsSet
);
const generatedImports = Array.from(generatedImportsSet).sort();
const frontendFiles = {};
const projectFileExtensions = [".js", ".js.map", ".ts", ".ts.map", ".tsx", ".tsx.map", ".css", ".css.map"];
const isThemeComponentsResource = (id) => id.startsWith(themeOptions.frontendGeneratedFolder.replace(/\\/g, "/")) && id.match(/.*\/jar-resources\/themes\/[^\/]+\/components\//);
modules.map((id) => id.replace(/\\/g, "/")).filter((id) => id.startsWith(frontendFolder.replace(/\\/g, "/"))).filter((id) => !id.startsWith(themeOptions.frontendGeneratedFolder.replace(/\\/g, "/")) || isThemeComponentsResource(id)).map((id) => id.substring(frontendFolder.length + 1)).map((line) => line.includes("?") ? line.substring(0, line.lastIndexOf("?")) : line).forEach((line) => {
const filePath = path.resolve(frontendFolder, line);
if (projectFileExtensions.includes(path.extname(filePath))) {
const fileBuffer = readFileSync4(filePath, { encoding: "utf-8" }).replace(/\r\n/g, "\n");
frontendFiles[line] = createHash("sha256").update(fileBuffer, "utf8").digest("hex");
}
});
generatedImports.filter((line) => line.includes("generated/jar-resources")).forEach((line) => {
let filename = line.substring(line.indexOf("generated"));
const fileBuffer = readFileSync4(path.resolve(frontendFolder, filename), { encoding: "utf-8" }).replace(
/\r\n/g,
"\n"
);
const hash = createHash("sha256").update(fileBuffer, "utf8").digest("hex");
const fileKey = line.substring(line.indexOf("jar-resources/") + 14);
frontendFiles[fileKey] = hash;
});
if (existsSync5(path.resolve(frontendFolder, "index.ts"))) {
const fileBuffer = readFileSync4(path.resolve(frontendFolder, "index.ts"), { encoding: "utf-8" }).replace(
/\r\n/g,
"\n"
);
frontendFiles[`index.ts`] = createHash("sha256").update(fileBuffer, "utf8").digest("hex");
}
const themeJsonContents = {};
const themesFolder = path.resolve(jarResourcesFolder, "themes");
if (existsSync5(themesFolder)) {
readdirSync2(themesFolder).forEach((themeFolder2) => {
const themeJson = path.resolve(themesFolder, themeFolder2, "theme.json");
if (existsSync5(themeJson)) {
themeJsonContents[path.basename(themeFolder2)] = readFileSync4(themeJson, { encoding: "utf-8" }).replace(
/\r\n/g,
"\n"
);
}
});
}
collectThemeJsonsInFrontend(themeJsonContents, vaadin_dev_server_settings_default.themeName);
let webComponents = [];
if (webComponentTags) {
webComponents = webComponentTags.split(";");
}
const stats = {
packageJsonDependencies: projectPackageJson.dependencies,
npmModules: npmModuleAndVersion,
bundleImports: generatedImports,
frontendHashes: frontendFiles,
themeJsonContents,
entryScripts,
webComponents,
cvdlModules: cvdls,
packageJsonHash: projectPackageJson?.vaadin?.hash,
indexHtmlGenerated: rowsGenerated
};
writeFileSync2(statsFile, JSON.stringify(stats, null, 1));
}
};
}
function vaadinBundlesPlugin() {
const disabledMessage = "Vaadin component dependency bundles are disabled.";
const modulesDirectory = nodeModulesFolder.replace(/\\/g, "/");
let vaadinBundleJson;
function parseModuleId(id) {
const [scope, scopedPackageName] = id.split("/", 3);
const packageName = scope.startsWith("@") ? `${scope}/${scopedPackageName}` : scope;
const modulePath = `.${id.substring(packageName.length)}`;
return {
packageName,
modulePath
};
}
function getExports(id) {
const { packageName, modulePath } = parseModuleId(id);
const packageInfo = vaadinBundleJson.packages[packageName];
if (!packageInfo)
return;
const exposeInfo = packageInfo.exposes[modulePath];
if (!exposeInfo)
return;
const exportsSet = /* @__PURE__ */ new Set();
for (const e of exposeInfo.exports) {
if (typeof e === "string") {
exportsSet.add(e);
} else {
const { namespace, source } = e;
if (namespace) {
exportsSet.add(namespace);
} else {
const sourceExports = getExports(source);
if (sourceExports) {
sourceExports.forEach((e2) => exportsSet.add(e2));
}
}
}
}
return Array.from(exportsSet);
}
function getExportBinding(binding) {
return binding === "default" ? "_default as default" : binding;
}
function getImportAssigment(binding) {
return binding === "default" ? "default: _default" : binding;
}
return {
name: "vaadin:bundles",
enforce: "pre",
apply(config, { command }) {
if (command !== "serve")
return false;
try {
const vaadinBundleJsonPath = require2.resolve("@vaadin/bundles/vaadin-bundle.json");
vaadinBundleJson = JSON.parse(readFileSync4(vaadinBundleJsonPath, { encoding: "utf8" }));
} catch (e) {
if (typeof e === "object" && e.code === "MODULE_NOT_FOUND") {
vaadinBundleJson = { packages: {} };
console.info(`@vaadin/bundles npm package is not found, ${disabledMessage}`);
return false;
} else {
throw e;
}
}
const versionMismatches = [];
for (const [name, packageInfo] of Object.entries(vaadinBundleJson.packages)) {
let installedVersion = void 0;
try {
const { version: bundledVersion } = packageInfo;
const installedPackageJsonFile = path.resolve(modulesDirectory, name, "package.json");
const packageJson = JSON.parse(readFileSync4(installedPackageJsonFile, { encoding: "utf8" }));
installedVersion = packageJson.version;
if (installedVersion && installedVersion !== bundledVersion) {
versionMismatches.push({
name,
bundledVersion,
installedVersion
});
}
} catch (_) {
}
}
if (versionMismatches.length) {
console.info(`@vaadin/bundles has version mismatches with installed packages, ${disabledMessage}`);
console.info(`Packages with version mismatches: ${JSON.stringify(versionMismatches, void 0, 2)}`);
vaadinBundleJson = { packages: {} };
return false;
}
return true;
},
async config(config) {
return mergeConfig(
{
optimizeDeps: {
exclude: [
// Vaadin bundle
"@vaadin/bundles",
...Object.keys(vaadinBundleJson.packages),
"@vaadin/vaadin-material-styles"
]
}
},
config
);
},
load(rawId) {
const [path2, params] = rawId.split("?");
if (!path2.startsWith(modulesDirectory))
return;
const id = path2.substring(modulesDirectory.length + 1);
const bindings = getExports(id);
if (bindings === void 0)