Writing Packages article

This is the comment thread for the Writing Packages article in the Meteor Guide.

Read the article: http://guide.meteor.com/writing-packages.html

The comment thread for each article appears at the very bottom of the page. Use this thread to post:

  • Interesting articles related to the content
  • New ways to do things that aren’t covered in the Guide
  • Suggestions for Guide improvements

Or anything else related to this topic that people could find useful!

I don’t think the Guide mentioned how to publish to Atmosphere, or how to update a package you already have on Atmosphere.

We have an outline for a “Publishing Packages” article: https://github.com/meteor/guide/issues/45 but we decided to focus on other articles for the 1.3 release. Considering the 1.4 release is going to be focussed on moving towards npm and away from Atmosphere, I’m kind of doubtful we will end up getting round to writing it.

Community contributions are welcome though!

1 Like

Is there a way to import within packages without explicitly depending on a package? I.e optional import? Example is here:

In Meteor 1.3 this blows up because Slack is undefined. If I try to add:

import {
  Slack
} from 'meteor/acemtp:accounts-slack';

but that inevitably doesn’t work.

Only other way is explicitly depending on it but then that loads a bunch of packages that aren’t needed.

Yes, you can use require in this situation (http://guide.meteor.com/structure.html#using-require)

Got it. That makes sense. Still doesn’t work because now that package doesn’t export Slack - good ol’ fun. I’ll try to coordinate with the package maintainers. :slight_smile:

Hi @tmeasday My team wish to start the process of migrating our packages from Atmosphere to npm now.

How do we write npm packages that depend on Meteor apis?

Also I’m wondering if you see any need for a private npm repo like https://www.npmjs.com/package/sinopia

Thanks

I think you’ll need to wait for the core Meteor packages to
a) be rewritten to not rely on psuedo-globals (/the linker)
b) be imported into npm

There are a lot of little things to get right in doing so (let alone figuring out a system for doing so for non-core packages). We’re working on it but it’s still a little ways away.

Why do you think we’d need this?

OK…so a simple strategy like Where to publish? Atmosphere vs NPM won’t work?

I’m looking for a package sharing strategy. Since I posted that package I’ve learned more about npm link and local paths which I think negate the need for a local package repo.

1 Like

I guess that works, yeah. Kind of a pain but better than nothing in the interim, sure.

1 Like

Yeah, I think we are just in that awkward limbo where we are quite on NPM and we are afraid to use the Meteor package system since we know it will die off this year.

2 Likes

I wrote a internal Meteor package and I had issue when I created the first template: "Can’t find the module ./some_template.html'
The solution is quite easy and logic but I spend too much time to find out, so maybe you can add it on the guide:
Add the following line in the Package.onUse block in the package.js file:

api.use(‘templating’, ‘client’);

if you want to be able to import an html template with the lastest syntax:

import ‘./some_template.html’

1 Like

I used these instructions to try to setup some code in a separate folder. The npm link is clearly working, because if I just import my shared package, and have it do a console.log, it all works.

If, instead, I do:

exports.myPackageLog = function() {
  console.log("logged from my-package");
};

… as described in this article, I get an “Unexpected token” pointing to the “exports” line from “meteor run”.

I also tried “export default class …” with a corresponding import. With this version, I get “modules.js?hash=9e60446…:71833 Uncaught SyntaxError: Unexpected token export” and then multiple “es5-shim.js?hash=4187fff…:17 Uncaught TypeError: Cannot read property ‘meteorInstall’ of undefined” messages in my browser console.

I think this article has not been updated to work with the latest module export and import system, and I’m guessing that I need to add something to my package.json. I’ve experimented with dependencies on babel-runtime and meteor-node-stubs but those just generated other errors. So how do I make this work?

I just saw the isImport option for resources like scss fragment files.

  • This option is not covered in the official Meteor docs. Is it safe to use it?
  • Isn’t it a convention in Sass that files starting with an _ aren’t imported by default anyways?