"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Component = exports.ComponentInvalidPatternError = void 0;
const resolveBaseURLPath_1 = require("./resolveBaseURLPath");
const deriveCommonPatternBase_1 = require("./deriveCommonPatternBase");
const deriveGlobOptions_1 = require("./deriveGlobOptions");
const micromatch_1 = require("micromatch");
class ComponentInvalidPatternError extends Error {
    constructor(pattern) {
        super(`Config 'files' option glob pattern must not contain '..' or start with '/'. Received: '${pattern}'`);
        this.name = 'ComponentInvalidPatternError';
    }
}
exports.ComponentInvalidPatternError = ComponentInvalidPatternError;
class Component {
    globOptions;
    baseURLPath;
    patternBases;
    directory;
    name;
    config;
    commonPatternBase;
    constructor(name, directory, config) {
        this.name = name;
        this.directory = directory;
        this.config = config;
        this.baseURLPath = (0, resolveBaseURLPath_1.resolveBaseURLPath)(this.name, this.config.urlPath);
        this.globOptions = (0, deriveGlobOptions_1.deriveGlobOptions)(this.config.files);
        this.globOptions.source = this.globOptions.source.map((pattern) => {
            if (pattern.includes('..') || pattern.startsWith('/')) {
                throw new ComponentInvalidPatternError(pattern);
            }
            if (pattern === '.' || pattern === './') {
                return '**/*';
            }
            return pattern;
        });
        this.patternBases = this.globOptions.source.map((pattern) => (0, micromatch_1.scan)(pattern).base);
        this.commonPatternBase = (0, deriveCommonPatternBase_1.deriveCommonPatternBase)(this.patternBases);
    }
}
exports.Component = Component;
//# sourceMappingURL=Component.js.map