123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143 |
- 'use strict';
- Object.defineProperty(exports, '__esModule', { value: true });
- var util = require('util');
- var path = require('path');
- var Ajv = require('ajv');
- var globals = require('globals');
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
- var util__default = _interopDefaultLegacy(util);
- var path__default = _interopDefaultLegacy(path);
- var Ajv__default = _interopDefaultLegacy(Ajv);
- var globals__default = _interopDefaultLegacy(globals);
- const RULE_SEVERITY_STRINGS = ["off", "warn", "error"],
- RULE_SEVERITY = RULE_SEVERITY_STRINGS.reduce((map, value, index) => {
- map[value] = index;
- return map;
- }, {}),
- VALID_SEVERITIES = [0, 1, 2, "off", "warn", "error"];
- function getRuleSeverity(ruleConfig) {
- const severityValue = Array.isArray(ruleConfig) ? ruleConfig[0] : ruleConfig;
- if (severityValue === 0 || severityValue === 1 || severityValue === 2) {
- return severityValue;
- }
- if (typeof severityValue === "string") {
- return RULE_SEVERITY[severityValue.toLowerCase()] || 0;
- }
- return 0;
- }
- function normalizeToStrings(config) {
- if (config.rules) {
- Object.keys(config.rules).forEach(ruleId => {
- const ruleConfig = config.rules[ruleId];
- if (typeof ruleConfig === "number") {
- config.rules[ruleId] = RULE_SEVERITY_STRINGS[ruleConfig] || RULE_SEVERITY_STRINGS[0];
- } else if (Array.isArray(ruleConfig) && typeof ruleConfig[0] === "number") {
- ruleConfig[0] = RULE_SEVERITY_STRINGS[ruleConfig[0]] || RULE_SEVERITY_STRINGS[0];
- }
- });
- }
- }
- function isErrorSeverity(ruleConfig) {
- return getRuleSeverity(ruleConfig) === 2;
- }
- function isValidSeverity(ruleConfig) {
- let severity = Array.isArray(ruleConfig) ? ruleConfig[0] : ruleConfig;
- if (typeof severity === "string") {
- severity = severity.toLowerCase();
- }
- return VALID_SEVERITIES.indexOf(severity) !== -1;
- }
- function isEverySeverityValid(config) {
- return Object.keys(config).every(ruleId => isValidSeverity(config[ruleId]));
- }
- function normalizeConfigGlobal(configuredValue) {
- switch (configuredValue) {
- case "off":
- return "off";
- case true:
- case "true":
- case "writeable":
- case "writable":
- return "writable";
- case null:
- case false:
- case "false":
- case "readable":
- case "readonly":
- return "readonly";
- default:
- throw new Error(`'${configuredValue}' is not a valid configuration for a global (use 'readonly', 'writable', or 'off')`);
- }
- }
- var ConfigOps = {
- __proto__: null,
- getRuleSeverity: getRuleSeverity,
- normalizeToStrings: normalizeToStrings,
- isErrorSeverity: isErrorSeverity,
- isValidSeverity: isValidSeverity,
- isEverySeverityValid: isEverySeverityValid,
- normalizeConfigGlobal: normalizeConfigGlobal
- };
- const deprecationWarningMessages = {
- ESLINT_LEGACY_ECMAFEATURES:
- "The 'ecmaFeatures' config file property is deprecated and has no effect.",
- ESLINT_PERSONAL_CONFIG_LOAD:
- "'~/.eslintrc.*' config files have been deprecated. " +
- "Please use a config file per project or the '--config' option.",
- ESLINT_PERSONAL_CONFIG_SUPPRESS:
- "'~/.eslintrc.*' config files have been deprecated. " +
- "Please remove it or add 'root:true' to the config files in your " +
- "projects in order to avoid loading '~/.eslintrc.*' accidentally."
- };
- const sourceFileErrorCache = new Set();
- function emitDeprecationWarning(source, errorCode) {
- const cacheKey = JSON.stringify({ source, errorCode });
- if (sourceFileErrorCache.has(cacheKey)) {
- return;
- }
- sourceFileErrorCache.add(cacheKey);
- const rel = path__default["default"].relative(process.cwd(), source);
- const message = deprecationWarningMessages[errorCode];
- process.emitWarning(
- `${message} (found in "${rel}")`,
- "DeprecationWarning",
- errorCode
- );
- }
- const metaSchema = {
- id: "http://json-schema.org/draft-04/schema#",
- $schema: "http://json-schema.org/draft-04/schema#",
- description: "Core schema meta-schema",
- definitions: {
- schemaArray: {
- type: "array",
- minItems: 1,
- items: { $ref: "#" }
- },
- positiveInteger: {
- type: "integer",
- minimum: 0
- },
- positiveIntegerDefault0: {
- allOf: [{ $ref: "#/definitions/positiveInteger" }, { default: 0 }]
- },
- simpleTypes: {
- enum: ["array", "boolean", "integer", "null", "number", "object", "string"]
- },
- stringArray: {
- type: "array",
- items: { type: "string" },
- minItems: 1,
- uniqueItems: true
- }
- },
- type: "object",
- properties: {
- id: {
- type: "string"
- },
- $schema: {
- type: "string"
- },
- title: {
- type: "string"
- },
- description: {
- type: "string"
- },
- default: { },
- multipleOf: {
- type: "number",
- minimum: 0,
- exclusiveMinimum: true
- },
- maximum: {
- type: "number"
- },
- exclusiveMaximum: {
- type: "boolean",
- default: false
- },
- minimum: {
- type: "number"
- },
- exclusiveMinimum: {
- type: "boolean",
- default: false
- },
- maxLength: { $ref: "#/definitions/positiveInteger" },
- minLength: { $ref: "#/definitions/positiveIntegerDefault0" },
- pattern: {
- type: "string",
- format: "regex"
- },
- additionalItems: {
- anyOf: [
- { type: "boolean" },
- { $ref: "#" }
- ],
- default: { }
- },
- items: {
- anyOf: [
- { $ref: "#" },
- { $ref: "#/definitions/schemaArray" }
- ],
- default: { }
- },
- maxItems: { $ref: "#/definitions/positiveInteger" },
- minItems: { $ref: "#/definitions/positiveIntegerDefault0" },
- uniqueItems: {
- type: "boolean",
- default: false
- },
- maxProperties: { $ref: "#/definitions/positiveInteger" },
- minProperties: { $ref: "#/definitions/positiveIntegerDefault0" },
- required: { $ref: "#/definitions/stringArray" },
- additionalProperties: {
- anyOf: [
- { type: "boolean" },
- { $ref: "#" }
- ],
- default: { }
- },
- definitions: {
- type: "object",
- additionalProperties: { $ref: "#" },
- default: { }
- },
- properties: {
- type: "object",
- additionalProperties: { $ref: "#" },
- default: { }
- },
- patternProperties: {
- type: "object",
- additionalProperties: { $ref: "#" },
- default: { }
- },
- dependencies: {
- type: "object",
- additionalProperties: {
- anyOf: [
- { $ref: "#" },
- { $ref: "#/definitions/stringArray" }
- ]
- }
- },
- enum: {
- type: "array",
- minItems: 1,
- uniqueItems: true
- },
- type: {
- anyOf: [
- { $ref: "#/definitions/simpleTypes" },
- {
- type: "array",
- items: { $ref: "#/definitions/simpleTypes" },
- minItems: 1,
- uniqueItems: true
- }
- ]
- },
- format: { type: "string" },
- allOf: { $ref: "#/definitions/schemaArray" },
- anyOf: { $ref: "#/definitions/schemaArray" },
- oneOf: { $ref: "#/definitions/schemaArray" },
- not: { $ref: "#" }
- },
- dependencies: {
- exclusiveMaximum: ["maximum"],
- exclusiveMinimum: ["minimum"]
- },
- default: { }
- };
- var ajvOrig = (additionalOptions = {}) => {
- const ajv = new Ajv__default["default"]({
- meta: false,
- useDefaults: true,
- validateSchema: false,
- missingRefs: "ignore",
- verbose: true,
- schemaId: "auto",
- ...additionalOptions
- });
- ajv.addMetaSchema(metaSchema);
-
- ajv._opts.defaultMeta = metaSchema.id;
- return ajv;
- };
- const baseConfigProperties = {
- $schema: { type: "string" },
- env: { type: "object" },
- extends: { $ref: "#/definitions/stringOrStrings" },
- globals: { type: "object" },
- overrides: {
- type: "array",
- items: { $ref: "#/definitions/overrideConfig" },
- additionalItems: false
- },
- parser: { type: ["string", "null"] },
- parserOptions: { type: "object" },
- plugins: { type: "array" },
- processor: { type: "string" },
- rules: { type: "object" },
- settings: { type: "object" },
- noInlineConfig: { type: "boolean" },
- reportUnusedDisableDirectives: { type: "boolean" },
- ecmaFeatures: { type: "object" }
- };
- const configSchema = {
- definitions: {
- stringOrStrings: {
- oneOf: [
- { type: "string" },
- {
- type: "array",
- items: { type: "string" },
- additionalItems: false
- }
- ]
- },
- stringOrStringsRequired: {
- oneOf: [
- { type: "string" },
- {
- type: "array",
- items: { type: "string" },
- additionalItems: false,
- minItems: 1
- }
- ]
- },
-
- objectConfig: {
- type: "object",
- properties: {
- root: { type: "boolean" },
- ignorePatterns: { $ref: "#/definitions/stringOrStrings" },
- ...baseConfigProperties
- },
- additionalProperties: false
- },
-
- overrideConfig: {
- type: "object",
- properties: {
- excludedFiles: { $ref: "#/definitions/stringOrStrings" },
- files: { $ref: "#/definitions/stringOrStringsRequired" },
- ...baseConfigProperties
- },
- required: ["files"],
- additionalProperties: false
- }
- },
- $ref: "#/definitions/objectConfig"
- };
- function getDiff(current, prev) {
- const retv = {};
- for (const [key, value] of Object.entries(current)) {
- if (!Object.hasOwnProperty.call(prev, key)) {
- retv[key] = value;
- }
- }
- return retv;
- }
- const newGlobals2015 = getDiff(globals__default["default"].es2015, globals__default["default"].es5);
- const newGlobals2017 = {
- Atomics: false,
- SharedArrayBuffer: false
- };
- const newGlobals2020 = {
- BigInt: false,
- BigInt64Array: false,
- BigUint64Array: false,
- globalThis: false
- };
- const newGlobals2021 = {
- AggregateError: false,
- FinalizationRegistry: false,
- WeakRef: false
- };
- var environments = new Map(Object.entries({
-
- builtin: {
- globals: globals__default["default"].es5
- },
- es6: {
- globals: newGlobals2015,
- parserOptions: {
- ecmaVersion: 6
- }
- },
- es2015: {
- globals: newGlobals2015,
- parserOptions: {
- ecmaVersion: 6
- }
- },
- es2016: {
- globals: newGlobals2015,
- parserOptions: {
- ecmaVersion: 7
- }
- },
- es2017: {
- globals: { ...newGlobals2015, ...newGlobals2017 },
- parserOptions: {
- ecmaVersion: 8
- }
- },
- es2018: {
- globals: { ...newGlobals2015, ...newGlobals2017 },
- parserOptions: {
- ecmaVersion: 9
- }
- },
- es2019: {
- globals: { ...newGlobals2015, ...newGlobals2017 },
- parserOptions: {
- ecmaVersion: 10
- }
- },
- es2020: {
- globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020 },
- parserOptions: {
- ecmaVersion: 11
- }
- },
- es2021: {
- globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020, ...newGlobals2021 },
- parserOptions: {
- ecmaVersion: 12
- }
- },
- es2022: {
- globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020, ...newGlobals2021 },
- parserOptions: {
- ecmaVersion: 13
- }
- },
- es2023: {
- globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020, ...newGlobals2021 },
- parserOptions: {
- ecmaVersion: 14
- }
- },
- es2024: {
- globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020, ...newGlobals2021 },
- parserOptions: {
- ecmaVersion: 15
- }
- },
-
- browser: {
- globals: globals__default["default"].browser
- },
- node: {
- globals: globals__default["default"].node,
- parserOptions: {
- ecmaFeatures: {
- globalReturn: true
- }
- }
- },
- "shared-node-browser": {
- globals: globals__default["default"]["shared-node-browser"]
- },
- worker: {
- globals: globals__default["default"].worker
- },
- serviceworker: {
- globals: globals__default["default"].serviceworker
- },
-
- commonjs: {
- globals: globals__default["default"].commonjs,
- parserOptions: {
- ecmaFeatures: {
- globalReturn: true
- }
- }
- },
- amd: {
- globals: globals__default["default"].amd
- },
- mocha: {
- globals: globals__default["default"].mocha
- },
- jasmine: {
- globals: globals__default["default"].jasmine
- },
- jest: {
- globals: globals__default["default"].jest
- },
- phantomjs: {
- globals: globals__default["default"].phantomjs
- },
- jquery: {
- globals: globals__default["default"].jquery
- },
- qunit: {
- globals: globals__default["default"].qunit
- },
- prototypejs: {
- globals: globals__default["default"].prototypejs
- },
- shelljs: {
- globals: globals__default["default"].shelljs
- },
- meteor: {
- globals: globals__default["default"].meteor
- },
- mongo: {
- globals: globals__default["default"].mongo
- },
- protractor: {
- globals: globals__default["default"].protractor
- },
- applescript: {
- globals: globals__default["default"].applescript
- },
- nashorn: {
- globals: globals__default["default"].nashorn
- },
- atomtest: {
- globals: globals__default["default"].atomtest
- },
- embertest: {
- globals: globals__default["default"].embertest
- },
- webextensions: {
- globals: globals__default["default"].webextensions
- },
- greasemonkey: {
- globals: globals__default["default"].greasemonkey
- }
- }));
- const ajv = ajvOrig();
- const ruleValidators = new WeakMap();
- const noop = Function.prototype;
- let validateSchema;
- const severityMap = {
- error: 2,
- warn: 1,
- off: 0
- };
- const validated = new WeakSet();
- const noOptionsSchema = Object.freeze({
- type: "array",
- minItems: 0,
- maxItems: 0
- });
- class ConfigValidator {
- constructor({ builtInRules = new Map() } = {}) {
- this.builtInRules = builtInRules;
- }
-
- getRuleOptionsSchema(rule) {
- if (!rule) {
- return null;
- }
- if (!rule.meta) {
- return { ...noOptionsSchema };
- }
- const schema = rule.meta.schema;
- if (typeof schema === "undefined") {
- return { ...noOptionsSchema };
- }
-
- if (schema === false) {
- return null;
- }
- if (typeof schema !== "object" || schema === null) {
- throw new TypeError("Rule's `meta.schema` must be an array or object");
- }
-
- if (Array.isArray(schema)) {
- if (schema.length) {
- return {
- type: "array",
- items: schema,
- minItems: 0,
- maxItems: schema.length
- };
- }
-
- return { ...noOptionsSchema };
- }
-
- return schema;
- }
-
- validateRuleSeverity(options) {
- const severity = Array.isArray(options) ? options[0] : options;
- const normSeverity = typeof severity === "string" ? severityMap[severity.toLowerCase()] : severity;
- if (normSeverity === 0 || normSeverity === 1 || normSeverity === 2) {
- return normSeverity;
- }
- throw new Error(`\tSeverity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '${util__default["default"].inspect(severity).replace(/'/gu, "\"").replace(/\n/gu, "")}').\n`);
- }
-
- validateRuleSchema(rule, localOptions) {
- if (!ruleValidators.has(rule)) {
- try {
- const schema = this.getRuleOptionsSchema(rule);
- if (schema) {
- ruleValidators.set(rule, ajv.compile(schema));
- }
- } catch (err) {
- const errorWithCode = new Error(err.message, { cause: err });
- errorWithCode.code = "ESLINT_INVALID_RULE_OPTIONS_SCHEMA";
- throw errorWithCode;
- }
- }
- const validateRule = ruleValidators.get(rule);
- if (validateRule) {
- validateRule(localOptions);
- if (validateRule.errors) {
- throw new Error(validateRule.errors.map(
- error => `\tValue ${JSON.stringify(error.data)} ${error.message}.\n`
- ).join(""));
- }
- }
- }
-
- validateRuleOptions(rule, ruleId, options, source = null) {
- try {
- const severity = this.validateRuleSeverity(options);
- if (severity !== 0) {
- this.validateRuleSchema(rule, Array.isArray(options) ? options.slice(1) : []);
- }
- } catch (err) {
- let enhancedMessage = err.code === "ESLINT_INVALID_RULE_OPTIONS_SCHEMA"
- ? `Error while processing options validation schema of rule '${ruleId}': ${err.message}`
- : `Configuration for rule "${ruleId}" is invalid:\n${err.message}`;
- if (typeof source === "string") {
- enhancedMessage = `${source}:\n\t${enhancedMessage}`;
- }
- const enhancedError = new Error(enhancedMessage, { cause: err });
- if (err.code) {
- enhancedError.code = err.code;
- }
- throw enhancedError;
- }
- }
-
- validateEnvironment(
- environment,
- source,
- getAdditionalEnv = noop
- ) {
-
- if (!environment) {
- return;
- }
- Object.keys(environment).forEach(id => {
- const env = getAdditionalEnv(id) || environments.get(id) || null;
- if (!env) {
- const message = `${source}:\n\tEnvironment key "${id}" is unknown\n`;
- throw new Error(message);
- }
- });
- }
-
- validateRules(
- rulesConfig,
- source,
- getAdditionalRule = noop
- ) {
- if (!rulesConfig) {
- return;
- }
- Object.keys(rulesConfig).forEach(id => {
- const rule = getAdditionalRule(id) || this.builtInRules.get(id) || null;
- this.validateRuleOptions(rule, id, rulesConfig[id], source);
- });
- }
-
- validateGlobals(globalsConfig, source = null) {
- if (!globalsConfig) {
- return;
- }
- Object.entries(globalsConfig)
- .forEach(([configuredGlobal, configuredValue]) => {
- try {
- normalizeConfigGlobal(configuredValue);
- } catch (err) {
- throw new Error(`ESLint configuration of global '${configuredGlobal}' in ${source} is invalid:\n${err.message}`);
- }
- });
- }
-
- validateProcessor(processorName, source, getProcessor) {
- if (processorName && !getProcessor(processorName)) {
- throw new Error(`ESLint configuration of processor in '${source}' is invalid: '${processorName}' was not found.`);
- }
- }
-
- formatErrors(errors) {
- return errors.map(error => {
- if (error.keyword === "additionalProperties") {
- const formattedPropertyPath = error.dataPath.length ? `${error.dataPath.slice(1)}.${error.params.additionalProperty}` : error.params.additionalProperty;
- return `Unexpected top-level property "${formattedPropertyPath}"`;
- }
- if (error.keyword === "type") {
- const formattedField = error.dataPath.slice(1);
- const formattedExpectedType = Array.isArray(error.schema) ? error.schema.join("/") : error.schema;
- const formattedValue = JSON.stringify(error.data);
- return `Property "${formattedField}" is the wrong type (expected ${formattedExpectedType} but got \`${formattedValue}\`)`;
- }
- const field = error.dataPath[0] === "." ? error.dataPath.slice(1) : error.dataPath;
- return `"${field}" ${error.message}. Value: ${JSON.stringify(error.data)}`;
- }).map(message => `\t- ${message}.\n`).join("");
- }
-
- validateConfigSchema(config, source = null) {
- validateSchema = validateSchema || ajv.compile(configSchema);
- if (!validateSchema(config)) {
- throw new Error(`ESLint configuration in ${source} is invalid:\n${this.formatErrors(validateSchema.errors)}`);
- }
- if (Object.hasOwnProperty.call(config, "ecmaFeatures")) {
- emitDeprecationWarning(source, "ESLINT_LEGACY_ECMAFEATURES");
- }
- }
-
- validate(config, source, getAdditionalRule, getAdditionalEnv) {
- this.validateConfigSchema(config, source);
- this.validateRules(config.rules, source, getAdditionalRule);
- this.validateEnvironment(config.env, source, getAdditionalEnv);
- this.validateGlobals(config.globals, source);
- for (const override of config.overrides || []) {
- this.validateRules(override.rules, source, getAdditionalRule);
- this.validateEnvironment(override.env, source, getAdditionalEnv);
- this.validateGlobals(config.globals, source);
- }
- }
-
- validateConfigArray(configArray) {
- const getPluginEnv = Map.prototype.get.bind(configArray.pluginEnvironments);
- const getPluginProcessor = Map.prototype.get.bind(configArray.pluginProcessors);
- const getPluginRule = Map.prototype.get.bind(configArray.pluginRules);
-
- for (const element of configArray) {
- if (validated.has(element)) {
- continue;
- }
- validated.add(element);
- this.validateEnvironment(element.env, element.name, getPluginEnv);
- this.validateGlobals(element.globals, element.name);
- this.validateProcessor(element.processor, element.name, getPluginProcessor);
- this.validateRules(element.rules, element.name, getPluginRule);
- }
- }
- }
- const NAMESPACE_REGEX = /^@.*\//iu;
- function normalizePackageName(name, prefix) {
- let normalizedName = name;
-
- if (normalizedName.includes("\\")) {
- normalizedName = normalizedName.replace(/\\/gu, "/");
- }
- if (normalizedName.charAt(0) === "@") {
-
- const scopedPackageShortcutRegex = new RegExp(`^(@[^/]+)(?:/(?:${prefix})?)?$`, "u"),
- scopedPackageNameRegex = new RegExp(`^${prefix}(-|$)`, "u");
- if (scopedPackageShortcutRegex.test(normalizedName)) {
- normalizedName = normalizedName.replace(scopedPackageShortcutRegex, `$1/${prefix}`);
- } else if (!scopedPackageNameRegex.test(normalizedName.split("/")[1])) {
-
- normalizedName = normalizedName.replace(/^@([^/]+)\/(.*)$/u, `@$1/${prefix}-$2`);
- }
- } else if (!normalizedName.startsWith(`${prefix}-`)) {
- normalizedName = `${prefix}-${normalizedName}`;
- }
- return normalizedName;
- }
- function getShorthandName(fullname, prefix) {
- if (fullname[0] === "@") {
- let matchResult = new RegExp(`^(@[^/]+)/${prefix}$`, "u").exec(fullname);
- if (matchResult) {
- return matchResult[1];
- }
- matchResult = new RegExp(`^(@[^/]+)/${prefix}-(.+)$`, "u").exec(fullname);
- if (matchResult) {
- return `${matchResult[1]}/${matchResult[2]}`;
- }
- } else if (fullname.startsWith(`${prefix}-`)) {
- return fullname.slice(prefix.length + 1);
- }
- return fullname;
- }
- function getNamespaceFromTerm(term) {
- const match = term.match(NAMESPACE_REGEX);
- return match ? match[0] : "";
- }
- var naming = {
- __proto__: null,
- normalizePackageName: normalizePackageName,
- getShorthandName: getShorthandName,
- getNamespaceFromTerm: getNamespaceFromTerm
- };
- const Legacy = {
- environments,
-
- ConfigOps,
- ConfigValidator,
- naming
- };
- exports.Legacy = Legacy;
|