tyfigo 0.2.0-next.a30eb96.0 → 0.2.1
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/README.md +28 -4
- package/dist/bun.d.mts +8 -1
- package/dist/bun.mjs +7 -7
- package/dist/bun.mjs.map +1 -1
- package/dist/effect.mjs +2 -2
- package/dist/{env-Bd-1Atoz.mjs → env--pSRlq_k.mjs} +2 -2
- package/dist/{env-Bd-1Atoz.mjs.map → env--pSRlq_k.mjs.map} +1 -1
- package/dist/env-Dv5OHfEf.mjs +51 -0
- package/dist/env-Dv5OHfEf.mjs.map +1 -0
- package/dist/{formats-D_dKXoPf.mjs → formats-Bf8-iQw-.mjs} +43 -15
- package/dist/{formats-D_dKXoPf.mjs.map → formats-Bf8-iQw-.mjs.map} +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{load-C-kweoyY.d.mts → load-D1KO5LdK.d.mts} +6 -4
- package/dist/{load-DxIjRpX6.mjs → load-yFCdP4to.mjs} +49 -23
- package/dist/load-yFCdP4to.mjs.map +1 -0
- package/dist/mapper.mjs +28 -11
- package/dist/mapper.mjs.map +1 -1
- package/dist/plugins/esbuild.d.mts +2 -2
- package/dist/plugins/esbuild.mjs +1 -1
- package/dist/plugins/jest.d.mts +1 -1
- package/dist/plugins/jest.mjs +4 -4
- package/dist/plugins/loader.d.mts +1 -1
- package/dist/plugins/loader.mjs +3 -2
- package/dist/plugins/loader.mjs.map +1 -1
- package/dist/plugins/next.d.mts +1 -1
- package/dist/plugins/next.mjs +9 -4
- package/dist/plugins/next.mjs.map +1 -1
- package/dist/plugins/rolldown.d.mts +2 -2
- package/dist/plugins/rolldown.mjs +1 -1
- package/dist/plugins/rollup.d.mts +2 -2
- package/dist/plugins/rollup.mjs +1 -1
- package/dist/plugins/rsbuild.d.mts +2 -2
- package/dist/plugins/rsbuild.mjs +1 -1
- package/dist/plugins/rspack.d.mts +2 -2
- package/dist/plugins/rspack.mjs +1 -1
- package/dist/plugins/vite.d.mts +2 -2
- package/dist/plugins/vite.mjs +1 -1
- package/dist/plugins/webpack.d.mts +2 -2
- package/dist/plugins/webpack.mjs +1 -1
- package/dist/problems-DS_eJB6e.mjs +86 -0
- package/dist/problems-DS_eJB6e.mjs.map +1 -0
- package/dist/register.mjs +5 -5
- package/dist/register.mjs.map +1 -1
- package/dist/{resolve-D3geHCGs.mjs → resolve-DQfTdYJN.mjs} +32 -12
- package/dist/resolve-DQfTdYJN.mjs.map +1 -0
- package/dist/runtime/index.d.mts +13 -4
- package/dist/runtime/index.mjs +2 -2
- package/dist/{runtime-DeRUtPZ9.mjs → runtime-B3GmIYop.mjs} +13 -9
- package/dist/runtime-B3GmIYop.mjs.map +1 -0
- package/dist/{shared-CZ44uwQq.d.mts → shared-B6Y3_kdn.d.mts} +6 -5
- package/dist/{shared-BnK77Zcp.mjs → shared-DOMPQnVO.mjs} +4 -6
- package/dist/shared-DOMPQnVO.mjs.map +1 -0
- package/dist/{sync-B-HAK-_E.mjs → sync-mWkXcCOW.mjs} +2 -2
- package/dist/{sync-B-HAK-_E.mjs.map → sync-mWkXcCOW.mjs.map} +1 -1
- package/dist/unplugin-BYfqHkIE.d.mts +2 -0
- package/dist/{unplugin-BQGm_bhA.mjs → unplugin-BoZ7PwTA.mjs} +36 -13
- package/dist/unplugin-BoZ7PwTA.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/env-R3_XPW_u.mjs +0 -78
- package/dist/env-R3_XPW_u.mjs.map +0 -1
- package/dist/load-DxIjRpX6.mjs.map +0 -1
- package/dist/problems-BNAqmOzL.mjs +0 -23
- package/dist/problems-BNAqmOzL.mjs.map +0 -1
- package/dist/resolve-D3geHCGs.mjs.map +0 -1
- package/dist/runtime-DeRUtPZ9.mjs.map +0 -1
- package/dist/shared-BnK77Zcp.mjs.map +0 -1
- package/dist/unplugin-AC_HM_T2.d.mts +0 -2
- package/dist/unplugin-BQGm_bhA.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"problems-BNAqmOzL.mjs","names":[],"sources":["../src/core/problems.ts"],"sourcesContent":["import type { SourceIndex } from './positions.ts';\n\nexport type ProblemCode =\n\t| 'parse-error'\n\t| 'duplicate-key'\n\t| 'file-not-found'\n\t| 'read-error'\n\t| 'unsupported-file'\n\t| 'missing-variable'\n\t| 'invalid-placeholder'\n\t| 'browser-placeholder'\n\t| 'placeholder-type'\n\t| 'unknown-key'\n\t| 'type-mismatch';\n\n/**\n * Something wrong with a config file. `start` and `length` are UTF-8 byte offsets, `line` and `column` are 1-based and\n * `column` counts UTF-16 code units.\n */\nexport interface Problem {\n\treadonly file: string;\n\treadonly start: number;\n\treadonly length: number;\n\treadonly line: number;\n\treadonly column: number;\n\treadonly message: string;\n\treadonly code: ProblemCode;\n}\n\nexport const problemAt = (\n\tsource: SourceIndex,\n\tfile: string,\n\tstart: number,\n\tlength: number,\n\tcode: ProblemCode,\n\tmessage: string,\n): Problem => ({ file, start, length, ...source.lineColumn(start), message, code });\n\nexport const fileProblem = (file: string, code: ProblemCode, message: string): Problem => ({\n\tfile,\n\tstart: 0,\n\tlength: 0,\n\tline: 1,\n\tcolumn: 1,\n\tmessage,\n\tcode,\n});\n\nexport const formatProblem = (problem: Problem): string =>\n\t`${problem.file}:${problem.line}:${problem.column} - ${problem.message} (${problem.code})`;\n\nexport const formatProblems = (problems: readonly Problem[]): string => problems.map(formatProblem).join('\\n');\n"],"mappings":";AA6BA,MAAa,aACZ,QACA,MACA,OACA,QACA,MACA,aACc;CAAE;CAAM;CAAO;CAAQ,GAAG,OAAO,WAAW,KAAK;CAAG;CAAS;AAAK;AAEjF,MAAa,eAAe,MAAc,MAAmB,aAA8B;CAC1F;CACA,OAAO;CACP,QAAQ;CACR,MAAM;CACN,QAAQ;CACR;CACA;AACD;AAEA,MAAa,iBAAiB,YAC7B,GAAG,QAAQ,KAAK,GAAG,QAAQ,KAAK,GAAG,QAAQ,OAAO,KAAK,QAAQ,QAAQ,IAAI,QAAQ,KAAK;AAEzF,MAAa,kBAAkB,aAAyC,SAAS,IAAI,aAAa,CAAC,CAAC,KAAK,IAAI"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-D3geHCGs.mjs","names":[],"sources":["../src/core/layers.ts","../src/core/merge.ts","../src/core/resolve.ts"],"sourcesContent":["import { basename, dirname, join, resolve } from 'node:path';\n\nimport { Effect } from 'effect';\n\nimport { findFile, isFile, searchDirectories } from './files.ts';\nimport { parseConfigFileName } from './formats/index.ts';\n\nexport type LayerKind = 'base' | 'environment' | 'local' | 'environment-local';\n\nexport interface LayerFile {\n\treadonly file: string;\n\treadonly kind: LayerKind;\n}\n\n/**\n * The layer files of a base config file, in the order they apply: `app.config.yaml`, `app.<environment>.config.yaml`,\n * `app.local.config.yaml` and `app.<environment>.local.config.yaml`. Only files that exist are listed. Environment files sit next\n * to the base file, and local files are searched next to it first, then in the nearest directory with a `package.json`.\n */\nexport const discoverLayers = Effect.fn('discoverLayers')(function* (baseFile: string, environment?: string) {\n\tconst file = resolve(baseFile);\n\tconst name = parseConfigFileName(basename(file));\n\tif (!name) return [];\n\n\tconst directories = yield* searchDirectories(file);\n\tconst layers: LayerFile[] = [];\n\tif (yield* isFile(file)) layers.push({ file, kind: 'base' });\n\tif (environment) {\n\t\tconst environmentFile = join(dirname(file), `${name.stem}.${environment}${name.suffix}`);\n\t\tif (yield* isFile(environmentFile)) layers.push({ file: environmentFile, kind: 'environment' });\n\t}\n\n\tconst local = yield* findFile(directories, `${name.stem}.local${name.suffix}`);\n\tif (local) layers.push({ file: local, kind: 'local' });\n\tif (environment) {\n\t\tconst environmentLocal = yield* findFile(directories, `${name.stem}.${environment}.local${name.suffix}`);\n\t\tif (environmentLocal) layers.push({ file: environmentLocal, kind: 'environment-local' });\n\t}\n\n\treturn layers;\n});\n","import { basename } from 'node:path';\n\nimport { isPlainObject, kindOf } from './placeholders.ts';\nimport { formatPath, pathKey } from './positions.ts';\nimport { problemAt } from './problems.ts';\n\nimport type { Path, PositionMap, SourceIndex, Span } from './positions.ts';\nimport type { Problem } from './problems.ts';\n\n/**\n * A {@link Span} together with the file it is in.\n */\nexport interface LocatedSpan extends Span {\n\treadonly file: string;\n}\n\nexport interface MergeLayer {\n\treadonly file: string;\n\treadonly value: unknown;\n\treadonly positions: PositionMap;\n\treadonly source: SourceIndex;\n}\n\nexport interface MergeResult {\n\treadonly value: unknown;\n\treadonly positions: ReadonlyMap<string, LocatedSpan>;\n\treadonly problems: readonly Problem[];\n}\n\nconst isWithin = (id: string, prefix: string) =>\n\tid === prefix || id.startsWith(prefix === '[]' ? '[' : `${prefix.slice(0, -1)},`);\n\nexport const locate = (file: string, positions: PositionMap): Map<string, LocatedSpan> =>\n\tnew Map([...positions].map(([id, span]) => [id, { ...span, file }]));\n\n/**\n * Applies `layer` over `base`. Objects merge, arrays and primitives replace. A key that `base` lacks, or a value of a different\n * type (`null`, boolean, number, string, array or object), is a problem and that part of the layer is skipped.\n */\nexport const mergeLayer = (\n\tbase: { readonly value: unknown; readonly positions: ReadonlyMap<string, LocatedSpan> },\n\tlayer: MergeLayer,\n): MergeResult => {\n\tconst positions = new Map(base.positions);\n\tconst problems: Problem[] = [];\n\n\tconst report = (path: Path, onKey: boolean, code: 'unknown-key' | 'type-mismatch', message: string) => {\n\t\tconst span = layer.positions.get(pathKey(path));\n\t\tconst start = span ? (onKey ? span.keyStart : span.valueStart) : 0;\n\t\tconst length = span ? (onKey ? span.keyLength : span.valueLength) : 0;\n\t\tproblems.push(problemAt(layer.source, layer.file, start, length, code, message));\n\t};\n\n\tconst origin = (path: Path) => {\n\t\tconst file = positions.get(pathKey(path))?.file;\n\t\treturn file ? basename(file) : 'the base file';\n\t};\n\n\tconst replace = (path: Path) => {\n\t\tconst prefix = pathKey(path);\n\t\tfor (const id of positions.keys()) if (isWithin(id, prefix)) positions.delete(id);\n\t\tfor (const [id, span] of layer.positions) {\n\t\t\tif (isWithin(id, prefix)) positions.set(id, { ...span, file: layer.file });\n\t\t}\n\t};\n\n\tconst merge = (current: unknown, next: unknown, path: Path): unknown => {\n\t\tif (isPlainObject(current) && isPlainObject(next)) {\n\t\t\tconst result = { ...current };\n\t\t\tfor (const [key, value] of Object.entries(next)) {\n\t\t\t\tconst childPath = [...path, key];\n\t\t\t\tif (Object.hasOwn(current, key)) result[key] = merge(current[key], value, childPath);\n\t\t\t\telse {\n\t\t\t\t\treport(\n\t\t\t\t\t\tchildPath,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t'unknown-key',\n\t\t\t\t\t\t`'${formatPath(childPath)}' is not in ${origin(path)}; environment and local files can only override existing keys`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tconst expected = kindOf(current);\n\t\tconst actual = kindOf(next);\n\t\tif (expected !== actual) {\n\t\t\treport(\n\t\t\t\tpath,\n\t\t\t\tfalse,\n\t\t\t\t'type-mismatch',\n\t\t\t\t`Expected ${expected} at '${formatPath(path) || '(root)'}' as in ${origin(path)}, got ${actual}`,\n\t\t\t);\n\t\t\treturn current;\n\t\t}\n\n\t\treplace(path);\n\t\treturn next;\n\t};\n\n\treturn { value: merge(base.value, layer.value, []), positions, problems };\n};\n","import { readFileSync } from 'node:fs';\nimport { basename, resolve } from 'node:path';\n\nimport { Effect, Result } from 'effect';\n\nimport { processEnv, readEnv } from './env.ts';\nimport { isFile } from './files.ts';\nimport { configSuffixes, parseConfigFileName } from './formats/index.ts';\nimport { discoverLayers } from './layers.ts';\nimport { locate, mergeLayer } from './merge.ts';\nimport { resolvePlaceholders } from './placeholders.ts';\nimport { SourceIndex } from './positions.ts';\nimport { fileProblem } from './problems.ts';\n\nimport type { EnvVariables } from './env.ts';\nimport type { Format } from './formats/index.ts';\nimport type { LayerFile, LayerKind } from './layers.ts';\nimport type { LocatedSpan } from './merge.ts';\nimport type { Path, PositionMap } from './positions.ts';\nimport type { Problem } from './problems.ts';\n\nexport interface ResolveOptions {\n\t/**\n\t * The real environment variables, which win over every `.env` file. Defaults to a copy of the current ones.\n\t */\n\treadonly env?: EnvVariables | undefined;\n\t/**\n\t * The environment name that picks `app.<environment>.config.yaml` and `.env.<environment>`. Defaults to `env.NODE_ENV`.\n\t */\n\treadonly environment?: string | undefined;\n\t/**\n\t * The layer kinds to read. Defaults to all of them.\n\t */\n\treadonly layers?: readonly LayerKind[] | undefined;\n}\n\nexport interface ResolvedLayer {\n\treadonly file: string;\n\treadonly kind: LayerKind;\n\treadonly text: string;\n\t/**\n\t * The parsed value with placeholders resolved, or `undefined` when the file could not be parsed.\n\t */\n\treadonly value: unknown;\n\treadonly positions: PositionMap;\n}\n\nexport interface ResolvedConfig {\n\t/**\n\t * The base file, resolved to an absolute path.\n\t */\n\treadonly file: string;\n\treadonly format: Format | undefined;\n\treadonly environment: string | undefined;\n\t/**\n\t * The merged value, or `undefined` when the base file is missing or could not be parsed.\n\t */\n\treadonly value: unknown;\n\treadonly layers: readonly ResolvedLayer[];\n\treadonly envFiles: readonly string[];\n\t/**\n\t * Where each key path of `value` came from, keyed by `pathKey`.\n\t */\n\treadonly positions: ReadonlyMap<string, LocatedSpan>;\n\treadonly problems: readonly Problem[];\n}\n\nconst readText = (file: string) =>\n\tEffect.try({\n\t\ttry: () => readFileSync(file, 'utf8'),\n\t\tcatch: (error) => fileProblem(file, 'read-error', `Cannot read ${file}: ${(error as Error).message}`),\n\t});\n\nconst valueAt = (value: unknown, path: Path): unknown =>\n\tpath.reduce<unknown>(\n\t\t(current, segment) =>\n\t\t\ttypeof current === 'object' && current !== null && Object.hasOwn(current, segment)\n\t\t\t\t? (current as Record<string | number, unknown>)[segment]\n\t\t\t\t: undefined,\n\t\tvalue,\n\t);\n\nconst mergeLayers = Effect.fn('mergeLayers')(function* <Layer extends LayerFile>(\n\tformat: Format,\n\tfiles: readonly Layer[],\n\tread: (layer: Layer) => Effect.Effect<string, Problem>,\n\tvariables: EnvVariables,\n) {\n\tconst problems: Problem[] = [];\n\tconst layers: ResolvedLayer[] = [];\n\tlet merged: { value: unknown; positions: ReadonlyMap<string, LocatedSpan> } | undefined;\n\n\tfor (const layer of files) {\n\t\tconst content = yield* Effect.result(read(layer));\n\t\tif (Result.isFailure(content)) {\n\t\t\tproblems.push(content.failure);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst text = content.success;\n\t\tconst parsed = format.parse(text, layer.file);\n\t\tproblems.push(...parsed.problems);\n\t\tconst source = new SourceIndex(text);\n\t\tconst base = merged?.value;\n\t\tconst resolved =\n\t\t\tparsed.value === undefined\n\t\t\t\t? { value: undefined, problems: [] }\n\t\t\t\t: resolvePlaceholders({\n\t\t\t\t\t\tvalue: parsed.value,\n\t\t\t\t\t\tpositions: parsed.positions,\n\t\t\t\t\t\tsource,\n\t\t\t\t\t\tfile: layer.file,\n\t\t\t\t\t\tformat,\n\t\t\t\t\t\tvariables,\n\t\t\t\t\t\tbaseValueAt: merged && ((path) => valueAt(base, path)),\n\t\t\t\t\t});\n\t\tproblems.push(...resolved.problems);\n\t\tlayers.push({ file: layer.file, kind: layer.kind, text, value: resolved.value, positions: parsed.positions });\n\t\tif (resolved.value === undefined) continue;\n\n\t\tif (!merged) {\n\t\t\tmerged =\n\t\t\t\tlayer.kind === 'base'\n\t\t\t\t\t? { value: resolved.value, positions: locate(layer.file, parsed.positions) }\n\t\t\t\t\t: undefined;\n\t\t\tcontinue;\n\t\t}\n\t\tconst result = mergeLayer(merged, {\n\t\t\tfile: layer.file,\n\t\t\tvalue: resolved.value,\n\t\t\tpositions: parsed.positions,\n\t\t\tsource,\n\t\t});\n\t\tproblems.push(...result.problems);\n\t\tmerged = result;\n\t}\n\n\treturn { layers, value: merged?.value, positions: merged?.positions ?? new Map(), problems };\n});\n\nconst unsupportedFile = (file: string) =>\n\tfileProblem(\n\t\tfile,\n\t\t'unsupported-file',\n\t\t`${basename(file)} is not a config file; expected a name ending in ${configSuffixes.join(', ')}`,\n\t);\n\n/**\n * Reads a config file with its environment and local layers and `.env` files, resolves placeholders and merges the layers.\n * Never fails: everything that went wrong is in `problems`.\n */\nexport const resolveConfig = Effect.fn('resolveConfig')(function* (path: string, options: ResolveOptions = {}) {\n\tconst file = resolve(path);\n\tconst env = options.env ?? processEnv();\n\tconst environment = options.environment ?? (env.NODE_ENV || undefined);\n\tconst name = parseConfigFileName(basename(file));\n\tconst empty = {\n\t\tfile,\n\t\tformat: name?.format,\n\t\tenvironment,\n\t\tvalue: undefined,\n\t\tlayers: [],\n\t\tenvFiles: [],\n\t\tpositions: new Map(),\n\t};\n\tif (!name) return { ...empty, problems: [unsupportedFile(file)] } satisfies ResolvedConfig;\n\tif (!(yield* isFile(file))) {\n\t\treturn {\n\t\t\t...empty,\n\t\t\tproblems: [fileProblem(file, 'file-not-found', `Cannot find ${file}`)],\n\t\t} satisfies ResolvedConfig;\n\t}\n\n\tconst envResult = yield* readEnv(file, { environment, env });\n\tconst files = (yield* discoverLayers(file, environment)).filter(\n\t\t(layer) => !options.layers || options.layers.includes(layer.kind),\n\t);\n\tconst merged = yield* mergeLayers(name.format, files, (layer) => readText(layer.file), envResult.variables);\n\treturn {\n\t\t...empty,\n\t\t...merged,\n\t\tenvFiles: envResult.files,\n\t\tproblems: [...envResult.problems, ...merged.problems],\n\t} satisfies ResolvedConfig;\n});\n\nexport interface LayerSource extends LayerFile {\n\treadonly text: string;\n}\n\nexport interface ResolveSourcesOptions {\n\treadonly env?: EnvVariables | undefined;\n\treadonly environment?: string | undefined;\n\t/**\n\t * A path in the directory to search `.env` files from first, before the nearest directory with a `package.json`.\n\t */\n\treadonly envFrom: string;\n}\n\n/**\n * {@link resolveConfig} for layer files whose text was read earlier, such as the layers a bundler inlined at build time. `file`\n * names the base file and picks the format; it is used as given and never read. Never fails: everything that went wrong is in\n * `problems`.\n */\nexport const resolveConfigSources = Effect.fn('resolveConfigSources')(function* (\n\tfile: string,\n\tsources: readonly LayerSource[],\n\toptions: ResolveSourcesOptions,\n) {\n\tconst env = options.env ?? processEnv();\n\tconst environment = options.environment ?? (env.NODE_ENV || undefined);\n\tconst name = parseConfigFileName(basename(file));\n\tconst empty = {\n\t\tfile,\n\t\tformat: name?.format,\n\t\tenvironment,\n\t\tvalue: undefined,\n\t\tlayers: [],\n\t\tenvFiles: [],\n\t\tpositions: new Map(),\n\t};\n\tif (!name) return { ...empty, problems: [unsupportedFile(file)] } satisfies ResolvedConfig;\n\n\tconst envResult = yield* readEnv(options.envFrom, { environment, env });\n\tconst merged = yield* mergeLayers(name.format, sources, (layer) => Effect.succeed(layer.text), envResult.variables);\n\treturn {\n\t\t...empty,\n\t\t...merged,\n\t\tenvFiles: envResult.files,\n\t\tproblems: [...envResult.problems, ...merged.problems],\n\t} satisfies ResolvedConfig;\n});\n"],"mappings":";;;;;;;;;;;;;AAmBA,MAAa,iBAAiB,OAAO,GAAG,gBAAgB,CAAC,CAAC,WAAW,UAAkB,aAAsB;CAC5G,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,OAAO,oBAAoB,SAAS,IAAI,CAAC;CAC/C,IAAI,CAAC,MAAM,OAAO,CAAC;CAEnB,MAAM,cAAc,OAAO,kBAAkB,IAAI;CACjD,MAAM,SAAsB,CAAC;CAC7B,IAAI,OAAO,OAAO,IAAI,GAAG,OAAO,KAAK;EAAE;EAAM,MAAM;CAAO,CAAC;CAC3D,IAAI,aAAa;EAChB,MAAM,kBAAkB,KAAK,QAAQ,IAAI,GAAG,GAAG,KAAK,KAAK,GAAG,cAAc,KAAK,QAAQ;EACvF,IAAI,OAAO,OAAO,eAAe,GAAG,OAAO,KAAK;GAAE,MAAM;GAAiB,MAAM;EAAc,CAAC;CAC/F;CAEA,MAAM,QAAQ,OAAO,SAAS,aAAa,GAAG,KAAK,KAAK,QAAQ,KAAK,QAAQ;CAC7E,IAAI,OAAO,OAAO,KAAK;EAAE,MAAM;EAAO,MAAM;CAAQ,CAAC;CACrD,IAAI,aAAa;EAChB,MAAM,mBAAmB,OAAO,SAAS,aAAa,GAAG,KAAK,KAAK,GAAG,Y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,CAAC;EACT,UAAU,CAAC;EACX,2BAAW,IAAI,IAAI;CACpB;CACA,IAAI,CAAC,MAAM,OAAO;EAAE,GAAG;EAAO,UAAU,CAAC,gBAAgB,IAAI,CAAC;CAAE;CAEhE,MAAM,YAAY,OAAO,QAAQ,QAAQ,SAAS;EAAE;EAAa;CAAI,CAAC;CACtE,MAAM,SAAS,OAAO,YAAY,KAAK,QAAQ,UAAU,UAAU,OAAO,QAAQ,MAAM,IAAI,GAAG,UAAU,SAAS;CAClH,OAAO;EACN,GAAG;EACH,GAAG;EACH,UAAU,UAAU;EACpB,UAAU,CAAC,GAAG,UAAU,UAAU,GAAG,OAAO,QAAQ;CACrD;AACD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-DeRUtPZ9.mjs","names":[],"sources":["../src/runtime/resolve.ts"],"sourcesContent":["import { basename, join } from 'node:path';\nimport process from 'node:process';\n\nimport { Data } from 'effect';\n\nimport { configSource } from './source.ts';\n\nimport { formatProblems, pathKey, resolveConfigSourcesSync, resolveConfigSync, SourceIndex } from '../core/index.ts';\n\nimport type { LayerSource, Problem, ResolvedConfig } from '../core/index.ts';\nimport type { ConfigSource } from './source.ts';\n\nexport class ConfigModuleError extends Data.TaggedError('ConfigModuleError')<{\n\treadonly message: string;\n\treadonly file: string;\n\treadonly problems: readonly Problem[];\n}> {}\n\nexport interface ConfigModuleOptions {\n\t/**\n\t * The environment name that picks `app.<environment>.config.yaml` and `.env.<environment>`. Defaults to `NODE_ENV`.\n\t */\n\treadonly environment?: string | undefined;\n}\n\nexport const deepFreeze = <T>(value: T): T => {\n\tif (typeof value === 'object' && value !== null && !Object.isFrozen(value)) {\n\t\tObject.freeze(value);\n\t\tfor (const item of Object.values(value)) deepFreeze(item);\n\t}\n\treturn value;\n};\n\nconst sourceOf = (result: ResolvedConfig): ConfigSource => {\n\tconst texts = new Map(result.layers.map((layer) => [layer.file, layer.text]));\n\tconst indexes = new Map<string, SourceIndex>();\n\tconst indexOf = (file: string) => {\n\t\tconst text = texts.get(file);\n\t\tif (text === undefined) return undefined;\n\t\tconst index = indexes.get(file) ?? new SourceIndex(text);\n\t\tindexes.set(file, index);\n\t\treturn index;\n\t};\n\n\treturn {\n\t\tfile: result.file,\n\t\tenvironment: result.environment,\n\t\tlayers: result.layers.map((layer) => layer.file),\n\t\tenvFiles: result.envFiles,\n\t\tposition: (path) => {\n\t\t\tfor (let depth = path.length; depth >= 0; depth--) {\n\t\t\t\tconst span = result.positions.get(pathKey(path.slice(0, depth)));\n\t\t\t\tif (!span) continue;\n\t\t\t\tconst index = indexOf(span.file);\n\t\t\t\treturn index ? { file: span.file, ...index.lineColumn(span.valueStart) } : undefined;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t},\n\t};\n};\n\nconst toModule = (result: ResolvedConfig): unknown => {\n\tif (result.problems.length > 0) {\n\t\tthrow new ConfigModuleError({\n\t\t\tmessage: `Invalid config ${result.file}\\n${formatProblems(result.problems)}`,\n\t\t\tfile: result.file,\n\t\t\tproblems: result.problems,\n\t\t});\n\t}\n\n\tif (typeof result.value === 'object' && result.value !== null) {\n\t\tObject.defineProperty(result.value, configSource, { value: sourceOf(result) });\n\t}\n\treturn deepFreeze(result.value);\n};\n\n/**\n * Resolves a config file with its layers, `.env` files and placeholders, and returns the deep-frozen value. This is what a\n * generated server module calls when it is evaluated. Throws a {@link ConfigModuleError} listing every problem.\n */\nexport const resolveConfigModule = (file: string, options: ConfigModuleOptions = {}): unknown =>\n\ttoModule(resolveConfigSync(file, { environment: options.environment }));\n\n/**\n * The layer files a bundled server module carries, with paths relative to the project root of the machine that built it.\n */\nexport interface BundledConfig {\n\treadonly file: string;\n\treadonly environment?: string | undefined;\n\treadonly layers: readonly LayerSource[];\n}\n\n/**\n * {@link resolveConfigModule} for a bundled server module: merges the layers inlined at build time with the `.env` files found\n * from `process.cwd()` and the environment variables.\n */\nexport const resolveBundledConfigModule = (bundle: BundledConfig): unknown =>\n\ttoModule(\n\t\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EA,MAAM,YAAY,WAAoC;CACrD,IAAI,OAAO,SAAS,SAAS,GAC5B,MAAM,IAAI,kBAAkB;EAC3B,SAAS,kBAAkB,OAAO,KAAK,IAAI,eAAe,OAAO,QAAQ;EACzE,MAAM,OAAO;EACb,UAAU,OAAO;CAClB,CAAC;CAGF,IAAI,OAAO,OAAO,UAAU,YAAY,OAAO,UAAU,MACxD,OAAO,eAAe,OAAO,OAAO,cAAc,EAAE,OAAO,SAAS,MAAM,EAAE,CAAC;CAE9E,OAAO,WAAW,OAAO,KAAK;AAC/B;;;;;AAMA,MAAa,uBAAuB,MAAc,UAA+B,CAAC,MACjF,SAAS,kBAAkB,MAAM,EAAE,aAAa,QAAQ,YAAY,CAAC,CAAC;;;;;AAevE,MAAa,8BAA8B,WAC1C,SACC,yBAAyB,OAAO,MAAM,OAAO,QAAQ;CACpD,aAAa,OAAO;CACpB,SAAS,KAAK,QAAQ,IAAI,GAAG,SAAS,OAAO,IAAI,CAAC;AACnD,CAAC,CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shared-BnK77Zcp.mjs","names":[],"sources":["../src/plugins/shared.ts"],"sourcesContent":["import { configSuffixes, formatProblems } from '../core/index.ts';\nimport { load } from '../runtime/load.ts';\n\nimport type { LoadOptions, LoadResult, LoadTarget } from '../runtime/load.ts';\n\nexport interface TyfigoPluginOptions {\n\t/**\n\t * Overrides the detected target. `browser` inlines the base and environment files and fails on placeholders and on imports of\n\t * `loadEnv` and the other exports that need Node.js. `server` inlines the base, environment and local files of the build's\n\t * environment and reads `.env` files and environment variables when the bundle runs.\n\t */\n\treadonly target?: LoadTarget | undefined;\n\t/**\n\t * The environment name. Defaults to the bundler's mode where it has one (Vite, webpack, Rspack, Rsbuild), otherwise `NODE_ENV`.\n\t */\n\treadonly environment?: string | undefined;\n\t/**\n\t * The specifier server modules import the runtime from. Defaults to `tyfigo/runtime`.\n\t */\n\treadonly runtime?: string | undefined;\n}\n\nexport const configFilePattern = new RegExp(\n\t`(?:${configSuffixes.map((suffix) => suffix.replaceAll('.', String.raw`\\.`)).join('|')})$`,\n\t'u',\n);\n\n/**\n * Generates the module for a config import and throws one error listing every problem, which fails the build.\n */\nexport const loadConfigImport = (file: string, options: LoadOptions): LoadResult => {\n\tconst result = load(file, options);\n\tif (result.problems.length > 0) throw new Error(`Invalid config ${file}\\n${formatProblems(result.problems)}`);\n\treturn result;\n};\n\nexport interface WebpackLikePlatform {\n\treadonly web?: boolean | null;\n\treadonly node?: boolean | null;\n}\n\nexport interface WebpackLikeCompiler {\n\treadonly platform: WebpackLikePlatform;\n\treadonly options: { readonly mode?: string | undefined };\n}\n\nexport const isServerPlatform = (platform: WebpackLikePlatform): boolean => platform.node === true && !platform.web;\n\nconst nodeOnlyExports: Readonly<Record<string, readonly string[]>> = {\n\ttyfigo: ['loadEnv', 'loadEnvAsync'],\n\t'tyfigo/effect': ['loadEnv', 'layerEnv', 'configProviderFromFile', 'layerConfigProviderFromFile'],\n};\n\nconst tyfigoSource = /\\bfrom\\s*[\"'](tyfigo(?:\\/effect)?)[\"']/gu;\n\nexport const tyfigoImportPattern = /[\"']tyfigo(?:\\/effect)?[\"']/u;\n\nconst usesNamespaceMember = (code: string, namespace: string, name: string) =>\n\tnew RegExp(String.raw`(?<![\\w$.])${namespace.replaceAll('$', String.raw`\\$`)}\\s*\\??\\.\\s*${name}\\b`, 'u').test(code);\n\nconst namedSpecifiers = (clause: string): string[] => {\n\tconst open = clause.indexOf('{');\n\tconst close = clause.indexOf('}', open);\n\tif (open === -1 || close === -1) return [];\n\treturn clause\n\t\t.slice(open + 1, close)\n\t\t.split(',')\n\t\t.map((specifier) => specifier.trim().split(/\\s/u)[0] ?? '');\n};\n\n/**\n * Finds imports of the tyfigo exports that need Node.js, such as `loadEnv`, and returns one message per import for a browser\n * build to fail with.\n */\nexport const findNodeOnlyImports = (code: string, id: string): string[] => {\n\tconst messages: string[] = [];\n\tfor (const match of code.matchAll(tyfigoSource)) {\n\t\tconst source = match[1] ?? '';\n\t\tconst start = Math.max(code.lastIndexOf('import', match.index), code.lastIndexOf('export', match.index));\n\t\tconst clause = code.slice(start + 'import'.length, match.index);\n\t\tif (start === -1 || /[;'\"`]/u.test(clause) || /^\\s*type[\\s{]/u.test(clause)) continue;\n\n\t\tconst specifiers = namedSpecifiers(clause);\n\t\tconst namespace = /\\*\\s*as\\s+([\\w$]+)/u.exec(clause)?.[1];\n\t\tconst used = (nodeOnlyExports[source] ?? []).filter(\n\t\t\t(name) =>\n\t\t\t\tspecifiers.includes(name) || (namespace !== undefined && usesNamespaceMember(code, namespace, name)),\n\t\t);\n\t\tconst before = code.slice(0, start);\n\t\tconst location = `${id}:${before.split('\\n').length}:${start - before.lastIndexOf('\\n')}`;\n\t\tfor (const name of used) {\n\t\t\tmessages.push(\n\t\t\t\t`${location} - ${name} from '${source}' reads files and environment variables with Node.js, so it cannot run in a browser bundle. Call it in server code, or set the tyfigo plugin's target option to 'server' if this bundle runs on a server.`,\n\t\t\t);\n\t\t}\n\t}\n\treturn messages;\n};\n"],"mappings":";;;;AAsBA,MAAa,oBAAoB,IAAI,OACpC,MAAM,eAAe,KAAK,WAAW,OAAO,WAAW,KAAK,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,KACvF,GACD;;;;AAKA,MAAa,oBAAoB,MAAc,YAAqC;CACnF,MAAM,SAAS,KAAK,MAAM,OAAO;CACjC,IAAI,OAAO,SAAS,SAAS,GAAG,MAAM,IAAI,MAAM,kBAAkB,KAAK,IAAI,eAAe,OAAO,QAAQ,GAAG;CAC5G,OAAO;AACR;AAYA,MAAa,oBAAoB,aAA2C,SAAS,SAAS,QAAQ,CAAC,SAAS;AAEhH,MAAM,kBAA+D;CACpE,QAAQ,CAAC,WAAW,cAAc;CAClC,iBAAiB;EAAC;EAAW;EAAY;EAA0B;CAA6B;AACjG;AAEA,MAAM,eAAe;AAErB,MAAa,sBAAsB;AAEnC,MAAM,uBAAuB,MAAc,WA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,KACR,GAAG,SAAS,KAAK,KAAK,SAAS,OAAO,0MACvC;CAEF;CACA,OAAO;AACR"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unplugin-BQGm_bhA.mjs","names":[],"sources":["../src/plugins/unplugin.ts"],"sourcesContent":["import { createUnplugin } from 'unplugin';\n\nimport {\n\tconfigFilePattern,\n\tfindNodeOnlyImports,\n\tisServerPlatform,\n\tloadConfigImport,\n\ttyfigoImportPattern,\n} from './shared.ts';\n\nimport type { LoadOptions } from '../runtime/load.ts';\nimport type { TyfigoPluginOptions, WebpackLikeCompiler } from './shared.ts';\nimport type { UnpluginBuildContext, UnpluginFactory } from 'unplugin';\n\nexport type { TyfigoPluginOptions } from './shared.ts';\n\nconst webpackMode = (compiler: WebpackLikeCompiler) =>\n\tcompiler.options.mode === 'none' ? undefined : compiler.options.mode;\n\ninterface ViteContext {\n\treadonly environment?: { readonly config: { readonly consumer: string } };\n}\n\nexport const unpluginFactory: UnpluginFactory<TyfigoPluginOptions | undefined, false> = (options = {}) => {\n\tlet viteCommand: string | undefined;\n\tlet viteMode: string | undefined;\n\tlet rolldownPlatform: string | undefined;\n\n\tconst detect = (\n\t\tcontext: UnpluginBuildContext,\n\t\tloadOptions: { readonly ssr?: boolean } | undefined,\n\t): Pick<LoadOptions, 'target' | 'bundle' | 'environment'> => {\n\t\tconst native = context.getNativeBuildContext?.();\n\t\tif (native?.framework === 'webpack' || native?.framework === 'rspack') {\n\t\t\tconst compiler = native.compiler as WebpackLikeCompiler;\n\t\t\treturn {\n\t\t\t\ttarget: isServerPlatform(compiler.platform) ? 'server' : 'browser',\n\t\t\t\tbundle: true,\n\t\t\t\tenvironment: webpackMode(compiler),\n\t\t\t};\n\t\t}\n\t\tif (native?.framework === 'esbuild') {\n\t\t\treturn { target: native.build.initialOptions.platform === 'node' ? 'server' : 'browser', bundle: true };\n\t\t}\n\t\tif (viteCommand) {\n\t\t\tconst consumer = (context as ViteContext).environment?.config.consumer;\n\t\t\treturn {\n\t\t\t\ttarget: (consumer === undefined ? loadOptions?.ssr : consumer === 'server') ? 'server' : 'browser',\n\t\t\t\tbundle: viteCommand === 'build',\n\t\t\t\tenvironment: viteMode,\n\t\t\t};\n\t\t}\n\t\treturn { target: rolldownPlatform === 'node' ? 'server' : 'browser', bundle: true };\n\t};\n\n\treturn {\n\t\tname: 'tyfigo',\n\t\tenforce: 'pre',\n\t\tload: {\n\t\t\tfilter: { id: configFilePattern },\n\t\t\thandler(id, loadOptions?: { readonly ssr?: boolean }) {\n\t\t\t\tconst detected = detect(this, loadOptions);\n\t\t\t\tconst result = loadConfigImport(id, {\n\t\t\t\t\t...detected,\n\t\t\t\t\ttarget: options.target ?? detected.target,\n\t\t\t\t\tenvironment: options.environment ?? detected.environment,\n\t\t\t\t\truntime: options.runtime,\n\t\t\t\t});\n\t\t\t\tfor (const file of result.watchFiles) this.addWatchFile(file);\n\t\t\t\treturn { code: result.code, moduleType: 'js' };\n\t\t\t},\n\t\t},\n\t\ttransform: {\n\t\t\tfilter: {\n\t\t\t\tid: { include: /\\.(?:[cm]?[jt]sx?|vue|svelte|astro)(?:\\?|$)/u, exclude: /[\\\\/]node_modules[\\\\/]/u },\n\t\t\t\tcode: tyfigoImportPattern,\n\t\t\t},\n\t\t\thandler(code, id, transformOptions?: { readonly ssr?: boolean }) {\n\t\t\t\tif ((options.target ?? detect(this, transformOptions).target) !== 'browser') return;\n\t\t\t\tconst messages = findNodeOnlyImports(code, id);\n\t\t\t\tif (messages.length > 0) throw new Error(messages.join('\\n'));\n\t\t\t},\n\t\t},\n\t\tvite: {\n\t\t\tconfigResolved(config) {\n\t\t\t\tviteCommand = config.command;\n\t\t\t\tviteMode = config.mode;\n\t\t\t},\n\t\t},\n\t\trolldown: {\n\t\t\toptions(input) {\n\t\t\t\trolldownPlatform = input.platform;\n\t\t\t},\n\t\t},\n\t\tesbuild: { loader: 'js' },\n\t};\n};\n\nexport const tyfigo = createUnplugin(unpluginFactory);\n"],"mappings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