@opennextjs/aws 3.9.14 → 3.9.15

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.
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Copies a file and ensures the destination is writable.
3
+ * This is necessary because copyFileSync preserves file permissions,
4
+ * and source files may be read-only (e.g., in Bazel's node_modules).
5
+ * Without this, subsequent patches would fail with EACCES errors.
6
+ */
7
+ export declare function copyFileAndMakeOwnerWritable(src: string, dest: string): void;
1
8
  export declare function isExcluded(srcPath: string): boolean;
2
9
  interface CopyTracedFilesOptions {
3
10
  buildOutputPath: string;
@@ -1,11 +1,25 @@
1
1
  import url from "node:url";
2
- import { copyFileSync, cpSync, existsSync, mkdirSync, readFileSync, readdirSync, readlinkSync, statSync, symlinkSync, writeFileSync, } from "node:fs";
2
+ import { chmodSync, copyFileSync, cpSync, existsSync, mkdirSync, readFileSync, readdirSync, readlinkSync, statSync, symlinkSync, writeFileSync, } from "node:fs";
3
3
  import path from "node:path";
4
4
  import { loadAppPathsManifest, loadBuildId, loadConfig, loadFunctionsConfigManifest, loadMiddlewareManifest, loadPagesManifest, loadPrerenderManifest, } from "../adapters/config/util.js";
5
5
  import { getCrossPlatformPathRegex } from "../utils/regex.js";
6
6
  import logger from "../logger.js";
7
7
  import { INSTRUMENTATION_TRACE_FILE, MIDDLEWARE_TRACE_FILE, } from "./constant.js";
8
8
  const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
9
+ /**
10
+ * Copies a file and ensures the destination is writable.
11
+ * This is necessary because copyFileSync preserves file permissions,
12
+ * and source files may be read-only (e.g., in Bazel's node_modules).
13
+ * Without this, subsequent patches would fail with EACCES errors.
14
+ */
15
+ export function copyFileAndMakeOwnerWritable(src, dest) {
16
+ copyFileSync(src, dest);
17
+ // Ensure the copied file is writable (add owner write permission)
18
+ const stats = statSync(dest);
19
+ if (!(stats.mode & 0o200)) {
20
+ chmodSync(dest, stats.mode | 0o200);
21
+ }
22
+ }
9
23
  //TODO: we need to figure which packages we could safely remove
10
24
  const EXCLUDED_PACKAGES = [
11
25
  "caniuse-lite",
@@ -29,7 +43,7 @@ export function isExcluded(srcPath) {
29
43
  function copyPatchFile(outputDir) {
30
44
  const patchFile = path.join(__dirname, "patch", "patchedAsyncStorage.js");
31
45
  const outputPatchFile = path.join(outputDir, "patchedAsyncStorage.cjs");
32
- copyFileSync(patchFile, outputPatchFile);
46
+ copyFileAndMakeOwnerWritable(patchFile, outputPatchFile);
33
47
  }
34
48
  export function getManifests(nextDir) {
35
49
  return {
@@ -138,13 +152,13 @@ File ${serverPath} does not exist
138
152
  // Check for instrumentation trace file
139
153
  if (existsSync(path.join(dotNextDir, INSTRUMENTATION_TRACE_FILE))) {
140
154
  // We still need to copy the nft.json file so that computeCopyFilesForPage doesn't throw
141
- copyFileSync(path.join(dotNextDir, INSTRUMENTATION_TRACE_FILE), path.join(standaloneNextDir, INSTRUMENTATION_TRACE_FILE));
155
+ copyFileAndMakeOwnerWritable(path.join(dotNextDir, INSTRUMENTATION_TRACE_FILE), path.join(standaloneNextDir, INSTRUMENTATION_TRACE_FILE));
142
156
  computeCopyFilesForPage("instrumentation");
143
157
  logger.debug("Adding instrumentation trace files");
144
158
  }
145
159
  if (existsSync(path.join(dotNextDir, MIDDLEWARE_TRACE_FILE))) {
146
160
  // We still need to copy the nft.json file so that computeCopyFilesForPage doesn't throw
147
- copyFileSync(path.join(dotNextDir, MIDDLEWARE_TRACE_FILE), path.join(standaloneNextDir, MIDDLEWARE_TRACE_FILE));
161
+ copyFileAndMakeOwnerWritable(path.join(dotNextDir, MIDDLEWARE_TRACE_FILE), path.join(standaloneNextDir, MIDDLEWARE_TRACE_FILE));
148
162
  computeCopyFilesForPage("middleware");
149
163
  logger.debug("Adding node middleware trace files");
150
164
  }
@@ -207,7 +221,7 @@ File ${serverPath} does not exist
207
221
  // where some files listed in the .nft.json might not be present in the standalone folder
208
222
  // TODO: investigate that further - is it expected?
209
223
  try {
210
- copyFileSync(from, to);
224
+ copyFileAndMakeOwnerWritable(from, to);
211
225
  }
212
226
  catch (e) {
213
227
  logger.debug("Error copying file:", e);
@@ -218,7 +232,7 @@ File ${serverPath} does not exist
218
232
  readdirSync(standaloneNextDir)
219
233
  .filter((fileOrDir) => !statSync(path.join(standaloneNextDir, fileOrDir)).isDirectory())
220
234
  .forEach((file) => {
221
- copyFileSync(path.join(standaloneNextDir, file), path.join(outputNextDir, file));
235
+ copyFileAndMakeOwnerWritable(path.join(standaloneNextDir, file), path.join(outputNextDir, file));
222
236
  tracedFiles.push(path.join(outputNextDir, file));
223
237
  });
224
238
  // We then need to copy all the files at the root of server
@@ -227,7 +241,7 @@ File ${serverPath} does not exist
227
241
  .filter((fileOrDir) => !statSync(path.join(standaloneServerDir, fileOrDir)).isDirectory())
228
242
  .filter((file) => file !== "server.js")
229
243
  .forEach((file) => {
230
- copyFileSync(path.join(standaloneServerDir, file), path.join(path.join(outputNextDir, "server"), file));
244
+ copyFileAndMakeOwnerWritable(path.join(standaloneServerDir, file), path.join(path.join(outputNextDir, "server"), file));
231
245
  tracedFiles.push(path.join(outputNextDir, "server", file));
232
246
  });
233
247
  // Copy patch file
@@ -245,7 +259,7 @@ File ${serverPath} does not exist
245
259
  mkdirSync(path.dirname(path.join(outputNextDir, filePath)), {
246
260
  recursive: true,
247
261
  });
248
- copyFileSync(path.join(standaloneNextDir, filePath), path.join(outputNextDir, filePath));
262
+ copyFileAndMakeOwnerWritable(path.join(standaloneNextDir, filePath), path.join(outputNextDir, filePath));
249
263
  }
250
264
  };
251
265
  const manifests = getManifests(standaloneNextDir);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "access": "public"
4
4
  },
5
5
  "name": "@opennextjs/aws",
6
- "version": "3.9.14",
6
+ "version": "3.9.15",
7
7
  "bin": {
8
8
  "open-next": "./dist/index.js"
9
9
  },
@@ -33,7 +33,7 @@
33
33
  "README.md"
34
34
  ],
35
35
  "dependencies": {
36
- "@ast-grep/napi": "^0.40.0",
36
+ "@ast-grep/napi": "^0.40.5",
37
37
  "@aws-sdk/client-cloudfront": "3.398.0",
38
38
  "@aws-sdk/client-dynamodb": "^3.398.0",
39
39
  "@aws-sdk/client-lambda": "^3.398.0",