Server IP : 185.86.78.101 / Your IP : 216.73.216.124 Web Server : Apache System : Linux 675867-vds-valikoshka1996.gmhost.pp.ua 5.4.0-150-generic #167-Ubuntu SMP Mon May 15 17:35:05 UTC 2023 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /www/wwwroot/mifepriston.org/node_modules/webpack-cli/lib/commands/ |
Upload File : |
"use strict"; const fs = require("fs"); const chalk = require("chalk"); const diff = require("diff"); const inquirer = require("inquirer"); const PLazy = require("p-lazy"); const Listr = require("listr"); const validate = require("webpack").validate; const WebpackOptionsValidationError = require("webpack") .WebpackOptionsValidationError; const runPrettier = require("../utils/run-prettier"); /** * * Runs migration on a given configuration using AST's and promises * to sequentially transform a configuration file. * * @param {String} currentConfigPath - Location of the configuration to be migrated * @param {String} outputConfigPath - Location to where the configuration should be written * @param {Object} options - Any additional options regarding code style of the written configuration * @returns {Promise} Runs the migration using a promise that will throw any errors during each transform * or output if the user decides to abort the migration */ module.exports = function migrate( currentConfigPath, outputConfigPath, options ) { const recastOptions = Object.assign( { quote: "single" }, options ); const tasks = new Listr([ { title: "Reading webpack config", task: ctx => new PLazy((resolve, reject) => { fs.readFile(currentConfigPath, "utf8", (err, content) => { if (err) { reject(err); } try { const jscodeshift = require("jscodeshift"); ctx.source = content; ctx.ast = jscodeshift(content); resolve(); } catch (err) { reject("Error generating AST", err); } }); }) }, { title: "Migrating config from v1 to v2", task: ctx => { const transformations = require("../migrate").transformations; return new Listr( Object.keys(transformations).map(key => { const transform = transformations[key]; return { title: key, task: _ => transform(ctx.ast, ctx.source) }; }) ); } } ]); tasks .run() .then(ctx => { const result = ctx.ast.toSource(recastOptions); const diffOutput = diff.diffLines(ctx.source, result); diffOutput.forEach(diffLine => { if (diffLine.added) { process.stdout.write(chalk.green(`+ ${diffLine.value}`)); } else if (diffLine.removed) { process.stdout.write(chalk.red(`- ${diffLine.value}`)); } }); return inquirer .prompt([ { type: "confirm", name: "confirmMigration", message: "Are you sure these changes are fine?", default: "Y" } ]) .then(answers => { if (answers["confirmMigration"]) { return inquirer.prompt([ { type: "confirm", name: "confirmValidation", message: "Do you want to validate your configuration? " + "(If you're using webpack merge, validation isn't useful)", default: "Y" } ]); } else { console.log(chalk.red("✖ Migration aborted")); } }) .then(answer => { if (!answer) return; runPrettier(outputConfigPath, result, err => { if (err) { throw err; } }); if (answer["confirmValidation"]) { const webpackOptionsValidationErrors = validate( require(outputConfigPath) ); if (webpackOptionsValidationErrors.length) { console.log( chalk.red( "\n✖ Your configuration validation wasn't successful \n" ) ); console.error( new WebpackOptionsValidationError( webpackOptionsValidationErrors ).message ); } } console.log( chalk.green( `\n ✔︎ New webpack v2 config file is at ${outputConfigPath}` ) ); }); }) .catch(err => { console.log(chalk.red("✖ ︎Migration aborted due to some errors")); console.error(err); process.exitCode = 1; }); };