@windwalker-io/core 4.2.0 → 4.2.2

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.
Files changed (55) hide show
  1. package/LICENSE +19 -19
  2. package/dist/debugger/Dashboard-Bm7ihi81.js +1 -0
  3. package/dist/debugger/Database-BGuRRq-L.js +36 -0
  4. package/dist/debugger/DefaultLayout-DviqbPNR.js +1 -0
  5. package/dist/debugger/Events-CNF6gvg0.js +1 -0
  6. package/dist/debugger/KeyValueTable-BfTkP1Rg.js +1 -0
  7. package/dist/debugger/Request-yQA1-Fkb.js +1 -0
  8. package/dist/debugger/Routing-C5mAPB17.js +1 -0
  9. package/dist/debugger/System-JFuNpoZY.js +1 -0
  10. package/dist/debugger/Timeline-Uii-K9v_.js +1 -0
  11. package/dist/debugger/debugger-ChQADeB6.js +2 -0
  12. package/dist/debugger/debugger.js +564 -0
  13. package/dist/debugger/system.min.js +5 -0
  14. package/dist/debugger/utilities-jMzguz3m.js +1 -0
  15. package/dist/debugger/vue-animate.min-BkEL-t1R.js +9 -0
  16. package/dist/debugger/windwalker-logo-h-w.svg +1 -0
  17. package/dist/debugger-console.css +6 -0
  18. package/dist/next.d.ts +112 -0
  19. package/dist/next.js +576 -0
  20. package/package.json +11 -4
  21. package/src/app/app.ts +43 -0
  22. package/src/asset-bundler.mjs +114 -114
  23. package/src/debugger/types/global.d.js +2 -2
  24. package/src/index.mjs +11 -11
  25. package/src/legacy/4.0/js-sync.mjs +74 -74
  26. package/src/next/fusion/index.ts +2 -2
  27. package/src/next/fusion/plugins/assets.ts +29 -29
  28. package/src/next/fusion/plugins/index.ts +3 -3
  29. package/src/next/fusion/plugins/systemjs.ts +66 -66
  30. package/src/next/fusion/processors/cloneAssets.ts +81 -81
  31. package/src/next/fusion/processors/cssModulize.ts +127 -105
  32. package/src/next/fusion/processors/index.ts +4 -4
  33. package/src/next/fusion/processors/installVendors.ts +178 -178
  34. package/src/next/fusion/processors/jsModulize.ts +293 -296
  35. package/src/next/index.ts +2 -2
  36. package/src/next/utilities/asset-sync.ts +47 -47
  37. package/src/next/utilities/crypto.ts +11 -11
  38. package/src/next/utilities/fs.ts +61 -61
  39. package/src/next/utilities/index.ts +5 -5
  40. package/src/next/utilities/modules.ts +17 -17
  41. package/bin/release.js +0 -47
  42. package/core/index.d.ts +0 -1
  43. package/core/index.html +0 -13
  44. package/core/lib/main.ts +0 -9
  45. package/core/package.json +0 -26
  46. package/core/public/vite.svg +0 -1
  47. package/core/src/main.ts +0 -23
  48. package/core/src/style.css +0 -95
  49. package/core/src/typescript.svg +0 -1
  50. package/core/src/vite-env.d.ts +0 -1
  51. package/postcss.config.js +0 -12
  52. package/tailwind/console.tailwind.config.cjs +0 -32
  53. package/tailwind.config.js +0 -10
  54. package/vite.config.debugger.ts +0 -94
  55. package/vite.config.next.ts +0 -75
