Skip to content

Prevent require()ing executable-only files #789

@nfischer

Description

@nfischer

This was a point raised in #786. We can prevent require()ing files with:

if (require.main === module) {
    // everything goes here
}

This might be a good idea for files which we only intend to execute (e.g. bin/shjs).

I would also consider rewriting as:

if (require.main !== module) {
  throw new Error('Module should not be required');
}
// everything goes here

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions