deps: package-json-from-dist@1.0.1 · npm/cli@ef1c368 · GitHub
Skip to content

Commit ef1c368

Browse files
committed
deps: package-json-from-dist@1.0.1
1 parent 92e6f07 commit ef1c368

4 files changed

Lines changed: 27 additions & 7 deletions

File tree

node_modules/package-json-from-dist/dist/commonjs/index.js

Lines changed: 11 additions & 1 deletion

node_modules/package-json-from-dist/dist/esm/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { readFileSync } from 'node:fs';
22
import { dirname, resolve, sep } from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
const NM = `${sep}node_modules${sep}`;
5+
const STORE = `.store${sep}`;
6+
const PKG = `${sep}package${sep}`;
57
const DIST = `${sep}dist${sep}`;
68
/**
79
* Find the package.json file, either from a TypeScript file somewhere not
@@ -56,8 +58,16 @@ export const findPackageJson = (from, pathFromSrc = '../package.json') => {
5658
// inside of node_modules. find the dist directly under package name.
5759
const nm = __dirname.substring(0, nms + NM.length);
5860
const pkgDir = __dirname.substring(nms + NM.length);
61+
// affordance for yarn berry, which puts package contents in
62+
// '.../node_modules/.store/${id}-${hash}/package/...'
63+
if (pkgDir.startsWith(STORE)) {
64+
const pkg = pkgDir.indexOf(PKG, STORE.length);
65+
if (pkg) {
66+
return resolve(nm, pkgDir.substring(0, pkg + PKG.length), 'package.json');
67+
}
68+
}
5969
const pkgName = pkgDir.startsWith('@') ?
60-
pkgDir.split(sep).slice(0, 2).join(sep)
70+
pkgDir.split(sep, 2).join(sep)
6171
: String(pkgDir.split(sep)[0]);
6272
return resolve(nm, pkgName, 'package.json');
6373
}

node_modules/package-json-from-dist/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "package-json-from-dist",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Load the local package.json from either src or dist folder",
55
"main": "./dist/commonjs/index.js",
66
"exports": {
@@ -28,7 +28,7 @@
2828
"presnap": "npm run prepare",
2929
"test": "tap",
3030
"snap": "tap",
31-
"format": "prettier --write . --loglevel warn --ignore-path ../../.prettierignore --cache",
31+
"format": "prettier --write . --log-level warn",
3232
"typedoc": "typedoc"
3333
},
3434
"author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)",

package-lock.json

Lines changed: 3 additions & 3 deletions

0 commit comments

Comments
 (0)