"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolvePackage = exports.isWebTarget = exports.z = exports.isURL = exports.getSharedPkgCompiledPath = exports.isUseCssSourceMap = exports.isUseJsSourceMap = exports.awaitableGetter = exports.addTrailingSlash = exports.removeLeadingSlash = exports.createVirtualModule = void 0;
const path_1 = require("path");
const createVirtualModule = (content) => `data:text/javascript,${content}`;
exports.createVirtualModule = createVirtualModule;
const removeLeadingSlash = (s) => s.replace(/^\/+/, '');
exports.removeLeadingSlash = removeLeadingSlash;
const addTrailingSlash = (s) => s.endsWith('/') ? s : `${s}/`;
exports.addTrailingSlash = addTrailingSlash;
/**
 * Make Awaitable.
 */
const awaitableGetter = (promises) => {
    const then = (...args) => Promise.all(promises).then(...args);
    return { then, promises };
};
exports.awaitableGetter = awaitableGetter;
const isUseJsSourceMap = (config) => {
    const { disableSourceMap } = config.output || {};
    if (typeof disableSourceMap === 'boolean') {
        return !disableSourceMap;
    }
    return !disableSourceMap.js;
};
exports.isUseJsSourceMap = isUseJsSourceMap;
const isUseCssSourceMap = (config) => {
    const { disableSourceMap } = config.output || {};
    if (typeof disableSourceMap === 'boolean') {
        return !disableSourceMap;
    }
    // If the disableSourceMap.css option is not specified, we will enable it in development mode.
    // We do not need CSS Source Map in production mode.
    if (disableSourceMap.css === undefined) {
        return process.env.NODE_ENV !== 'production';
    }
    return !disableSourceMap.css;
};
exports.isUseCssSourceMap = isUseCssSourceMap;
const getSharedPkgCompiledPath = (packageName) => {
    return (0, path_1.join)(__dirname, '../compiled', packageName);
};
exports.getSharedPkgCompiledPath = getSharedPkgCompiledPath;
// Determine if the string is a URL
const isURL = (str) => str.startsWith('http') || str.startsWith('//:');
exports.isURL = isURL;
exports.z = __importStar(require("./zod"));
function isWebTarget(target) {
    return ['modern-web', 'web', 'web-worker'].some(t => (Array.isArray(target) ? target : [target]).includes(t));
}
exports.isWebTarget = isWebTarget;
function resolvePackage(loader, dirname) {
    // Vitest do not support require.resolve to source file
    return process.env.VITEST
        ? loader
        : require.resolve(loader, { paths: [dirname] });
}
exports.resolvePackage = resolvePackage;
