Skip to content

Commit

Permalink
fix: inject function only on prebuild (#111)
Browse files Browse the repository at this point in the history
* fix: inject function only on prebuild

When running the plugin with the netlify-react-ui locally or running the
circle ci tests would fail. This is because netlify-react-ui would run
the csp edge function before the page was even bundled.

* fix tests
  • Loading branch information
YujohnNattrass authored Nov 20, 2024
1 parent 9a409c1 commit 30532e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,15 @@ export const onPreBuild = async ({
console.log(` Done.`);
};

export const onPreDev = onPreBuild;
export const onPreDev = async ({ inputs, netlifyConfig, utils, constants }) => {
if (!process.env.RUN_NETLIFY_CSP_NONCE_PLUGIN_TESTS) {
return;
}

return onPreBuild({
inputs,
netlifyConfig,
utils,
constants,
});
};
1 change: 1 addition & 0 deletions tests/integration/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const serve = async ({
const proc = execa(...command(port), {
all: true,
cancelSignal: abortController.signal,
env: { RUN_NETLIFY_CSP_NONCE_PLUGIN_TESTS: "1" },
});

await new Promise<void>((resolve) => {
Expand Down

0 comments on commit 30532e3

Please sign in to comment.