diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index 860f219c70703..10ba566551970 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -293,6 +293,7 @@ graph LR; glob-->jackspeak; glob-->minimatch; glob-->minipass; + glob-->package-json-from-dist; glob-->path-scurry; hasown-->function-bind; hosted-git-info-->lru-cache; diff --git a/node_modules/.gitignore b/node_modules/.gitignore index 50a396cdfdfb9..0fac962be9c75 100644 --- a/node_modules/.gitignore +++ b/node_modules/.gitignore @@ -155,6 +155,7 @@ !/npm-registry-fetch !/npm-user-validate !/p-map +!/package-json-from-dist !/pacote !/parse-conflict-json !/path-key diff --git a/node_modules/glob/dist/esm/bin.mjs b/node_modules/glob/dist/esm/bin.mjs index 4bf17c5efd61c..5c7bf1e925610 100755 --- a/node_modules/glob/dist/esm/bin.mjs +++ b/node_modules/glob/dist/esm/bin.mjs @@ -1,14 +1,11 @@ #!/usr/bin/env node import { foregroundChild } from 'foreground-child'; import { existsSync } from 'fs'; -import { readFile } from 'fs/promises'; import { jack } from 'jackspeak'; +import { loadPackageJson } from 'package-json-from-dist'; import { join } from 'path'; -import { fileURLToPath } from 'url'; import { globStream } from './index.js'; -/* c8 ignore start */ -const { version } = JSON.parse(await readFile(fileURLToPath(new URL('../../package.json', import.meta.url)), 'utf8').catch(() => readFile(fileURLToPath(new URL('../../package.json', import.meta.url)), 'utf8'))); -/* c8 ignore stop */ +const { version } = loadPackageJson(import.meta.url, '../package.json'); const j = jack({ usage: 'glob [options] [ [ ...]]', }) diff --git a/node_modules/glob/package.json b/node_modules/glob/package.json index f6f7eb4e8b059..4838947dfc188 100644 --- a/node_modules/glob/package.json +++ b/node_modules/glob/package.json @@ -2,7 +2,7 @@ "author": "Isaac Z. Schlueter (https://blog.izs.me/)", "name": "glob", "description": "the most correct and second fastest glob implementation in JavaScript", - "version": "10.4.1", + "version": "10.4.2", "type": "module", "tshy": { "main": true, @@ -71,6 +71,7 @@ "jackspeak": "^3.1.2", "minimatch": "^9.0.4", "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", "path-scurry": "^1.11.1" }, "devDependencies": { diff --git a/node_modules/package-json-from-dist/LICENSE.md b/node_modules/package-json-from-dist/LICENSE.md new file mode 100644 index 0000000000000..881248b6d7f0c --- /dev/null +++ b/node_modules/package-json-from-dist/LICENSE.md @@ -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 +. + +## 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.*** diff --git a/node_modules/package-json-from-dist/dist/commonjs/index.js b/node_modules/package-json-from-dist/dist/commonjs/index.js new file mode 100644 index 0000000000000..5cff210d855cb --- /dev/null +++ b/node_modules/package-json-from-dist/dist/commonjs/index.js @@ -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 \ No newline at end of file diff --git a/node_modules/package-json-from-dist/dist/commonjs/package.json b/node_modules/package-json-from-dist/dist/commonjs/package.json new file mode 100644 index 0000000000000..5bbefffbabee3 --- /dev/null +++ b/node_modules/package-json-from-dist/dist/commonjs/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} diff --git a/node_modules/package-json-from-dist/dist/esm/index.js b/node_modules/package-json-from-dist/dist/esm/index.js new file mode 100644 index 0000000000000..0627645f9c35a --- /dev/null +++ b/node_modules/package-json-from-dist/dist/esm/index.js @@ -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 \ No newline at end of file diff --git a/node_modules/package-json-from-dist/dist/esm/package.json b/node_modules/package-json-from-dist/dist/esm/package.json new file mode 100644 index 0000000000000..3dbc1ca591c05 --- /dev/null +++ b/node_modules/package-json-from-dist/dist/esm/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/node_modules/package-json-from-dist/package.json b/node_modules/package-json-from-dist/package.json new file mode 100644 index 0000000000000..2d5526e87b7fa --- /dev/null +++ b/node_modules/package-json-from-dist/package.json @@ -0,0 +1,68 @@ +{ + "name": "package-json-from-dist", + "version": "1.0.0", + "description": "Load the local package.json from either src or dist folder", + "main": "./dist/commonjs/index.js", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./dist/esm/index.d.ts", + "default": "./dist/esm/index.js" + }, + "require": { + "types": "./dist/commonjs/index.d.ts", + "default": "./dist/commonjs/index.js" + } + } + }, + "files": [ + "dist" + ], + "scripts": { + "preversion": "npm test", + "postversion": "npm publish", + "prepublishOnly": "git push origin --follow-tags", + "prepare": "tshy", + "pretest": "npm run prepare", + "presnap": "npm run prepare", + "test": "tap", + "snap": "tap", + "format": "prettier --write . --loglevel warn --ignore-path ../../.prettierignore --cache", + "typedoc": "typedoc" + }, + "author": "Isaac Z. Schlueter (https://izs.me)", + "license": "BlueOak-1.0.0", + "repository": { + "type": "git", + "url": "git+https://github.com/isaacs/package-json-from-dist.git" + }, + "devDependencies": { + "@types/node": "^20.12.12", + "prettier": "^3.2.5", + "tap": "^18.5.3", + "typedoc": "^0.24.8", + "typescript": "^5.1.6", + "tshy": "^1.14.0" + }, + "prettier": { + "semi": false, + "printWidth": 70, + "tabWidth": 2, + "useTabs": false, + "singleQuote": true, + "jsxSingleQuote": false, + "bracketSameLine": true, + "arrowParens": "avoid", + "endOfLine": "lf", + "experimentalTernaries": true + }, + "tshy": { + "exports": { + "./package.json": "./package.json", + ".": "./src/index.ts" + } + }, + "types": "./dist/commonjs/index.d.ts", + "type": "module" +} diff --git a/package-lock.json b/package-lock.json index 996c649c01cf8..be562217bf4fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -104,7 +104,7 @@ "cli-columns": "^4.0.0", "fastest-levenshtein": "^1.0.16", "fs-minipass": "^3.0.3", - "glob": "^10.4.1", + "glob": "^10.4.2", "graceful-fs": "^4.2.11", "hosted-git-info": "^7.0.2", "ini": "^4.1.3", @@ -5898,9 +5898,9 @@ "license": "ISC" }, "node_modules/glob": { - "version": "10.4.1", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.1.tgz", - "integrity": "sha512-2jelhlq3E4ho74ZyVLN03oKdAZVUa6UDZzFLVH1H7dnoax+y9qyaq8zBkfDIggjniU19z0wU18y16jMB2eyVIw==", + "version": "10.4.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.2.tgz", + "integrity": "sha512-GwMlUF6PkPo3Gk21UxkCohOv0PLcIXVtKyLlpEI28R/cO/4eNOdmLk3CMW1wROV/WR/EsZOWAfBbBOqYvs88/w==", "inBundle": true, "license": "ISC", "dependencies": { @@ -5908,6 +5908,7 @@ "jackspeak": "^3.1.2", "minimatch": "^9.0.4", "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", "path-scurry": "^1.11.1" }, "bin": { @@ -10180,6 +10181,13 @@ "node": ">=8" } }, + "node_modules/package-json-from-dist": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.0.tgz", + "integrity": "sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==", + "inBundle": true, + "license": "BlueOak-1.0.0" + }, "node_modules/pacote": { "version": "18.0.6", "resolved": "https://registry.npmjs.org/pacote/-/pacote-18.0.6.tgz", diff --git a/package.json b/package.json index 4cff4eac43c23..ed39424dbfe40 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "cli-columns": "^4.0.0", "fastest-levenshtein": "^1.0.16", "fs-minipass": "^3.0.3", - "glob": "^10.4.1", + "glob": "^10.4.2", "graceful-fs": "^4.2.11", "hosted-git-info": "^7.0.2", "ini": "^4.1.3",