-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
399 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
All packages under `src/` are licensed according to the terms in | ||
their respective `LICENSE` or `LICENSE.md` files. | ||
|
||
The remainder of this project is licensed under the Blue Oak | ||
Model License, as follows: | ||
|
||
----- | ||
|
||
# Blue Oak Model License | ||
|
||
Version 1.0.0 | ||
|
||
## Purpose | ||
|
||
This license gives everyone as much permission to work with | ||
this software as possible, while protecting contributors | ||
from liability. | ||
|
||
## Acceptance | ||
|
||
In order to receive this license, you must agree to its | ||
rules. The rules of this license are both obligations | ||
under that agreement and conditions to your license. | ||
You must not do anything with this software that triggers | ||
a rule that you cannot or will not follow. | ||
|
||
## Copyright | ||
|
||
Each contributor licenses you to do everything with this | ||
software that would otherwise infringe that contributor's | ||
copyright in it. | ||
|
||
## Notices | ||
|
||
You must ensure that everyone who gets a copy of | ||
any part of this software from you, with or without | ||
changes, also gets the text of this license or a link to | ||
<https://blueoakcouncil.org/license/1.0.0>. | ||
|
||
## Excuse | ||
|
||
If anyone notifies you in writing that you have not | ||
complied with [Notices](#notices), you can keep your | ||
license by taking all practical steps to comply within 30 | ||
days after the notice. If you do not do so, your license | ||
ends immediately. | ||
|
||
## Patent | ||
|
||
Each contributor licenses you to do everything with this | ||
software that would otherwise infringe any patent claims | ||
they can license or become able to license. | ||
|
||
## Reliability | ||
|
||
No contributor can revoke this license. | ||
|
||
## No Liability | ||
|
||
***As far as the law allows, this software comes as is, | ||
without any warranty or condition, and no contributor | ||
will be liable to anyone for any damages related to this | ||
software or this license, under any kind of legal claim.*** |
124 changes: 124 additions & 0 deletions
124
node_modules/package-json-from-dist/dist/commonjs/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.loadPackageJson = exports.findPackageJson = void 0; | ||
const node_fs_1 = require("node:fs"); | ||
const node_path_1 = require("node:path"); | ||
const node_url_1 = require("node:url"); | ||
const NM = `${node_path_1.sep}node_modules${node_path_1.sep}`; | ||
const DIST = `${node_path_1.sep}dist${node_path_1.sep}`; | ||
/** | ||
* Find the package.json file, either from a TypeScript file somewhere not | ||
* in a 'dist' folder, or a built and/or installed 'dist' folder. | ||
* | ||
* Note: this *only* works if you build your code into `'./dist'`, and that the | ||
* source path does not also contain `'dist'`! If you don't build into | ||
* `'./dist'`, or if you have files at `./src/dist/dist.ts`, then this will | ||
* not work properly! | ||
* | ||
* The default `pathFromSrc` option assumes that the calling code lives one | ||
* folder below the root of the package. Otherwise, it must be specified. | ||
* | ||
* Example: | ||
* | ||
* ```ts | ||
* // src/index.ts | ||
* import { findPackageJson } from 'package-json-from-dist' | ||
* | ||
* const pj = findPackageJson(import.meta.url) | ||
* console.log(`package.json found at ${pj}`) | ||
* ``` | ||
* | ||
* If the caller is deeper within the project source, then you must provide | ||
* the appropriate fallback path: | ||
* | ||
* ```ts | ||
* // src/components/something.ts | ||
* import { findPackageJson } from 'package-json-from-dist' | ||
* | ||
* const pj = findPackageJson(import.meta.url, '../../package.json') | ||
* console.log(`package.json found at ${pj}`) | ||
* ``` | ||
* | ||
* When running from CommmonJS, use `__filename` instead of `import.meta.url` | ||
* | ||
* ```ts | ||
* // src/index.cts | ||
* import { findPackageJson } from 'package-json-from-dist' | ||
* | ||
* const pj = findPackageJson(__filename) | ||
* console.log(`package.json found at ${pj}`) | ||
* ``` | ||
*/ | ||
const findPackageJson = (from, pathFromSrc = '../package.json') => { | ||
const f = typeof from === 'object' || from.startsWith('file://') ? | ||
(0, node_url_1.fileURLToPath)(from) | ||
: from; | ||
const __dirname = (0, node_path_1.dirname)(f); | ||
const nms = __dirname.lastIndexOf(NM); | ||
if (nms !== -1) { | ||
// inside of node_modules. find the dist directly under package name. | ||
const nm = __dirname.substring(0, nms + NM.length); | ||
const pkgDir = __dirname.substring(nms + NM.length); | ||
const pkgName = pkgDir.startsWith('@') ? | ||
pkgDir.split(node_path_1.sep).slice(0, 2).join(node_path_1.sep) | ||
: String(pkgDir.split(node_path_1.sep)[0]); | ||
return (0, node_path_1.resolve)(nm, pkgName, 'package.json'); | ||
} | ||
else { | ||
// see if we are in a dist folder. | ||
const d = __dirname.lastIndexOf(DIST); | ||
if (d !== -1) { | ||
return (0, node_path_1.resolve)(__dirname.substring(0, d), 'package.json'); | ||
} | ||
else { | ||
return (0, node_path_1.resolve)(__dirname, pathFromSrc); | ||
} | ||
} | ||
}; | ||
exports.findPackageJson = findPackageJson; | ||
/** | ||
* Load the package.json file, either from a TypeScript file somewhere not | ||
* in a 'dist' folder, or a built and/or installed 'dist' folder. | ||
* | ||
* Note: this *only* works if you build your code into `'./dist'`, and that the | ||
* source path does not also contain `'dist'`! If you don't build into | ||
* `'./dist'`, or if you have files at `./src/dist/dist.ts`, then this will | ||
* not work properly! | ||
* | ||
* The default `pathFromSrc` option assumes that the calling code lives one | ||
* folder below the root of the package. Otherwise, it must be specified. | ||
* | ||
* Example: | ||
* | ||
* ```ts | ||
* // src/index.ts | ||
* import { loadPackageJson } from 'package-json-from-dist' | ||
* | ||
* const pj = loadPackageJson(import.meta.url) | ||
* console.log(`Hello from ${pj.name}@${pj.version}`) | ||
* ``` | ||
* | ||
* If the caller is deeper within the project source, then you must provide | ||
* the appropriate fallback path: | ||
* | ||
* ```ts | ||
* // src/components/something.ts | ||
* import { loadPackageJson } from 'package-json-from-dist' | ||
* | ||
* const pj = loadPackageJson(import.meta.url, '../../package.json') | ||
* console.log(`Hello from ${pj.name}@${pj.version}`) | ||
* ``` | ||
* | ||
* When running from CommmonJS, use `__filename` instead of `import.meta.url` | ||
* | ||
* ```ts | ||
* // src/index.cts | ||
* import { loadPackageJson } from 'package-json-from-dist' | ||
* | ||
* const pj = loadPackageJson(__filename) | ||
* console.log(`Hello from ${pj.name}@${pj.version}`) | ||
* ``` | ||
*/ | ||
const loadPackageJson = (from, pathFromSrc = '../package.json') => JSON.parse((0, node_fs_1.readFileSync)((0, exports.findPackageJson)(from, pathFromSrc), 'utf8')); | ||
exports.loadPackageJson = loadPackageJson; | ||
//# sourceMappingURL=index.js.map |
3 changes: 3 additions & 0 deletions
3
node_modules/package-json-from-dist/dist/commonjs/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "commonjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { readFileSync } from 'node:fs'; | ||
import { dirname, resolve, sep } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
const NM = `${sep}node_modules${sep}`; | ||
const DIST = `${sep}dist${sep}`; | ||
/** | ||
* Find the package.json file, either from a TypeScript file somewhere not | ||
* in a 'dist' folder, or a built and/or installed 'dist' folder. | ||
* | ||
* Note: this *only* works if you build your code into `'./dist'`, and that the | ||
* source path does not also contain `'dist'`! If you don't build into | ||
* `'./dist'`, or if you have files at `./src/dist/dist.ts`, then this will | ||
* not work properly! | ||
* | ||
* The default `pathFromSrc` option assumes that the calling code lives one | ||
* folder below the root of the package. Otherwise, it must be specified. | ||
* | ||
* Example: | ||
* | ||
* ```ts | ||
* // src/index.ts | ||
* import { findPackageJson } from 'package-json-from-dist' | ||
* | ||
* const pj = findPackageJson(import.meta.url) | ||
* console.log(`package.json found at ${pj}`) | ||
* ``` | ||
* | ||
* If the caller is deeper within the project source, then you must provide | ||
* the appropriate fallback path: | ||
* | ||
* ```ts | ||
* // src/components/something.ts | ||
* import { findPackageJson } from 'package-json-from-dist' | ||
* | ||
* const pj = findPackageJson(import.meta.url, '../../package.json') | ||
* console.log(`package.json found at ${pj}`) | ||
* ``` | ||
* | ||
* When running from CommmonJS, use `__filename` instead of `import.meta.url` | ||
* | ||
* ```ts | ||
* // src/index.cts | ||
* import { findPackageJson } from 'package-json-from-dist' | ||
* | ||
* const pj = findPackageJson(__filename) | ||
* console.log(`package.json found at ${pj}`) | ||
* ``` | ||
*/ | ||
export const findPackageJson = (from, pathFromSrc = '../package.json') => { | ||
const f = typeof from === 'object' || from.startsWith('file://') ? | ||
fileURLToPath(from) | ||
: from; | ||
const __dirname = dirname(f); | ||
const nms = __dirname.lastIndexOf(NM); | ||
if (nms !== -1) { | ||
// inside of node_modules. find the dist directly under package name. | ||
const nm = __dirname.substring(0, nms + NM.length); | ||
const pkgDir = __dirname.substring(nms + NM.length); | ||
const pkgName = pkgDir.startsWith('@') ? | ||
pkgDir.split(sep).slice(0, 2).join(sep) | ||
: String(pkgDir.split(sep)[0]); | ||
return resolve(nm, pkgName, 'package.json'); | ||
} | ||
else { | ||
// see if we are in a dist folder. | ||
const d = __dirname.lastIndexOf(DIST); | ||
if (d !== -1) { | ||
return resolve(__dirname.substring(0, d), 'package.json'); | ||
} | ||
else { | ||
return resolve(__dirname, pathFromSrc); | ||
} | ||
} | ||
}; | ||
/** | ||
* Load the package.json file, either from a TypeScript file somewhere not | ||
* in a 'dist' folder, or a built and/or installed 'dist' folder. | ||
* | ||
* Note: this *only* works if you build your code into `'./dist'`, and that the | ||
* source path does not also contain `'dist'`! If you don't build into | ||
* `'./dist'`, or if you have files at `./src/dist/dist.ts`, then this will | ||
* not work properly! | ||
* | ||
* The default `pathFromSrc` option assumes that the calling code lives one | ||
* folder below the root of the package. Otherwise, it must be specified. | ||
* | ||
* Example: | ||
* | ||
* ```ts | ||
* // src/index.ts | ||
* import { loadPackageJson } from 'package-json-from-dist' | ||
* | ||
* const pj = loadPackageJson(import.meta.url) | ||
* console.log(`Hello from ${pj.name}@${pj.version}`) | ||
* ``` | ||
* | ||
* If the caller is deeper within the project source, then you must provide | ||
* the appropriate fallback path: | ||
* | ||
* ```ts | ||
* // src/components/something.ts | ||
* import { loadPackageJson } from 'package-json-from-dist' | ||
* | ||
* const pj = loadPackageJson(import.meta.url, '../../package.json') | ||
* console.log(`Hello from ${pj.name}@${pj.version}`) | ||
* ``` | ||
* | ||
* When running from CommmonJS, use `__filename` instead of `import.meta.url` | ||
* | ||
* ```ts | ||
* // src/index.cts | ||
* import { loadPackageJson } from 'package-json-from-dist' | ||
* | ||
* const pj = loadPackageJson(__filename) | ||
* console.log(`Hello from ${pj.name}@${pj.version}`) | ||
* ``` | ||
*/ | ||
export const loadPackageJson = (from, pathFromSrc = '../package.json') => JSON.parse(readFileSync(findPackageJson(from, pathFromSrc), 'utf8')); | ||
//# sourceMappingURL=index.js.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
Oops, something went wrong.