Giter VIP home page Giter VIP logo

node-pkginfo's Introduction

node-pkginfo

An easy way to expose properties on a module from a package.json

Installing pkginfo

  npm install pkginfo

Motivation

How often when writing node.js modules have you written the following line(s) of code?

  • Hard code your version string into your code
  exports.version = '0.1.0';
  • Programmatically expose the version from the package.json
  exports.version = require('/path/to/package.json').version;

In other words, how often have you wanted to expose basic information from your package.json onto your module programmatically? WELL NOW YOU CAN!

Usage

Using pkginfo is idiot-proof, just require and invoke it.

  var pkginfo = require('pkginfo')(module);

  console.dir(module.exports);

By invoking the pkginfo module all of the properties in your package.json file will be automatically exposed on the callee module (i.e. the parent module of pkginfo).

Here's a sample of the output:

  { name: 'simple-app',
    description: 'A test fixture for pkginfo',
    version: '0.1.0',
    author: 'Charlie Robbins <[email protected]>',
    keywords: [ 'test', 'fixture' ],
    main: './index.js',
    scripts: { test: 'vows test/*-test.js --spec' },
    engines: { node: '>= 0.4.0' } }

Expose specific properties

If you don't want to expose all properties on from your package.json on your module then simple pass those properties to the pkginfo function:

  var pkginfo = require('pkginfo')(module, 'version', 'author');

  console.dir(module.exports);
  { version: '0.1.0',
    author: 'Charlie Robbins <[email protected]>' }

If you're looking for further usage see the examples included in this repository.

Run Tests

Tests are written in vows and give complete coverage of all APIs.

  npm install
  npm test

Author: Charlie Robbins

License: MIT

node-pkginfo's People

Contributors

aldeed avatar indexzero avatar jwulf avatar kapouer avatar michaelsanford avatar raoulmillais avatar trentm 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar

node-pkginfo's Issues

Test failures in Windows

Looks like path names are giving pkginfo trouble in Windows.

Trace:

$ npm test

> [email protected] test c:\Documents and Settings\apenneba\Desktop\src\node-pkginfo
> vows test/*-test.js --spec


  ♢ pkginfo

  When using the pkginfo module and passed a single string argument
    ✗ should expose that property correctly
        » expected null, got {
      stack: "Error: Command failed: \015\nmodule.js:340\015\n    throw err;\015\n
    ^\015\nError: Cannot find module 'c:\\Documents'\015\n    at Function.Module._resolveFilename (module.js:338:15)\015\n    at Function.Module._load (module.js:280:25)\015\n
   at Function.Module.runMain (module.js:497:10)\015\n    at startup (node.js:119:16)\015\n    at node.js:901:3\015\n\n    at ChildProcess.exithandler (child_process.js:634:15)\n    at ChildProcess.EventEmitter.emit (events.js:98:17)\n    at ChildProcess.options.Emitter.emit (c:\\Documents and Settings\\apenneba\\Desktop\\src\\node-pkginfo\\node_modules\\vows\\lib\\vows.js:237:24)\n    at maybeClose (child_process.js:732:16)\n    at Process.ChildProcess._handle.onexit (child_process.js:799:5)",
      arguments: undefined,
      type: undefined,
      message: "Command failed: \015\nmodule.js:340\015\n    throw err;\015\n          ^\015\nError: Cannot find module 'c:\\Documents'\015\n    at Function.Module._resolveFilename (module.js:338:15)\015\n    at Function.Module._load (module.js:280:25)\015\n    at Function.Module.runMain (module.js:497:10)\015\n    at startup (node.js:119:16)\015\n
  at node.js:901:3\015\n",
      killed: false,
      code: 8,
      signal: null
  } // module.js:338
  When using the pkginfo module and passed an object argument
    ✗ should expose that property correctly
        » expected null, got . // pkginfo-test.js:43
  When using the pkginfo module and passed multiple string arguments
    ✗ should expose that property correctly
        » expected null, got . // pkginfo-test.js:43
  When using the pkginfo module and read from a specified directory
    ✗ should expose that property correctly
        » expected null, got . // pkginfo-test.js:43
  When using the pkginfo module and passed an array argument
    ✗ should expose that property correctly
        » expected null, got . // pkginfo-test.js:43
  When using the pkginfo module and passed no arguments
    ✗ should expose that property correctly
        » expected null, got . // pkginfo-test.js:43

✗ Broken » 6 broken (4.377s)

I tried npm test in Command Prompt as well as Git Bash, and get the same failing tests.

System:

$ specs node git os
Specs:

specs 0.4
https://github.com/mcandre/specs#readme

npm --version
1.2.17

node --version
v0.10.3

git --version
git version 1.8.0.msysgit.0

systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name:                   Microsoft Windows XP Professional
OS Version:                5.1.2600 Service Pack 3 Build 2600

Issue with /lib/pkginfo.js for finding package.json

I've experienced a rather serious issue in which when attempting to debug in visual studio code a solution that uses pkginfo, I would get an error for pkginfo that the package.json file cannot be found inside \lib/package.json.

I believe on line 104 of pkgingfo.js file in /lib is wrong and should actually be looking 2 directories back in the root folder.

e.g.

wrong line: contents = require(dir + '/package.json');
should be: contents = require(dir + '../../package.json');

Missing licensing information

Hello,

your code is lacking licensing information. It would be nice if there was a COPYING/LICENSE file in the source code -- bonus points if you also specify the chosen license both in package.json and in pkginfo.js .

Kindly,
David

Detect install from git vs npm vs local

Is there any way to do this? I've looked at package.json for a package I installed from a git repo, and it appears to have the same information in it as a package installed from git does.

example of what "module" is?

I have tried passing a string 'my-module' a require('my-module') and a path ../../../node_modules/my-module none of which work.

Please provide examples of what module is supposed to be here.

I'm trying to get version of an installed module.

rtrewtr4ewat4w4rwe56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t56t4

아바타2: 물의 길 전체 영화 (2022-HD)"Avatar-2
아바타 2: 물의 길 풀 버전 [2022-KO] 전체 영화 다시보기 𝟏𝟎𝟖𝟎𝐏
아바타 2: 물의 길 (2022) 전체 영화((한국영화))전체 버전 - 다운로드
아바타 2: 물의 길 풀 버전 [2022] 전체 영화 다시보기 1080P
아바타 2 물의 길 풀 버전 [2022] 전체 영화 온라인
아바타 2: 물의 길 풀 버전 2022-KO 전체 영화 다시보기 1080pHD

Problems with pkginfo in bundles?

Hello:

I'm trying to use pkginfo in a bundle of JavaScript for a Node.js application. I'm trying to use webpack or browserify to do this, but the resulting module (passed into the pkginfo class) seems to lack the necessary fields.

Has anyone been able to include pkginfo into a bundle?

Thanks,
Glenn

Error when trying to install package

When I try to install package via npm or yarn I'm getting the following error:

verbose stack package: No valid versions available for package

node version: v10.1.0
npm version: v6.4.1
os: macOS Mojave 10.14.2

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.