@netlify/plugin-csp-nonce 1.0.2 → 1.0.3
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/index.js +14 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
1
1
|
import fs, { copyFileSync } from "fs";
|
|
2
2
|
|
|
3
|
+
const SITE_ID = "321a7119-6008-49a8-9d2f-e20602b1b349";
|
|
4
|
+
|
|
3
5
|
/* eslint-disable no-console */
|
|
4
6
|
export const onPreBuild = async ({ inputs, netlifyConfig, utils }) => {
|
|
5
7
|
console.log(` Current working directory: ${process.cwd()}`);
|
|
6
8
|
const config = JSON.stringify(inputs, null, 2);
|
|
9
|
+
const { build } = netlifyConfig;
|
|
10
|
+
const basePath =
|
|
11
|
+
build.environment.SITE_ID === SITE_ID
|
|
12
|
+
? "./src"
|
|
13
|
+
: "./node_modules/@netlify/plugin-csp-nonce/src";
|
|
7
14
|
|
|
8
|
-
const functionsDir =
|
|
15
|
+
const functionsDir = build.functions || "./netlify/functions";
|
|
9
16
|
// make the directory in case it actually doesn't exist yet
|
|
10
17
|
await utils.run.command(`mkdir -p ${functionsDir}`);
|
|
11
18
|
console.log(` Copying function to ${functionsDir}...`);
|
|
12
19
|
copyFileSync(
|
|
13
|
-
|
|
20
|
+
`${basePath}/__csp-violations.ts`,
|
|
14
21
|
`${functionsDir}/__csp-violations.ts`
|
|
15
22
|
);
|
|
16
23
|
|
|
17
|
-
const edgeFunctionsDir =
|
|
18
|
-
netlifyConfig.build.edge_functions || "./netlify/edge-functions";
|
|
24
|
+
const edgeFunctionsDir = build.edge_functions || "./netlify/edge-functions";
|
|
19
25
|
// make the directory in case it actually doesn't exist yet
|
|
20
26
|
await utils.run.command(`mkdir -p ${edgeFunctionsDir}`);
|
|
21
27
|
console.log(` Copying edge function to ${edgeFunctionsDir}...`);
|
|
22
|
-
copyFileSync(
|
|
28
|
+
copyFileSync(
|
|
29
|
+
`${basePath}/__csp-nonce.ts`,
|
|
30
|
+
`${edgeFunctionsDir}/__csp-nonce.ts`
|
|
31
|
+
);
|
|
23
32
|
console.log(` Copying config inputs to ${edgeFunctionsDir}...`);
|
|
24
33
|
fs.writeFileSync(`${edgeFunctionsDir}/__csp-nonce-inputs.json`, config);
|
|
25
34
|
|