Skip to content

Commit d322fc1

Browse files
refactor(build): Overhaul build configuration and introduce comprehensive debug system
This commit represents a significant refactoring of the Sky element's build infrastructure and environment handling, centered around the introduction of a new debug module. **Key Changes:** 1. **New Debug Module (`Source/Function/Debug.ts`)**: Added a comprehensive build-time debugger that centralizes environment variable resolution, configuration constants, and provides extensive color-coded terminal reporting. This serves as a single source of truth for build parameters. 2. **Astro Configuration Refactor (`astro.config.ts`)**: Completely rewrote the configuration to delegate all environment resolution and logging to the new debug module, resulting in cleaner, more maintainable code. 3. **Astro Version Update**: Upgraded Astro from 5.7.10 to 5.16.11, updating the internal configuration digest accordingly. 4. **Environment Type Definitions (`Source/env.d.ts`)**: Enhanced global type declarations to better support the Tauri isolation hook and NLS loading state. 5. **API Hook Refinement (`Source/Function/API.ts`)**: Transformed the Tauri isolation hook from a minimal implementation to a more robust function with proper logging. 6. **Content Security Policy Updates (`Source/pages/Application.astro`)**: Significantly expanded CSP directives to allow localhost and Tauri localhost domains across multiple resource types, and disabled upgrade-insecure-requests for development flexibility. 7. **Workbench Import Correction (`Source/Workbench/Default.astro`)**: Changed import from electron-browser to browser workbench module for better cross-platform compatibility. 8. **Static Asset Optimization**: Updated favicon and manifest files (reduced file sizes) and improved static resource paths. **Motivation:** These changes improve build transparency, centralize configuration management, enhance development experience with detailed environment reporting, and better support both Tauri and browser deployment targets. The debug module provides immediate visibility into build context before Astro/Vite processes take over, reducing configuration-related issues.
1 parent 574e766 commit d322fc1

14 files changed

Lines changed: 434 additions & 236 deletions

β€Ž.astro/data-store.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[["Map",1,2],"meta::meta",["Map",3,4,5,6],"astro-version","5.7.10","astro-config-digest","{\"root\":{},\"srcDir\":{},\"publicDir\":{},\"outDir\":{},\"cacheDir\":{},\"site\":\"https://130.204.164.63\",\"compressHTML\":false,\"base\":\"/\",\"trailingSlash\":\"ignore\",\"output\":\"static\",\"scopedStyleStrategy\":\"attribute\",\"build\":{\"format\":\"directory\",\"client\":{},\"server\":{},\"assets\":\"_astro\",\"serverEntry\":\"entry.mjs\",\"redirects\":true,\"inlineStylesheets\":\"auto\",\"concurrency\":9999},\"server\":{\"open\":false,\"host\":true,\"port\":9999,\"streaming\":true,\"allowedHosts\":[]},\"redirects\":{},\"prefetch\":false,\"image\":{\"endpoint\":{\"route\":\"/_image\"},\"service\":{\"entrypoint\":\"astro/assets/services/sharp\",\"config\":{}},\"domains\":[],\"remotePatterns\":[]},\"devToolbar\":{\"enabled\":true},\"markdown\":{\"syntaxHighlight\":{\"type\":\"shiki\",\"excludeLangs\":[\"math\"]},\"shikiConfig\":{\"langs\":[],\"langAlias\":{},\"theme\":\"github-dark\",\"themes\":{},\"wrap\":false,\"transformers\":[]},\"remarkPlugins\":[],\"rehypePlugins\":[],\"remarkRehype\":{},\"gfm\":true,\"smartypants\":true},\"security\":{\"checkOrigin\":true},\"env\":{\"schema\":{},\"validateSecrets\":false},\"experimental\":{\"clientPrerender\":true,\"contentIntellisense\":true,\"responsiveImages\":false,\"headingIdCompat\":false,\"preserveScriptOrder\":false},\"legacy\":{\"collections\":false}}"]
1+
[["Map",1,2],"meta::meta",["Map",3,4,5,6],"astro-version","5.16.11","astro-config-digest","{\"root\":{},\"srcDir\":{},\"publicDir\":{},\"outDir\":{},\"cacheDir\":{},\"site\":\"https://localhost\",\"compressHTML\":false,\"base\":\"/\",\"trailingSlash\":\"ignore\",\"output\":\"static\",\"scopedStyleStrategy\":\"attribute\",\"build\":{\"format\":\"directory\",\"client\":{},\"server\":{},\"assets\":\"_astro\",\"serverEntry\":\"entry.mjs\",\"redirects\":true,\"inlineStylesheets\":\"auto\",\"concurrency\":9999},\"server\":{\"open\":false,\"host\":true,\"port\":9999,\"streaming\":true,\"allowedHosts\":[]},\"redirects\":{},\"prefetch\":false,\"image\":{\"endpoint\":{\"route\":\"/_image\"},\"service\":{\"entrypoint\":\"astro/assets/services/sharp\",\"config\":{}},\"domains\":[],\"remotePatterns\":[],\"responsiveStyles\":false},\"devToolbar\":{\"enabled\":true},\"markdown\":{\"syntaxHighlight\":{\"type\":\"shiki\",\"excludeLangs\":[\"math\"]},\"shikiConfig\":{\"langs\":[],\"langAlias\":{},\"theme\":\"github-dark\",\"themes\":{},\"wrap\":false,\"transformers\":[]},\"remarkPlugins\":[],\"rehypePlugins\":[],\"remarkRehype\":{},\"gfm\":true,\"smartypants\":true},\"security\":{\"checkOrigin\":true,\"allowedDomains\":[]},\"env\":{\"schema\":{},\"validateSecrets\":false},\"experimental\":{\"clientPrerender\":true,\"contentIntellisense\":true,\"headingIdCompat\":false,\"preserveScriptOrder\":false,\"liveContentCollections\":false,\"csp\":false,\"staticImportMetaEnv\":false,\"chromeDevtoolsWorkspace\":false,\"failOnPrerenderConflict\":false,\"svgo\":false},\"legacy\":{\"collections\":false}}"]

