Repository: pedroslopez/whatsapp-web.js
File: src/Client.js (JavaScript)

Code before:
 * @fires Client#message_revoke_me
 * @fires Client#message_revoke_everyone
 * @fires Client#media_uploaded
 * @fires Client#group_join
 * @fires Client#group_leave
 * @fires Client#group_update
 * @fires Client#disconnected
 * @fires Client#change_state
 */
class Client extends EventEmitter {
    constructor(options = {}) {
        super();

        this.options = Util.mergeDefault(DefaultOptions, options);

        this.id = this.options.clientId;

        // eslint-disable-next-line no-useless-escape
        const foldernameRegex = /^(?!.{256,})(?!(aux|clock\$|con|nul|prn|com[1-9]|lpt[1-9])(?:$|\.))[^ ][ \.\w-$()+=[\];#@~,&amp;']+[^\. ]$/i;
        if (this.id && !foldernameRegex.test(this.id)) throw Error('Invalid client ID. Make sure you abide by the folder naming rules of your operating system.');

        if (!this.options.useDeprecatedSessionAuth) {
            this.dataDir = this.options.puppeteer.userDataDir;
            const dirPath = path.join(process.cwd(), this.options.dataPath, this.id ? 'session-' + this.id : 'session');
            if (!this.dataDir) this.dataDir = dirPath;
            fs.mkdirSync(this.dataDir, { recursive: true })
        }

        this.pupBrowser = null;
        this.pupPage = null;

        Util.setFfmpegPath(this.options.ffmpegPath);
    }

    /**
     * Sets up events and requirements, kicks off authentication request
     */
    async initialize() {
        let [browser, page] = [null, null];

        const puppeteerOpts = {
            ...this.options.puppeteer,
            userDataDir: this.options.useDeprecatedSessionAuth ? undefined : this.dataDir
        };
        if (puppeteerOpts && puppeteerOpts.browserWSEndpoint) {
            browser = await puppeteer.connect(puppeteerOpts);
            page = await browser.newPage();
        } else {
            browser = await puppeteer.launch(puppeteerOpts);
            page = (await browser.pages())[0];
        }

Review comment (suggestion):
```suggestion
            fs.mkdirSync(this.dataDir, { recursive: true });
```

Code after:
 * @fires Client#message_revoke_me
 * @fires Client#message_revoke_everyone
 * @fires Client#media_uploaded
 * @fires Client#group_join
 * @fires Client#group_leave
 * @fires Client#group_update
 * @fires Client#disconnected
 * @fires Client#change_state
 */
class Client extends EventEmitter {
    constructor(options = {}) {
        super();

        this.options = Util.mergeDefault(DefaultOptions, options);

        this.id = this.options.clientId;

        // eslint-disable-next-line no-useless-escape
        const foldernameRegex = /^(?!.{256,})(?!(aux|clock\$|con|nul|prn|com[1-9]|lpt[1-9])(?:$|\.))[^ ][ \.\w-$()+=[\];#@~,&amp;']+[^\. ]$/i;
        if (this.id && !foldernameRegex.test(this.id)) throw Error('Invalid client ID. Make sure you abide by the folder naming rules of your operating system.');

        if (!this.options.useDeprecatedSessionAuth) {
            this.dataDir = this.options.puppeteer.userDataDir;
            const dirPath = path.join(process.cwd(), this.options.dataPath, this.id ? 'session-' + this.id : 'session');
            if (!this.dataDir) this.dataDir = dirPath;
            fs.mkdirSync(this.dataDir, { recursive: true });
        }

        this.pupBrowser = null;
        this.pupPage = null;

        Util.setFfmpegPath(this.options.ffmpegPath);
    }

    /**
     * Sets up events and requirements, kicks off authentication request
     */
    async initialize() {
        let [browser, page] = [null, null];

        const puppeteerOpts = {
            ...this.options.puppeteer,
            userDataDir: this.options.useDeprecatedSessionAuth ? undefined : this.dataDir
        };
        if (puppeteerOpts && puppeteerOpts.browserWSEndpoint) {
            browser = await puppeteer.connect(puppeteerOpts);
            page = await browser.newPage();
        } else {
            browser = await puppeteer.launch(puppeteerOpts);
            page = (await browser.pages())[0];
        }