initial commit of actions

This commit is contained in:
Dominik Polakovics Polakovics 2026-01-31 18:56:04 +01:00
commit 949ece5785
44660 changed files with 12034344 additions and 0 deletions

View file

@ -0,0 +1,99 @@
export type Config = Record<string, unknown>;
export interface Options<ConfigType extends Config> {
/**
The directory to start looking up for a `package.json` file.
@default process.cwd()
*/
readonly cwd?: string;
/**
The default config.
@default {}
*/
readonly defaults?: ConfigType;
/**
Skip `package.json` files that have the namespaced config explicitly set to `false`.
Continues searching upwards until the next `package.json` file is reached. This can be useful when you need to support the ability for users to have nested `package.json` files, but only read from the root one, like in the case of [`electron-builder`](https://github.com/electron-userland/electron-builder/wiki/Options#AppMetadata) where you have one `package.json` file for the app and one top-level for development.
@default false
@example
```
{
"name": "some-package",
"version": "1.0.0",
"unicorn": false
}
```
*/
readonly skipOnFalse?: boolean;
}
/**
It [walks up](https://github.com/sindresorhus/find-up) parent directories until a `package.json` can be found, reads it, and returns the user specified namespace or an empty object if not found.
@param namespace - The `package.json` namespace you want.
@returns A `Promise` for the config.
@example
```
// {
// "name": "some-package",
// "version": "1.0.0",
// "unicorn": {
// "rainbow": true
// }
// }
import {packageConfig} from 'pkg-conf';
const config = await packageConfig('unicorn');
console.log(config.rainbow);
//=> true
```
*/
export function packageConfig<ConfigType extends Config = Config>(
namespace: string,
options?: Options<ConfigType>
): Promise<ConfigType & Config>;
/**
It [walks up](https://github.com/sindresorhus/find-up) parent directories until a `package.json` can be found, reads it, and returns the user specified namespace or an empty object if not found.
@param namespace - The `package.json` namespace you want.
@returns Returns the config.
@example
```
// {
// "name": "some-package",
// "version": "1.0.0",
// "unicorn": {
// "rainbow": true
// }
// }
import {packageConfigSync} from 'pkg-conf';
const config = packageConfigSync('unicorn');
console.log(config.rainbow);
//=> true
```
*/
export function packageConfigSync<ConfigType extends Config = Config>(
namespace: string,
options?: Options<ConfigType>
): ConfigType & Config;
/**
@param config - The config returned from any of the above methods.
@returns The file path to the `package.json` file or `undefined` if not found.
*/
export function packageJsonPath(config: Config): string | undefined;

55
github/codeql-action-v2/node_modules/pkg-conf/index.js generated vendored Normal file
View file

@ -0,0 +1,55 @@
import path from 'node:path';
import {findUp, findUpSync} from 'find-up';
import {loadJsonFile, loadJsonFileSync} from 'load-json-file';
const filePaths = new WeakMap();
const findNextCwd = pkgPath => path.resolve(path.dirname(pkgPath), '..');
const addFilePath = (object, filePath) => {
filePaths.set(object, filePath);
return object;
};
export async function packageConfig(namespace, options = {}) {
if (!namespace) {
throw new TypeError('Expected a namespace');
}
const filePath = await findUp('package.json', options.cwd ? {cwd: options.cwd} : {});
if (!filePath) {
return addFilePath({...options.defaults}, filePath);
}
const packageJson = await loadJsonFile(filePath);
if (options.skipOnFalse && packageJson[namespace] === false) {
return packageConfig(namespace, {...options, cwd: findNextCwd(filePath)});
}
return addFilePath({...options.defaults, ...packageJson[namespace]}, filePath);
}
export function packageConfigSync(namespace, options = {}) {
if (!namespace) {
throw new TypeError('Expected a namespace');
}
const filePath = findUpSync('package.json', options.cwd ? {cwd: options.cwd} : {});
if (!filePath) {
return addFilePath({...options.defaults}, filePath);
}
const packageJson = loadJsonFileSync(filePath);
if (options.skipOnFalse && packageJson[namespace] === false) {
return packageConfigSync(namespace, {...options, cwd: findNextCwd(filePath)});
}
return addFilePath({...options.defaults, ...packageJson[namespace]}, filePath);
}
export function packageJsonPath(config) {
return filePaths.get(config);
}

View file

@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,52 @@
{
"name": "pkg-conf",
"version": "4.0.0",
"description": "Get namespaced config from the closest package.json",
"license": "MIT",
"repository": "sindresorhus/pkg-conf",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"json",
"read",
"parse",
"file",
"fs",
"graceful",
"load",
"package",
"config",
"configuration",
"object",
"namespace",
"namespaced"
],
"dependencies": {
"find-up": "^6.0.0",
"load-json-file": "^7.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
"tsd": "^0.17.0",
"xo": "^0.44.0"
},
"fixture": {
"foo": true
}
}

View file

@ -0,0 +1,98 @@
# pkg-conf
> Get namespaced config from the closest package.json
Having tool specific config in package.json reduces the amount of metafiles in your repo (there are usually a lot!) and makes the config obvious compared to hidden dotfiles like `.eslintrc`, which can end up causing confusion. [XO](https://github.com/xojs/xo), for example, uses the `xo` namespace in package.json, and [ESLint](http://eslint.org) uses `eslintConfig`. Many more tools supports this, like [AVA](https://avajs.dev), [Babel](https://babeljs.io), [nyc](https://github.com/istanbuljs/nyc), etc.
## Install
```
$ npm install pkg-conf
```
## Usage
```json
{
"name": "some-package",
"version": "1.0.0",
"unicorn": {
"rainbow": true
}
}
```
```js
import {packageConfig} from 'pkg-conf';
const config = await packageConfig('unicorn');
console.log(config.rainbow);
//=> true
```
## API
It [walks up](https://github.com/sindresorhus/find-up) parent directories until a `package.json` can be found, reads it, and returns the user specified namespace or an empty object if not found.
### packageConfig(namespace, options?)
Returns a `Promise` for the config.
### packageConfigSync(namespace, options?)
Returns the config.
#### namespace
Type: `string`
The package.json namespace you want.
#### options
Type: `object`
##### cwd
Type: `string`\
Default: `process.cwd()`
The directory to start looking up for a package.json file.
##### defaults
Type: `object`
The default config.
##### skipOnFalse
Type: `boolean`\
Default: `false`
Skip `package.json` files that have the namespaced config explicitly set to `false`.
Continues searching upwards until the next `package.json` file is reached. This can be useful when you need to support the ability for users to have nested `package.json` files, but only read from the root one, like in the case of [`electron-builder`](https://github.com/electron-userland/electron-builder/wiki/Options#AppMetadata) where you have one `package.json` file for the app and one top-level for development.
Example usage for the user:
```json
{
"name": "some-package",
"version": "1.0.0",
"unicorn": false
}
```
### packageJsonPath(config)
Pass in the config returned from any of the above methods.
Returns the file path to the package.json file or `undefined` if not found.
## Related
- [read-pkg-up](https://github.com/sindresorhus/read-pkg-up) - Read the closest package.json file
- [read-pkg](https://github.com/sindresorhus/read-pkg) - Read a package.json file
- [find-up](https://github.com/sindresorhus/find-up) - Find a file by walking up parent directories