Giter Site home page Giter Site logo

debashish2014 / local-package-publisher Goto Github PK

View Code? Open in Web Editor NEW
24.0 2.0 2.0 55 KB

A utility app for publishing your npm packages locally for testing

License: MIT License

JavaScript 100.00%
npm package publish publisher-utils local nodejs node-js testing test publisher npm-publish

local-package-publisher's Introduction

local-package-publisher

A utility app for publishing your npm packages locally for testing, which works !!

npm Package License

About

You have created this awesome npm package and you want to test it locally, before publishing to NPM repository. What are the options you have?

Well, below are some of the possible options, but each of them has some caveat, and as a result, it found out need for this project.

  1. Symbolic Linking :

    At the root directory of your npm package under test, run the command npm link. It would create a symbolic link to the entire folder to the global namespace. So, a folder will be created in the directory where global packages are stored with the name that is same as that of the value of name property in package.json.

    To test/consume this package, at the root of the target project, run npm link [name], where [name] is the value of name property in package.json which is being consumed.

    Cons: Every file in the directory gets linked, which can create problems and can interfere with the build process if the linked package is consumed in another project.

  2. Local NPM Repository :

    You can publish the package under test to a local npm repository hosted using these awesome projects like CNPM,Sinopia, Verdaccio, local-npm etc.

    Cons: You will need to change the registry which npm is pointing to by running npm set registry http://localhost:[port].

    For most of us this might not be a feasible option due to several reasons, but if it does then it is indeed an option worth considering.

  3. Manual Process :

    You can first run npm pack command at the root directory of the project under test. It will generate a tar file with the name [package-name]-[version].tgz.

    Then, unzip the tar file content to a directory, separate from your project.

    Go, to this new directory where the tar contents have been extracted, and run npm link from the directory root. Rest of the steps are same as option 1.

    Cons: The process is a bit cumbersome and involves a lot of steps.

I have found out the third option i.e. Manual Process to be most elegant, even though it requires more steps since it relies on npm pack and it ensures that the content it packs will be same as that of when it will be actually published to NPM repository.

This project is an effort to automate this manual process.

Installation

npm install --save-dev local-package-publisher

To install the package locally to the project

or

npm install -g local-package-publisher

To install the package globally

Usage

Say, you have created a project with the name my-awesome-new-package

To publish this package, go to root directory of the project and run below command:

local-package-publisher -p

or

local-package-publisher --publish

Once you run this command it will give you below success message.

my-awesome-new-package package published successfully to global

This command will publish the package globally. It will also create a directory .local-pack with a setings.json file in it, in your project. Please do not delete it.

You can safely add below line to .gitignore as well.

.local-pack

Thats it !! Now whenever you do any modification in the project and you want to publish the changes, just run the local-package-publisher -p command again.

Now, to consume this published package, just go the root directory of the project where you want to consume it, and run below command. It needs to be done only once.

npm link my-awesome-new-package

Note: No need to run above command again and again.

Once, you are done and you want to remove the published package from global, run below command in the root directory of my-awesome-new-package project:

local-package-publisher -u

or

local-package-publisher --unpublish

Once you run this command it will give you below message.

my-awesome-new-package package has been removed from global

Credit

local-package-publisher wouldn't be possible without using the modules from the following authors:

License

Licensed under MIT

Copyright (c) 2019-2020 Debashish Pal

local-package-publisher's People

Contributors

debashish-emtec avatar debashish2014 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

local-package-publisher's Issues

Breaks with `npx`

I tried publishing 2 packages with npx local-package-publisher -p and the second time there was problem accessing the cache.

I then tried to install the package globally but the cache is still broken and now I don't know how to fix it.

image

Publish fails on Windows

When I try to publish on Windows, I get no such file or directory errors. I'm guessing this is a path issue, where somehow it's not recognizing the OS and not converting /'s to 's or something?

The specific error is:

C:\Users\{userName}\AppData\Roaming\npm/node: line 8: C:\Users\{userName}\AppData\Roaming\npm/node_modules/node/bin/node: No such file or directory

Windows 11 Pro; version 10.0.22000 Build 22000

Is there a workaround for this?

Add possibility to specifiy folder to publish

Hey,

this is a really useful library, thanks for sharing it!

