Deployed the page to Github Pages.

This commit is contained in:
Batuhan Berk Başoğlu 2024-11-03 21:30:09 -05:00
parent 1d79754e93
commit 2c89899458
Signed by: batuhan-basoglu
SSH key fingerprint: SHA256:kEsnuHX+qbwhxSAXPUQ4ox535wFHu/hIRaa53FzxRpo
62797 changed files with 6551425 additions and 15279 deletions

15
node_modules/@npmcli/run-script/LICENSE generated vendored Normal file
View file

@ -0,0 +1,15 @@
The ISC License
Copyright (c) npm, Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

174
node_modules/@npmcli/run-script/README.md generated vendored Normal file
View file

@ -0,0 +1,174 @@
# @npmcli/run-script
Run a lifecycle script for a package (descendant of npm-lifecycle)
## USAGE
```js
const runScript = require('@npmcli/run-script')
runScript({
// required, the script to run
event: 'install',
// extra args to pass to the command, defaults to []
args: [],
// required, the folder where the package lives
path: '/path/to/package/folder',
// optional, these paths will be put at the beginning of `$PATH`, even
// after run-script adds the node_modules/.bin folder(s) from
// `process.cwd()`. This is for commands like `npm init`, `npm exec`,
// and `npx` to make sure manually installed packages come before
// anything that happens to be in the tree in `process.cwd()`.
binPaths: [
'/path/to/npx/node_modules/.bin',
'/path/to/npm/prefix/node_modules/.bin',
],
// optional, defaults to /bin/sh on unix, or cmd.exe on windows
scriptShell: '/bin/bash',
// optional, passed directly to `@npmcli/promise-spawn` which defaults it to true
// return stdout and stderr as strings rather than buffers
stdioString: false,
// optional, additional environment variables to add
// note that process.env IS inherited by default
// Always set:
// - npm_package_json The package.json file in the folder
// - npm_lifecycle_event The event that this is being run for
// - npm_lifecycle_script The script being run
// The fields described in https://github.com/npm/rfcs/pull/183
env: {
npm_package_from: 'foo@bar',
npm_package_resolved: 'https://registry.npmjs.org/foo/-/foo-1.2.3.tgz',
npm_package_integrity: 'sha512-foobarbaz',
},
// defaults to 'pipe'. Can also pass an array like you would to node's
// exec or spawn functions. Note that if it's anything other than
// 'pipe' then the stdout/stderr values on the result will be missing.
// npm cli sets this to 'inherit' for explicit run-scripts (test, etc.)
// but leaves it as 'pipe' for install scripts that run in parallel.
stdio: 'inherit',
// print the package id and script, and the command to be run, like:
// > somepackage@1.2.3 postinstall
// > make all-the-things
})
.then(({ code, signal, stdout, stderr, pkgid, path, event, script }) => {
// do something with the results
})
.catch(er => {
// command did not work.
// er is decorated with:
// - code
// - signal
// - stdout
// - stderr
// - path
// - pkgid (name@version string)
// - event
// - script
})
```
## API
Call the exported `runScript` function with an options object.
Returns a promise that resolves to the result of the execution. Promise
rejects if the execution fails (exits non-zero) or has any other error.
Rejected errors are decorated with the same values as the result object.
If the stdio options mean that it'll have a piped stdin, then the stdin is
ended immediately on the child process. If stdin is shared with the parent
terminal, then it is up to the user to end it, of course.
### Results
- `code` Process exit code
- `signal` Process exit signal
- `stdout` stdout data (Buffer, or String when `stdioString` set to true)
- `stderr` stderr data (Buffer, or String when `stdioString` set to true)
- `path` Path to the package executing its script
- `event` Lifecycle event being run
- `script` Command being run
If stdio is `inherit` this package will emit a banner with the package
name and version, event name, and script command to be run, and send it
to [`proc-log.output.standard`](https://npm.im/proc-log). Consuming
libraries can decide whether or not to display this.
### Options
- `path` Required. The path to the package having its script run.
- `event` Required. The event being executed.
- `args` Optional, default `[]`. Extra arguments to pass to the script.
- `env` Optional, object of fields to add to the environment of the
subprocess. Note that process.env IS inherited by default These are
always set:
- `npm_package_json` The package.json file in the folder
- `npm_lifecycle_event` The event that this is being run for
- `npm_lifecycle_script` The script being run
- The `package.json` fields described in
[RFC183](https://github.com/npm/rfcs/pull/183/files).
- `scriptShell` Optional, defaults to `/bin/sh` on Unix, defaults to
`env.ComSpec` or `cmd` on Windows. Custom script to use to execute the
command.
- `stdio` Optional, defaults to `'pipe'`. The same as the `stdio` argument
passed to `child_process` functions in Node.js. Note that if a stdio
output is set to anything other than `pipe`, it will not be present in
the result/error object.
- `cmd` Optional. Override the script from the `package.json` with
something else, which will be run in an otherwise matching environment.
- `stdioString` Optional, passed directly to `@npmcli/promise-spawn` which
defaults it to `true`. Return string values for `stderr` and `stdout` rather
than Buffers.
Note that this does _not_ run pre-event and post-event scripts. The
caller has to manage that process themselves.
## Differences from [npm-lifecycle](https://github.com/npm/npm-lifecycle)
This is an implementation to satisfy [RFC
90](https://github.com/npm/rfcs/pull/90), [RFC
77](https://github.com/npm/rfcs/pull/77), and [RFC
73](https://github.com/npm/rfcs/pull/73).
Apart from those behavior changes in npm v7, this is also just refresh of
the codebase, with modern coding techniques and better test coverage.
Functionally, this means:
- Output is not dumped to the top level process's stdio by default.
- Less stuff is put into the environment.
- It is not opinionated about logging. (So, at least with the logging
framework in npm v7.0 and before, the caller has to call
`log.disableProgress()` and `log.enableProgress()` at the appropriate
times, if necessary.)
- The directory containing the `node` executable is _never_ added to the
`PATH` environment variable. (Ie, `--scripts-prepend-node-path` is
effectively always set to `false`.) Doing so causes more unintended side
effects than it ever prevented.
- Hook scripts are not run by this module. If the caller wishes to run
hook scripts, then they can override the default package script with an
explicit `cmd` option pointing to the `node_modules/.hook/${event}`
script.
## Escaping
In order to ensure that arguments are handled consistently, this module
writes a temporary script file containing the command as it exists in
the package.json, followed by the user supplied arguments having been
escaped to ensure they are processed as literal strings. We then instruct
the shell to execute the script file, and when the process exits we remove
the temporary file.
In Windows, when the shell is cmd, and when the initial command in the script
is a known batch file (i.e. `something.cmd`) we double escape additional
arguments so that the shim scripts npm installs work correctly.
The actual implementation of the escaping is in `lib/escape.js`.

View file

@ -0,0 +1,11 @@
const { stat } = require('node:fs/promises')
const { resolve } = require('node:path')
module.exports = async path => {
try {
const st = await stat(resolve(path, 'server.js'))
return st.isFile()
} catch (er) {
return false
}
}

40
node_modules/@npmcli/run-script/lib/make-spawn-args.js generated vendored Normal file
View file

@ -0,0 +1,40 @@
/* eslint camelcase: "off" */
const setPATH = require('./set-path.js')
const { resolve } = require('path')
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
const makeSpawnArgs = options => {
const {
event,
path,
scriptShell = true,
binPaths,
env,
stdio,
cmd,
args,
stdioString,
} = options
const spawnEnv = setPATH(path, binPaths, {
// we need to at least save the PATH environment var
...process.env,
...env,
npm_package_json: resolve(path, 'package.json'),
npm_lifecycle_event: event,
npm_lifecycle_script: cmd,
npm_config_node_gyp,
})
const spawnOpts = {
env: spawnEnv,
stdioString,
stdio,
cwd: path,
shell: scriptShell,
}
return [cmd, args, spawnOpts]
}
module.exports = makeSpawnArgs

2
node_modules/@npmcli/run-script/lib/node-gyp-bin/node-gyp generated vendored Executable file
View file

@ -0,0 +1,2 @@
#!/usr/bin/env sh
node "$npm_config_node_gyp" "$@"

View file

@ -0,0 +1 @@
@node "%npm_config_node_gyp%" %*

29
node_modules/@npmcli/run-script/lib/package-envs.js generated vendored Normal file
View file

@ -0,0 +1,29 @@
const packageEnvs = (vals, prefix, env = {}) => {
for (const [key, val] of Object.entries(vals)) {
if (val === undefined) {
continue
} else if (val === null || val === false) {
env[`${prefix}${key}`] = ''
} else if (Array.isArray(val)) {
val.forEach((item, index) => {
packageEnvs({ [`${key}_${index}`]: item }, `${prefix}`, env)
})
} else if (typeof val === 'object') {
packageEnvs(val, `${prefix}${key}_`, env)
} else {
env[`${prefix}${key}`] = String(val)
}
}
return env
}
// https://github.com/npm/rfcs/pull/183 defines which fields we put into the environment
module.exports = pkg => {
return packageEnvs({
name: pkg.name,
version: pkg.version,
config: pkg.config,
engines: pkg.engines,
bin: pkg.bin,
}, 'npm_package_')
}

112
node_modules/@npmcli/run-script/lib/run-script-pkg.js generated vendored Normal file
View file

@ -0,0 +1,112 @@
const makeSpawnArgs = require('./make-spawn-args.js')
const promiseSpawn = require('@npmcli/promise-spawn')
const packageEnvs = require('./package-envs.js')
const { isNodeGypPackage, defaultGypInstallScript } = require('@npmcli/node-gyp')
const signalManager = require('./signal-manager.js')
const isServerPackage = require('./is-server-package.js')
const runScriptPkg = async options => {
const {
event,
path,
scriptShell,
binPaths = false,
env = {},
stdio = 'pipe',
pkg,
args = [],
stdioString,
// how long to wait for a process.kill signal
// only exposed here so that we can make the test go a bit faster.
signalTimeout = 500,
} = options
const { scripts = {}, gypfile } = pkg
let cmd = null
if (options.cmd) {
cmd = options.cmd
} else if (pkg.scripts && pkg.scripts[event]) {
cmd = pkg.scripts[event]
} else if (
// If there is no preinstall or install script, default to rebuilding node-gyp packages.
event === 'install' &&
!scripts.install &&
!scripts.preinstall &&
gypfile !== false &&
await isNodeGypPackage(path)
) {
cmd = defaultGypInstallScript
} else if (event === 'start' && await isServerPackage(path)) {
cmd = 'node server.js'
}
if (!cmd) {
return { code: 0, signal: null }
}
let inputEnd = () => {}
if (stdio === 'inherit') {
let banner
if (pkg._id) {
banner = `\n> ${pkg._id} ${event}\n`
} else {
banner = `\n> ${event}\n`
}
banner += `> ${cmd.trim().replace(/\n/g, '\n> ')}`
if (args.length) {
banner += ` ${args.join(' ')}`
}
banner += '\n'
const { output, input } = require('proc-log')
output.standard(banner)
inputEnd = input.start()
}
const [spawnShell, spawnArgs, spawnOpts] = makeSpawnArgs({
event,
path,
scriptShell,
binPaths,
env: { ...env, ...packageEnvs(pkg) },
stdio,
cmd,
args,
stdioString,
})
const p = promiseSpawn(spawnShell, spawnArgs, spawnOpts, {
event,
script: cmd,
pkgid: pkg._id,
path,
})
if (stdio === 'inherit') {
signalManager.add(p.process)
}
if (p.stdin) {
p.stdin.end()
}
return p.catch(er => {
const { signal } = er
// coverage disabled because win32 never emits signals
/* istanbul ignore next */
if (stdio === 'inherit' && signal) {
// by the time we reach here, the child has already exited. we send the
// signal back to ourselves again so that npm will exit with the same
// status as the child
process.kill(process.pid, signal)
// just in case we don't die, reject after 500ms
// this also keeps the node process open long enough to actually
// get the signal, rather than terminating gracefully.
return new Promise((res, rej) => setTimeout(() => rej(er), signalTimeout))
} else {
throw er
}
}).finally(inputEnd)
}
module.exports = runScriptPkg

15
node_modules/@npmcli/run-script/lib/run-script.js generated vendored Normal file
View file

@ -0,0 +1,15 @@
const PackageJson = require('@npmcli/package-json')
const runScriptPkg = require('./run-script-pkg.js')
const validateOptions = require('./validate-options.js')
const isServerPackage = require('./is-server-package.js')
const runScript = async options => {
validateOptions(options)
if (options.pkg) {
return runScriptPkg(options)
}
const { content: pkg } = await PackageJson.normalize(options.path)
return runScriptPkg({ ...options, pkg })
}
module.exports = Object.assign(runScript, { isServerPackage })

45
node_modules/@npmcli/run-script/lib/set-path.js generated vendored Normal file
View file

@ -0,0 +1,45 @@
const { resolve, dirname, delimiter } = require('path')
// the path here is relative, even though it does not need to be
// in order to make the posix tests pass in windows
const nodeGypPath = resolve(__dirname, '../lib/node-gyp-bin')
// Windows typically calls its PATH environ 'Path', but this is not
// guaranteed, nor is it guaranteed to be the only one. Merge them
// all together in the order they appear in the object.
const setPATH = (projectPath, binPaths, env) => {
const PATH = Object.keys(env).filter(p => /^path$/i.test(p) && env[p])
.map(p => env[p].split(delimiter))
.reduce((set, p) => set.concat(p.filter(concatted => !set.includes(concatted))), [])
.join(delimiter)
const pathArr = []
if (binPaths) {
pathArr.push(...binPaths)
}
// unshift the ./node_modules/.bin from every folder
// walk up until dirname() does nothing, at the root
// XXX we should specify a cwd that we don't go above
let p = projectPath
let pp
do {
pathArr.push(resolve(p, 'node_modules', '.bin'))
pp = p
p = dirname(p)
} while (p !== pp)
pathArr.push(nodeGypPath, PATH)
const pathVal = pathArr.join(delimiter)
// XXX include the node-gyp-bin path somehow? Probably better for
// npm or arborist or whoever to just provide that by putting it in
// the PATH environ, since that's preserved anyway.
for (const key of Object.keys(env)) {
if (/^path$/i.test(key)) {
env[key] = pathVal
}
}
return env
}
module.exports = setPATH

50
node_modules/@npmcli/run-script/lib/signal-manager.js generated vendored Normal file
View file

@ -0,0 +1,50 @@
const runningProcs = new Set()
let handlersInstalled = false
const forwardedSignals = [
'SIGINT',
'SIGTERM',
]
// no-op, this is so receiving the signal doesn't cause us to exit immediately
// instead, we exit after all children have exited when we re-send the signal
// to ourselves. see the catch handler at the bottom of run-script-pkg.js
const handleSignal = signal => {
for (const proc of runningProcs) {
proc.kill(signal)
}
}
const setupListeners = () => {
for (const signal of forwardedSignals) {
process.on(signal, handleSignal)
}
handlersInstalled = true
}
const cleanupListeners = () => {
if (runningProcs.size === 0) {
for (const signal of forwardedSignals) {
process.removeListener(signal, handleSignal)
}
handlersInstalled = false
}
}
const add = proc => {
runningProcs.add(proc)
if (!handlersInstalled) {
setupListeners()
}
proc.once('exit', () => {
runningProcs.delete(proc)
cleanupListeners()
})
}
module.exports = {
add,
handleSignal,
forwardedSignals,
}

View file

@ -0,0 +1,39 @@
const validateOptions = options => {
if (typeof options !== 'object' || !options) {
throw new TypeError('invalid options object provided to runScript')
}
const {
event,
path,
scriptShell,
env = {},
stdio = 'pipe',
args = [],
cmd,
} = options
if (!event || typeof event !== 'string') {
throw new TypeError('valid event not provided to runScript')
}
if (!path || typeof path !== 'string') {
throw new TypeError('valid path not provided to runScript')
}
if (scriptShell !== undefined && typeof scriptShell !== 'string') {
throw new TypeError('invalid scriptShell option provided to runScript')
}
if (typeof env !== 'object' || !env) {
throw new TypeError('invalid env option provided to runScript')
}
if (typeof stdio !== 'string' && !Array.isArray(stdio)) {
throw new TypeError('invalid stdio option provided to runScript')
}
if (!Array.isArray(args) || args.some(a => typeof a !== 'string')) {
throw new TypeError('invalid args option provided to runScript')
}
if (cmd !== undefined && typeof cmd !== 'string') {
throw new TypeError('invalid cmd option provided to runScript')
}
}
module.exports = validateOptions

View file

@ -0,0 +1 @@
../which/bin/which.js

View file

@ -0,0 +1,15 @@
The ISC License
Copyright (c) 2016-2022 Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

View file

@ -0,0 +1,74 @@
# isexe
Minimal module to check if a file is executable, and a normal file.
Uses `fs.stat` and tests against the `PATHEXT` environment variable on
Windows.
## USAGE
```js
import { isexe, sync } from 'isexe'
// or require() works too
// const { isexe } = require('isexe')
isexe('some-file-name').then(isExe => {
if (isExe) {
console.error('this thing can be run')
} else {
console.error('cannot be run')
}
}, (err) => {
console.error('probably file doesnt exist or something')
})
// same thing but synchronous, throws errors
isExe = sync('some-file-name')
// treat errors as just "not executable"
const isExe = await isexe('maybe-missing-file', { ignoreErrors: true })
const isExe = sync('maybe-missing-file', { ignoreErrors: true })
```
## API
### `isexe(path, [options]) => Promise<boolean>`
Check if the path is executable.
Will raise whatever errors may be raised by `fs.stat`, unless
`options.ignoreErrors` is set to true.
### `sync(path, [options]) => boolean`
Same as `isexe` but returns the value and throws any errors raised.
## Platform Specific Implementations
If for some reason you want to use the implementation for a
specific platform, you can do that.
```js
import { win32, posix } from 'isexe'
win32.isexe(...)
win32.sync(...)
// etc
// or:
import { isexe, sync } from 'isexe/posix'
```
The default exported implementation will be chosen based on
`process.platform`.
### Options
```ts
import type IsexeOptions from 'isexe'
```
* `ignoreErrors` Treat all errors as "no, this is not
executable", but don't raise them.
* `uid` Number to use as the user id on posix
* `gid` Number to use as the group id on posix
* `pathExt` List of path extensions to use instead of `PATHEXT`
environment variable on Windows.

View file

@ -0,0 +1,14 @@
import * as posix from './posix.js';
import * as win32 from './win32.js';
export * from './options.js';
export { win32, posix };
/**
* Determine whether a path is executable on the current platform.
*/
export declare const isexe: (path: string, options?: import("./options.js").IsexeOptions) => Promise<boolean>;
/**
* Synchronously determine whether a path is executable on the
* current platform.
*/
export declare const sync: (path: string, options?: import("./options.js").IsexeOptions) => boolean;
//# sourceMappingURL=index.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AAKvB;;GAEG;AACH,eAAO,MAAM,KAAK,mFAAa,CAAA;AAC/B;;;GAGG;AACH,eAAO,MAAM,IAAI,0EAAY,CAAA"}

View file

@ -0,0 +1,46 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sync = exports.isexe = exports.posix = exports.win32 = void 0;
const posix = __importStar(require("./posix.js"));
exports.posix = posix;
const win32 = __importStar(require("./win32.js"));
exports.win32 = win32;
__exportStar(require("./options.js"), exports);
const platform = process.env._ISEXE_TEST_PLATFORM_ || process.platform;
const impl = platform === 'win32' ? win32 : posix;
/**
* Determine whether a path is executable on the current platform.
*/
exports.isexe = impl.isexe;
/**
* Synchronously determine whether a path is executable on the
* current platform.
*/
exports.sync = impl.sync;
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAmC;AAGnB,sBAAK;AAFrB,kDAAmC;AAE1B,sBAAK;AADd,+CAA4B;AAG5B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,OAAO,CAAC,QAAQ,CAAA;AACtE,MAAM,IAAI,GAAG,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;AAEjD;;GAEG;AACU,QAAA,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;AAC/B;;;GAGG;AACU,QAAA,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA","sourcesContent":["import * as posix from './posix.js'\nimport * as win32 from './win32.js'\nexport * from './options.js'\nexport { win32, posix }\n\nconst platform = process.env._ISEXE_TEST_PLATFORM_ || process.platform\nconst impl = platform === 'win32' ? win32 : posix\n\n/**\n * Determine whether a path is executable on the current platform.\n */\nexport const isexe = impl.isexe\n/**\n * Synchronously determine whether a path is executable on the\n * current platform.\n */\nexport const sync = impl.sync\n"]}

View file

@ -0,0 +1,32 @@
export interface IsexeOptions {
/**
* Ignore errors arising from attempting to get file access status
* Note that EACCES is always ignored, because that just means
* it's not executable. If this is not set, then attempting to check
* the executable-ness of a nonexistent file will raise ENOENT, for
* example.
*/
ignoreErrors?: boolean;
/**
* effective uid when checking executable mode flags on posix
* Defaults to process.getuid()
*/
uid?: number;
/**
* effective gid when checking executable mode flags on posix
* Defaults to process.getgid()
*/
gid?: number;
/**
* effective group ID list to use when checking executable mode flags
* on posix
* Defaults to process.getgroups()
*/
groups?: number[];
/**
* The ;-delimited path extension list for win32 implementation.
* Defaults to process.env.PATHEXT
*/
pathExt?: string;
}
//# sourceMappingURL=options.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IAEtB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB"}

View file

@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=options.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":"","sourcesContent":["export interface IsexeOptions {\n /**\n * Ignore errors arising from attempting to get file access status\n * Note that EACCES is always ignored, because that just means\n * it's not executable. If this is not set, then attempting to check\n * the executable-ness of a nonexistent file will raise ENOENT, for\n * example.\n */\n ignoreErrors?: boolean\n\n /**\n * effective uid when checking executable mode flags on posix\n * Defaults to process.getuid()\n */\n uid?: number\n\n /**\n * effective gid when checking executable mode flags on posix\n * Defaults to process.getgid()\n */\n gid?: number\n\n /**\n * effective group ID list to use when checking executable mode flags\n * on posix\n * Defaults to process.getgroups()\n */\n groups?: number[]\n\n /**\n * The ;-delimited path extension list for win32 implementation.\n * Defaults to process.env.PATHEXT\n */\n pathExt?: string\n}\n"]}

View file

@ -0,0 +1,3 @@
{
"type": "commonjs"
}

View file

@ -0,0 +1,18 @@
/**
* This is the Posix implementation of isexe, which uses the file
* mode and uid/gid values.
*
* @module
*/
import { IsexeOptions } from './options';
/**
* Determine whether a path is executable according to the mode and
* current (or specified) user and group IDs.
*/
export declare const isexe: (path: string, options?: IsexeOptions) => Promise<boolean>;
/**
* Synchronously determine whether a path is executable according to
* the mode and current (or specified) user and group IDs.
*/
export declare const sync: (path: string, options?: IsexeOptions) => boolean;
//# sourceMappingURL=posix.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"posix.d.ts","sourceRoot":"","sources":["../../src/posix.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC;;;GAGG;AACH,eAAO,MAAM,KAAK,SACV,MAAM,YACH,YAAY,KACpB,QAAQ,OAAO,CASjB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,SACT,MAAM,YACH,YAAY,KACpB,OASF,CAAA"}

View file

@ -0,0 +1,67 @@
"use strict";
/**
* This is the Posix implementation of isexe, which uses the file
* mode and uid/gid values.
*
* @module
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.sync = exports.isexe = void 0;
const fs_1 = require("fs");
const promises_1 = require("fs/promises");
/**
* Determine whether a path is executable according to the mode and
* current (or specified) user and group IDs.
*/
const isexe = async (path, options = {}) => {
const { ignoreErrors = false } = options;
try {
return checkStat(await (0, promises_1.stat)(path), options);
}
catch (e) {
const er = e;
if (ignoreErrors || er.code === 'EACCES')
return false;
throw er;
}
};
exports.isexe = isexe;
/**
* Synchronously determine whether a path is executable according to
* the mode and current (or specified) user and group IDs.
*/
const sync = (path, options = {}) => {
const { ignoreErrors = false } = options;
try {
return checkStat((0, fs_1.statSync)(path), options);
}
catch (e) {
const er = e;
if (ignoreErrors || er.code === 'EACCES')
return false;
throw er;
}
};
exports.sync = sync;
const checkStat = (stat, options) => stat.isFile() && checkMode(stat, options);
const checkMode = (stat, options) => {
const myUid = options.uid ?? process.getuid?.();
const myGroups = options.groups ?? process.getgroups?.() ?? [];
const myGid = options.gid ?? process.getgid?.() ?? myGroups[0];
if (myUid === undefined || myGid === undefined) {
throw new Error('cannot get uid or gid');
}
const groups = new Set([myGid, ...myGroups]);
const mod = stat.mode;
const uid = stat.uid;
const gid = stat.gid;
const u = parseInt('100', 8);
const g = parseInt('010', 8);
const o = parseInt('001', 8);
const ug = u | g;
return !!(mod & o ||
(mod & g && groups.has(gid)) ||
(mod & u && uid === myUid) ||
(mod & ug && myUid === 0));
};
//# sourceMappingURL=posix.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"posix.js","sourceRoot":"","sources":["../../src/posix.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2BAAoC;AACpC,0CAAkC;AAGlC;;;GAGG;AACI,MAAM,KAAK,GAAG,KAAK,EACxB,IAAY,EACZ,UAAwB,EAAE,EACR,EAAE;IACpB,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,GAAG,OAAO,CAAA;IACxC,IAAI;QACF,OAAO,SAAS,CAAC,MAAM,IAAA,eAAI,EAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAA;KAC5C;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,EAAE,GAAG,CAA0B,CAAA;QACrC,IAAI,YAAY,IAAI,EAAE,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAA;QACtD,MAAM,EAAE,CAAA;KACT;AACH,CAAC,CAAA;AAZY,QAAA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GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;IACpB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;IAEpB,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC5B,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC5B,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC5B,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;IAEhB,OAAO,CAAC,CAAC,CACP,GAAG,GAAG,CAAC;QACP,CAAC,GAAG,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC,GAAG,GAAG,CAAC,IAAI,GAAG,KAAK,KAAK,CAAC;QAC1B,CAAC,GAAG,GAAG,EAAE,IAAI,KAAK,KAAK,CAAC,CAAC,CAC1B,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\n * This is the Posix implementation of isexe, which uses the file\n * mode and uid/gid values.\n *\n * @module\n */\n\nimport { Stats, statSync } from 'fs'\nimport { stat } from 'fs/promises'\nimport { IsexeOptions } from './options'\n\n/**\n * Determine whether a path is executable according to the mode and\n * current (or specified) user and group IDs.\n */\nexport const isexe = async (\n path: string,\n options: IsexeOptions = {}\n): Promise<boolean> => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(await stat(path), options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\n/**\n * Synchronously determine whether a path is executable according to\n * the mode and current (or specified) user and group IDs.\n */\nexport const sync = (\n path: string,\n options: IsexeOptions = {}\n): boolean => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(statSync(path), options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\nconst checkStat = (stat: Stats, options: IsexeOptions) =>\n stat.isFile() && checkMode(stat, options)\n\nconst checkMode = (stat: Stats, options: IsexeOptions) => {\n const myUid = options.uid ?? process.getuid?.()\n const myGroups = options.groups ?? process.getgroups?.() ?? []\n const myGid = options.gid ?? process.getgid?.() ?? myGroups[0]\n if (myUid === undefined || myGid === undefined) {\n throw new Error('cannot get uid or gid')\n }\n\n const groups = new Set([myGid, ...myGroups])\n\n const mod = stat.mode\n const uid = stat.uid\n const gid = stat.gid\n\n const u = parseInt('100', 8)\n const g = parseInt('010', 8)\n const o = parseInt('001', 8)\n const ug = u | g\n\n return !!(\n mod & o ||\n (mod & g && groups.has(gid)) ||\n (mod & u && uid === myUid) ||\n (mod & ug && myUid === 0)\n )\n}\n"]}

View file

@ -0,0 +1,18 @@
/**
* This is the Windows implementation of isexe, which uses the file
* extension and PATHEXT setting.
*
* @module
*/
import { IsexeOptions } from './options';
/**
* Determine whether a path is executable based on the file extension
* and PATHEXT environment variable (or specified pathExt option)
*/
export declare const isexe: (path: string, options?: IsexeOptions) => Promise<boolean>;
/**
* Synchronously determine whether a path is executable based on the file
* extension and PATHEXT environment variable (or specified pathExt option)
*/
export declare const sync: (path: string, options?: IsexeOptions) => boolean;
//# sourceMappingURL=win32.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"win32.d.ts","sourceRoot":"","sources":["../../src/win32.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC;;;GAGG;AACH,eAAO,MAAM,KAAK,SACV,MAAM,YACH,YAAY,KACpB,QAAQ,OAAO,CASjB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,SACT,MAAM,YACH,YAAY,KACpB,OASF,CAAA"}

View file

@ -0,0 +1,62 @@
"use strict";
/**
* This is the Windows implementation of isexe, which uses the file
* extension and PATHEXT setting.
*
* @module
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.sync = exports.isexe = void 0;
const fs_1 = require("fs");
const promises_1 = require("fs/promises");
/**
* Determine whether a path is executable based on the file extension
* and PATHEXT environment variable (or specified pathExt option)
*/
const isexe = async (path, options = {}) => {
const { ignoreErrors = false } = options;
try {
return checkStat(await (0, promises_1.stat)(path), path, options);
}
catch (e) {
const er = e;
if (ignoreErrors || er.code === 'EACCES')
return false;
throw er;
}
};
exports.isexe = isexe;
/**
* Synchronously determine whether a path is executable based on the file
* extension and PATHEXT environment variable (or specified pathExt option)
*/
const sync = (path, options = {}) => {
const { ignoreErrors = false } = options;
try {
return checkStat((0, fs_1.statSync)(path), path, options);
}
catch (e) {
const er = e;
if (ignoreErrors || er.code === 'EACCES')
return false;
throw er;
}
};
exports.sync = sync;
const checkPathExt = (path, options) => {
const { pathExt = process.env.PATHEXT || '' } = options;
const peSplit = pathExt.split(';');
if (peSplit.indexOf('') !== -1) {
return true;
}
for (let i = 0; i < peSplit.length; i++) {
const p = peSplit[i].toLowerCase();
const ext = path.substring(path.length - p.length).toLowerCase();
if (p && ext === p) {
return true;
}
}
return false;
};
const checkStat = (stat, path, options) => stat.isFile() && checkPathExt(path, options);
//# sourceMappingURL=win32.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"win32.js","sourceRoot":"","sources":["../../src/win32.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2BAAoC;AACpC,0CAAkC;AAGlC;;;GAGG;AACI,MAAM,KAAK,GAAG,KAAK,EACxB,IAAY,EACZ,UAAwB,EAAE,EACR,EAAE;IACpB,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,GAAG,OAAO,CAAA;IACxC,IAAI;QACF,OAAO,SAAS,CAAC,MAAM,IAAA,eAAI,EAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;KAClD;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,EAAE,GAAG,CAA0B,CAAA;QACrC,IAAI,YAAY,IAAI,EAAE,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAA;QACt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O,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,CAAC,IAAW,EAAE,IAAY,EAAE,OAAqB,EAAE,EAAE,CACrE,IAAI,CAAC,MAAM,EAAE,IAAI,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA","sourcesContent":["/**\n * This is the Windows implementation of isexe, which uses the file\n * extension and PATHEXT setting.\n *\n * @module\n */\n\nimport { Stats, statSync } from 'fs'\nimport { stat } from 'fs/promises'\nimport { IsexeOptions } from './options'\n\n/**\n * Determine whether a path is executable based on the file extension\n * and PATHEXT environment variable (or specified pathExt option)\n */\nexport const isexe = async (\n path: string,\n options: IsexeOptions = {}\n): Promise<boolean> => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(await stat(path), path, options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\n/**\n * Synchronously determine whether a path is executable based on the file\n * extension and PATHEXT environment variable (or specified pathExt option)\n */\nexport const sync = (\n path: string,\n options: IsexeOptions = {}\n): boolean => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(statSync(path), path, options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\nconst checkPathExt = (path: string, options: IsexeOptions) => {\n const { pathExt = process.env.PATHEXT || '' } = options\n const peSplit = pathExt.split(';')\n if (peSplit.indexOf('') !== -1) {\n return true\n }\n\n for (let i = 0; i < peSplit.length; i++) {\n const p = peSplit[i].toLowerCase()\n const ext = path.substring(path.length - p.length).toLowerCase()\n\n if (p && ext === p) {\n return true\n }\n }\n return false\n}\n\nconst checkStat = (stat: Stats, path: string, options: IsexeOptions) =>\n stat.isFile() && checkPathExt(path, options)\n"]}

View file

@ -0,0 +1,14 @@
import * as posix from './posix.js';
import * as win32 from './win32.js';
export * from './options.js';
export { win32, posix };
/**
* Determine whether a path is executable on the current platform.
*/
export declare const isexe: (path: string, options?: import("./options.js").IsexeOptions) => Promise<boolean>;
/**
* Synchronously determine whether a path is executable on the
* current platform.
*/
export declare const sync: (path: string, options?: import("./options.js").IsexeOptions) => boolean;
//# sourceMappingURL=index.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AAKvB;;GAEG;AACH,eAAO,MAAM,KAAK,mFAAa,CAAA;AAC/B;;;GAGG;AACH,eAAO,MAAM,IAAI,0EAAY,CAAA"}

View file

@ -0,0 +1,16 @@
import * as posix from './posix.js';
import * as win32 from './win32.js';
export * from './options.js';
export { win32, posix };
const platform = process.env._ISEXE_TEST_PLATFORM_ || process.platform;
const impl = platform === 'win32' ? win32 : posix;
/**
* Determine whether a path is executable on the current platform.
*/
export const isexe = impl.isexe;
/**
* Synchronously determine whether a path is executable on the
* current platform.
*/
export const sync = impl.sync;
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AAEvB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,OAAO,CAAC,QAAQ,CAAA;AACtE,MAAM,IAAI,GAAG,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;AAC/B;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA","sourcesContent":["import * as posix from './posix.js'\nimport * as win32 from './win32.js'\nexport * from './options.js'\nexport { win32, posix }\n\nconst platform = process.env._ISEXE_TEST_PLATFORM_ || process.platform\nconst impl = platform === 'win32' ? win32 : posix\n\n/**\n * Determine whether a path is executable on the current platform.\n */\nexport const isexe = impl.isexe\n/**\n * Synchronously determine whether a path is executable on the\n * current platform.\n */\nexport const sync = impl.sync\n"]}

View file

@ -0,0 +1,32 @@
export interface IsexeOptions {
/**
* Ignore errors arising from attempting to get file access status
* Note that EACCES is always ignored, because that just means
* it's not executable. If this is not set, then attempting to check
* the executable-ness of a nonexistent file will raise ENOENT, for
* example.
*/
ignoreErrors?: boolean;
/**
* effective uid when checking executable mode flags on posix
* Defaults to process.getuid()
*/
uid?: number;
/**
* effective gid when checking executable mode flags on posix
* Defaults to process.getgid()
*/
gid?: number;
/**
* effective group ID list to use when checking executable mode flags
* on posix
* Defaults to process.getgroups()
*/
groups?: number[];
/**
* The ;-delimited path extension list for win32 implementation.
* Defaults to process.env.PATHEXT
*/
pathExt?: string;
}
//# sourceMappingURL=options.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IAEtB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB"}

View file

@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=options.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":"","sourcesContent":["export interface IsexeOptions {\n /**\n * Ignore errors arising from attempting to get file access status\n * Note that EACCES is always ignored, because that just means\n * it's not executable. If this is not set, then attempting to check\n * the executable-ness of a nonexistent file will raise ENOENT, for\n * example.\n */\n ignoreErrors?: boolean\n\n /**\n * effective uid when checking executable mode flags on posix\n * Defaults to process.getuid()\n */\n uid?: number\n\n /**\n * effective gid when checking executable mode flags on posix\n * Defaults to process.getgid()\n */\n gid?: number\n\n /**\n * effective group ID list to use when checking executable mode flags\n * on posix\n * Defaults to process.getgroups()\n */\n groups?: number[]\n\n /**\n * The ;-delimited path extension list for win32 implementation.\n * Defaults to process.env.PATHEXT\n */\n pathExt?: string\n}\n"]}

View file

@ -0,0 +1,3 @@
{
"type": "module"
}

View file

@ -0,0 +1,18 @@
/**
* This is the Posix implementation of isexe, which uses the file
* mode and uid/gid values.
*
* @module
*/
import { IsexeOptions } from './options';
/**
* Determine whether a path is executable according to the mode and
* current (or specified) user and group IDs.
*/
export declare const isexe: (path: string, options?: IsexeOptions) => Promise<boolean>;
/**
* Synchronously determine whether a path is executable according to
* the mode and current (or specified) user and group IDs.
*/
export declare const sync: (path: string, options?: IsexeOptions) => boolean;
//# sourceMappingURL=posix.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"posix.d.ts","sourceRoot":"","sources":["../../src/posix.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC;;;GAGG;AACH,eAAO,MAAM,KAAK,SACV,MAAM,YACH,YAAY,KACpB,QAAQ,OAAO,CASjB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,SACT,MAAM,YACH,YAAY,KACpB,OASF,CAAA"}

View file

@ -0,0 +1,62 @@
/**
* This is the Posix implementation of isexe, which uses the file
* mode and uid/gid values.
*
* @module
*/
import { statSync } from 'fs';
import { stat } from 'fs/promises';
/**
* Determine whether a path is executable according to the mode and
* current (or specified) user and group IDs.
*/
export const isexe = async (path, options = {}) => {
const { ignoreErrors = false } = options;
try {
return checkStat(await stat(path), options);
}
catch (e) {
const er = e;
if (ignoreErrors || er.code === 'EACCES')
return false;
throw er;
}
};
/**
* Synchronously determine whether a path is executable according to
* the mode and current (or specified) user and group IDs.
*/
export const sync = (path, options = {}) => {
const { ignoreErrors = false } = options;
try {
return checkStat(statSync(path), options);
}
catch (e) {
const er = e;
if (ignoreErrors || er.code === 'EACCES')
return false;
throw er;
}
};
const checkStat = (stat, options) => stat.isFile() && checkMode(stat, options);
const checkMode = (stat, options) => {
const myUid = options.uid ?? process.getuid?.();
const myGroups = options.groups ?? process.getgroups?.() ?? [];
const myGid = options.gid ?? process.getgid?.() ?? myGroups[0];
if (myUid === undefined || myGid === undefined) {
throw new Error('cannot get uid or gid');
}
const groups = new Set([myGid, ...myGroups]);
const mod = stat.mode;
const uid = stat.uid;
const gid = stat.gid;
const u = parseInt('100', 8);
const g = parseInt('010', 8);
const o = parseInt('001', 8);
const ug = u | g;
return !!(mod & o ||
(mod & g && groups.has(gid)) ||
(mod & u && uid === myUid) ||
(mod & ug && myUid === 0));
};
//# sourceMappingURL=posix.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"posix.js","sourceRoot":"","sources":["../../src/posix.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAS,QAAQ,EAAE,MAAM,IAAI,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGlC;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EACxB,IAAY,EACZ,UAAwB,EAAE,EACR,EAAE;IACpB,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,GAAG,OAAO,CAAA;IACxC,IAAI;QACF,OAAO,SAAS,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAA;KAC5C;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,EAAE,GAA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C,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAA;IAE5C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAA;IACrB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;IACpB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;IAEpB,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC5B,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC5B,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC5B,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;IAEhB,OAAO,CAAC,CAAC,CACP,GAAG,GAAG,CAAC;QACP,CAAC,GAAG,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC,GAAG,GAAG,CAAC,IAAI,GAAG,KAAK,KAAK,CAAC;QAC1B,CAAC,GAAG,GAAG,EAAE,IAAI,KAAK,KAAK,CAAC,CAAC,CAC1B,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\n * This is the Posix implementation of isexe, which uses the file\n * mode and uid/gid values.\n *\n * @module\n */\n\nimport { Stats, statSync } from 'fs'\nimport { stat } from 'fs/promises'\nimport { IsexeOptions } from './options'\n\n/**\n * Determine whether a path is executable according to the mode and\n * current (or specified) user and group IDs.\n */\nexport const isexe = async (\n path: string,\n options: IsexeOptions = {}\n): Promise<boolean> => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(await stat(path), options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\n/**\n * Synchronously determine whether a path is executable according to\n * the mode and current (or specified) user and group IDs.\n */\nexport const sync = (\n path: string,\n options: IsexeOptions = {}\n): boolean => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(statSync(path), options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\nconst checkStat = (stat: Stats, options: IsexeOptions) =>\n stat.isFile() && checkMode(stat, options)\n\nconst checkMode = (stat: Stats, options: IsexeOptions) => {\n const myUid = options.uid ?? process.getuid?.()\n const myGroups = options.groups ?? process.getgroups?.() ?? []\n const myGid = options.gid ?? process.getgid?.() ?? myGroups[0]\n if (myUid === undefined || myGid === undefined) {\n throw new Error('cannot get uid or gid')\n }\n\n const groups = new Set([myGid, ...myGroups])\n\n const mod = stat.mode\n const uid = stat.uid\n const gid = stat.gid\n\n const u = parseInt('100', 8)\n const g = parseInt('010', 8)\n const o = parseInt('001', 8)\n const ug = u | g\n\n return !!(\n mod & o ||\n (mod & g && groups.has(gid)) ||\n (mod & u && uid === myUid) ||\n (mod & ug && myUid === 0)\n )\n}\n"]}

View file

@ -0,0 +1,18 @@
/**
* This is the Windows implementation of isexe, which uses the file
* extension and PATHEXT setting.
*
* @module
*/
import { IsexeOptions } from './options';
/**
* Determine whether a path is executable based on the file extension
* and PATHEXT environment variable (or specified pathExt option)
*/
export declare const isexe: (path: string, options?: IsexeOptions) => Promise<boolean>;
/**
* Synchronously determine whether a path is executable based on the file
* extension and PATHEXT environment variable (or specified pathExt option)
*/
export declare const sync: (path: string, options?: IsexeOptions) => boolean;
//# sourceMappingURL=win32.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"win32.d.ts","sourceRoot":"","sources":["../../src/win32.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC;;;GAGG;AACH,eAAO,MAAM,KAAK,SACV,MAAM,YACH,YAAY,KACpB,QAAQ,OAAO,CASjB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,SACT,MAAM,YACH,YAAY,KACpB,OASF,CAAA"}

View file

@ -0,0 +1,57 @@
/**
* This is the Windows implementation of isexe, which uses the file
* extension and PATHEXT setting.
*
* @module
*/
import { statSync } from 'fs';
import { stat } from 'fs/promises';
/**
* Determine whether a path is executable based on the file extension
* and PATHEXT environment variable (or specified pathExt option)
*/
export const isexe = async (path, options = {}) => {
const { ignoreErrors = false } = options;
try {
return checkStat(await stat(path), path, options);
}
catch (e) {
const er = e;
if (ignoreErrors || er.code === 'EACCES')
return false;
throw er;
}
};
/**
* Synchronously determine whether a path is executable based on the file
* extension and PATHEXT environment variable (or specified pathExt option)
*/
export const sync = (path, options = {}) => {
const { ignoreErrors = false } = options;
try {
return checkStat(statSync(path), path, options);
}
catch (e) {
const er = e;
if (ignoreErrors || er.code === 'EACCES')
return false;
throw er;
}
};
const checkPathExt = (path, options) => {
const { pathExt = process.env.PATHEXT || '' } = options;
const peSplit = pathExt.split(';');
if (peSplit.indexOf('') !== -1) {
return true;
}
for (let i = 0; i < peSplit.length; i++) {
const p = peSplit[i].toLowerCase();
const ext = path.substring(path.length - p.length).toLowerCase();
if (p && ext === p) {
return true;
}
}
return false;
};
const checkStat = (stat, path, options) => stat.isFile() && checkPathExt(path, options);
//# sourceMappingURL=win32.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"win32.js","sourceRoot":"","sources":["../../src/win32.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAS,QAAQ,EAAE,MAAM,IAAI,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAGlC;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EACxB,IAAY,EACZ,UAAwB,EAAE,EACR,EAAE;IACpB,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,GAAG,OAAO,CAAA;IACxC,IAAI;QACF,OAAO,SAAS,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;KAClD;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,EAAE,GAAG,CAA0B,CAAA;QACrC,I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IAAI,CAAA;SACZ;KACF;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,CAAC,IAAW,EAAE,IAAY,EAAE,OAAqB,EAAE,EAAE,CACrE,IAAI,CAAC,MAAM,EAAE,IAAI,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA","sourcesContent":["/**\n * This is the Windows implementation of isexe, which uses the file\n * extension and PATHEXT setting.\n *\n * @module\n */\n\nimport { Stats, statSync } from 'fs'\nimport { stat } from 'fs/promises'\nimport { IsexeOptions } from './options'\n\n/**\n * Determine whether a path is executable based on the file extension\n * and PATHEXT environment variable (or specified pathExt option)\n */\nexport const isexe = async (\n path: string,\n options: IsexeOptions = {}\n): Promise<boolean> => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(await stat(path), path, options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\n/**\n * Synchronously determine whether a path is executable based on the file\n * extension and PATHEXT environment variable (or specified pathExt option)\n */\nexport const sync = (\n path: string,\n options: IsexeOptions = {}\n): boolean => {\n const { ignoreErrors = false } = options\n try {\n return checkStat(statSync(path), path, options)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (ignoreErrors || er.code === 'EACCES') return false\n throw er\n }\n}\n\nconst checkPathExt = (path: string, options: IsexeOptions) => {\n const { pathExt = process.env.PATHEXT || '' } = options\n const peSplit = pathExt.split(';')\n if (peSplit.indexOf('') !== -1) {\n return true\n }\n\n for (let i = 0; i < peSplit.length; i++) {\n const p = peSplit[i].toLowerCase()\n const ext = path.substring(path.length - p.length).toLowerCase()\n\n if (p && ext === p) {\n return true\n }\n }\n return false\n}\n\nconst checkStat = (stat: Stats, path: string, options: IsexeOptions) =>\n stat.isFile() && checkPathExt(path, options)\n"]}

View file

@ -0,0 +1,96 @@
{
"name": "isexe",
"version": "3.1.1",
"description": "Minimal module to check if a file is executable.",
"main": "./dist/cjs/index.js",
"module": "./dist/mjs/index.js",
"types": "./dist/cjs/index.js",
"files": [
"dist"
],
"exports": {
".": {
"import": {
"types": "./dist/mjs/index.d.ts",
"default": "./dist/mjs/index.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
},
"./posix": {
"import": {
"types": "./dist/mjs/posix.d.ts",
"default": "./dist/mjs/posix.js"
},
"require": {
"types": "./dist/cjs/posix.d.ts",
"default": "./dist/cjs/posix.js"
}
},
"./win32": {
"import": {
"types": "./dist/mjs/win32.d.ts",
"default": "./dist/mjs/win32.js"
},
"require": {
"types": "./dist/cjs/win32.d.ts",
"default": "./dist/cjs/win32.js"
}
},
"./package.json": "./package.json"
},
"devDependencies": {
"@types/node": "^20.4.5",
"@types/tap": "^15.0.8",
"c8": "^8.0.1",
"mkdirp": "^0.5.1",
"prettier": "^2.8.8",
"rimraf": "^2.5.0",
"sync-content": "^1.0.2",
"tap": "^16.3.8",
"ts-node": "^10.9.1",
"typedoc": "^0.24.8",
"typescript": "^5.1.6"
},
"scripts": {
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"prepare": "tsc -p tsconfig/cjs.json && tsc -p tsconfig/esm.json && bash ./scripts/fixup.sh",
"pretest": "npm run prepare",
"presnap": "npm run prepare",
"test": "c8 tap",
"snap": "c8 tap",
"format": "prettier --write . --loglevel warn --ignore-path ../../.prettierignore --cache",
"typedoc": "typedoc --tsconfig tsconfig/esm.json ./src/*.ts"
},
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
"license": "ISC",
"tap": {
"coverage": false,
"node-arg": [
"--enable-source-maps",
"--no-warnings",
"--loader",
"ts-node/esm"
],
"ts": false
},
"prettier": {
"semi": false,
"printWidth": 75,
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"jsxSingleQuote": false,
"bracketSameLine": true,
"arrowParens": "avoid",
"endOfLine": "lf"
},
"repository": "https://github.com/isaacs/isexe",
"engines": {
"node": ">=16"
}
}

View file

@ -0,0 +1,15 @@
The ISC License
Copyright (c) Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

View file

@ -0,0 +1,51 @@
# which
Like the unix `which` utility.
Finds the first instance of a specified executable in the PATH
environment variable. Does not cache the results, so `hash -r` is not
needed when the PATH changes.
## USAGE
```javascript
const which = require('which')
// async usage
// rejects if not found
const resolved = await which('node')
// if nothrow option is used, returns null if not found
const resolvedOrNull = await which('node', { nothrow: true })
// sync usage
// throws if not found
const resolved = which.sync('node')
// if nothrow option is used, returns null if not found
const resolvedOrNull = which.sync('node', { nothrow: true })
// Pass options to override the PATH and PATHEXT environment vars.
await which('node', { path: someOtherPath, pathExt: somePathExt })
```
## CLI USAGE
Just like the BSD `which(1)` binary but using `node-which`.
```
usage: node-which [-as] program ...
```
You can learn more about why the binary is `node-which` and not `which`
[here](https://github.com/npm/node-which/pull/67)
## OPTIONS
You may pass an options object as the second argument.
- `path`: Use instead of the `PATH` environment variable.
- `pathExt`: Use instead of the `PATHEXT` environment variable.
- `all`: Return all matches, instead of just the first one. Note that
this means the function returns an array of strings instead of a
single string.

View file

@ -0,0 +1,52 @@
#!/usr/bin/env node
const which = require('../lib')
const argv = process.argv.slice(2)
const usage = (err) => {
if (err) {
console.error(`which: ${err}`)
}
console.error('usage: which [-as] program ...')
process.exit(1)
}
if (!argv.length) {
return usage()
}
let dashdash = false
const [commands, flags] = argv.reduce((acc, arg) => {
if (dashdash || arg === '--') {
dashdash = true
return acc
}
if (!/^-/.test(arg)) {
acc[0].push(arg)
return acc
}
for (const flag of arg.slice(1).split('')) {
if (flag === 's') {
acc[1].silent = true
} else if (flag === 'a') {
acc[1].all = true
} else {
usage(`illegal option -- ${flag}`)
}
}
return acc
}, [[], {}])
for (const command of commands) {
try {
const res = which.sync(command, { all: flags.all })
if (!flags.silent) {
console.log([].concat(res).join('\n'))
}
} catch (err) {
process.exitCode = 1
}
}

View file

@ -0,0 +1,111 @@
const { isexe, sync: isexeSync } = require('isexe')
const { join, delimiter, sep, posix } = require('path')
const isWindows = process.platform === 'win32'
// used to check for slashed in commands passed in. always checks for the posix
// seperator on all platforms, and checks for the current separator when not on
// a posix platform. don't use the isWindows check for this since that is mocked
// in tests but we still need the code to actually work when called. that is also
// why it is ignored from coverage.
/* istanbul ignore next */
const rSlash = new RegExp(`[${posix.sep}${sep === posix.sep ? '' : sep}]`.replace(/(\\)/g, '\\$1'))
const rRel = new RegExp(`^\\.${rSlash.source}`)
const getNotFoundError = (cmd) =>
Object.assign(new Error(`not found: ${cmd}`), { code: 'ENOENT' })
const getPathInfo = (cmd, {
path: optPath = process.env.PATH,
pathExt: optPathExt = process.env.PATHEXT,
delimiter: optDelimiter = delimiter,
}) => {
// If it has a slash, then we don't bother searching the pathenv.
// just check the file itself, and that's it.
const pathEnv = cmd.match(rSlash) ? [''] : [
// windows always checks the cwd first
...(isWindows ? [process.cwd()] : []),
...(optPath || /* istanbul ignore next: very unusual */ '').split(optDelimiter),
]
if (isWindows) {
const pathExtExe = optPathExt ||
['.EXE', '.CMD', '.BAT', '.COM'].join(optDelimiter)
const pathExt = pathExtExe.split(optDelimiter).flatMap((item) => [item, item.toLowerCase()])
if (cmd.includes('.') && pathExt[0] !== '') {
pathExt.unshift('')
}
return { pathEnv, pathExt, pathExtExe }
}
return { pathEnv, pathExt: [''] }
}
const getPathPart = (raw, cmd) => {
const pathPart = /^".*"$/.test(raw) ? raw.slice(1, -1) : raw
const prefix = !pathPart && rRel.test(cmd) ? cmd.slice(0, 2) : ''
return prefix + join(pathPart, cmd)
}
const which = async (cmd, opt = {}) => {
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt)
const found = []
for (const envPart of pathEnv) {
const p = getPathPart(envPart, cmd)
for (const ext of pathExt) {
const withExt = p + ext
const is = await isexe(withExt, { pathExt: pathExtExe, ignoreErrors: true })
if (is) {
if (!opt.all) {
return withExt
}
found.push(withExt)
}
}
}
if (opt.all && found.length) {
return found
}
if (opt.nothrow) {
return null
}
throw getNotFoundError(cmd)
}
const whichSync = (cmd, opt = {}) => {
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt)
const found = []
for (const pathEnvPart of pathEnv) {
const p = getPathPart(pathEnvPart, cmd)
for (const ext of pathExt) {
const withExt = p + ext
const is = isexeSync(withExt, { pathExt: pathExtExe, ignoreErrors: true })
if (is) {
if (!opt.all) {
return withExt
}
found.push(withExt)
}
}
}
if (opt.all && found.length) {
return found
}
if (opt.nothrow) {
return null
}
throw getNotFoundError(cmd)
}
module.exports = which
which.sync = whichSync

View file

@ -0,0 +1,57 @@
{
"author": "GitHub Inc.",
"name": "which",
"description": "Like which(1) unix command. Find the first instance of an executable in the PATH.",
"version": "4.0.0",
"repository": {
"type": "git",
"url": "https://github.com/npm/node-which.git"
},
"main": "lib/index.js",
"bin": {
"node-which": "./bin/which.js"
},
"license": "ISC",
"dependencies": {
"isexe": "^3.1.1"
},
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.18.0",
"tap": "^16.3.0"
},
"scripts": {
"test": "tap",
"lint": "eslint \"**/*.js\"",
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"snap": "tap",
"posttest": "npm run lint"
},
"files": [
"bin/",
"lib/"
],
"tap": {
"check-coverage": true,
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
},
"engines": {
"node": "^16.13.0 || >=18.0.0"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"ciVersions": [
"16.13.0",
"16.x",
"18.0.0",
"18.x"
],
"version": "4.18.0",
"publish": "true"
}
}

54
node_modules/@npmcli/run-script/package.json generated vendored Normal file
View file

@ -0,0 +1,54 @@
{
"name": "@npmcli/run-script",
"version": "8.1.0",
"description": "Run a lifecycle script for a package (descendant of npm-lifecycle)",
"author": "GitHub Inc.",
"license": "ISC",
"scripts": {
"test": "tap",
"eslint": "eslint",
"lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
"lintfix": "npm run lint -- --fix",
"postlint": "template-oss-check",
"snap": "tap",
"posttest": "npm run lint",
"template-oss-apply": "template-oss-apply --force"
},
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.21.4",
"spawk": "^1.8.1",
"tap": "^16.0.1"
},
"dependencies": {
"@npmcli/node-gyp": "^3.0.0",
"@npmcli/package-json": "^5.0.0",
"@npmcli/promise-spawn": "^7.0.0",
"node-gyp": "^10.0.0",
"proc-log": "^4.0.0",
"which": "^4.0.0"
},
"files": [
"bin/",
"lib/"
],
"main": "lib/run-script.js",
"repository": {
"type": "git",
"url": "https://github.com/npm/run-script.git"
},
"engines": {
"node": "^16.14.0 || >=18.0.0"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.21.4",
"publish": "true"
},
"tap": {
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
}
}