Socket
Socket
Sign inDemoInstall

package-json-from-dist

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

package-json-from-dist - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

12

dist/commonjs/index.js

@@ -8,2 +8,4 @@ "use strict";

const NM = `${node_path_1.sep}node_modules${node_path_1.sep}`;
const STORE = `.store${node_path_1.sep}`;
const PKG = `${node_path_1.sep}package${node_path_1.sep}`;
const DIST = `${node_path_1.sep}dist${node_path_1.sep}`;

@@ -63,4 +65,12 @@ /**

const pkgDir = __dirname.substring(nms + NM.length);
// affordance for yarn berry, which puts package contents in
// '.../node_modules/.store/${id}-${hash}/package/...'
if (pkgDir.startsWith(STORE)) {
const pkg = pkgDir.indexOf(PKG, STORE.length);
if (pkg) {
return (0, node_path_1.resolve)(nm, pkgDir.substring(0, pkg + PKG.length), 'package.json');
}
}
const pkgName = pkgDir.startsWith('@') ?
pkgDir.split(node_path_1.sep).slice(0, 2).join(node_path_1.sep)
pkgDir.split(node_path_1.sep, 2).join(node_path_1.sep)
: String(pkgDir.split(node_path_1.sep)[0]);

@@ -67,0 +77,0 @@ return (0, node_path_1.resolve)(nm, pkgName, 'package.json');

@@ -5,2 +5,4 @@ import { readFileSync } from 'node:fs';

const NM = `${sep}node_modules${sep}`;
const STORE = `.store${sep}`;
const PKG = `${sep}package${sep}`;
const DIST = `${sep}dist${sep}`;

@@ -60,4 +62,12 @@ /**

const pkgDir = __dirname.substring(nms + NM.length);
// affordance for yarn berry, which puts package contents in
// '.../node_modules/.store/${id}-${hash}/package/...'
if (pkgDir.startsWith(STORE)) {
const pkg = pkgDir.indexOf(PKG, STORE.length);
if (pkg) {
return resolve(nm, pkgDir.substring(0, pkg + PKG.length), 'package.json');
}
}
const pkgName = pkgDir.startsWith('@') ?
pkgDir.split(sep).slice(0, 2).join(sep)
pkgDir.split(sep, 2).join(sep)
: String(pkgDir.split(sep)[0]);

@@ -64,0 +74,0 @@ return resolve(nm, pkgName, 'package.json');

4

package.json
{
"name": "package-json-from-dist",
"version": "1.0.0",
"version": "1.0.1",
"description": "Load the local package.json from either src or dist folder",

@@ -31,3 +31,3 @@ "main": "./dist/commonjs/index.js",

"snap": "tap",
"format": "prettier --write . --loglevel warn --ignore-path ../../.prettierignore --cache",
"format": "prettier --write . --log-level warn",
"typedoc": "typedoc"

@@ -34,0 +34,0 @@ },

@@ -22,3 +22,3 @@ # package-json-from-dist

This *only* works if your code builds into a target folder called
This _only_ works if your code builds into a target folder called
`dist`, which is in the root of the package. It also requires

@@ -38,3 +38,6 @@ that you do not have a folder named `node_modules` anywhere

// src/index.ts
import { findPackageJson, loadPackageJson } from 'package-json-from-dist'
import {
findPackageJson,
loadPackageJson,
} from 'package-json-from-dist'

@@ -54,3 +57,6 @@ const pj = findPackageJson(import.meta.url)

// src/components/something.ts
import { findPackageJson, loadPackageJson } from 'package-json-from-dist'
import {
findPackageJson,
loadPackageJson,
} from 'package-json-from-dist'

@@ -69,3 +75,6 @@ const pj = findPackageJson(import.meta.url, '../../package.json')

// src/index.cts
import { findPackageJson, loadPackageJson } from 'package-json-from-dist'
import {
findPackageJson,
loadPackageJson,
} from 'package-json-from-dist'

@@ -86,3 +95,6 @@ const pj = findPackageJson(__filename)

```js
import { findPackageJson, loadPackageJson } from 'package-json-from-dist'
import {
findPackageJson,
loadPackageJson,
} from 'package-json-from-dist'
//@ts-ignore

@@ -97,5 +109,8 @@ export const pkg = loadPackageJson(import.meta.url)

```js
import { findPackageJson, loadPackageJson } from 'package-json-from-dist'
import {
findPackageJson,
loadPackageJson,
} from 'package-json-from-dist'
export const pkg = loadPackageJson(__filename)
export const pj = findPackageJson(__filename)
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc