@netlify/plugin-csp-nonce 1.0.2 → 1.0.4

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 CHANGED
@@ -1,25 +1,34 @@
1
+ /* eslint-disable no-console */
1
2
  import fs, { copyFileSync } from "fs";
2
3
 
3
- /* eslint-disable no-console */
4
+ const SITE_ID = "321a7119-6008-49a8-9d2f-e20602b1b349";
5
+
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 = netlifyConfig.build.functions || "./netlify/functions";
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
- `./src/__csp-violations.ts`,
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(`./src/__csp-nonce.ts`, `${edgeFunctionsDir}/__csp-nonce.ts`);
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-csp-nonce",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Use a nonce for the script-src and style-src directives of your Content Security Policy.",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -1,5 +1,4 @@
1
- /* eslint-disable import/extensions */
2
- /* eslint-disable import/no-unresolved */
1
+ /* eslint-disable */
3
2
  // @ts-expect-error
4
3
  import { cryptoRandomString } from "https://deno.land/x/crypto_random_string@1.0.0/mod.ts";
5
4
  // @ts-expect-error
@@ -1,8 +1,8 @@
1
+ /* eslint-disable */
1
2
  const handler = async (event) => {
2
3
  try {
3
4
  const { "csp-report": cspReport } = JSON.parse(event.body);
4
5
  if (cspReport) {
5
- // eslint-disable-next-line no-console
6
6
  console.log(JSON.stringify(cspReport));
7
7
  }
8
8
  } catch (err) {