react-native-config-ultimate 0.0.7 → 0.2.0

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.
Files changed (152) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/gradle.properties +6 -0
  3. package/lib/commonjs/NativeUltimateConfig.js +20 -0
  4. package/lib/commonjs/NativeUltimateConfig.js.map +1 -0
  5. package/lib/commonjs/bin.spec.js +48 -0
  6. package/lib/commonjs/bin.spec.js.map +1 -0
  7. package/lib/commonjs/cli.js +146 -0
  8. package/lib/commonjs/cli.js.map +1 -0
  9. package/lib/commonjs/cli.spec.js +190 -0
  10. package/lib/commonjs/cli.spec.js.map +1 -0
  11. package/lib/commonjs/flatten.js +23 -0
  12. package/lib/commonjs/flatten.js.map +1 -0
  13. package/lib/commonjs/flatten.spec.js +32 -0
  14. package/lib/commonjs/flatten.spec.js.map +1 -0
  15. package/lib/commonjs/index.js +34 -0
  16. package/lib/commonjs/index.js.map +1 -0
  17. package/lib/commonjs/load-env.js +86 -0
  18. package/lib/commonjs/load-env.js.map +1 -0
  19. package/lib/commonjs/load-env.spec.js +257 -0
  20. package/lib/commonjs/load-env.spec.js.map +1 -0
  21. package/lib/commonjs/main.js +36 -0
  22. package/lib/commonjs/main.js.map +1 -0
  23. package/lib/commonjs/main.spec.js +228 -0
  24. package/lib/commonjs/main.spec.js.map +1 -0
  25. package/lib/commonjs/package.json +1 -0
  26. package/lib/commonjs/render-env.js +90 -0
  27. package/lib/commonjs/render-env.js.map +1 -0
  28. package/lib/commonjs/render-env.spec.js +397 -0
  29. package/lib/commonjs/render-env.spec.js.map +1 -0
  30. package/lib/commonjs/resolve-env.js +30 -0
  31. package/lib/commonjs/resolve-env.js.map +1 -0
  32. package/lib/commonjs/resolve-env.spec.js +31 -0
  33. package/lib/commonjs/resolve-env.spec.js.map +1 -0
  34. package/lib/commonjs/templates/ConfigValues.h.handlebars +24 -0
  35. package/lib/commonjs/templates/index.d.ts.handlebars +18 -0
  36. package/lib/commonjs/templates/index.web.js.handlebars +1 -0
  37. package/lib/commonjs/templates/override.js.handlebars +16 -0
  38. package/lib/commonjs/templates/rncu.xcconfig.handlebars +4 -0
  39. package/lib/commonjs/templates/rncu.yaml.handlebars +7 -0
  40. package/lib/commonjs/validate-env.js +63 -0
  41. package/lib/commonjs/validate-env.js.map +1 -0
  42. package/lib/commonjs/validate-env.spec.js +325 -0
  43. package/lib/commonjs/validate-env.spec.js.map +1 -0
  44. package/lib/commonjs/write-env.js +80 -0
  45. package/lib/commonjs/write-env.js.map +1 -0
  46. package/lib/commonjs/write-env.spec.js +115 -0
  47. package/lib/commonjs/write-env.spec.js.map +1 -0
  48. package/lib/module/NativeUltimateConfig.js +16 -0
  49. package/lib/module/NativeUltimateConfig.js.map +1 -0
  50. package/lib/module/bin.spec.js +47 -0
  51. package/lib/module/bin.spec.js.map +1 -0
  52. package/lib/module/cli.js +139 -0
  53. package/lib/module/cli.js.map +1 -0
  54. package/lib/module/cli.spec.js +190 -0
  55. package/lib/module/cli.spec.js.map +1 -0
  56. package/lib/module/flatten.js +18 -0
  57. package/lib/module/flatten.js.map +1 -0
  58. package/lib/module/flatten.spec.js +31 -0
  59. package/lib/module/flatten.spec.js.map +1 -0
  60. package/lib/module/index.js +30 -0
  61. package/lib/module/index.js.map +1 -0
  62. package/lib/module/load-env.js +81 -0
  63. package/lib/module/load-env.js.map +1 -0
  64. package/lib/module/load-env.spec.js +257 -0
  65. package/lib/module/load-env.spec.js.map +1 -0
  66. package/lib/module/main.js +31 -0
  67. package/lib/module/main.js.map +1 -0
  68. package/lib/module/main.spec.js +224 -0
  69. package/lib/module/main.spec.js.map +1 -0
  70. package/lib/module/render-env.js +84 -0
  71. package/lib/module/render-env.js.map +1 -0
  72. package/lib/module/render-env.spec.js +396 -0
  73. package/lib/module/render-env.spec.js.map +1 -0
  74. package/lib/module/resolve-env.js +26 -0
  75. package/lib/module/resolve-env.js.map +1 -0
  76. package/lib/module/resolve-env.spec.js +30 -0
  77. package/lib/module/resolve-env.spec.js.map +1 -0
  78. package/lib/module/templates/ConfigValues.h.handlebars +24 -0
  79. package/lib/module/templates/index.d.ts.handlebars +18 -0
  80. package/lib/module/templates/index.web.js.handlebars +1 -0
  81. package/lib/module/templates/override.js.handlebars +16 -0
  82. package/lib/module/templates/rncu.xcconfig.handlebars +4 -0
  83. package/lib/module/templates/rncu.yaml.handlebars +7 -0
  84. package/lib/module/validate-env.js +59 -0
  85. package/lib/module/validate-env.js.map +1 -0
  86. package/lib/module/validate-env.spec.js +325 -0
  87. package/lib/module/validate-env.spec.js.map +1 -0
  88. package/lib/module/write-env.js +75 -0
  89. package/lib/module/write-env.js.map +1 -0
  90. package/lib/module/write-env.spec.js +115 -0
  91. package/lib/module/write-env.spec.js.map +1 -0
  92. package/lib/typescript/src/NativeUltimateConfig.d.ts +18 -0
  93. package/lib/typescript/src/NativeUltimateConfig.d.ts.map +1 -0
  94. package/lib/typescript/src/bin.spec.d.ts +2 -0
  95. package/lib/typescript/src/bin.spec.d.ts.map +1 -0
  96. package/lib/typescript/src/cli.d.ts +2 -0
  97. package/lib/typescript/src/cli.d.ts.map +1 -0
  98. package/lib/typescript/src/cli.spec.d.ts +14 -0
  99. package/lib/typescript/src/cli.spec.d.ts.map +1 -0
  100. package/lib/typescript/src/flatten.d.ts +8 -0
  101. package/lib/typescript/src/flatten.d.ts.map +1 -0
  102. package/lib/typescript/src/flatten.spec.d.ts +2 -0
  103. package/lib/typescript/src/flatten.spec.d.ts.map +1 -0
  104. package/lib/typescript/src/index.d.ts +6 -0
  105. package/lib/typescript/src/index.d.ts.map +1 -0
  106. package/lib/typescript/src/load-env.d.ts +23 -0
  107. package/lib/typescript/src/load-env.d.ts.map +1 -0
  108. package/lib/typescript/src/load-env.spec.d.ts +6 -0
  109. package/lib/typescript/src/load-env.spec.d.ts.map +1 -0
  110. package/lib/typescript/src/main.d.ts +12 -0
  111. package/lib/typescript/src/main.d.ts.map +1 -0
  112. package/lib/typescript/src/main.spec.d.ts +2 -0
  113. package/lib/typescript/src/main.spec.d.ts.map +1 -0
  114. package/lib/typescript/src/render-env.d.ts +11 -0
  115. package/lib/typescript/src/render-env.d.ts.map +1 -0
  116. package/lib/typescript/src/render-env.spec.d.ts +2 -0
  117. package/lib/typescript/src/render-env.spec.d.ts.map +1 -0
  118. package/lib/typescript/src/resolve-env.d.ts +35 -0
  119. package/lib/typescript/src/resolve-env.d.ts.map +1 -0
  120. package/lib/typescript/src/resolve-env.spec.d.ts +2 -0
  121. package/lib/typescript/src/resolve-env.spec.d.ts.map +1 -0
  122. package/lib/typescript/src/validate-env.d.ts +10 -0
  123. package/lib/typescript/src/validate-env.d.ts.map +1 -0
  124. package/lib/typescript/src/validate-env.spec.d.ts +2 -0
  125. package/lib/typescript/src/validate-env.spec.d.ts.map +1 -0
  126. package/lib/typescript/src/write-env.d.ts +13 -0
  127. package/lib/typescript/src/write-env.d.ts.map +1 -0
  128. package/lib/typescript/src/write-env.spec.d.ts +9 -0
  129. package/lib/typescript/src/write-env.spec.d.ts.map +1 -0
  130. package/package.json +86 -52
  131. package/src/NativeUltimateConfig.ts +1 -2
  132. package/src/cli.ts +161 -0
  133. package/src/flatten.ts +26 -0
  134. package/src/index.ts +37 -0
  135. package/src/load-env.ts +81 -0
  136. package/src/main.ts +39 -0
  137. package/src/render-env.ts +111 -0
  138. package/src/resolve-env.ts +45 -0
  139. package/src/validate-env.ts +71 -0
  140. package/src/write-env.ts +74 -0
  141. package/bin.js +0 -5
  142. package/index.js +0 -28
  143. package/override.js +0 -1
  144. package/src/NativeUltimateConfig.js +0 -4
  145. package/src/cli.js +0 -176
  146. package/src/flatten.js +0 -22
  147. package/src/load-env.js +0 -107
  148. package/src/main.js +0 -34
  149. package/src/render-env.js +0 -113
  150. package/src/resolve-env.js +0 -12
  151. package/src/validate-env.js +0 -59
  152. package/src/write-env.js +0 -102
