mnfst-render 0.5.29 → 0.5.30
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/manifest.render.mjs +41 -0
- package/package.json +1 -1
package/manifest.render.mjs
CHANGED
|
@@ -2894,6 +2894,41 @@ async function main() {
|
|
|
2894
2894
|
process.stdout.write(`prerender: total time ${hours}h ${minutes}m ${seconds}s\n`);
|
|
2895
2895
|
}
|
|
2896
2896
|
|
|
2897
|
+
/** Remove unresolved `${VAR}` env-var placeholders from the output manifest.json.
|
|
2898
|
+
*
|
|
2899
|
+
* Env interpolation is runtime-only: the loader's interpolateManifestEnv resolves
|
|
2900
|
+
* `${VAR}` against window.env, which the mnfst-run dev server fills from .env (or
|
|
2901
|
+
* a developer's inline <script>window.env={…}</script>). A prerendered static
|
|
2902
|
+
* site has no window.env, so an unresolved placeholder ships literally and any
|
|
2903
|
+
* plugin reading it errors. Such placeholders are dev-only by definition (a
|
|
2904
|
+
* production value would be hard-coded), so delete object keys and drop array
|
|
2905
|
+
* items whose string value still contains a `${VAR}` reference. We never
|
|
2906
|
+
* substitute from process.env — that would risk baking a dev secret (e.g. an
|
|
2907
|
+
* Appwrite devKey) into the public manifest.json. */
|
|
2908
|
+
function stripUnresolvedEnvFromOutputManifest(outputDir) {
|
|
2909
|
+
const manifestPath = join(outputDir, 'manifest.json');
|
|
2910
|
+
if (!existsSync(manifestPath)) return;
|
|
2911
|
+
let manifest;
|
|
2912
|
+
try { manifest = JSON.parse(readFileSync(manifestPath, 'utf8')); } catch { return; }
|
|
2913
|
+
const unresolved = (v) => typeof v === 'string' && /\$\{[^}]+\}/.test(v);
|
|
2914
|
+
let changed = false;
|
|
2915
|
+
const walk = (node) => {
|
|
2916
|
+
if (Array.isArray(node)) {
|
|
2917
|
+
for (let i = node.length - 1; i >= 0; i--) {
|
|
2918
|
+
if (unresolved(node[i])) { node.splice(i, 1); changed = true; }
|
|
2919
|
+
else if (node[i] && typeof node[i] === 'object') walk(node[i]);
|
|
2920
|
+
}
|
|
2921
|
+
} else if (node && typeof node === 'object') {
|
|
2922
|
+
for (const key of Object.keys(node)) {
|
|
2923
|
+
if (unresolved(node[key])) { delete node[key]; changed = true; }
|
|
2924
|
+
else if (node[key] && typeof node[key] === 'object') walk(node[key]);
|
|
2925
|
+
}
|
|
2926
|
+
}
|
|
2927
|
+
};
|
|
2928
|
+
walk(manifest);
|
|
2929
|
+
if (changed) writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + '\n', 'utf8');
|
|
2930
|
+
}
|
|
2931
|
+
|
|
2897
2932
|
async function runPrerender(config) {
|
|
2898
2933
|
const manifest = loadConfig(config.root);
|
|
2899
2934
|
const localesConfig = config.locales;
|
|
@@ -2971,6 +3006,12 @@ async function runPrerender(config) {
|
|
|
2971
3006
|
}
|
|
2972
3007
|
mkdirSync(outputResolved, { recursive: true });
|
|
2973
3008
|
copyProjectIntoDist(rootResolved, outputResolved);
|
|
3009
|
+
// Env placeholders (${VAR}) only resolve at runtime via window.env (populated
|
|
3010
|
+
// by the mnfst-run dev server from .env). A static prod build has no
|
|
3011
|
+
// window.env, so any ${VAR} left in the shipped manifest.json stays literal
|
|
3012
|
+
// and plugins that read it (e.g. appwrite-auth) log a console error. Strip the
|
|
3013
|
+
// unresolved placeholders from the copy.
|
|
3014
|
+
stripUnresolvedEnvFromOutputManifest(outputResolved);
|
|
2974
3015
|
// Projects that use data-tailwind get their Tailwind from Manifest (compiled
|
|
2975
3016
|
// prerender.tailwind.css below, or the runtime style engine). A leftover
|
|
2976
3017
|
// `@import "tailwindcss"` in a browser-linked stylesheet (e.g. the
|