Skip to content

Commit 1b8e02b

Browse files
feat(Sky): Add LAND_SKIP_BUILTIN_EXTENSIONS to skip extension copy
Add support for the LAND_SKIP_BUILTIN_EXTENSIONS environment variable in CopyVSCode Step 13. When set to "true", the build process skips copying built-in VS Code extensions to the target directory. This enables the `debug-electron-minimal` and `release-electron-minimal` profiles (Atom J2) to produce bundles with zero built-in extensions on disk. Mountain's Scanner observes the same flag (Atom J3) and returns early for the built-in fallback paths at runtime, ensuring the runtime state matches the zero-on-disk configuration. Also convert the PostHog telemetry request import from dynamic to top-of-file static binding, following the same pattern used for StripDanglingSourceMaps. Dynamic imports fail in `astro:build:done` because the Vite module runner has been closed by that stage.
1 parent 42372a2 commit 1b8e02b

1 file changed

Lines changed: 80 additions & 50 deletions

File tree

astro.config.ts

Lines changed: 80 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
stat,
2424
writeFile,
2525
} from "node:fs/promises";
26+
import { request } from "node:https";
2627
import { join, resolve } from "node:path";
2728
import { fileURLToPath } from "node:url";
2829

@@ -440,7 +441,10 @@ export default defineConfig({
440441
// doesn't gate channel access on window
441442
// restoration.
442443
await writeFile(
443-
join(SharedProcessDir, "sharedProcessService.js"),
444+
join(
445+
SharedProcessDir,
446+
"sharedProcessService.js",
447+
),
444448
[
445449
`import { TauriMainProcessService } from '../../../../platform/ipc/electron-browser/TauriMainProcessService.js';`,
446450
``,
@@ -794,12 +798,16 @@ export default defineConfig({
794798
// this runs inside astro:build:done, after Vite tears down its
795799
// ModuleRunner. Static imports survive the teardown; dynamic ones
796800
// re-enter the runner and throw.
797-
const StripDanglingSourceMaps = async (Root: string): Promise<number> => {
801+
const StripDanglingSourceMaps = async (
802+
Root: string,
803+
): Promise<number> => {
798804
let Stripped = 0;
799805
const Walk = async (Dir: string): Promise<void> => {
800806
let Entries: Dirent[] = [];
801807
try {
802-
Entries = await readdir(Dir, { withFileTypes: true });
808+
Entries = await readdir(Dir, {
809+
withFileTypes: true,
810+
});
803811
} catch {
804812
return;
805813
}
@@ -817,13 +825,20 @@ export default defineConfig({
817825
// No sibling map — strip the trailing comment.
818826
}
819827
try {
820-
const Content = await readFile(Full, "utf-8");
828+
const Content = await readFile(
829+
Full,
830+
"utf-8",
831+
);
821832
const Rewritten = Content.replace(
822833
/\n?\/\/[#@][ \t]*sourceMappingURL=[^\n]*\n?$/,
823834
"\n",
824835
);
825836
if (Rewritten !== Content) {
826-
await writeFile(Full, Rewritten, "utf-8");
837+
await writeFile(
838+
Full,
839+
Rewritten,
840+
"utf-8",
841+
);
827842
Stripped++;
828843
}
829844
} catch {
@@ -884,52 +899,65 @@ export default defineConfig({
884899
// Primary: .build/extensions/ (compiled via gulp compile-extensions-build)
885900
// Fallback: extensions/ (source - themes, snippets, grammars work uncompiled)
886901
// Mountain scans Static/Application/extensions/ at startup.
887-
const ExtensionsTarget = join(
888-
TargetDir,
889-
"Static/Application/extensions",
890-
);
891-
const ExtensionsSources = [
892-
resolve(
893-
process.cwd(),
894-
"../../Dependency/Microsoft/Dependency/Editor/.build/extensions",
895-
),
896-
resolve(
897-
process.cwd(),
898-
"../../Dependency/Microsoft/Dependency/Editor/extensions",
899-
),
900-
];
901-
let ExtensionsCopied = false;
902-
for (const ExtensionsSource of ExtensionsSources) {
903-
try {
904-
const ExtDirs = await readdir(ExtensionsSource);
905-
let Copied = 0;
906-
for (const Ext of ExtDirs) {
907-
const Source = join(ExtensionsSource, Ext);
908-
const PkgPath = join(Source, "package.json");
909-
try {
910-
await readFile(PkgPath);
911-
const Dest = join(ExtensionsTarget, Ext);
912-
await cp(Source, Dest, { recursive: true });
913-
Copied++;
914-
} catch {
915-
// Skip dirs without package.json or broken extensions
902+
//
903+
// Atom J2: `debug-electron-minimal` / `release-electron-minimal`
904+
// profiles set `LAND_SKIP_BUILTIN_EXTENSIONS=true` so the
905+
// shipping bundle excludes every bundled extension. Mountain's
906+
// Scanner observes the same flag (Atom J3) and returns early
907+
// for the built-in fallback paths, so the runtime matches the
908+
// zero-on-disk state.
909+
if (process.env["LAND_SKIP_BUILTIN_EXTENSIONS"] === "true") {
910+
console.log(
911+
"[CopyVSCode] Step 13: LAND_SKIP_BUILTIN_EXTENSIONS=true — skipping built-in extension copy",
912+
);
913+
} else {
914+
const ExtensionsTarget = join(
915+
TargetDir,
916+
"Static/Application/extensions",
917+
);
918+
const ExtensionsSources = [
919+
resolve(
920+
process.cwd(),
921+
"../../Dependency/Microsoft/Dependency/Editor/.build/extensions",
922+
),
923+
resolve(
924+
process.cwd(),
925+
"../../Dependency/Microsoft/Dependency/Editor/extensions",
926+
),
927+
];
928+
let ExtensionsCopied = false;
929+
for (const ExtensionsSource of ExtensionsSources) {
930+
try {
931+
const ExtDirs = await readdir(ExtensionsSource);
932+
let Copied = 0;
933+
for (const Ext of ExtDirs) {
934+
const Source = join(ExtensionsSource, Ext);
935+
const PkgPath = join(Source, "package.json");
936+
try {
937+
await readFile(PkgPath);
938+
const Dest = join(ExtensionsTarget, Ext);
939+
await cp(Source, Dest, { recursive: true });
940+
Copied++;
941+
} catch {
942+
// Skip dirs without package.json or broken extensions
943+
}
916944
}
945+
if (Copied > 0) {
946+
console.log(
947+
`[CopyVSCode] Step 13: Copied ${Copied} built-in extensions from ${ExtensionsSource}`,
948+
);
949+
ExtensionsCopied = true;
950+
break;
951+
}
952+
} catch {
953+
// Source dir not found, try next
917954
}
918-
if (Copied > 0) {
919-
console.log(
920-
`[CopyVSCode] Step 13: Copied ${Copied} built-in extensions from ${ExtensionsSource}`,
921-
);
922-
ExtensionsCopied = true;
923-
break;
924-
}
925-
} catch {
926-
// Source dir not found, try next
927955
}
928-
}
929-
if (!ExtensionsCopied) {
930-
console.warn(
931-
"[CopyVSCode] Step 13: No built-in extensions found",
932-
);
956+
if (!ExtensionsCopied) {
957+
console.warn(
958+
"[CopyVSCode] Step 13: No built-in extensions found",
959+
);
960+
}
933961
}
934962

935963
// Step 14: Patch extensionsScannerService (node/) to fetch
@@ -1112,10 +1140,12 @@ export { ExtensionsScannerService, IExtensionsScannerService };
11121140
StepMark("done");
11131141
console.log("[CopyVSCode] ✓ Assets ready in Target/");
11141142

1115-
// PostHog build telemetry - debug only, skipped in production
1143+
// PostHog build telemetry - debug only, skipped in production.
1144+
// Uses top-level static `request` import; dynamic imports fail
1145+
// here because the Vite module runner has been closed by the
1146+
// time astro:build:done fires.
11161147
if (process.env["NODE_ENV"] !== "production") {
11171148
try {
1118-
const { request } = await import("node:https");
11191149
const Body = JSON.stringify({
11201150
api_key:
11211151
"phc_mCwHy7LgvbnEqh6a2DyMiLUJcaZvmmj7JNmmpQzvr7mA",

0 commit comments

Comments
 (0)