CommonJS

The CJS filter maps export statements to their CommonJS counterparts.

  • export def f to exports.f =
  • export async def f to exports.f = async
  • export v = to exports.v =
  • export default proc to module.exports =
  • export default async proc to module.exports = async
  • export default to module.exports =

__FILE__

Ruby’s __FILE__ constant is converted to __filename, which is available in Node.js CommonJS modules:

__FILE__
# => __filename

puts __FILE__
# => puts(__filename)

__dir__

Ruby’s __dir__ method is converted to __dirname, which is available in Node.js CommonJS modules:

__dir__
# => __dirname

puts __dir__
# => puts(__dirname)

Next: Combiner