Skip to content

Instantly share code, notes, and snippets.

@jduff
Created February 12, 2024 13:28
Show Gist options
  • Save jduff/a88fc49b76c42cfc2332ad1f6468ee62 to your computer and use it in GitHub Desktop.
Save jduff/a88fc49b76c42cfc2332ad1f6468ee62 to your computer and use it in GitHub Desktop.
@shopify/cli Patch to allow liquid templating in toml files
diff --git a/node_modules/@shopify/cli-kit/dist/public/node/toml.js b/node_modules/@shopify/cli-kit/dist/public/node/toml.js
index a3c4503..8e26498 100644
--- a/node_modules/@shopify/cli-kit/dist/public/node/toml.js
+++ b/node_modules/@shopify/cli-kit/dist/public/node/toml.js
@@ -1,13 +1,28 @@
import * as toml from '@iarna/toml';
+import {Liquid} from 'liquidjs';
+import {readAndParseDotEnv } from './dot-env.js'
+import {fileExists} from './fs.js'
+import {joinPath, cwd} from './path.js'
/**
* Given a TOML string, it returns a JSON object.
*
* @param input - TOML string.
* @returns JSON object.
*/
-export function decodeToml(input) {
+export async function decodeToml(input) {
+ const engine = new Liquid()
const normalizedInput = input.replace(/\r\n$/g, '\n');
- return toml.parse(normalizedInput);
+
+ let envData = process.env;
+ const envFile = joinPath(cwd(), '.env');
+ if (await fileExists(envFile)) {
+ const dotenv = await readAndParseDotEnv(envFile);
+ envData = { ...envData, ...dotenv.variables };
+ }
+
+ const data = { env: envData }
+ const renderedInput = await engine.render(engine.parse(normalizedInput), data);
+ return toml.parse(renderedInput);
}
/**
* Given a JSON object, it returns a TOML string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment