# core/loaders/leak.output.loader.ts

> 34 lines of code and 7 definitions.

Tree: Build tree
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/build#file-build-core-loaders-leak-output-loader-ts
Source text: https://banes-lab.com/source/build/core/loaders/leak.output.loader.ts.txt

Listed in [core/loaders](https://banes-lab.com/api/source/build/core/loaders.md), after [core/loaders/leak.loader.ts](https://banes-lab.com/source/build/core/loaders/leak.loader.ts.md) and before [core/loaders/link.loader.ts](https://banes-lab.com/source/build/core/loaders/link.loader.ts.md).

## Definitions

- `publishedPaths` (lexical_declaration, line 26, exported)
- `readPublished` (lexical_declaration, line 32, exported)
- `WINDOWS_SEPARATOR` (lexical_declaration, line 14)
- `textFilesUnder` (lexical_declaration, line 16)
- `full` (lexical_declaration, line 18)
- `machinePaths` (lexical_declaration, line 36, exported)
- `segments` (lexical_declaration, line 37, exported)

## Used by

- [runtime/entrypoints/leak.entrypoint.ts](https://banes-lab.com/source/build/runtime/entrypoints/leak.entrypoint.ts.md)

## Source

```typescript
import {
    ESCAPED_SEPARATOR,
    PATH_SEPARATOR,
    PUBLISHED_ROOT_KEYS,
    PUBLISHED_TEXT_EXTENSIONS,
    VCS_FOLDER,
} from "#configuration/constants/leak.constants";
import { ROOT, absolutePath } from "@ssot/paths";
import { existsSync, readFileSync, readdirSync } from "node:fs";
import { extname, join, relative, sep } from "node:path";
import type { PublishedFile } from "#types/leak.types";
import { UTF8 } from "#configuration/constants/source.constants";

const WINDOWS_SEPARATOR = "\\";

const textFilesUnder = function textFilesUnder(dir: string): string[] {
    return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
        const full = join(dir, entry.name);
        if (entry.isDirectory()) {
            return entry.name === VCS_FOLDER ? [] : textFilesUnder(full);
        }
        return entry.isFile() && PUBLISHED_TEXT_EXTENSIONS.has(extname(entry.name).toLowerCase()) ? [full] : [];
    });
};

export const publishedPaths = function publishedPaths(): string[] {
    return PUBLISHED_ROOT_KEYS.map((key) => absolutePath(key))
        .filter((root) => existsSync(root))
        .flatMap(textFilesUnder);
};

export const readPublished = function readPublished(path: string): PublishedFile {
    return { file: relative(ROOT, path).split(sep).join(PATH_SEPARATOR), text: readFileSync(path, UTF8) };
};

export const machinePaths = function machinePaths(): string[] {
    const segments = ROOT.split(WINDOWS_SEPARATOR).join(PATH_SEPARATOR).split(PATH_SEPARATOR);
    return [...new Set([ROOT, segments.join(PATH_SEPARATOR), segments.join(ESCAPED_SEPARATOR)])];
};
```
