@parcel/utils 2.0.0-nightly.1285 → 2.0.0-nightly.1290

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/lib/index.js CHANGED
@@ -3440,6 +3440,7 @@ $parcel$export(module.exports, "setUnion", () => $9631335a11debdd4$export$667066
3440
3440
  $parcel$export(module.exports, "resolveConfig", () => $10671d0be444e08b$export$7eca4ea16d4c8343);
3441
3441
  $parcel$export(module.exports, "resolveConfigSync", () => $10671d0be444e08b$export$d175e66e9fcd7b75);
3442
3442
  $parcel$export(module.exports, "loadConfig", () => $10671d0be444e08b$export$c1a4367d4847eb06);
3443
+ $parcel$export(module.exports, "readConfig", () => $10671d0be444e08b$export$f5327b421858c8cd);
3443
3444
  $parcel$export(module.exports, "DefaultMap", () => $5783bf7916ff59db$export$674cd7dcb504ac5c);
3444
3445
  $parcel$export(module.exports, "DefaultWeakMap", () => $5783bf7916ff59db$export$4924f7ffab2ae440);
3445
3446
  $parcel$export(module.exports, "makeDeferredWithPromise", () => $75952a43539cb60f$export$93f345b3f0dd27e7);
@@ -36041,7 +36042,7 @@ async function $10671d0be444e08b$export$c1a4367d4847eb06(fs, filepath, filenames
36041
36042
  if (extname === "js" || extname === "cjs") {
36042
36043
  let output = {
36043
36044
  // $FlowFixMe
36044
- config: (0, (/*@__PURE__*/$parcel$interopDefault($284aeb9e515b63c0$exports)))(require(configFile)),
36045
+ config: (0, (/*@__PURE__*/$parcel$interopDefault($284aeb9e515b63c0$exports)))(module.require(configFile)),
36045
36046
  files: [
36046
36047
  {
36047
36048
  filePath: configFile
@@ -36051,52 +36052,7 @@ async function $10671d0be444e08b$export$c1a4367d4847eb06(fs, filepath, filenames
36051
36052
  $10671d0be444e08b$var$configCache.set(configFile, output);
36052
36053
  return output;
36053
36054
  }
36054
- let configContent = await fs.readFile(configFile, "utf8");
36055
- let config;
36056
- if (parse === false) config = configContent;
36057
- else {
36058
- var _opts_parser;
36059
- let parse = (_opts_parser = opts === null || opts === void 0 ? void 0 : opts.parser) !== null && _opts_parser !== void 0 ? _opts_parser : $10671d0be444e08b$var$getParser(extname);
36060
- try {
36061
- config = parse(configContent);
36062
- } catch (e) {
36063
- if (extname !== "" && extname !== "json") throw e;
36064
- let pos = {
36065
- line: e.lineNumber,
36066
- column: e.columnNumber
36067
- };
36068
- throw new (0, ($parcel$interopDefault($8C1kk$parceldiagnostic)))({
36069
- diagnostic: {
36070
- message: `Failed to parse ${(0, ($parcel$interopDefault($8C1kk$path))).basename(configFile)}`,
36071
- origin: "@parcel/utils",
36072
- codeFrames: [
36073
- {
36074
- language: "json5",
36075
- filePath: configFile,
36076
- code: configContent,
36077
- codeHighlights: [
36078
- {
36079
- start: pos,
36080
- end: pos,
36081
- message: e.message
36082
- }
36083
- ]
36084
- }
36085
- ]
36086
- }
36087
- });
36088
- }
36089
- }
36090
- let output = {
36091
- config: config,
36092
- files: [
36093
- {
36094
- filePath: configFile
36095
- }
36096
- ]
36097
- };
36098
- $10671d0be444e08b$var$configCache.set(String(parse) + configFile, output);
36099
- return output;
36055
+ return $10671d0be444e08b$export$f5327b421858c8cd(fs, configFile, opts);
36100
36056
  } catch (err) {
36101
36057
  if (err.code === "MODULE_NOT_FOUND" || err.code === "ENOENT") return null;
36102
36058
  throw err;
@@ -36108,6 +36064,64 @@ $10671d0be444e08b$export$c1a4367d4847eb06.clear = ()=>{
36108
36064
  $10671d0be444e08b$var$configCache.reset();
36109
36065
  $10671d0be444e08b$var$resolveCache.clear();
36110
36066
  };
36067
+ async function $10671d0be444e08b$export$f5327b421858c8cd(fs, configFile, opts) {
36068
+ var _opts_parse;
36069
+ let parse = (_opts_parse = opts === null || opts === void 0 ? void 0 : opts.parse) !== null && _opts_parse !== void 0 ? _opts_parse : true;
36070
+ let cachedOutput = $10671d0be444e08b$var$configCache.get(String(parse) + configFile);
36071
+ if (cachedOutput) return cachedOutput;
36072
+ try {
36073
+ let configContent = await fs.readFile(configFile, "utf8");
36074
+ let config;
36075
+ if (parse === false) config = configContent;
36076
+ else {
36077
+ let extname = (0, ($parcel$interopDefault($8C1kk$path))).extname(configFile).slice(1);
36078
+ var _opts_parser;
36079
+ let parse = (_opts_parser = opts === null || opts === void 0 ? void 0 : opts.parser) !== null && _opts_parser !== void 0 ? _opts_parser : $10671d0be444e08b$var$getParser(extname);
36080
+ try {
36081
+ config = parse(configContent);
36082
+ } catch (e) {
36083
+ if (extname !== "" && extname !== "json") throw e;
36084
+ let pos = {
36085
+ line: e.lineNumber,
36086
+ column: e.columnNumber
36087
+ };
36088
+ throw new (0, ($parcel$interopDefault($8C1kk$parceldiagnostic)))({
36089
+ diagnostic: {
36090
+ message: `Failed to parse ${(0, ($parcel$interopDefault($8C1kk$path))).basename(configFile)}`,
36091
+ origin: "@parcel/utils",
36092
+ codeFrames: [
36093
+ {
36094
+ language: "json5",
36095
+ filePath: configFile,
36096
+ code: configContent,
36097
+ codeHighlights: [
36098
+ {
36099
+ start: pos,
36100
+ end: pos,
36101
+ message: e.message
36102
+ }
36103
+ ]
36104
+ }
36105
+ ]
36106
+ }
36107
+ });
36108
+ }
36109
+ }
36110
+ let output = {
36111
+ config: config,
36112
+ files: [
36113
+ {
36114
+ filePath: configFile
36115
+ }
36116
+ ]
36117
+ };
36118
+ $10671d0be444e08b$var$configCache.set(String(parse) + configFile, output);
36119
+ return output;
36120
+ } catch (err) {
36121
+ if (err.code === "MODULE_NOT_FOUND" || err.code === "ENOENT") return null;
36122
+ throw err;
36123
+ }
36124
+ }
36111
36125
  function $10671d0be444e08b$var$getParser(extname) {
36112
36126
  switch(extname){
36113
36127
  case "toml":