Get the full path of a file inside a Meteor package


#1

I am writing a compiler for Meteor. One problem I’m facing is I need to include the compiler itself in the package (written in Node.js as compiler.js), and use “node” command to execute it:

node compiler.js

Including compiler.js as source to Package.registerBuildPlugin() doesn’t work, because first, the file is huge (5.6MB) which significantly slows down the entire execution cycle of Meteor, second, it’s a pure node.js script and has a few compatibility errors when included in Meteor apps.

My plan is to use child process to execute the node command above (similar to how it’s done in this TypeScript compiler for Meteor. So here comes my problem: is there a way to get the path of compiler.js, so that I can spawn a node executable to execute the compiler script?

( The Npm.require('fs') trick doesn’t seem to work, neither does process.env.PWD, because they both give a wrong path).

Any help would be appreciated. Thanks!