"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var createContext_exports = {};
__export(createContext_exports, {
  createContextByConfig: () => createContextByConfig,
  createPublicContext: () => createPublicContext
});
module.exports = __toCommonJS(createContext_exports);
var import_fs = require("fs");
var import_path = require("path");
var import_rslog = require("rslog");
var import_fs2 = require("./fs");
function createContextByConfig(options, outputConfig, bundlerType) {
  const { cwd, target, configPath } = options;
  const rootPath = cwd;
  const srcPath = (0, import_path.join)(rootPath, "src");
  const distPath = (0, import_fs2.getAbsoluteDistPath)(cwd, outputConfig);
  const cachePath = (0, import_path.join)(rootPath, "node_modules", ".cache");
  const context = {
    entry: options.entry,
    target,
    srcPath,
    rootPath,
    distPath,
    cachePath,
    bundlerType
  };
  if (configPath && (0, import_fs.existsSync)(configPath)) {
    context.configPath = configPath;
  }
  return context;
}
function createPublicContext(context) {
  const exposedKeys = [
    "entry",
    "target",
    "srcPath",
    "rootPath",
    "distPath",
    "devServer",
    "cachePath",
    "configPath",
    "tsconfigPath",
    "bundlerType"
  ];
  return new Proxy(context, {
    get(target, prop) {
      if (exposedKeys.includes(prop)) {
        return target[prop];
      }
      return void 0;
    },
    set(target, prop) {
      import_rslog.logger.error(
        `Context is readonly, you can not assign to the "context.${prop}" prop.`
      );
      return true;
    }
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createContextByConfig,
  createPublicContext
});
