question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Allow custom publish subdirectory

See original GitHub issue

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');

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
jacobwgillespiecommented, Feb 21, 2017

Do you mean running npm publish in a nested directory within each package?

Sorry, super late reply, but yes. The idea is that the npm publish would run inside a subdirectory, like packages/package-name/dist, as that would give more control over what appeared in the final published package beyond a basic .npmignore, for example a customized package.json or README different from the parent.

Perhaps a key inside package.json could control this behavior:

{
  "lerna": {
    "publishDir": "dist"
  }
}
1reaction
evocateurcommented, Feb 28, 2017

@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 a postpublish script to clean up the generated artifacts. I don’t think you need to run npm publish in a different directory.

Or, even simpler, just configure "main": "dist/index.js" in package.json? Use the files array to customize what is included in the tarball, perhaps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom GitLab Pages domain for group with subdirectories for ...
I have setup a custom domain name for the Group (by adding a groupname.gitlab.io repository in the top of the Group). Let's say...
Read more >
Deploy a GitHub sub directory - Render community
Hello! Yes, this is possible. To start, you select the repo and branch you want as normal. The only difference is that in...
Read more >
How to deploy from a subdirectory on Github - Stack Overflow
I see MarketBasket on your master branch; it should be in your gh-pages branch to be accessible from dhirajkhanna.github.io.
Read more >
An elegant solution of deploying React app into a subdirectory
This is an alternative solution that will help you to deploy your react app into subfolder utilizing native html capabilities.
Read more >
Configuration — Eleventy
If your site lives in a different subdirectory (particularly useful with GitHub pages), use pathPrefix to specify this. It's used by the url...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found