Skip to content
This repository has been archived by the owner on Feb 13, 2025. It is now read-only.

Commit

Permalink
fix: support mono repos in how we copy plugin artifacts (#36)
Browse files Browse the repository at this point in the history
* fix: support mono repos in how we copy plugin artifacts

* chore: use resolve instead

---------

Co-authored-by: Lewis Thorley <[email protected]>
  • Loading branch information
lemusthelroy and lemusthelroy authored Jul 3, 2024
1 parent a666beb commit 5a2cab2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from "fs";
import path from "path";

export const onPreBuild = async ({
config,
Expand All @@ -8,7 +9,13 @@ export const onPreBuild = async ({
}) => {
const configString = JSON.stringify(config, null, 2);
const { build } = netlifyConfig;
const { INTERNAL_FUNCTIONS_SRC, INTERNAL_EDGE_FUNCTIONS_SRC } = constants;
const { INTERNAL_FUNCTIONS_SRC, INTERNAL_EDGE_FUNCTIONS_SRC, PACKAGE_PATH } =
constants;

const pluginDir = path.resolve(
PACKAGE_PATH || "",
".netlify/plugins/node_modules/@netlify/plugin-csp-nonce/src",
);

// CSP_NONCE_DISTRIBUTION is a number from 0 to 1,
// but 0 to 100 is also supported, along with a trailing %
Expand All @@ -35,8 +42,7 @@ export const onPreBuild = async ({
console.log(
` Writing nonce edge function to ${INTERNAL_EDGE_FUNCTIONS_SRC}...`,
);
const nonceSource =
".netlify/plugins/node_modules/@netlify/plugin-csp-nonce/src/__csp-nonce.ts";
const nonceSource = `${pluginDir}/__csp-nonce.ts`;
const nonceDest = `${INTERNAL_EDGE_FUNCTIONS_SRC}/__csp-nonce.ts`;
fs.copyFileSync(nonceSource, nonceDest);

Expand All @@ -47,8 +53,7 @@ export const onPreBuild = async ({
console.log(
` Writing violations logging function to ${INTERNAL_FUNCTIONS_SRC}...`,
);
const violationsSource =
".netlify/plugins/node_modules/@netlify/plugin-csp-nonce/src/__csp-violations.ts";
const violationsSource = `${pluginDir}/__csp-violations.ts`;
const violationsDest = `${INTERNAL_FUNCTIONS_SRC}/__csp-violations.ts`;
fs.copyFileSync(violationsSource, violationsDest);
} else {
Expand Down

0 comments on commit 5a2cab2

Please sign in to comment.