1
votes

How do I achieve the same functionality on the server side that the client/compatibility folder provides on the client side.

I have files with lots of old js functions that are defined as:

function functionName() {...}

I need to access these from my new server side Meteor code but because they are in different files and Meteor gives each file its own namspace they aren't in scope.

I could force each library function to be global by changing the declaration to:

functionName = function() {...}

but this is impractical as I don't own or maintain the js functions.

To prevent this wrapping on the client side you can place the js file in the folder client/compatibility. How do I prevent this wrapping server side? server/compatibility doesn't seem to work. Neither does creating a package and using api.export()

1
Are you asking "how do I make a function global on the server"? - David Weldon
How do I make all the functions in a file global.I could edit each to use the funcName = function() {...} syntax but I don't want to change the files if I can help it. - Unstableair
If you don't want to modify the file, then you'll need to create a package and expose the necessary methods. The details of that process can vary depending on the input source. What lib are your trying to wrap? - David Weldon
I did try and create a package for the library file. However api.export() requires that the function is "declared without var" but function x(){} is just shorthand for var x = function x (){} in JavaScript so it still doesn't work. This is the same issue I have with the unpackaged file. - Unstableair

1 Answers

0
votes

By default meteor wraps each js file to give it it's own namespace.

That's not accurate. If you make a file /client/lib/something.js and put this in it:

GlobalObject = {};

Then GlobalObject will be accessible throughout the entire project.

Can you edit your question to be more specific? What are you trying to achieve exactly? Can you post some code?