package-json-from-dist
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -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'); |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36453
437
111