@windwalker-io/core 4.2.6 → 4.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/next.js CHANGED
@@ -121,7 +121,7 @@ function handleCloneAssets(builder2, clonePatterns) {
121
121
  }
122
122
  function handleReposition(builder2, reposition) {
123
123
  builder2.assetFileNamesCallbacks.push((assetInfo) => {
124
- const fileName = assetInfo.originalFileName;
124
+ const fileName = assetInfo.originalFileName || assetInfo.name || assetInfo.names[0] || "";
125
125
  for (const base in reposition) {
126
126
  if (match(fileName, base)) {
127
127
  return normalize(reposition[base] + relative(removeLastGlob(base), fileName)).replace(/\\/g, "/");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windwalker-io/core",
3
- "version": "4.2.6",
3
+ "version": "4.2.8",
4
4
  "type": "module",
5
5
  "description": "Windwalker Core JS package",
6
6
  "scripts": {
@@ -9,7 +9,8 @@
9
9
  "build:next": "vite build --config vite.next.config.ts",
10
10
  "dev:next": "yarn build:next --watch",
11
11
  "build:debugger": "vite build --config vite.debugger.config.ts",
12
- "dev:debugger": "vite --config vite.debugger.config.ts"
12
+ "dev:debugger": "vite --config vite.debugger.config.ts",
13
+ "upgrade": "yarn up '**' -R"
13
14
  },
14
15
  "exports": {
15
16
  ".": "./src/index.mjs",
package/src/app/app.ts CHANGED
@@ -2,6 +2,8 @@ type Route = string | RouteLoader;
2
2
  type RouteLoader = () => Promise<any>;
3
3
 
4
4
  let currentProps: Record<string, any> | null = null;
5
+ let currentRoute: string = '';
6
+ let readyHooks: Record<string, ((...args: any[]) => any)> = {};
5
7
 
6
8
  export class App {
7
9
  routes: Record<string, RouteLoader> = {};
@@ -56,7 +58,19 @@ export class App {
56
58
 
57
59
  this.queue.push(async () => {
58
60
  currentProps = props;
59
- resolve(await target());
61
+ currentRoute = route;
62
+
63
+ let module = await target();
64
+
65
+ if (module.default && typeof module.default === 'function') {
66
+ module.default();
67
+ }
68
+
69
+ if (readyHooks[currentRoute]) {
70
+ readyHooks[currentRoute]();
71
+ }
72
+
73
+ resolve(module);
60
74
  });
61
75
 
62
76
  this.runQueue();
@@ -84,10 +98,17 @@ export class App {
84
98
  }
85
99
 
86
100
  export function useMacroProps<T extends Record<string, any> = Record<string, any>>(): T {
87
- console.log('get');
88
101
  if (currentProps == null) {
89
102
  throw new Error('Cannot get macro props.');
90
103
  }
91
-
104
+
92
105
  return { ...currentProps } as T;
93
106
  }
107
+
108
+ export function onMacroReady(handler: () => any): void {
109
+ if (!currentRoute) {
110
+ throw new Error('Cannot find current script name for macro ready.');
111
+ }
112
+
113
+ readyHooks[currentRoute] = handler;
114
+ }
@@ -62,7 +62,7 @@ export function handleCloneAssets(builder: ConfigBuilder, clonePatterns: string[
62
62
 
63
63
  export function handleReposition(builder: ConfigBuilder, reposition: Record<string, string>) {
64
64
  builder.assetFileNamesCallbacks.push((assetInfo) => {
65
- const fileName = assetInfo.originalFileName!;
65
+ const fileName = assetInfo.originalFileName || assetInfo.name || assetInfo.names[0] || '';
66
66
 
67
67
  for (const base in reposition) {
68
68
  if (match(fileName, base)) {