cf-envsync 0.3.15 → 0.3.17
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/index.js +29 -20
- package/package.json +1 -1
- package/src/types/config.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -13695,6 +13695,24 @@ function detectIndent(content) {
|
|
|
13695
13695
|
const match = content.match(/\n(\s+)"/);
|
|
13696
13696
|
return match ? match[1] : " ";
|
|
13697
13697
|
}
|
|
13698
|
+
function reindentJson(json, baseIndent) {
|
|
13699
|
+
return json.replace(/\n/g, `
|
|
13700
|
+
${baseIndent}`);
|
|
13701
|
+
}
|
|
13702
|
+
function insertIntoObject(content, objEnd, key, value, keyIndent, braceIndent) {
|
|
13703
|
+
const closingBrace = objEnd - 1;
|
|
13704
|
+
let pos = closingBrace - 1;
|
|
13705
|
+
while (pos >= 0 && (content[pos] === " " || content[pos] === "\t" || content[pos] === `
|
|
13706
|
+
` || content[pos] === "\r"))
|
|
13707
|
+
pos--;
|
|
13708
|
+
const needsComma = pos >= 0 && content[pos] !== "," && content[pos] !== "{";
|
|
13709
|
+
const comma = needsComma ? "," : "";
|
|
13710
|
+
pos++;
|
|
13711
|
+
const insertion = `${comma}
|
|
13712
|
+
${keyIndent}"${key}": ${value}
|
|
13713
|
+
${braceIndent}`;
|
|
13714
|
+
return content.slice(0, pos) + insertion + content.slice(closingBrace);
|
|
13715
|
+
}
|
|
13698
13716
|
async function updateWranglerVars(appPath, environment, vars) {
|
|
13699
13717
|
const configPath = findWranglerConfig(appPath);
|
|
13700
13718
|
if (!configPath) {
|
|
@@ -13706,7 +13724,7 @@ async function updateWranglerVars(appPath, environment, vars) {
|
|
|
13706
13724
|
const envSection = parsed?.env ?? {};
|
|
13707
13725
|
const existingVars = envSection[environment]?.vars ?? {};
|
|
13708
13726
|
const mergedVars = { ...existingVars, ...vars };
|
|
13709
|
-
const varsJson = JSON.stringify(mergedVars, null, indent);
|
|
13727
|
+
const varsJson = reindentJson(JSON.stringify(mergedVars, null, indent), indent.repeat(3));
|
|
13710
13728
|
const envRange = findKeyRange(content, "env");
|
|
13711
13729
|
if (envRange) {
|
|
13712
13730
|
const envObjRange = findKeyRange(content, environment, envRange[0]);
|
|
@@ -13717,38 +13735,24 @@ async function updateWranglerVars(appPath, environment, vars) {
|
|
|
13717
13735
|
await writeFile(configPath, content);
|
|
13718
13736
|
return { success: true, filePath: configPath, updatedCount: Object.keys(vars).length };
|
|
13719
13737
|
}
|
|
13720
|
-
|
|
13721
|
-
const envIndent3 = indent.repeat(3);
|
|
13722
|
-
const insertion3 = `,
|
|
13723
|
-
${envIndent3}"vars": ${varsJson}
|
|
13724
|
-
${indent.repeat(2)}`;
|
|
13725
|
-
content = content.slice(0, insertAt2) + insertion3 + content.slice(insertAt2);
|
|
13738
|
+
content = insertIntoObject(content, envObjRange[1], "vars", varsJson, indent.repeat(3), indent.repeat(2));
|
|
13726
13739
|
await writeFile(configPath, content);
|
|
13727
13740
|
return { success: true, filePath: configPath, updatedCount: Object.keys(vars).length };
|
|
13728
13741
|
}
|
|
13729
|
-
const insertAt = envRange[1] - 1;
|
|
13730
|
-
const envIndent2 = indent.repeat(2);
|
|
13731
13742
|
const inner2 = `{
|
|
13732
13743
|
${indent.repeat(3)}"vars": ${varsJson}
|
|
13733
|
-
${
|
|
13734
|
-
|
|
13735
|
-
${envIndent2}"${environment}": ${inner2}
|
|
13736
|
-
${indent}`;
|
|
13737
|
-
content = content.slice(0, insertAt) + insertion2 + content.slice(insertAt);
|
|
13744
|
+
${indent.repeat(2)}}`;
|
|
13745
|
+
content = insertIntoObject(content, envRange[1], environment, inner2, indent.repeat(2), indent);
|
|
13738
13746
|
await writeFile(configPath, content);
|
|
13739
13747
|
return { success: true, filePath: configPath, updatedCount: Object.keys(vars).length };
|
|
13740
13748
|
}
|
|
13741
13749
|
const lastBrace = content.lastIndexOf("}");
|
|
13742
|
-
const envIndent = indent;
|
|
13743
13750
|
const inner = `{
|
|
13744
13751
|
${indent.repeat(2)}"${environment}": ` + `{
|
|
13745
13752
|
${indent.repeat(3)}"vars": ${varsJson}
|
|
13746
13753
|
${indent.repeat(2)}}
|
|
13747
13754
|
${indent}}`;
|
|
13748
|
-
|
|
13749
|
-
${envIndent}"env": ${inner}
|
|
13750
|
-
`;
|
|
13751
|
-
content = content.slice(0, lastBrace) + insertion + content.slice(lastBrace);
|
|
13755
|
+
content = insertIntoObject(content, lastBrace + 1, "env", inner, indent, "");
|
|
13752
13756
|
await writeFile(configPath, content);
|
|
13753
13757
|
return { success: true, filePath: configPath, updatedCount: Object.keys(vars).length };
|
|
13754
13758
|
}
|
|
@@ -14211,7 +14215,12 @@ var init_validate = __esm(() => {
|
|
|
14211
14215
|
environments = config.environments;
|
|
14212
14216
|
appNames = undefined;
|
|
14213
14217
|
}
|
|
14214
|
-
const
|
|
14218
|
+
const allApps = resolveApps(config, appNames);
|
|
14219
|
+
const apps = allApps.filter((app) => app.validate !== false);
|
|
14220
|
+
if (apps.length === 0) {
|
|
14221
|
+
consola.info("All resolved apps have validate: false. Nothing to validate.");
|
|
14222
|
+
return;
|
|
14223
|
+
}
|
|
14215
14224
|
const examplePath = join7(config.projectRoot, ".env.example");
|
|
14216
14225
|
if (!fileExists(examplePath)) {
|
|
14217
14226
|
consola.error("No .env.example found at project root.");
|
package/package.json
CHANGED
package/src/types/config.ts
CHANGED
|
@@ -44,6 +44,8 @@ export interface AppConfig {
|
|
|
44
44
|
/** Output file(s) for `envsync dev`. Defaults to ".dev.vars".
|
|
45
45
|
* Use an array to generate multiple files, e.g. [".dev.vars", ".env.local"] */
|
|
46
46
|
devFile?: string | string[];
|
|
47
|
+
/** Whether to include this app in `envsync validate`. Defaults to true. */
|
|
48
|
+
validate?: boolean;
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
/** Resolved config after defaults and path resolution */
|