PHP 7.4.33
Preview: worker.js Size: 2.25 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/metro-file-map/src/worker.js
"use strict";

const dependencyExtractor = require("./lib/dependencyExtractor");
const excludedExtensions = require("./workerExclusionList");
const { createHash } = require("crypto");
const fs = require("graceful-fs");
const path = require("path");
const PACKAGE_JSON = path.sep + "package.json";
let hasteImpl = null;
let hasteImplModulePath = null;
function getHasteImpl(requestedModulePath) {
  if (hasteImpl) {
    if (requestedModulePath !== hasteImplModulePath) {
      throw new Error("metro-file-map: hasteImplModulePath changed");
    }
    return hasteImpl;
  }
  hasteImplModulePath = requestedModulePath;
  hasteImpl = require(hasteImplModulePath);
  return hasteImpl;
}
function sha1hex(content) {
  return createHash("sha1").update(content).digest("hex");
}
async function worker(data) {
  let content;
  let dependencies;
  let id;
  let sha1;
  const { computeDependencies, computeSha1, enableHastePackages, filePath } =
    data;
  const getContent = () => {
    if (content == null) {
      content = fs.readFileSync(filePath);
    }
    return content;
  };
  if (enableHastePackages && filePath.endsWith(PACKAGE_JSON)) {
    try {
      const fileData = JSON.parse(getContent().toString());
      if (fileData.name) {
        id = fileData.name;
      }
    } catch (err) {
      throw new Error(`Cannot parse ${filePath} as JSON: ${err.message}`);
    }
  } else if (
    (data.hasteImplModulePath != null || computeDependencies) &&
    !excludedExtensions.has(filePath.substr(filePath.lastIndexOf(".")))
  ) {
    if (data.hasteImplModulePath != null) {
      id = getHasteImpl(data.hasteImplModulePath).getHasteName(filePath);
    }
    if (computeDependencies) {
      dependencies = Array.from(
        data.dependencyExtractor != null
          ? require(data.dependencyExtractor).extract(
              getContent().toString(),
              filePath,
              dependencyExtractor.extract
            )
          : dependencyExtractor.extract(getContent().toString())
      );
    }
  }
  if (computeSha1) {
    sha1 = sha1hex(getContent());
  }
  return content && data.maybeReturnContent
    ? {
        content,
        dependencies,
        id,
        sha1,
      }
    : {
        dependencies,
        id,
        sha1,
      };
}
module.exports = {
  worker,
};

Directory Contents

Dirs: 5 × Files: 15
Name Size Perms Modified Actions
cache DIR
- drwxr-xr-x 2025-03-28 11:04:32
Edit Download
crawlers DIR
- drwxr-xr-x 2025-03-28 11:04:32
Edit Download
lib DIR
- drwxr-xr-x 2025-03-28 11:04:32
Edit Download
plugins DIR
- drwxr-xr-x 2025-03-28 11:04:32
Edit Download
watchers DIR
- drwxr-xr-x 2025-03-28 11:04:32
Edit Download
285 B lrw-r--r-- 2025-03-28 11:04:32
Edit Download
1.06 KB lrw-r--r-- 2025-03-28 11:04:32
Edit Download
9.49 KB lrw-r--r-- 2025-03-28 11:04:32
Edit Download
14 B lrw-r--r-- 2025-03-28 11:04:32
Edit Download
12.11 KB lrw-r--r-- 2025-03-28 11:04:32
Edit Download
2.39 KB lrw-r--r-- 2025-03-28 11:04:32
Edit Download
25.24 KB lrw-r--r-- 2025-03-28 11:04:32
Edit Download
34.69 KB lrw-r--r-- 2025-03-28 11:04:32
Edit Download
575 B lrw-r--r-- 2025-03-28 11:04:32
Edit Download
8.49 KB lrw-r--r-- 2025-03-28 11:04:32
Edit Download
9.47 KB lrw-r--r-- 2025-03-28 11:04:32
Edit Download
2.25 KB lrw-r--r-- 2025-03-28 11:04:32
Edit Download
3.11 KB lrw-r--r-- 2025-03-28 11:04:32
Edit Download
407 B lrw-r--r-- 2025-03-28 11:04:32
Edit Download
1.30 KB lrw-r--r-- 2025-03-28 11:04:32
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).