β€Ž.astro/settings.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"_variables": {
3-
"lastUpdateCheck": 1745858732868
3+
"lastUpdateCheck": 1768744983804
44
}
55
}

β€ŽSource/Function/API.tsβ€Ž

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
// @ts-expect-error
2-
window.__TAURI_ISOLATION_HOOK__ = (Request: any) => Request;
1+
/// <reference path="../env.d.ts" />
2+
3+
window.__TAURI_ISOLATION_HOOK__ = (Payload: any) => {
4+
console.log(`__TAURI_ISOLATION_HOOK__: ${Payload}`);
5+
6+
return Payload;
7+
};

β€ŽSource/Function/Debug.tsβ€Ž

Lines changed: 329 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,329 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Sky Build Debugger
3+
* --------------------------------------------------------------------------------------------
4+
* This script is designed to run during the build phase of the Sky webview (the client-side
5+
* of the Astro-based application).
6+
*
7+
* Its primary responsibilities are:
8+
* 1. To inspect, resolve, and normalize all environment variables required for the build.
9+
* 2. To provide a "Single Source of Truth" for build configuration constants (e.g., Path,
10+
* Platform flags, Bundling modes).
11+
* 3. To output an EXTENSIVE, structured, and color-coded report to the build terminal,
12+
* ensuring developers have full visibility into the build context (Env, Path,
13+
* Flags) before the main Astro/Vite process takes over.
14+
*
15+
* Usage:
16+
* This file is imported by `astro.config.ts`. The act of importing it triggers the
17+
* console logging side-effects immediately.
18+
*--------------------------------------------------------------------------------------------*/
19+
20+
import type { ViteStaticCopyOptions } from "vite-plugin-static-copy";
21+
22+
// -----------------------------------------------------------------------------
23+
// 1. Core Utilities & Exports
24+
// -----------------------------------------------------------------------------
25+
export const { readFile } = await import("node:fs/promises");
26+
27+
// -----------------------------------------------------------------------------
28+
// 2. Environment Variable Resolution
29+
// -----------------------------------------------------------------------------
30+
31+
export const Bundle = process.env["Bundle"] === "true";
32+
33+
export const Browser = process.env["Browser"] === "true";
34+
35+
export const Dependency = process.env["Dependency"] ?? "CodeEditorLand/Editor";
36+
37+
export const Tauri = typeof process.env["TAURI_ENV_ARCH"] !== "undefined";
38+
39+
export const Platform = ((Platform) => {
40+
switch (Platform?.toLowerCase()) {
41+
case "windows":
42+
return "Windows";
43+
44+
case "darwin":
45+
return "Mac";
46+
47+
case "linux":
48+
return "Linux";
49+
50+
case "android":
51+
return "Android";
52+
53+
case "ios":
54+
return "iOS";
55+
56+
default:
57+
return "Windows";
58+
}
59+
})(process.env["TAURI_ENV_PLATFORM"]);
60+
61+
/**
62+
* "On" represents the active development/debugging state.
63+
* True if NODE_ENV is 'development' OR TAURI_ENV_DEBUG is set.
64+
*/
65+
export const On =
66+
process.env["NODE_ENV"] === "development" ||
67+
process.env["TAURI_ENV_DEBUG"] === "true";
68+
69+
// -----------------------------------------------------------------------------
70+
// 3. Constants & Path
71+
// -----------------------------------------------------------------------------
72+
73+
export const Link = [
74+
"@codeeditorland/common",
75+
76+
"@codeeditorland/output",
77+
78+
// "@codeeditorland/wind",
79+
80+
"@codeeditorland/worker",
81+
];
82+
83+
export const External = ["@microsoft/1ds-core-js", "@microsoft/1ds-post-js"];
84+
85+
export const Host = process.env["TAURI_DEV_HOST"]
86+
? `https://${process.env["TAURI_DEV_HOST"]}`
87+
: On
88+
? "http://localhost"
89+
: Tauri
90+
? "https://tauri.localhost"
91+
: "https://editor.land";
92+
93+
export const ApplicationStatic = "Static/Application";
94+
95+
export const VSCodeOutput =
96+
"node_modules/@codeeditorland/output/Target/Microsoft/VSCode";
97+
98+
export const KeyboardLayouts =
99+
"vs/workbench/services/keybinding/browser/keyboardLayouts";
100+
101+
// -----------------------------------------------------------------------------
102+
// 4. Static Asset Logic
103+
// -----------------------------------------------------------------------------
104+
105+
export const Static: ViteStaticCopyOptions = {
106+
targets: [],
107+
108+
structured: false,
109+
};
110+
111+
// Logic to populate Static.targets based on the environment
112+
if (Bundle) {
113+
switch (Platform) {
114+
case "Windows":
115+
Static.targets.push({
116+
src: `${VSCodeOutput}/${KeyboardLayouts}/*.win.js`,
117+
118+
dest: `${ApplicationStatic}/${KeyboardLayouts}/`,
119+
});
120+
121+
break;
122+
123+
case "Mac":
124+
Static.targets.push({
125+
src: `${VSCodeOutput}/${KeyboardLayouts}/*.darwin.js`,
126+
127+
dest: `${ApplicationStatic}/${KeyboardLayouts}/`,
128+
});
129+
130+
break;
131+
132+
case "Linux":
133+
Static.targets.push({
134+
src: `${VSCodeOutput}/${KeyboardLayouts}/*.linux.js`,
135+
136+
dest: `${ApplicationStatic}/${KeyboardLayouts}/`,
137+
});
138+
139+
break;
140+
141+
default:
142+
break;
143+
}
144+
145+
Static.targets.push(
146+
...[
147+
{
148+
src: `node_modules/@codeeditorland/output/Target/${Dependency}/${On ? "vs/" : ""}${On ? "nls.js" : "nls.messages.js"}`,
149+
150+
dest: `${ApplicationStatic}/${On ? "vs/" : ""}`,
151+
},
152+
153+
{
154+
src: `${VSCodeOutput}/${KeyboardLayouts}/_.contribution.js`,
155+
156+
dest: `${ApplicationStatic}/${KeyboardLayouts}/`,
157+
},
158+
159+
{
160+
src: "node_modules/@codeeditorland/worker/Target/Worker.js",
161+
162+
dest: ".",
163+
},
164+
],
165+
);
166+
} else {
167+
Static.targets.push(
168+
...[
169+
{
170+
src: `${VSCodeOutput}/*`,
171+
172+
dest: ApplicationStatic,
173+
},
174+
175+
{
176+
src: "node_modules/@codeeditorland/worker/Target/*",
177+
178+
dest: ".",
179+
},
180+
],
181+
);
182+
}
183+
184+
Browser
185+
? External.push(
186+
...[
187+
"@codeeditorland/output/vs/code/electron-browser/workbench/workbench.js",
188+
],
189+
)
190+
: {};
191+
192+
// -----------------------------------------------------------------------------
193+
// 5. EXTENSIVE DEBUG LOGGING
194+
// -----------------------------------------------------------------------------
195+
// This self-executing block runs immediately on import to output the build context.
196+
(() => {
197+
const Color = {
198+
Reset: "\x1b[0m",
199+
Bright: "\x1b[1m",
200+
Dim: "\x1b[2m",
201+
Cyan: "\x1b[36m",
202+
Green: "\x1b[32m",
203+
Yellow: "\x1b[33m",
204+
Red: "\x1b[31m",
205+
Magenta: "\x1b[35m",
206+
Blue: "\x1b[34m",
207+
};
208+
209+
const Header = (Text: string) =>
210+
`\n${Color.Bright}${Color.Cyan}════ ${Text} ════${Color.Reset}`;
211+
212+
const Output = (Key: string, Value: any) =>
213+
` ${Color.Cyan}${Key.padEnd(18)}${Color.Reset}: ${Value}`;
214+
215+
console.log(
216+
`\n${Color.Bright}${Color.Magenta}╔══════════════════════════════════════════════════════════════════════════════╗${Color.Reset}`,
217+
);
218+
219+
console.log(
220+
`${Color.Bright}${Color.Magenta}β•‘ SKY BUILD CONTEXT DEBUGGER β•‘${Color.Reset}`,
221+
);
222+
223+
console.log(
224+
`${Color.Bright}${Color.Magenta}β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•${Color.Reset}`,
225+
);
226+
227+
console.log(Header("Resolved Flags"));
228+
229+
console.log(
230+
Output("Bundle", Bundle ? Color.Green + "TRUE" : Color.Dim + "false"),
231+
);
232+
233+
console.log(
234+
Output("Browser", Browser ? Color.Green + "TRUE" : Color.Dim + "false"),
235+
);
236+
237+
console.log(
238+
Output("Tauri", Tauri ? Color.Green + "TRUE" : Color.Dim + "false"),
239+
);
240+
241+
console.log(
242+
Output(
243+
"Debug Mode (On)",
244+
On ? Color.Red + "ACTIVE" : Color.Green + "Inactive (Production)",
245+
),
246+
);
247+
248+
console.log(Output("Platform", `${Color.Yellow}${Platform}${Color.Reset}`));
249+
250+
console.log(Output("Host", `${Color.Blue}${Host}${Color.Reset}`));
251+
252+
console.log(Output("Dependency", Dependency));
253+
254+
console.log(Header("Process Environment (Raw)"));
255+
256+
console.log(
257+
Output("NODE_ENV", process.env["NODE_ENV"] || Color.Dim + "undefined"),
258+
);
259+
260+
console.log(
261+
Output(
262+
"TAURI_ENV_ARCH",
263+
process.env["TAURI_ENV_ARCH"] || Color.Dim + "undefined",
264+
),
265+
);
266+
267+
console.log(
268+
Output(
269+
"TAURI_ENV_PLATFORM",
270+
process.env["TAURI_ENV_PLATFORM"] || Color.Dim + "undefined",
271+
),
272+
);
273+
274+
console.log(
275+
Output(
276+
"TAURI_ENV_DEBUG",
277+
process.env["TAURI_ENV_DEBUG"] || Color.Dim + "undefined",
278+
),
279+
);
280+
281+
console.log(
282+
Output(
283+
"TAURI_DEV_HOST",
284+
process.env["TAURI_DEV_HOST"] || Color.Dim + "undefined",
285+
),
286+
);
287+
288+
console.log(Header("Build Path"));
289+
290+
console.log(Output("ApplicationStatic", ApplicationStatic));
291+
292+
console.log(Output("VSCodeOutput", VSCodeOutput));
293+
294+
console.log(Output("KeyboardLayouts", KeyboardLayouts));
295+
296+
console.log(Header("Module Configuration"));
297+
298+
console.log(
299+
` ${Color.Cyan}External Modules${Color.Reset} : [ ${External.map((e) => Color.Yellow + e + Color.Reset).join(", ")} ]`,
300+
);
301+
302+
console.log(
303+
` ${Color.Cyan}Linked Packages${Color.Reset} : [ ${Link.map((l) => Color.Yellow + l + Color.Reset).join(", ")} ]`,
304+
);
305+
306+
console.log(Header("Static Asset Copy Rules"));
307+
308+
if (Static.targets.length === 0) {
309+
console.log(` ${Color.Dim}(No static targets defined)${Color.Reset}`);
310+
} else {
311+
Static.targets.forEach((Target, i) => {
312+
// @ts-ignore
313+
const Source = Target.src;
314+
315+
// @ts-ignore
316+
const Destination = Target.dest;
317+
318+
console.log(
319+
` ${Color.Dim}[${i + 1}]${Color.Reset} ${Color.Green}${Source}${Color.Reset}`,
320+
);
321+
322+
console.log(` ${Color.Dim}➜${Color.Reset} ${Destination}`);
323+
});
324+
}
325+
326+
console.log(
327+
`\n${Color.Bright}${Color.Magenta}════════════════════════════════════════════════════════════════════════════════${Color.Reset}\n`,
328+
);
329+
})();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<script>
2-
import "@codeeditorland/output/vs/code/electron-browser/workbench/workbench.js";
2+
import "@codeeditorland/output/vs/code/browser/workbench/workbench.js";
33
</script>

β€ŽSource/env.d.tsβ€Ž

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
/// <reference path="../.astro/types.d.ts" />
22
/// <reference types="astro/client" />
33

4+
// Global window properties for the application
45
declare global {
56
interface Window {
6-
__TAURI_ISOLATION_HOOK__: () => void;
7+
__TAURI_ISOLATION_HOOK__: (payload: any) => any;
8+
NLS_LOADED?: boolean;
79
}
810
}
11+
12+
export {};

0 commit comments

Comments
Β (0)