[Feature] Allow custom publish subdirectory
See original GitHub issueEDIT: 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');
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:21 (6 by maintainers)
Top GitHub Comments
Sorry, super late reply, but yes. The idea is that the
npm publish
would run inside a subdirectory, likepackages/package-name/dist
, as that would give more control over what appeared in the final published package beyond a basic.npmignore
, for example a customizedpackage.json
or README different from the parent.Perhaps a key inside
package.json
could control this behavior:@jacobwgillespie What you describe is quite possible in stock npm (which is what lerna strives to emulate when it comes to publishing): a
prepublish
script to generate the artifacts and move them in-place, and apostpublish
script to clean up the generated artifacts. I don’t think you need to runnpm publish
in a different directory.Or, even simpler, just configure
"main": "dist/index.js"
inpackage.json
? Use the files array to customize what is included in the tarball, perhaps.