drone-plugins / drone-npm

Drone plugin for publishing packages to NPM
http://plugins.drone.io/drone-plugins/drone-npm
Apache License 2.0
20 stars 18 forks source link

How to set arbitrary npm config #24

Closed jasonkarns closed 7 years ago

jasonkarns commented 7 years ago

What is the recommended approach for setting arbitrary npm config values? Is there a dedicated key in the yaml for the plugin which can accept arbitrary config settings that will be written to the generated npmrc?

donny-dont commented 7 years ago

No there's nothing like that. I'm not sure the use case for this either. Why would you need to do what you're asking?

tboerger commented 7 years ago

It doesn't provide any functionality for additional data so far

jasonkarns commented 7 years ago

We leverage npm's package-specific configuration features (set via config in package.json) for setting default options for many of the tools invoked via npm scripts. eg, formatter/reporter for lint and test, output files for same, etc.

In this manner, the defaults set in package.json are the intended values for most developers. That way, npm run lint or npm test use the suggested defaults. (Devs are then free to override them to their liking with ~/.npmrc or .npmrc in project root.) However, we want completely different values for these options for CI. At present, we override them via the CLI in our drone.yml:

commands: 
 - npm run lint --my-project:lint:reporter=checkstyle --my-project:lint:outputFile=output/lint.xml

This is all well and good until we have multiple build sections and suddenly we're duplicating these super long, visibly distracting (and hard to mentally parse) commands. I am attempting to reduce all the redundant settings into a single location, since these settings semantically represent CI-specific config (essentially, CI environment settings). In Jenkins or similar, I would probably accomplish this by setting these in the jenkins user's ~/.npmrc. For drone, I would have preferred to set them via environment: but I don't believe they can be overridden via env vars.

Which leaves me hoping there's some other blessed approach for setting CI-specific, project settings like this. Since opening this ticket, I've added an extra build section which does a series of npm config set commands for each relevant settings.

Alternatives?

donny-dont commented 7 years ago

This plugin is used for publishing to NPM not to use for calling NPM. It sounds like you want a plugin for calling NPM. If that's the case then you can write your own that would standardize whatever it is you're looking for.

If I am mistaken please let me know. Otherwise I'm going to close this particular issue.

jasonkarns commented 7 years ago

Well, you're right that this isn't strictly necessary for publishing to npm registries. However, the question is about drone-blessed ways of setting npm config info, which is directly related to publish scripts (any scripts that need npm-config info prior to publishing for instance). I can open elsewhere, but since this is npm-specific, I figured the conversation belongs here more than in a generic non-npm-related drone repo.

donny-dont commented 7 years ago

@jasonkarns there isn't a "blessed" way to do what it is you're doing. Drone lets you do what you want so you and the other developers on your project can decide what it is that works best for them. At work we're currently iterating on our own strategy for Node projects in general. Something like that might eventually land itself in the tutorials for Node or somewhere else in the documentation.

But this particular question of yours is really what http://discourse.drone.io/ is for. I can take a stab at a response for you there if you like but as I said its really up to what you guys find helpful.