package/dist/next.js ADDED
@@ -0,0 +1,576 @@
1
+ import { getGlobBaseFromPattern, callback, css, js, shortHash, plugin, callbackAfterBuild, copyGlob, symlink } from "@windwalker-io/fusion-next";
2
+ import isGlob from "is-glob";
3
+ import micromatch from "micromatch";
4
+ import path, { relative, normalize, resolve } from "node:path";
5
+ import fs from "node:fs";
6
+ import fg from "fast-glob";
7
+ import crypto, { randomBytes } from "node:crypto";
8
+ import { createRequire } from "node:module";
9
+ import fs$1 from "fs-extra";
10
+ import { parse } from "node-html-parser";
11
+ function loadJson(file) {
12
+ if (!fs.existsSync(file)) {
13
+ return null;
14
+ }
15
+ return JSON.parse(fs.readFileSync(file, "utf8"));
16
+ }
17
+ function containsMiddleGlob(str) {
18
+ return isGlob(removeLastGlob(str));
19
+ }
20
+ function removeLastGlob(str) {
21
+ return str.replace(/(\/\*|\/\*\*?|\*\*\/\*?)$/, "");
22
+ }
23
+ const ds = process.platform === "win32" ? "\\" : "/";
24
+ function ensureDirPath(path2, slash = ds) {
25
+ if (!path2.endsWith(slash)) {
26
+ return path2 + slash;
27
+ }
28
+ return path2;
29
+ }
30
+ function findFilesFromGlobArray(sources) {
31
+ let files = [];
32
+ for (const source of sources) {
33
+ files = [
34
+ ...files,
35
+ ...findFiles(source)
36
+ ];
37
+ }
38
+ return files;
39
+ }
40
+ function findFiles(src) {
41
+ return fg.globSync(src).map((file) => {
42
+ file = file.replace(/\\/g, "/");
43
+ return {
44
+ fullpath: file,
45
+ relativePath: relative(getGlobBaseFromPattern(src), file).replace(/\\/g, "/")
46
+ };
47
+ });
48
+ }
49
+ function findModules(suffix = "", rootModule = "src/Module") {
50
+ const pkg = path.resolve(process.cwd(), "composer.json");
51
+ const pkgJson = loadJson(pkg);
52
+ const vendors = Object.keys(pkgJson["require"] || {}).concat(Object.keys(pkgJson["require-dev"] || {})).map((id) => `vendor/${id}/composer.json`).map((file) => loadJson(file)).filter((pkgJson2) => pkgJson2?.extra?.windwalker != null).map((pkgJson2) => {
53
+ return pkgJson2?.extra?.windwalker?.modules?.map((module) => {
54
+ return `vendor/${pkgJson2.name}/${module}/${suffix}`;
55
+ }) || [];
56
+ }).flat();
57
+ if (rootModule) {
58
+ vendors.push(rootModule + "/" + suffix);
59
+ }
60
+ return [...new Set(vendors)];
61
+ }
62
+ function findPackages(suffix = "", withRoot = true) {
63
+ const pkg = path.resolve(process.cwd(), "composer.json");
64
+ const pkgJson = loadJson(pkg);
65
+ const vendors = Object.keys(pkgJson["require"] || {}).concat(Object.keys(pkgJson["require-dev"] || {})).map((id) => `vendor/${id}/composer.json`).map((file) => loadJson(file)).filter((pkgJson2) => pkgJson2?.extra?.windwalker != null).map((pkgJson2) => `vendor/${pkgJson2.name}/${suffix}`).flat();
66
+ if (withRoot) {
67
+ vendors.unshift(suffix);
68
+ }
69
+ return [...new Set(vendors)];
70
+ }
71
+ function uniqId(prefix = "", size = 16) {
72
+ let id = randomBytes(size).toString("hex");
73
+ if (prefix) {
74
+ id = prefix + id;
75
+ }
76
+ return id;
77
+ }
78
+ function resolveModuleRealpath(url, module) {
79
+ const require2 = createRequire(url);
80
+ return require2.resolve(module);
81
+ }
82
+ function stripUrlQuery(src) {
83
+ const qPos = src.indexOf("?");
84
+ if (qPos !== -1) {
85
+ return src.substring(0, qPos);
86
+ }
87
+ return src;
88
+ }
89
+ function cloneAssets(patterns) {
90
+ return callback((taskName, builder) => {
91
+ const reposition = getAvailableForReposition(patterns);
92
+ handleReposition(builder, reposition);
93
+ handleCloneAssets(builder, Object.keys(patterns));
94
+ return null;
95
+ });
96
+ }
97
+ function getAvailableForReposition(patterns) {
98
+ const reposition = {};
99
+ for (const from in patterns) {
100
+ if (!containsMiddleGlob(from)) {
101
+ reposition[from] = patterns[from];
102
+ }
103
+ }
104
+ return reposition;
105
+ }
106
+ function handleCloneAssets(builder, clonePatterns) {
107
+ const id = uniqId("hidden:clone-asset-") + ".js";
108
+ builder.addTask(id);
109
+ builder.resolveIdCallbacks.push((src) => {
110
+ if (src === id) {
111
+ return id;
112
+ }
113
+ });
114
+ builder.loadCallbacks.push((src) => {
115
+ if (src === id) {
116
+ const glob = clonePatterns.map((v) => v.replace(/\\/g, "/")).map((v) => v.startsWith("./") || !v.startsWith("/") ? `/${v}` : v).map((v) => `'${v}'`).join(", ");
117
+ return `import.meta.glob(${glob});
118
+ `;
119
+ }
120
+ });
121
+ }
122
+ function handleReposition(builder, reposition) {
123
+ builder.assetFileNamesCallbacks.push((assetInfo) => {
124
+ const fileName = assetInfo.originalFileName;
125
+ for (const base in reposition) {
126
+ if (match(fileName, base)) {
127
+ return normalize(reposition[base] + relative(removeLastGlob(base), fileName)).replace(/\\/g, "/");
128
+ }
129
+ }
130
+ });
131
+ }
132
+ function match(str, pattern) {
133
+ if (isGlob(pattern)) {
134
+ return micromatch.isMatch(str, pattern);
135
+ }
136
+ return str.startsWith(pattern);
137
+ }
138
+ function globalAssets(options) {
139
+ return {
140
+ name: "core:global-assets",
141
+ buildConfig(builder) {
142
+ const clone = options.clone || {};
143
+ let reposition = options.reposition || {};
144
+ reposition = { ...reposition, ...getAvailableForReposition(clone) };
145
+ handleReposition(builder, reposition);
146
+ const clonePatterns = Object.keys(clone);
147
+ if (clonePatterns.length > 0) {
148
+ handleCloneAssets(builder, clonePatterns);
149
+ }
150
+ }
151
+ };
152
+ }
153
+ function injectSystemJS(systemPath, filter) {
154
+ systemPath ??= resolve("node_modules/systemjs/dist/system.min.js");
155
+ return {
156
+ name: "core:inject-systemjs",
157
+ async generateBundle(options, bundle) {
158
+ if (options.format !== "system") {
159
+ return;
160
+ }
161
+ const systemjsCode = fs$1.readFileSync(
162
+ resolve(systemPath),
163
+ "utf-8"
164
+ );
165
+ for (const file of Object.values(bundle)) {
166
+ if (filter && !filter(file)) {
167
+ continue;
168
+ }
169
+ if (file.type === "chunk" && file.isEntry && file.fileName.endsWith(".js")) {
170
+ file.code = systemjsCode + "\n" + file.code;
171
+ }
172
+ }
173
+ }
174
+ };
175
+ }
176
+ function systemCSSFix() {
177
+ return {
178
+ name: "core:systemjs-css-fix",
179
+ async generateBundle(options, bundle) {
180
+ if (options.format !== "system") {
181
+ return;
182
+ }
183
+ for (const [fileName, chunk] of Object.entries(bundle)) {
184
+ if (fileName.endsWith(".css") && "code" in chunk) {
185
+ const regex = /__vite_style__\.textContent\s*=\s*"([\s\S]*?)";/;
186
+ let match2 = chunk.code.match(regex);
187
+ if (!match2) {
188
+ const regex2 = /\.textContent\s*=\s*`([\s\S]*?)`/;
189
+ match2 = chunk.code.match(regex2);
190
+ }
191
+ if (match2 && match2[1]) {
192
+ chunk.code = match2[1].replace(/\\"/g, '"').replace(/\\n/g, "\n").replace(/\\t/g, " ").replace(/\\\\/g, "\\").replace(/\/\*\$vite\$:\d+\*\/$/, "");
193
+ }
194
+ }
195
+ }
196
+ }
197
+ };
198
+ }
199
+ function cssModulize(entry, dest) {
200
+ return new CssModulizeProcessor(css(entry, dest));
201
+ }
202
+ function cssModulizeDeep(stage, entry, dest, options = {}) {
203
+ const processor = cssModulize(entry, dest);
204
+ if (options.mergeCss ?? true) {
205
+ processor.mergeCss(findModules(`${stage}/**/assets/*.scss`));
206
+ }
207
+ if (options.parseBlades ?? true) {
208
+ processor.parseBlades(
209
+ findModules(`${stage}/**/*.blade.php`),
210
+ findPackages("views/**/*.blade.php")
211
+ );
212
+ }
213
+ return processor;
214
+ }
215
+ class CssModulizeProcessor {
216
+ constructor(processor, bladePatterns = [], cssPatterns = []) {
217
+ this.processor = processor;
218
+ this.bladePatterns = bladePatterns;
219
+ this.cssPatterns = cssPatterns;
220
+ }
221
+ parseBlades(...bladePatterns) {
222
+ this.bladePatterns = this.bladePatterns.concat(bladePatterns.flat());
223
+ return this;
224
+ }
225
+ mergeCss(...css2) {
226
+ this.cssPatterns = this.cssPatterns.concat(css2.flat());
227
+ return this;
228
+ }
229
+ config(taskName, builder) {
230
+ const tasks = this.processor.config(taskName, builder);
231
+ const task = tasks[0];
232
+ const inputFile = resolve(task.input);
233
+ const bladeFiles = fg.globSync(this.bladePatterns);
234
+ for (const file of bladeFiles) {
235
+ builder.watches.push({
236
+ file,
237
+ moduleFile: inputFile,
238
+ updateType: "css-update"
239
+ });
240
+ }
241
+ builder.loadCallbacks.push((src, options) => {
242
+ const file = stripUrlQuery(src);
243
+ if (normalize(file) === inputFile) {
244
+ const patterns = fg.globSync(
245
+ this.cssPatterns.map((v) => resolve(v)).map((v) => v.replace(/\\/g, "/"))
246
+ );
247
+ const imports = patterns.map((pattern) => `@import "${pattern}";`).concat(this.parseStylesFromBlades(bladeFiles)).join("\n");
248
+ let main = fs$1.readFileSync(file, "utf-8");
249
+ main += `
250
+
251
+ ${imports}
252
+ `;
253
+ return main;
254
+ }
255
+ });
256
+ return void 0;
257
+ }
258
+ parseStylesFromBlades(files) {
259
+ return files.map((file) => {
260
+ const bladeText = fs$1.readFileSync(file, "utf8");
261
+ const html = parse(bladeText);
262
+ return html.querySelectorAll("style[type][data-macro],script[type][data-macro]").filter(
263
+ (el) => ["text/scss", "text/css"].includes(el.getAttribute("type") || "")
264
+ ).map((el) => {
265
+ const scope = el.getAttribute("data-scope");
266
+ if (scope) {
267
+ return `${scope} {
268
+ ${el.innerHTML}
269
+ }`;
270
+ } else {
271
+ return el.innerHTML;
272
+ }
273
+ });
274
+ }).filter((c) => c.length > 0).flat();
275
+ }
276
+ preview() {
277
+ return [];
278
+ }
279
+ }
280
+ function jsModulize(entry, dest, options = {}) {
281
+ return new JsModulizeProcessor(js(entry, dest), options);
282
+ }
283
+ function jsModulizeDeep(stage, entry, dest, options = {}) {
284
+ const processor = jsModulize(entry, dest, options).stage(stage.toLowerCase());
285
+ if (options.mergeScripts ?? true) {
286
+ processor.mergeScripts(
287
+ findModules(`${stage}/**/assets/*.ts`)
288
+ );
289
+ }
290
+ if (options.parseBlades ?? true) {
291
+ processor.parseBlades(
292
+ findModules(`${stage}/**/*.blade.php`),
293
+ findPackages("views/**/*.blade.php")
294
+ );
295
+ }
296
+ return processor;
297
+ }
298
+ class JsModulizeProcessor {
299
+ constructor(processor, options = {}) {
300
+ this.processor = processor;
301
+ this.options = options;
302
+ }
303
+ scriptPatterns = [];
304
+ bladePatterns = [];
305
+ stagePrefix = "";
306
+ config(taskName, builder) {
307
+ const tasks = this.processor.config(taskName, builder);
308
+ const task = tasks[0];
309
+ const inputFile = resolve(task.input);
310
+ const tmpPath = this.options.tmpPath ?? resolve("./tmp/fusion/jsmodules/").replace(/\\/g, "/");
311
+ const clean = this.options.cleanTmp ?? true;
312
+ if (clean) {
313
+ builder.postBuildCallbacks.push((options, bundle) => {
314
+ fs$1.removeSync(tmpPath);
315
+ });
316
+ }
317
+ this.ignoreMainImport(task);
318
+ builder.resolveIdCallbacks.push((id) => {
319
+ if (id === "@main") {
320
+ return { id, external: true };
321
+ }
322
+ });
323
+ const scriptFiles = findFilesFromGlobArray(this.scriptPatterns);
324
+ const bladeFiles = findBladeFiles(this.bladePatterns);
325
+ builder.loadCallbacks.push((src, options) => {
326
+ const srcFile = stripUrlQuery(src);
327
+ const scripts = {};
328
+ if (normalize(srcFile) === inputFile) {
329
+ const bladeScripts = parseScriptsFromBlades(bladeFiles);
330
+ fs$1.removeSync(tmpPath);
331
+ for (const scriptFile of scriptFiles) {
332
+ let fullpath = scriptFile.fullpath;
333
+ if (fullpath.endsWith(".d.ts")) {
334
+ continue;
335
+ }
336
+ let key = scriptFile.relativePath.replace(/assets\//, "").toLowerCase();
337
+ fullpath = resolve(fullpath).replace(/\\/g, "/");
338
+ key = key.substring(0, key.lastIndexOf("."));
339
+ if (this.stagePrefix) {
340
+ key = this.stagePrefix + "/" + key;
341
+ }
342
+ key = "view:" + crypto.createHash("md5").update(key).digest("hex");
343
+ scripts[key] = fullpath;
344
+ }
345
+ const listens = [];
346
+ fs$1.ensureDirSync(tmpPath);
347
+ for (const result of bladeScripts) {
348
+ let key = result.as;
349
+ const tmpFile = tmpPath + "/" + result.path.replace(/\\|\//g, "_") + "-" + shortHash(result.code) + ".ts";
350
+ if (!fs$1.existsSync(tmpFile) || fs$1.readFileSync(tmpFile, "utf8") !== result.code) {
351
+ fs$1.writeFileSync(tmpFile, result.code);
352
+ }
353
+ scripts[`inline:${key}`] = tmpFile;
354
+ const fullpath = resolve(result.file.fullpath).replace(/\\/g, "/");
355
+ if (!listens.includes(fullpath)) {
356
+ listens.push(fullpath);
357
+ }
358
+ }
359
+ let listJS = `{
360
+ `;
361
+ for (const key in scripts) {
362
+ const fullpath = scripts[key];
363
+ listJS += `'${key}': () => import('${fullpath}'),
364
+ `;
365
+ }
366
+ listJS += `}`;
367
+ builder.watches.push(...listens);
368
+ let { code, comments } = stripComments(fs$1.readFileSync(srcFile, "utf-8"));
369
+ code = code.replace(/defineJsModules\((.*?)\)/g, listJS);
370
+ return restoreComments(code, comments);
371
+ }
372
+ });
373
+ return void 0;
374
+ }
375
+ /**
376
+ * @see https://github.com/vitejs/vite/issues/6393#issuecomment-1006819717
377
+ * @see https://stackoverflow.com/questions/76259677/vite-dev-server-throws-error-when-resolving-external-path-from-importmap
378
+ */
379
+ ignoreMainImport(task) {
380
+ const VALID_ID_PREFIX = `/@id/`;
381
+ const importKeys = ["@main"];
382
+ const reg = new RegExp(
383
+ `${VALID_ID_PREFIX}(${importKeys.join("|")})`,
384
+ "g"
385
+ );
386
+ plugin({
387
+ name: "keep-main-external-" + task.id,
388
+ transform(code) {
389
+ return reg.test(code) ? code.replace(reg, (m, s1) => s1) : code;
390
+ }
391
+ });
392
+ }
393
+ preview() {
394
+ return [];
395
+ }
396
+ mergeScripts(...patterns) {
397
+ this.scriptPatterns = this.scriptPatterns.concat(patterns.flat());
398
+ return this;
399
+ }
400
+ parseBlades(...bladePatterns) {
401
+ this.bladePatterns = this.bladePatterns.concat(bladePatterns.flat());
402
+ return this;
403
+ }
404
+ stage(stage) {
405
+ this.stagePrefix = stage;
406
+ return this;
407
+ }
408
+ }
409
+ function findBladeFiles(patterns) {
410
+ return findFilesFromGlobArray(Array.isArray(patterns) ? patterns : [patterns]);
411
+ }
412
+ function parseScriptsFromBlades(files) {
413
+ return files.map((file) => {
414
+ const bladeText = fs$1.readFileSync(file.fullpath, "utf8");
415
+ const html = parse(bladeText);
416
+ return html.querySelectorAll("script[lang][data-macro]").filter(
417
+ (el) => ["ts", "typescript"].includes(el.getAttribute("lang") || "")
418
+ ).map((el) => ({
419
+ as: el.getAttribute("data-macro") || "",
420
+ file,
421
+ path: file.relativePath.replace(/.blade.php$/, ""),
422
+ code: el.innerHTML
423
+ })).filter((c) => c.code.trim() !== "");
424
+ }).flat();
425
+ }
426
+ function stripComments(code) {
427
+ const comments = [];
428
+ let i = 0;
429
+ code = code.replace(/\/\*[\s\S]*?\*\//g, (match2) => {
430
+ const key = `__COMMENT_BLOCK_${i}__`;
431
+ comments.push({ key, value: match2 });
432
+ i++;
433
+ return key;
434
+ }).replace(/\/\/.*$/gm, (match2) => {
435
+ const key = `__COMMENT_LINE_${i}__`;
436
+ comments.push({ key, value: match2 });
437
+ i++;
438
+ return key;
439
+ });
440
+ return { code, comments };
441
+ }
442
+ function restoreComments(code, comments) {
443
+ for (const { key, value } of comments) {
444
+ const re = new RegExp(key, "g");
445
+ code = code.replace(re, value);
446
+ }
447
+ return code;
448
+ }
449
+ function installVendors(npmVendors = [], to = "www/assets/vendor") {
450
+ return callbackAfterBuild(() => findAndInstall(npmVendors, to));
451
+ }
452
+ async function findAndInstall(npmVendors = [], to = "www/assets/vendor") {
453
+ const root = to;
454
+ let vendors = npmVendors;
455
+ const action = process.env.INSTALL_VENDOR === "hard" ? "Copy" : "Link";
456
+ console.log("");
457
+ if (!fs$1.existsSync(root)) {
458
+ fs$1.mkdirSync(root);
459
+ }
460
+ const dirs = fs$1.readdirSync(root, { withFileTypes: true }).filter((d) => d.isDirectory()).map((dir) => path.join(root, dir.name));
461
+ dirs.unshift(root);
462
+ dirs.forEach((dir) => {
463
+ deleteExists(dir);
464
+ });
465
+ const composerJsons = getInstalledComposerVendors().map((cv) => `vendor/${cv}/composer.json`).map((file) => loadJson(file)).filter((composerJson) => composerJson?.extra?.windwalker != null);
466
+ vendors = findNpmVendors(composerJsons).concat(vendors);
467
+ vendors = [...new Set(vendors)];
468
+ for (const vendor of vendors) {
469
+ const source = `node_modules/${vendor}/`;
470
+ if (fs$1.existsSync(source)) {
471
+ console.log(`[${action} NPM] node_modules/${vendor}/ => ${root}/${vendor}/`);
472
+ doInstall(source, `${root}/${vendor}/`);
473
+ }
474
+ }
475
+ for (const composerJson of composerJsons) {
476
+ const vendorName = composerJson.name;
477
+ let assets = composerJson?.extra?.windwalker?.assets?.link;
478
+ if (!assets) {
479
+ continue;
480
+ }
481
+ if (!assets.endsWith("/")) {
482
+ assets += "/";
483
+ }
484
+ if (fs$1.existsSync(`vendor/${vendorName}/${assets}`)) {
485
+ console.log(`[${action} Composer] vendor/${vendorName}/${assets} => ${root}/${vendorName}/`);
486
+ doInstall(`vendor/${vendorName}/${assets}`, `${root}/${vendorName}/`);
487
+ }
488
+ }
489
+ const staticVendorDir = "resources/assets/vendor/";
490
+ if (fs$1.existsSync(staticVendorDir)) {
491
+ const staticVendors = fs$1.readdirSync(staticVendorDir);
492
+ for (const staticVendor of staticVendors) {
493
+ if (staticVendor.startsWith("@")) {
494
+ const subVendors = fs$1.readdirSync(staticVendorDir + staticVendor);
495
+ for (const subVendor of subVendors) {
496
+ const subVendorName = staticVendor + "/" + subVendor;
497
+ const source = staticVendorDir + subVendorName + "/";
498
+ if (fs$1.existsSync(source)) {
499
+ console.log(`[${action} Local] resources/assets/vendor/${subVendorName}/ => ${root}/${subVendorName}/`);
500
+ doInstall(source, `${root}/${subVendorName}/`);
501
+ }
502
+ }
503
+ } else {
504
+ let source = staticVendorDir + staticVendor;
505
+ if (fs$1.existsSync(source)) {
506
+ console.log(`[${action} Local] resources/assets/vendor/${staticVendor}/ => ${root}/${staticVendor}/`);
507
+ doInstall(source, `${root}/${staticVendor}/`);
508
+ }
509
+ }
510
+ }
511
+ }
512
+ }
513
+ async function doInstall(source, dest) {
514
+ if (process.env.INSTALL_VENDOR === "hard") {
515
+ await copyGlob(source + "/**/*", dest);
516
+ } else {
517
+ await symlink(source, dest);
518
+ }
519
+ }
520
+ function findNpmVendors(composerJsons = []) {
521
+ const pkg = path.resolve(process.cwd(), "package.json");
522
+ const pkgJson = loadJson(pkg);
523
+ let vendors = Object.keys(pkgJson.devDependencies || {}).concat(Object.keys(pkgJson.dependencies || {})).map((id) => `node_modules/${id}/package.json`).map((file) => loadJson(file)).filter((pkgJson2) => pkgJson2?.windwalker != null).map((pkgJson2) => pkgJson2?.windwalker.vendors || []).flat();
524
+ const vendorsFromComposer = composerJsons.map((composerJson) => {
525
+ return [
526
+ ...composerJson?.extra?.windwalker?.asset_vendors || [],
527
+ ...composerJson?.extra?.windwalker?.assets?.exposes || [],
528
+ ...Object.keys(composerJson?.extra?.windwalker?.assets?.vendors || {})
529
+ ];
530
+ }).flat();
531
+ return [...new Set(vendors.concat(vendorsFromComposer))];
532
+ }
533
+ function getInstalledComposerVendors() {
534
+ const composerFile = path.resolve(process.cwd(), "composer.json");
535
+ const composerJson = loadJson(composerFile);
536
+ return [
537
+ ...new Set(
538
+ Object.keys(composerJson["require"] || {}).concat(Object.keys(composerJson["require-dev"] || {}))
539
+ )
540
+ ];
541
+ }
542
+ function deleteExists(dir) {
543
+ if (!fs$1.existsSync(dir)) {
544
+ return;
545
+ }
546
+ const subDirs = fs$1.readdirSync(dir, { withFileTypes: true });
547
+ for (const subDir of subDirs) {
548
+ if (subDir.isSymbolicLink() || subDir.isFile()) {
549
+ fs$1.unlinkSync(path.join(dir, subDir.name));
550
+ } else if (subDir.isDirectory()) {
551
+ deleteExists(path.join(dir, subDir.name));
552
+ }
553
+ }
554
+ fs$1.rmdirSync(dir);
555
+ }
556
+ export {
557
+ cloneAssets,
558
+ containsMiddleGlob,
559
+ cssModulize,
560
+ cssModulizeDeep,
561
+ ensureDirPath,
562
+ findFilesFromGlobArray,
563
+ findModules,
564
+ findPackages,
565
+ globalAssets,
566
+ injectSystemJS,
567
+ installVendors,
568
+ jsModulize,
569
+ jsModulizeDeep,
570
+ loadJson,
571
+ removeLastGlob,
572
+ resolveModuleRealpath,
573
+ stripUrlQuery,
574
+ systemCSSFix,
575
+ uniqId
576
+ };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@windwalker-io/core",
3
- "version": "4.2.0",
3
+ "version": "4.2.2",
4
4
  "type": "module",
5
5
  "description": "Windwalker Core JS package",
6
6
  "scripts": {
7
7
  "build": "yarn build:next && yarn build:debugger",
8
8
  "dev": "yarn dev:debugger",
9
- "build:next": "vite build --config vite.config.next.ts",
9
+ "build:next": "vite build --config vite.next.config.ts",
10
10
  "dev:next": "yarn build:next --watch",
11
- "build:debugger": "vite build --config vite.config.debugger.ts",
12
- "dev:debugger": "vite --config vite.config.debugger.ts"
11
+ "build:debugger": "vite build --config vite.debugger.config.ts",
12
+ "dev:debugger": "vite --config vite.debugger.config.ts"
13
13
  },
14
14
  "exports": {
15
15
  ".": "./src/index.js",
@@ -23,6 +23,13 @@
23
23
  "import": "./src/app/index.ts"
24
24
  }
25
25
  },
26
+ "files": [
27
+ "dist",
28
+ "images",
29
+ "scss",
30
+ "src",
31
+ "package.json"
32
+ ],
26
33
  "repository": "https://github.com/ventoviro/windwalker-core",
27
34
  "author": "Simon Asika",
28
35
  "license": "MIT",
package/src/app/app.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  type Route = string | RouteLoader;
2
2
  type RouteLoader = () => Promise<any>;
3
3
 
4
+ let currentProps: Record<string, any> | null = null;
5
+
4
6
  export class App {
5
7
  routes: Record<string, RouteLoader> = {};
8
+ queue: (() => Promise<any>)[] = [];
9
+ queueRunning = false;
6
10
 
7
11
  constructor(routes: Record<string, Route> = {}) {
8
12
  this.registerRoutes(routes);
@@ -42,9 +46,48 @@ export class App {
42
46
  return target();
43
47
  }
44
48
 
49
+ async importSync<T = any>(route: string, props: Record<string, any> = {}): Promise<T> {
50
+ return new Promise<any>((resolve) => {
51
+ const target = this.routes[route];
52
+
53
+ if (!target) {
54
+ throw new Error(`Unable to import file: ${route}, file not found.`);
55
+ }
56
+
57
+ this.queue.push(async () => {
58
+ currentProps = props;
59
+ resolve(await target());
60
+ });
61
+
62
+ this.runQueue();
63
+ });
64
+ }
65
+
66
+ async runQueue() {
67
+ if (!this.queueRunning) {
68
+ this.queueRunning = true;
69
+ let item: () => any;
70
+
71
+ while (item = this.queue.shift()) {
72
+ await item();
73
+ }
74
+
75
+ this.queueRunning = false;
76
+ }
77
+ }
78
+
45
79
  reset() {
46
80
  this.routes = {};
47
81
 
48
82
  return this;
49
83
  }
50
84
  }
85
+
86
+ export function useMacroProps<T extends Record<string, any> = Record<string, any>>(): T {
87
+ console.log('get');
88
+ if (currentProps == null) {
89
+ throw new Error('Cannot get macro props.');
90
+ }
91
+
92
+ return { ...currentProps } as T;
93
+ }