<commit_before>const Generator = require('../../lib/generator');
const { cloneDeep } = require('lodash');
const crypto = require('crypto');

const oldPackages = [
  '@feathersjs/authentication-oauth1',
  '@feathersjs/authentication-oauth2',
  '@feathersjs/authentication-jwt'
];

module.exports = class UpgradeGenerator extends Generator {
  writing() {
    const config = this.fs.readJSON(this.destinationPath('config', 'default.json'));
    const dependencies = [ '@feathersjs/authentication-oauth' ];
    const pkg = cloneDeep(this.pkg);
    
    config.authentication = {
      'entity': 'user',
      'service': 'users',
      'secret': crypto.randomBytes(20).toString('base64'),
      'authStrategies': ['jwt', 'local'],
      'jwtOptions': {
        'header': { 'typ': 'access' },
        'audience': 'https://yourdomain.com',
        'issuer': 'feathers',
        'algorithm': 'HS256',
        'expiresIn': '1d'
      },
      'local': {
        'usernameField': 'email',
        'passwordField': 'password'
      }
    };

    Object.keys(this.pkg.dependencies).forEach(name => {
      const isCore = name.startsWith('@feathersjs/') && !oldPackages.includes(name);
      const isAdapter = name.startsWith('feathers-') && this.generatorPkg.dependencies[name];

      if (isCore || isAdapter) {
        dependencies.push(name);
        delete pkg.dependencies[name];
      }
    });

    this.fs.copy(
      this.destinationPath(this.libDirectory, 'authentication.js'),
      this.destinationPath(this.libDirectory, 'authentication.backup.js')
    );
    this.fs.copy(
      this.destinationPath('config', 'default.json'),
      this.destinationPath('config', 'default.backup.json')
    );

    this.fs.copy(
      this.templatePath('authentication.js'),
      this.destinationPath(this.libDirectory, 'authentication.js')
    );
    this.fs.writeJSON(this.destinationPath('config', 'default.json'), config);
    this.fs.writeJSON(this.destinationPath('package.json'), pkg);
    this._packagerInstall(dependencies, {
      save: true
    });
  }
};<commit_msg>Fix issue in v4 upgrade command (#423)<commit_after>const Generator = require('../../lib/generator');
const crypto = require('crypto');

const oldPackages = [
  '@feathersjs/authentication-oauth1',
  '@feathersjs/authentication-oauth2',
  '@feathersjs/authentication-jwt'
];

module.exports = class UpgradeGenerator extends Generator {
  writing() {
    const config = this.fs.readJSON(this.destinationPath('config', 'default.json'));
    const dependencies = [ '@feathersjs/authentication-oauth' ];
    
    config.authentication = {
      'entity': 'user',
      'service': 'users',
      'secret': crypto.randomBytes(20).toString('base64'),
      'authStrategies': ['jwt', 'local'],
      'jwtOptions': {
        'header': { 'typ': 'access' },
        'audience': 'https://yourdomain.com',
        'issuer': 'feathers',
        'algorithm': 'HS256',
        'expiresIn': '1d'
      },
      'local': {
        'usernameField': 'email',
        'passwordField': 'password'
      }
    };

    Object.keys(this.pkg.dependencies).forEach(name => {
      const isCore = name.startsWith('@feathersjs/') && !oldPackages.includes(name);
      const isAdapter = name.startsWith('feathers-') && this.generatorPkg.dependencies[name];

      if (isCore || isAdapter) {
        dependencies.push(name);
        delete this.pkg.dependencies[name];
      }
    });

    this.conflicter.force = true;
    
    this.fs.copy(
      this.destinationPath(this.libDirectory, 'authentication.js'),
      this.destinationPath(this.libDirectory, 'authentication.backup.js')
    );
    this.fs.copy(
      this.destinationPath('config', 'default.json'),
      this.destinationPath('config', 'default.backup.json')
    );

    this.fs.copy(
      this.templatePath('authentication.js'),
      this.destinationPath(this.libDirectory, 'authentication.js')
    );
    this.fs.writeJSON(this.destinationPath('config', 'default.json'), config);
    this.fs.writeJSON(this.destinationPath('package.json'), this.pkg);
    this._packagerInstall(dependencies, {
      save: true
    });
  }
};
{'fraction_non_alphanumeric': 0.16763565891472867, 'fraction_numerical': 0.005813953488372093, 'mean_word_length': 3.2479423868312756, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4092322', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1270, 'n_words': 190}