Skip to content

Docs: Improve the “Extending generator” section in the “Writing Your Own Yeoman Generator” page #864

Description

@hb20007

Suggestion 1

The “Extending generator” section in the “Writing Your Own Yeoman Generator” page uses CommonJS:

var Generator = require('yeoman-generator');

module.exports = class extends Generator {};

However, according to the Node.js documentation,

ECMAScript modules are the official standard format to package JavaScript code for reuse.

Therefore, I suggest changing the code to:

import Generator from 'yeoman-generator';

export default class extends Generator {};

Suggestion 2

The text below the aforementioned code snippet on the “Writing Your Own Yeoman Generator” page links to the URL "https://nodejs.org/api/modules.html#modules_module_exports", which links to a fragment that does not exist anymore. I believe that the updated URL would be "https://nodejs.org/api/modules.html#modules_module_exports". However, if my suggestion of using ESM is accepted, the URL should be updated to link to the page https://nodejs.org/api/esm.html instead.

Suggestion 3

This is a minor suggestion, but it is generally better practice to name default exports. Therefore, I recommend the following modification:

var Generator = require('yeoman-generator');

module.exports = class MyGenerator extends Generator {};

Or, if we insist on CommonJS,

var Generator = require('yeoman-generator');

module.exports = class MyGenerator extends Generator {};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions