@sentry/wizard
Version:
Sentry wizard helping you to configure your project
52 lines • 2.21 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEntryPointFromWranglerConfig = exports.defaultEntryPoint = void 0;
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const find_wrangler_config_1 = require("./find-wrangler-config");
const ast_utils_1 = require("../../utils/ast-utils");
exports.defaultEntryPoint = 'src/index.ts';
/**
* Reads the main entry point from the wrangler config file
* Returns undefined if no config exists or if main field is not specified
*/
function getEntryPointFromWranglerConfig() {
const configFile = (0, find_wrangler_config_1.findWranglerConfig)();
if (!configFile) {
return undefined;
}
const configPath = node_path_1.default.join(process.cwd(), configFile);
const configContent = node_fs_1.default.readFileSync(configPath, 'utf-8');
const extname = node_path_1.default.extname(configFile);
switch (extname) {
case '.toml': {
const mainMatch = configContent.match(/^main\s*=\s*["'](.+)["']/m);
return mainMatch ? mainMatch[1] : undefined;
}
case '.json':
case '.jsonc':
try {
const { jsonObject } = (0, ast_utils_1.parseJsonC)(configContent);
if (!jsonObject) {
return undefined;
}
const mainProperty = (0, ast_utils_1.getObjectProperty)(jsonObject, 'main');
if ((mainProperty?.value.type === 'StringLiteral' ||
mainProperty?.value.type === 'Literal') &&
typeof mainProperty.value.value === 'string') {
return mainProperty.value.value;
}
return undefined;
}
catch {
return undefined;
}
default:
return undefined;
}
}
exports.getEntryPointFromWranglerConfig = getEntryPointFromWranglerConfig;
//# sourceMappingURL=get-entry-point-from-wrangler-config.js.map