package/src/load-env.js DELETED
@@ -1,107 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.default = load_env;
37
- const dotenv = __importStar(require("dotenv"));
38
- const dotenv_expand_1 = require("dotenv-expand");
39
- const yaml = __importStar(require("js-yaml"));
40
- const path = __importStar(require("path"));
41
- const fs = __importStar(require("fs"));
42
- function detect_format(config_path) {
43
- const { ext } = path.parse(config_path);
44
- return ext === '.yml' || ext === '.yaml' ? 'yaml' : 'dotenv';
45
- }
46
- function read_yaml(config_path) {
47
- const data = yaml.load(fs.readFileSync(config_path).toString());
48
- if (typeof data === 'undefined' || data === null || typeof data !== 'object') {
49
- throw new Error(`Expected to read object from ${config_path}, but got '${data}'`);
50
- }
51
- return data;
52
- }
53
- /**
54
- * Load one or more env files and merge them (last file wins for conflicting keys).
55
- *
56
- * Dotenv files (.env, .env.staging, etc.):
57
- * - All files are merged first, then variable expansion runs once.
58
- * - This means cross-file `$VAR` references work:
59
- * .env.base: BASE_URL=https://api.example.com
60
- * .env.staging: API_URL=$BASE_URL/v1 → https://api.example.com/v1
61
- *
62
- * YAML files (.yml, .yaml):
63
- * - Each file is loaded and shallow-merged (last wins for top-level keys).
64
- * - No variable expansion is applied (use YAML anchors instead).
65
- *
66
- * @example
67
- * // Single file (backward-compatible):
68
- * load_env('.env')
69
- *
70
- * // Multi-file merge:
71
- * load_env(['.env.base', '.env.staging'])
72
- */
73
- function load_env(config_paths) {
74
- var _a, _b;
75
- const paths = Array.isArray(config_paths) ? config_paths : [config_paths];
76
- if (paths.length === 0) {
77
- throw new Error('No env file specified. Usage: rncu <env-file> [env-file2 ...]');
78
- }
79
- const formats = paths.map(detect_format);
80
- const allDotenv = formats.every((f) => f === 'dotenv');
81
- if (allDotenv) {
82
- // Merge raw parsed content first, then expand once —
83
- // so cross-file $VAR references resolve correctly.
84
- const raw = {};
85
- for (const p of paths) {
86
- const content = fs.readFileSync(p, 'utf8');
87
- Object.assign(raw, dotenv.parse(content));
88
- }
89
- const result = (0, dotenv_expand_1.expand)({ parsed: raw });
90
- return ((_a = result.parsed) !== null && _a !== void 0 ? _a : raw);
91
- }
92
- // YAML or mixed: load each file individually and shallow-merge.
93
- const merged = {};
94
- for (let i = 0; i < paths.length; i++) {
95
- const p = paths[i];
96
- if (formats[i] === 'yaml') {
97
- Object.assign(merged, read_yaml(p));
98
- }
99
- else {
100
- const content = fs.readFileSync(p, 'utf8');
101
- const parsed = dotenv.parse(content);
102
- const expanded = (0, dotenv_expand_1.expand)({ parsed });
103
- Object.assign(merged, (_b = expanded.parsed) !== null && _b !== void 0 ? _b : parsed);
104
- }
105
- }
106
- return merged;
107
- }
package/src/main.js DELETED
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = main;
7
- const load_env_1 = __importDefault(require("./load-env"));
8
- const render_env_1 = __importDefault(require("./render-env"));
9
- const write_env_1 = __importDefault(require("./write-env"));
10
- const flatten_1 = __importDefault(require("./flatten"));
11
- const resolve_env_1 = __importDefault(require("./resolve-env"));
12
- const validate_env_1 = require("./validate-env");
13
- /**
14
- * Main build-time pipeline:
15
- * load → resolve (on_env hook) → validate (schema) → flatten → render → write
16
- *
17
- * @param project_root Root of the React Native project
18
- * @param lib_root Root of the react-native-config-ultimate install
19
- * @param env_file Path(s) to env file(s). Multiple files are merged (last wins).
20
- * @param rc Optional RC config from `.rncurc.js`
21
- */
22
- async function main(project_root, lib_root, env_file, rc) {
23
- const env = await (0, resolve_env_1.default)((0, load_env_1.default)(env_file), rc);
24
- if (rc === null || rc === void 0 ? void 0 : rc.schema) {
25
- (0, validate_env_1.validate_env)(env, rc.schema);
26
- }
27
- const flat = {
28
- ios: (0, flatten_1.default)(env, 'ios'),
29
- android: (0, flatten_1.default)(env, 'android'),
30
- web: (0, flatten_1.default)(env, 'web'),
31
- };
32
- const files_to_write = (0, render_env_1.default)(project_root, lib_root, flat, rc);
33
- (0, write_env_1.default)(files_to_write);
34
- }
package/src/render-env.js DELETED
@@ -1,113 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.default = render_env;
40
- const path = __importStar(require("path"));
41
- const fs = __importStar(require("fs"));
42
- const handlebars_1 = __importDefault(require("handlebars"));
43
- const code_file_name = 'ConfigValues';
44
- const config_file_name = 'rncu';
45
- // ─── Handlebars helpers (registered once at module load, not per-call) ────────
46
- function is_string(value) {
47
- return typeof value === 'string';
48
- }
49
- function is_number(value) {
50
- return typeof value === 'number';
51
- }
52
- function is_boolean(value) {
53
- return typeof value === 'boolean';
54
- }
55
- function escape(value) {
56
- if (is_string(value)) {
57
- return value
58
- .replace(/\\/gm, '\\\\')
59
- .replace(/"/gm, '\\"')
60
- .replace(/\n/gm, '\\n')
61
- .replace(/\r/gm, '\\r');
62
- }
63
- return value;
64
- }
65
- function xcconfig_format(value) {
66
- if (is_string(value)) {
67
- return value.replace(/\/\//gm, '/$()/');
68
- }
69
- return value;
70
- }
71
- function to_json(value) {
72
- return JSON.stringify(value, null, 2);
73
- }
74
- handlebars_1.default.registerHelper('isBoolean', is_boolean);
75
- handlebars_1.default.registerHelper('isString', is_string);
76
- handlebars_1.default.registerHelper('isNumber', is_number);
77
- handlebars_1.default.registerHelper('escape', escape);
78
- handlebars_1.default.registerHelper('xcconfigFormat', xcconfig_format);
79
- handlebars_1.default.registerHelper('toJSON', to_json);
80
- // ─── Template cache (compiled once per template name, not per build) ──────────
81
- const template_cache = new Map();
82
- function get_compiled_template(template_name) {
83
- const cached = template_cache.get(template_name);
84
- if (cached)
85
- return cached;
86
- const template_path = path.join(__dirname, 'templates', `${template_name}.handlebars`);
87
- const compiled = handlebars_1.default.compile(fs.readFileSync(template_path, 'utf8'));
88
- template_cache.set(template_name, compiled);
89
- return compiled;
90
- }
91
- function render_template(template_name, data) {
92
- return get_compiled_template(template_name)(data);
93
- }
94
- function render_env(project_root, lib_root, env, rc) {
95
- const { ios, android, web } = env;
96
- const map = {
97
- [path.join(lib_root, 'index.d.ts')]: render_template('index.d.ts', ios),
98
- [path.join(lib_root, 'index.web.js')]: render_template('index.web.js', web),
99
- [path.join(lib_root, 'ios', `${code_file_name}.h`)]: render_template('ConfigValues.h', ios),
100
- [path.join(lib_root, 'android', 'rncu.yaml')]: render_template('rncu.yaml', android),
101
- };
102
- // Only write xcconfig if the project has an ios folder.
103
- // All RN apps have it; some react-native-web apps may not.
104
- if (fs.existsSync(path.join(project_root, 'ios'))) {
105
- map[path.join(project_root, 'ios', `${config_file_name}.xcconfig`)] = render_template('rncu.xcconfig', ios);
106
- }
107
- const js_override = rc && typeof rc.js_override === 'boolean' && rc.js_override;
108
- map[path.join(lib_root, 'override.js')] = render_template('override.js', {
109
- ios: js_override ? ios : {},
110
- android: js_override ? android : {},
111
- });
112
- return map;
113
- }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = resolve_env;
4
- async function resolve_env(env, rc) {
5
- if (rc && rc.on_env) {
6
- const patched_env = await rc.on_env(env);
7
- return typeof patched_env === 'undefined' ? env : patched_env;
8
- }
9
- else {
10
- return env;
11
- }
12
- }
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validate_env = validate_env;
4
- const VALID_KEY_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
5
- /**
6
- * Validate env data against a schema defined in `.rncurc.js`.
7
- * Called after `on_env` so the hook can add/transform vars before validation.
8
- *
9
- * Throws with a human-readable error listing ALL failures at once
10
- * (not just the first one), so users can fix everything in one pass.
11
- */
12
- function validate_env(env, schema) {
13
- const errors = [];
14
- // Validate all env key names are valid identifiers
15
- for (const key of Object.keys(env)) {
16
- if (!VALID_KEY_PATTERN.test(key)) {
17
- errors.push(`Invalid env key name: "${key}". Keys must start with a letter or underscore and contain only letters, numbers, and underscores.`);
18
- }
19
- }
20
- // Pre-compile all regex patterns once, before iterating over env values.
21
- // This avoids re-compiling the same pattern for every validated key.
22
- const compiled_patterns = new Map();
23
- for (const [key, field] of Object.entries(schema)) {
24
- if (field.pattern) {
25
- try {
26
- compiled_patterns.set(key, new RegExp(field.pattern));
27
- }
28
- catch (_a) {
29
- errors.push(`${key}: invalid regex pattern /${field.pattern}/`);
30
- }
31
- }
32
- }
33
- for (const [key, field] of Object.entries(schema)) {
34
- const raw = env[key];
35
- const missing = raw === undefined || raw === null || String(raw).trim() === '';
36
- if (field.required && missing) {
37
- errors.push(`Missing required env var: ${key}`);
38
- continue; // can't type-check a missing value
39
- }
40
- if (missing)
41
- continue; // optional and not present → OK
42
- const value = String(raw);
43
- if (field.type === 'number' && isNaN(Number(value))) {
44
- errors.push(`${key} must be a number, got "${value}"`);
45
- }
46
- if (field.type === 'boolean' && !['true', 'false', '1', '0'].includes(value.toLowerCase())) {
47
- errors.push(`${key} must be a boolean (true/false/1/0), got "${value}"`);
48
- }
49
- const pattern = compiled_patterns.get(key);
50
- if (pattern && !pattern.test(value)) {
51
- errors.push(`${key} does not match pattern /${field.pattern}/, got "${value}"`);
52
- }
53
- }
54
- if (errors.length > 0) {
55
- throw new Error(`\n\n❌ react-native-config-ultimate: env validation failed:\n` +
56
- errors.map((e) => ` • ${e}`).join('\n') +
57
- '\n');
58
- }
59
- }
package/src/write-env.js DELETED
@@ -1,102 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.default = write_env;
37
- const fs = __importStar(require("fs"));
38
- const os = __importStar(require("os"));
39
- const path = __importStar(require("path"));
40
- /**
41
- * Atomically write all generated files.
42
- *
43
- * Strategy: write each file to a temp path first, then rename (atomic on POSIX).
44
- * If any write fails, we abort before committing any renames so the project
45
- * is never left in a partially-written state.
46
- *
47
- * On Windows, `fs.renameSync` across drives may fail — in that case we fall
48
- * back to a direct `writeFileSync` (best-effort, still better than nothing).
49
- */
50
- function write_env(files) {
51
- const tmp_dir = os.tmpdir();
52
- // Phase 1: write all content to temp files — if anything fails, no real files are touched.
53
- const pending = [];
54
- try {
55
- for (const dest of Object.keys(files)) {
56
- // Ensure the destination directory exists (handles first-run and hoisted workspaces).
57
- fs.mkdirSync(path.dirname(dest), { recursive: true });
58
- const tmp = path.join(tmp_dir, `rncu_${Date.now()}_${Math.random().toString(36).slice(2)}`);
59
- fs.writeFileSync(tmp, files[dest], 'utf8');
60
- pending.push({ tmp, dest });
61
- }
62
- }
63
- catch (err) {
64
- // Clean up any temp files we already created.
65
- for (const { tmp } of pending) {
66
- try {
67
- fs.unlinkSync(tmp);
68
- }
69
- catch (_a) {
70
- /* ignore */
71
- }
72
- }
73
- throw new Error(`[rncu] Failed to prepare output files: ${err instanceof Error ? err.message : String(err)}`);
74
- }
75
- // Phase 2: atomically rename temp → dest.
76
- // We collect errors and rethrow at the end so the caller gets a clear message.
77
- const rename_errors = [];
78
- for (const { tmp, dest } of pending) {
79
- try {
80
- fs.renameSync(tmp, dest);
81
- }
82
- catch (_b) {
83
- // Cross-device rename (e.g. Windows different drives) — fall back to copy+delete.
84
- try {
85
- fs.copyFileSync(tmp, dest);
86
- fs.unlinkSync(tmp);
87
- }
88
- catch (copy_err) {
89
- rename_errors.push(`${dest}: ${copy_err instanceof Error ? copy_err.message : String(copy_err)}`);
90
- try {
91
- fs.unlinkSync(tmp);
92
- }
93
- catch (_c) {
94
- /* ignore */
95
- }
96
- }
97
- }
98
- }
99
- if (rename_errors.length > 0) {
100
- throw new Error(`[rncu] Failed to write output files:\n` + rename_errors.map((e) => ` • ${e}`).join('\n'));
101
- }
102
- }