|
| 1 | +/** |
| 2 | + * @fileoverview Centralized path resolution for vscode-socket-security. |
| 3 | + * |
| 4 | + * Source of truth for every build/test/runtime path. Per the fleet |
| 5 | + * `1 path, 1 reference` rule — every other module imports from here |
| 6 | + * instead of constructing paths inline. |
| 7 | + * |
| 8 | + * Layout follows the socket-btm canonical pattern: |
| 9 | + * build/<mode>/<platform-arch>/out/<artifact> |
| 10 | + * |
| 11 | + * For this repo specifically, the bundled output is platform-agnostic |
| 12 | + * (esbuild emits a single CommonJS file that runs in whatever Node |
| 13 | + * VSCode provides — the only platform-fork inputs are the embedded |
| 14 | + * WASM binaries which esbuild includes via --loader:.wasm=binary). |
| 15 | + * We still expose getBuildPaths(mode, platformArch) for fleet |
| 16 | + * compatibility; consumers that don't care about platform can call |
| 17 | + * it with a fixed sentinel like 'any'. |
| 18 | + * |
| 19 | + * VSCode marketplace publishing expects `main: ./out/main.js` per |
| 20 | + * package.json. The canonical build output therefore lands at |
| 21 | + * `./out/main.js` directly (no platform/mode subtree) — same place |
| 22 | + * as before this refactor — but `BUILD_ROOT` and `getBuildPaths` |
| 23 | + * are still defined so future build steps (e.g. per-platform sfw |
| 24 | + * shims, signed VSIX outputs) can branch the layout without |
| 25 | + * inventing path conventions ad-hoc. |
| 26 | + */ |
| 27 | + |
| 28 | +import path from 'node:path' |
| 29 | +import { fileURLToPath } from 'node:url' |
| 30 | + |
| 31 | +const __filename = fileURLToPath(import.meta.url) |
| 32 | +const __dirname = path.dirname(__filename) |
| 33 | + |
| 34 | +// Package root: scripts/../ |
| 35 | +export const PACKAGE_ROOT = path.resolve(__dirname, '..') |
| 36 | + |
| 37 | +// Build roots. |
| 38 | +// |
| 39 | +// OUT_DIR is the canonical bundle output that VSCode loads at runtime |
| 40 | +// (package.json `main` resolves here). Always non-platform-specific |
| 41 | +// because the bundled CommonJS is portable. |
| 42 | +// |
| 43 | +// BUILD_ROOT is a staging area for any per-mode / per-platform |
| 44 | +// intermediates (test fixtures, signed VSIX archives, etc.) that get |
| 45 | +// produced during dev or CI. Empty today; reserved for future use. |
| 46 | +export const OUT_DIR = path.join(PACKAGE_ROOT, 'out') |
| 47 | +export const BUILD_ROOT = path.join(PACKAGE_ROOT, 'build') |
| 48 | + |
| 49 | +// Source roots. |
| 50 | +export const SRC_DIR = path.join(PACKAGE_ROOT, 'src') |
| 51 | +export const VENDOR_DIR = path.join(PACKAGE_ROOT, 'vendor') |
| 52 | + |
| 53 | +// Top-level artifact paths. |
| 54 | +export const MAIN_BUNDLE = path.join(OUT_DIR, 'main.js') |
| 55 | +export const MAIN_BUNDLE_SOURCEMAP = path.join(OUT_DIR, 'main.js.map') |
| 56 | + |
| 57 | +// Source entrypoints. |
| 58 | +export const EXTENSION_ENTRY = path.join(SRC_DIR, 'extension.ts') |
| 59 | + |
| 60 | +/** |
| 61 | + * Build paths for a specific (mode, platform-arch) tuple. |
| 62 | + * |
| 63 | + * @param buildMode 'dev' | 'prod' (determines minify, debug toggles) |
| 64 | + * @param platformArch e.g. 'darwin-arm64', 'linux-x64', 'win32-x64'. |
| 65 | + * Use 'any' when the artifact is platform-agnostic. |
| 66 | + * |
| 67 | + * Returns an object whose keys mirror the socket-btm canonical: |
| 68 | + * buildDir build/<mode>/<platformArch> |
| 69 | + * outputFinalDir build/<mode>/<platformArch>/out/Final |
| 70 | + * outputFinalFile the bundled JS output |
| 71 | + * |
| 72 | + * For vscode-socket-security the `out/Final/main.js` mirror is |
| 73 | + * documentation only — the real shipped path is OUT_DIR/main.js (so |
| 74 | + * vsce packaging finds it). Per-mode build trees are reserved for |
| 75 | + * future use. |
| 76 | + */ |
| 77 | +export function getBuildPaths( |
| 78 | + buildMode: 'dev' | 'prod', |
| 79 | + platformArch: string, |
| 80 | +): { |
| 81 | + buildDir: string |
| 82 | + outputFinalDir: string |
| 83 | + outputFinalFile: string |
| 84 | +} { |
| 85 | + if (!buildMode) { |
| 86 | + throw new Error('buildMode is required for getBuildPaths()') |
| 87 | + } |
| 88 | + if (!platformArch) { |
| 89 | + throw new Error('platformArch is required for getBuildPaths()') |
| 90 | + } |
| 91 | + const buildDir = path.join(BUILD_ROOT, buildMode, platformArch) |
| 92 | + const outputFinalDir = path.join(buildDir, 'out', 'Final') |
| 93 | + return { |
| 94 | + buildDir, |
| 95 | + outputFinalDir, |
| 96 | + outputFinalFile: path.join(outputFinalDir, 'main.js'), |
| 97 | + } |
| 98 | +} |
0 commit comments