@dxos/config 0.3.8-main.c3b295a → 0.3.8-main.c66298b
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/dist/lib/node/index.cjs +13 -25
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/plugin/node/chunk-2FZXTCPZ.cjs +160 -0
- package/dist/plugin/node/chunk-2FZXTCPZ.cjs.map +7 -0
- package/dist/plugin/node/esbuild-plugin.cjs +2 -143
- package/dist/plugin/node/esbuild-plugin.cjs.map +4 -4
- package/dist/plugin/node/meta.json +1 -1
- package/dist/plugin/node/rollup-plugin.cjs +2 -143
- package/dist/plugin/node/rollup-plugin.cjs.map +4 -4
- package/dist/plugin/node/vite-plugin.cjs +5 -146
- package/dist/plugin/node/vite-plugin.cjs.map +4 -4
- package/package.json +4 -4
- package/dist/types/dist/lib/node/index.d.cts +0 -59
- package/dist/types/dist/lib/node/index.d.cts.map +0 -1
- package/dist/types/dist/plugin/node/esbuild-plugin.d.cts +0 -9
- package/dist/types/dist/plugin/node/esbuild-plugin.d.cts.map +0 -1
- package/dist/types/src/testing/build.d.ts +0 -2
- package/dist/types/src/testing/build.d.ts.map +0 -1
- package/dist/types/src/testing/entry.d.ts +0 -2
- package/dist/types/src/testing/entry.d.ts.map +0 -1
package/dist/lib/node/index.cjs
CHANGED
|
@@ -26,10 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
29
|
+
var node_exports = {};
|
|
30
|
+
__export(node_exports, {
|
|
33
31
|
Config: () => Config,
|
|
34
32
|
Defaults: () => Defaults,
|
|
35
33
|
Dynamics: () => Dynamics,
|
|
@@ -44,15 +42,23 @@ __export(src_exports, {
|
|
|
44
42
|
mapToKeyValues: () => mapToKeyValues,
|
|
45
43
|
validateConfig: () => validateConfig
|
|
46
44
|
});
|
|
47
|
-
module.exports = __toCommonJS(
|
|
45
|
+
module.exports = __toCommonJS(node_exports);
|
|
48
46
|
var defs = __toESM(require("@dxos/protocols/proto/dxos/config"));
|
|
49
|
-
|
|
50
|
-
// packages/sdk/config/src/config.ts
|
|
51
47
|
var import_boolean = require("boolean");
|
|
52
48
|
var import_lodash = __toESM(require("lodash.defaultsdeep"));
|
|
53
49
|
var import_lodash2 = __toESM(require("lodash.get"));
|
|
54
50
|
var import_lodash3 = __toESM(require("lodash.set"));
|
|
55
51
|
var import_protocols = require("@dxos/protocols");
|
|
52
|
+
var import_js_yaml = __toESM(require("js-yaml"));
|
|
53
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
54
|
+
var import_node_path = __toESM(require("node:path"));
|
|
55
|
+
var import_js_yaml2 = __toESM(require("js-yaml"));
|
|
56
|
+
var import_lodash4 = __toESM(require("lodash.set"));
|
|
57
|
+
var import_node_child_process = require("node:child_process");
|
|
58
|
+
var import_node_fs2 = require("node:fs");
|
|
59
|
+
var import_node_path2 = require("node:path");
|
|
60
|
+
var import_pkg_up = __toESM(require("pkg-up"));
|
|
61
|
+
var import_log = require("@dxos/log");
|
|
56
62
|
var configRootType = import_protocols.schema.getCodecForType("dxos.config.Config");
|
|
57
63
|
var mapFromKeyValues = (spec, values) => {
|
|
58
64
|
const config = {};
|
|
@@ -163,18 +169,9 @@ var Config = class {
|
|
|
163
169
|
return value;
|
|
164
170
|
}
|
|
165
171
|
};
|
|
166
|
-
|
|
167
|
-
// packages/sdk/config/src/loaders/index.ts
|
|
168
|
-
var import_js_yaml = __toESM(require("js-yaml"));
|
|
169
|
-
var import_node_fs = __toESM(require("node:fs"));
|
|
170
|
-
var import_node_path = __toESM(require("node:path"));
|
|
171
|
-
|
|
172
|
-
// packages/sdk/config/src/types.ts
|
|
173
172
|
var FILE_DEFAULTS = "defaults.yml";
|
|
174
173
|
var FILE_ENVS = "envs-map.yml";
|
|
175
174
|
var FILE_DYNAMICS = "config.yml";
|
|
176
|
-
|
|
177
|
-
// packages/sdk/config/src/loaders/index.ts
|
|
178
175
|
var DEFAULT_BASE_PATH = import_node_path.default.resolve(process.cwd(), "config");
|
|
179
176
|
var maybeLoadFile = (file) => {
|
|
180
177
|
try {
|
|
@@ -191,15 +188,6 @@ var Envs = (basePath = DEFAULT_BASE_PATH) => {
|
|
|
191
188
|
return content ? mapFromKeyValues(content, process.env) : {};
|
|
192
189
|
};
|
|
193
190
|
var Defaults = (basePath = DEFAULT_BASE_PATH) => maybeLoadFile(import_node_path.default.resolve(basePath, FILE_DEFAULTS)) ?? {};
|
|
194
|
-
|
|
195
|
-
// packages/sdk/config/src/plugin/definitions.ts
|
|
196
|
-
var import_js_yaml2 = __toESM(require("js-yaml"));
|
|
197
|
-
var import_lodash4 = __toESM(require("lodash.set"));
|
|
198
|
-
var import_node_child_process = require("node:child_process");
|
|
199
|
-
var import_node_fs2 = require("node:fs");
|
|
200
|
-
var import_node_path2 = require("node:path");
|
|
201
|
-
var import_pkg_up = __toESM(require("pkg-up"));
|
|
202
|
-
var import_log = require("@dxos/log");
|
|
203
191
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/config/src/plugin/definitions.ts";
|
|
204
192
|
var CWD = process.cwd();
|
|
205
193
|
var definitions = ({ configPath, envPath, devPath, mode = process.env.NODE_ENV, publicUrl = "", env }) => {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/config.ts", "../../../src/loaders/index.ts", "../../../src/types.ts", "../../../src/plugin/definitions.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\n// TODO(burdon): Why is this exported? (Rename).\nexport * as defs from '@dxos/protocols/proto/dxos/config';\n\nexport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nexport * from './config';\nexport * from './loaders';\nexport * from './plugin';\nexport * from './types';\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { boolean } from 'boolean';\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport get from 'lodash.get';\nimport set from 'lodash.set';\n\nimport { InvalidConfigError, schema } from '@dxos/protocols';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nimport { type ConfigKey, type DeepIndex, type ParseKey } from './types';\n\ntype MappingSpec = Record<string, { path: string; type?: string }>;\nconst configRootType = schema.getCodecForType('dxos.config.Config');\n\n/**\n * Maps the given objects onto a flattened set of (key x values).\n *\n * Expects parsed yaml content of the form:\n *\n * ```\n * ENV_VAR:\n * path: config.selector.path\n * ```\n *\n * @param {object} spec\n * @param {object} values\n * @return {object}\n */\nexport const mapFromKeyValues = (spec: MappingSpec, values: Record<string, any>) => {\n const config = {};\n\n for (const [key, { path, type }] of Object.entries(spec)) {\n let value = values[key];\n\n if (value !== undefined) {\n if (type) {\n switch (type) {\n case 'boolean': {\n value = boolean(value);\n break;\n }\n\n case 'number': {\n value = Number(value);\n break;\n }\n\n case 'string': {\n break;\n }\n\n case 'json': {\n value = value ? JSON.parse(value) : null;\n break;\n }\n\n default: {\n throw new Error(`Invalid type: ${type}`);\n }\n }\n }\n\n set(config, path, value);\n }\n }\n\n return config;\n};\n\n/**\n * Maps the given flattend set of (key x values) onto a JSON object.\n * @param {object} spec\n * @param {object} values\n */\nexport const mapToKeyValues = (spec: MappingSpec, values: any) => {\n const config: Record<string, any> = {};\n\n for (const [key, { path, type }] of Object.entries(spec)) {\n const value = get(values, path);\n if (value !== undefined) {\n switch (type) {\n case 'json':\n config[key] = JSON.stringify(value);\n break;\n default:\n config[key] = value;\n }\n }\n }\n\n return config;\n};\n\n/**\n * Validate config object.\n */\nexport const validateConfig = (config: ConfigProto): ConfigProto => {\n if (!('version' in config)) {\n throw new InvalidConfigError('Version not specified');\n }\n\n if (config?.version !== 1) {\n throw new InvalidConfigError(`Invalid config version: ${config.version}`);\n }\n\n const error = configRootType.protoType.verify(config);\n if (error) {\n throw new InvalidConfigError(error);\n }\n\n return config;\n};\n\n/**\n * Global configuration object.\n * NOTE: Config objects are immutable.\n */\nexport class Config {\n private readonly _config: any;\n\n /**\n * Creates an immutable instance.\n * @constructor\n * @param objects\n */\n constructor(config: ConfigProto = {}, ...objects: ConfigProto[]) {\n this._config = validateConfig(defaultsDeep(config, ...objects, { version: 1 }));\n }\n\n /**\n * Returns an immutable config JSON object.\n */\n get values(): ConfigProto {\n return this._config;\n }\n\n /**\n * Returns the given config property.\n *\n * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.\n * @param defaultValue Default value to return if option is not present in the config.\n * @returns The config value or undefined if the option is not present.\n */\n get<K extends ConfigKey>(\n key: K,\n defaultValue?: DeepIndex<ConfigProto, ParseKey<K>>,\n ): DeepIndex<ConfigProto, ParseKey<K>> {\n return get(this._config, key, defaultValue);\n }\n\n /**\n * Returns config key without type checking.\n *\n * @deprecated Use the type-checked version.\n */\n getUnchecked<T>(key: string, defaultValue?: T): T {\n return get(this._config, key, defaultValue);\n }\n\n /**\n * Returns the given config property or throw if it doesn't exist.\n *\n * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.\n */\n getOrThrow<K extends ConfigKey>(key: K): Exclude<DeepIndex<ConfigProto, ParseKey<K>>, undefined> {\n const value = get(this._config, key);\n if (!value) {\n throw new Error(`Config option not present: ${key}`);\n }\n return value;\n }\n}\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport yaml from 'js-yaml';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nimport { mapFromKeyValues } from '../config';\nimport { FILE_DEFAULTS, FILE_ENVS } from '../types';\n\n// TODO(burdon): Move code out of index file.\n\nconst DEFAULT_BASE_PATH = path.resolve(process.cwd(), 'config');\n\nconst maybeLoadFile = (file: string): any => {\n try {\n return yaml.load(fs.readFileSync(file, { encoding: 'utf8' }));\n } catch (err: any) {\n // Ignored.\n }\n};\n\n//\n// NOTE: Export LocalStorage and Dynamics for typescript to typecheck browser code (see ConfigPlugin).\n//\n\n/**\n * Development config.\n */\nexport const Local = (): Partial<ConfigProto> => ({});\n\n/**\n * Provided dynamically by server.\n */\nexport const Dynamics = (): Partial<ConfigProto> => ({});\n\n/**\n * ENV variable (key/value) map.\n */\nexport const Envs = (basePath = DEFAULT_BASE_PATH): Partial<ConfigProto> => {\n const content = maybeLoadFile(path.resolve(basePath, FILE_ENVS));\n return content ? mapFromKeyValues(content, process.env) : {};\n};\n\n/**\n * JSON config.\n */\nexport const Defaults = (basePath = DEFAULT_BASE_PATH): Partial<ConfigProto> =>\n maybeLoadFile(path.resolve(basePath, FILE_DEFAULTS)) ?? {};\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nexport const FILE_DEFAULTS = 'defaults.yml';\nexport const FILE_ENVS = 'envs-map.yml';\nexport const FILE_DYNAMICS = 'config.yml';\n\ntype DotPrefix<T extends string> = T extends '' ? '' : `.${T}`;\n\n/**\n * Returns all dot-separated nested keys for an object.\n *\n * Read more: https://stackoverflow.com/a/68404823.\n */\ntype DotNestedKeys<T> = (\n T extends object\n ? {\n [K in Exclude<keyof T, symbol>]: `${K}${DotPrefix<DotNestedKeys<T[K]>>}`;\n }[Exclude<keyof T, symbol>]\n : ''\n) extends infer D\n ? Extract<D, string>\n : never;\n\n/**\n * Parse a dot separated nested key into an array of keys.\n *\n * Example: 'services.signal.server' -> ['services', 'signal', 'server'].\n */\nexport type ParseKey<K extends string> = K extends `${infer L}.${infer Rest}` ? [L, ...ParseKey<Rest>] : [K];\n\n/**\n * Array of types that can act as an object key.\n */\ntype Keys = (keyof any)[];\n\n/**\n * Retrieves a property type in a series of nested objects.\n *\n * Read more: https://stackoverflow.com/a/61648690.\n */\nexport type DeepIndex<T, KS extends Keys, Fail = undefined> = KS extends [infer F, ...infer R]\n ? F extends keyof Exclude<T, undefined>\n ? R extends Keys\n ? DeepIndex<Exclude<T, undefined>[F], R, Fail>\n : Fail\n : Fail\n : T;\n\n/**\n * Any nested dot separated key that can be in config.\n */\n// TODO(egorgripasov): Clean once old config deprecated.\nexport type ConfigKey = DotNestedKeys<ConfigProto>;\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport yaml from 'js-yaml';\nimport set from 'lodash.set';\nimport { execSync } from 'node:child_process';\nimport { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport pkgUp from 'pkg-up';\n\nimport { log } from '@dxos/log';\n\nimport { type ConfigPluginOpts } from './types';\nimport { mapFromKeyValues } from '../config';\n\nconst CWD = process.cwd();\n\nexport const definitions = ({\n configPath,\n envPath,\n devPath,\n mode = process.env.NODE_ENV,\n publicUrl = '',\n env,\n}: ConfigPluginOpts) => {\n const KEYS_TO_FILE = {\n __CONFIG_DEFAULTS__: configPath ?? resolve(CWD, 'dx.yml'),\n __CONFIG_ENVS__: envPath ?? resolve(CWD, 'dx-env.yml'),\n } as { [key: string]: string };\n\n if (mode !== 'production') {\n KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? resolve(CWD, 'dx-local.yml');\n }\n\n return Object.entries(KEYS_TO_FILE).reduce(\n (prev, [key, value]) => {\n let content = {};\n\n try {\n content = yaml.load(readFileSync(value, 'utf-8')) as any;\n\n // Map environment variables to config values.\n if (key === '__CONFIG_ENVS__') {\n content = mapFromKeyValues(content, process.env);\n }\n\n if (key === '__CONFIG_DEFAULTS__') {\n // Load app environment variables into default config.\n env?.map((key) => set(content, ['runtime', 'app', 'env', key], process.env[key]));\n\n // Set build info automatically if available.\n try {\n const timestamp = new Date().toISOString();\n const commitHash = execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).replace('\\n', '');\n const packagePath = pkgUp.sync();\n const packageJson = packagePath && JSON.parse(readFileSync(packagePath, 'utf-8'));\n set(content, ['runtime', 'app', 'build', 'timestamp'], timestamp);\n set(content, ['runtime', 'app', 'build', 'commitHash'], commitHash);\n set(content, ['runtime', 'app', 'build', 'version'], packageJson?.version);\n } catch {}\n }\n } catch (err: any) {\n log(`Failed to load file ${value}:`, err);\n\n if (key === '__CONFIG_DEFAULTS__') {\n // Default config is required.\n throw new Error(`Failed to load default config file from ${value}`);\n }\n }\n\n return {\n ...prev,\n [key]: content,\n };\n },\n {\n __DXOS_CONFIG__: { dynamic: mode === 'production', publicUrl },\n __CONFIG_DEFAULTS__: {},\n __CONFIG_ENVS__: {},\n __CONFIG_LOCAL__: {},\n },\n );\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["import_lodash", "configRootType", "schema", "getCodecForType", "mapFromKeyValues", "spec", "values", "config", "key", "path", "type", "Object", "entries", "value", "undefined", "boolean", "Number", "JSON", "parse", "Error", "set", "mapToKeyValues", "get", "stringify", "validateConfig", "InvalidConfigError", "version", "error", "protoType", "verify", "Config", "constructor", "objects", "_config", "defaultsDeep", "defaultValue", "getUnchecked", "getOrThrow", "FILE_DEFAULTS", "FILE_ENVS", "FILE_DYNAMICS", "DEFAULT_BASE_PATH", "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,WAAsB;ACDtB,qBAAwB;AACxB,oBAAyB;AACzB,IAAAA,iBAAgB;AAChB,IAAAA,iBAAgB;AAEhB,uBAA2C;ACL3C,qBAAiB;AACjB,qBAAe;AACf,uBAAiB;AEFjB,IAAAC,kBAAiB;AACjB,IAAAD,iBAAgB;AAChB,gCAAyB;AACzB,IAAAE,kBAA6B;AAC7B,IAAAC,oBAAwB;AACxB,oBAAkB;AAElB,iBAAoB;AHIpB,IAAMC,iBAAiBC,wBAAOC,gBAAgB,oBAAA;AAgBvC,IAAMC,mBAAmB,CAACC,MAAmBC,WAAAA;AAClD,QAAMC,SAAS,CAAC;AAEhB,aAAW,CAACC,KAAK,EAAEC,MAAAA,OAAMC,KAAI,CAAE,KAAKC,OAAOC,QAAQP,IAAAA,GAAO;AACxD,QAAIQ,QAAQP,OAAOE,GAAAA;AAEnB,QAAIK,UAAUC,QAAW;AACvB,UAAIJ,MAAM;AACR,gBAAQA,MAAAA;UACN,KAAK,WAAW;AACdG,wBAAQE,wBAAQF,KAAAA;AAChB;UACF;UAEA,KAAK,UAAU;AACbA,oBAAQG,OAAOH,KAAAA;AACf;UACF;UAEA,KAAK,UAAU;AACb;UACF;UAEA,KAAK,QAAQ;AACXA,oBAAQA,QAAQI,KAAKC,MAAML,KAAAA,IAAS;AACpC;UACF;UAEA,SAAS;AACP,kBAAM,IAAIM,MAAM,iBAAiBT,IAAAA,EAAM;UACzC;QACF;MACF;AAEAU,yBAAAA,SAAIb,QAAQE,OAAMI,KAAAA;IACpB;EACF;AAEA,SAAON;AACT;AAOO,IAAMc,iBAAiB,CAAChB,MAAmBC,WAAAA;AAChD,QAAMC,SAA8B,CAAC;AAErC,aAAW,CAACC,KAAK,EAAEC,MAAAA,OAAMC,KAAI,CAAE,KAAKC,OAAOC,QAAQP,IAAAA,GAAO;AACxD,UAAMQ,YAAQS,eAAAA,SAAIhB,QAAQG,KAAAA;AAC1B,QAAII,UAAUC,QAAW;AACvB,cAAQJ,MAAAA;QACN,KAAK;AACHH,iBAAOC,GAAAA,IAAOS,KAAKM,UAAUV,KAAAA;AAC7B;QACF;AACEN,iBAAOC,GAAAA,IAAOK;MAClB;IACF;EACF;AAEA,SAAON;AACT;AAKO,IAAMiB,iBAAiB,CAACjB,WAAAA;AAC7B,MAAI,EAAE,aAAaA,SAAS;AAC1B,UAAM,IAAIkB,oCAAmB,uBAAA;EAC/B;AAEA,MAAIlB,QAAQmB,YAAY,GAAG;AACzB,UAAM,IAAID,oCAAmB,2BAA2BlB,OAAOmB,OAAO,EAAE;EAC1E;AAEA,QAAMC,QAAQ1B,eAAe2B,UAAUC,OAAOtB,MAAAA;AAC9C,MAAIoB,OAAO;AACT,UAAM,IAAIF,oCAAmBE,KAAAA;EAC/B;AAEA,SAAOpB;AACT;AAMO,IAAMuB,SAAN,MAAMA;;;;;;EAQXC,YAAYxB,SAAsB,CAAC,MAAMyB,SAAwB;AAC/D,SAAKC,UAAUT,mBAAeU,cAAAA,SAAa3B,QAAAA,GAAWyB,SAAS;MAAEN,SAAS;IAAE,CAAA,CAAA;EAC9E;;;;EAKA,IAAIpB,SAAsB;AACxB,WAAO,KAAK2B;EACd;;;;;;;;EASAX,IACEd,KACA2B,cACqC;AACrC,eAAOb,eAAAA,SAAI,KAAKW,SAASzB,KAAK2B,YAAAA;EAChC;;;;;;EAOAC,aAAgB5B,KAAa2B,cAAqB;AAChD,eAAOb,eAAAA,SAAI,KAAKW,SAASzB,KAAK2B,YAAAA;EAChC;;;;;;EAOAE,WAAgC7B,KAAiE;AAC/F,UAAMK,YAAQS,eAAAA,SAAI,KAAKW,SAASzB,GAAAA;AAChC,QAAI,CAACK,OAAO;AACV,YAAM,IAAIM,MAAM,8BAA8BX,GAAAA,EAAK;IACrD;AACA,WAAOK;EACT;AACF;AExKO,IAAMyB,gBAAgB;AACtB,IAAMC,YAAY;AAClB,IAAMC,gBAAgB;ADO7B,IAAMC,oBAAoBhC,iBAAAA,QAAKiC,QAAQC,QAAQC,IAAG,GAAI,QAAA;AAEtD,IAAMC,gBAAgB,CAACC,SAAAA;AACrB,MAAI;AACF,WAAOC,eAAAA,QAAKC,KAAKC,eAAAA,QAAGC,aAAaJ,MAAM;MAAEK,UAAU;IAAO,CAAA,CAAA;EAC5D,SAASC,KAAU;EAEnB;AACF;AASO,IAAMC,QAAQ,OAA6B,CAAC;AAK5C,IAAMC,WAAW,OAA6B,CAAC;AAK/C,IAAMC,OAAO,CAACC,WAAWf,sBAAiB;AAC/C,QAAMgB,UAAUZ,cAAcpC,iBAAAA,QAAKiC,QAAQc,UAAUjB,SAAAA,CAAAA;AACrD,SAAOkB,UAAUrD,iBAAiBqD,SAASd,QAAQe,GAAG,IAAI,CAAC;AAC7D;AAKO,IAAMC,WAAW,CAACH,WAAWf,sBAClCI,cAAcpC,iBAAAA,QAAKiC,QAAQc,UAAUlB,aAAAA,CAAAA,KAAmB,CAAC;;AEnC3D,IAAMsB,MAAMjB,QAAQC,IAAG;AAEhB,IAAMiB,cAAc,CAAC,EAC1BC,YACAC,SACAC,SACAC,OAAOtB,QAAQe,IAAIQ,UACnBC,YAAY,IACZT,IAAG,MACc;AACjB,QAAMU,eAAe;IACnBC,qBAAqBP,kBAAcpB,2BAAQkB,KAAK,QAAA;IAChDU,iBAAiBP,eAAWrB,2BAAQkB,KAAK,YAAA;EAC3C;AAEA,MAAIK,SAAS,cAAc;AACzBG,iBAAaG,mBAAmBP,eAAWtB,2BAAQkB,KAAK,cAAA;EAC1D;AAEA,SAAOjD,OAAOC,QAAQwD,YAAAA,EAAcI,OAClC,CAACC,MAAM,CAACjE,KAAKK,KAAAA,MAAM;AACjB,QAAI4C,UAAU,CAAC;AAEf,QAAI;AACFA,gBAAUV,gBAAAA,QAAKC,SAAKE,8BAAarC,OAAO,OAAA,CAAA;AAGxC,UAAIL,QAAQ,mBAAmB;AAC7BiD,kBAAUrD,iBAAiBqD,SAASd,QAAQe,GAAG;MACjD;AAEA,UAAIlD,QAAQ,uBAAuB;AAEjCkD,aAAKgB,IAAI,CAAClE,aAAQY,eAAAA,SAAIqC,SAAS;UAAC;UAAW;UAAO;UAAOjD;WAAMmC,QAAQe,IAAIlD,IAAAA,CAAI,CAAA;AAG/E,YAAI;AACF,gBAAMmE,aAAY,oBAAIC,KAAAA,GAAOC,YAAW;AACxC,gBAAMC,iBAAaC,oCAAS,8BAA8B;YAAE5B,UAAU;UAAQ,CAAA,EAAG6B,QAAQ,MAAM,EAAA;AAC/F,gBAAMC,cAAcC,cAAAA,QAAMC,KAAI;AAC9B,gBAAMC,cAAcH,eAAehE,KAAKC,UAAMgC,8BAAa+B,aAAa,OAAA,CAAA;AACxE7D,6BAAAA,SAAIqC,SAAS;YAAC;YAAW;YAAO;YAAS;aAAckB,SAAAA;AACvDvD,6BAAAA,SAAIqC,SAAS;YAAC;YAAW;YAAO;YAAS;aAAeqB,UAAAA;AACxD1D,6BAAAA,SAAIqC,SAAS;YAAC;YAAW;YAAO;YAAS;aAAY2B,aAAa1D,OAAAA;QACpE,QAAQ;QAAC;MACX;IACF,SAAS0B,KAAU;AACjBiC,0BAAI,uBAAuBxE,KAAAA,KAAUuC,KAAAA;;;;;;AAErC,UAAI5C,QAAQ,uBAAuB;AAEjC,cAAM,IAAIW,MAAM,2CAA2CN,KAAAA,EAAO;MACpE;IACF;AAEA,WAAO;MACL,GAAG4D;MACH,CAACjE,GAAAA,GAAMiD;IACT;EACF,GACA;IACE6B,iBAAiB;MAAEC,SAAStB,SAAS;MAAcE;IAAU;IAC7DE,qBAAqB,CAAC;IACtBC,iBAAiB,CAAC;IAClBC,kBAAkB,CAAC;EACrB,CAAA;AAEJ;",
|
|
6
|
+
"names": ["import_lodash", "import_js_yaml", "import_node_fs", "import_node_path", "configRootType", "schema", "getCodecForType", "mapFromKeyValues", "spec", "values", "config", "key", "path", "type", "Object", "entries", "value", "undefined", "boolean", "Number", "JSON", "parse", "Error", "set", "mapToKeyValues", "get", "stringify", "validateConfig", "InvalidConfigError", "version", "error", "protoType", "verify", "Config", "constructor", "objects", "_config", "defaultsDeep", "defaultValue", "getUnchecked", "getOrThrow", "FILE_DEFAULTS", "FILE_ENVS", "FILE_DYNAMICS", "DEFAULT_BASE_PATH", "resolve", "process", "cwd", "maybeLoadFile", "file", "yaml", "load", "fs", "readFileSync", "encoding", "err", "Local", "Dynamics", "Envs", "basePath", "content", "env", "Defaults", "CWD", "definitions", "configPath", "envPath", "devPath", "mode", "NODE_ENV", "publicUrl", "KEYS_TO_FILE", "__CONFIG_DEFAULTS__", "__CONFIG_ENVS__", "__CONFIG_LOCAL__", "reduce", "prev", "map", "timestamp", "Date", "toISOString", "commitHash", "execSync", "replace", "packagePath", "pkgUp", "sync", "packageJson", "log", "__DXOS_CONFIG__", "dynamic"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/sdk/config/src/config.ts":{"bytes":13900,"imports":[{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.get","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/config/src/types.ts":{"bytes":2748,"imports":[],"format":"esm"},"packages/sdk/config/src/loaders/index.ts":{"bytes":4561,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/sdk/config/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/sdk/config/src/plugin/definitions.ts":{"bytes":10041,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/config.ts","kind":"import-statement","original":"../config"}],"format":"esm"},"packages/sdk/config/src/plugin/types.ts":{"bytes":1498,"imports":[],"format":"esm"},"packages/sdk/config/src/plugin/index.ts":{"bytes":558,"imports":[{"path":"packages/sdk/config/src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"},{"path":"packages/sdk/config/src/plugin/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"},"packages/sdk/config/src/index.ts":{"bytes":1143,"imports":[{"path":"@dxos/protocols/proto/dxos/config","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/sdk/config/src/loaders/index.ts","kind":"import-statement","original":"./loaders"},{"path":"packages/sdk/config/src/plugin/index.ts","kind":"import-statement","original":"./plugin"},{"path":"packages/sdk/config/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"}},"outputs":{"packages/sdk/config/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":
|
|
1
|
+
{"inputs":{"packages/sdk/config/src/config.ts":{"bytes":13900,"imports":[{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.get","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/config/src/types.ts":{"bytes":2748,"imports":[],"format":"esm"},"packages/sdk/config/src/loaders/index.ts":{"bytes":4561,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/config.ts","kind":"import-statement","original":"../config"},{"path":"packages/sdk/config/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/sdk/config/src/plugin/definitions.ts":{"bytes":10041,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/config.ts","kind":"import-statement","original":"../config"}],"format":"esm"},"packages/sdk/config/src/plugin/types.ts":{"bytes":1498,"imports":[],"format":"esm"},"packages/sdk/config/src/plugin/index.ts":{"bytes":558,"imports":[{"path":"packages/sdk/config/src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"},{"path":"packages/sdk/config/src/plugin/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"},"packages/sdk/config/src/index.ts":{"bytes":1143,"imports":[{"path":"@dxos/protocols/proto/dxos/config","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/config.ts","kind":"import-statement","original":"./config"},{"path":"packages/sdk/config/src/loaders/index.ts","kind":"import-statement","original":"./loaders"},{"path":"packages/sdk/config/src/plugin/index.ts","kind":"import-statement","original":"./plugin"},{"path":"packages/sdk/config/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"}},"outputs":{"packages/sdk/config/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":16094},"packages/sdk/config/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/protocols/proto/dxos/config","kind":"import-statement","external":true},{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.get","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"js-yaml","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"js-yaml","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["Config","Defaults","Dynamics","Envs","FILE_DEFAULTS","FILE_DYNAMICS","FILE_ENVS","Local","definitions","defs","mapFromKeyValues","mapToKeyValues","validateConfig"],"entryPoint":"packages/sdk/config/src/index.ts","inputs":{"packages/sdk/config/src/index.ts":{"bytesInOutput":59},"packages/sdk/config/src/config.ts":{"bytesInOutput":3135},"packages/sdk/config/src/loaders/index.ts":{"bytesInOutput":631},"packages/sdk/config/src/types.ts":{"bytesInOutput":102},"packages/sdk/config/src/plugin/definitions.ts":{"bytesInOutput":2545},"packages/sdk/config/src/plugin/index.ts":{"bytesInOutput":0}},"bytes":6946}}}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var chunk_2FZXTCPZ_exports = {};
|
|
30
|
+
__export(chunk_2FZXTCPZ_exports, {
|
|
31
|
+
definitions: () => definitions
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(chunk_2FZXTCPZ_exports);
|
|
34
|
+
var import_js_yaml = __toESM(require("js-yaml"));
|
|
35
|
+
var import_lodash = __toESM(require("lodash.set"));
|
|
36
|
+
var import_node_child_process = require("node:child_process");
|
|
37
|
+
var import_node_fs = require("node:fs");
|
|
38
|
+
var import_node_path = require("node:path");
|
|
39
|
+
var import_pkg_up = __toESM(require("pkg-up"));
|
|
40
|
+
var import_log = require("@dxos/log");
|
|
41
|
+
var import_boolean = require("boolean");
|
|
42
|
+
var import_lodash2 = __toESM(require("lodash.defaultsdeep"));
|
|
43
|
+
var import_lodash3 = __toESM(require("lodash.get"));
|
|
44
|
+
var import_lodash4 = __toESM(require("lodash.set"));
|
|
45
|
+
var import_protocols = require("@dxos/protocols");
|
|
46
|
+
var configRootType = import_protocols.schema.getCodecForType("dxos.config.Config");
|
|
47
|
+
var mapFromKeyValues = (spec, values) => {
|
|
48
|
+
const config = {};
|
|
49
|
+
for (const [key, { path, type }] of Object.entries(spec)) {
|
|
50
|
+
let value = values[key];
|
|
51
|
+
if (value !== void 0) {
|
|
52
|
+
if (type) {
|
|
53
|
+
switch (type) {
|
|
54
|
+
case "boolean": {
|
|
55
|
+
value = (0, import_boolean.boolean)(value);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case "number": {
|
|
59
|
+
value = Number(value);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case "string": {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case "json": {
|
|
66
|
+
value = value ? JSON.parse(value) : null;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
default: {
|
|
70
|
+
throw new Error(`Invalid type: ${type}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
(0, import_lodash4.default)(config, path, value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return config;
|
|
78
|
+
};
|
|
79
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/config/src/plugin/definitions.ts";
|
|
80
|
+
var CWD = process.cwd();
|
|
81
|
+
var definitions = ({ configPath, envPath, devPath, mode = process.env.NODE_ENV, publicUrl = "", env }) => {
|
|
82
|
+
const KEYS_TO_FILE = {
|
|
83
|
+
__CONFIG_DEFAULTS__: configPath ?? (0, import_node_path.resolve)(CWD, "dx.yml"),
|
|
84
|
+
__CONFIG_ENVS__: envPath ?? (0, import_node_path.resolve)(CWD, "dx-env.yml")
|
|
85
|
+
};
|
|
86
|
+
if (mode !== "production") {
|
|
87
|
+
KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? (0, import_node_path.resolve)(CWD, "dx-local.yml");
|
|
88
|
+
}
|
|
89
|
+
return Object.entries(KEYS_TO_FILE).reduce((prev, [key, value]) => {
|
|
90
|
+
let content = {};
|
|
91
|
+
try {
|
|
92
|
+
content = import_js_yaml.default.load((0, import_node_fs.readFileSync)(value, "utf-8"));
|
|
93
|
+
if (key === "__CONFIG_ENVS__") {
|
|
94
|
+
content = mapFromKeyValues(content, process.env);
|
|
95
|
+
}
|
|
96
|
+
if (key === "__CONFIG_DEFAULTS__") {
|
|
97
|
+
env?.map((key2) => (0, import_lodash.default)(content, [
|
|
98
|
+
"runtime",
|
|
99
|
+
"app",
|
|
100
|
+
"env",
|
|
101
|
+
key2
|
|
102
|
+
], process.env[key2]));
|
|
103
|
+
try {
|
|
104
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
105
|
+
const commitHash = (0, import_node_child_process.execSync)("git rev-parse --short HEAD", {
|
|
106
|
+
encoding: "utf-8"
|
|
107
|
+
}).replace("\n", "");
|
|
108
|
+
const packagePath = import_pkg_up.default.sync();
|
|
109
|
+
const packageJson = packagePath && JSON.parse((0, import_node_fs.readFileSync)(packagePath, "utf-8"));
|
|
110
|
+
(0, import_lodash.default)(content, [
|
|
111
|
+
"runtime",
|
|
112
|
+
"app",
|
|
113
|
+
"build",
|
|
114
|
+
"timestamp"
|
|
115
|
+
], timestamp);
|
|
116
|
+
(0, import_lodash.default)(content, [
|
|
117
|
+
"runtime",
|
|
118
|
+
"app",
|
|
119
|
+
"build",
|
|
120
|
+
"commitHash"
|
|
121
|
+
], commitHash);
|
|
122
|
+
(0, import_lodash.default)(content, [
|
|
123
|
+
"runtime",
|
|
124
|
+
"app",
|
|
125
|
+
"build",
|
|
126
|
+
"version"
|
|
127
|
+
], packageJson?.version);
|
|
128
|
+
} catch {
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
} catch (err) {
|
|
132
|
+
(0, import_log.log)(`Failed to load file ${value}:`, err, {
|
|
133
|
+
F: __dxlog_file,
|
|
134
|
+
L: 64,
|
|
135
|
+
S: void 0,
|
|
136
|
+
C: (f, a) => f(...a)
|
|
137
|
+
});
|
|
138
|
+
if (key === "__CONFIG_DEFAULTS__") {
|
|
139
|
+
throw new Error(`Failed to load default config file from ${value}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
...prev,
|
|
144
|
+
[key]: content
|
|
145
|
+
};
|
|
146
|
+
}, {
|
|
147
|
+
__DXOS_CONFIG__: {
|
|
148
|
+
dynamic: mode === "production",
|
|
149
|
+
publicUrl
|
|
150
|
+
},
|
|
151
|
+
__CONFIG_DEFAULTS__: {},
|
|
152
|
+
__CONFIG_ENVS__: {},
|
|
153
|
+
__CONFIG_LOCAL__: {}
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
157
|
+
0 && (module.exports = {
|
|
158
|
+
definitions
|
|
159
|
+
});
|
|
160
|
+
//# sourceMappingURL=chunk-2FZXTCPZ.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugin/definitions.ts", "../../../src/config.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport yaml from 'js-yaml';\nimport set from 'lodash.set';\nimport { execSync } from 'node:child_process';\nimport { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport pkgUp from 'pkg-up';\n\nimport { log } from '@dxos/log';\n\nimport { type ConfigPluginOpts } from './types';\nimport { mapFromKeyValues } from '../config';\n\nconst CWD = process.cwd();\n\nexport const definitions = ({\n configPath,\n envPath,\n devPath,\n mode = process.env.NODE_ENV,\n publicUrl = '',\n env,\n}: ConfigPluginOpts) => {\n const KEYS_TO_FILE = {\n __CONFIG_DEFAULTS__: configPath ?? resolve(CWD, 'dx.yml'),\n __CONFIG_ENVS__: envPath ?? resolve(CWD, 'dx-env.yml'),\n } as { [key: string]: string };\n\n if (mode !== 'production') {\n KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? resolve(CWD, 'dx-local.yml');\n }\n\n return Object.entries(KEYS_TO_FILE).reduce(\n (prev, [key, value]) => {\n let content = {};\n\n try {\n content = yaml.load(readFileSync(value, 'utf-8')) as any;\n\n // Map environment variables to config values.\n if (key === '__CONFIG_ENVS__') {\n content = mapFromKeyValues(content, process.env);\n }\n\n if (key === '__CONFIG_DEFAULTS__') {\n // Load app environment variables into default config.\n env?.map((key) => set(content, ['runtime', 'app', 'env', key], process.env[key]));\n\n // Set build info automatically if available.\n try {\n const timestamp = new Date().toISOString();\n const commitHash = execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).replace('\\n', '');\n const packagePath = pkgUp.sync();\n const packageJson = packagePath && JSON.parse(readFileSync(packagePath, 'utf-8'));\n set(content, ['runtime', 'app', 'build', 'timestamp'], timestamp);\n set(content, ['runtime', 'app', 'build', 'commitHash'], commitHash);\n set(content, ['runtime', 'app', 'build', 'version'], packageJson?.version);\n } catch {}\n }\n } catch (err: any) {\n log(`Failed to load file ${value}:`, err);\n\n if (key === '__CONFIG_DEFAULTS__') {\n // Default config is required.\n throw new Error(`Failed to load default config file from ${value}`);\n }\n }\n\n return {\n ...prev,\n [key]: content,\n };\n },\n {\n __DXOS_CONFIG__: { dynamic: mode === 'production', publicUrl },\n __CONFIG_DEFAULTS__: {},\n __CONFIG_ENVS__: {},\n __CONFIG_LOCAL__: {},\n },\n );\n};\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { boolean } from 'boolean';\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport get from 'lodash.get';\nimport set from 'lodash.set';\n\nimport { InvalidConfigError, schema } from '@dxos/protocols';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nimport { type ConfigKey, type DeepIndex, type ParseKey } from './types';\n\ntype MappingSpec = Record<string, { path: string; type?: string }>;\nconst configRootType = schema.getCodecForType('dxos.config.Config');\n\n/**\n * Maps the given objects onto a flattened set of (key x values).\n *\n * Expects parsed yaml content of the form:\n *\n * ```\n * ENV_VAR:\n * path: config.selector.path\n * ```\n *\n * @param {object} spec\n * @param {object} values\n * @return {object}\n */\nexport const mapFromKeyValues = (spec: MappingSpec, values: Record<string, any>) => {\n const config = {};\n\n for (const [key, { path, type }] of Object.entries(spec)) {\n let value = values[key];\n\n if (value !== undefined) {\n if (type) {\n switch (type) {\n case 'boolean': {\n value = boolean(value);\n break;\n }\n\n case 'number': {\n value = Number(value);\n break;\n }\n\n case 'string': {\n break;\n }\n\n case 'json': {\n value = value ? JSON.parse(value) : null;\n break;\n }\n\n default: {\n throw new Error(`Invalid type: ${type}`);\n }\n }\n }\n\n set(config, path, value);\n }\n }\n\n return config;\n};\n\n/**\n * Maps the given flattend set of (key x values) onto a JSON object.\n * @param {object} spec\n * @param {object} values\n */\nexport const mapToKeyValues = (spec: MappingSpec, values: any) => {\n const config: Record<string, any> = {};\n\n for (const [key, { path, type }] of Object.entries(spec)) {\n const value = get(values, path);\n if (value !== undefined) {\n switch (type) {\n case 'json':\n config[key] = JSON.stringify(value);\n break;\n default:\n config[key] = value;\n }\n }\n }\n\n return config;\n};\n\n/**\n * Validate config object.\n */\nexport const validateConfig = (config: ConfigProto): ConfigProto => {\n if (!('version' in config)) {\n throw new InvalidConfigError('Version not specified');\n }\n\n if (config?.version !== 1) {\n throw new InvalidConfigError(`Invalid config version: ${config.version}`);\n }\n\n const error = configRootType.protoType.verify(config);\n if (error) {\n throw new InvalidConfigError(error);\n }\n\n return config;\n};\n\n/**\n * Global configuration object.\n * NOTE: Config objects are immutable.\n */\nexport class Config {\n private readonly _config: any;\n\n /**\n * Creates an immutable instance.\n * @constructor\n * @param objects\n */\n constructor(config: ConfigProto = {}, ...objects: ConfigProto[]) {\n this._config = validateConfig(defaultsDeep(config, ...objects, { version: 1 }));\n }\n\n /**\n * Returns an immutable config JSON object.\n */\n get values(): ConfigProto {\n return this._config;\n }\n\n /**\n * Returns the given config property.\n *\n * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.\n * @param defaultValue Default value to return if option is not present in the config.\n * @returns The config value or undefined if the option is not present.\n */\n get<K extends ConfigKey>(\n key: K,\n defaultValue?: DeepIndex<ConfigProto, ParseKey<K>>,\n ): DeepIndex<ConfigProto, ParseKey<K>> {\n return get(this._config, key, defaultValue);\n }\n\n /**\n * Returns config key without type checking.\n *\n * @deprecated Use the type-checked version.\n */\n getUnchecked<T>(key: string, defaultValue?: T): T {\n return get(this._config, key, defaultValue);\n }\n\n /**\n * Returns the given config property or throw if it doesn't exist.\n *\n * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.\n */\n getOrThrow<K extends ConfigKey>(key: K): Exclude<DeepIndex<ConfigProto, ParseKey<K>>, undefined> {\n const value = get(this._config, key);\n if (!value) {\n throw new Error(`Config option not present: ${key}`);\n }\n return value;\n }\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["import_lodash", "configRootType", "schema", "getCodecForType", "mapFromKeyValues", "spec", "values", "config", "key", "path", "type", "Object", "entries", "value", "undefined", "boolean", "Number", "JSON", "parse", "Error", "set", "CWD", "process", "cwd", "definitions", "configPath", "envPath", "devPath", "mode", "env", "NODE_ENV", "publicUrl", "KEYS_TO_FILE", "__CONFIG_DEFAULTS__", "resolve", "__CONFIG_ENVS__", "__CONFIG_LOCAL__", "reduce", "prev", "content", "yaml", "load", "readFileSync", "map", "timestamp", "Date", "toISOString", "commitHash", "execSync", "encoding", "replace", "packagePath", "pkgUp", "sync", "packageJson", "version", "err", "log", "__DXOS_CONFIG__", "dynamic"]
|
|
7
|
+
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,159 +15,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// packages/sdk/config/src/plugin/esbuild-plugin.ts
|
|
31
19
|
var esbuild_plugin_exports = {};
|
|
32
20
|
__export(esbuild_plugin_exports, {
|
|
33
21
|
ConfigPlugin: () => ConfigPlugin
|
|
34
22
|
});
|
|
35
23
|
module.exports = __toCommonJS(esbuild_plugin_exports);
|
|
36
|
-
|
|
37
|
-
// packages/sdk/config/src/plugin/definitions.ts
|
|
38
|
-
var import_js_yaml = __toESM(require("js-yaml"));
|
|
39
|
-
var import_lodash4 = __toESM(require("lodash.set"));
|
|
40
|
-
var import_node_child_process = require("node:child_process");
|
|
41
|
-
var import_node_fs = require("node:fs");
|
|
42
|
-
var import_node_path = require("node:path");
|
|
43
|
-
var import_pkg_up = __toESM(require("pkg-up"));
|
|
44
|
-
var import_log = require("@dxos/log");
|
|
45
|
-
|
|
46
|
-
// packages/sdk/config/src/config.ts
|
|
47
|
-
var import_boolean = require("boolean");
|
|
48
|
-
var import_lodash = __toESM(require("lodash.defaultsdeep"));
|
|
49
|
-
var import_lodash2 = __toESM(require("lodash.get"));
|
|
50
|
-
var import_lodash3 = __toESM(require("lodash.set"));
|
|
51
|
-
var import_protocols = require("@dxos/protocols");
|
|
52
|
-
var configRootType = import_protocols.schema.getCodecForType("dxos.config.Config");
|
|
53
|
-
var mapFromKeyValues = (spec, values) => {
|
|
54
|
-
const config = {};
|
|
55
|
-
for (const [key, { path, type }] of Object.entries(spec)) {
|
|
56
|
-
let value = values[key];
|
|
57
|
-
if (value !== void 0) {
|
|
58
|
-
if (type) {
|
|
59
|
-
switch (type) {
|
|
60
|
-
case "boolean": {
|
|
61
|
-
value = (0, import_boolean.boolean)(value);
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
case "number": {
|
|
65
|
-
value = Number(value);
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
case "string": {
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
case "json": {
|
|
72
|
-
value = value ? JSON.parse(value) : null;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
default: {
|
|
76
|
-
throw new Error(`Invalid type: ${type}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
(0, import_lodash3.default)(config, path, value);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return config;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// packages/sdk/config/src/plugin/definitions.ts
|
|
87
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/config/src/plugin/definitions.ts";
|
|
88
|
-
var CWD = process.cwd();
|
|
89
|
-
var definitions = ({ configPath, envPath, devPath, mode = process.env.NODE_ENV, publicUrl = "", env }) => {
|
|
90
|
-
const KEYS_TO_FILE = {
|
|
91
|
-
__CONFIG_DEFAULTS__: configPath ?? (0, import_node_path.resolve)(CWD, "dx.yml"),
|
|
92
|
-
__CONFIG_ENVS__: envPath ?? (0, import_node_path.resolve)(CWD, "dx-env.yml")
|
|
93
|
-
};
|
|
94
|
-
if (mode !== "production") {
|
|
95
|
-
KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? (0, import_node_path.resolve)(CWD, "dx-local.yml");
|
|
96
|
-
}
|
|
97
|
-
return Object.entries(KEYS_TO_FILE).reduce((prev, [key, value]) => {
|
|
98
|
-
let content = {};
|
|
99
|
-
try {
|
|
100
|
-
content = import_js_yaml.default.load((0, import_node_fs.readFileSync)(value, "utf-8"));
|
|
101
|
-
if (key === "__CONFIG_ENVS__") {
|
|
102
|
-
content = mapFromKeyValues(content, process.env);
|
|
103
|
-
}
|
|
104
|
-
if (key === "__CONFIG_DEFAULTS__") {
|
|
105
|
-
env?.map((key2) => (0, import_lodash4.default)(content, [
|
|
106
|
-
"runtime",
|
|
107
|
-
"app",
|
|
108
|
-
"env",
|
|
109
|
-
key2
|
|
110
|
-
], process.env[key2]));
|
|
111
|
-
try {
|
|
112
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
113
|
-
const commitHash = (0, import_node_child_process.execSync)("git rev-parse --short HEAD", {
|
|
114
|
-
encoding: "utf-8"
|
|
115
|
-
}).replace("\n", "");
|
|
116
|
-
const packagePath = import_pkg_up.default.sync();
|
|
117
|
-
const packageJson = packagePath && JSON.parse((0, import_node_fs.readFileSync)(packagePath, "utf-8"));
|
|
118
|
-
(0, import_lodash4.default)(content, [
|
|
119
|
-
"runtime",
|
|
120
|
-
"app",
|
|
121
|
-
"build",
|
|
122
|
-
"timestamp"
|
|
123
|
-
], timestamp);
|
|
124
|
-
(0, import_lodash4.default)(content, [
|
|
125
|
-
"runtime",
|
|
126
|
-
"app",
|
|
127
|
-
"build",
|
|
128
|
-
"commitHash"
|
|
129
|
-
], commitHash);
|
|
130
|
-
(0, import_lodash4.default)(content, [
|
|
131
|
-
"runtime",
|
|
132
|
-
"app",
|
|
133
|
-
"build",
|
|
134
|
-
"version"
|
|
135
|
-
], packageJson?.version);
|
|
136
|
-
} catch {
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
} catch (err) {
|
|
140
|
-
(0, import_log.log)(`Failed to load file ${value}:`, err, {
|
|
141
|
-
F: __dxlog_file,
|
|
142
|
-
L: 64,
|
|
143
|
-
S: void 0,
|
|
144
|
-
C: (f, a) => f(...a)
|
|
145
|
-
});
|
|
146
|
-
if (key === "__CONFIG_DEFAULTS__") {
|
|
147
|
-
throw new Error(`Failed to load default config file from ${value}`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return {
|
|
151
|
-
...prev,
|
|
152
|
-
[key]: content
|
|
153
|
-
};
|
|
154
|
-
}, {
|
|
155
|
-
__DXOS_CONFIG__: {
|
|
156
|
-
dynamic: mode === "production",
|
|
157
|
-
publicUrl
|
|
158
|
-
},
|
|
159
|
-
__CONFIG_DEFAULTS__: {},
|
|
160
|
-
__CONFIG_ENVS__: {},
|
|
161
|
-
__CONFIG_LOCAL__: {}
|
|
162
|
-
});
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
// packages/sdk/config/src/plugin/esbuild-plugin.ts
|
|
24
|
+
var import_chunk_2FZXTCPZ = require("./chunk-2FZXTCPZ.cjs");
|
|
166
25
|
var ConfigPlugin = (options = {}) => {
|
|
167
26
|
return {
|
|
168
27
|
name: "dxos-config",
|
|
169
28
|
setup: ({ initialOptions }) => {
|
|
170
29
|
const esbuildOptions = initialOptions;
|
|
171
30
|
esbuildOptions.define ||= {};
|
|
172
|
-
Object.entries(definitions({
|
|
31
|
+
Object.entries((0, import_chunk_2FZXTCPZ.definitions)({
|
|
173
32
|
...options,
|
|
174
33
|
mode: process.env.NODE_ENV
|
|
175
34
|
})).reduce((define, [key, value]) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/plugin/esbuild-plugin.ts"
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\nimport type { Plugin } from 'esbuild';\n\nimport { definitions } from './definitions';\nimport { type ConfigPluginOpts } from './types';\n\nexport const ConfigPlugin = (options: ConfigPluginOpts = {}): Plugin => {\n return {\n name: 'dxos-config',\n setup: ({ initialOptions }) => {\n const esbuildOptions = initialOptions;\n esbuildOptions.define ||= {};\n\n Object.entries(definitions({ ...options, mode: process.env.NODE_ENV })).reduce((define, [key, value]) => {\n define[key] = JSON.stringify(value);\n return define;\n }, esbuildOptions.define);\n },\n };\n};\n"
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../src/plugin/esbuild-plugin.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\nimport type { Plugin } from 'esbuild';\n\nimport { definitions } from './definitions';\nimport { type ConfigPluginOpts } from './types';\n\nexport const ConfigPlugin = (options: ConfigPluginOpts = {}): Plugin => {\n return {\n name: 'dxos-config',\n setup: ({ initialOptions }) => {\n const esbuildOptions = initialOptions;\n esbuildOptions.define ||= {};\n\n Object.entries(definitions({ ...options, mode: process.env.NODE_ENV })).reduce((define, [key, value]) => {\n define[key] = JSON.stringify(value);\n return define;\n }, esbuildOptions.define);\n },\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AASO,IAAMA,eAAe,CAACC,UAA4B,CAAC,MAAC;AACzD,SAAO;IACLC,MAAM;IACNC,OAAO,CAAC,EAAEC,eAAc,MAAE;AACxB,YAAMC,iBAAiBD;AACvBC,qBAAeC,WAAW,CAAC;AAE3BC,aAAOC,YAAQC,mCAAY;QAAE,GAAGR;QAASS,MAAMC,QAAQC,IAAIC;MAAS,CAAA,CAAA,EAAIC,OAAO,CAACR,QAAQ,CAACS,KAAKC,KAAAA,MAAM;AAClGV,eAAOS,GAAAA,IAAOE,KAAKC,UAAUF,KAAAA;AAC7B,eAAOV;MACT,GAAGD,eAAeC,MAAM;IAC1B;EACF;AACF;",
|
|
6
|
+
"names": ["ConfigPlugin", "options", "name", "setup", "initialOptions", "esbuildOptions", "define", "Object", "entries", "definitions", "mode", "process", "env", "NODE_ENV", "reduce", "key", "value", "JSON", "stringify"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/sdk/config/src/config.ts":{"bytes":13900,"imports":[{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.get","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/config/src/plugin/definitions.ts":{"bytes":10041,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/config.ts","kind":"import-statement","original":"../config"}],"format":"esm"},"packages/sdk/config/src/plugin/esbuild-plugin.ts":{"bytes":2584,"imports":[{"path":"packages/sdk/config/src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"}],"format":"esm"},"packages/sdk/config/src/plugin/rollup-plugin.ts":{"bytes":2068,"imports":[{"path":"packages/sdk/config/src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"}],"format":"esm"},"packages/sdk/config/src/plugin/vite-plugin.ts":{"bytes":3319,"imports":[{"path":"node:path","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"}],"format":"esm"}},"outputs":{"packages/sdk/config/dist/plugin/node/esbuild-plugin.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":
|
|
1
|
+
{"inputs":{"packages/sdk/config/src/config.ts":{"bytes":13900,"imports":[{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.get","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/config/src/plugin/definitions.ts":{"bytes":10041,"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/config.ts","kind":"import-statement","original":"../config"}],"format":"esm"},"packages/sdk/config/src/plugin/esbuild-plugin.ts":{"bytes":2584,"imports":[{"path":"packages/sdk/config/src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"}],"format":"esm"},"packages/sdk/config/src/plugin/rollup-plugin.ts":{"bytes":2068,"imports":[{"path":"packages/sdk/config/src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"}],"format":"esm"},"packages/sdk/config/src/plugin/vite-plugin.ts":{"bytes":3319,"imports":[{"path":"node:path","kind":"import-statement","external":true},{"path":"packages/sdk/config/src/plugin/definitions.ts","kind":"import-statement","original":"./definitions"}],"format":"esm"}},"outputs":{"packages/sdk/config/dist/plugin/node/esbuild-plugin.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":1346},"packages/sdk/config/dist/plugin/node/esbuild-plugin.cjs":{"imports":[{"path":"packages/sdk/config/dist/plugin/node/chunk-2FZXTCPZ.cjs","kind":"import-statement"}],"exports":["ConfigPlugin"],"entryPoint":"packages/sdk/config/src/plugin/esbuild-plugin.ts","inputs":{"packages/sdk/config/src/plugin/esbuild-plugin.ts":{"bytesInOutput":443}},"bytes":621},"packages/sdk/config/dist/plugin/node/rollup-plugin.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":1102},"packages/sdk/config/dist/plugin/node/rollup-plugin.cjs":{"imports":[{"path":"packages/sdk/config/dist/plugin/node/chunk-2FZXTCPZ.cjs","kind":"import-statement"}],"exports":["ConfigPlugin"],"entryPoint":"packages/sdk/config/src/plugin/rollup-plugin.ts","inputs":{"packages/sdk/config/src/plugin/rollup-plugin.ts":{"bytesInOutput":288}},"bytes":464},"packages/sdk/config/dist/plugin/node/vite-plugin.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":1707},"packages/sdk/config/dist/plugin/node/vite-plugin.cjs":{"imports":[{"path":"packages/sdk/config/dist/plugin/node/chunk-2FZXTCPZ.cjs","kind":"import-statement"},{"path":"node:path","kind":"import-statement","external":true}],"exports":["ConfigPlugin"],"entryPoint":"packages/sdk/config/src/plugin/vite-plugin.ts","inputs":{"packages/sdk/config/src/plugin/vite-plugin.ts":{"bytesInOutput":634}},"bytes":806},"packages/sdk/config/dist/plugin/node/chunk-2FZXTCPZ.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":10383},"packages/sdk/config/dist/plugin/node/chunk-2FZXTCPZ.cjs":{"imports":[{"path":"js-yaml","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"boolean","kind":"import-statement","external":true},{"path":"lodash.defaultsdeep","kind":"import-statement","external":true},{"path":"lodash.get","kind":"import-statement","external":true},{"path":"lodash.set","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true}],"exports":["definitions"],"inputs":{"packages/sdk/config/src/plugin/definitions.ts":{"bytesInOutput":2543},"packages/sdk/config/src/config.ts":{"bytesInOutput":1020}},"bytes":3771}}}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,154 +15,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// packages/sdk/config/src/plugin/rollup-plugin.ts
|
|
31
19
|
var rollup_plugin_exports = {};
|
|
32
20
|
__export(rollup_plugin_exports, {
|
|
33
21
|
ConfigPlugin: () => ConfigPlugin
|
|
34
22
|
});
|
|
35
23
|
module.exports = __toCommonJS(rollup_plugin_exports);
|
|
36
|
-
|
|
37
|
-
// packages/sdk/config/src/plugin/definitions.ts
|
|
38
|
-
var import_js_yaml = __toESM(require("js-yaml"));
|
|
39
|
-
var import_lodash4 = __toESM(require("lodash.set"));
|
|
40
|
-
var import_node_child_process = require("node:child_process");
|
|
41
|
-
var import_node_fs = require("node:fs");
|
|
42
|
-
var import_node_path = require("node:path");
|
|
43
|
-
var import_pkg_up = __toESM(require("pkg-up"));
|
|
44
|
-
var import_log = require("@dxos/log");
|
|
45
|
-
|
|
46
|
-
// packages/sdk/config/src/config.ts
|
|
47
|
-
var import_boolean = require("boolean");
|
|
48
|
-
var import_lodash = __toESM(require("lodash.defaultsdeep"));
|
|
49
|
-
var import_lodash2 = __toESM(require("lodash.get"));
|
|
50
|
-
var import_lodash3 = __toESM(require("lodash.set"));
|
|
51
|
-
var import_protocols = require("@dxos/protocols");
|
|
52
|
-
var configRootType = import_protocols.schema.getCodecForType("dxos.config.Config");
|
|
53
|
-
var mapFromKeyValues = (spec, values) => {
|
|
54
|
-
const config = {};
|
|
55
|
-
for (const [key, { path, type }] of Object.entries(spec)) {
|
|
56
|
-
let value = values[key];
|
|
57
|
-
if (value !== void 0) {
|
|
58
|
-
if (type) {
|
|
59
|
-
switch (type) {
|
|
60
|
-
case "boolean": {
|
|
61
|
-
value = (0, import_boolean.boolean)(value);
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
case "number": {
|
|
65
|
-
value = Number(value);
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
case "string": {
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
case "json": {
|
|
72
|
-
value = value ? JSON.parse(value) : null;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
default: {
|
|
76
|
-
throw new Error(`Invalid type: ${type}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
(0, import_lodash3.default)(config, path, value);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return config;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// packages/sdk/config/src/plugin/definitions.ts
|
|
87
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/config/src/plugin/definitions.ts";
|
|
88
|
-
var CWD = process.cwd();
|
|
89
|
-
var definitions = ({ configPath, envPath, devPath, mode = process.env.NODE_ENV, publicUrl = "", env }) => {
|
|
90
|
-
const KEYS_TO_FILE = {
|
|
91
|
-
__CONFIG_DEFAULTS__: configPath ?? (0, import_node_path.resolve)(CWD, "dx.yml"),
|
|
92
|
-
__CONFIG_ENVS__: envPath ?? (0, import_node_path.resolve)(CWD, "dx-env.yml")
|
|
93
|
-
};
|
|
94
|
-
if (mode !== "production") {
|
|
95
|
-
KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? (0, import_node_path.resolve)(CWD, "dx-local.yml");
|
|
96
|
-
}
|
|
97
|
-
return Object.entries(KEYS_TO_FILE).reduce((prev, [key, value]) => {
|
|
98
|
-
let content = {};
|
|
99
|
-
try {
|
|
100
|
-
content = import_js_yaml.default.load((0, import_node_fs.readFileSync)(value, "utf-8"));
|
|
101
|
-
if (key === "__CONFIG_ENVS__") {
|
|
102
|
-
content = mapFromKeyValues(content, process.env);
|
|
103
|
-
}
|
|
104
|
-
if (key === "__CONFIG_DEFAULTS__") {
|
|
105
|
-
env?.map((key2) => (0, import_lodash4.default)(content, [
|
|
106
|
-
"runtime",
|
|
107
|
-
"app",
|
|
108
|
-
"env",
|
|
109
|
-
key2
|
|
110
|
-
], process.env[key2]));
|
|
111
|
-
try {
|
|
112
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
113
|
-
const commitHash = (0, import_node_child_process.execSync)("git rev-parse --short HEAD", {
|
|
114
|
-
encoding: "utf-8"
|
|
115
|
-
}).replace("\n", "");
|
|
116
|
-
const packagePath = import_pkg_up.default.sync();
|
|
117
|
-
const packageJson = packagePath && JSON.parse((0, import_node_fs.readFileSync)(packagePath, "utf-8"));
|
|
118
|
-
(0, import_lodash4.default)(content, [
|
|
119
|
-
"runtime",
|
|
120
|
-
"app",
|
|
121
|
-
"build",
|
|
122
|
-
"timestamp"
|
|
123
|
-
], timestamp);
|
|
124
|
-
(0, import_lodash4.default)(content, [
|
|
125
|
-
"runtime",
|
|
126
|
-
"app",
|
|
127
|
-
"build",
|
|
128
|
-
"commitHash"
|
|
129
|
-
], commitHash);
|
|
130
|
-
(0, import_lodash4.default)(content, [
|
|
131
|
-
"runtime",
|
|
132
|
-
"app",
|
|
133
|
-
"build",
|
|
134
|
-
"version"
|
|
135
|
-
], packageJson?.version);
|
|
136
|
-
} catch {
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
} catch (err) {
|
|
140
|
-
(0, import_log.log)(`Failed to load file ${value}:`, err, {
|
|
141
|
-
F: __dxlog_file,
|
|
142
|
-
L: 64,
|
|
143
|
-
S: void 0,
|
|
144
|
-
C: (f, a) => f(...a)
|
|
145
|
-
});
|
|
146
|
-
if (key === "__CONFIG_DEFAULTS__") {
|
|
147
|
-
throw new Error(`Failed to load default config file from ${value}`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return {
|
|
151
|
-
...prev,
|
|
152
|
-
[key]: content
|
|
153
|
-
};
|
|
154
|
-
}, {
|
|
155
|
-
__DXOS_CONFIG__: {
|
|
156
|
-
dynamic: mode === "production",
|
|
157
|
-
publicUrl
|
|
158
|
-
},
|
|
159
|
-
__CONFIG_DEFAULTS__: {},
|
|
160
|
-
__CONFIG_ENVS__: {},
|
|
161
|
-
__CONFIG_LOCAL__: {}
|
|
162
|
-
});
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
// packages/sdk/config/src/plugin/rollup-plugin.ts
|
|
24
|
+
var import_chunk_2FZXTCPZ = require("./chunk-2FZXTCPZ.cjs");
|
|
166
25
|
var ConfigPlugin = (options = {}) => {
|
|
167
|
-
const contents = Object.entries(definitions({
|
|
26
|
+
const contents = Object.entries((0, import_chunk_2FZXTCPZ.definitions)({
|
|
168
27
|
...options,
|
|
169
28
|
mode: process.env.NODE_ENV
|
|
170
29
|
})).map(([key, value]) => `globalThis.${key} = ${JSON.stringify(value)};`).join("\n");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/plugin/rollup-plugin.ts"
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { type Plugin } from 'rollup';\n\nimport { definitions } from './definitions';\nimport { type ConfigPluginOpts } from './types';\n\nexport const ConfigPlugin = (options: ConfigPluginOpts = {}): Plugin => {\n const contents = Object.entries(definitions({ ...options, mode: process.env.NODE_ENV }))\n .map(([key, value]) => `globalThis.${key} = ${JSON.stringify(value)};`)\n .join('\\n');\n\n return {\n name: 'dxos-config',\n banner: contents,\n };\n};\n"
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../src/plugin/rollup-plugin.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { type Plugin } from 'rollup';\n\nimport { definitions } from './definitions';\nimport { type ConfigPluginOpts } from './types';\n\nexport const ConfigPlugin = (options: ConfigPluginOpts = {}): Plugin => {\n const contents = Object.entries(definitions({ ...options, mode: process.env.NODE_ENV }))\n .map(([key, value]) => `globalThis.${key} = ${JSON.stringify(value)};`)\n .join('\\n');\n\n return {\n name: 'dxos-config',\n banner: contents,\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AASO,IAAMA,eAAe,CAACC,UAA4B,CAAC,MAAC;AACzD,QAAMC,WAAWC,OAAOC,YAAQC,mCAAY;IAAE,GAAGJ;IAASK,MAAMC,QAAQC,IAAIC;EAAS,CAAA,CAAA,EAClFC,IAAI,CAAC,CAACC,KAAKC,KAAAA,MAAW,cAAcD,GAAAA,MAASE,KAAKC,UAAUF,KAAAA,CAAAA,GAAS,EACrEG,KAAK,IAAA;AAER,SAAO;IACLC,MAAM;IACNC,QAAQf;EACV;AACF;",
|
|
6
|
+
"names": ["ConfigPlugin", "options", "contents", "Object", "entries", "definitions", "mode", "process", "env", "NODE_ENV", "map", "key", "value", "JSON", "stringify", "join", "name", "banner"]
|
|
7
7
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,160 +15,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// packages/sdk/config/src/plugin/vite-plugin.ts
|
|
31
19
|
var vite_plugin_exports = {};
|
|
32
20
|
__export(vite_plugin_exports, {
|
|
33
21
|
ConfigPlugin: () => ConfigPlugin
|
|
34
22
|
});
|
|
35
23
|
module.exports = __toCommonJS(vite_plugin_exports);
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
// packages/sdk/config/src/plugin/definitions.ts
|
|
39
|
-
var import_js_yaml = __toESM(require("js-yaml"));
|
|
40
|
-
var import_lodash4 = __toESM(require("lodash.set"));
|
|
41
|
-
var import_node_child_process = require("node:child_process");
|
|
42
|
-
var import_node_fs = require("node:fs");
|
|
24
|
+
var import_chunk_2FZXTCPZ = require("./chunk-2FZXTCPZ.cjs");
|
|
43
25
|
var import_node_path = require("node:path");
|
|
44
|
-
var import_pkg_up = __toESM(require("pkg-up"));
|
|
45
|
-
var import_log = require("@dxos/log");
|
|
46
|
-
|
|
47
|
-
// packages/sdk/config/src/config.ts
|
|
48
|
-
var import_boolean = require("boolean");
|
|
49
|
-
var import_lodash = __toESM(require("lodash.defaultsdeep"));
|
|
50
|
-
var import_lodash2 = __toESM(require("lodash.get"));
|
|
51
|
-
var import_lodash3 = __toESM(require("lodash.set"));
|
|
52
|
-
var import_protocols = require("@dxos/protocols");
|
|
53
|
-
var configRootType = import_protocols.schema.getCodecForType("dxos.config.Config");
|
|
54
|
-
var mapFromKeyValues = (spec, values) => {
|
|
55
|
-
const config = {};
|
|
56
|
-
for (const [key, { path, type }] of Object.entries(spec)) {
|
|
57
|
-
let value = values[key];
|
|
58
|
-
if (value !== void 0) {
|
|
59
|
-
if (type) {
|
|
60
|
-
switch (type) {
|
|
61
|
-
case "boolean": {
|
|
62
|
-
value = (0, import_boolean.boolean)(value);
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
case "number": {
|
|
66
|
-
value = Number(value);
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
case "string": {
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
case "json": {
|
|
73
|
-
value = value ? JSON.parse(value) : null;
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
default: {
|
|
77
|
-
throw new Error(`Invalid type: ${type}`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
(0, import_lodash3.default)(config, path, value);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return config;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// packages/sdk/config/src/plugin/definitions.ts
|
|
88
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/config/src/plugin/definitions.ts";
|
|
89
|
-
var CWD = process.cwd();
|
|
90
|
-
var definitions = ({ configPath, envPath, devPath, mode = process.env.NODE_ENV, publicUrl = "", env }) => {
|
|
91
|
-
const KEYS_TO_FILE = {
|
|
92
|
-
__CONFIG_DEFAULTS__: configPath ?? (0, import_node_path.resolve)(CWD, "dx.yml"),
|
|
93
|
-
__CONFIG_ENVS__: envPath ?? (0, import_node_path.resolve)(CWD, "dx-env.yml")
|
|
94
|
-
};
|
|
95
|
-
if (mode !== "production") {
|
|
96
|
-
KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? (0, import_node_path.resolve)(CWD, "dx-local.yml");
|
|
97
|
-
}
|
|
98
|
-
return Object.entries(KEYS_TO_FILE).reduce((prev, [key, value]) => {
|
|
99
|
-
let content = {};
|
|
100
|
-
try {
|
|
101
|
-
content = import_js_yaml.default.load((0, import_node_fs.readFileSync)(value, "utf-8"));
|
|
102
|
-
if (key === "__CONFIG_ENVS__") {
|
|
103
|
-
content = mapFromKeyValues(content, process.env);
|
|
104
|
-
}
|
|
105
|
-
if (key === "__CONFIG_DEFAULTS__") {
|
|
106
|
-
env?.map((key2) => (0, import_lodash4.default)(content, [
|
|
107
|
-
"runtime",
|
|
108
|
-
"app",
|
|
109
|
-
"env",
|
|
110
|
-
key2
|
|
111
|
-
], process.env[key2]));
|
|
112
|
-
try {
|
|
113
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
114
|
-
const commitHash = (0, import_node_child_process.execSync)("git rev-parse --short HEAD", {
|
|
115
|
-
encoding: "utf-8"
|
|
116
|
-
}).replace("\n", "");
|
|
117
|
-
const packagePath = import_pkg_up.default.sync();
|
|
118
|
-
const packageJson = packagePath && JSON.parse((0, import_node_fs.readFileSync)(packagePath, "utf-8"));
|
|
119
|
-
(0, import_lodash4.default)(content, [
|
|
120
|
-
"runtime",
|
|
121
|
-
"app",
|
|
122
|
-
"build",
|
|
123
|
-
"timestamp"
|
|
124
|
-
], timestamp);
|
|
125
|
-
(0, import_lodash4.default)(content, [
|
|
126
|
-
"runtime",
|
|
127
|
-
"app",
|
|
128
|
-
"build",
|
|
129
|
-
"commitHash"
|
|
130
|
-
], commitHash);
|
|
131
|
-
(0, import_lodash4.default)(content, [
|
|
132
|
-
"runtime",
|
|
133
|
-
"app",
|
|
134
|
-
"build",
|
|
135
|
-
"version"
|
|
136
|
-
], packageJson?.version);
|
|
137
|
-
} catch {
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
} catch (err) {
|
|
141
|
-
(0, import_log.log)(`Failed to load file ${value}:`, err, {
|
|
142
|
-
F: __dxlog_file,
|
|
143
|
-
L: 64,
|
|
144
|
-
S: void 0,
|
|
145
|
-
C: (f, a) => f(...a)
|
|
146
|
-
});
|
|
147
|
-
if (key === "__CONFIG_DEFAULTS__") {
|
|
148
|
-
throw new Error(`Failed to load default config file from ${value}`);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
...prev,
|
|
153
|
-
[key]: content
|
|
154
|
-
};
|
|
155
|
-
}, {
|
|
156
|
-
__DXOS_CONFIG__: {
|
|
157
|
-
dynamic: mode === "production",
|
|
158
|
-
publicUrl
|
|
159
|
-
},
|
|
160
|
-
__CONFIG_DEFAULTS__: {},
|
|
161
|
-
__CONFIG_ENVS__: {},
|
|
162
|
-
__CONFIG_LOCAL__: {}
|
|
163
|
-
});
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
// packages/sdk/config/src/plugin/vite-plugin.ts
|
|
167
26
|
var ConfigPlugin = (options = {}) => ({
|
|
168
27
|
name: "dxos-config",
|
|
169
28
|
config: ({ root }) => {
|
|
170
|
-
const configPath = root && (0,
|
|
171
|
-
const envPath = root && (0,
|
|
172
|
-
const devPath = root && (0,
|
|
173
|
-
const define = Object.entries(definitions({
|
|
29
|
+
const configPath = root && (0, import_node_path.resolve)(root, options.configPath ?? "dx.yml");
|
|
30
|
+
const envPath = root && (0, import_node_path.resolve)(root, options.envPath ?? "dx-env.yml");
|
|
31
|
+
const devPath = root && (0, import_node_path.resolve)(root, options.devPath ?? "dx-local.yml");
|
|
32
|
+
const define = Object.entries((0, import_chunk_2FZXTCPZ.definitions)({
|
|
174
33
|
...options,
|
|
175
34
|
configPath,
|
|
176
35
|
envPath,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/plugin/vite-plugin.ts"
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { resolve } from 'node:path';\nimport type { Plugin } from 'vite';\n\nimport { definitions } from './definitions';\nimport { type ConfigPluginOpts } from './types';\n\nexport const ConfigPlugin = (options: ConfigPluginOpts = {}): Plugin => ({\n name: 'dxos-config',\n config: ({ root }) => {\n const configPath = root && resolve(root, options.configPath ?? 'dx.yml');\n const envPath = root && resolve(root, options.envPath ?? 'dx-env.yml');\n const devPath = root && resolve(root, options.devPath ?? 'dx-local.yml');\n const define = Object.entries(definitions({ ...options, configPath, envPath, devPath })).reduce(\n (define, [key, value]) => {\n define[key] = JSON.stringify(value);\n return define;\n },\n {} as { [key: string]: string },\n );\n\n return { define };\n },\n});\n"
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../src/plugin/vite-plugin.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { resolve } from 'node:path';\nimport type { Plugin } from 'vite';\n\nimport { definitions } from './definitions';\nimport { type ConfigPluginOpts } from './types';\n\nexport const ConfigPlugin = (options: ConfigPluginOpts = {}): Plugin => ({\n name: 'dxos-config',\n config: ({ root }) => {\n const configPath = root && resolve(root, options.configPath ?? 'dx.yml');\n const envPath = root && resolve(root, options.envPath ?? 'dx-env.yml');\n const devPath = root && resolve(root, options.devPath ?? 'dx-local.yml');\n const define = Object.entries(definitions({ ...options, configPath, envPath, devPath })).reduce(\n (define, [key, value]) => {\n define[key] = JSON.stringify(value);\n return define;\n },\n {} as { [key: string]: string },\n );\n\n return { define };\n },\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAIA,uBAAwB;AAMjB,IAAMA,eAAe,CAACC,UAA4B,CAAC,OAAe;EACvEC,MAAM;EACNC,QAAQ,CAAC,EAAEC,KAAI,MAAE;AACf,UAAMC,aAAaD,YAAQE,0BAAQF,MAAMH,QAAQI,cAAc,QAAA;AAC/D,UAAME,UAAUH,YAAQE,0BAAQF,MAAMH,QAAQM,WAAW,YAAA;AACzD,UAAMC,UAAUJ,YAAQE,0BAAQF,MAAMH,QAAQO,WAAW,cAAA;AACzD,UAAMC,SAASC,OAAOC,YAAQC,mCAAY;MAAE,GAAGX;MAASI;MAAYE;MAASC;IAAQ,CAAA,CAAA,EAAIK,OACvF,CAACJ,SAAQ,CAACK,KAAKC,KAAAA,MAAM;AACnBN,cAAOK,GAAAA,IAAOE,KAAKC,UAAUF,KAAAA;AAC7B,aAAON;IACT,GACA,CAAC,CAAA;AAGH,WAAO;MAAEA;IAAO;EAClB;AACF;",
|
|
6
|
+
"names": ["ConfigPlugin", "options", "name", "config", "root", "configPath", "resolve", "envPath", "devPath", "define", "Object", "entries", "definitions", "reduce", "key", "value", "JSON", "stringify"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/config",
|
|
3
|
-
"version": "0.3.8-main.
|
|
3
|
+
"version": "0.3.8-main.c66298b",
|
|
4
4
|
"description": "Config utilities",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"lodash.get": "^4.4.2",
|
|
32
32
|
"lodash.set": "^4.3.2",
|
|
33
33
|
"pkg-up": "^3.1.0",
|
|
34
|
-
"@dxos/log": "0.3.8-main.
|
|
35
|
-
"@dxos/node-std": "0.3.8-main.
|
|
36
|
-
"@dxos/protocols": "0.3.8-main.
|
|
34
|
+
"@dxos/log": "0.3.8-main.c66298b",
|
|
35
|
+
"@dxos/node-std": "0.3.8-main.c66298b",
|
|
36
|
+
"@dxos/protocols": "0.3.8-main.c66298b"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/js-yaml": "^4.0.5",
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
declare const _exports: any;
|
|
2
|
-
export = _exports;
|
|
3
|
-
export var Config: {
|
|
4
|
-
new (config?: {}, ...objects: any[]): {
|
|
5
|
-
_config: any;
|
|
6
|
-
/**
|
|
7
|
-
* Returns an immutable config JSON object.
|
|
8
|
-
*/
|
|
9
|
-
readonly values: any;
|
|
10
|
-
/**
|
|
11
|
-
* Returns the given config property.
|
|
12
|
-
*
|
|
13
|
-
* @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
|
|
14
|
-
* @param defaultValue Default value to return if option is not present in the config.
|
|
15
|
-
* @returns The config value or undefined if the option is not present.
|
|
16
|
-
*/
|
|
17
|
-
get(key: any, defaultValue: any): any;
|
|
18
|
-
/**
|
|
19
|
-
* Returns config key without type checking.
|
|
20
|
-
*
|
|
21
|
-
* @deprecated Use the type-checked version.
|
|
22
|
-
*/
|
|
23
|
-
getUnchecked(key: any, defaultValue: any): any;
|
|
24
|
-
/**
|
|
25
|
-
* Returns the given config property or throw if it doesn't exist.
|
|
26
|
-
*
|
|
27
|
-
* @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
|
|
28
|
-
*/
|
|
29
|
-
getOrThrow(key: any): any;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
export function Defaults(basePath?: any): any;
|
|
33
|
-
export function Dynamics(): {};
|
|
34
|
-
export function Envs(basePath?: any): {};
|
|
35
|
-
export var FILE_DEFAULTS: string;
|
|
36
|
-
export var FILE_DYNAMICS: string;
|
|
37
|
-
export var FILE_ENVS: string;
|
|
38
|
-
export function Local(): {};
|
|
39
|
-
export function definitions({ configPath, envPath, devPath, mode, publicUrl, env }: {
|
|
40
|
-
configPath: any;
|
|
41
|
-
envPath: any;
|
|
42
|
-
devPath: any;
|
|
43
|
-
mode?: string | undefined;
|
|
44
|
-
publicUrl?: string | undefined;
|
|
45
|
-
env: any;
|
|
46
|
-
}): {
|
|
47
|
-
__DXOS_CONFIG__: {
|
|
48
|
-
dynamic: boolean;
|
|
49
|
-
publicUrl: string;
|
|
50
|
-
};
|
|
51
|
-
__CONFIG_DEFAULTS__: {};
|
|
52
|
-
__CONFIG_ENVS__: {};
|
|
53
|
-
__CONFIG_LOCAL__: {};
|
|
54
|
-
};
|
|
55
|
-
export var defs: any;
|
|
56
|
-
export function mapFromKeyValues(spec: any, values: any): {};
|
|
57
|
-
export function mapToKeyValues(spec: any, values: any): {};
|
|
58
|
-
export function validateConfig(config: any): any;
|
|
59
|
-
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../lib/node/index.cjs"],"names":[],"mappings":";;AAqHA;;;QAWE;;UAEE;;QAIF;;;;;;UAME;;QAIF;;;;UAIE;;QAIF;;;;UAIE;;;EAQF;AA4BF,8CAA+H;AAL/H,+BAAyB;AACzB,yCAGC;AAnBD,iCAAmC;AAEnC,iCAAiC;AADjC,6BAA+B;AAa/B,4BAAsB;AAkBtB;;;;;;;;;;;;;;;EA0EC;AAvOD,qBAAiE;AASjE,6DA+BC;AACD,2DAeC;AACD,iDAYC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-plugin.d.cts","sourceRoot":"","sources":["../../../../plugin/node/esbuild-plugin.cjs"],"names":[],"mappings":";;AAqKA;;;;;EAeC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../../src/testing/build.js"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../../../src/testing/entry.js"],"names":[],"mappings":""}
|