-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
EDIT: I overlooked package/[name]/scripts/prepublish.js, so that's awesome. It would however be a bit difficult to customize the directory in which npm publish is run just with a prepublish script. I'll adjust this issue to recommend adding a way to customize that publish directory, since it's hard-coded in publishTaggedInDir.
It would be awesome to be able to customize the publish behavior (like the publish directory) - for my use case, I build the packages like packages/abc/src into a directory called packages/abc/dist, then copy the package.json into dist and publish from there (to have a flat module structure). I've gotten it working for now by overriding the exports of npmUtils, but in the future it would be awesome to be able to customize this step:
#!/usr/bin/env node
// Wrapper script that patches lerna with our custom publish path
import child from 'child_process';
import logger from 'lerna/lib/utils/logger';
import path from 'path';
const newPublishTaggedInDir = logger.logifyAsync('npmUtils.publishTaggedInDir', (tag, dir, callback) => {
const cmd = `cd ${dir}/dist && cp ../package.json . && npm publish --tag ${tag}`;
child.exec(cmd, (err, stdout, stderr) => {
callback(stderr || err, stdout);
});
});
// Manually require npmUtils to load it into the cache
require('lerna/lib/utils/npmUtils');
// Patch the exports
const modulePath = path.resolve(__dirname, '../node_modules/lerna/lib/utils/npmUtils.js');
require('module')._cache[modulePath].exports.publishTaggedInDir = newPublishTaggedInDir;
// Run the original binary
require('lerna/bin/lerna');