message: fix: simplify how relative path to compatLayer is calculated
diff: @@ -13,27 +13,32 @@ const lambdaHandlerWithCompatLayer = `
  };
  `;
  -const fixCompatLayerPath = p => {
  - // path.relative doesn't check if is a file or dir
  - // this makes sure the path is actually correct
  - // https://stackoverflow.com/questions/31023972/node-path-relative-returns-incorrect-path
  - if (p.startsWith("../compatLayer")) {
  - return p.replace(path.normalize("../"), path.normalize("./"));
  +const relativePathToCompatLayerFile = jsHandlerPath => {
  + const pathSegments = jsHandlerPath.split(path.sep);
  + let relativePathToCompatLayer = "";
  +
  + if (pathSegments.length > 2) {
  + // this is a nested page in the build directory. e.g. sls-next-build/categories/uno/dos.js
  + // compatLayer is in sls-next-build/compatLayer.js
  + const stepsUp = pathSegments.length - 2;
  +
  + for (let index = 0; index < stepsUp; index++) {
  + relativePathToCompatLayer += "../";
  + }
  } else {
  - return p.replace(path.normalize("../"), "");
  + relativePathToCompatLayer = "./";
  }
  +
  + relativePathToCompatLayer += "compatLayer";
  + return relativePathToCompatLayer;
  };
  module.exports = jsHandlerPath => {
  const basename = path.basename(jsHandlerPath, ".js");
  - const [rootDir] = jsHandlerPath.split(path.sep);
  - const pathToCompatLayer = path.resolve(path.join(rootDir, "compatLayer"));
  - let relativePathToCompatLayer = path.relative(
  - jsHandlerPath,
  - pathToCompatLayer
  - );
  - relativePathToCompatLayer = fixCompatLayerPath(relativePathToCompatLayer);
  + const relativePathToCompatLayer = relativePathToCompatLayerFile(
  + jsHandlerPath
  + );
  return lambdaHandlerWithCompatLayer
  .replace(PAGE_BUNDLE_PATH, `./${basename}.original.js`)
  