Package: `api.export` doesn't export to client


#1

Hey there!
My Meteor app uses a package-only structure, and now I’m about to add a collection-fs package, that manages my files.

For the collection, I’m adding two files, one for the client, one for the server. Both define a PDFs variable, which I then export. The problem is, that I get the var on the server, but not on the client.

This is my code:

// package.js

Package.onUse(function (api) {
  var c = 'client';
  var s = 'server';

  // Core Dependencies
  api.use([
    'coffeescript'
  ]);

  // Atmosphere Dependencies
  api.use([
    'cfs:standard-packages@0.5.8',
    'cfs:filesystem@0.1.2',
    'cfs:s3@0.1.3'
  ]);

  // Collections
  api.addFiles('collections/pdfs/collection_client.coffee', c);
  api.addFiles([
    'collections/pdfs/collection_server.coffee',
    'collections/pdfs/allow_deny.coffee'
  ], s);

  // Methods
  api.addFiles('methods/pdfs/server.coffee', s);

  // Exports
  api.export('PDFs');
});


### Client (collections/pdfs/collection_client.coffee) ###

PDFs = new FS.Collection 'pdfs',
  stores: [
    new FS.Store.S3 'pdfs'
  ]

### Server (collections/pdfs/collection_server.coffee) ###

access = Meteor.settings.amazon

PDFs = new FS.Collection 'pdfs',
  stores: [
    new FS.Store.S3 'pdfs',
      bucket: 'app-development'
      accessKeyId: access.accessKeyId
      secretAccessKey: access.secretAccessKey
      region: 'eu-central-1'
  ]

I’ve not converted to JavaScript here, because I don’t know if it’s some Meteor - CoffeeScript thing causing my problem.

When I open the browser console and run PDFs, expecting an Object, I get undefined. Package['collection-fs'].PDFs however returns it correctly.

Why doesn’t my PDFs object get added to the window namespace?


#2

It seems like PDFs should be global. I’m not sure why it’s not on first glance.


#3

Are you sure PDFs is properly initialized when you are doing new FS.Collection ‘pdfs’ ?
Have you tried adding a console.log after that ?


#4

I have had a similar problem, and asked this SO question: http://stackoverflow.com/questions/30553376/meteor-package-export-sometimes-missing/30555544#30555544

The answer for me was that debugOnly was clobbering the exports- is the package exporting PDFs debugOnly ?