However, for my current problem I'm trying to locally publish an Angular library, so the contents to be published lie under dist/. I think the easiest would be, to have another CLI option to specify the path to be published. Do you think this is possible to be added?

Thanks in advance
Alex

Temp folder issue (Mac Os X).

Hi guys.
Following the documentation, I tried to globally publish a package name super running local-package-publisher --publish in the project root directory.
I'm on Mac Os X (with node version v15.14.0) and get an error like the following:

super package published successfully to global
To consume this package, run npm link super in target project
node:internal/bootstrap/switches/does_own_process_state:112
  rawMethods.chdir(directory);
             ^

Error: ENOENT: no such file or directory, chdir '/Volumes/x/dev/super' -> '/var/folders/vf/9bptzv4d4cxfym7g6bt9yyrw0000gn/T/tmp-60750SDC706yNP5V'
    at process.wrappedChdir (node:internal/bootstrap/switches/does_own_process_state:112:14)
    at process.chdir (/Users/me/.nvm/versions/node/v15.14.0/lib/node_modules/local-package-publisher/node_modules/graceful-fs/polyfills.js:22:11)
    at /Users/me/.nvm/versions/node/v15.14.0/lib/node_modules/local-package-publisher/index.js:138:17
    at new Promise (<anonymous>)
    at linkDirGlobal (/Users/me/.nvm/versions/node/v15.14.0/lib/node_modules/local-package-publisher/index.js:129:12)
    at /Users/me/.nvm/versions/node/v15.14.0/lib/node_modules/local-package-publisher/index.js:324:13 {
  errno: -2,
  code: 'ENOENT',
  syscall: 'chdir',
  path: '/Volumes/x/dev/super',
  dest: '/var/folders/vf/9bptzv4d4cxfym7g6bt9yyrw0000gn/T/tmp-60750SDC706yNP5V'
}

The .local-pack folder is created and contains the settings.json file with the following content:

{"TempPath":"/var/folders/vf/9bptzv4d4cxfym7g6bt9yyrw0000gn/T/tmp-60750SDC706yNP5V"}

It's like there is a problem with the temp folder, it doesn't seem to be created.

Any idea? Thanks!

Hangs on publish

When I try to use this tool it hangs when I try to publish my package. I left it running for 3 hours last night.

CleanShot 2023-08-28 at 06 35 43

It creates the <package>-<version>.tgz file in the root folder of the package.

Unfortunately, it never builds the .local-pack folder and it does not seem to create the npm link for my project to use, because in my project that consumes it, I use npm link <package> and then npm install <package> and it is still pulling from the externally published registry with the previous version.

Installs all the dev dependencies when publishing

Actual behavior:
With package.json looking similiar to this:

  "name": "@mynamespace/mypackage",
  "description": "....",
  "version": "1.0.0",
  "main": "dist/index.js",
  "module": "dist/index.es.js",
  "files": [
    "dist"
  ],
  "peerDependencies": {
    "classnames": "^2.2.6",
    "dinero.js": "^1.8.0",
    "@material-ui/core": "^4.9.5",
    "@material-ui/icons": "^4.9.1",
    "@material-ui/lab": "^4.0.0-alpha.46",
     .........
  },
  "devDependencies": {
    "classnames": "^2.2.6",
    "dinero.js": "^1.8.0",
    "axios": "^0.21.1",
    "prop-types": "^15.7.2",
    "react-responsive": "^8.2.0",
    "lodash.throttle": "^4.1.1",
    "js-cookie": "^2.2.1",
    "moment": "^2.28.0",
    "react-html-parser": "^2.0.2",
     "react": "^16.13.0",
    "react-dom": "^16.13.0",
    "react-i18next": "^11.8.5",
    "react-responsive": "^8.2.0",
     .......

it seems to be installing all the dev dependencies when publishing.

Expected behavior: install only peers if missing.

Broken on Win 11;

Still having an issue similar to #5 #3 where I get
Error: EPERM: operation not permitted, unlink 'C:\Users\Benjy\AppData\Local\Temp\tmp-21752-ol0DdkWDa11N\mypackage-ui-1.0.27.tgz' Failed to publish package to global

Also, when I go to the temp folder tmp-21752-ol0DdkWDa11N it's empty;

[email protected];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.