UNPKG

@nx/cypress

Version:

The Nx Plugin for Cypress contains executors and generators allowing your workspace to use the powerful Cypress integration testing capabilities.

48 lines (47 loc) 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = removeExperimentalPromptCommand; const devkit_1 = require("@nx/devkit"); const tsquery_1 = require("@phenomnomnominal/tsquery"); const migrations_1 = require("../../utils/migrations"); // Match both `experimentalPromptCommand: true` and `'experimentalPromptCommand': true` // (string-literal keys appear in JSON-style configs and after some formatters). const SELECTOR = 'PropertyAssignment:has(Identifier[name=experimentalPromptCommand]),' + 'PropertyAssignment:has(StringLiteral[value=experimentalPromptCommand])'; async function removeExperimentalPromptCommand(tree) { for await (const { cypressConfigPath } of (0, migrations_1.cypressProjectConfigs)(tree)) { if (!tree.exists(cypressConfigPath)) { continue; } const contents = tree.read(cypressConfigPath, 'utf-8'); if (!contents.includes('experimentalPromptCommand')) { continue; } const sourceFile = (0, tsquery_1.ast)(contents); // `:has()` may match nested PropertyAssignments (e.g. an outer object whose // value contains the flag). Restrict to ones whose own `name` is the flag. const propAssigns = (0, tsquery_1.query)(sourceFile, SELECTOR).filter((p) => { const name = p.name; return ( // Identifier name has `.text`; StringLiteral name does too. 'text' in name && name.text === 'experimentalPromptCommand'); }); if (propAssigns.length === 0) { continue; } let updated = contents; // Walk end-to-start so positions remain valid as we slice. for (let i = propAssigns.length - 1; i >= 0; i--) { const propAssign = propAssigns[i]; const start = propAssign.getStart(sourceFile); let end = propAssign.getEnd(); // Eat a single trailing comma if present (prettier handles whitespace). if (updated[end] === ',') { end++; } updated = updated.slice(0, start) + updated.slice(end); } tree.write(cypressConfigPath, updated); } await (0, devkit_1.formatFiles)(tree); }