feat(frontend): implement all views using Svelte 5 runes and TS 7.0
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
../svelte-check/bin/svelte-check
|
||||
+1
@@ -0,0 +1 @@
|
||||
../typescript/bin/tsc
|
||||
+1
@@ -0,0 +1 @@
|
||||
../typescript/bin/tsserver
|
||||
+93
-6
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"version": "1.0.0",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
@@ -173,7 +173,6 @@
|
||||
"integrity": "sha512-ILXmxC7HAsnkK2eslgPetrqqW1BKSL7LktsFgqzNj83MaivMGZzluWq32m25j2mDOjmSKX7GGWahePhuEs7P/g==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"deepmerge": "^4.3.1",
|
||||
"magic-string": "^0.30.21",
|
||||
@@ -281,6 +280,22 @@
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/chokidar": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz",
|
||||
"integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"readdirp": "^4.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14.16.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/clsx": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz",
|
||||
@@ -307,7 +322,6 @@
|
||||
"integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
@@ -463,6 +477,16 @@
|
||||
"@jridgewell/sourcemap-codec": "^1.5.5"
|
||||
}
|
||||
},
|
||||
"node_modules/mri": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
||||
"integrity": "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/mrmime": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/mrmime/-/mrmime-2.0.1.tgz",
|
||||
@@ -501,8 +525,7 @@
|
||||
"https://github.com/sponsors/sxzz",
|
||||
"https://opencollective.com/debug"
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/picocolors": {
|
||||
"version": "1.1.1",
|
||||
@@ -553,6 +576,20 @@
|
||||
"node": "^10 || ^12 || >=14"
|
||||
}
|
||||
},
|
||||
"node_modules/readdirp": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz",
|
||||
"integrity": "sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 14.18.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "individual",
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/rolldown": {
|
||||
"version": "1.0.0-rc.17",
|
||||
"resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.0.0-rc.17.tgz",
|
||||
@@ -587,6 +624,19 @@
|
||||
"@rolldown/binding-win32-x64-msvc": "1.0.0-rc.17"
|
||||
}
|
||||
},
|
||||
"node_modules/sade": {
|
||||
"version": "1.8.1",
|
||||
"resolved": "https://registry.npmjs.org/sade/-/sade-1.8.1.tgz",
|
||||
"integrity": "sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mri": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/set-cookie-parser": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-3.1.0.tgz",
|
||||
@@ -647,6 +697,30 @@
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/svelte-check": {
|
||||
"version": "4.4.6",
|
||||
"resolved": "https://registry.npmjs.org/svelte-check/-/svelte-check-4.4.6.tgz",
|
||||
"integrity": "sha512-kP1zG81EWaFe9ZyTv4ZXv44Csi6Pkdpb7S3oj6m+K2ec/IcDg/a8LsFsnVLqm2nxtkSwsd5xPj/qFkTBgXHXjg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jridgewell/trace-mapping": "^0.3.25",
|
||||
"chokidar": "^4.0.1",
|
||||
"fdir": "^6.2.0",
|
||||
"picocolors": "^1.0.0",
|
||||
"sade": "^1.7.4"
|
||||
},
|
||||
"bin": {
|
||||
"svelte-check": "bin/svelte-check"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"svelte": "^4.0.0 || ^5.0.0-next.0",
|
||||
"typescript": ">=5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tinyglobby": {
|
||||
"version": "0.2.16",
|
||||
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.16.tgz",
|
||||
@@ -674,6 +748,20 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz",
|
||||
"integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/vite": {
|
||||
"version": "8.0.10",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-8.0.10.tgz",
|
||||
@@ -758,7 +846,6 @@
|
||||
"integrity": "sha512-ub4okH7Z5KLjb6hDyjqrGXqWtWvoYdU3IGm/NorpgHncKoLTCfRIbvlhBm7r0YstIaQRYlp4yEbFqDcKSzXSSg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"workspaces": [
|
||||
"tests/deps/*",
|
||||
"tests/projects/*",
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2012 Paul Miller (https://paulmillr.com), Elan Shanker
|
||||
|
||||
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.
|
||||
+305
@@ -0,0 +1,305 @@
|
||||
# Chokidar [](https://github.com/paulmillr/chokidar)
|
||||
|
||||
> Minimal and efficient cross-platform file watching library
|
||||
|
||||
## Why?
|
||||
|
||||
There are many reasons to prefer Chokidar to raw fs.watch / fs.watchFile in 2024:
|
||||
|
||||
- Events are properly reported
|
||||
- macOS events report filenames
|
||||
- events are not reported twice
|
||||
- changes are reported as add / change / unlink instead of useless `rename`
|
||||
- Atomic writes are supported, using `atomic` option
|
||||
- Some file editors use them
|
||||
- Chunked writes are supported, using `awaitWriteFinish` option
|
||||
- Large files are commonly written in chunks
|
||||
- File / dir filtering is supported
|
||||
- Symbolic links are supported
|
||||
- Recursive watching is always supported, instead of partial when using raw events
|
||||
- Includes a way to limit recursion depth
|
||||
|
||||
Chokidar relies on the Node.js core `fs` module, but when using
|
||||
`fs.watch` and `fs.watchFile` for watching, it normalizes the events it
|
||||
receives, often checking for truth by getting file stats and/or dir contents.
|
||||
The `fs.watch`-based implementation is the default, which
|
||||
avoids polling and keeps CPU usage down. Be advised that chokidar will initiate
|
||||
watchers recursively for everything within scope of the paths that have been
|
||||
specified, so be judicious about not wasting system resources by watching much
|
||||
more than needed. For some cases, `fs.watchFile`, which utilizes polling and uses more resources, is used.
|
||||
|
||||
Made for [Brunch](https://brunch.io/) in 2012,
|
||||
it is now used in [~30 million repositories](https://www.npmjs.com/browse/depended/chokidar) and
|
||||
has proven itself in production environments.
|
||||
|
||||
**Sep 2024 update:** v4 is out! It decreases dependency count from 13 to 1, removes
|
||||
support for globs, adds support for ESM / Common.js modules, and bumps minimum node.js version from v8 to v14.
|
||||
Check out [upgrading](#upgrading).
|
||||
|
||||
## Getting started
|
||||
|
||||
Install with npm:
|
||||
|
||||
```sh
|
||||
npm install chokidar
|
||||
```
|
||||
|
||||
Use it in your code:
|
||||
|
||||
```javascript
|
||||
import chokidar from 'chokidar';
|
||||
|
||||
// One-liner for current directory
|
||||
chokidar.watch('.').on('all', (event, path) => {
|
||||
console.log(event, path);
|
||||
});
|
||||
|
||||
|
||||
// Extended options
|
||||
// ----------------
|
||||
|
||||
// Initialize watcher.
|
||||
const watcher = chokidar.watch('file, dir, or array', {
|
||||
ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), // only watch js files
|
||||
persistent: true
|
||||
});
|
||||
|
||||
// Something to use when events are received.
|
||||
const log = console.log.bind(console);
|
||||
// Add event listeners.
|
||||
watcher
|
||||
.on('add', path => log(`File ${path} has been added`))
|
||||
.on('change', path => log(`File ${path} has been changed`))
|
||||
.on('unlink', path => log(`File ${path} has been removed`));
|
||||
|
||||
// More possible events.
|
||||
watcher
|
||||
.on('addDir', path => log(`Directory ${path} has been added`))
|
||||
.on('unlinkDir', path => log(`Directory ${path} has been removed`))
|
||||
.on('error', error => log(`Watcher error: ${error}`))
|
||||
.on('ready', () => log('Initial scan complete. Ready for changes'))
|
||||
.on('raw', (event, path, details) => { // internal
|
||||
log('Raw event info:', event, path, details);
|
||||
});
|
||||
|
||||
// 'add', 'addDir' and 'change' events also receive stat() results as second
|
||||
// argument when available: https://nodejs.org/api/fs.html#fs_class_fs_stats
|
||||
watcher.on('change', (path, stats) => {
|
||||
if (stats) console.log(`File ${path} changed size to ${stats.size}`);
|
||||
});
|
||||
|
||||
// Watch new files.
|
||||
watcher.add('new-file');
|
||||
watcher.add(['new-file-2', 'new-file-3']);
|
||||
|
||||
// Get list of actual paths being watched on the filesystem
|
||||
let watchedPaths = watcher.getWatched();
|
||||
|
||||
// Un-watch some files.
|
||||
await watcher.unwatch('new-file');
|
||||
|
||||
// Stop watching. The method is async!
|
||||
await watcher.close().then(() => console.log('closed'));
|
||||
|
||||
// Full list of options. See below for descriptions.
|
||||
// Do not use this example!
|
||||
chokidar.watch('file', {
|
||||
persistent: true,
|
||||
|
||||
// ignore .txt files
|
||||
ignored: (file) => file.endsWith('.txt'),
|
||||
// watch only .txt files
|
||||
// ignored: (file, _stats) => _stats?.isFile() && !file.endsWith('.txt'),
|
||||
|
||||
awaitWriteFinish: true, // emit single event when chunked writes are completed
|
||||
atomic: true, // emit proper events when "atomic writes" (mv _tmp file) are used
|
||||
|
||||
// The options also allow specifying custom intervals in ms
|
||||
// awaitWriteFinish: {
|
||||
// stabilityThreshold: 2000,
|
||||
// pollInterval: 100
|
||||
// },
|
||||
// atomic: 100,
|
||||
|
||||
interval: 100,
|
||||
binaryInterval: 300,
|
||||
|
||||
cwd: '.',
|
||||
depth: 99,
|
||||
|
||||
followSymlinks: true,
|
||||
ignoreInitial: false,
|
||||
ignorePermissionErrors: false,
|
||||
usePolling: false,
|
||||
alwaysStat: false,
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
`chokidar.watch(paths, [options])`
|
||||
|
||||
* `paths` (string or array of strings). Paths to files, dirs to be watched
|
||||
recursively.
|
||||
* `options` (object) Options object as defined below:
|
||||
|
||||
#### Persistence
|
||||
|
||||
* `persistent` (default: `true`). Indicates whether the process
|
||||
should continue to run as long as files are being watched.
|
||||
|
||||
#### Path filtering
|
||||
|
||||
* `ignored` function, regex, or path. Defines files/paths to be ignored.
|
||||
The whole relative or absolute path is tested, not just filename. If a function with two arguments
|
||||
is provided, it gets called twice per path - once with a single argument (the path), second
|
||||
time with two arguments (the path and the
|
||||
[`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats)
|
||||
object of that path).
|
||||
* `ignoreInitial` (default: `false`). If set to `false` then `add`/`addDir` events are also emitted for matching paths while
|
||||
instantiating the watching as chokidar discovers these file paths (before the `ready` event).
|
||||
* `followSymlinks` (default: `true`). When `false`, only the
|
||||
symlinks themselves will be watched for changes instead of following
|
||||
the link references and bubbling events through the link's path.
|
||||
* `cwd` (no default). The base directory from which watch `paths` are to be
|
||||
derived. Paths emitted with events will be relative to this.
|
||||
|
||||
#### Performance
|
||||
|
||||
* `usePolling` (default: `false`).
|
||||
Whether to use fs.watchFile (backed by polling), or fs.watch. If polling
|
||||
leads to high CPU utilization, consider setting this to `false`. It is
|
||||
typically necessary to **set this to `true` to successfully watch files over
|
||||
a network**, and it may be necessary to successfully watch files in other
|
||||
non-standard situations. Setting to `true` explicitly on MacOS overrides the
|
||||
`useFsEvents` default. You may also set the CHOKIDAR_USEPOLLING env variable
|
||||
to true (1) or false (0) in order to override this option.
|
||||
* _Polling-specific settings_ (effective when `usePolling: true`)
|
||||
* `interval` (default: `100`). Interval of file system polling, in milliseconds. You may also
|
||||
set the CHOKIDAR_INTERVAL env variable to override this option.
|
||||
* `binaryInterval` (default: `300`). Interval of file system
|
||||
polling for binary files.
|
||||
([see list of binary extensions](https://github.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json))
|
||||
* `alwaysStat` (default: `false`). If relying upon the
|
||||
[`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats)
|
||||
object that may get passed with `add`, `addDir`, and `change` events, set
|
||||
this to `true` to ensure it is provided even in cases where it wasn't
|
||||
already available from the underlying watch events.
|
||||
* `depth` (default: `undefined`). If set, limits how many levels of
|
||||
subdirectories will be traversed.
|
||||
* `awaitWriteFinish` (default: `false`).
|
||||
By default, the `add` event will fire when a file first appears on disk, before
|
||||
the entire file has been written. Furthermore, in some cases some `change`
|
||||
events will be emitted while the file is being written. In some cases,
|
||||
especially when watching for large files there will be a need to wait for the
|
||||
write operation to finish before responding to a file creation or modification.
|
||||
Setting `awaitWriteFinish` to `true` (or a truthy value) will poll file size,
|
||||
holding its `add` and `change` events until the size does not change for a
|
||||
configurable amount of time. The appropriate duration setting is heavily
|
||||
dependent on the OS and hardware. For accurate detection this parameter should
|
||||
be relatively high, making file watching much less responsive.
|
||||
Use with caution.
|
||||
* *`options.awaitWriteFinish` can be set to an object in order to adjust
|
||||
timing params:*
|
||||
* `awaitWriteFinish.stabilityThreshold` (default: 2000). Amount of time in
|
||||
milliseconds for a file size to remain constant before emitting its event.
|
||||
* `awaitWriteFinish.pollInterval` (default: 100). File size polling interval, in milliseconds.
|
||||
|
||||
#### Errors
|
||||
|
||||
* `ignorePermissionErrors` (default: `false`). Indicates whether to watch files
|
||||
that don't have read permissions if possible. If watching fails due to `EPERM`
|
||||
or `EACCES` with this set to `true`, the errors will be suppressed silently.
|
||||
* `atomic` (default: `true` if `useFsEvents` and `usePolling` are `false`).
|
||||
Automatically filters out artifacts that occur when using editors that use
|
||||
"atomic writes" instead of writing directly to the source file. If a file is
|
||||
re-added within 100 ms of being deleted, Chokidar emits a `change` event
|
||||
rather than `unlink` then `add`. If the default of 100 ms does not work well
|
||||
for you, you can override it by setting `atomic` to a custom value, in
|
||||
milliseconds.
|
||||
|
||||
### Methods & Events
|
||||
|
||||
`chokidar.watch()` produces an instance of `FSWatcher`. Methods of `FSWatcher`:
|
||||
|
||||
* `.add(path / paths)`: Add files, directories for tracking.
|
||||
Takes an array of strings or just one string.
|
||||
* `.on(event, callback)`: Listen for an FS event.
|
||||
Available events: `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `ready`,
|
||||
`raw`, `error`.
|
||||
Additionally `all` is available which gets emitted with the underlying event
|
||||
name and path for every event other than `ready`, `raw`, and `error`. `raw` is internal, use it carefully.
|
||||
* `.unwatch(path / paths)`: Stop watching files or directories.
|
||||
Takes an array of strings or just one string.
|
||||
* `.close()`: **async** Removes all listeners from watched files. Asynchronous, returns Promise. Use with `await` to ensure bugs don't happen.
|
||||
* `.getWatched()`: Returns an object representing all the paths on the file
|
||||
system being watched by this `FSWatcher` instance. The object's keys are all the
|
||||
directories (using absolute paths unless the `cwd` option was used), and the
|
||||
values are arrays of the names of the items contained in each directory.
|
||||
|
||||
### CLI
|
||||
|
||||
Check out third party [chokidar-cli](https://github.com/open-cli-tools/chokidar-cli),
|
||||
which allows to execute a command on each change, or get a stdio stream of change events.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Sometimes, Chokidar runs out of file handles, causing `EMFILE` and `ENOSP` errors:
|
||||
|
||||
* `bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell`
|
||||
* `Error: watch /home/ ENOSPC`
|
||||
|
||||
There are two things that can cause it.
|
||||
|
||||
1. Exhausted file handles for generic fs operations
|
||||
- Can be solved by using [graceful-fs](https://www.npmjs.com/package/graceful-fs),
|
||||
which can monkey-patch native `fs` module used by chokidar: `let fs = require('fs'); let grfs = require('graceful-fs'); grfs.gracefulify(fs);`
|
||||
- Can also be solved by tuning OS: `echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p`.
|
||||
2. Exhausted file handles for `fs.watch`
|
||||
- Can't seem to be solved by graceful-fs or OS tuning
|
||||
- It's possible to start using `usePolling: true`, which will switch backend to resource-intensive `fs.watchFile`
|
||||
|
||||
All fsevents-related issues (`WARN optional dep failed`, `fsevents is not a constructor`) are solved by upgrading to v4+.
|
||||
|
||||
## Changelog
|
||||
|
||||
- **v4 (Sep 2024):** remove glob support and bundled fsevents. Decrease dependency count from 13 to 1. Rewrite in typescript. Bumps minimum node.js requirement to v14+
|
||||
- **v3 (Apr 2019):** massive CPU & RAM consumption improvements; reduces deps / package size by a factor of 17x and bumps Node.js requirement to v8.16+.
|
||||
- **v2 (Dec 2017):** globs are now posix-style-only. Tons of bugfixes.
|
||||
- **v1 (Apr 2015):** glob support, symlink support, tons of bugfixes. Node 0.8+ is supported
|
||||
- **v0.1 (Apr 2012):** Initial release, extracted from [Brunch](https://github.com/brunch/brunch/blob/9847a065aea300da99bd0753f90354cde9de1261/src/helpers.coffee#L66)
|
||||
|
||||
### Upgrading
|
||||
|
||||
If you've used globs before and want do replicate the functionality with v4:
|
||||
|
||||
```js
|
||||
// v3
|
||||
chok.watch('**/*.js');
|
||||
chok.watch("./directory/**/*");
|
||||
|
||||
// v4
|
||||
chok.watch('.', {
|
||||
ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), // only watch js files
|
||||
});
|
||||
chok.watch('./directory');
|
||||
|
||||
// other way
|
||||
import { glob } from 'node:fs/promises';
|
||||
const watcher = watch(await Array.fromAsync(glob('**/*.js')));
|
||||
|
||||
// unwatching
|
||||
// v3
|
||||
chok.unwatch('**/*.js');
|
||||
// v4
|
||||
chok.unwatch(await glob('**/*.js'));
|
||||
```
|
||||
|
||||
## Also
|
||||
|
||||
Why was chokidar named this way? What's the meaning behind it?
|
||||
|
||||
>Chowkidar is a transliteration of a Hindi word meaning 'watchman, gatekeeper', चौकीदार. This ultimately comes from Sanskrit _ चतुष्क_ (crossway, quadrangle, consisting-of-four). This word is also used in other languages like Urdu as (چوکیدار) which is widely used in Pakistan and India.
|
||||
|
||||
## License
|
||||
|
||||
MIT (c) Paul Miller (<https://paulmillr.com>), see [LICENSE](LICENSE) file.
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
import type { WatchEventType, Stats, FSWatcher as NativeFsWatcher } from 'fs';
|
||||
import type { FSWatcher, WatchHelper, Throttler } from './index.js';
|
||||
import type { EntryInfo } from 'readdirp';
|
||||
export type Path = string;
|
||||
export declare const STR_DATA = "data";
|
||||
export declare const STR_END = "end";
|
||||
export declare const STR_CLOSE = "close";
|
||||
export declare const EMPTY_FN: () => void;
|
||||
export declare const IDENTITY_FN: (val: unknown) => unknown;
|
||||
export declare const isWindows: boolean;
|
||||
export declare const isMacos: boolean;
|
||||
export declare const isLinux: boolean;
|
||||
export declare const isFreeBSD: boolean;
|
||||
export declare const isIBMi: boolean;
|
||||
export declare const EVENTS: {
|
||||
readonly ALL: "all";
|
||||
readonly READY: "ready";
|
||||
readonly ADD: "add";
|
||||
readonly CHANGE: "change";
|
||||
readonly ADD_DIR: "addDir";
|
||||
readonly UNLINK: "unlink";
|
||||
readonly UNLINK_DIR: "unlinkDir";
|
||||
readonly RAW: "raw";
|
||||
readonly ERROR: "error";
|
||||
};
|
||||
export type EventName = (typeof EVENTS)[keyof typeof EVENTS];
|
||||
export type FsWatchContainer = {
|
||||
listeners: (path: string) => void | Set<any>;
|
||||
errHandlers: (err: unknown) => void | Set<any>;
|
||||
rawEmitters: (ev: WatchEventType, path: string, opts: unknown) => void | Set<any>;
|
||||
watcher: NativeFsWatcher;
|
||||
watcherUnusable?: boolean;
|
||||
};
|
||||
export interface WatchHandlers {
|
||||
listener: (path: string) => void;
|
||||
errHandler: (err: unknown) => void;
|
||||
rawEmitter: (ev: WatchEventType, path: string, opts: unknown) => void;
|
||||
}
|
||||
/**
|
||||
* @mixin
|
||||
*/
|
||||
export declare class NodeFsHandler {
|
||||
fsw: FSWatcher;
|
||||
_boundHandleError: (error: unknown) => void;
|
||||
constructor(fsW: FSWatcher);
|
||||
/**
|
||||
* Watch file for changes with fs_watchFile or fs_watch.
|
||||
* @param path to file or dir
|
||||
* @param listener on fs change
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_watchWithNodeFs(path: string, listener: (path: string, newStats?: any) => void | Promise<void>): (() => void) | undefined;
|
||||
/**
|
||||
* Watch a file and emit add event if warranted.
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_handleFile(file: Path, stats: Stats, initialAdd: boolean): (() => void) | undefined;
|
||||
/**
|
||||
* Handle symlinks encountered while reading a dir.
|
||||
* @param entry returned by readdirp
|
||||
* @param directory path of dir being read
|
||||
* @param path of this item
|
||||
* @param item basename of this item
|
||||
* @returns true if no more processing is needed for this entry.
|
||||
*/
|
||||
_handleSymlink(entry: EntryInfo, directory: string, path: Path, item: string): Promise<boolean | undefined>;
|
||||
_handleRead(directory: string, initialAdd: boolean, wh: WatchHelper, target: Path, dir: Path, depth: number, throttler: Throttler): Promise<unknown> | undefined;
|
||||
/**
|
||||
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
||||
* @param dir fs path
|
||||
* @param stats
|
||||
* @param initialAdd
|
||||
* @param depth relative to user-supplied path
|
||||
* @param target child path targeted for watch
|
||||
* @param wh Common watch helpers for this path
|
||||
* @param realpath
|
||||
* @returns closer for the watcher instance.
|
||||
*/
|
||||
_handleDir(dir: string, stats: Stats, initialAdd: boolean, depth: number, target: string, wh: WatchHelper, realpath: string): Promise<(() => void) | undefined>;
|
||||
/**
|
||||
* Handle added file, directory, or glob pattern.
|
||||
* Delegates call to _handleFile / _handleDir after checks.
|
||||
* @param path to file or ir
|
||||
* @param initialAdd was the file added at watch instantiation?
|
||||
* @param priorWh depth relative to user-supplied path
|
||||
* @param depth Child path actually targeted for watch
|
||||
* @param target Child path actually targeted for watch
|
||||
*/
|
||||
_addToNodeFs(path: string, initialAdd: boolean, priorWh: WatchHelper | undefined, depth: number, target?: string): Promise<string | false | undefined>;
|
||||
}
|
||||
+629
@@ -0,0 +1,629 @@
|
||||
import { watchFile, unwatchFile, watch as fs_watch } from 'fs';
|
||||
import { open, stat, lstat, realpath as fsrealpath } from 'fs/promises';
|
||||
import * as sysPath from 'path';
|
||||
import { type as osType } from 'os';
|
||||
export const STR_DATA = 'data';
|
||||
export const STR_END = 'end';
|
||||
export const STR_CLOSE = 'close';
|
||||
export const EMPTY_FN = () => { };
|
||||
export const IDENTITY_FN = (val) => val;
|
||||
const pl = process.platform;
|
||||
export const isWindows = pl === 'win32';
|
||||
export const isMacos = pl === 'darwin';
|
||||
export const isLinux = pl === 'linux';
|
||||
export const isFreeBSD = pl === 'freebsd';
|
||||
export const isIBMi = osType() === 'OS400';
|
||||
export const EVENTS = {
|
||||
ALL: 'all',
|
||||
READY: 'ready',
|
||||
ADD: 'add',
|
||||
CHANGE: 'change',
|
||||
ADD_DIR: 'addDir',
|
||||
UNLINK: 'unlink',
|
||||
UNLINK_DIR: 'unlinkDir',
|
||||
RAW: 'raw',
|
||||
ERROR: 'error',
|
||||
};
|
||||
const EV = EVENTS;
|
||||
const THROTTLE_MODE_WATCH = 'watch';
|
||||
const statMethods = { lstat, stat };
|
||||
const KEY_LISTENERS = 'listeners';
|
||||
const KEY_ERR = 'errHandlers';
|
||||
const KEY_RAW = 'rawEmitters';
|
||||
const HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
||||
// prettier-ignore
|
||||
const binaryExtensions = new Set([
|
||||
'3dm', '3ds', '3g2', '3gp', '7z', 'a', 'aac', 'adp', 'afdesign', 'afphoto', 'afpub', 'ai',
|
||||
'aif', 'aiff', 'alz', 'ape', 'apk', 'appimage', 'ar', 'arj', 'asf', 'au', 'avi',
|
||||
'bak', 'baml', 'bh', 'bin', 'bk', 'bmp', 'btif', 'bz2', 'bzip2',
|
||||
'cab', 'caf', 'cgm', 'class', 'cmx', 'cpio', 'cr2', 'cur', 'dat', 'dcm', 'deb', 'dex', 'djvu',
|
||||
'dll', 'dmg', 'dng', 'doc', 'docm', 'docx', 'dot', 'dotm', 'dra', 'DS_Store', 'dsk', 'dts',
|
||||
'dtshd', 'dvb', 'dwg', 'dxf',
|
||||
'ecelp4800', 'ecelp7470', 'ecelp9600', 'egg', 'eol', 'eot', 'epub', 'exe',
|
||||
'f4v', 'fbs', 'fh', 'fla', 'flac', 'flatpak', 'fli', 'flv', 'fpx', 'fst', 'fvt',
|
||||
'g3', 'gh', 'gif', 'graffle', 'gz', 'gzip',
|
||||
'h261', 'h263', 'h264', 'icns', 'ico', 'ief', 'img', 'ipa', 'iso',
|
||||
'jar', 'jpeg', 'jpg', 'jpgv', 'jpm', 'jxr', 'key', 'ktx',
|
||||
'lha', 'lib', 'lvp', 'lz', 'lzh', 'lzma', 'lzo',
|
||||
'm3u', 'm4a', 'm4v', 'mar', 'mdi', 'mht', 'mid', 'midi', 'mj2', 'mka', 'mkv', 'mmr', 'mng',
|
||||
'mobi', 'mov', 'movie', 'mp3',
|
||||
'mp4', 'mp4a', 'mpeg', 'mpg', 'mpga', 'mxu',
|
||||
'nef', 'npx', 'numbers', 'nupkg',
|
||||
'o', 'odp', 'ods', 'odt', 'oga', 'ogg', 'ogv', 'otf', 'ott',
|
||||
'pages', 'pbm', 'pcx', 'pdb', 'pdf', 'pea', 'pgm', 'pic', 'png', 'pnm', 'pot', 'potm',
|
||||
'potx', 'ppa', 'ppam',
|
||||
'ppm', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx', 'psd', 'pya', 'pyc', 'pyo', 'pyv',
|
||||
'qt',
|
||||
'rar', 'ras', 'raw', 'resources', 'rgb', 'rip', 'rlc', 'rmf', 'rmvb', 'rpm', 'rtf', 'rz',
|
||||
's3m', 's7z', 'scpt', 'sgi', 'shar', 'snap', 'sil', 'sketch', 'slk', 'smv', 'snk', 'so',
|
||||
'stl', 'suo', 'sub', 'swf',
|
||||
'tar', 'tbz', 'tbz2', 'tga', 'tgz', 'thmx', 'tif', 'tiff', 'tlz', 'ttc', 'ttf', 'txz',
|
||||
'udf', 'uvh', 'uvi', 'uvm', 'uvp', 'uvs', 'uvu',
|
||||
'viv', 'vob',
|
||||
'war', 'wav', 'wax', 'wbmp', 'wdp', 'weba', 'webm', 'webp', 'whl', 'wim', 'wm', 'wma',
|
||||
'wmv', 'wmx', 'woff', 'woff2', 'wrm', 'wvx',
|
||||
'xbm', 'xif', 'xla', 'xlam', 'xls', 'xlsb', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx', 'xm',
|
||||
'xmind', 'xpi', 'xpm', 'xwd', 'xz',
|
||||
'z', 'zip', 'zipx',
|
||||
]);
|
||||
const isBinaryPath = (filePath) => binaryExtensions.has(sysPath.extname(filePath).slice(1).toLowerCase());
|
||||
// TODO: emit errors properly. Example: EMFILE on Macos.
|
||||
const foreach = (val, fn) => {
|
||||
if (val instanceof Set) {
|
||||
val.forEach(fn);
|
||||
}
|
||||
else {
|
||||
fn(val);
|
||||
}
|
||||
};
|
||||
const addAndConvert = (main, prop, item) => {
|
||||
let container = main[prop];
|
||||
if (!(container instanceof Set)) {
|
||||
main[prop] = container = new Set([container]);
|
||||
}
|
||||
container.add(item);
|
||||
};
|
||||
const clearItem = (cont) => (key) => {
|
||||
const set = cont[key];
|
||||
if (set instanceof Set) {
|
||||
set.clear();
|
||||
}
|
||||
else {
|
||||
delete cont[key];
|
||||
}
|
||||
};
|
||||
const delFromSet = (main, prop, item) => {
|
||||
const container = main[prop];
|
||||
if (container instanceof Set) {
|
||||
container.delete(item);
|
||||
}
|
||||
else if (container === item) {
|
||||
delete main[prop];
|
||||
}
|
||||
};
|
||||
const isEmptySet = (val) => (val instanceof Set ? val.size === 0 : !val);
|
||||
const FsWatchInstances = new Map();
|
||||
/**
|
||||
* Instantiates the fs_watch interface
|
||||
* @param path to be watched
|
||||
* @param options to be passed to fs_watch
|
||||
* @param listener main event handler
|
||||
* @param errHandler emits info about errors
|
||||
* @param emitRaw emits raw event data
|
||||
* @returns {NativeFsWatcher}
|
||||
*/
|
||||
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
||||
const handleEvent = (rawEvent, evPath) => {
|
||||
listener(path);
|
||||
emitRaw(rawEvent, evPath, { watchedPath: path });
|
||||
// emit based on events occurring for files from a directory's watcher in
|
||||
// case the file's watcher misses it (and rely on throttling to de-dupe)
|
||||
if (evPath && path !== evPath) {
|
||||
fsWatchBroadcast(sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath));
|
||||
}
|
||||
};
|
||||
try {
|
||||
return fs_watch(path, {
|
||||
persistent: options.persistent,
|
||||
}, handleEvent);
|
||||
}
|
||||
catch (error) {
|
||||
errHandler(error);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Helper for passing fs_watch event data to a collection of listeners
|
||||
* @param fullPath absolute path bound to fs_watch instance
|
||||
*/
|
||||
const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
||||
const cont = FsWatchInstances.get(fullPath);
|
||||
if (!cont)
|
||||
return;
|
||||
foreach(cont[listenerType], (listener) => {
|
||||
listener(val1, val2, val3);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Instantiates the fs_watch interface or binds listeners
|
||||
* to an existing one covering the same file system entry
|
||||
* @param path
|
||||
* @param fullPath absolute path
|
||||
* @param options to be passed to fs_watch
|
||||
* @param handlers container for event listener functions
|
||||
*/
|
||||
const setFsWatchListener = (path, fullPath, options, handlers) => {
|
||||
const { listener, errHandler, rawEmitter } = handlers;
|
||||
let cont = FsWatchInstances.get(fullPath);
|
||||
let watcher;
|
||||
if (!options.persistent) {
|
||||
watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
|
||||
if (!watcher)
|
||||
return;
|
||||
return watcher.close.bind(watcher);
|
||||
}
|
||||
if (cont) {
|
||||
addAndConvert(cont, KEY_LISTENERS, listener);
|
||||
addAndConvert(cont, KEY_ERR, errHandler);
|
||||
addAndConvert(cont, KEY_RAW, rawEmitter);
|
||||
}
|
||||
else {
|
||||
watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, // no need to use broadcast here
|
||||
fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
|
||||
if (!watcher)
|
||||
return;
|
||||
watcher.on(EV.ERROR, async (error) => {
|
||||
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
||||
if (cont)
|
||||
cont.watcherUnusable = true; // documented since Node 10.4.1
|
||||
// Workaround for https://github.com/joyent/node/issues/4337
|
||||
if (isWindows && error.code === 'EPERM') {
|
||||
try {
|
||||
const fd = await open(path, 'r');
|
||||
await fd.close();
|
||||
broadcastErr(error);
|
||||
}
|
||||
catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
else {
|
||||
broadcastErr(error);
|
||||
}
|
||||
});
|
||||
cont = {
|
||||
listeners: listener,
|
||||
errHandlers: errHandler,
|
||||
rawEmitters: rawEmitter,
|
||||
watcher,
|
||||
};
|
||||
FsWatchInstances.set(fullPath, cont);
|
||||
}
|
||||
// const index = cont.listeners.indexOf(listener);
|
||||
// removes this instance's listeners and closes the underlying fs_watch
|
||||
// instance if there are no more listeners left
|
||||
return () => {
|
||||
delFromSet(cont, KEY_LISTENERS, listener);
|
||||
delFromSet(cont, KEY_ERR, errHandler);
|
||||
delFromSet(cont, KEY_RAW, rawEmitter);
|
||||
if (isEmptySet(cont.listeners)) {
|
||||
// Check to protect against issue gh-730.
|
||||
// if (cont.watcherUnusable) {
|
||||
cont.watcher.close();
|
||||
// }
|
||||
FsWatchInstances.delete(fullPath);
|
||||
HANDLER_KEYS.forEach(clearItem(cont));
|
||||
// @ts-ignore
|
||||
cont.watcher = undefined;
|
||||
Object.freeze(cont);
|
||||
}
|
||||
};
|
||||
};
|
||||
// fs_watchFile helpers
|
||||
// object to hold per-process fs_watchFile instances
|
||||
// (may be shared across chokidar FSWatcher instances)
|
||||
const FsWatchFileInstances = new Map();
|
||||
/**
|
||||
* Instantiates the fs_watchFile interface or binds listeners
|
||||
* to an existing one covering the same file system entry
|
||||
* @param path to be watched
|
||||
* @param fullPath absolute path
|
||||
* @param options options to be passed to fs_watchFile
|
||||
* @param handlers container for event listener functions
|
||||
* @returns closer
|
||||
*/
|
||||
const setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
||||
const { listener, rawEmitter } = handlers;
|
||||
let cont = FsWatchFileInstances.get(fullPath);
|
||||
// let listeners = new Set();
|
||||
// let rawEmitters = new Set();
|
||||
const copts = cont && cont.options;
|
||||
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
||||
// "Upgrade" the watcher to persistence or a quicker interval.
|
||||
// This creates some unlikely edge case issues if the user mixes
|
||||
// settings in a very weird way, but solving for those cases
|
||||
// doesn't seem worthwhile for the added complexity.
|
||||
// listeners = cont.listeners;
|
||||
// rawEmitters = cont.rawEmitters;
|
||||
unwatchFile(fullPath);
|
||||
cont = undefined;
|
||||
}
|
||||
if (cont) {
|
||||
addAndConvert(cont, KEY_LISTENERS, listener);
|
||||
addAndConvert(cont, KEY_RAW, rawEmitter);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
// listeners.add(listener);
|
||||
// rawEmitters.add(rawEmitter);
|
||||
cont = {
|
||||
listeners: listener,
|
||||
rawEmitters: rawEmitter,
|
||||
options,
|
||||
watcher: watchFile(fullPath, options, (curr, prev) => {
|
||||
foreach(cont.rawEmitters, (rawEmitter) => {
|
||||
rawEmitter(EV.CHANGE, fullPath, { curr, prev });
|
||||
});
|
||||
const currmtime = curr.mtimeMs;
|
||||
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
||||
foreach(cont.listeners, (listener) => listener(path, curr));
|
||||
}
|
||||
}),
|
||||
};
|
||||
FsWatchFileInstances.set(fullPath, cont);
|
||||
}
|
||||
// const index = cont.listeners.indexOf(listener);
|
||||
// Removes this instance's listeners and closes the underlying fs_watchFile
|
||||
// instance if there are no more listeners left.
|
||||
return () => {
|
||||
delFromSet(cont, KEY_LISTENERS, listener);
|
||||
delFromSet(cont, KEY_RAW, rawEmitter);
|
||||
if (isEmptySet(cont.listeners)) {
|
||||
FsWatchFileInstances.delete(fullPath);
|
||||
unwatchFile(fullPath);
|
||||
cont.options = cont.watcher = undefined;
|
||||
Object.freeze(cont);
|
||||
}
|
||||
};
|
||||
};
|
||||
/**
|
||||
* @mixin
|
||||
*/
|
||||
export class NodeFsHandler {
|
||||
constructor(fsW) {
|
||||
this.fsw = fsW;
|
||||
this._boundHandleError = (error) => fsW._handleError(error);
|
||||
}
|
||||
/**
|
||||
* Watch file for changes with fs_watchFile or fs_watch.
|
||||
* @param path to file or dir
|
||||
* @param listener on fs change
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_watchWithNodeFs(path, listener) {
|
||||
const opts = this.fsw.options;
|
||||
const directory = sysPath.dirname(path);
|
||||
const basename = sysPath.basename(path);
|
||||
const parent = this.fsw._getWatchedDir(directory);
|
||||
parent.add(basename);
|
||||
const absolutePath = sysPath.resolve(path);
|
||||
const options = {
|
||||
persistent: opts.persistent,
|
||||
};
|
||||
if (!listener)
|
||||
listener = EMPTY_FN;
|
||||
let closer;
|
||||
if (opts.usePolling) {
|
||||
const enableBin = opts.interval !== opts.binaryInterval;
|
||||
options.interval = enableBin && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
|
||||
closer = setFsWatchFileListener(path, absolutePath, options, {
|
||||
listener,
|
||||
rawEmitter: this.fsw._emitRaw,
|
||||
});
|
||||
}
|
||||
else {
|
||||
closer = setFsWatchListener(path, absolutePath, options, {
|
||||
listener,
|
||||
errHandler: this._boundHandleError,
|
||||
rawEmitter: this.fsw._emitRaw,
|
||||
});
|
||||
}
|
||||
return closer;
|
||||
}
|
||||
/**
|
||||
* Watch a file and emit add event if warranted.
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_handleFile(file, stats, initialAdd) {
|
||||
if (this.fsw.closed) {
|
||||
return;
|
||||
}
|
||||
const dirname = sysPath.dirname(file);
|
||||
const basename = sysPath.basename(file);
|
||||
const parent = this.fsw._getWatchedDir(dirname);
|
||||
// stats is always present
|
||||
let prevStats = stats;
|
||||
// if the file is already being watched, do nothing
|
||||
if (parent.has(basename))
|
||||
return;
|
||||
const listener = async (path, newStats) => {
|
||||
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
||||
return;
|
||||
if (!newStats || newStats.mtimeMs === 0) {
|
||||
try {
|
||||
const newStats = await stat(file);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
// Check that change event was not fired because of changed only accessTime.
|
||||
const at = newStats.atimeMs;
|
||||
const mt = newStats.mtimeMs;
|
||||
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
||||
this.fsw._emit(EV.CHANGE, file, newStats);
|
||||
}
|
||||
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats.ino) {
|
||||
this.fsw._closeFile(path);
|
||||
prevStats = newStats;
|
||||
const closer = this._watchWithNodeFs(file, listener);
|
||||
if (closer)
|
||||
this.fsw._addPathCloser(path, closer);
|
||||
}
|
||||
else {
|
||||
prevStats = newStats;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
// Fix issues where mtime is null but file is still present
|
||||
this.fsw._remove(dirname, basename);
|
||||
}
|
||||
// add is about to be emitted if file not already tracked in parent
|
||||
}
|
||||
else if (parent.has(basename)) {
|
||||
// Check that change event was not fired because of changed only accessTime.
|
||||
const at = newStats.atimeMs;
|
||||
const mt = newStats.mtimeMs;
|
||||
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
||||
this.fsw._emit(EV.CHANGE, file, newStats);
|
||||
}
|
||||
prevStats = newStats;
|
||||
}
|
||||
};
|
||||
// kick off the watcher
|
||||
const closer = this._watchWithNodeFs(file, listener);
|
||||
// emit an add event if we're supposed to
|
||||
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
||||
if (!this.fsw._throttle(EV.ADD, file, 0))
|
||||
return;
|
||||
this.fsw._emit(EV.ADD, file, stats);
|
||||
}
|
||||
return closer;
|
||||
}
|
||||
/**
|
||||
* Handle symlinks encountered while reading a dir.
|
||||
* @param entry returned by readdirp
|
||||
* @param directory path of dir being read
|
||||
* @param path of this item
|
||||
* @param item basename of this item
|
||||
* @returns true if no more processing is needed for this entry.
|
||||
*/
|
||||
async _handleSymlink(entry, directory, path, item) {
|
||||
if (this.fsw.closed) {
|
||||
return;
|
||||
}
|
||||
const full = entry.fullPath;
|
||||
const dir = this.fsw._getWatchedDir(directory);
|
||||
if (!this.fsw.options.followSymlinks) {
|
||||
// watch symlink directly (don't follow) and detect changes
|
||||
this.fsw._incrReadyCount();
|
||||
let linkPath;
|
||||
try {
|
||||
linkPath = await fsrealpath(path);
|
||||
}
|
||||
catch (e) {
|
||||
this.fsw._emitReady();
|
||||
return true;
|
||||
}
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
if (dir.has(item)) {
|
||||
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
||||
this.fsw._symlinkPaths.set(full, linkPath);
|
||||
this.fsw._emit(EV.CHANGE, path, entry.stats);
|
||||
}
|
||||
}
|
||||
else {
|
||||
dir.add(item);
|
||||
this.fsw._symlinkPaths.set(full, linkPath);
|
||||
this.fsw._emit(EV.ADD, path, entry.stats);
|
||||
}
|
||||
this.fsw._emitReady();
|
||||
return true;
|
||||
}
|
||||
// don't follow the same symlink more than once
|
||||
if (this.fsw._symlinkPaths.has(full)) {
|
||||
return true;
|
||||
}
|
||||
this.fsw._symlinkPaths.set(full, true);
|
||||
}
|
||||
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
||||
// Normalize the directory name on Windows
|
||||
directory = sysPath.join(directory, '');
|
||||
throttler = this.fsw._throttle('readdir', directory, 1000);
|
||||
if (!throttler)
|
||||
return;
|
||||
const previous = this.fsw._getWatchedDir(wh.path);
|
||||
const current = new Set();
|
||||
let stream = this.fsw._readdirp(directory, {
|
||||
fileFilter: (entry) => wh.filterPath(entry),
|
||||
directoryFilter: (entry) => wh.filterDir(entry),
|
||||
});
|
||||
if (!stream)
|
||||
return;
|
||||
stream
|
||||
.on(STR_DATA, async (entry) => {
|
||||
if (this.fsw.closed) {
|
||||
stream = undefined;
|
||||
return;
|
||||
}
|
||||
const item = entry.path;
|
||||
let path = sysPath.join(directory, item);
|
||||
current.add(item);
|
||||
if (entry.stats.isSymbolicLink() &&
|
||||
(await this._handleSymlink(entry, directory, path, item))) {
|
||||
return;
|
||||
}
|
||||
if (this.fsw.closed) {
|
||||
stream = undefined;
|
||||
return;
|
||||
}
|
||||
// Files that present in current directory snapshot
|
||||
// but absent in previous are added to watch list and
|
||||
// emit `add` event.
|
||||
if (item === target || (!target && !previous.has(item))) {
|
||||
this.fsw._incrReadyCount();
|
||||
// ensure relativeness of path is preserved in case of watcher reuse
|
||||
path = sysPath.join(dir, sysPath.relative(dir, path));
|
||||
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
||||
}
|
||||
})
|
||||
.on(EV.ERROR, this._boundHandleError);
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!stream)
|
||||
return reject();
|
||||
stream.once(STR_END, () => {
|
||||
if (this.fsw.closed) {
|
||||
stream = undefined;
|
||||
return;
|
||||
}
|
||||
const wasThrottled = throttler ? throttler.clear() : false;
|
||||
resolve(undefined);
|
||||
// Files that absent in current directory snapshot
|
||||
// but present in previous emit `remove` event
|
||||
// and are removed from @watched[directory].
|
||||
previous
|
||||
.getChildren()
|
||||
.filter((item) => {
|
||||
return item !== directory && !current.has(item);
|
||||
})
|
||||
.forEach((item) => {
|
||||
this.fsw._remove(directory, item);
|
||||
});
|
||||
stream = undefined;
|
||||
// one more time for any missed in case changes came in extremely quickly
|
||||
if (wasThrottled)
|
||||
this._handleRead(directory, false, wh, target, dir, depth, throttler);
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
||||
* @param dir fs path
|
||||
* @param stats
|
||||
* @param initialAdd
|
||||
* @param depth relative to user-supplied path
|
||||
* @param target child path targeted for watch
|
||||
* @param wh Common watch helpers for this path
|
||||
* @param realpath
|
||||
* @returns closer for the watcher instance.
|
||||
*/
|
||||
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
|
||||
const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
|
||||
const tracked = parentDir.has(sysPath.basename(dir));
|
||||
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
|
||||
this.fsw._emit(EV.ADD_DIR, dir, stats);
|
||||
}
|
||||
// ensure dir is tracked (harmless if redundant)
|
||||
parentDir.add(sysPath.basename(dir));
|
||||
this.fsw._getWatchedDir(dir);
|
||||
let throttler;
|
||||
let closer;
|
||||
const oDepth = this.fsw.options.depth;
|
||||
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
|
||||
if (!target) {
|
||||
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
}
|
||||
closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
|
||||
// if current directory is removed, do nothing
|
||||
if (stats && stats.mtimeMs === 0)
|
||||
return;
|
||||
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
||||
});
|
||||
}
|
||||
return closer;
|
||||
}
|
||||
/**
|
||||
* Handle added file, directory, or glob pattern.
|
||||
* Delegates call to _handleFile / _handleDir after checks.
|
||||
* @param path to file or ir
|
||||
* @param initialAdd was the file added at watch instantiation?
|
||||
* @param priorWh depth relative to user-supplied path
|
||||
* @param depth Child path actually targeted for watch
|
||||
* @param target Child path actually targeted for watch
|
||||
*/
|
||||
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
||||
const ready = this.fsw._emitReady;
|
||||
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
||||
ready();
|
||||
return false;
|
||||
}
|
||||
const wh = this.fsw._getWatchHelpers(path);
|
||||
if (priorWh) {
|
||||
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
||||
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
||||
}
|
||||
// evaluate what is at the path we're being asked to watch
|
||||
try {
|
||||
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
||||
ready();
|
||||
return false;
|
||||
}
|
||||
const follow = this.fsw.options.followSymlinks;
|
||||
let closer;
|
||||
if (stats.isDirectory()) {
|
||||
const absPath = sysPath.resolve(path);
|
||||
const targetPath = follow ? await fsrealpath(path) : path;
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
// preserve this symlink's target path
|
||||
if (absPath !== targetPath && targetPath !== undefined) {
|
||||
this.fsw._symlinkPaths.set(absPath, targetPath);
|
||||
}
|
||||
}
|
||||
else if (stats.isSymbolicLink()) {
|
||||
const targetPath = follow ? await fsrealpath(path) : path;
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
const parent = sysPath.dirname(wh.watchPath);
|
||||
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
||||
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
||||
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
// preserve this symlink's target path
|
||||
if (targetPath !== undefined) {
|
||||
this.fsw._symlinkPaths.set(sysPath.resolve(path), targetPath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
||||
}
|
||||
ready();
|
||||
if (closer)
|
||||
this.fsw._addPathCloser(path, closer);
|
||||
return false;
|
||||
}
|
||||
catch (error) {
|
||||
if (this.fsw._handleError(error)) {
|
||||
ready();
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
||||
import { Stats } from 'fs';
|
||||
import { EventEmitter } from 'events';
|
||||
import { ReaddirpStream, ReaddirpOptions, EntryInfo } from 'readdirp';
|
||||
import { NodeFsHandler, EventName, Path, EVENTS as EV, WatchHandlers } from './handler.js';
|
||||
type AWF = {
|
||||
stabilityThreshold: number;
|
||||
pollInterval: number;
|
||||
};
|
||||
type BasicOpts = {
|
||||
persistent: boolean;
|
||||
ignoreInitial: boolean;
|
||||
followSymlinks: boolean;
|
||||
cwd?: string;
|
||||
usePolling: boolean;
|
||||
interval: number;
|
||||
binaryInterval: number;
|
||||
alwaysStat?: boolean;
|
||||
depth?: number;
|
||||
ignorePermissionErrors: boolean;
|
||||
atomic: boolean | number;
|
||||
};
|
||||
export type Throttler = {
|
||||
timeoutObject: NodeJS.Timeout;
|
||||
clear: () => void;
|
||||
count: number;
|
||||
};
|
||||
export type ChokidarOptions = Partial<BasicOpts & {
|
||||
ignored: Matcher | Matcher[];
|
||||
awaitWriteFinish: boolean | Partial<AWF>;
|
||||
}>;
|
||||
export type FSWInstanceOptions = BasicOpts & {
|
||||
ignored: Matcher[];
|
||||
awaitWriteFinish: false | AWF;
|
||||
};
|
||||
export type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';
|
||||
export type EmitArgs = [path: Path, stats?: Stats];
|
||||
export type EmitErrorArgs = [error: Error, stats?: Stats];
|
||||
export type EmitArgsWithName = [event: EventName, ...EmitArgs];
|
||||
export type MatchFunction = (val: string, stats?: Stats) => boolean;
|
||||
export interface MatcherObject {
|
||||
path: string;
|
||||
recursive?: boolean;
|
||||
}
|
||||
export type Matcher = string | RegExp | MatchFunction | MatcherObject;
|
||||
/**
|
||||
* Directory entry.
|
||||
*/
|
||||
declare class DirEntry {
|
||||
path: Path;
|
||||
_removeWatcher: (dir: string, base: string) => void;
|
||||
items: Set<Path>;
|
||||
constructor(dir: Path, removeWatcher: (dir: string, base: string) => void);
|
||||
add(item: string): void;
|
||||
remove(item: string): Promise<void>;
|
||||
has(item: string): boolean | undefined;
|
||||
getChildren(): string[];
|
||||
dispose(): void;
|
||||
}
|
||||
export declare class WatchHelper {
|
||||
fsw: FSWatcher;
|
||||
path: string;
|
||||
watchPath: string;
|
||||
fullWatchPath: string;
|
||||
dirParts: string[][];
|
||||
followSymlinks: boolean;
|
||||
statMethod: 'stat' | 'lstat';
|
||||
constructor(path: string, follow: boolean, fsw: FSWatcher);
|
||||
entryPath(entry: EntryInfo): Path;
|
||||
filterPath(entry: EntryInfo): boolean;
|
||||
filterDir(entry: EntryInfo): boolean;
|
||||
}
|
||||
export interface FSWatcherKnownEventMap {
|
||||
[EV.READY]: [];
|
||||
[EV.RAW]: Parameters<WatchHandlers['rawEmitter']>;
|
||||
[EV.ERROR]: Parameters<WatchHandlers['errHandler']>;
|
||||
[EV.ALL]: [event: EventName, ...EmitArgs];
|
||||
}
|
||||
export type FSWatcherEventMap = FSWatcherKnownEventMap & {
|
||||
[k in Exclude<EventName, keyof FSWatcherKnownEventMap>]: EmitArgs;
|
||||
};
|
||||
/**
|
||||
* Watches files & directories for changes. Emitted events:
|
||||
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
||||
*
|
||||
* new FSWatcher()
|
||||
* .add(directories)
|
||||
* .on('add', path => log('File', path, 'was added'))
|
||||
*/
|
||||
export declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
|
||||
closed: boolean;
|
||||
options: FSWInstanceOptions;
|
||||
_closers: Map<string, Array<any>>;
|
||||
_ignoredPaths: Set<Matcher>;
|
||||
_throttled: Map<ThrottleType, Map<any, any>>;
|
||||
_streams: Set<ReaddirpStream>;
|
||||
_symlinkPaths: Map<Path, string | boolean>;
|
||||
_watched: Map<string, DirEntry>;
|
||||
_pendingWrites: Map<string, any>;
|
||||
_pendingUnlinks: Map<string, EmitArgsWithName>;
|
||||
_readyCount: number;
|
||||
_emitReady: () => void;
|
||||
_closePromise?: Promise<void>;
|
||||
_userIgnored?: MatchFunction;
|
||||
_readyEmitted: boolean;
|
||||
_emitRaw: WatchHandlers['rawEmitter'];
|
||||
_boundRemove: (dir: string, item: string) => void;
|
||||
_nodeFsHandler: NodeFsHandler;
|
||||
constructor(_opts?: ChokidarOptions);
|
||||
_addIgnoredPath(matcher: Matcher): void;
|
||||
_removeIgnoredPath(matcher: Matcher): void;
|
||||
/**
|
||||
* Adds paths to be watched on an existing FSWatcher instance.
|
||||
* @param paths_ file or file list. Other arguments are unused
|
||||
*/
|
||||
add(paths_: Path | Path[], _origAdd?: string, _internal?: boolean): FSWatcher;
|
||||
/**
|
||||
* Close watchers or start ignoring events from specified paths.
|
||||
*/
|
||||
unwatch(paths_: Path | Path[]): FSWatcher;
|
||||
/**
|
||||
* Close watchers and remove all listeners from watched paths.
|
||||
*/
|
||||
close(): Promise<void>;
|
||||
/**
|
||||
* Expose list of watched paths
|
||||
* @returns for chaining
|
||||
*/
|
||||
getWatched(): Record<string, string[]>;
|
||||
emitWithAll(event: EventName, args: EmitArgs): void;
|
||||
/**
|
||||
* Normalize and emit events.
|
||||
* Calling _emit DOES NOT MEAN emit() would be called!
|
||||
* @param event Type of event
|
||||
* @param path File or directory path
|
||||
* @param stats arguments to be passed with event
|
||||
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
_emit(event: EventName, path: Path, stats?: Stats): Promise<this | undefined>;
|
||||
/**
|
||||
* Common handler for errors
|
||||
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
_handleError(error: Error): Error | boolean;
|
||||
/**
|
||||
* Helper utility for throttling
|
||||
* @param actionType type being throttled
|
||||
* @param path being acted upon
|
||||
* @param timeout duration of time to suppress duplicate actions
|
||||
* @returns tracking object or false if action should be suppressed
|
||||
*/
|
||||
_throttle(actionType: ThrottleType, path: Path, timeout: number): Throttler | false;
|
||||
_incrReadyCount(): number;
|
||||
/**
|
||||
* Awaits write operation to finish.
|
||||
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
||||
* @param path being acted upon
|
||||
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
||||
* @param event
|
||||
* @param awfEmit Callback to be called when ready for event to be emitted.
|
||||
*/
|
||||
_awaitWriteFinish(path: Path, threshold: number, event: EventName, awfEmit: (err?: Error, stat?: Stats) => void): void;
|
||||
/**
|
||||
* Determines whether user has asked to ignore this path.
|
||||
*/
|
||||
_isIgnored(path: Path, stats?: Stats): boolean;
|
||||
_isntIgnored(path: Path, stat?: Stats): boolean;
|
||||
/**
|
||||
* Provides a set of common helpers and properties relating to symlink handling.
|
||||
* @param path file or directory pattern being watched
|
||||
*/
|
||||
_getWatchHelpers(path: Path): WatchHelper;
|
||||
/**
|
||||
* Provides directory tracking objects
|
||||
* @param directory path of the directory
|
||||
*/
|
||||
_getWatchedDir(directory: string): DirEntry;
|
||||
/**
|
||||
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
||||
*/
|
||||
_hasReadPermissions(stats: Stats): boolean;
|
||||
/**
|
||||
* Handles emitting unlink events for
|
||||
* files and directories, and via recursion, for
|
||||
* files and directories within directories that are unlinked
|
||||
* @param directory within which the following item is located
|
||||
* @param item base path of item/directory
|
||||
*/
|
||||
_remove(directory: string, item: string, isDirectory?: boolean): void;
|
||||
/**
|
||||
* Closes all watchers for a path
|
||||
*/
|
||||
_closePath(path: Path): void;
|
||||
/**
|
||||
* Closes only file-specific watchers
|
||||
*/
|
||||
_closeFile(path: Path): void;
|
||||
_addPathCloser(path: Path, closer: () => void): void;
|
||||
_readdirp(root: Path, opts?: Partial<ReaddirpOptions>): ReaddirpStream | undefined;
|
||||
}
|
||||
/**
|
||||
* Instantiates watcher with paths to be tracked.
|
||||
* @param paths file / directory paths
|
||||
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
||||
* @returns an instance of FSWatcher for chaining.
|
||||
* @example
|
||||
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
||||
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
||||
*/
|
||||
export declare function watch(paths: string | string[], options?: ChokidarOptions): FSWatcher;
|
||||
declare const _default: {
|
||||
watch: typeof watch;
|
||||
FSWatcher: typeof FSWatcher;
|
||||
};
|
||||
export default _default;
|
||||
+798
@@ -0,0 +1,798 @@
|
||||
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
||||
import { stat as statcb } from 'fs';
|
||||
import { stat, readdir } from 'fs/promises';
|
||||
import { EventEmitter } from 'events';
|
||||
import * as sysPath from 'path';
|
||||
import { readdirp } from 'readdirp';
|
||||
import { NodeFsHandler, EVENTS as EV, isWindows, isIBMi, EMPTY_FN, STR_CLOSE, STR_END, } from './handler.js';
|
||||
const SLASH = '/';
|
||||
const SLASH_SLASH = '//';
|
||||
const ONE_DOT = '.';
|
||||
const TWO_DOTS = '..';
|
||||
const STRING_TYPE = 'string';
|
||||
const BACK_SLASH_RE = /\\/g;
|
||||
const DOUBLE_SLASH_RE = /\/\//;
|
||||
const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
||||
const REPLACER_RE = /^\.[/\\]/;
|
||||
function arrify(item) {
|
||||
return Array.isArray(item) ? item : [item];
|
||||
}
|
||||
const isMatcherObject = (matcher) => typeof matcher === 'object' && matcher !== null && !(matcher instanceof RegExp);
|
||||
function createPattern(matcher) {
|
||||
if (typeof matcher === 'function')
|
||||
return matcher;
|
||||
if (typeof matcher === 'string')
|
||||
return (string) => matcher === string;
|
||||
if (matcher instanceof RegExp)
|
||||
return (string) => matcher.test(string);
|
||||
if (typeof matcher === 'object' && matcher !== null) {
|
||||
return (string) => {
|
||||
if (matcher.path === string)
|
||||
return true;
|
||||
if (matcher.recursive) {
|
||||
const relative = sysPath.relative(matcher.path, string);
|
||||
if (!relative) {
|
||||
return false;
|
||||
}
|
||||
return !relative.startsWith('..') && !sysPath.isAbsolute(relative);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
return () => false;
|
||||
}
|
||||
function normalizePath(path) {
|
||||
if (typeof path !== 'string')
|
||||
throw new Error('string expected');
|
||||
path = sysPath.normalize(path);
|
||||
path = path.replace(/\\/g, '/');
|
||||
let prepend = false;
|
||||
if (path.startsWith('//'))
|
||||
prepend = true;
|
||||
const DOUBLE_SLASH_RE = /\/\//;
|
||||
while (path.match(DOUBLE_SLASH_RE))
|
||||
path = path.replace(DOUBLE_SLASH_RE, '/');
|
||||
if (prepend)
|
||||
path = '/' + path;
|
||||
return path;
|
||||
}
|
||||
function matchPatterns(patterns, testString, stats) {
|
||||
const path = normalizePath(testString);
|
||||
for (let index = 0; index < patterns.length; index++) {
|
||||
const pattern = patterns[index];
|
||||
if (pattern(path, stats)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function anymatch(matchers, testString) {
|
||||
if (matchers == null) {
|
||||
throw new TypeError('anymatch: specify first argument');
|
||||
}
|
||||
// Early cache for matchers.
|
||||
const matchersArray = arrify(matchers);
|
||||
const patterns = matchersArray.map((matcher) => createPattern(matcher));
|
||||
if (testString == null) {
|
||||
return (testString, stats) => {
|
||||
return matchPatterns(patterns, testString, stats);
|
||||
};
|
||||
}
|
||||
return matchPatterns(patterns, testString);
|
||||
}
|
||||
const unifyPaths = (paths_) => {
|
||||
const paths = arrify(paths_).flat();
|
||||
if (!paths.every((p) => typeof p === STRING_TYPE)) {
|
||||
throw new TypeError(`Non-string provided as watch path: ${paths}`);
|
||||
}
|
||||
return paths.map(normalizePathToUnix);
|
||||
};
|
||||
// If SLASH_SLASH occurs at the beginning of path, it is not replaced
|
||||
// because "//StoragePC/DrivePool/Movies" is a valid network path
|
||||
const toUnix = (string) => {
|
||||
let str = string.replace(BACK_SLASH_RE, SLASH);
|
||||
let prepend = false;
|
||||
if (str.startsWith(SLASH_SLASH)) {
|
||||
prepend = true;
|
||||
}
|
||||
while (str.match(DOUBLE_SLASH_RE)) {
|
||||
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
||||
}
|
||||
if (prepend) {
|
||||
str = SLASH + str;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
// Our version of upath.normalize
|
||||
// TODO: this is not equal to path-normalize module - investigate why
|
||||
const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));
|
||||
// TODO: refactor
|
||||
const normalizeIgnored = (cwd = '') => (path) => {
|
||||
if (typeof path === 'string') {
|
||||
return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
|
||||
}
|
||||
else {
|
||||
return path;
|
||||
}
|
||||
};
|
||||
const getAbsolutePath = (path, cwd) => {
|
||||
if (sysPath.isAbsolute(path)) {
|
||||
return path;
|
||||
}
|
||||
return sysPath.join(cwd, path);
|
||||
};
|
||||
const EMPTY_SET = Object.freeze(new Set());
|
||||
/**
|
||||
* Directory entry.
|
||||
*/
|
||||
class DirEntry {
|
||||
constructor(dir, removeWatcher) {
|
||||
this.path = dir;
|
||||
this._removeWatcher = removeWatcher;
|
||||
this.items = new Set();
|
||||
}
|
||||
add(item) {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return;
|
||||
if (item !== ONE_DOT && item !== TWO_DOTS)
|
||||
items.add(item);
|
||||
}
|
||||
async remove(item) {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return;
|
||||
items.delete(item);
|
||||
if (items.size > 0)
|
||||
return;
|
||||
const dir = this.path;
|
||||
try {
|
||||
await readdir(dir);
|
||||
}
|
||||
catch (err) {
|
||||
if (this._removeWatcher) {
|
||||
this._removeWatcher(sysPath.dirname(dir), sysPath.basename(dir));
|
||||
}
|
||||
}
|
||||
}
|
||||
has(item) {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return;
|
||||
return items.has(item);
|
||||
}
|
||||
getChildren() {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return [];
|
||||
return [...items.values()];
|
||||
}
|
||||
dispose() {
|
||||
this.items.clear();
|
||||
this.path = '';
|
||||
this._removeWatcher = EMPTY_FN;
|
||||
this.items = EMPTY_SET;
|
||||
Object.freeze(this);
|
||||
}
|
||||
}
|
||||
const STAT_METHOD_F = 'stat';
|
||||
const STAT_METHOD_L = 'lstat';
|
||||
export class WatchHelper {
|
||||
constructor(path, follow, fsw) {
|
||||
this.fsw = fsw;
|
||||
const watchPath = path;
|
||||
this.path = path = path.replace(REPLACER_RE, '');
|
||||
this.watchPath = watchPath;
|
||||
this.fullWatchPath = sysPath.resolve(watchPath);
|
||||
this.dirParts = [];
|
||||
this.dirParts.forEach((parts) => {
|
||||
if (parts.length > 1)
|
||||
parts.pop();
|
||||
});
|
||||
this.followSymlinks = follow;
|
||||
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
||||
}
|
||||
entryPath(entry) {
|
||||
return sysPath.join(this.watchPath, sysPath.relative(this.watchPath, entry.fullPath));
|
||||
}
|
||||
filterPath(entry) {
|
||||
const { stats } = entry;
|
||||
if (stats && stats.isSymbolicLink())
|
||||
return this.filterDir(entry);
|
||||
const resolvedPath = this.entryPath(entry);
|
||||
// TODO: what if stats is undefined? remove !
|
||||
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
||||
}
|
||||
filterDir(entry) {
|
||||
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Watches files & directories for changes. Emitted events:
|
||||
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
||||
*
|
||||
* new FSWatcher()
|
||||
* .add(directories)
|
||||
* .on('add', path => log('File', path, 'was added'))
|
||||
*/
|
||||
export class FSWatcher extends EventEmitter {
|
||||
// Not indenting methods for history sake; for now.
|
||||
constructor(_opts = {}) {
|
||||
super();
|
||||
this.closed = false;
|
||||
this._closers = new Map();
|
||||
this._ignoredPaths = new Set();
|
||||
this._throttled = new Map();
|
||||
this._streams = new Set();
|
||||
this._symlinkPaths = new Map();
|
||||
this._watched = new Map();
|
||||
this._pendingWrites = new Map();
|
||||
this._pendingUnlinks = new Map();
|
||||
this._readyCount = 0;
|
||||
this._readyEmitted = false;
|
||||
const awf = _opts.awaitWriteFinish;
|
||||
const DEF_AWF = { stabilityThreshold: 2000, pollInterval: 100 };
|
||||
const opts = {
|
||||
// Defaults
|
||||
persistent: true,
|
||||
ignoreInitial: false,
|
||||
ignorePermissionErrors: false,
|
||||
interval: 100,
|
||||
binaryInterval: 300,
|
||||
followSymlinks: true,
|
||||
usePolling: false,
|
||||
// useAsync: false,
|
||||
atomic: true, // NOTE: overwritten later (depends on usePolling)
|
||||
..._opts,
|
||||
// Change format
|
||||
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
||||
awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === 'object' ? { ...DEF_AWF, ...awf } : false,
|
||||
};
|
||||
// Always default to polling on IBM i because fs.watch() is not available on IBM i.
|
||||
if (isIBMi)
|
||||
opts.usePolling = true;
|
||||
// Editor atomic write normalization enabled by default with fs.watch
|
||||
if (opts.atomic === undefined)
|
||||
opts.atomic = !opts.usePolling;
|
||||
// opts.atomic = typeof _opts.atomic === 'number' ? _opts.atomic : 100;
|
||||
// Global override. Useful for developers, who need to force polling for all
|
||||
// instances of chokidar, regardless of usage / dependency depth
|
||||
const envPoll = process.env.CHOKIDAR_USEPOLLING;
|
||||
if (envPoll !== undefined) {
|
||||
const envLower = envPoll.toLowerCase();
|
||||
if (envLower === 'false' || envLower === '0')
|
||||
opts.usePolling = false;
|
||||
else if (envLower === 'true' || envLower === '1')
|
||||
opts.usePolling = true;
|
||||
else
|
||||
opts.usePolling = !!envLower;
|
||||
}
|
||||
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
||||
if (envInterval)
|
||||
opts.interval = Number.parseInt(envInterval, 10);
|
||||
// This is done to emit ready only once, but each 'add' will increase that?
|
||||
let readyCalls = 0;
|
||||
this._emitReady = () => {
|
||||
readyCalls++;
|
||||
if (readyCalls >= this._readyCount) {
|
||||
this._emitReady = EMPTY_FN;
|
||||
this._readyEmitted = true;
|
||||
// use process.nextTick to allow time for listener to be bound
|
||||
process.nextTick(() => this.emit(EV.READY));
|
||||
}
|
||||
};
|
||||
this._emitRaw = (...args) => this.emit(EV.RAW, ...args);
|
||||
this._boundRemove = this._remove.bind(this);
|
||||
this.options = opts;
|
||||
this._nodeFsHandler = new NodeFsHandler(this);
|
||||
// You’re frozen when your heart’s not open.
|
||||
Object.freeze(opts);
|
||||
}
|
||||
_addIgnoredPath(matcher) {
|
||||
if (isMatcherObject(matcher)) {
|
||||
// return early if we already have a deeply equal matcher object
|
||||
for (const ignored of this._ignoredPaths) {
|
||||
if (isMatcherObject(ignored) &&
|
||||
ignored.path === matcher.path &&
|
||||
ignored.recursive === matcher.recursive) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this._ignoredPaths.add(matcher);
|
||||
}
|
||||
_removeIgnoredPath(matcher) {
|
||||
this._ignoredPaths.delete(matcher);
|
||||
// now find any matcher objects with the matcher as path
|
||||
if (typeof matcher === 'string') {
|
||||
for (const ignored of this._ignoredPaths) {
|
||||
// TODO (43081j): make this more efficient.
|
||||
// probably just make a `this._ignoredDirectories` or some
|
||||
// such thing.
|
||||
if (isMatcherObject(ignored) && ignored.path === matcher) {
|
||||
this._ignoredPaths.delete(ignored);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Public methods
|
||||
/**
|
||||
* Adds paths to be watched on an existing FSWatcher instance.
|
||||
* @param paths_ file or file list. Other arguments are unused
|
||||
*/
|
||||
add(paths_, _origAdd, _internal) {
|
||||
const { cwd } = this.options;
|
||||
this.closed = false;
|
||||
this._closePromise = undefined;
|
||||
let paths = unifyPaths(paths_);
|
||||
if (cwd) {
|
||||
paths = paths.map((path) => {
|
||||
const absPath = getAbsolutePath(path, cwd);
|
||||
// Check `path` instead of `absPath` because the cwd portion can't be a glob
|
||||
return absPath;
|
||||
});
|
||||
}
|
||||
paths.forEach((path) => {
|
||||
this._removeIgnoredPath(path);
|
||||
});
|
||||
this._userIgnored = undefined;
|
||||
if (!this._readyCount)
|
||||
this._readyCount = 0;
|
||||
this._readyCount += paths.length;
|
||||
Promise.all(paths.map(async (path) => {
|
||||
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, undefined, 0, _origAdd);
|
||||
if (res)
|
||||
this._emitReady();
|
||||
return res;
|
||||
})).then((results) => {
|
||||
if (this.closed)
|
||||
return;
|
||||
results.forEach((item) => {
|
||||
if (item)
|
||||
this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item));
|
||||
});
|
||||
});
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Close watchers or start ignoring events from specified paths.
|
||||
*/
|
||||
unwatch(paths_) {
|
||||
if (this.closed)
|
||||
return this;
|
||||
const paths = unifyPaths(paths_);
|
||||
const { cwd } = this.options;
|
||||
paths.forEach((path) => {
|
||||
// convert to absolute path unless relative path already matches
|
||||
if (!sysPath.isAbsolute(path) && !this._closers.has(path)) {
|
||||
if (cwd)
|
||||
path = sysPath.join(cwd, path);
|
||||
path = sysPath.resolve(path);
|
||||
}
|
||||
this._closePath(path);
|
||||
this._addIgnoredPath(path);
|
||||
if (this._watched.has(path)) {
|
||||
this._addIgnoredPath({
|
||||
path,
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
// reset the cached userIgnored anymatch fn
|
||||
// to make ignoredPaths changes effective
|
||||
this._userIgnored = undefined;
|
||||
});
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Close watchers and remove all listeners from watched paths.
|
||||
*/
|
||||
close() {
|
||||
if (this._closePromise) {
|
||||
return this._closePromise;
|
||||
}
|
||||
this.closed = true;
|
||||
// Memory management.
|
||||
this.removeAllListeners();
|
||||
const closers = [];
|
||||
this._closers.forEach((closerList) => closerList.forEach((closer) => {
|
||||
const promise = closer();
|
||||
if (promise instanceof Promise)
|
||||
closers.push(promise);
|
||||
}));
|
||||
this._streams.forEach((stream) => stream.destroy());
|
||||
this._userIgnored = undefined;
|
||||
this._readyCount = 0;
|
||||
this._readyEmitted = false;
|
||||
this._watched.forEach((dirent) => dirent.dispose());
|
||||
this._closers.clear();
|
||||
this._watched.clear();
|
||||
this._streams.clear();
|
||||
this._symlinkPaths.clear();
|
||||
this._throttled.clear();
|
||||
this._closePromise = closers.length
|
||||
? Promise.all(closers).then(() => undefined)
|
||||
: Promise.resolve();
|
||||
return this._closePromise;
|
||||
}
|
||||
/**
|
||||
* Expose list of watched paths
|
||||
* @returns for chaining
|
||||
*/
|
||||
getWatched() {
|
||||
const watchList = {};
|
||||
this._watched.forEach((entry, dir) => {
|
||||
const key = this.options.cwd ? sysPath.relative(this.options.cwd, dir) : dir;
|
||||
const index = key || ONE_DOT;
|
||||
watchList[index] = entry.getChildren().sort();
|
||||
});
|
||||
return watchList;
|
||||
}
|
||||
emitWithAll(event, args) {
|
||||
this.emit(event, ...args);
|
||||
if (event !== EV.ERROR)
|
||||
this.emit(EV.ALL, event, ...args);
|
||||
}
|
||||
// Common helpers
|
||||
// --------------
|
||||
/**
|
||||
* Normalize and emit events.
|
||||
* Calling _emit DOES NOT MEAN emit() would be called!
|
||||
* @param event Type of event
|
||||
* @param path File or directory path
|
||||
* @param stats arguments to be passed with event
|
||||
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
async _emit(event, path, stats) {
|
||||
if (this.closed)
|
||||
return;
|
||||
const opts = this.options;
|
||||
if (isWindows)
|
||||
path = sysPath.normalize(path);
|
||||
if (opts.cwd)
|
||||
path = sysPath.relative(opts.cwd, path);
|
||||
const args = [path];
|
||||
if (stats != null)
|
||||
args.push(stats);
|
||||
const awf = opts.awaitWriteFinish;
|
||||
let pw;
|
||||
if (awf && (pw = this._pendingWrites.get(path))) {
|
||||
pw.lastChange = new Date();
|
||||
return this;
|
||||
}
|
||||
if (opts.atomic) {
|
||||
if (event === EV.UNLINK) {
|
||||
this._pendingUnlinks.set(path, [event, ...args]);
|
||||
setTimeout(() => {
|
||||
this._pendingUnlinks.forEach((entry, path) => {
|
||||
this.emit(...entry);
|
||||
this.emit(EV.ALL, ...entry);
|
||||
this._pendingUnlinks.delete(path);
|
||||
});
|
||||
}, typeof opts.atomic === 'number' ? opts.atomic : 100);
|
||||
return this;
|
||||
}
|
||||
if (event === EV.ADD && this._pendingUnlinks.has(path)) {
|
||||
event = EV.CHANGE;
|
||||
this._pendingUnlinks.delete(path);
|
||||
}
|
||||
}
|
||||
if (awf && (event === EV.ADD || event === EV.CHANGE) && this._readyEmitted) {
|
||||
const awfEmit = (err, stats) => {
|
||||
if (err) {
|
||||
event = EV.ERROR;
|
||||
args[0] = err;
|
||||
this.emitWithAll(event, args);
|
||||
}
|
||||
else if (stats) {
|
||||
// if stats doesn't exist the file must have been deleted
|
||||
if (args.length > 1) {
|
||||
args[1] = stats;
|
||||
}
|
||||
else {
|
||||
args.push(stats);
|
||||
}
|
||||
this.emitWithAll(event, args);
|
||||
}
|
||||
};
|
||||
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
||||
return this;
|
||||
}
|
||||
if (event === EV.CHANGE) {
|
||||
const isThrottled = !this._throttle(EV.CHANGE, path, 50);
|
||||
if (isThrottled)
|
||||
return this;
|
||||
}
|
||||
if (opts.alwaysStat &&
|
||||
stats === undefined &&
|
||||
(event === EV.ADD || event === EV.ADD_DIR || event === EV.CHANGE)) {
|
||||
const fullPath = opts.cwd ? sysPath.join(opts.cwd, path) : path;
|
||||
let stats;
|
||||
try {
|
||||
stats = await stat(fullPath);
|
||||
}
|
||||
catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
// Suppress event when fs_stat fails, to avoid sending undefined 'stat'
|
||||
if (!stats || this.closed)
|
||||
return;
|
||||
args.push(stats);
|
||||
}
|
||||
this.emitWithAll(event, args);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Common handler for errors
|
||||
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
_handleError(error) {
|
||||
const code = error && error.code;
|
||||
if (error &&
|
||||
code !== 'ENOENT' &&
|
||||
code !== 'ENOTDIR' &&
|
||||
(!this.options.ignorePermissionErrors || (code !== 'EPERM' && code !== 'EACCES'))) {
|
||||
this.emit(EV.ERROR, error);
|
||||
}
|
||||
return error || this.closed;
|
||||
}
|
||||
/**
|
||||
* Helper utility for throttling
|
||||
* @param actionType type being throttled
|
||||
* @param path being acted upon
|
||||
* @param timeout duration of time to suppress duplicate actions
|
||||
* @returns tracking object or false if action should be suppressed
|
||||
*/
|
||||
_throttle(actionType, path, timeout) {
|
||||
if (!this._throttled.has(actionType)) {
|
||||
this._throttled.set(actionType, new Map());
|
||||
}
|
||||
const action = this._throttled.get(actionType);
|
||||
if (!action)
|
||||
throw new Error('invalid throttle');
|
||||
const actionPath = action.get(path);
|
||||
if (actionPath) {
|
||||
actionPath.count++;
|
||||
return false;
|
||||
}
|
||||
// eslint-disable-next-line prefer-const
|
||||
let timeoutObject;
|
||||
const clear = () => {
|
||||
const item = action.get(path);
|
||||
const count = item ? item.count : 0;
|
||||
action.delete(path);
|
||||
clearTimeout(timeoutObject);
|
||||
if (item)
|
||||
clearTimeout(item.timeoutObject);
|
||||
return count;
|
||||
};
|
||||
timeoutObject = setTimeout(clear, timeout);
|
||||
const thr = { timeoutObject, clear, count: 0 };
|
||||
action.set(path, thr);
|
||||
return thr;
|
||||
}
|
||||
_incrReadyCount() {
|
||||
return this._readyCount++;
|
||||
}
|
||||
/**
|
||||
* Awaits write operation to finish.
|
||||
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
||||
* @param path being acted upon
|
||||
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
||||
* @param event
|
||||
* @param awfEmit Callback to be called when ready for event to be emitted.
|
||||
*/
|
||||
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
||||
const awf = this.options.awaitWriteFinish;
|
||||
if (typeof awf !== 'object')
|
||||
return;
|
||||
const pollInterval = awf.pollInterval;
|
||||
let timeoutHandler;
|
||||
let fullPath = path;
|
||||
if (this.options.cwd && !sysPath.isAbsolute(path)) {
|
||||
fullPath = sysPath.join(this.options.cwd, path);
|
||||
}
|
||||
const now = new Date();
|
||||
const writes = this._pendingWrites;
|
||||
function awaitWriteFinishFn(prevStat) {
|
||||
statcb(fullPath, (err, curStat) => {
|
||||
if (err || !writes.has(path)) {
|
||||
if (err && err.code !== 'ENOENT')
|
||||
awfEmit(err);
|
||||
return;
|
||||
}
|
||||
const now = Number(new Date());
|
||||
if (prevStat && curStat.size !== prevStat.size) {
|
||||
writes.get(path).lastChange = now;
|
||||
}
|
||||
const pw = writes.get(path);
|
||||
const df = now - pw.lastChange;
|
||||
if (df >= threshold) {
|
||||
writes.delete(path);
|
||||
awfEmit(undefined, curStat);
|
||||
}
|
||||
else {
|
||||
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!writes.has(path)) {
|
||||
writes.set(path, {
|
||||
lastChange: now,
|
||||
cancelWait: () => {
|
||||
writes.delete(path);
|
||||
clearTimeout(timeoutHandler);
|
||||
return event;
|
||||
},
|
||||
});
|
||||
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Determines whether user has asked to ignore this path.
|
||||
*/
|
||||
_isIgnored(path, stats) {
|
||||
if (this.options.atomic && DOT_RE.test(path))
|
||||
return true;
|
||||
if (!this._userIgnored) {
|
||||
const { cwd } = this.options;
|
||||
const ign = this.options.ignored;
|
||||
const ignored = (ign || []).map(normalizeIgnored(cwd));
|
||||
const ignoredPaths = [...this._ignoredPaths];
|
||||
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
||||
this._userIgnored = anymatch(list, undefined);
|
||||
}
|
||||
return this._userIgnored(path, stats);
|
||||
}
|
||||
_isntIgnored(path, stat) {
|
||||
return !this._isIgnored(path, stat);
|
||||
}
|
||||
/**
|
||||
* Provides a set of common helpers and properties relating to symlink handling.
|
||||
* @param path file or directory pattern being watched
|
||||
*/
|
||||
_getWatchHelpers(path) {
|
||||
return new WatchHelper(path, this.options.followSymlinks, this);
|
||||
}
|
||||
// Directory helpers
|
||||
// -----------------
|
||||
/**
|
||||
* Provides directory tracking objects
|
||||
* @param directory path of the directory
|
||||
*/
|
||||
_getWatchedDir(directory) {
|
||||
const dir = sysPath.resolve(directory);
|
||||
if (!this._watched.has(dir))
|
||||
this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
||||
return this._watched.get(dir);
|
||||
}
|
||||
// File helpers
|
||||
// ------------
|
||||
/**
|
||||
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
||||
*/
|
||||
_hasReadPermissions(stats) {
|
||||
if (this.options.ignorePermissionErrors)
|
||||
return true;
|
||||
return Boolean(Number(stats.mode) & 0o400);
|
||||
}
|
||||
/**
|
||||
* Handles emitting unlink events for
|
||||
* files and directories, and via recursion, for
|
||||
* files and directories within directories that are unlinked
|
||||
* @param directory within which the following item is located
|
||||
* @param item base path of item/directory
|
||||
*/
|
||||
_remove(directory, item, isDirectory) {
|
||||
// if what is being deleted is a directory, get that directory's paths
|
||||
// for recursive deleting and cleaning of watched object
|
||||
// if it is not a directory, nestedDirectoryChildren will be empty array
|
||||
const path = sysPath.join(directory, item);
|
||||
const fullPath = sysPath.resolve(path);
|
||||
isDirectory =
|
||||
isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
|
||||
// prevent duplicate handling in case of arriving here nearly simultaneously
|
||||
// via multiple paths (such as _handleFile and _handleDir)
|
||||
if (!this._throttle('remove', path, 100))
|
||||
return;
|
||||
// if the only watched file is removed, watch for its return
|
||||
if (!isDirectory && this._watched.size === 1) {
|
||||
this.add(directory, item, true);
|
||||
}
|
||||
// This will create a new entry in the watched object in either case
|
||||
// so we got to do the directory check beforehand
|
||||
const wp = this._getWatchedDir(path);
|
||||
const nestedDirectoryChildren = wp.getChildren();
|
||||
// Recursively remove children directories / files.
|
||||
nestedDirectoryChildren.forEach((nested) => this._remove(path, nested));
|
||||
// Check if item was on the watched list and remove it
|
||||
const parent = this._getWatchedDir(directory);
|
||||
const wasTracked = parent.has(item);
|
||||
parent.remove(item);
|
||||
// Fixes issue #1042 -> Relative paths were detected and added as symlinks
|
||||
// (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
|
||||
// but never removed from the map in case the path was deleted.
|
||||
// This leads to an incorrect state if the path was recreated:
|
||||
// https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
|
||||
if (this._symlinkPaths.has(fullPath)) {
|
||||
this._symlinkPaths.delete(fullPath);
|
||||
}
|
||||
// If we wait for this file to be fully written, cancel the wait.
|
||||
let relPath = path;
|
||||
if (this.options.cwd)
|
||||
relPath = sysPath.relative(this.options.cwd, path);
|
||||
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
||||
const event = this._pendingWrites.get(relPath).cancelWait();
|
||||
if (event === EV.ADD)
|
||||
return;
|
||||
}
|
||||
// The Entry will either be a directory that just got removed
|
||||
// or a bogus entry to a file, in either case we have to remove it
|
||||
this._watched.delete(path);
|
||||
this._watched.delete(fullPath);
|
||||
const eventName = isDirectory ? EV.UNLINK_DIR : EV.UNLINK;
|
||||
if (wasTracked && !this._isIgnored(path))
|
||||
this._emit(eventName, path);
|
||||
// Avoid conflicts if we later create another file with the same name
|
||||
this._closePath(path);
|
||||
}
|
||||
/**
|
||||
* Closes all watchers for a path
|
||||
*/
|
||||
_closePath(path) {
|
||||
this._closeFile(path);
|
||||
const dir = sysPath.dirname(path);
|
||||
this._getWatchedDir(dir).remove(sysPath.basename(path));
|
||||
}
|
||||
/**
|
||||
* Closes only file-specific watchers
|
||||
*/
|
||||
_closeFile(path) {
|
||||
const closers = this._closers.get(path);
|
||||
if (!closers)
|
||||
return;
|
||||
closers.forEach((closer) => closer());
|
||||
this._closers.delete(path);
|
||||
}
|
||||
_addPathCloser(path, closer) {
|
||||
if (!closer)
|
||||
return;
|
||||
let list = this._closers.get(path);
|
||||
if (!list) {
|
||||
list = [];
|
||||
this._closers.set(path, list);
|
||||
}
|
||||
list.push(closer);
|
||||
}
|
||||
_readdirp(root, opts) {
|
||||
if (this.closed)
|
||||
return;
|
||||
const options = { type: EV.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
|
||||
let stream = readdirp(root, options);
|
||||
this._streams.add(stream);
|
||||
stream.once(STR_CLOSE, () => {
|
||||
stream = undefined;
|
||||
});
|
||||
stream.once(STR_END, () => {
|
||||
if (stream) {
|
||||
this._streams.delete(stream);
|
||||
stream = undefined;
|
||||
}
|
||||
});
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Instantiates watcher with paths to be tracked.
|
||||
* @param paths file / directory paths
|
||||
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
||||
* @returns an instance of FSWatcher for chaining.
|
||||
* @example
|
||||
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
||||
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
||||
*/
|
||||
export function watch(paths, options = {}) {
|
||||
const watcher = new FSWatcher(options);
|
||||
watcher.add(paths);
|
||||
return watcher;
|
||||
}
|
||||
export default { watch, FSWatcher };
|
||||
+1
@@ -0,0 +1 @@
|
||||
{ "type": "module", "sideEffects": false }
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
import type { WatchEventType, Stats, FSWatcher as NativeFsWatcher } from 'fs';
|
||||
import type { FSWatcher, WatchHelper, Throttler } from './index.js';
|
||||
import type { EntryInfo } from 'readdirp';
|
||||
export type Path = string;
|
||||
export declare const STR_DATA = "data";
|
||||
export declare const STR_END = "end";
|
||||
export declare const STR_CLOSE = "close";
|
||||
export declare const EMPTY_FN: () => void;
|
||||
export declare const IDENTITY_FN: (val: unknown) => unknown;
|
||||
export declare const isWindows: boolean;
|
||||
export declare const isMacos: boolean;
|
||||
export declare const isLinux: boolean;
|
||||
export declare const isFreeBSD: boolean;
|
||||
export declare const isIBMi: boolean;
|
||||
export declare const EVENTS: {
|
||||
readonly ALL: "all";
|
||||
readonly READY: "ready";
|
||||
readonly ADD: "add";
|
||||
readonly CHANGE: "change";
|
||||
readonly ADD_DIR: "addDir";
|
||||
readonly UNLINK: "unlink";
|
||||
readonly UNLINK_DIR: "unlinkDir";
|
||||
readonly RAW: "raw";
|
||||
readonly ERROR: "error";
|
||||
};
|
||||
export type EventName = (typeof EVENTS)[keyof typeof EVENTS];
|
||||
export type FsWatchContainer = {
|
||||
listeners: (path: string) => void | Set<any>;
|
||||
errHandlers: (err: unknown) => void | Set<any>;
|
||||
rawEmitters: (ev: WatchEventType, path: string, opts: unknown) => void | Set<any>;
|
||||
watcher: NativeFsWatcher;
|
||||
watcherUnusable?: boolean;
|
||||
};
|
||||
export interface WatchHandlers {
|
||||
listener: (path: string) => void;
|
||||
errHandler: (err: unknown) => void;
|
||||
rawEmitter: (ev: WatchEventType, path: string, opts: unknown) => void;
|
||||
}
|
||||
/**
|
||||
* @mixin
|
||||
*/
|
||||
export declare class NodeFsHandler {
|
||||
fsw: FSWatcher;
|
||||
_boundHandleError: (error: unknown) => void;
|
||||
constructor(fsW: FSWatcher);
|
||||
/**
|
||||
* Watch file for changes with fs_watchFile or fs_watch.
|
||||
* @param path to file or dir
|
||||
* @param listener on fs change
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_watchWithNodeFs(path: string, listener: (path: string, newStats?: any) => void | Promise<void>): (() => void) | undefined;
|
||||
/**
|
||||
* Watch a file and emit add event if warranted.
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_handleFile(file: Path, stats: Stats, initialAdd: boolean): (() => void) | undefined;
|
||||
/**
|
||||
* Handle symlinks encountered while reading a dir.
|
||||
* @param entry returned by readdirp
|
||||
* @param directory path of dir being read
|
||||
* @param path of this item
|
||||
* @param item basename of this item
|
||||
* @returns true if no more processing is needed for this entry.
|
||||
*/
|
||||
_handleSymlink(entry: EntryInfo, directory: string, path: Path, item: string): Promise<boolean | undefined>;
|
||||
_handleRead(directory: string, initialAdd: boolean, wh: WatchHelper, target: Path, dir: Path, depth: number, throttler: Throttler): Promise<unknown> | undefined;
|
||||
/**
|
||||
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
||||
* @param dir fs path
|
||||
* @param stats
|
||||
* @param initialAdd
|
||||
* @param depth relative to user-supplied path
|
||||
* @param target child path targeted for watch
|
||||
* @param wh Common watch helpers for this path
|
||||
* @param realpath
|
||||
* @returns closer for the watcher instance.
|
||||
*/
|
||||
_handleDir(dir: string, stats: Stats, initialAdd: boolean, depth: number, target: string, wh: WatchHelper, realpath: string): Promise<(() => void) | undefined>;
|
||||
/**
|
||||
* Handle added file, directory, or glob pattern.
|
||||
* Delegates call to _handleFile / _handleDir after checks.
|
||||
* @param path to file or ir
|
||||
* @param initialAdd was the file added at watch instantiation?
|
||||
* @param priorWh depth relative to user-supplied path
|
||||
* @param depth Child path actually targeted for watch
|
||||
* @param target Child path actually targeted for watch
|
||||
*/
|
||||
_addToNodeFs(path: string, initialAdd: boolean, priorWh: WatchHelper | undefined, depth: number, target?: string): Promise<string | false | undefined>;
|
||||
}
|
||||
+635
@@ -0,0 +1,635 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NodeFsHandler = exports.EVENTS = exports.isIBMi = exports.isFreeBSD = exports.isLinux = exports.isMacos = exports.isWindows = exports.IDENTITY_FN = exports.EMPTY_FN = exports.STR_CLOSE = exports.STR_END = exports.STR_DATA = void 0;
|
||||
const fs_1 = require("fs");
|
||||
const promises_1 = require("fs/promises");
|
||||
const sysPath = require("path");
|
||||
const os_1 = require("os");
|
||||
exports.STR_DATA = 'data';
|
||||
exports.STR_END = 'end';
|
||||
exports.STR_CLOSE = 'close';
|
||||
const EMPTY_FN = () => { };
|
||||
exports.EMPTY_FN = EMPTY_FN;
|
||||
const IDENTITY_FN = (val) => val;
|
||||
exports.IDENTITY_FN = IDENTITY_FN;
|
||||
const pl = process.platform;
|
||||
exports.isWindows = pl === 'win32';
|
||||
exports.isMacos = pl === 'darwin';
|
||||
exports.isLinux = pl === 'linux';
|
||||
exports.isFreeBSD = pl === 'freebsd';
|
||||
exports.isIBMi = (0, os_1.type)() === 'OS400';
|
||||
exports.EVENTS = {
|
||||
ALL: 'all',
|
||||
READY: 'ready',
|
||||
ADD: 'add',
|
||||
CHANGE: 'change',
|
||||
ADD_DIR: 'addDir',
|
||||
UNLINK: 'unlink',
|
||||
UNLINK_DIR: 'unlinkDir',
|
||||
RAW: 'raw',
|
||||
ERROR: 'error',
|
||||
};
|
||||
const EV = exports.EVENTS;
|
||||
const THROTTLE_MODE_WATCH = 'watch';
|
||||
const statMethods = { lstat: promises_1.lstat, stat: promises_1.stat };
|
||||
const KEY_LISTENERS = 'listeners';
|
||||
const KEY_ERR = 'errHandlers';
|
||||
const KEY_RAW = 'rawEmitters';
|
||||
const HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
||||
// prettier-ignore
|
||||
const binaryExtensions = new Set([
|
||||
'3dm', '3ds', '3g2', '3gp', '7z', 'a', 'aac', 'adp', 'afdesign', 'afphoto', 'afpub', 'ai',
|
||||
'aif', 'aiff', 'alz', 'ape', 'apk', 'appimage', 'ar', 'arj', 'asf', 'au', 'avi',
|
||||
'bak', 'baml', 'bh', 'bin', 'bk', 'bmp', 'btif', 'bz2', 'bzip2',
|
||||
'cab', 'caf', 'cgm', 'class', 'cmx', 'cpio', 'cr2', 'cur', 'dat', 'dcm', 'deb', 'dex', 'djvu',
|
||||
'dll', 'dmg', 'dng', 'doc', 'docm', 'docx', 'dot', 'dotm', 'dra', 'DS_Store', 'dsk', 'dts',
|
||||
'dtshd', 'dvb', 'dwg', 'dxf',
|
||||
'ecelp4800', 'ecelp7470', 'ecelp9600', 'egg', 'eol', 'eot', 'epub', 'exe',
|
||||
'f4v', 'fbs', 'fh', 'fla', 'flac', 'flatpak', 'fli', 'flv', 'fpx', 'fst', 'fvt',
|
||||
'g3', 'gh', 'gif', 'graffle', 'gz', 'gzip',
|
||||
'h261', 'h263', 'h264', 'icns', 'ico', 'ief', 'img', 'ipa', 'iso',
|
||||
'jar', 'jpeg', 'jpg', 'jpgv', 'jpm', 'jxr', 'key', 'ktx',
|
||||
'lha', 'lib', 'lvp', 'lz', 'lzh', 'lzma', 'lzo',
|
||||
'm3u', 'm4a', 'm4v', 'mar', 'mdi', 'mht', 'mid', 'midi', 'mj2', 'mka', 'mkv', 'mmr', 'mng',
|
||||
'mobi', 'mov', 'movie', 'mp3',
|
||||
'mp4', 'mp4a', 'mpeg', 'mpg', 'mpga', 'mxu',
|
||||
'nef', 'npx', 'numbers', 'nupkg',
|
||||
'o', 'odp', 'ods', 'odt', 'oga', 'ogg', 'ogv', 'otf', 'ott',
|
||||
'pages', 'pbm', 'pcx', 'pdb', 'pdf', 'pea', 'pgm', 'pic', 'png', 'pnm', 'pot', 'potm',
|
||||
'potx', 'ppa', 'ppam',
|
||||
'ppm', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx', 'psd', 'pya', 'pyc', 'pyo', 'pyv',
|
||||
'qt',
|
||||
'rar', 'ras', 'raw', 'resources', 'rgb', 'rip', 'rlc', 'rmf', 'rmvb', 'rpm', 'rtf', 'rz',
|
||||
's3m', 's7z', 'scpt', 'sgi', 'shar', 'snap', 'sil', 'sketch', 'slk', 'smv', 'snk', 'so',
|
||||
'stl', 'suo', 'sub', 'swf',
|
||||
'tar', 'tbz', 'tbz2', 'tga', 'tgz', 'thmx', 'tif', 'tiff', 'tlz', 'ttc', 'ttf', 'txz',
|
||||
'udf', 'uvh', 'uvi', 'uvm', 'uvp', 'uvs', 'uvu',
|
||||
'viv', 'vob',
|
||||
'war', 'wav', 'wax', 'wbmp', 'wdp', 'weba', 'webm', 'webp', 'whl', 'wim', 'wm', 'wma',
|
||||
'wmv', 'wmx', 'woff', 'woff2', 'wrm', 'wvx',
|
||||
'xbm', 'xif', 'xla', 'xlam', 'xls', 'xlsb', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx', 'xm',
|
||||
'xmind', 'xpi', 'xpm', 'xwd', 'xz',
|
||||
'z', 'zip', 'zipx',
|
||||
]);
|
||||
const isBinaryPath = (filePath) => binaryExtensions.has(sysPath.extname(filePath).slice(1).toLowerCase());
|
||||
// TODO: emit errors properly. Example: EMFILE on Macos.
|
||||
const foreach = (val, fn) => {
|
||||
if (val instanceof Set) {
|
||||
val.forEach(fn);
|
||||
}
|
||||
else {
|
||||
fn(val);
|
||||
}
|
||||
};
|
||||
const addAndConvert = (main, prop, item) => {
|
||||
let container = main[prop];
|
||||
if (!(container instanceof Set)) {
|
||||
main[prop] = container = new Set([container]);
|
||||
}
|
||||
container.add(item);
|
||||
};
|
||||
const clearItem = (cont) => (key) => {
|
||||
const set = cont[key];
|
||||
if (set instanceof Set) {
|
||||
set.clear();
|
||||
}
|
||||
else {
|
||||
delete cont[key];
|
||||
}
|
||||
};
|
||||
const delFromSet = (main, prop, item) => {
|
||||
const container = main[prop];
|
||||
if (container instanceof Set) {
|
||||
container.delete(item);
|
||||
}
|
||||
else if (container === item) {
|
||||
delete main[prop];
|
||||
}
|
||||
};
|
||||
const isEmptySet = (val) => (val instanceof Set ? val.size === 0 : !val);
|
||||
const FsWatchInstances = new Map();
|
||||
/**
|
||||
* Instantiates the fs_watch interface
|
||||
* @param path to be watched
|
||||
* @param options to be passed to fs_watch
|
||||
* @param listener main event handler
|
||||
* @param errHandler emits info about errors
|
||||
* @param emitRaw emits raw event data
|
||||
* @returns {NativeFsWatcher}
|
||||
*/
|
||||
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
||||
const handleEvent = (rawEvent, evPath) => {
|
||||
listener(path);
|
||||
emitRaw(rawEvent, evPath, { watchedPath: path });
|
||||
// emit based on events occurring for files from a directory's watcher in
|
||||
// case the file's watcher misses it (and rely on throttling to de-dupe)
|
||||
if (evPath && path !== evPath) {
|
||||
fsWatchBroadcast(sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath));
|
||||
}
|
||||
};
|
||||
try {
|
||||
return (0, fs_1.watch)(path, {
|
||||
persistent: options.persistent,
|
||||
}, handleEvent);
|
||||
}
|
||||
catch (error) {
|
||||
errHandler(error);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Helper for passing fs_watch event data to a collection of listeners
|
||||
* @param fullPath absolute path bound to fs_watch instance
|
||||
*/
|
||||
const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
||||
const cont = FsWatchInstances.get(fullPath);
|
||||
if (!cont)
|
||||
return;
|
||||
foreach(cont[listenerType], (listener) => {
|
||||
listener(val1, val2, val3);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Instantiates the fs_watch interface or binds listeners
|
||||
* to an existing one covering the same file system entry
|
||||
* @param path
|
||||
* @param fullPath absolute path
|
||||
* @param options to be passed to fs_watch
|
||||
* @param handlers container for event listener functions
|
||||
*/
|
||||
const setFsWatchListener = (path, fullPath, options, handlers) => {
|
||||
const { listener, errHandler, rawEmitter } = handlers;
|
||||
let cont = FsWatchInstances.get(fullPath);
|
||||
let watcher;
|
||||
if (!options.persistent) {
|
||||
watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
|
||||
if (!watcher)
|
||||
return;
|
||||
return watcher.close.bind(watcher);
|
||||
}
|
||||
if (cont) {
|
||||
addAndConvert(cont, KEY_LISTENERS, listener);
|
||||
addAndConvert(cont, KEY_ERR, errHandler);
|
||||
addAndConvert(cont, KEY_RAW, rawEmitter);
|
||||
}
|
||||
else {
|
||||
watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, // no need to use broadcast here
|
||||
fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
|
||||
if (!watcher)
|
||||
return;
|
||||
watcher.on(EV.ERROR, async (error) => {
|
||||
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
||||
if (cont)
|
||||
cont.watcherUnusable = true; // documented since Node 10.4.1
|
||||
// Workaround for https://github.com/joyent/node/issues/4337
|
||||
if (exports.isWindows && error.code === 'EPERM') {
|
||||
try {
|
||||
const fd = await (0, promises_1.open)(path, 'r');
|
||||
await fd.close();
|
||||
broadcastErr(error);
|
||||
}
|
||||
catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
else {
|
||||
broadcastErr(error);
|
||||
}
|
||||
});
|
||||
cont = {
|
||||
listeners: listener,
|
||||
errHandlers: errHandler,
|
||||
rawEmitters: rawEmitter,
|
||||
watcher,
|
||||
};
|
||||
FsWatchInstances.set(fullPath, cont);
|
||||
}
|
||||
// const index = cont.listeners.indexOf(listener);
|
||||
// removes this instance's listeners and closes the underlying fs_watch
|
||||
// instance if there are no more listeners left
|
||||
return () => {
|
||||
delFromSet(cont, KEY_LISTENERS, listener);
|
||||
delFromSet(cont, KEY_ERR, errHandler);
|
||||
delFromSet(cont, KEY_RAW, rawEmitter);
|
||||
if (isEmptySet(cont.listeners)) {
|
||||
// Check to protect against issue gh-730.
|
||||
// if (cont.watcherUnusable) {
|
||||
cont.watcher.close();
|
||||
// }
|
||||
FsWatchInstances.delete(fullPath);
|
||||
HANDLER_KEYS.forEach(clearItem(cont));
|
||||
// @ts-ignore
|
||||
cont.watcher = undefined;
|
||||
Object.freeze(cont);
|
||||
}
|
||||
};
|
||||
};
|
||||
// fs_watchFile helpers
|
||||
// object to hold per-process fs_watchFile instances
|
||||
// (may be shared across chokidar FSWatcher instances)
|
||||
const FsWatchFileInstances = new Map();
|
||||
/**
|
||||
* Instantiates the fs_watchFile interface or binds listeners
|
||||
* to an existing one covering the same file system entry
|
||||
* @param path to be watched
|
||||
* @param fullPath absolute path
|
||||
* @param options options to be passed to fs_watchFile
|
||||
* @param handlers container for event listener functions
|
||||
* @returns closer
|
||||
*/
|
||||
const setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
||||
const { listener, rawEmitter } = handlers;
|
||||
let cont = FsWatchFileInstances.get(fullPath);
|
||||
// let listeners = new Set();
|
||||
// let rawEmitters = new Set();
|
||||
const copts = cont && cont.options;
|
||||
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
||||
// "Upgrade" the watcher to persistence or a quicker interval.
|
||||
// This creates some unlikely edge case issues if the user mixes
|
||||
// settings in a very weird way, but solving for those cases
|
||||
// doesn't seem worthwhile for the added complexity.
|
||||
// listeners = cont.listeners;
|
||||
// rawEmitters = cont.rawEmitters;
|
||||
(0, fs_1.unwatchFile)(fullPath);
|
||||
cont = undefined;
|
||||
}
|
||||
if (cont) {
|
||||
addAndConvert(cont, KEY_LISTENERS, listener);
|
||||
addAndConvert(cont, KEY_RAW, rawEmitter);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
// listeners.add(listener);
|
||||
// rawEmitters.add(rawEmitter);
|
||||
cont = {
|
||||
listeners: listener,
|
||||
rawEmitters: rawEmitter,
|
||||
options,
|
||||
watcher: (0, fs_1.watchFile)(fullPath, options, (curr, prev) => {
|
||||
foreach(cont.rawEmitters, (rawEmitter) => {
|
||||
rawEmitter(EV.CHANGE, fullPath, { curr, prev });
|
||||
});
|
||||
const currmtime = curr.mtimeMs;
|
||||
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
||||
foreach(cont.listeners, (listener) => listener(path, curr));
|
||||
}
|
||||
}),
|
||||
};
|
||||
FsWatchFileInstances.set(fullPath, cont);
|
||||
}
|
||||
// const index = cont.listeners.indexOf(listener);
|
||||
// Removes this instance's listeners and closes the underlying fs_watchFile
|
||||
// instance if there are no more listeners left.
|
||||
return () => {
|
||||
delFromSet(cont, KEY_LISTENERS, listener);
|
||||
delFromSet(cont, KEY_RAW, rawEmitter);
|
||||
if (isEmptySet(cont.listeners)) {
|
||||
FsWatchFileInstances.delete(fullPath);
|
||||
(0, fs_1.unwatchFile)(fullPath);
|
||||
cont.options = cont.watcher = undefined;
|
||||
Object.freeze(cont);
|
||||
}
|
||||
};
|
||||
};
|
||||
/**
|
||||
* @mixin
|
||||
*/
|
||||
class NodeFsHandler {
|
||||
constructor(fsW) {
|
||||
this.fsw = fsW;
|
||||
this._boundHandleError = (error) => fsW._handleError(error);
|
||||
}
|
||||
/**
|
||||
* Watch file for changes with fs_watchFile or fs_watch.
|
||||
* @param path to file or dir
|
||||
* @param listener on fs change
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_watchWithNodeFs(path, listener) {
|
||||
const opts = this.fsw.options;
|
||||
const directory = sysPath.dirname(path);
|
||||
const basename = sysPath.basename(path);
|
||||
const parent = this.fsw._getWatchedDir(directory);
|
||||
parent.add(basename);
|
||||
const absolutePath = sysPath.resolve(path);
|
||||
const options = {
|
||||
persistent: opts.persistent,
|
||||
};
|
||||
if (!listener)
|
||||
listener = exports.EMPTY_FN;
|
||||
let closer;
|
||||
if (opts.usePolling) {
|
||||
const enableBin = opts.interval !== opts.binaryInterval;
|
||||
options.interval = enableBin && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
|
||||
closer = setFsWatchFileListener(path, absolutePath, options, {
|
||||
listener,
|
||||
rawEmitter: this.fsw._emitRaw,
|
||||
});
|
||||
}
|
||||
else {
|
||||
closer = setFsWatchListener(path, absolutePath, options, {
|
||||
listener,
|
||||
errHandler: this._boundHandleError,
|
||||
rawEmitter: this.fsw._emitRaw,
|
||||
});
|
||||
}
|
||||
return closer;
|
||||
}
|
||||
/**
|
||||
* Watch a file and emit add event if warranted.
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_handleFile(file, stats, initialAdd) {
|
||||
if (this.fsw.closed) {
|
||||
return;
|
||||
}
|
||||
const dirname = sysPath.dirname(file);
|
||||
const basename = sysPath.basename(file);
|
||||
const parent = this.fsw._getWatchedDir(dirname);
|
||||
// stats is always present
|
||||
let prevStats = stats;
|
||||
// if the file is already being watched, do nothing
|
||||
if (parent.has(basename))
|
||||
return;
|
||||
const listener = async (path, newStats) => {
|
||||
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
||||
return;
|
||||
if (!newStats || newStats.mtimeMs === 0) {
|
||||
try {
|
||||
const newStats = await (0, promises_1.stat)(file);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
// Check that change event was not fired because of changed only accessTime.
|
||||
const at = newStats.atimeMs;
|
||||
const mt = newStats.mtimeMs;
|
||||
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
||||
this.fsw._emit(EV.CHANGE, file, newStats);
|
||||
}
|
||||
if ((exports.isMacos || exports.isLinux || exports.isFreeBSD) && prevStats.ino !== newStats.ino) {
|
||||
this.fsw._closeFile(path);
|
||||
prevStats = newStats;
|
||||
const closer = this._watchWithNodeFs(file, listener);
|
||||
if (closer)
|
||||
this.fsw._addPathCloser(path, closer);
|
||||
}
|
||||
else {
|
||||
prevStats = newStats;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
// Fix issues where mtime is null but file is still present
|
||||
this.fsw._remove(dirname, basename);
|
||||
}
|
||||
// add is about to be emitted if file not already tracked in parent
|
||||
}
|
||||
else if (parent.has(basename)) {
|
||||
// Check that change event was not fired because of changed only accessTime.
|
||||
const at = newStats.atimeMs;
|
||||
const mt = newStats.mtimeMs;
|
||||
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
||||
this.fsw._emit(EV.CHANGE, file, newStats);
|
||||
}
|
||||
prevStats = newStats;
|
||||
}
|
||||
};
|
||||
// kick off the watcher
|
||||
const closer = this._watchWithNodeFs(file, listener);
|
||||
// emit an add event if we're supposed to
|
||||
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
||||
if (!this.fsw._throttle(EV.ADD, file, 0))
|
||||
return;
|
||||
this.fsw._emit(EV.ADD, file, stats);
|
||||
}
|
||||
return closer;
|
||||
}
|
||||
/**
|
||||
* Handle symlinks encountered while reading a dir.
|
||||
* @param entry returned by readdirp
|
||||
* @param directory path of dir being read
|
||||
* @param path of this item
|
||||
* @param item basename of this item
|
||||
* @returns true if no more processing is needed for this entry.
|
||||
*/
|
||||
async _handleSymlink(entry, directory, path, item) {
|
||||
if (this.fsw.closed) {
|
||||
return;
|
||||
}
|
||||
const full = entry.fullPath;
|
||||
const dir = this.fsw._getWatchedDir(directory);
|
||||
if (!this.fsw.options.followSymlinks) {
|
||||
// watch symlink directly (don't follow) and detect changes
|
||||
this.fsw._incrReadyCount();
|
||||
let linkPath;
|
||||
try {
|
||||
linkPath = await (0, promises_1.realpath)(path);
|
||||
}
|
||||
catch (e) {
|
||||
this.fsw._emitReady();
|
||||
return true;
|
||||
}
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
if (dir.has(item)) {
|
||||
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
||||
this.fsw._symlinkPaths.set(full, linkPath);
|
||||
this.fsw._emit(EV.CHANGE, path, entry.stats);
|
||||
}
|
||||
}
|
||||
else {
|
||||
dir.add(item);
|
||||
this.fsw._symlinkPaths.set(full, linkPath);
|
||||
this.fsw._emit(EV.ADD, path, entry.stats);
|
||||
}
|
||||
this.fsw._emitReady();
|
||||
return true;
|
||||
}
|
||||
// don't follow the same symlink more than once
|
||||
if (this.fsw._symlinkPaths.has(full)) {
|
||||
return true;
|
||||
}
|
||||
this.fsw._symlinkPaths.set(full, true);
|
||||
}
|
||||
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
||||
// Normalize the directory name on Windows
|
||||
directory = sysPath.join(directory, '');
|
||||
throttler = this.fsw._throttle('readdir', directory, 1000);
|
||||
if (!throttler)
|
||||
return;
|
||||
const previous = this.fsw._getWatchedDir(wh.path);
|
||||
const current = new Set();
|
||||
let stream = this.fsw._readdirp(directory, {
|
||||
fileFilter: (entry) => wh.filterPath(entry),
|
||||
directoryFilter: (entry) => wh.filterDir(entry),
|
||||
});
|
||||
if (!stream)
|
||||
return;
|
||||
stream
|
||||
.on(exports.STR_DATA, async (entry) => {
|
||||
if (this.fsw.closed) {
|
||||
stream = undefined;
|
||||
return;
|
||||
}
|
||||
const item = entry.path;
|
||||
let path = sysPath.join(directory, item);
|
||||
current.add(item);
|
||||
if (entry.stats.isSymbolicLink() &&
|
||||
(await this._handleSymlink(entry, directory, path, item))) {
|
||||
return;
|
||||
}
|
||||
if (this.fsw.closed) {
|
||||
stream = undefined;
|
||||
return;
|
||||
}
|
||||
// Files that present in current directory snapshot
|
||||
// but absent in previous are added to watch list and
|
||||
// emit `add` event.
|
||||
if (item === target || (!target && !previous.has(item))) {
|
||||
this.fsw._incrReadyCount();
|
||||
// ensure relativeness of path is preserved in case of watcher reuse
|
||||
path = sysPath.join(dir, sysPath.relative(dir, path));
|
||||
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
||||
}
|
||||
})
|
||||
.on(EV.ERROR, this._boundHandleError);
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!stream)
|
||||
return reject();
|
||||
stream.once(exports.STR_END, () => {
|
||||
if (this.fsw.closed) {
|
||||
stream = undefined;
|
||||
return;
|
||||
}
|
||||
const wasThrottled = throttler ? throttler.clear() : false;
|
||||
resolve(undefined);
|
||||
// Files that absent in current directory snapshot
|
||||
// but present in previous emit `remove` event
|
||||
// and are removed from @watched[directory].
|
||||
previous
|
||||
.getChildren()
|
||||
.filter((item) => {
|
||||
return item !== directory && !current.has(item);
|
||||
})
|
||||
.forEach((item) => {
|
||||
this.fsw._remove(directory, item);
|
||||
});
|
||||
stream = undefined;
|
||||
// one more time for any missed in case changes came in extremely quickly
|
||||
if (wasThrottled)
|
||||
this._handleRead(directory, false, wh, target, dir, depth, throttler);
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
||||
* @param dir fs path
|
||||
* @param stats
|
||||
* @param initialAdd
|
||||
* @param depth relative to user-supplied path
|
||||
* @param target child path targeted for watch
|
||||
* @param wh Common watch helpers for this path
|
||||
* @param realpath
|
||||
* @returns closer for the watcher instance.
|
||||
*/
|
||||
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
|
||||
const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
|
||||
const tracked = parentDir.has(sysPath.basename(dir));
|
||||
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
|
||||
this.fsw._emit(EV.ADD_DIR, dir, stats);
|
||||
}
|
||||
// ensure dir is tracked (harmless if redundant)
|
||||
parentDir.add(sysPath.basename(dir));
|
||||
this.fsw._getWatchedDir(dir);
|
||||
let throttler;
|
||||
let closer;
|
||||
const oDepth = this.fsw.options.depth;
|
||||
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
|
||||
if (!target) {
|
||||
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
}
|
||||
closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
|
||||
// if current directory is removed, do nothing
|
||||
if (stats && stats.mtimeMs === 0)
|
||||
return;
|
||||
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
||||
});
|
||||
}
|
||||
return closer;
|
||||
}
|
||||
/**
|
||||
* Handle added file, directory, or glob pattern.
|
||||
* Delegates call to _handleFile / _handleDir after checks.
|
||||
* @param path to file or ir
|
||||
* @param initialAdd was the file added at watch instantiation?
|
||||
* @param priorWh depth relative to user-supplied path
|
||||
* @param depth Child path actually targeted for watch
|
||||
* @param target Child path actually targeted for watch
|
||||
*/
|
||||
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
||||
const ready = this.fsw._emitReady;
|
||||
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
||||
ready();
|
||||
return false;
|
||||
}
|
||||
const wh = this.fsw._getWatchHelpers(path);
|
||||
if (priorWh) {
|
||||
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
||||
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
||||
}
|
||||
// evaluate what is at the path we're being asked to watch
|
||||
try {
|
||||
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
||||
ready();
|
||||
return false;
|
||||
}
|
||||
const follow = this.fsw.options.followSymlinks;
|
||||
let closer;
|
||||
if (stats.isDirectory()) {
|
||||
const absPath = sysPath.resolve(path);
|
||||
const targetPath = follow ? await (0, promises_1.realpath)(path) : path;
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
// preserve this symlink's target path
|
||||
if (absPath !== targetPath && targetPath !== undefined) {
|
||||
this.fsw._symlinkPaths.set(absPath, targetPath);
|
||||
}
|
||||
}
|
||||
else if (stats.isSymbolicLink()) {
|
||||
const targetPath = follow ? await (0, promises_1.realpath)(path) : path;
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
const parent = sysPath.dirname(wh.watchPath);
|
||||
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
||||
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
||||
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
// preserve this symlink's target path
|
||||
if (targetPath !== undefined) {
|
||||
this.fsw._symlinkPaths.set(sysPath.resolve(path), targetPath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
||||
}
|
||||
ready();
|
||||
if (closer)
|
||||
this.fsw._addPathCloser(path, closer);
|
||||
return false;
|
||||
}
|
||||
catch (error) {
|
||||
if (this.fsw._handleError(error)) {
|
||||
ready();
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.NodeFsHandler = NodeFsHandler;
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
||||
import { Stats } from 'fs';
|
||||
import { EventEmitter } from 'events';
|
||||
import { ReaddirpStream, ReaddirpOptions, EntryInfo } from 'readdirp';
|
||||
import { NodeFsHandler, EventName, Path, EVENTS as EV, WatchHandlers } from './handler.js';
|
||||
type AWF = {
|
||||
stabilityThreshold: number;
|
||||
pollInterval: number;
|
||||
};
|
||||
type BasicOpts = {
|
||||
persistent: boolean;
|
||||
ignoreInitial: boolean;
|
||||
followSymlinks: boolean;
|
||||
cwd?: string;
|
||||
usePolling: boolean;
|
||||
interval: number;
|
||||
binaryInterval: number;
|
||||
alwaysStat?: boolean;
|
||||
depth?: number;
|
||||
ignorePermissionErrors: boolean;
|
||||
atomic: boolean | number;
|
||||
};
|
||||
export type Throttler = {
|
||||
timeoutObject: NodeJS.Timeout;
|
||||
clear: () => void;
|
||||
count: number;
|
||||
};
|
||||
export type ChokidarOptions = Partial<BasicOpts & {
|
||||
ignored: Matcher | Matcher[];
|
||||
awaitWriteFinish: boolean | Partial<AWF>;
|
||||
}>;
|
||||
export type FSWInstanceOptions = BasicOpts & {
|
||||
ignored: Matcher[];
|
||||
awaitWriteFinish: false | AWF;
|
||||
};
|
||||
export type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';
|
||||
export type EmitArgs = [path: Path, stats?: Stats];
|
||||
export type EmitErrorArgs = [error: Error, stats?: Stats];
|
||||
export type EmitArgsWithName = [event: EventName, ...EmitArgs];
|
||||
export type MatchFunction = (val: string, stats?: Stats) => boolean;
|
||||
export interface MatcherObject {
|
||||
path: string;
|
||||
recursive?: boolean;
|
||||
}
|
||||
export type Matcher = string | RegExp | MatchFunction | MatcherObject;
|
||||
/**
|
||||
* Directory entry.
|
||||
*/
|
||||
declare class DirEntry {
|
||||
path: Path;
|
||||
_removeWatcher: (dir: string, base: string) => void;
|
||||
items: Set<Path>;
|
||||
constructor(dir: Path, removeWatcher: (dir: string, base: string) => void);
|
||||
add(item: string): void;
|
||||
remove(item: string): Promise<void>;
|
||||
has(item: string): boolean | undefined;
|
||||
getChildren(): string[];
|
||||
dispose(): void;
|
||||
}
|
||||
export declare class WatchHelper {
|
||||
fsw: FSWatcher;
|
||||
path: string;
|
||||
watchPath: string;
|
||||
fullWatchPath: string;
|
||||
dirParts: string[][];
|
||||
followSymlinks: boolean;
|
||||
statMethod: 'stat' | 'lstat';
|
||||
constructor(path: string, follow: boolean, fsw: FSWatcher);
|
||||
entryPath(entry: EntryInfo): Path;
|
||||
filterPath(entry: EntryInfo): boolean;
|
||||
filterDir(entry: EntryInfo): boolean;
|
||||
}
|
||||
export interface FSWatcherKnownEventMap {
|
||||
[EV.READY]: [];
|
||||
[EV.RAW]: Parameters<WatchHandlers['rawEmitter']>;
|
||||
[EV.ERROR]: Parameters<WatchHandlers['errHandler']>;
|
||||
[EV.ALL]: [event: EventName, ...EmitArgs];
|
||||
}
|
||||
export type FSWatcherEventMap = FSWatcherKnownEventMap & {
|
||||
[k in Exclude<EventName, keyof FSWatcherKnownEventMap>]: EmitArgs;
|
||||
};
|
||||
/**
|
||||
* Watches files & directories for changes. Emitted events:
|
||||
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
||||
*
|
||||
* new FSWatcher()
|
||||
* .add(directories)
|
||||
* .on('add', path => log('File', path, 'was added'))
|
||||
*/
|
||||
export declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
|
||||
closed: boolean;
|
||||
options: FSWInstanceOptions;
|
||||
_closers: Map<string, Array<any>>;
|
||||
_ignoredPaths: Set<Matcher>;
|
||||
_throttled: Map<ThrottleType, Map<any, any>>;
|
||||
_streams: Set<ReaddirpStream>;
|
||||
_symlinkPaths: Map<Path, string | boolean>;
|
||||
_watched: Map<string, DirEntry>;
|
||||
_pendingWrites: Map<string, any>;
|
||||
_pendingUnlinks: Map<string, EmitArgsWithName>;
|
||||
_readyCount: number;
|
||||
_emitReady: () => void;
|
||||
_closePromise?: Promise<void>;
|
||||
_userIgnored?: MatchFunction;
|
||||
_readyEmitted: boolean;
|
||||
_emitRaw: WatchHandlers['rawEmitter'];
|
||||
_boundRemove: (dir: string, item: string) => void;
|
||||
_nodeFsHandler: NodeFsHandler;
|
||||
constructor(_opts?: ChokidarOptions);
|
||||
_addIgnoredPath(matcher: Matcher): void;
|
||||
_removeIgnoredPath(matcher: Matcher): void;
|
||||
/**
|
||||
* Adds paths to be watched on an existing FSWatcher instance.
|
||||
* @param paths_ file or file list. Other arguments are unused
|
||||
*/
|
||||
add(paths_: Path | Path[], _origAdd?: string, _internal?: boolean): FSWatcher;
|
||||
/**
|
||||
* Close watchers or start ignoring events from specified paths.
|
||||
*/
|
||||
unwatch(paths_: Path | Path[]): FSWatcher;
|
||||
/**
|
||||
* Close watchers and remove all listeners from watched paths.
|
||||
*/
|
||||
close(): Promise<void>;
|
||||
/**
|
||||
* Expose list of watched paths
|
||||
* @returns for chaining
|
||||
*/
|
||||
getWatched(): Record<string, string[]>;
|
||||
emitWithAll(event: EventName, args: EmitArgs): void;
|
||||
/**
|
||||
* Normalize and emit events.
|
||||
* Calling _emit DOES NOT MEAN emit() would be called!
|
||||
* @param event Type of event
|
||||
* @param path File or directory path
|
||||
* @param stats arguments to be passed with event
|
||||
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
_emit(event: EventName, path: Path, stats?: Stats): Promise<this | undefined>;
|
||||
/**
|
||||
* Common handler for errors
|
||||
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
_handleError(error: Error): Error | boolean;
|
||||
/**
|
||||
* Helper utility for throttling
|
||||
* @param actionType type being throttled
|
||||
* @param path being acted upon
|
||||
* @param timeout duration of time to suppress duplicate actions
|
||||
* @returns tracking object or false if action should be suppressed
|
||||
*/
|
||||
_throttle(actionType: ThrottleType, path: Path, timeout: number): Throttler | false;
|
||||
_incrReadyCount(): number;
|
||||
/**
|
||||
* Awaits write operation to finish.
|
||||
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
||||
* @param path being acted upon
|
||||
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
||||
* @param event
|
||||
* @param awfEmit Callback to be called when ready for event to be emitted.
|
||||
*/
|
||||
_awaitWriteFinish(path: Path, threshold: number, event: EventName, awfEmit: (err?: Error, stat?: Stats) => void): void;
|
||||
/**
|
||||
* Determines whether user has asked to ignore this path.
|
||||
*/
|
||||
_isIgnored(path: Path, stats?: Stats): boolean;
|
||||
_isntIgnored(path: Path, stat?: Stats): boolean;
|
||||
/**
|
||||
* Provides a set of common helpers and properties relating to symlink handling.
|
||||
* @param path file or directory pattern being watched
|
||||
*/
|
||||
_getWatchHelpers(path: Path): WatchHelper;
|
||||
/**
|
||||
* Provides directory tracking objects
|
||||
* @param directory path of the directory
|
||||
*/
|
||||
_getWatchedDir(directory: string): DirEntry;
|
||||
/**
|
||||
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
||||
*/
|
||||
_hasReadPermissions(stats: Stats): boolean;
|
||||
/**
|
||||
* Handles emitting unlink events for
|
||||
* files and directories, and via recursion, for
|
||||
* files and directories within directories that are unlinked
|
||||
* @param directory within which the following item is located
|
||||
* @param item base path of item/directory
|
||||
*/
|
||||
_remove(directory: string, item: string, isDirectory?: boolean): void;
|
||||
/**
|
||||
* Closes all watchers for a path
|
||||
*/
|
||||
_closePath(path: Path): void;
|
||||
/**
|
||||
* Closes only file-specific watchers
|
||||
*/
|
||||
_closeFile(path: Path): void;
|
||||
_addPathCloser(path: Path, closer: () => void): void;
|
||||
_readdirp(root: Path, opts?: Partial<ReaddirpOptions>): ReaddirpStream | undefined;
|
||||
}
|
||||
/**
|
||||
* Instantiates watcher with paths to be tracked.
|
||||
* @param paths file / directory paths
|
||||
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
||||
* @returns an instance of FSWatcher for chaining.
|
||||
* @example
|
||||
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
||||
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
||||
*/
|
||||
export declare function watch(paths: string | string[], options?: ChokidarOptions): FSWatcher;
|
||||
declare const _default: {
|
||||
watch: typeof watch;
|
||||
FSWatcher: typeof FSWatcher;
|
||||
};
|
||||
export default _default;
|
||||
+804
@@ -0,0 +1,804 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FSWatcher = exports.WatchHelper = void 0;
|
||||
exports.watch = watch;
|
||||
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
||||
const fs_1 = require("fs");
|
||||
const promises_1 = require("fs/promises");
|
||||
const events_1 = require("events");
|
||||
const sysPath = require("path");
|
||||
const readdirp_1 = require("readdirp");
|
||||
const handler_js_1 = require("./handler.js");
|
||||
const SLASH = '/';
|
||||
const SLASH_SLASH = '//';
|
||||
const ONE_DOT = '.';
|
||||
const TWO_DOTS = '..';
|
||||
const STRING_TYPE = 'string';
|
||||
const BACK_SLASH_RE = /\\/g;
|
||||
const DOUBLE_SLASH_RE = /\/\//;
|
||||
const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
||||
const REPLACER_RE = /^\.[/\\]/;
|
||||
function arrify(item) {
|
||||
return Array.isArray(item) ? item : [item];
|
||||
}
|
||||
const isMatcherObject = (matcher) => typeof matcher === 'object' && matcher !== null && !(matcher instanceof RegExp);
|
||||
function createPattern(matcher) {
|
||||
if (typeof matcher === 'function')
|
||||
return matcher;
|
||||
if (typeof matcher === 'string')
|
||||
return (string) => matcher === string;
|
||||
if (matcher instanceof RegExp)
|
||||
return (string) => matcher.test(string);
|
||||
if (typeof matcher === 'object' && matcher !== null) {
|
||||
return (string) => {
|
||||
if (matcher.path === string)
|
||||
return true;
|
||||
if (matcher.recursive) {
|
||||
const relative = sysPath.relative(matcher.path, string);
|
||||
if (!relative) {
|
||||
return false;
|
||||
}
|
||||
return !relative.startsWith('..') && !sysPath.isAbsolute(relative);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
return () => false;
|
||||
}
|
||||
function normalizePath(path) {
|
||||
if (typeof path !== 'string')
|
||||
throw new Error('string expected');
|
||||
path = sysPath.normalize(path);
|
||||
path = path.replace(/\\/g, '/');
|
||||
let prepend = false;
|
||||
if (path.startsWith('//'))
|
||||
prepend = true;
|
||||
const DOUBLE_SLASH_RE = /\/\//;
|
||||
while (path.match(DOUBLE_SLASH_RE))
|
||||
path = path.replace(DOUBLE_SLASH_RE, '/');
|
||||
if (prepend)
|
||||
path = '/' + path;
|
||||
return path;
|
||||
}
|
||||
function matchPatterns(patterns, testString, stats) {
|
||||
const path = normalizePath(testString);
|
||||
for (let index = 0; index < patterns.length; index++) {
|
||||
const pattern = patterns[index];
|
||||
if (pattern(path, stats)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function anymatch(matchers, testString) {
|
||||
if (matchers == null) {
|
||||
throw new TypeError('anymatch: specify first argument');
|
||||
}
|
||||
// Early cache for matchers.
|
||||
const matchersArray = arrify(matchers);
|
||||
const patterns = matchersArray.map((matcher) => createPattern(matcher));
|
||||
if (testString == null) {
|
||||
return (testString, stats) => {
|
||||
return matchPatterns(patterns, testString, stats);
|
||||
};
|
||||
}
|
||||
return matchPatterns(patterns, testString);
|
||||
}
|
||||
const unifyPaths = (paths_) => {
|
||||
const paths = arrify(paths_).flat();
|
||||
if (!paths.every((p) => typeof p === STRING_TYPE)) {
|
||||
throw new TypeError(`Non-string provided as watch path: ${paths}`);
|
||||
}
|
||||
return paths.map(normalizePathToUnix);
|
||||
};
|
||||
// If SLASH_SLASH occurs at the beginning of path, it is not replaced
|
||||
// because "//StoragePC/DrivePool/Movies" is a valid network path
|
||||
const toUnix = (string) => {
|
||||
let str = string.replace(BACK_SLASH_RE, SLASH);
|
||||
let prepend = false;
|
||||
if (str.startsWith(SLASH_SLASH)) {
|
||||
prepend = true;
|
||||
}
|
||||
while (str.match(DOUBLE_SLASH_RE)) {
|
||||
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
||||
}
|
||||
if (prepend) {
|
||||
str = SLASH + str;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
// Our version of upath.normalize
|
||||
// TODO: this is not equal to path-normalize module - investigate why
|
||||
const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));
|
||||
// TODO: refactor
|
||||
const normalizeIgnored = (cwd = '') => (path) => {
|
||||
if (typeof path === 'string') {
|
||||
return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
|
||||
}
|
||||
else {
|
||||
return path;
|
||||
}
|
||||
};
|
||||
const getAbsolutePath = (path, cwd) => {
|
||||
if (sysPath.isAbsolute(path)) {
|
||||
return path;
|
||||
}
|
||||
return sysPath.join(cwd, path);
|
||||
};
|
||||
const EMPTY_SET = Object.freeze(new Set());
|
||||
/**
|
||||
* Directory entry.
|
||||
*/
|
||||
class DirEntry {
|
||||
constructor(dir, removeWatcher) {
|
||||
this.path = dir;
|
||||
this._removeWatcher = removeWatcher;
|
||||
this.items = new Set();
|
||||
}
|
||||
add(item) {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return;
|
||||
if (item !== ONE_DOT && item !== TWO_DOTS)
|
||||
items.add(item);
|
||||
}
|
||||
async remove(item) {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return;
|
||||
items.delete(item);
|
||||
if (items.size > 0)
|
||||
return;
|
||||
const dir = this.path;
|
||||
try {
|
||||
await (0, promises_1.readdir)(dir);
|
||||
}
|
||||
catch (err) {
|
||||
if (this._removeWatcher) {
|
||||
this._removeWatcher(sysPath.dirname(dir), sysPath.basename(dir));
|
||||
}
|
||||
}
|
||||
}
|
||||
has(item) {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return;
|
||||
return items.has(item);
|
||||
}
|
||||
getChildren() {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return [];
|
||||
return [...items.values()];
|
||||
}
|
||||
dispose() {
|
||||
this.items.clear();
|
||||
this.path = '';
|
||||
this._removeWatcher = handler_js_1.EMPTY_FN;
|
||||
this.items = EMPTY_SET;
|
||||
Object.freeze(this);
|
||||
}
|
||||
}
|
||||
const STAT_METHOD_F = 'stat';
|
||||
const STAT_METHOD_L = 'lstat';
|
||||
class WatchHelper {
|
||||
constructor(path, follow, fsw) {
|
||||
this.fsw = fsw;
|
||||
const watchPath = path;
|
||||
this.path = path = path.replace(REPLACER_RE, '');
|
||||
this.watchPath = watchPath;
|
||||
this.fullWatchPath = sysPath.resolve(watchPath);
|
||||
this.dirParts = [];
|
||||
this.dirParts.forEach((parts) => {
|
||||
if (parts.length > 1)
|
||||
parts.pop();
|
||||
});
|
||||
this.followSymlinks = follow;
|
||||
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
||||
}
|
||||
entryPath(entry) {
|
||||
return sysPath.join(this.watchPath, sysPath.relative(this.watchPath, entry.fullPath));
|
||||
}
|
||||
filterPath(entry) {
|
||||
const { stats } = entry;
|
||||
if (stats && stats.isSymbolicLink())
|
||||
return this.filterDir(entry);
|
||||
const resolvedPath = this.entryPath(entry);
|
||||
// TODO: what if stats is undefined? remove !
|
||||
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
||||
}
|
||||
filterDir(entry) {
|
||||
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
||||
}
|
||||
}
|
||||
exports.WatchHelper = WatchHelper;
|
||||
/**
|
||||
* Watches files & directories for changes. Emitted events:
|
||||
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
||||
*
|
||||
* new FSWatcher()
|
||||
* .add(directories)
|
||||
* .on('add', path => log('File', path, 'was added'))
|
||||
*/
|
||||
class FSWatcher extends events_1.EventEmitter {
|
||||
// Not indenting methods for history sake; for now.
|
||||
constructor(_opts = {}) {
|
||||
super();
|
||||
this.closed = false;
|
||||
this._closers = new Map();
|
||||
this._ignoredPaths = new Set();
|
||||
this._throttled = new Map();
|
||||
this._streams = new Set();
|
||||
this._symlinkPaths = new Map();
|
||||
this._watched = new Map();
|
||||
this._pendingWrites = new Map();
|
||||
this._pendingUnlinks = new Map();
|
||||
this._readyCount = 0;
|
||||
this._readyEmitted = false;
|
||||
const awf = _opts.awaitWriteFinish;
|
||||
const DEF_AWF = { stabilityThreshold: 2000, pollInterval: 100 };
|
||||
const opts = {
|
||||
// Defaults
|
||||
persistent: true,
|
||||
ignoreInitial: false,
|
||||
ignorePermissionErrors: false,
|
||||
interval: 100,
|
||||
binaryInterval: 300,
|
||||
followSymlinks: true,
|
||||
usePolling: false,
|
||||
// useAsync: false,
|
||||
atomic: true, // NOTE: overwritten later (depends on usePolling)
|
||||
..._opts,
|
||||
// Change format
|
||||
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
||||
awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === 'object' ? { ...DEF_AWF, ...awf } : false,
|
||||
};
|
||||
// Always default to polling on IBM i because fs.watch() is not available on IBM i.
|
||||
if (handler_js_1.isIBMi)
|
||||
opts.usePolling = true;
|
||||
// Editor atomic write normalization enabled by default with fs.watch
|
||||
if (opts.atomic === undefined)
|
||||
opts.atomic = !opts.usePolling;
|
||||
// opts.atomic = typeof _opts.atomic === 'number' ? _opts.atomic : 100;
|
||||
// Global override. Useful for developers, who need to force polling for all
|
||||
// instances of chokidar, regardless of usage / dependency depth
|
||||
const envPoll = process.env.CHOKIDAR_USEPOLLING;
|
||||
if (envPoll !== undefined) {
|
||||
const envLower = envPoll.toLowerCase();
|
||||
if (envLower === 'false' || envLower === '0')
|
||||
opts.usePolling = false;
|
||||
else if (envLower === 'true' || envLower === '1')
|
||||
opts.usePolling = true;
|
||||
else
|
||||
opts.usePolling = !!envLower;
|
||||
}
|
||||
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
||||
if (envInterval)
|
||||
opts.interval = Number.parseInt(envInterval, 10);
|
||||
// This is done to emit ready only once, but each 'add' will increase that?
|
||||
let readyCalls = 0;
|
||||
this._emitReady = () => {
|
||||
readyCalls++;
|
||||
if (readyCalls >= this._readyCount) {
|
||||
this._emitReady = handler_js_1.EMPTY_FN;
|
||||
this._readyEmitted = true;
|
||||
// use process.nextTick to allow time for listener to be bound
|
||||
process.nextTick(() => this.emit(handler_js_1.EVENTS.READY));
|
||||
}
|
||||
};
|
||||
this._emitRaw = (...args) => this.emit(handler_js_1.EVENTS.RAW, ...args);
|
||||
this._boundRemove = this._remove.bind(this);
|
||||
this.options = opts;
|
||||
this._nodeFsHandler = new handler_js_1.NodeFsHandler(this);
|
||||
// You’re frozen when your heart’s not open.
|
||||
Object.freeze(opts);
|
||||
}
|
||||
_addIgnoredPath(matcher) {
|
||||
if (isMatcherObject(matcher)) {
|
||||
// return early if we already have a deeply equal matcher object
|
||||
for (const ignored of this._ignoredPaths) {
|
||||
if (isMatcherObject(ignored) &&
|
||||
ignored.path === matcher.path &&
|
||||
ignored.recursive === matcher.recursive) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this._ignoredPaths.add(matcher);
|
||||
}
|
||||
_removeIgnoredPath(matcher) {
|
||||
this._ignoredPaths.delete(matcher);
|
||||
// now find any matcher objects with the matcher as path
|
||||
if (typeof matcher === 'string') {
|
||||
for (const ignored of this._ignoredPaths) {
|
||||
// TODO (43081j): make this more efficient.
|
||||
// probably just make a `this._ignoredDirectories` or some
|
||||
// such thing.
|
||||
if (isMatcherObject(ignored) && ignored.path === matcher) {
|
||||
this._ignoredPaths.delete(ignored);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Public methods
|
||||
/**
|
||||
* Adds paths to be watched on an existing FSWatcher instance.
|
||||
* @param paths_ file or file list. Other arguments are unused
|
||||
*/
|
||||
add(paths_, _origAdd, _internal) {
|
||||
const { cwd } = this.options;
|
||||
this.closed = false;
|
||||
this._closePromise = undefined;
|
||||
let paths = unifyPaths(paths_);
|
||||
if (cwd) {
|
||||
paths = paths.map((path) => {
|
||||
const absPath = getAbsolutePath(path, cwd);
|
||||
// Check `path` instead of `absPath` because the cwd portion can't be a glob
|
||||
return absPath;
|
||||
});
|
||||
}
|
||||
paths.forEach((path) => {
|
||||
this._removeIgnoredPath(path);
|
||||
});
|
||||
this._userIgnored = undefined;
|
||||
if (!this._readyCount)
|
||||
this._readyCount = 0;
|
||||
this._readyCount += paths.length;
|
||||
Promise.all(paths.map(async (path) => {
|
||||
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, undefined, 0, _origAdd);
|
||||
if (res)
|
||||
this._emitReady();
|
||||
return res;
|
||||
})).then((results) => {
|
||||
if (this.closed)
|
||||
return;
|
||||
results.forEach((item) => {
|
||||
if (item)
|
||||
this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item));
|
||||
});
|
||||
});
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Close watchers or start ignoring events from specified paths.
|
||||
*/
|
||||
unwatch(paths_) {
|
||||
if (this.closed)
|
||||
return this;
|
||||
const paths = unifyPaths(paths_);
|
||||
const { cwd } = this.options;
|
||||
paths.forEach((path) => {
|
||||
// convert to absolute path unless relative path already matches
|
||||
if (!sysPath.isAbsolute(path) && !this._closers.has(path)) {
|
||||
if (cwd)
|
||||
path = sysPath.join(cwd, path);
|
||||
path = sysPath.resolve(path);
|
||||
}
|
||||
this._closePath(path);
|
||||
this._addIgnoredPath(path);
|
||||
if (this._watched.has(path)) {
|
||||
this._addIgnoredPath({
|
||||
path,
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
// reset the cached userIgnored anymatch fn
|
||||
// to make ignoredPaths changes effective
|
||||
this._userIgnored = undefined;
|
||||
});
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Close watchers and remove all listeners from watched paths.
|
||||
*/
|
||||
close() {
|
||||
if (this._closePromise) {
|
||||
return this._closePromise;
|
||||
}
|
||||
this.closed = true;
|
||||
// Memory management.
|
||||
this.removeAllListeners();
|
||||
const closers = [];
|
||||
this._closers.forEach((closerList) => closerList.forEach((closer) => {
|
||||
const promise = closer();
|
||||
if (promise instanceof Promise)
|
||||
closers.push(promise);
|
||||
}));
|
||||
this._streams.forEach((stream) => stream.destroy());
|
||||
this._userIgnored = undefined;
|
||||
this._readyCount = 0;
|
||||
this._readyEmitted = false;
|
||||
this._watched.forEach((dirent) => dirent.dispose());
|
||||
this._closers.clear();
|
||||
this._watched.clear();
|
||||
this._streams.clear();
|
||||
this._symlinkPaths.clear();
|
||||
this._throttled.clear();
|
||||
this._closePromise = closers.length
|
||||
? Promise.all(closers).then(() => undefined)
|
||||
: Promise.resolve();
|
||||
return this._closePromise;
|
||||
}
|
||||
/**
|
||||
* Expose list of watched paths
|
||||
* @returns for chaining
|
||||
*/
|
||||
getWatched() {
|
||||
const watchList = {};
|
||||
this._watched.forEach((entry, dir) => {
|
||||
const key = this.options.cwd ? sysPath.relative(this.options.cwd, dir) : dir;
|
||||
const index = key || ONE_DOT;
|
||||
watchList[index] = entry.getChildren().sort();
|
||||
});
|
||||
return watchList;
|
||||
}
|
||||
emitWithAll(event, args) {
|
||||
this.emit(event, ...args);
|
||||
if (event !== handler_js_1.EVENTS.ERROR)
|
||||
this.emit(handler_js_1.EVENTS.ALL, event, ...args);
|
||||
}
|
||||
// Common helpers
|
||||
// --------------
|
||||
/**
|
||||
* Normalize and emit events.
|
||||
* Calling _emit DOES NOT MEAN emit() would be called!
|
||||
* @param event Type of event
|
||||
* @param path File or directory path
|
||||
* @param stats arguments to be passed with event
|
||||
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
async _emit(event, path, stats) {
|
||||
if (this.closed)
|
||||
return;
|
||||
const opts = this.options;
|
||||
if (handler_js_1.isWindows)
|
||||
path = sysPath.normalize(path);
|
||||
if (opts.cwd)
|
||||
path = sysPath.relative(opts.cwd, path);
|
||||
const args = [path];
|
||||
if (stats != null)
|
||||
args.push(stats);
|
||||
const awf = opts.awaitWriteFinish;
|
||||
let pw;
|
||||
if (awf && (pw = this._pendingWrites.get(path))) {
|
||||
pw.lastChange = new Date();
|
||||
return this;
|
||||
}
|
||||
if (opts.atomic) {
|
||||
if (event === handler_js_1.EVENTS.UNLINK) {
|
||||
this._pendingUnlinks.set(path, [event, ...args]);
|
||||
setTimeout(() => {
|
||||
this._pendingUnlinks.forEach((entry, path) => {
|
||||
this.emit(...entry);
|
||||
this.emit(handler_js_1.EVENTS.ALL, ...entry);
|
||||
this._pendingUnlinks.delete(path);
|
||||
});
|
||||
}, typeof opts.atomic === 'number' ? opts.atomic : 100);
|
||||
return this;
|
||||
}
|
||||
if (event === handler_js_1.EVENTS.ADD && this._pendingUnlinks.has(path)) {
|
||||
event = handler_js_1.EVENTS.CHANGE;
|
||||
this._pendingUnlinks.delete(path);
|
||||
}
|
||||
}
|
||||
if (awf && (event === handler_js_1.EVENTS.ADD || event === handler_js_1.EVENTS.CHANGE) && this._readyEmitted) {
|
||||
const awfEmit = (err, stats) => {
|
||||
if (err) {
|
||||
event = handler_js_1.EVENTS.ERROR;
|
||||
args[0] = err;
|
||||
this.emitWithAll(event, args);
|
||||
}
|
||||
else if (stats) {
|
||||
// if stats doesn't exist the file must have been deleted
|
||||
if (args.length > 1) {
|
||||
args[1] = stats;
|
||||
}
|
||||
else {
|
||||
args.push(stats);
|
||||
}
|
||||
this.emitWithAll(event, args);
|
||||
}
|
||||
};
|
||||
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
||||
return this;
|
||||
}
|
||||
if (event === handler_js_1.EVENTS.CHANGE) {
|
||||
const isThrottled = !this._throttle(handler_js_1.EVENTS.CHANGE, path, 50);
|
||||
if (isThrottled)
|
||||
return this;
|
||||
}
|
||||
if (opts.alwaysStat &&
|
||||
stats === undefined &&
|
||||
(event === handler_js_1.EVENTS.ADD || event === handler_js_1.EVENTS.ADD_DIR || event === handler_js_1.EVENTS.CHANGE)) {
|
||||
const fullPath = opts.cwd ? sysPath.join(opts.cwd, path) : path;
|
||||
let stats;
|
||||
try {
|
||||
stats = await (0, promises_1.stat)(fullPath);
|
||||
}
|
||||
catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
// Suppress event when fs_stat fails, to avoid sending undefined 'stat'
|
||||
if (!stats || this.closed)
|
||||
return;
|
||||
args.push(stats);
|
||||
}
|
||||
this.emitWithAll(event, args);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Common handler for errors
|
||||
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
_handleError(error) {
|
||||
const code = error && error.code;
|
||||
if (error &&
|
||||
code !== 'ENOENT' &&
|
||||
code !== 'ENOTDIR' &&
|
||||
(!this.options.ignorePermissionErrors || (code !== 'EPERM' && code !== 'EACCES'))) {
|
||||
this.emit(handler_js_1.EVENTS.ERROR, error);
|
||||
}
|
||||
return error || this.closed;
|
||||
}
|
||||
/**
|
||||
* Helper utility for throttling
|
||||
* @param actionType type being throttled
|
||||
* @param path being acted upon
|
||||
* @param timeout duration of time to suppress duplicate actions
|
||||
* @returns tracking object or false if action should be suppressed
|
||||
*/
|
||||
_throttle(actionType, path, timeout) {
|
||||
if (!this._throttled.has(actionType)) {
|
||||
this._throttled.set(actionType, new Map());
|
||||
}
|
||||
const action = this._throttled.get(actionType);
|
||||
if (!action)
|
||||
throw new Error('invalid throttle');
|
||||
const actionPath = action.get(path);
|
||||
if (actionPath) {
|
||||
actionPath.count++;
|
||||
return false;
|
||||
}
|
||||
// eslint-disable-next-line prefer-const
|
||||
let timeoutObject;
|
||||
const clear = () => {
|
||||
const item = action.get(path);
|
||||
const count = item ? item.count : 0;
|
||||
action.delete(path);
|
||||
clearTimeout(timeoutObject);
|
||||
if (item)
|
||||
clearTimeout(item.timeoutObject);
|
||||
return count;
|
||||
};
|
||||
timeoutObject = setTimeout(clear, timeout);
|
||||
const thr = { timeoutObject, clear, count: 0 };
|
||||
action.set(path, thr);
|
||||
return thr;
|
||||
}
|
||||
_incrReadyCount() {
|
||||
return this._readyCount++;
|
||||
}
|
||||
/**
|
||||
* Awaits write operation to finish.
|
||||
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
||||
* @param path being acted upon
|
||||
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
||||
* @param event
|
||||
* @param awfEmit Callback to be called when ready for event to be emitted.
|
||||
*/
|
||||
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
||||
const awf = this.options.awaitWriteFinish;
|
||||
if (typeof awf !== 'object')
|
||||
return;
|
||||
const pollInterval = awf.pollInterval;
|
||||
let timeoutHandler;
|
||||
let fullPath = path;
|
||||
if (this.options.cwd && !sysPath.isAbsolute(path)) {
|
||||
fullPath = sysPath.join(this.options.cwd, path);
|
||||
}
|
||||
const now = new Date();
|
||||
const writes = this._pendingWrites;
|
||||
function awaitWriteFinishFn(prevStat) {
|
||||
(0, fs_1.stat)(fullPath, (err, curStat) => {
|
||||
if (err || !writes.has(path)) {
|
||||
if (err && err.code !== 'ENOENT')
|
||||
awfEmit(err);
|
||||
return;
|
||||
}
|
||||
const now = Number(new Date());
|
||||
if (prevStat && curStat.size !== prevStat.size) {
|
||||
writes.get(path).lastChange = now;
|
||||
}
|
||||
const pw = writes.get(path);
|
||||
const df = now - pw.lastChange;
|
||||
if (df >= threshold) {
|
||||
writes.delete(path);
|
||||
awfEmit(undefined, curStat);
|
||||
}
|
||||
else {
|
||||
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!writes.has(path)) {
|
||||
writes.set(path, {
|
||||
lastChange: now,
|
||||
cancelWait: () => {
|
||||
writes.delete(path);
|
||||
clearTimeout(timeoutHandler);
|
||||
return event;
|
||||
},
|
||||
});
|
||||
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Determines whether user has asked to ignore this path.
|
||||
*/
|
||||
_isIgnored(path, stats) {
|
||||
if (this.options.atomic && DOT_RE.test(path))
|
||||
return true;
|
||||
if (!this._userIgnored) {
|
||||
const { cwd } = this.options;
|
||||
const ign = this.options.ignored;
|
||||
const ignored = (ign || []).map(normalizeIgnored(cwd));
|
||||
const ignoredPaths = [...this._ignoredPaths];
|
||||
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
||||
this._userIgnored = anymatch(list, undefined);
|
||||
}
|
||||
return this._userIgnored(path, stats);
|
||||
}
|
||||
_isntIgnored(path, stat) {
|
||||
return !this._isIgnored(path, stat);
|
||||
}
|
||||
/**
|
||||
* Provides a set of common helpers and properties relating to symlink handling.
|
||||
* @param path file or directory pattern being watched
|
||||
*/
|
||||
_getWatchHelpers(path) {
|
||||
return new WatchHelper(path, this.options.followSymlinks, this);
|
||||
}
|
||||
// Directory helpers
|
||||
// -----------------
|
||||
/**
|
||||
* Provides directory tracking objects
|
||||
* @param directory path of the directory
|
||||
*/
|
||||
_getWatchedDir(directory) {
|
||||
const dir = sysPath.resolve(directory);
|
||||
if (!this._watched.has(dir))
|
||||
this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
||||
return this._watched.get(dir);
|
||||
}
|
||||
// File helpers
|
||||
// ------------
|
||||
/**
|
||||
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
||||
*/
|
||||
_hasReadPermissions(stats) {
|
||||
if (this.options.ignorePermissionErrors)
|
||||
return true;
|
||||
return Boolean(Number(stats.mode) & 0o400);
|
||||
}
|
||||
/**
|
||||
* Handles emitting unlink events for
|
||||
* files and directories, and via recursion, for
|
||||
* files and directories within directories that are unlinked
|
||||
* @param directory within which the following item is located
|
||||
* @param item base path of item/directory
|
||||
*/
|
||||
_remove(directory, item, isDirectory) {
|
||||
// if what is being deleted is a directory, get that directory's paths
|
||||
// for recursive deleting and cleaning of watched object
|
||||
// if it is not a directory, nestedDirectoryChildren will be empty array
|
||||
const path = sysPath.join(directory, item);
|
||||
const fullPath = sysPath.resolve(path);
|
||||
isDirectory =
|
||||
isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
|
||||
// prevent duplicate handling in case of arriving here nearly simultaneously
|
||||
// via multiple paths (such as _handleFile and _handleDir)
|
||||
if (!this._throttle('remove', path, 100))
|
||||
return;
|
||||
// if the only watched file is removed, watch for its return
|
||||
if (!isDirectory && this._watched.size === 1) {
|
||||
this.add(directory, item, true);
|
||||
}
|
||||
// This will create a new entry in the watched object in either case
|
||||
// so we got to do the directory check beforehand
|
||||
const wp = this._getWatchedDir(path);
|
||||
const nestedDirectoryChildren = wp.getChildren();
|
||||
// Recursively remove children directories / files.
|
||||
nestedDirectoryChildren.forEach((nested) => this._remove(path, nested));
|
||||
// Check if item was on the watched list and remove it
|
||||
const parent = this._getWatchedDir(directory);
|
||||
const wasTracked = parent.has(item);
|
||||
parent.remove(item);
|
||||
// Fixes issue #1042 -> Relative paths were detected and added as symlinks
|
||||
// (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
|
||||
// but never removed from the map in case the path was deleted.
|
||||
// This leads to an incorrect state if the path was recreated:
|
||||
// https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
|
||||
if (this._symlinkPaths.has(fullPath)) {
|
||||
this._symlinkPaths.delete(fullPath);
|
||||
}
|
||||
// If we wait for this file to be fully written, cancel the wait.
|
||||
let relPath = path;
|
||||
if (this.options.cwd)
|
||||
relPath = sysPath.relative(this.options.cwd, path);
|
||||
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
||||
const event = this._pendingWrites.get(relPath).cancelWait();
|
||||
if (event === handler_js_1.EVENTS.ADD)
|
||||
return;
|
||||
}
|
||||
// The Entry will either be a directory that just got removed
|
||||
// or a bogus entry to a file, in either case we have to remove it
|
||||
this._watched.delete(path);
|
||||
this._watched.delete(fullPath);
|
||||
const eventName = isDirectory ? handler_js_1.EVENTS.UNLINK_DIR : handler_js_1.EVENTS.UNLINK;
|
||||
if (wasTracked && !this._isIgnored(path))
|
||||
this._emit(eventName, path);
|
||||
// Avoid conflicts if we later create another file with the same name
|
||||
this._closePath(path);
|
||||
}
|
||||
/**
|
||||
* Closes all watchers for a path
|
||||
*/
|
||||
_closePath(path) {
|
||||
this._closeFile(path);
|
||||
const dir = sysPath.dirname(path);
|
||||
this._getWatchedDir(dir).remove(sysPath.basename(path));
|
||||
}
|
||||
/**
|
||||
* Closes only file-specific watchers
|
||||
*/
|
||||
_closeFile(path) {
|
||||
const closers = this._closers.get(path);
|
||||
if (!closers)
|
||||
return;
|
||||
closers.forEach((closer) => closer());
|
||||
this._closers.delete(path);
|
||||
}
|
||||
_addPathCloser(path, closer) {
|
||||
if (!closer)
|
||||
return;
|
||||
let list = this._closers.get(path);
|
||||
if (!list) {
|
||||
list = [];
|
||||
this._closers.set(path, list);
|
||||
}
|
||||
list.push(closer);
|
||||
}
|
||||
_readdirp(root, opts) {
|
||||
if (this.closed)
|
||||
return;
|
||||
const options = { type: handler_js_1.EVENTS.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
|
||||
let stream = (0, readdirp_1.readdirp)(root, options);
|
||||
this._streams.add(stream);
|
||||
stream.once(handler_js_1.STR_CLOSE, () => {
|
||||
stream = undefined;
|
||||
});
|
||||
stream.once(handler_js_1.STR_END, () => {
|
||||
if (stream) {
|
||||
this._streams.delete(stream);
|
||||
stream = undefined;
|
||||
}
|
||||
});
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
exports.FSWatcher = FSWatcher;
|
||||
/**
|
||||
* Instantiates watcher with paths to be tracked.
|
||||
* @param paths file / directory paths
|
||||
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
||||
* @returns an instance of FSWatcher for chaining.
|
||||
* @example
|
||||
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
||||
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
||||
*/
|
||||
function watch(paths, options = {}) {
|
||||
const watcher = new FSWatcher(options);
|
||||
watcher.add(paths);
|
||||
return watcher;
|
||||
}
|
||||
exports.default = { watch, FSWatcher };
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"name": "chokidar",
|
||||
"description": "Minimal and efficient cross-platform file watching library",
|
||||
"version": "4.0.3",
|
||||
"homepage": "https://github.com/paulmillr/chokidar",
|
||||
"author": "Paul Miller (https://paulmillr.com)",
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"handler.js",
|
||||
"handler.d.ts",
|
||||
"esm"
|
||||
],
|
||||
"main": "./index.js",
|
||||
"module": "./esm/index.js",
|
||||
"types": "./index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./esm/index.js",
|
||||
"require": "./index.js"
|
||||
},
|
||||
"./handler.js": {
|
||||
"import": "./esm/handler.js",
|
||||
"require": "./handler.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"readdirp": "^4.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@paulmillr/jsbt": "0.2.1",
|
||||
"@types/node": "20.14.8",
|
||||
"chai": "4.3.4",
|
||||
"prettier": "3.1.1",
|
||||
"rimraf": "5.0.5",
|
||||
"sinon": "12.0.1",
|
||||
"sinon-chai": "3.7.0",
|
||||
"typescript": "5.5.2",
|
||||
"upath": "2.0.1"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">= 14.16.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/paulmillr/chokidar.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/paulmillr/chokidar/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "tsc && tsc -p tsconfig.esm.json",
|
||||
"lint": "prettier --check src",
|
||||
"format": "prettier --write src",
|
||||
"test": "node --test"
|
||||
},
|
||||
"keywords": [
|
||||
"fs",
|
||||
"watch",
|
||||
"watchFile",
|
||||
"watcher",
|
||||
"watching",
|
||||
"file",
|
||||
"fsevents"
|
||||
],
|
||||
"funding": "https://paulmillr.com/funding/"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
type Dict<T> = Record<string, T>;
|
||||
type Arrayable<T> = T | T[];
|
||||
type Default = Dict<any>;
|
||||
|
||||
declare function mri<T=Default>(args?: string[], options?: mri.Options): mri.Argv<T>;
|
||||
|
||||
declare namespace mri {
|
||||
export interface Options {
|
||||
boolean?: Arrayable<string>;
|
||||
string?: Arrayable<string>;
|
||||
alias?: Dict<Arrayable<string>>;
|
||||
default?: Dict<any>;
|
||||
unknown?(flag: string): void;
|
||||
}
|
||||
|
||||
export type Argv<T=Default> = T & {
|
||||
_: string[];
|
||||
}
|
||||
}
|
||||
|
||||
export = mri;
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
function toArr(any) {
|
||||
return any == null ? [] : Array.isArray(any) ? any : [any];
|
||||
}
|
||||
|
||||
function toVal(out, key, val, opts) {
|
||||
var x, old=out[key], nxt=(
|
||||
!!~opts.string.indexOf(key) ? (val == null || val === true ? '' : String(val))
|
||||
: typeof val === 'boolean' ? val
|
||||
: !!~opts.boolean.indexOf(key) ? (val === 'false' ? false : val === 'true' || (out._.push((x = +val,x * 0 === 0) ? x : val),!!val))
|
||||
: (x = +val,x * 0 === 0) ? x : val
|
||||
);
|
||||
out[key] = old == null ? nxt : (Array.isArray(old) ? old.concat(nxt) : [old, nxt]);
|
||||
}
|
||||
|
||||
module.exports = function (args, opts) {
|
||||
args = args || [];
|
||||
opts = opts || {};
|
||||
|
||||
var k, arr, arg, name, val, out={ _:[] };
|
||||
var i=0, j=0, idx=0, len=args.length;
|
||||
|
||||
const alibi = opts.alias !== void 0;
|
||||
const strict = opts.unknown !== void 0;
|
||||
const defaults = opts.default !== void 0;
|
||||
|
||||
opts.alias = opts.alias || {};
|
||||
opts.string = toArr(opts.string);
|
||||
opts.boolean = toArr(opts.boolean);
|
||||
|
||||
if (alibi) {
|
||||
for (k in opts.alias) {
|
||||
arr = opts.alias[k] = toArr(opts.alias[k]);
|
||||
for (i=0; i < arr.length; i++) {
|
||||
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i=opts.boolean.length; i-- > 0;) {
|
||||
arr = opts.alias[opts.boolean[i]] || [];
|
||||
for (j=arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
||||
}
|
||||
|
||||
for (i=opts.string.length; i-- > 0;) {
|
||||
arr = opts.alias[opts.string[i]] || [];
|
||||
for (j=arr.length; j-- > 0;) opts.string.push(arr[j]);
|
||||
}
|
||||
|
||||
if (defaults) {
|
||||
for (k in opts.default) {
|
||||
name = typeof opts.default[k];
|
||||
arr = opts.alias[k] = opts.alias[k] || [];
|
||||
if (opts[name] !== void 0) {
|
||||
opts[name].push(k);
|
||||
for (i=0; i < arr.length; i++) {
|
||||
opts[name].push(arr[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const keys = strict ? Object.keys(opts.alias) : [];
|
||||
|
||||
for (i=0; i < len; i++) {
|
||||
arg = args[i];
|
||||
|
||||
if (arg === '--') {
|
||||
out._ = out._.concat(args.slice(++i));
|
||||
break;
|
||||
}
|
||||
|
||||
for (j=0; j < arg.length; j++) {
|
||||
if (arg.charCodeAt(j) !== 45) break; // "-"
|
||||
}
|
||||
|
||||
if (j === 0) {
|
||||
out._.push(arg);
|
||||
} else if (arg.substring(j, j + 3) === 'no-') {
|
||||
name = arg.substring(j + 3);
|
||||
if (strict && !~keys.indexOf(name)) {
|
||||
return opts.unknown(arg);
|
||||
}
|
||||
out[name] = false;
|
||||
} else {
|
||||
for (idx=j+1; idx < arg.length; idx++) {
|
||||
if (arg.charCodeAt(idx) === 61) break; // "="
|
||||
}
|
||||
|
||||
name = arg.substring(j, idx);
|
||||
val = arg.substring(++idx) || (i+1 === len || (''+args[i+1]).charCodeAt(0) === 45 || args[++i]);
|
||||
arr = (j === 2 ? [name] : name);
|
||||
|
||||
for (idx=0; idx < arr.length; idx++) {
|
||||
name = arr[idx];
|
||||
if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
|
||||
toVal(out, name, (idx + 1 < arr.length) || val, opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defaults) {
|
||||
for (k in opts.default) {
|
||||
if (out[k] === void 0) {
|
||||
out[k] = opts.default[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (alibi) {
|
||||
for (k in out) {
|
||||
arr = opts.alias[k] || [];
|
||||
while (arr.length > 0) {
|
||||
out[arr.shift()] = out[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
function toArr(any) {
|
||||
return any == null ? [] : Array.isArray(any) ? any : [any];
|
||||
}
|
||||
|
||||
function toVal(out, key, val, opts) {
|
||||
var x, old=out[key], nxt=(
|
||||
!!~opts.string.indexOf(key) ? (val == null || val === true ? '' : String(val))
|
||||
: typeof val === 'boolean' ? val
|
||||
: !!~opts.boolean.indexOf(key) ? (val === 'false' ? false : val === 'true' || (out._.push((x = +val,x * 0 === 0) ? x : val),!!val))
|
||||
: (x = +val,x * 0 === 0) ? x : val
|
||||
);
|
||||
out[key] = old == null ? nxt : (Array.isArray(old) ? old.concat(nxt) : [old, nxt]);
|
||||
}
|
||||
|
||||
export default function (args, opts) {
|
||||
args = args || [];
|
||||
opts = opts || {};
|
||||
|
||||
var k, arr, arg, name, val, out={ _:[] };
|
||||
var i=0, j=0, idx=0, len=args.length;
|
||||
|
||||
const alibi = opts.alias !== void 0;
|
||||
const strict = opts.unknown !== void 0;
|
||||
const defaults = opts.default !== void 0;
|
||||
|
||||
opts.alias = opts.alias || {};
|
||||
opts.string = toArr(opts.string);
|
||||
opts.boolean = toArr(opts.boolean);
|
||||
|
||||
if (alibi) {
|
||||
for (k in opts.alias) {
|
||||
arr = opts.alias[k] = toArr(opts.alias[k]);
|
||||
for (i=0; i < arr.length; i++) {
|
||||
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i=opts.boolean.length; i-- > 0;) {
|
||||
arr = opts.alias[opts.boolean[i]] || [];
|
||||
for (j=arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
||||
}
|
||||
|
||||
for (i=opts.string.length; i-- > 0;) {
|
||||
arr = opts.alias[opts.string[i]] || [];
|
||||
for (j=arr.length; j-- > 0;) opts.string.push(arr[j]);
|
||||
}
|
||||
|
||||
if (defaults) {
|
||||
for (k in opts.default) {
|
||||
name = typeof opts.default[k];
|
||||
arr = opts.alias[k] = opts.alias[k] || [];
|
||||
if (opts[name] !== void 0) {
|
||||
opts[name].push(k);
|
||||
for (i=0; i < arr.length; i++) {
|
||||
opts[name].push(arr[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const keys = strict ? Object.keys(opts.alias) : [];
|
||||
|
||||
for (i=0; i < len; i++) {
|
||||
arg = args[i];
|
||||
|
||||
if (arg === '--') {
|
||||
out._ = out._.concat(args.slice(++i));
|
||||
break;
|
||||
}
|
||||
|
||||
for (j=0; j < arg.length; j++) {
|
||||
if (arg.charCodeAt(j) !== 45) break; // "-"
|
||||
}
|
||||
|
||||
if (j === 0) {
|
||||
out._.push(arg);
|
||||
} else if (arg.substring(j, j + 3) === 'no-') {
|
||||
name = arg.substring(j + 3);
|
||||
if (strict && !~keys.indexOf(name)) {
|
||||
return opts.unknown(arg);
|
||||
}
|
||||
out[name] = false;
|
||||
} else {
|
||||
for (idx=j+1; idx < arg.length; idx++) {
|
||||
if (arg.charCodeAt(idx) === 61) break; // "="
|
||||
}
|
||||
|
||||
name = arg.substring(j, idx);
|
||||
val = arg.substring(++idx) || (i+1 === len || (''+args[i+1]).charCodeAt(0) === 45 || args[++i]);
|
||||
arr = (j === 2 ? [name] : name);
|
||||
|
||||
for (idx=0; idx < arr.length; idx++) {
|
||||
name = arr[idx];
|
||||
if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
|
||||
toVal(out, name, (idx + 1 < arr.length) || val, opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defaults) {
|
||||
for (k in opts.default) {
|
||||
if (out[k] === void 0) {
|
||||
out[k] = opts.default[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (alibi) {
|
||||
for (k in out) {
|
||||
arr = opts.alias[k] || [];
|
||||
while (arr.length > 0) {
|
||||
out[arr.shift()] = out[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (lukeed.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.
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "mri",
|
||||
"version": "1.2.0",
|
||||
"description": "Quickly scan for CLI flags and arguments",
|
||||
"repository": "lukeed/mri",
|
||||
"module": "lib/index.mjs",
|
||||
"main": "lib/index.js",
|
||||
"types": "index.d.ts",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"*.d.ts",
|
||||
"lib"
|
||||
],
|
||||
"author": {
|
||||
"name": "Luke Edwards",
|
||||
"email": "luke.edwards05@gmail.com",
|
||||
"url": "https://lukeed.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "bundt",
|
||||
"bench": "node bench",
|
||||
"pretest": "npm run build",
|
||||
"test": "tape test/*.js | tap-spec"
|
||||
},
|
||||
"keywords": [
|
||||
"argv",
|
||||
"arguments",
|
||||
"cli",
|
||||
"minimist",
|
||||
"options",
|
||||
"optimist",
|
||||
"parser",
|
||||
"args"
|
||||
],
|
||||
"devDependencies": {
|
||||
"bundt": "1.0.2",
|
||||
"tap-spec": "4.1.2",
|
||||
"tape": "4.13.3"
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
# mri [](https://github.com/lukeed/mri/actions)
|
||||
|
||||
> Quickly scan for CLI flags and arguments
|
||||
|
||||
This is a [fast](#benchmarks) and lightweight alternative to [`minimist`](https://github.com/substack/minimist) and [`yargs-parser`](https://github.com/yargs/yargs-parser).
|
||||
|
||||
It only exists because I find that I usually don't need most of what `minimist` and `yargs-parser` have to offer. However, `mri` is similar _enough_ that it might function as a "drop-in replacement" for you, too!
|
||||
|
||||
See [Comparisons](#comparisons) for more info.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
$ npm install --save mri
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
$ demo-cli --foo --bar=baz -mtv -- hello world
|
||||
```
|
||||
|
||||
```js
|
||||
const mri = require('mri');
|
||||
|
||||
const argv = process.argv.slice(2);
|
||||
|
||||
mri(argv);
|
||||
//=> { _: ['hello', 'world'], foo:true, bar:'baz', m:true, t:true, v:true }
|
||||
|
||||
mri(argv, { boolean:['bar'] });
|
||||
//=> { _: ['baz', 'hello', 'world'], foo:true, bar:true, m:true, t:true, v:true }
|
||||
|
||||
mri(argv, {
|
||||
alias: {
|
||||
b: 'bar',
|
||||
foo: ['f', 'fuz']
|
||||
}
|
||||
});
|
||||
//=> { _: ['hello', 'world'], foo:true, f:true, fuz:true, b:'baz', bar:'baz', m:true, t:true, v:true }
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### mri(args, options)
|
||||
Return: `Object`
|
||||
|
||||
#### args
|
||||
Type: `Array`<br>
|
||||
Default: `[]`
|
||||
|
||||
An array of arguments to parse. For CLI usage, send `process.argv.slice(2)`. See [`process.argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) for info.
|
||||
|
||||
#### options.alias
|
||||
Type: `Object`<br>
|
||||
Default: `{}`
|
||||
|
||||
An object of keys whose values are `String`s or `Array<String>` of aliases. These will be added to the parsed output with matching values.
|
||||
|
||||
#### options.boolean
|
||||
Type: `Array|String`<br>
|
||||
Default: `[]`
|
||||
|
||||
A single key (or array of keys) that should be parsed as `Boolean`s.
|
||||
|
||||
#### options.default
|
||||
Type: `Object`<br>
|
||||
Default: `{}`
|
||||
|
||||
An `key:value` object of defaults. If a default is provided for a key, its type (`typeof`) will be used to cast parsed arguments.
|
||||
|
||||
```js
|
||||
mri(['--foo', 'bar']);
|
||||
//=> { _:[], foo:'bar' }
|
||||
|
||||
mri(['--foo', 'bar'], {
|
||||
default: { foo:true, baz:'hello', bat:42 }
|
||||
});
|
||||
//=> { _:['bar'], foo:true, baz:'hello', bat:42 }
|
||||
```
|
||||
|
||||
> **Note:** Because `--foo` has a default of `true`, its output is cast to a Boolean. This means that `foo=true`, making `'bar'` an extra argument (`_` key).
|
||||
|
||||
#### options.string
|
||||
Type: `Array|String`<br>
|
||||
Default: `[]`
|
||||
|
||||
A single key (or array of keys) that should be parsed as `String`s.
|
||||
|
||||
#### options.unknown
|
||||
Type: `Function`<br>
|
||||
Default: `undefined`
|
||||
|
||||
Callback that is run when a parsed flag has not been defined as a known key or alias. Its only parameter is the unknown flag itself; eg `--foobar` or `-f`.
|
||||
|
||||
Once an unknown flag is encountered, parsing will terminate, regardless of your return value.
|
||||
|
||||
> **Note:** `mri` _only_ checks for unknown flags if `options.unknown` **and** `options.alias` are populated. Otherwise, everything will be accepted.
|
||||
|
||||
|
||||
## Comparisons
|
||||
|
||||
#### minimist
|
||||
|
||||
- `mri` is 5x faster (see [benchmarks](#benchmarks))
|
||||
- Numerical values are cast as `Number`s when possible
|
||||
- A key (and its aliases) will always honor `opts.boolean` or `opts.string`
|
||||
- Short flag groups are treated as `Boolean`s by default:
|
||||
```js
|
||||
minimist(['-abc', 'hello']);
|
||||
//=> { _:[], a:'', b:'', c:'hello' }
|
||||
|
||||
mri(['-abc', 'hello']);
|
||||
//=> { _:[], a:true, b:true, c:'hello' }
|
||||
```
|
||||
- The `opts.unknown` behaves differently:
|
||||
- Unlike `minimist`, `mri` will not continue continue parsing after encountering an unknown flag
|
||||
- Missing `options`:
|
||||
- `opts.stopEarly`
|
||||
- `opts['--']`
|
||||
- Ignores newlines (`\n`) within args (see [test](https://github.com/substack/minimist/blob/master/test/parse.js#L69-L80))
|
||||
- Ignores slashBreaks within args (see [test](https://github.com/substack/minimist/blob/master/test/parse.js#L147-L157))
|
||||
- Ignores dot-nested flags (see [test](https://github.com/substack/minimist/blob/master/test/parse.js#L180-L197))
|
||||
|
||||
#### yargs-parser
|
||||
|
||||
- `mri` is 40x faster (see [benchmarks](#benchmarks))
|
||||
- Numerical values are cast as `Number`s when possible
|
||||
- A key (and its aliases) will always honor `opts.boolean` or `opts.string`
|
||||
- Missing `options`:
|
||||
- `opts.array`
|
||||
- `opts.config`
|
||||
- `opts.coerce`
|
||||
- `opts.count`
|
||||
- `opts.envPrefix`
|
||||
- `opts.narg`
|
||||
- `opts.normalize`
|
||||
- `opts.configuration`
|
||||
- `opts.number`
|
||||
- `opts['--']`
|
||||
- Missing [`parser.detailed()`](https://github.com/yargs/yargs-parser#requireyargs-parserdetailedargs-opts) method
|
||||
- No [additional configuration](https://github.com/yargs/yargs-parser#configuration) object
|
||||
- Added [`options.unknown`](#optionsunknown) feature
|
||||
|
||||
|
||||
## Benchmarks
|
||||
|
||||
> Running Node.js v10.13.0
|
||||
|
||||
```
|
||||
Load Times:
|
||||
nopt 3.179ms
|
||||
yargs-parser 2.137ms
|
||||
minimist 0.746ms
|
||||
mri 0.517ms
|
||||
|
||||
Benchmark:
|
||||
minimist x 328,747 ops/sec ±1.09% (89 runs sampled)
|
||||
mri x 1,622,801 ops/sec ±0.94% (92 runs sampled)
|
||||
nopt x 888,223 ops/sec ±0.22% (92 runs sampled)
|
||||
yargs-parser x 30,538 ops/sec ±0.81% (91 runs sampled)
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Luke Edwards](https://lukeed.com)
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2012-2019 Thorsten Lorenz, Paul Miller (https://paulmillr.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.
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
# readdirp [](https://github.com/paulmillr/readdirp)
|
||||
|
||||
Recursive version of fs.readdir. Exposes a **stream API** (with small RAM & CPU footprint) and a **promise API**.
|
||||
|
||||
```sh
|
||||
npm install readdirp
|
||||
jsr add jsr:@paulmillr/readdirp
|
||||
```
|
||||
|
||||
```javascript
|
||||
// Use streams to achieve small RAM & CPU footprint.
|
||||
// 1) Streams example with for-await.
|
||||
import readdirp from 'readdirp';
|
||||
for await (const entry of readdirp('.')) {
|
||||
const {path} = entry;
|
||||
console.log(`${JSON.stringify({path})}`);
|
||||
}
|
||||
|
||||
// 2) Streams example, non for-await.
|
||||
// Print out all JS files along with their size within the current folder & subfolders.
|
||||
import readdirp from 'readdirp';
|
||||
readdirp('.', {alwaysStat: true, fileFilter: (f) => f.basename.endsWith('.js')})
|
||||
.on('data', (entry) => {
|
||||
const {path, stats: {size}} = entry;
|
||||
console.log(`${JSON.stringify({path, size})}`);
|
||||
})
|
||||
// Optionally call stream.destroy() in `warn()` in order to abort and cause 'close' to be emitted
|
||||
.on('warn', error => console.error('non-fatal error', error))
|
||||
.on('error', error => console.error('fatal error', error))
|
||||
.on('end', () => console.log('done'));
|
||||
|
||||
// 3) Promise example. More RAM and CPU than streams / for-await.
|
||||
import { readdirpPromise } from 'readdirp';
|
||||
const files = await readdirpPromise('.');
|
||||
console.log(files.map(file => file.path));
|
||||
|
||||
// Other options.
|
||||
import readdirp from 'readdirp';
|
||||
readdirp('test', {
|
||||
fileFilter: (f) => f.basename.endsWith('.js'),
|
||||
directoryFilter: (d) => d.basename !== '.git',
|
||||
// directoryFilter: (di) => di.basename.length === 9
|
||||
type: 'files_directories',
|
||||
depth: 1
|
||||
});
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
`const stream = readdirp(root[, options])` — **Stream API**
|
||||
|
||||
- Reads given root recursively and returns a `stream` of [entry infos](#entryinfo)
|
||||
- Optionally can be used like `for await (const entry of stream)` with node.js 10+ (`asyncIterator`).
|
||||
- `on('data', (entry) => {})` [entry info](#entryinfo) for every file / dir.
|
||||
- `on('warn', (error) => {})` non-fatal `Error` that prevents a file / dir from being processed. Example: inaccessible to the user.
|
||||
- `on('error', (error) => {})` fatal `Error` which also ends the stream. Example: illegal options where passed.
|
||||
- `on('end')` — we are done. Called when all entries were found and no more will be emitted.
|
||||
- `on('close')` — stream is destroyed via `stream.destroy()`.
|
||||
Could be useful if you want to manually abort even on a non fatal error.
|
||||
At that point the stream is no longer `readable` and no more entries, warning or errors are emitted
|
||||
- To learn more about streams, consult the very detailed [nodejs streams documentation](https://nodejs.org/api/stream.html)
|
||||
or the [stream-handbook](https://github.com/substack/stream-handbook)
|
||||
|
||||
`const entries = await readdirp.promise(root[, options])` — **Promise API**. Returns a list of [entry infos](#entryinfo).
|
||||
|
||||
First argument is awalys `root`, path in which to start reading and recursing into subdirectories.
|
||||
|
||||
### options
|
||||
|
||||
- `fileFilter`: filter to include or exclude files
|
||||
- **Function**: a function that takes an entry info as a parameter and returns true to include or false to exclude the entry
|
||||
- `directoryFilter`: filter to include/exclude directories found and to recurse into. Directories that do not pass a filter will not be recursed into.
|
||||
- `depth: 5`: depth at which to stop recursing even if more subdirectories are found
|
||||
- `type: 'files'`: determines if data events on the stream should be emitted for `'files'` (default), `'directories'`, `'files_directories'`, or `'all'`. Setting to `'all'` will also include entries for other types of file descriptors like character devices, unix sockets and named pipes.
|
||||
- `alwaysStat: false`: always return `stats` property for every file. Default is `false`, readdirp will return `Dirent` entries. Setting it to `true` can double readdir execution time - use it only when you need file `size`, `mtime` etc. Cannot be enabled on node <10.10.0.
|
||||
- `lstat: false`: include symlink entries in the stream along with files. When `true`, `fs.lstat` would be used instead of `fs.stat`
|
||||
|
||||
### `EntryInfo`
|
||||
|
||||
Has the following properties:
|
||||
|
||||
- `path: 'assets/javascripts/react.js'`: path to the file/directory (relative to given root)
|
||||
- `fullPath: '/Users/dev/projects/app/assets/javascripts/react.js'`: full path to the file/directory found
|
||||
- `basename: 'react.js'`: name of the file/directory
|
||||
- `dirent: fs.Dirent`: built-in [dir entry object](https://nodejs.org/api/fs.html#fs_class_fs_dirent) - only with `alwaysStat: false`
|
||||
- `stats: fs.Stats`: built in [stat object](https://nodejs.org/api/fs.html#fs_class_fs_stats) - only with `alwaysStat: true`
|
||||
|
||||
## Changelog
|
||||
|
||||
- 4.0 (Aug 25, 2024) rewritten in typescript, producing hybrid common.js / esm module.
|
||||
- Remove glob support and all dependencies
|
||||
- Make sure you're using `let {readdirp} = require('readdirp')` in common.js
|
||||
- 3.5 (Oct 13, 2020) disallows recursive directory-based symlinks.
|
||||
Before, it could have entered infinite loop.
|
||||
- 3.4 (Mar 19, 2020) adds support for directory-based symlinks.
|
||||
- 3.3 (Dec 6, 2019) stabilizes RAM consumption and enables perf management with `highWaterMark` option. Fixes race conditions related to `for-await` looping.
|
||||
- 3.2 (Oct 14, 2019) improves performance by 250% and makes streams implementation more idiomatic.
|
||||
- 3.1 (Jul 7, 2019) brings `bigint` support to `stat` output on Windows. This is backwards-incompatible for some cases. Be careful. It you use it incorrectly, you'll see "TypeError: Cannot mix BigInt and other types, use explicit conversions".
|
||||
- 3.0 brings huge performance improvements and stream backpressure support.
|
||||
- Upgrading 2.x to 3.x:
|
||||
- Signature changed from `readdirp(options)` to `readdirp(root, options)`
|
||||
- Replaced callback API with promise API.
|
||||
- Renamed `entryType` option to `type`
|
||||
- Renamed `entryType: 'both'` to `'files_directories'`
|
||||
- `EntryInfo`
|
||||
- Renamed `stat` to `stats`
|
||||
- Emitted only when `alwaysStat: true`
|
||||
- `dirent` is emitted instead of `stats` by default with `alwaysStat: false`
|
||||
- Renamed `name` to `basename`
|
||||
- Removed `parentDir` and `fullParentDir` properties
|
||||
- Supported node.js versions:
|
||||
- 4.x: node 14+
|
||||
- 3.x: node 8+
|
||||
- 2.x: node 0.6+
|
||||
|
||||
## License
|
||||
|
||||
Copyright (c) 2012-2019 Thorsten Lorenz, Paul Miller (<https://paulmillr.com>)
|
||||
|
||||
MIT License, see [LICENSE](LICENSE) file.
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* Recursive version of readdir. Exposes a streaming API and promise API.
|
||||
* Streaming API allows to use a small amount of RAM.
|
||||
*
|
||||
* @module
|
||||
* @example
|
||||
```js
|
||||
import readdirp from 'readdirp';
|
||||
for await (const entry of readdirp('.')) {
|
||||
const {path} = entry;
|
||||
console.log(`${JSON.stringify({path})}`);
|
||||
}
|
||||
```
|
||||
*/
|
||||
/*! readdirp - MIT License (c) 2012-2019 Thorsten Lorenz, Paul Miller (https://paulmillr.com) */
|
||||
import type { Stats, Dirent } from 'node:fs';
|
||||
import { Readable } from 'node:stream';
|
||||
/** Path in file system. */
|
||||
export type Path = string;
|
||||
/** Emitted entry. Contains relative & absolute path, basename, and either stats or dirent. */
|
||||
export interface EntryInfo {
|
||||
path: string;
|
||||
fullPath: string;
|
||||
stats?: Stats;
|
||||
dirent?: Dirent;
|
||||
basename: string;
|
||||
}
|
||||
/** Path or dir entries (files) */
|
||||
export type PathOrDirent = Dirent | Path;
|
||||
/** Filterer for files */
|
||||
export type Tester = (entryInfo: EntryInfo) => boolean;
|
||||
export type Predicate = string[] | string | Tester;
|
||||
export declare const EntryTypes: {
|
||||
readonly FILE_TYPE: "files";
|
||||
readonly DIR_TYPE: "directories";
|
||||
readonly FILE_DIR_TYPE: "files_directories";
|
||||
readonly EVERYTHING_TYPE: "all";
|
||||
};
|
||||
export type EntryType = (typeof EntryTypes)[keyof typeof EntryTypes];
|
||||
/**
|
||||
* Options for readdirp.
|
||||
* * type: files, directories, or both
|
||||
* * lstat: whether to use symlink-friendly stat
|
||||
* * depth: max depth
|
||||
* * alwaysStat: whether to use stat (more resources) or dirent
|
||||
* * highWaterMark: streaming param, specifies max amount of resources per entry
|
||||
*/
|
||||
export type ReaddirpOptions = {
|
||||
root: string;
|
||||
fileFilter?: Predicate;
|
||||
directoryFilter?: Predicate;
|
||||
type?: EntryType;
|
||||
lstat?: boolean;
|
||||
depth?: number;
|
||||
alwaysStat?: boolean;
|
||||
highWaterMark?: number;
|
||||
};
|
||||
/** Directory entry. Contains path, depth count, and files. */
|
||||
export interface DirEntry {
|
||||
files: PathOrDirent[];
|
||||
depth: number;
|
||||
path: Path;
|
||||
}
|
||||
/** Readable readdir stream, emitting new files as they're being listed. */
|
||||
export declare class ReaddirpStream extends Readable {
|
||||
parents: any[];
|
||||
reading: boolean;
|
||||
parent?: DirEntry;
|
||||
_stat: Function;
|
||||
_maxDepth: number;
|
||||
_wantsDir: boolean;
|
||||
_wantsFile: boolean;
|
||||
_wantsEverything: boolean;
|
||||
_root: Path;
|
||||
_isDirent: boolean;
|
||||
_statsProp: 'dirent' | 'stats';
|
||||
_rdOptions: {
|
||||
encoding: 'utf8';
|
||||
withFileTypes: boolean;
|
||||
};
|
||||
_fileFilter: Tester;
|
||||
_directoryFilter: Tester;
|
||||
constructor(options?: Partial<ReaddirpOptions>);
|
||||
_read(batch: number): Promise<void>;
|
||||
_exploreDir(path: Path, depth: number): Promise<{
|
||||
files: string[] | undefined;
|
||||
depth: number;
|
||||
path: string;
|
||||
}>;
|
||||
_formatEntry(dirent: PathOrDirent, path: Path): Promise<EntryInfo | undefined>;
|
||||
_onError(err: Error): void;
|
||||
_getEntryType(entry: EntryInfo): Promise<void | '' | 'file' | 'directory'>;
|
||||
_includeAsFile(entry: EntryInfo): boolean | undefined;
|
||||
}
|
||||
/**
|
||||
* Streaming version: Reads all files and directories in given root recursively.
|
||||
* Consumes ~constant small amount of RAM.
|
||||
* @param root Root directory
|
||||
* @param options Options to specify root (start directory), filters and recursion depth
|
||||
*/
|
||||
export declare function readdirp(root: Path, options?: Partial<ReaddirpOptions>): ReaddirpStream;
|
||||
/**
|
||||
* Promise version: Reads all files and directories in given root recursively.
|
||||
* Compared to streaming version, will consume a lot of RAM e.g. when 1 million files are listed.
|
||||
* @returns array of paths and their entry infos
|
||||
*/
|
||||
export declare function readdirpPromise(root: Path, options?: Partial<ReaddirpOptions>): Promise<EntryInfo[]>;
|
||||
export default readdirp;
|
||||
+257
@@ -0,0 +1,257 @@
|
||||
import { stat, lstat, readdir, realpath } from 'node:fs/promises';
|
||||
import { Readable } from 'node:stream';
|
||||
import { resolve as presolve, relative as prelative, join as pjoin, sep as psep } from 'node:path';
|
||||
export const EntryTypes = {
|
||||
FILE_TYPE: 'files',
|
||||
DIR_TYPE: 'directories',
|
||||
FILE_DIR_TYPE: 'files_directories',
|
||||
EVERYTHING_TYPE: 'all',
|
||||
};
|
||||
const defaultOptions = {
|
||||
root: '.',
|
||||
fileFilter: (_entryInfo) => true,
|
||||
directoryFilter: (_entryInfo) => true,
|
||||
type: EntryTypes.FILE_TYPE,
|
||||
lstat: false,
|
||||
depth: 2147483648,
|
||||
alwaysStat: false,
|
||||
highWaterMark: 4096,
|
||||
};
|
||||
Object.freeze(defaultOptions);
|
||||
const RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR';
|
||||
const NORMAL_FLOW_ERRORS = new Set(['ENOENT', 'EPERM', 'EACCES', 'ELOOP', RECURSIVE_ERROR_CODE]);
|
||||
const ALL_TYPES = [
|
||||
EntryTypes.DIR_TYPE,
|
||||
EntryTypes.EVERYTHING_TYPE,
|
||||
EntryTypes.FILE_DIR_TYPE,
|
||||
EntryTypes.FILE_TYPE,
|
||||
];
|
||||
const DIR_TYPES = new Set([
|
||||
EntryTypes.DIR_TYPE,
|
||||
EntryTypes.EVERYTHING_TYPE,
|
||||
EntryTypes.FILE_DIR_TYPE,
|
||||
]);
|
||||
const FILE_TYPES = new Set([
|
||||
EntryTypes.EVERYTHING_TYPE,
|
||||
EntryTypes.FILE_DIR_TYPE,
|
||||
EntryTypes.FILE_TYPE,
|
||||
]);
|
||||
const isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
|
||||
const wantBigintFsStats = process.platform === 'win32';
|
||||
const emptyFn = (_entryInfo) => true;
|
||||
const normalizeFilter = (filter) => {
|
||||
if (filter === undefined)
|
||||
return emptyFn;
|
||||
if (typeof filter === 'function')
|
||||
return filter;
|
||||
if (typeof filter === 'string') {
|
||||
const fl = filter.trim();
|
||||
return (entry) => entry.basename === fl;
|
||||
}
|
||||
if (Array.isArray(filter)) {
|
||||
const trItems = filter.map((item) => item.trim());
|
||||
return (entry) => trItems.some((f) => entry.basename === f);
|
||||
}
|
||||
return emptyFn;
|
||||
};
|
||||
/** Readable readdir stream, emitting new files as they're being listed. */
|
||||
export class ReaddirpStream extends Readable {
|
||||
constructor(options = {}) {
|
||||
super({
|
||||
objectMode: true,
|
||||
autoDestroy: true,
|
||||
highWaterMark: options.highWaterMark,
|
||||
});
|
||||
const opts = { ...defaultOptions, ...options };
|
||||
const { root, type } = opts;
|
||||
this._fileFilter = normalizeFilter(opts.fileFilter);
|
||||
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
||||
const statMethod = opts.lstat ? lstat : stat;
|
||||
// Use bigint stats if it's windows and stat() supports options (node 10+).
|
||||
if (wantBigintFsStats) {
|
||||
this._stat = (path) => statMethod(path, { bigint: true });
|
||||
}
|
||||
else {
|
||||
this._stat = statMethod;
|
||||
}
|
||||
this._maxDepth = opts.depth ?? defaultOptions.depth;
|
||||
this._wantsDir = type ? DIR_TYPES.has(type) : false;
|
||||
this._wantsFile = type ? FILE_TYPES.has(type) : false;
|
||||
this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
|
||||
this._root = presolve(root);
|
||||
this._isDirent = !opts.alwaysStat;
|
||||
this._statsProp = this._isDirent ? 'dirent' : 'stats';
|
||||
this._rdOptions = { encoding: 'utf8', withFileTypes: this._isDirent };
|
||||
// Launch stream with one parent, the root dir.
|
||||
this.parents = [this._exploreDir(root, 1)];
|
||||
this.reading = false;
|
||||
this.parent = undefined;
|
||||
}
|
||||
async _read(batch) {
|
||||
if (this.reading)
|
||||
return;
|
||||
this.reading = true;
|
||||
try {
|
||||
while (!this.destroyed && batch > 0) {
|
||||
const par = this.parent;
|
||||
const fil = par && par.files;
|
||||
if (fil && fil.length > 0) {
|
||||
const { path, depth } = par;
|
||||
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path));
|
||||
const awaited = await Promise.all(slice);
|
||||
for (const entry of awaited) {
|
||||
if (!entry)
|
||||
continue;
|
||||
if (this.destroyed)
|
||||
return;
|
||||
const entryType = await this._getEntryType(entry);
|
||||
if (entryType === 'directory' && this._directoryFilter(entry)) {
|
||||
if (depth <= this._maxDepth) {
|
||||
this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
|
||||
}
|
||||
if (this._wantsDir) {
|
||||
this.push(entry);
|
||||
batch--;
|
||||
}
|
||||
}
|
||||
else if ((entryType === 'file' || this._includeAsFile(entry)) &&
|
||||
this._fileFilter(entry)) {
|
||||
if (this._wantsFile) {
|
||||
this.push(entry);
|
||||
batch--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const parent = this.parents.pop();
|
||||
if (!parent) {
|
||||
this.push(null);
|
||||
break;
|
||||
}
|
||||
this.parent = await parent;
|
||||
if (this.destroyed)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
this.destroy(error);
|
||||
}
|
||||
finally {
|
||||
this.reading = false;
|
||||
}
|
||||
}
|
||||
async _exploreDir(path, depth) {
|
||||
let files;
|
||||
try {
|
||||
files = await readdir(path, this._rdOptions);
|
||||
}
|
||||
catch (error) {
|
||||
this._onError(error);
|
||||
}
|
||||
return { files, depth, path };
|
||||
}
|
||||
async _formatEntry(dirent, path) {
|
||||
let entry;
|
||||
const basename = this._isDirent ? dirent.name : dirent;
|
||||
try {
|
||||
const fullPath = presolve(pjoin(path, basename));
|
||||
entry = { path: prelative(this._root, fullPath), fullPath, basename };
|
||||
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
||||
}
|
||||
catch (err) {
|
||||
this._onError(err);
|
||||
return;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
_onError(err) {
|
||||
if (isNormalFlowError(err) && !this.destroyed) {
|
||||
this.emit('warn', err);
|
||||
}
|
||||
else {
|
||||
this.destroy(err);
|
||||
}
|
||||
}
|
||||
async _getEntryType(entry) {
|
||||
// entry may be undefined, because a warning or an error were emitted
|
||||
// and the statsProp is undefined
|
||||
if (!entry && this._statsProp in entry) {
|
||||
return '';
|
||||
}
|
||||
const stats = entry[this._statsProp];
|
||||
if (stats.isFile())
|
||||
return 'file';
|
||||
if (stats.isDirectory())
|
||||
return 'directory';
|
||||
if (stats && stats.isSymbolicLink()) {
|
||||
const full = entry.fullPath;
|
||||
try {
|
||||
const entryRealPath = await realpath(full);
|
||||
const entryRealPathStats = await lstat(entryRealPath);
|
||||
if (entryRealPathStats.isFile()) {
|
||||
return 'file';
|
||||
}
|
||||
if (entryRealPathStats.isDirectory()) {
|
||||
const len = entryRealPath.length;
|
||||
if (full.startsWith(entryRealPath) && full.substr(len, 1) === psep) {
|
||||
const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
|
||||
// @ts-ignore
|
||||
recursiveError.code = RECURSIVE_ERROR_CODE;
|
||||
return this._onError(recursiveError);
|
||||
}
|
||||
return 'directory';
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
this._onError(error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
_includeAsFile(entry) {
|
||||
const stats = entry && entry[this._statsProp];
|
||||
return stats && this._wantsEverything && !stats.isDirectory();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Streaming version: Reads all files and directories in given root recursively.
|
||||
* Consumes ~constant small amount of RAM.
|
||||
* @param root Root directory
|
||||
* @param options Options to specify root (start directory), filters and recursion depth
|
||||
*/
|
||||
export function readdirp(root, options = {}) {
|
||||
// @ts-ignore
|
||||
let type = options.entryType || options.type;
|
||||
if (type === 'both')
|
||||
type = EntryTypes.FILE_DIR_TYPE; // backwards-compatibility
|
||||
if (type)
|
||||
options.type = type;
|
||||
if (!root) {
|
||||
throw new Error('readdirp: root argument is required. Usage: readdirp(root, options)');
|
||||
}
|
||||
else if (typeof root !== 'string') {
|
||||
throw new TypeError('readdirp: root argument must be a string. Usage: readdirp(root, options)');
|
||||
}
|
||||
else if (type && !ALL_TYPES.includes(type)) {
|
||||
throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(', ')}`);
|
||||
}
|
||||
options.root = root;
|
||||
return new ReaddirpStream(options);
|
||||
}
|
||||
/**
|
||||
* Promise version: Reads all files and directories in given root recursively.
|
||||
* Compared to streaming version, will consume a lot of RAM e.g. when 1 million files are listed.
|
||||
* @returns array of paths and their entry infos
|
||||
*/
|
||||
export function readdirpPromise(root, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const files = [];
|
||||
readdirp(root, options)
|
||||
.on('data', (entry) => files.push(entry))
|
||||
.on('end', () => resolve(files))
|
||||
.on('error', (error) => reject(error));
|
||||
});
|
||||
}
|
||||
export default readdirp;
|
||||
+1
@@ -0,0 +1 @@
|
||||
{ "type": "module", "sideEffects": false }
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* Recursive version of readdir. Exposes a streaming API and promise API.
|
||||
* Streaming API allows to use a small amount of RAM.
|
||||
*
|
||||
* @module
|
||||
* @example
|
||||
```js
|
||||
import readdirp from 'readdirp';
|
||||
for await (const entry of readdirp('.')) {
|
||||
const {path} = entry;
|
||||
console.log(`${JSON.stringify({path})}`);
|
||||
}
|
||||
```
|
||||
*/
|
||||
/*! readdirp - MIT License (c) 2012-2019 Thorsten Lorenz, Paul Miller (https://paulmillr.com) */
|
||||
import type { Stats, Dirent } from 'node:fs';
|
||||
import { Readable } from 'node:stream';
|
||||
/** Path in file system. */
|
||||
export type Path = string;
|
||||
/** Emitted entry. Contains relative & absolute path, basename, and either stats or dirent. */
|
||||
export interface EntryInfo {
|
||||
path: string;
|
||||
fullPath: string;
|
||||
stats?: Stats;
|
||||
dirent?: Dirent;
|
||||
basename: string;
|
||||
}
|
||||
/** Path or dir entries (files) */
|
||||
export type PathOrDirent = Dirent | Path;
|
||||
/** Filterer for files */
|
||||
export type Tester = (entryInfo: EntryInfo) => boolean;
|
||||
export type Predicate = string[] | string | Tester;
|
||||
export declare const EntryTypes: {
|
||||
readonly FILE_TYPE: "files";
|
||||
readonly DIR_TYPE: "directories";
|
||||
readonly FILE_DIR_TYPE: "files_directories";
|
||||
readonly EVERYTHING_TYPE: "all";
|
||||
};
|
||||
export type EntryType = (typeof EntryTypes)[keyof typeof EntryTypes];
|
||||
/**
|
||||
* Options for readdirp.
|
||||
* * type: files, directories, or both
|
||||
* * lstat: whether to use symlink-friendly stat
|
||||
* * depth: max depth
|
||||
* * alwaysStat: whether to use stat (more resources) or dirent
|
||||
* * highWaterMark: streaming param, specifies max amount of resources per entry
|
||||
*/
|
||||
export type ReaddirpOptions = {
|
||||
root: string;
|
||||
fileFilter?: Predicate;
|
||||
directoryFilter?: Predicate;
|
||||
type?: EntryType;
|
||||
lstat?: boolean;
|
||||
depth?: number;
|
||||
alwaysStat?: boolean;
|
||||
highWaterMark?: number;
|
||||
};
|
||||
/** Directory entry. Contains path, depth count, and files. */
|
||||
export interface DirEntry {
|
||||
files: PathOrDirent[];
|
||||
depth: number;
|
||||
path: Path;
|
||||
}
|
||||
/** Readable readdir stream, emitting new files as they're being listed. */
|
||||
export declare class ReaddirpStream extends Readable {
|
||||
parents: any[];
|
||||
reading: boolean;
|
||||
parent?: DirEntry;
|
||||
_stat: Function;
|
||||
_maxDepth: number;
|
||||
_wantsDir: boolean;
|
||||
_wantsFile: boolean;
|
||||
_wantsEverything: boolean;
|
||||
_root: Path;
|
||||
_isDirent: boolean;
|
||||
_statsProp: 'dirent' | 'stats';
|
||||
_rdOptions: {
|
||||
encoding: 'utf8';
|
||||
withFileTypes: boolean;
|
||||
};
|
||||
_fileFilter: Tester;
|
||||
_directoryFilter: Tester;
|
||||
constructor(options?: Partial<ReaddirpOptions>);
|
||||
_read(batch: number): Promise<void>;
|
||||
_exploreDir(path: Path, depth: number): Promise<{
|
||||
files: string[] | undefined;
|
||||
depth: number;
|
||||
path: string;
|
||||
}>;
|
||||
_formatEntry(dirent: PathOrDirent, path: Path): Promise<EntryInfo | undefined>;
|
||||
_onError(err: Error): void;
|
||||
_getEntryType(entry: EntryInfo): Promise<void | '' | 'file' | 'directory'>;
|
||||
_includeAsFile(entry: EntryInfo): boolean | undefined;
|
||||
}
|
||||
/**
|
||||
* Streaming version: Reads all files and directories in given root recursively.
|
||||
* Consumes ~constant small amount of RAM.
|
||||
* @param root Root directory
|
||||
* @param options Options to specify root (start directory), filters and recursion depth
|
||||
*/
|
||||
export declare function readdirp(root: Path, options?: Partial<ReaddirpOptions>): ReaddirpStream;
|
||||
/**
|
||||
* Promise version: Reads all files and directories in given root recursively.
|
||||
* Compared to streaming version, will consume a lot of RAM e.g. when 1 million files are listed.
|
||||
* @returns array of paths and their entry infos
|
||||
*/
|
||||
export declare function readdirpPromise(root: Path, options?: Partial<ReaddirpOptions>): Promise<EntryInfo[]>;
|
||||
export default readdirp;
|
||||
+263
@@ -0,0 +1,263 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ReaddirpStream = exports.EntryTypes = void 0;
|
||||
exports.readdirp = readdirp;
|
||||
exports.readdirpPromise = readdirpPromise;
|
||||
const promises_1 = require("node:fs/promises");
|
||||
const node_stream_1 = require("node:stream");
|
||||
const node_path_1 = require("node:path");
|
||||
exports.EntryTypes = {
|
||||
FILE_TYPE: 'files',
|
||||
DIR_TYPE: 'directories',
|
||||
FILE_DIR_TYPE: 'files_directories',
|
||||
EVERYTHING_TYPE: 'all',
|
||||
};
|
||||
const defaultOptions = {
|
||||
root: '.',
|
||||
fileFilter: (_entryInfo) => true,
|
||||
directoryFilter: (_entryInfo) => true,
|
||||
type: exports.EntryTypes.FILE_TYPE,
|
||||
lstat: false,
|
||||
depth: 2147483648,
|
||||
alwaysStat: false,
|
||||
highWaterMark: 4096,
|
||||
};
|
||||
Object.freeze(defaultOptions);
|
||||
const RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR';
|
||||
const NORMAL_FLOW_ERRORS = new Set(['ENOENT', 'EPERM', 'EACCES', 'ELOOP', RECURSIVE_ERROR_CODE]);
|
||||
const ALL_TYPES = [
|
||||
exports.EntryTypes.DIR_TYPE,
|
||||
exports.EntryTypes.EVERYTHING_TYPE,
|
||||
exports.EntryTypes.FILE_DIR_TYPE,
|
||||
exports.EntryTypes.FILE_TYPE,
|
||||
];
|
||||
const DIR_TYPES = new Set([
|
||||
exports.EntryTypes.DIR_TYPE,
|
||||
exports.EntryTypes.EVERYTHING_TYPE,
|
||||
exports.EntryTypes.FILE_DIR_TYPE,
|
||||
]);
|
||||
const FILE_TYPES = new Set([
|
||||
exports.EntryTypes.EVERYTHING_TYPE,
|
||||
exports.EntryTypes.FILE_DIR_TYPE,
|
||||
exports.EntryTypes.FILE_TYPE,
|
||||
]);
|
||||
const isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
|
||||
const wantBigintFsStats = process.platform === 'win32';
|
||||
const emptyFn = (_entryInfo) => true;
|
||||
const normalizeFilter = (filter) => {
|
||||
if (filter === undefined)
|
||||
return emptyFn;
|
||||
if (typeof filter === 'function')
|
||||
return filter;
|
||||
if (typeof filter === 'string') {
|
||||
const fl = filter.trim();
|
||||
return (entry) => entry.basename === fl;
|
||||
}
|
||||
if (Array.isArray(filter)) {
|
||||
const trItems = filter.map((item) => item.trim());
|
||||
return (entry) => trItems.some((f) => entry.basename === f);
|
||||
}
|
||||
return emptyFn;
|
||||
};
|
||||
/** Readable readdir stream, emitting new files as they're being listed. */
|
||||
class ReaddirpStream extends node_stream_1.Readable {
|
||||
constructor(options = {}) {
|
||||
super({
|
||||
objectMode: true,
|
||||
autoDestroy: true,
|
||||
highWaterMark: options.highWaterMark,
|
||||
});
|
||||
const opts = { ...defaultOptions, ...options };
|
||||
const { root, type } = opts;
|
||||
this._fileFilter = normalizeFilter(opts.fileFilter);
|
||||
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
||||
const statMethod = opts.lstat ? promises_1.lstat : promises_1.stat;
|
||||
// Use bigint stats if it's windows and stat() supports options (node 10+).
|
||||
if (wantBigintFsStats) {
|
||||
this._stat = (path) => statMethod(path, { bigint: true });
|
||||
}
|
||||
else {
|
||||
this._stat = statMethod;
|
||||
}
|
||||
this._maxDepth = opts.depth ?? defaultOptions.depth;
|
||||
this._wantsDir = type ? DIR_TYPES.has(type) : false;
|
||||
this._wantsFile = type ? FILE_TYPES.has(type) : false;
|
||||
this._wantsEverything = type === exports.EntryTypes.EVERYTHING_TYPE;
|
||||
this._root = (0, node_path_1.resolve)(root);
|
||||
this._isDirent = !opts.alwaysStat;
|
||||
this._statsProp = this._isDirent ? 'dirent' : 'stats';
|
||||
this._rdOptions = { encoding: 'utf8', withFileTypes: this._isDirent };
|
||||
// Launch stream with one parent, the root dir.
|
||||
this.parents = [this._exploreDir(root, 1)];
|
||||
this.reading = false;
|
||||
this.parent = undefined;
|
||||
}
|
||||
async _read(batch) {
|
||||
if (this.reading)
|
||||
return;
|
||||
this.reading = true;
|
||||
try {
|
||||
while (!this.destroyed && batch > 0) {
|
||||
const par = this.parent;
|
||||
const fil = par && par.files;
|
||||
if (fil && fil.length > 0) {
|
||||
const { path, depth } = par;
|
||||
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path));
|
||||
const awaited = await Promise.all(slice);
|
||||
for (const entry of awaited) {
|
||||
if (!entry)
|
||||
continue;
|
||||
if (this.destroyed)
|
||||
return;
|
||||
const entryType = await this._getEntryType(entry);
|
||||
if (entryType === 'directory' && this._directoryFilter(entry)) {
|
||||
if (depth <= this._maxDepth) {
|
||||
this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
|
||||
}
|
||||
if (this._wantsDir) {
|
||||
this.push(entry);
|
||||
batch--;
|
||||
}
|
||||
}
|
||||
else if ((entryType === 'file' || this._includeAsFile(entry)) &&
|
||||
this._fileFilter(entry)) {
|
||||
if (this._wantsFile) {
|
||||
this.push(entry);
|
||||
batch--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const parent = this.parents.pop();
|
||||
if (!parent) {
|
||||
this.push(null);
|
||||
break;
|
||||
}
|
||||
this.parent = await parent;
|
||||
if (this.destroyed)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
this.destroy(error);
|
||||
}
|
||||
finally {
|
||||
this.reading = false;
|
||||
}
|
||||
}
|
||||
async _exploreDir(path, depth) {
|
||||
let files;
|
||||
try {
|
||||
files = await (0, promises_1.readdir)(path, this._rdOptions);
|
||||
}
|
||||
catch (error) {
|
||||
this._onError(error);
|
||||
}
|
||||
return { files, depth, path };
|
||||
}
|
||||
async _formatEntry(dirent, path) {
|
||||
let entry;
|
||||
const basename = this._isDirent ? dirent.name : dirent;
|
||||
try {
|
||||
const fullPath = (0, node_path_1.resolve)((0, node_path_1.join)(path, basename));
|
||||
entry = { path: (0, node_path_1.relative)(this._root, fullPath), fullPath, basename };
|
||||
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
||||
}
|
||||
catch (err) {
|
||||
this._onError(err);
|
||||
return;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
_onError(err) {
|
||||
if (isNormalFlowError(err) && !this.destroyed) {
|
||||
this.emit('warn', err);
|
||||
}
|
||||
else {
|
||||
this.destroy(err);
|
||||
}
|
||||
}
|
||||
async _getEntryType(entry) {
|
||||
// entry may be undefined, because a warning or an error were emitted
|
||||
// and the statsProp is undefined
|
||||
if (!entry && this._statsProp in entry) {
|
||||
return '';
|
||||
}
|
||||
const stats = entry[this._statsProp];
|
||||
if (stats.isFile())
|
||||
return 'file';
|
||||
if (stats.isDirectory())
|
||||
return 'directory';
|
||||
if (stats && stats.isSymbolicLink()) {
|
||||
const full = entry.fullPath;
|
||||
try {
|
||||
const entryRealPath = await (0, promises_1.realpath)(full);
|
||||
const entryRealPathStats = await (0, promises_1.lstat)(entryRealPath);
|
||||
if (entryRealPathStats.isFile()) {
|
||||
return 'file';
|
||||
}
|
||||
if (entryRealPathStats.isDirectory()) {
|
||||
const len = entryRealPath.length;
|
||||
if (full.startsWith(entryRealPath) && full.substr(len, 1) === node_path_1.sep) {
|
||||
const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
|
||||
// @ts-ignore
|
||||
recursiveError.code = RECURSIVE_ERROR_CODE;
|
||||
return this._onError(recursiveError);
|
||||
}
|
||||
return 'directory';
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
this._onError(error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
_includeAsFile(entry) {
|
||||
const stats = entry && entry[this._statsProp];
|
||||
return stats && this._wantsEverything && !stats.isDirectory();
|
||||
}
|
||||
}
|
||||
exports.ReaddirpStream = ReaddirpStream;
|
||||
/**
|
||||
* Streaming version: Reads all files and directories in given root recursively.
|
||||
* Consumes ~constant small amount of RAM.
|
||||
* @param root Root directory
|
||||
* @param options Options to specify root (start directory), filters and recursion depth
|
||||
*/
|
||||
function readdirp(root, options = {}) {
|
||||
// @ts-ignore
|
||||
let type = options.entryType || options.type;
|
||||
if (type === 'both')
|
||||
type = exports.EntryTypes.FILE_DIR_TYPE; // backwards-compatibility
|
||||
if (type)
|
||||
options.type = type;
|
||||
if (!root) {
|
||||
throw new Error('readdirp: root argument is required. Usage: readdirp(root, options)');
|
||||
}
|
||||
else if (typeof root !== 'string') {
|
||||
throw new TypeError('readdirp: root argument must be a string. Usage: readdirp(root, options)');
|
||||
}
|
||||
else if (type && !ALL_TYPES.includes(type)) {
|
||||
throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(', ')}`);
|
||||
}
|
||||
options.root = root;
|
||||
return new ReaddirpStream(options);
|
||||
}
|
||||
/**
|
||||
* Promise version: Reads all files and directories in given root recursively.
|
||||
* Compared to streaming version, will consume a lot of RAM e.g. when 1 million files are listed.
|
||||
* @returns array of paths and their entry infos
|
||||
*/
|
||||
function readdirpPromise(root, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const files = [];
|
||||
readdirp(root, options)
|
||||
.on('data', (entry) => files.push(entry))
|
||||
.on('end', () => resolve(files))
|
||||
.on('error', (error) => reject(error));
|
||||
});
|
||||
}
|
||||
exports.default = readdirp;
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"name": "readdirp",
|
||||
"description": "Recursive version of fs.readdir with small RAM & CPU footprint.",
|
||||
"version": "4.1.2",
|
||||
"homepage": "https://github.com/paulmillr/readdirp",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/paulmillr/readdirp.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/paulmillr/readdirp/issues"
|
||||
},
|
||||
"author": "Thorsten Lorenz <thlorenz@gmx.de> (thlorenz.com)",
|
||||
"contributors": [
|
||||
"Thorsten Lorenz <thlorenz@gmx.de> (thlorenz.com)",
|
||||
"Paul Miller (https://paulmillr.com)"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 14.18.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"index.d.ts.map",
|
||||
"index.js.map",
|
||||
"esm"
|
||||
],
|
||||
"main": "./index.js",
|
||||
"module": "./esm/index.js",
|
||||
"types": "./index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./esm/index.js",
|
||||
"require": "./index.js"
|
||||
}
|
||||
},
|
||||
"sideEffects": false,
|
||||
"keywords": [
|
||||
"recursive",
|
||||
"fs",
|
||||
"stream",
|
||||
"streams",
|
||||
"readdir",
|
||||
"filesystem",
|
||||
"find",
|
||||
"filter"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc && tsc -p tsconfig.cjs.json",
|
||||
"lint": "prettier --check index.ts test/index.test.js",
|
||||
"format": "prettier --write index.ts test/index.test.js",
|
||||
"test": "node test/index.test.js",
|
||||
"test:coverage": "c8 node test/index.test.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@paulmillr/jsbt": "0.3.1",
|
||||
"@types/node": "20.14.8",
|
||||
"c8": "10.1.3",
|
||||
"chai": "4.3.4",
|
||||
"chai-subset": "1.6.0",
|
||||
"micro-should": "0.5.0",
|
||||
"prettier": "3.1.1",
|
||||
"typescript": "5.5.2"
|
||||
},
|
||||
"funding": {
|
||||
"type": "individual",
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
import type * as mri from 'mri';
|
||||
|
||||
type Arrayable<T> = T | T[];
|
||||
|
||||
declare function sade(usage: string, isSingle?: boolean): sade.Sade;
|
||||
|
||||
declare namespace sade {
|
||||
export type Handler = (...args: any[]) => any;
|
||||
export type Value = number | string | boolean | null;
|
||||
|
||||
export interface LazyOutput {
|
||||
name: string;
|
||||
handler: Handler;
|
||||
args: string[];
|
||||
}
|
||||
|
||||
export interface Sade {
|
||||
command(usage: string, description?: string, options?: {
|
||||
alias?: Arrayable<string>;
|
||||
default?: boolean;
|
||||
}): Sade;
|
||||
|
||||
option(flag: string, description?: string, value?: Value): Sade;
|
||||
action(handler: Handler): Sade;
|
||||
describe(text: Arrayable<string>): Sade;
|
||||
alias(...names: string[]): Sade;
|
||||
example(usage: string): Sade;
|
||||
|
||||
parse(arr: string[], opts: { lazy: true } & mri.Options): LazyOutput;
|
||||
parse(arr: string[], opts?: { lazy?: boolean } & mri.Options): void;
|
||||
|
||||
version(value: string): Sade;
|
||||
help(cmd?: string): void;
|
||||
}
|
||||
}
|
||||
|
||||
export = sade;
|
||||
+1
@@ -0,0 +1 @@
|
||||
const e=require("mri"),t="__all__",i="__default__",s="\n";function r(e){if(!e.length)return"";let t=function(e){let t=0,i=0,s=0,r=e.length;if(r)for(;r--;)i=e[r].length,i>t&&(s=r,t=i);return e[s].length}(e.map(e=>e[0]))+4;return e.map(e=>e[0]+" ".repeat(t-e[0].length)+e[1]+(null==e[2]?"":` (default ${e[2]})`))}function n(e){return e}function l(e,t,i){if(!t||!t.length)return"";let r=0,n="";for(n+="\n "+e;r<t.length;r++)n+="\n "+i(t[r]);return n+s}function a(e,t,i=1){let s=l("ERROR",[t],n);s+=`\n Run \`$ ${e} --help\` for more info.\n`,console.error(s),process.exit(i)}class o{constructor(e,s){let[r,...n]=e.split(/\s+/);s=s||n.length>0,this.bin=r,this.ver="0.0.0",this.default="",this.tree={},this.command(t),this.command([i].concat(s?n:"<command>").join(" ")),this.single=s,this.curr=""}command(e,t,i={}){if(this.single)throw new Error('Disable "single" mode to add commands');let s=[],r=[],n=/(\[|<)/;if(e.split(/\s+/).forEach(e=>{(n.test(e.charAt(0))?r:s).push(e)}),s=s.join(" "),s in this.tree)throw new Error("Command already exists: "+s);return s.includes("__")||r.unshift(s),r=r.join(" "),this.curr=s,i.default&&(this.default=s),this.tree[s]={usage:r,alibi:[],options:[],alias:{},default:{},examples:[]},i.alias&&this.alias(i.alias),t&&this.describe(t),this}describe(e){return this.tree[this.curr||i].describe=Array.isArray(e)?e:function(e){return(e||"").replace(/([.?!])\s*(?=[A-Z])/g,"$1|").split("|")}(e),this}alias(...e){if(this.single)throw new Error('Cannot call `alias()` in "single" mode');if(!this.curr)throw new Error("Cannot call `alias()` before defining a command");return(this.tree[this.curr].alibi=this.tree[this.curr].alibi.concat(...e)).forEach(e=>this.tree[e]=this.curr),this}option(e,i,s){let r=this.tree[this.curr||t],[n,l]=function(e){return(e||"").split(/^-{1,2}|,|\s+-{1,2}|\s+/).filter(Boolean)}(e);if(l&&l.length>1&&([n,l]=[l,n]),e="--"+n,l&&l.length>0){e=`-${l}, ${e}`;let t=r.alias[l];r.alias[l]=(t||[]).concat(n)}let a=[e,i||""];return void 0!==s?(a.push(s),r.default[n]=s):l||(r.default[n]=void 0),r.options.push(a),this}action(e){return this.tree[this.curr||i].handler=e,this}example(e){return this.tree[this.curr||i].examples.push(e),this}version(e){return this.ver=e,this}parse(s,r={}){s=s.slice();let n,l,o,h,u=2,c=e(s.slice(u),{alias:{h:"help",v:"version"}}),f=this.single,p=this.bin,d="";if(f)h=this.tree[i];else{let e,t=1,i=c._.length+1;for(;t<i;t++)if(n=c._.slice(0,t).join(" "),e=this.tree[n],"string"==typeof e)l=(d=e).split(" "),s.splice(s.indexOf(c._[0]),t,...l),t+=l.length-t;else if(e)d=n;else if(d)break;if(h=this.tree[d],o=void 0===h,o)if(this.default)d=this.default,h=this.tree[d],s.unshift(d),u++;else if(n)return a(p,"Invalid command: "+n)}if(c.help)return this.help(!f&&!o&&d);if(c.version)return this._version();if(!f&&void 0===h)return a(p,"No command specified.");let g=this.tree[t];r.alias=Object.assign(g.alias,h.alias,r.alias),r.default=Object.assign(g.default,h.default,r.default),n=d.split(" "),l=s.indexOf(n[0],2),~l&&s.splice(l,n.length);let m=e(s.slice(u),r);if(!m||"string"==typeof m)return a(p,m||"Parsed unknown option flag(s)!");let b=h.usage.split(/\s+/),_=b.filter(e=>"<"===e.charAt(0)),v=m._.splice(0,_.length);if(v.length<_.length)return d&&(p+=" "+d),a(p,"Insufficient arguments!");b.filter(e=>"["===e.charAt(0)).forEach(e=>{v.push(m._.shift())}),v.push(m);let $=h.handler;return r.lazy?{args:v,name:d,handler:$}:$.apply(null,v)}help(e){console.log(function(e,a,o,h){let u="",c=a[o],f="$ "+e,p=a[t],d=e=>`${f} ${e}`.replace(/\s+/g," "),g=[["-h, --help","Displays this message"]];if(o===i&&g.unshift(["-v, --version","Displays current version"]),c.options=(c.options||[]).concat(p.options,g),c.options.length>0&&(c.usage+=" [options]"),u+=l("Description",c.describe,n),u+=l("Usage",[c.usage],d),h||o!==i)h||o===i||(u+=l("Aliases",c.alibi,d));else{let e,t=/^__/,i="",o=[];for(e in a)"string"==typeof a[e]||t.test(e)||o.push([e,(a[e].describe||[""])[0]])<3&&(i+=`\n ${f} ${e} --help`);u+=l("Available Commands",r(o),n),u+="\n For more info, run any command with the `--help` flag"+i+s}return u+=l("Options",r(c.options),n),u+=l("Examples",c.examples.map(d),n),u}(this.bin,this.tree,e||i,this.single))}_version(){console.log(`${this.bin}, ${this.ver}`)}}module.exports=(e,t)=>new o(e,t);
|
||||
+1
@@ -0,0 +1 @@
|
||||
import e from"mri";const t="__all__",i="__default__",s="\n";function r(e){if(!e.length)return"";let t=function(e){let t=0,i=0,s=0,r=e.length;if(r)for(;r--;)i=e[r].length,i>t&&(s=r,t=i);return e[s].length}(e.map(e=>e[0]))+4;return e.map(e=>e[0]+" ".repeat(t-e[0].length)+e[1]+(null==e[2]?"":` (default ${e[2]})`))}function n(e){return e}function l(e,t,i){if(!t||!t.length)return"";let r=0,n="";for(n+="\n "+e;r<t.length;r++)n+="\n "+i(t[r]);return n+s}function a(e,t,i=1){let s=l("ERROR",[t],n);s+=`\n Run \`$ ${e} --help\` for more info.\n`,console.error(s),process.exit(i)}class o{constructor(e,s){let[r,...n]=e.split(/\s+/);s=s||n.length>0,this.bin=r,this.ver="0.0.0",this.default="",this.tree={},this.command(t),this.command([i].concat(s?n:"<command>").join(" ")),this.single=s,this.curr=""}command(e,t,i={}){if(this.single)throw new Error('Disable "single" mode to add commands');let s=[],r=[],n=/(\[|<)/;if(e.split(/\s+/).forEach(e=>{(n.test(e.charAt(0))?r:s).push(e)}),s=s.join(" "),s in this.tree)throw new Error("Command already exists: "+s);return s.includes("__")||r.unshift(s),r=r.join(" "),this.curr=s,i.default&&(this.default=s),this.tree[s]={usage:r,alibi:[],options:[],alias:{},default:{},examples:[]},i.alias&&this.alias(i.alias),t&&this.describe(t),this}describe(e){return this.tree[this.curr||i].describe=Array.isArray(e)?e:function(e){return(e||"").replace(/([.?!])\s*(?=[A-Z])/g,"$1|").split("|")}(e),this}alias(...e){if(this.single)throw new Error('Cannot call `alias()` in "single" mode');if(!this.curr)throw new Error("Cannot call `alias()` before defining a command");return(this.tree[this.curr].alibi=this.tree[this.curr].alibi.concat(...e)).forEach(e=>this.tree[e]=this.curr),this}option(e,i,s){let r=this.tree[this.curr||t],[n,l]=function(e){return(e||"").split(/^-{1,2}|,|\s+-{1,2}|\s+/).filter(Boolean)}(e);if(l&&l.length>1&&([n,l]=[l,n]),e="--"+n,l&&l.length>0){e=`-${l}, ${e}`;let t=r.alias[l];r.alias[l]=(t||[]).concat(n)}let a=[e,i||""];return void 0!==s?(a.push(s),r.default[n]=s):l||(r.default[n]=void 0),r.options.push(a),this}action(e){return this.tree[this.curr||i].handler=e,this}example(e){return this.tree[this.curr||i].examples.push(e),this}version(e){return this.ver=e,this}parse(s,r={}){s=s.slice();let n,l,o,h,u=2,f=e(s.slice(u),{alias:{h:"help",v:"version"}}),c=this.single,p=this.bin,d="";if(c)h=this.tree[i];else{let e,t=1,i=f._.length+1;for(;t<i;t++)if(n=f._.slice(0,t).join(" "),e=this.tree[n],"string"==typeof e)l=(d=e).split(" "),s.splice(s.indexOf(f._[0]),t,...l),t+=l.length-t;else if(e)d=n;else if(d)break;if(h=this.tree[d],o=void 0===h,o)if(this.default)d=this.default,h=this.tree[d],s.unshift(d),u++;else if(n)return a(p,"Invalid command: "+n)}if(f.help)return this.help(!c&&!o&&d);if(f.version)return this._version();if(!c&&void 0===h)return a(p,"No command specified.");let g=this.tree[t];r.alias=Object.assign(g.alias,h.alias,r.alias),r.default=Object.assign(g.default,h.default,r.default),n=d.split(" "),l=s.indexOf(n[0],2),~l&&s.splice(l,n.length);let m=e(s.slice(u),r);if(!m||"string"==typeof m)return a(p,m||"Parsed unknown option flag(s)!");let b=h.usage.split(/\s+/),_=b.filter(e=>"<"===e.charAt(0)),v=m._.splice(0,_.length);if(v.length<_.length)return d&&(p+=" "+d),a(p,"Insufficient arguments!");b.filter(e=>"["===e.charAt(0)).forEach(e=>{v.push(m._.shift())}),v.push(m);let $=h.handler;return r.lazy?{args:v,name:d,handler:$}:$.apply(null,v)}help(e){console.log(function(e,a,o,h){let u="",f=a[o],c="$ "+e,p=a[t],d=e=>`${c} ${e}`.replace(/\s+/g," "),g=[["-h, --help","Displays this message"]];if(o===i&&g.unshift(["-v, --version","Displays current version"]),f.options=(f.options||[]).concat(p.options,g),f.options.length>0&&(f.usage+=" [options]"),u+=l("Description",f.describe,n),u+=l("Usage",[f.usage],d),h||o!==i)h||o===i||(u+=l("Aliases",f.alibi,d));else{let e,t=/^__/,i="",o=[];for(e in a)"string"==typeof a[e]||t.test(e)||o.push([e,(a[e].describe||[""])[0]])<3&&(i+=`\n ${c} ${e} --help`);u+=l("Available Commands",r(o),n),u+="\n For more info, run any command with the `--help` flag"+i+s}return u+=l("Options",r(f.options),n),u+=l("Examples",f.examples.map(d),n),u}(this.bin,this.tree,e||i,this.single))}_version(){console.log(`${this.bin}, ${this.ver}`)}}export default(e,t)=>new o(e,t);
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (https://lukeed.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.
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "sade",
|
||||
"version": "1.8.1",
|
||||
"description": "Smooth (CLI) operator 🎶",
|
||||
"repository": "lukeed/sade",
|
||||
"module": "lib/index.mjs",
|
||||
"main": "lib/index.js",
|
||||
"types": "index.d.ts",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"*.d.ts",
|
||||
"lib"
|
||||
],
|
||||
"author": {
|
||||
"name": "Luke Edwards",
|
||||
"email": "luke.edwards05@gmail.com",
|
||||
"url": "https://lukeed.com"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rollup -c",
|
||||
"test": "tape -r esm test/*.js | tap-spec"
|
||||
},
|
||||
"dependencies": {
|
||||
"mri": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"keywords": [
|
||||
"cli",
|
||||
"cli-app",
|
||||
"commander",
|
||||
"arguments",
|
||||
"parser",
|
||||
"yargs",
|
||||
"argv"
|
||||
],
|
||||
"devDependencies": {
|
||||
"esm": "3.2.25",
|
||||
"rollup": "1.32.1",
|
||||
"tap-spec": "4.1.2",
|
||||
"tape": "4.14.0",
|
||||
"terser": "4.8.0"
|
||||
}
|
||||
}
|
||||
+672
@@ -0,0 +1,672 @@
|
||||
# sade [](https://travis-ci.org/lukeed/sade)
|
||||
|
||||
> Smooth (CLI) Operator 🎶
|
||||
|
||||
Sade is a small but powerful tool for building command-line interface (CLI) applications for Node.js that are fast, responsive, and helpful!
|
||||
|
||||
It enables default commands, git-like subcommands, option flags with aliases, default option values with type-casting, required-vs-optional argument handling, command validation, and automated help text generation!
|
||||
|
||||
Your app's UX will be as smooth as butter... just like [Sade's voice](https://www.youtube.com/watch?v=4TYv2PhG89A). 😉
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save sade
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
***Input:***
|
||||
|
||||
```js
|
||||
#!/usr/bin/env node
|
||||
|
||||
const sade = require('sade');
|
||||
|
||||
const prog = sade('my-cli');
|
||||
|
||||
prog
|
||||
.version('1.0.5')
|
||||
.option('--global, -g', 'An example global flag')
|
||||
.option('-c, --config', 'Provide path to custom config', 'foo.config.js');
|
||||
|
||||
prog
|
||||
.command('build <src> <dest>')
|
||||
.describe('Build the source directory. Expects an `index.js` entry file.')
|
||||
.option('-o, --output', 'Change the name of the output file', 'bundle.js')
|
||||
.example('build src build --global --config my-conf.js')
|
||||
.example('build app public -o main.js')
|
||||
.action((src, dest, opts) => {
|
||||
console.log(`> building from ${src} to ${dest}`);
|
||||
console.log('> these are extra opts', opts);
|
||||
});
|
||||
|
||||
prog.parse(process.argv);
|
||||
```
|
||||
|
||||
***Output:***
|
||||
|
||||
```a
|
||||
$ my-cli --help
|
||||
|
||||
Usage
|
||||
$ my-cli <command> [options]
|
||||
|
||||
Available Commands
|
||||
build Build the source directory.
|
||||
|
||||
For more info, run any command with the `--help` flag
|
||||
$ my-cli build --help
|
||||
|
||||
Options
|
||||
-v, --version Displays current version
|
||||
-g, --global An example global flag
|
||||
-c, --config Provide path to custom config (default foo.config.js)
|
||||
-h, --help Displays this message
|
||||
|
||||
|
||||
$ my-cli build --help
|
||||
|
||||
Description
|
||||
Build the source directory.
|
||||
Expects an `index.js` entry file.
|
||||
|
||||
Usage
|
||||
$ my-cli build <src> [options]
|
||||
|
||||
Options
|
||||
-o, --output Change the name of the output file (default bundle.js)
|
||||
-g, --global An example global flag
|
||||
-c, --config Provide path to custom config (default foo.config.js)
|
||||
-h, --help Displays this message
|
||||
|
||||
Examples
|
||||
$ my-cli build src build --global --config my-conf.js
|
||||
$ my-cli build app public -o main.js
|
||||
```
|
||||
|
||||
## Tips
|
||||
|
||||
- **Define your global/program-wide version, options, description, and/or examples first.**<br>
|
||||
_Once you define a Command, you can't access the global-scope again._
|
||||
|
||||
- **Define all commands & options in the order that you want them to appear.**<br>
|
||||
_Sade will not mutate or sort your CLI for you. Global options print before local options._
|
||||
|
||||
- **Required arguments without values will error & exit**<br>
|
||||
_An `Insufficient arguments!` error will be displayed along with a help prompt._
|
||||
|
||||
- **Don't worry about manually displaying help~!**<br>
|
||||
_Your help text is displayed automatically... including command-specific help text!_
|
||||
|
||||
- **Automatic default/basic patterns**<br>
|
||||
_Usage text will always append `[options]` & `--help` and `--version` are done for you._
|
||||
|
||||
- **Only define what you want to display!**<br>
|
||||
_Help text sections (example, options, etc) will only display if you provide values._
|
||||
|
||||
|
||||
## Subcommands
|
||||
|
||||
Subcommands are defined & parsed like any other command! When defining their [`usage`](#usage-1), everything up until the first argument (`[foo]` or `<foo>`) is interpreted as the command string.
|
||||
|
||||
They should be defined in the order that you want them to appear in your general `--help` output.
|
||||
|
||||
Lastly, it is _not_ necessary to define the subcommand's "base" as an additional command. However, if you choose to do so, it's recommended that you define it first for better visibility.
|
||||
|
||||
```js
|
||||
const prog = sade('git');
|
||||
|
||||
// Not necessary for subcommands to work, but it's here anyway!
|
||||
prog
|
||||
.command('remote')
|
||||
.describe('Manage set of tracked repositories')
|
||||
.action(opts => {
|
||||
console.log('~> Print current remotes...');
|
||||
});
|
||||
|
||||
prog
|
||||
.command('remote add <name> <url>', 'Demo...')
|
||||
.action((name, url, opts) => {
|
||||
console.log(`~> Adding a new remote (${name}) to ${url}`);
|
||||
});
|
||||
|
||||
prog
|
||||
.command('remote rename <old> <new>', 'Demo...')
|
||||
.action((old, nxt, opts) => {
|
||||
console.log(`~> Renaming from ${old} to ${nxt}~!`);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Single Command Mode
|
||||
|
||||
In certain circumstances, you may only need `sade` for a single-command CLI application.
|
||||
|
||||
> **Note:** Until `v1.6.0`, this made for an awkward pairing.
|
||||
|
||||
To enable this, you may make use of the [`isSingle`](#issingle) argument. Doing so allows you to pass the program's entire [`usage` text](#usage-1) into the `name` argument.
|
||||
|
||||
With "Single Command Mode" enabled, your entire binary operates as one command. This means that any [`prog.command`](#progcommandusage-desc-opts) calls are disallowed & will instead throw an Error. Of course, you may still define a program version, a description, an example or two, and declare options. You are customizing the program's attributes as a whole.<sup>*</sup>
|
||||
|
||||
> <sup>*</sup> This is true for multi-command applications, too, up until your first `prog.command()` call!
|
||||
|
||||
***Example***
|
||||
|
||||
Let's reconstruct [`sirv-cli`](https://github.com/lukeed/sirv), which is a single-command application that (optionally) accepts a directory from which to serve files. It also offers a slew of option flags:
|
||||
|
||||
```js
|
||||
sade('sirv [dir]', true)
|
||||
.version('1.0.0')
|
||||
.describe('Run a static file server')
|
||||
.example('public -qeim 31536000')
|
||||
.example('--port 8080 --etag')
|
||||
.example('my-app --dev')
|
||||
.option('-D, --dev', 'Enable "dev" mode')
|
||||
.option('-e, --etag', 'Enable "Etag" header')
|
||||
// There are a lot...
|
||||
.option('-H, --host', 'Hostname to bind', 'localhost')
|
||||
.option('-p, --port', 'Port to bind', 5000)
|
||||
.action((dir, opts) => {
|
||||
// Program handler
|
||||
})
|
||||
.parse(process.argv);
|
||||
```
|
||||
|
||||
When `sirv --help` is run, the generated help text is trimmed, fully aware that there's only one command in this program:
|
||||
|
||||
```
|
||||
Description
|
||||
Run a static file server
|
||||
|
||||
Usage
|
||||
$ sirv [dir] [options]
|
||||
|
||||
Options
|
||||
-D, --dev Enable "dev" mode
|
||||
-e, --etag Enable "Etag" header
|
||||
-H, --host Hostname to bind (default localhost)
|
||||
-p, --port Port to bind (default 5000)
|
||||
-v, --version Displays current version
|
||||
-h, --help Displays this message
|
||||
|
||||
Examples
|
||||
$ sirv public -qeim 31536000
|
||||
$ sirv --port 8080 --etag
|
||||
$ sirv my-app --dev
|
||||
```
|
||||
|
||||
## Command Aliases
|
||||
|
||||
Command aliases are alternative names (aliases) for a command. They are often used as shortcuts or as typo relief!
|
||||
|
||||
The aliased names do not appear in the general help text.<br>
|
||||
Instead, they only appear within the Command-specific help text under an "Aliases" section.
|
||||
|
||||
***Limitations***
|
||||
|
||||
* You cannot assign aliases while in [Single Command Mode](#single-command-mode)
|
||||
* You cannot call [`prog.alias()`](#progaliasnames) before defining any Commands (via `prog.commmand()`)
|
||||
* You, the developer, must keep track of which aliases have already been used and/or exist as Command names
|
||||
|
||||
***Example***
|
||||
|
||||
Let's reconstruct the `npm install` command as a Sade program:
|
||||
|
||||
```js
|
||||
sade('npm')
|
||||
// ...
|
||||
.command('install [package]', 'Install a package', {
|
||||
alias: ['i', 'add', 'isntall']
|
||||
})
|
||||
.option('-P, --save-prod', 'Package will appear in your dependencies.')
|
||||
.option('-D, --save-dev', 'Package will appear in your devDependencies.')
|
||||
.option('-O, --save-optional', 'Package will appear in your optionalDependencies')
|
||||
.option('-E, --save-exact', 'Save exact versions instead of using a semver range operator')
|
||||
// ...
|
||||
```
|
||||
|
||||
When we run `npm --help` we'll see this general help text:
|
||||
|
||||
```
|
||||
Usage
|
||||
$ npm <command> [options]
|
||||
|
||||
Available Commands
|
||||
install Install a package
|
||||
|
||||
For more info, run any command with the `--help` flag
|
||||
$ npm install --help
|
||||
|
||||
Options
|
||||
-v, --version Displays current version
|
||||
-h, --help Displays this message
|
||||
```
|
||||
|
||||
When we run `npm install --help` — ***or*** the help flag with any of `install`'s aliases — we'll see this command-specific help text:
|
||||
|
||||
```
|
||||
Description
|
||||
Install a package
|
||||
|
||||
Usage
|
||||
$ npm install [package] [options]
|
||||
|
||||
Aliases
|
||||
$ npm i
|
||||
$ npm add
|
||||
$ npm isntall
|
||||
|
||||
Options
|
||||
-P, --save-prod Package will appear in your dependencies.
|
||||
-D, --save-dev Package will appear in your devDependencies.
|
||||
-O, --save-optional Package will appear in your optionalDependencies
|
||||
-E, --save-exact Save exact versions instead of using a semver range operator
|
||||
-h, --help Displays this message
|
||||
```
|
||||
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### sade(name, isSingle)
|
||||
Returns: `Program`
|
||||
|
||||
Returns your chainable Sade instance, aka your `Program`.
|
||||
|
||||
#### name
|
||||
Type: `String`<br>
|
||||
Required: `true`
|
||||
|
||||
The name of your `Program` / binary application.
|
||||
|
||||
#### isSingle
|
||||
Type: `Boolean`<br>
|
||||
Default: `name.includes(' ');`
|
||||
|
||||
If your `Program` is meant to have ***only one command***.<br>
|
||||
When `true`, this simplifies your generated `--help` output such that:
|
||||
|
||||
* the "root-level help" is your _only_ help text
|
||||
* the "root-level help" does not display an `Available Commands` section
|
||||
* the "root-level help" does not inject `$ name <command>` into the `Usage` section
|
||||
* the "root-level help" does not display `For more info, run any command with the `--help` flag` text
|
||||
|
||||
You may customize the `Usage` of your command by modifying the `name` argument directly.<br>
|
||||
Please read [Single Command Mode](#single-command-mode) for an example and more information.
|
||||
|
||||
> **Important:** Whenever `name` includes a custom usage, then `isSingle` is automatically assumed and enforced!
|
||||
|
||||
### prog.command(usage, desc, opts)
|
||||
|
||||
Create a new Command for your Program. This changes the current state of your Program.
|
||||
|
||||
All configuration methods (`prog.describe`, `prog.action`, etc) will apply to this Command until another Command has been created!
|
||||
|
||||
#### usage
|
||||
|
||||
Type: `String`
|
||||
|
||||
The usage pattern for your current Command. This will be included in the general or command-specific `--help` output.
|
||||
|
||||
_Required_ arguments are wrapped with `<` and `>` characters; for example, `<foo>` and `<bar>`.
|
||||
|
||||
_Optional_ arguments are wrapped with `[` and `]` characters; for example, `[foo]` and `[bar]`.
|
||||
|
||||
All arguments are ***positionally important***, which means they are passed to your current Command's [`handler`](#handler) function in the order that they were defined.
|
||||
|
||||
When optional arguments are defined but don't receive a value, their positionally-equivalent function parameter will be `undefined`.
|
||||
|
||||
> **Important:** You **must** define & expect required arguments _before_ optional arguments!
|
||||
|
||||
```js
|
||||
sade('foo')
|
||||
|
||||
.command('greet <adjective> <noun>')
|
||||
.action((adjective, noun, opts) => {
|
||||
console.log(`Hello, ${adjective} ${noun}!`);
|
||||
})
|
||||
|
||||
.command('drive <vehicle> [color] [speed]')
|
||||
.action((vehicle, color, speed, opts) => {
|
||||
let arr = ['Driving my'];
|
||||
arr.push(color ? `${color} ${vehicle}` : vehicle);
|
||||
speed && arr.push(`at ${speed}`);
|
||||
opts.yolo && arr.push('...YOLO!!');
|
||||
let str = arr.join(' ');
|
||||
console.log(str);
|
||||
});
|
||||
```
|
||||
|
||||
```sh
|
||||
$ foo greet beautiful person
|
||||
# //=> Hello, beautiful person!
|
||||
|
||||
$ foo drive car
|
||||
# //=> Driving my car
|
||||
|
||||
$ foo drive car red
|
||||
# //=> Driving my red card
|
||||
|
||||
$ foo drive car blue 100mph --yolo
|
||||
# //=> Driving my blue car at 100mph ...YOLO!!
|
||||
```
|
||||
|
||||
|
||||
#### desc
|
||||
|
||||
Type: `String`<br>
|
||||
Default: `''`
|
||||
|
||||
The Command's description. The value is passed directly to [`prog.describe`](#progdescribetext).
|
||||
|
||||
#### opts
|
||||
|
||||
Type: `Object`<br>
|
||||
Default: `{}`
|
||||
|
||||
##### opts.alias
|
||||
Type: `String|Array`
|
||||
|
||||
Optionally define one or more aliases for the current Command.<br>
|
||||
When declared, the `opts.alias` value is passed _directly_ to the [`prog.alias`](#progaliasnames) method.
|
||||
|
||||
```js
|
||||
// Program A is equivalent to Program B
|
||||
// ---
|
||||
|
||||
const A = sade('bin')
|
||||
.command('build', 'My build command', { alias: 'b' })
|
||||
.command('watch', 'My watch command', { alias: ['w', 'dev'] });
|
||||
|
||||
const B = sade('bin')
|
||||
.command('build', 'My build command').alias('b')
|
||||
.command('watch', 'My watch command').alias('w', 'dev');
|
||||
```
|
||||
|
||||
|
||||
##### opts.default
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Manually set/force the current Command to be the Program's default command. This ensures that the current Command will run if no command was specified.
|
||||
|
||||
> **Important:** If you run your Program without a Command _and_ without specifying a default command, your Program will exit with a `No command specified` error.
|
||||
|
||||
```js
|
||||
const prog = sade('greet');
|
||||
|
||||
prog.command('hello');
|
||||
//=> only runs if :: `$ greet hello`
|
||||
|
||||
// $ greet
|
||||
//=> error: No command specified.
|
||||
|
||||
prog.command('howdy', '', { default:true });
|
||||
//=> runs as `$ greet` OR `$ greet howdy`
|
||||
|
||||
// $ greet
|
||||
//=> runs 'howdy' handler
|
||||
|
||||
// $ greet foobar
|
||||
//=> error: Invalid command
|
||||
```
|
||||
|
||||
|
||||
### prog.describe(text)
|
||||
|
||||
Add a description to the current Command.
|
||||
|
||||
#### text
|
||||
|
||||
Type: `String|Array`
|
||||
|
||||
The description text for the current Command. This will be included in the general or command-specific `--help` output.
|
||||
|
||||
Internally, your description will be separated into an `Array` of sentences.
|
||||
|
||||
For general `--help` output, ***only*** the first sentence will be displayed. However, **all sentences** will be printed for command-specific `--help` text.
|
||||
|
||||
> **Note:** Pass an `Array` if you don't want internal assumptions. However, the first item is _always_ displayed in general help, so it's recommended to keep it short.
|
||||
|
||||
|
||||
### prog.alias(...names)
|
||||
|
||||
Define one or more aliases for the current Command.
|
||||
|
||||
> **Important:** An error will be thrown if:<br>1) the program is in [Single Command Mode](#single-command-mode); or<br>2) `prog.alias` is called before any `prog.command`.
|
||||
|
||||
#### names
|
||||
|
||||
Type: `String`
|
||||
|
||||
The list of alternative names (aliases) for the current Command.<br>
|
||||
For example, you may want to define shortcuts and/or common typos for the Command's full name.
|
||||
|
||||
> **Important:** Sade _does not_ check if the incoming `names` are already in use by other Commands or their aliases.<br>During conflicts, the Command with the same `name` is given priority, otherwise the first Command (according to Program order) with `name` as an alias is chosen.
|
||||
|
||||
The `prog.alias()` is append-only, so calling it multiple times within a Command context will _keep_ all aliases, including those initially passed via [`opts.alias`](#optsdefault).
|
||||
|
||||
```js
|
||||
sade('bin')
|
||||
.command('hello <name>', 'Greet someone by their name', {
|
||||
alias: ['hey', 'yo']
|
||||
})
|
||||
.alias('hi', 'howdy')
|
||||
.alias('hola', 'oi');
|
||||
//=> hello aliases: hey, yo, hi, howdy, hola, oi
|
||||
```
|
||||
|
||||
|
||||
### prog.action(handler)
|
||||
|
||||
Attach a callback to the current Command.
|
||||
|
||||
#### handler
|
||||
|
||||
Type: `Function`
|
||||
|
||||
The function to run when the current Command is executed.
|
||||
|
||||
Its parameters are based (positionally) on your Command's [`usage`](#usage-1) definition.
|
||||
|
||||
All options, flags, and extra/unknown values are included as the last parameter.
|
||||
|
||||
> **Note:** Optional arguments are also passed as parameters & may be `undefined`!
|
||||
|
||||
```js
|
||||
sade('foo')
|
||||
.command('cp <src> <dest>')
|
||||
.option('-f, --force', 'Overwrite without confirmation')
|
||||
.option('-c, --clone-dir', 'Copy files to additional directory')
|
||||
.option('-v, --verbose', 'Enable verbose output')
|
||||
.action((src, dest, opts) => {
|
||||
console.log(`Copying files from ${src} --> ${dest}`);
|
||||
opts.c && console.log(`ALSO copying files from ${src} --> ${opts['clone-dir']}`);
|
||||
console.log('My options:', opts);
|
||||
})
|
||||
|
||||
// $ foo cp original my-copy -v
|
||||
//=> Copying files from original --> my-copy
|
||||
//=> My options: { _:[], v:true, verbose:true }
|
||||
|
||||
// $ foo cp original my-copy --clone-dir my-backup
|
||||
//=> Copying files from original --> my-copy
|
||||
//=> ALSO copying files from original --> my-backup
|
||||
//=> My options: { _:[], c:'my-backup', 'clone-dir':'my-backup' }
|
||||
```
|
||||
|
||||
|
||||
### prog.example(str)
|
||||
|
||||
Add an example for the current Command.
|
||||
|
||||
#### str
|
||||
|
||||
Type: `String`
|
||||
|
||||
The example string to add. This will be included in the general or command-specific `--help` output.
|
||||
|
||||
> **Note:** Your example's `str` will be prefixed with your Program's [`name`](#sadename).
|
||||
|
||||
|
||||
### prog.option(flags, desc, value)
|
||||
|
||||
Add an Option to the current Command.
|
||||
|
||||
#### flags
|
||||
|
||||
Type: `String`
|
||||
|
||||
The Option's flags, which may optionally include an alias.
|
||||
|
||||
You may use a comma (`,`) or a space (` `) to separate the flags.
|
||||
|
||||
> **Note:** The short & long flags can be declared in any order. However, the alias will always be displayed first.
|
||||
|
||||
> **Important:** If using hyphenated flag names, they will be accessible **as declared** within your [`action()`](#progactionhandler) handler!
|
||||
|
||||
```js
|
||||
prog.option('--global'); // no alias
|
||||
prog.option('-g, --global'); // alias first, comma
|
||||
prog.option('--global -g'); // alias last, space
|
||||
// etc...
|
||||
```
|
||||
|
||||
#### desc
|
||||
|
||||
Type: `String`
|
||||
|
||||
The description for the Option.
|
||||
|
||||
#### value
|
||||
|
||||
Type: `String`
|
||||
|
||||
The **default** value for the Option.
|
||||
|
||||
Flags and aliases, if parsed, are `true` by default. See [`mri`](https://github.com/lukeed/mri#minimist) for more info.
|
||||
|
||||
> **Note:** You probably only want to define a default `value` if you're expecting a `String` or `Number` value type.
|
||||
|
||||
If you _do_ pass a `String` or `Number` value type, your flag value will be casted to the same type. See [`mri#options.default`](https://github.com/lukeed/mri#optionsdefault) for info~!
|
||||
|
||||
|
||||
### prog.version(str)
|
||||
|
||||
The `--version` and `-v` flags will automatically output the Program version.
|
||||
|
||||
#### str
|
||||
|
||||
Type: `String`<br>
|
||||
Default: `0.0.0`
|
||||
|
||||
The new version number for your Program.
|
||||
|
||||
> **Note:** Your Program `version` is `0.0.0` until you change it.
|
||||
|
||||
### prog.parse(arr, opts)
|
||||
|
||||
Parse a set of CLI arguments.
|
||||
|
||||
#### arr
|
||||
|
||||
Type: `Array`
|
||||
|
||||
Your Program's `process.argv` input.
|
||||
|
||||
> **Important:** Do not `.slice(2)`! Doing so will break parsing~!
|
||||
|
||||
#### opts
|
||||
|
||||
Type: `Object`<br>
|
||||
Default: `{}`
|
||||
|
||||
Additional `process.argv` parsing config. See [`mri`'s options](https://github.com/lukeed/mri#mriargs-options) for details.
|
||||
|
||||
> **Important:** These values _override_ any internal values!
|
||||
|
||||
```js
|
||||
prog
|
||||
.command('hello')
|
||||
.option('-f, --force', 'My flag');
|
||||
//=> currently has alias pair: f <--> force
|
||||
|
||||
prog.parse(process.argv, {
|
||||
alias: {
|
||||
f: ['foo', 'fizz']
|
||||
},
|
||||
default: {
|
||||
abc: 123
|
||||
}
|
||||
});
|
||||
//=> ADDS alias pair: f <--> foo
|
||||
//=> REMOVES alias pair: f <--> force
|
||||
//=> ADDS alias pair: f <--> fizz
|
||||
//=> ADDS default: abc -> 123 (number)
|
||||
```
|
||||
|
||||
#### opts.unknown
|
||||
|
||||
Type: `Function`<br>
|
||||
Default: `undefined`
|
||||
|
||||
Callback to run when an unspecified option flag has been found. This is [passed directly to `mri`](https://github.com/lukeed/mri#optionsunknown).
|
||||
|
||||
Your handler will receive the unknown flag (string) as its only argument.<br>
|
||||
You may return a string, which will be used as a custom error message. Otherwise, a default message is displayed.
|
||||
|
||||
```js
|
||||
sade('sirv')
|
||||
.command('start [dir]')
|
||||
.parse(process.argv, {
|
||||
unknown: arg => `Custom error message: ${arg}`
|
||||
});
|
||||
|
||||
/*
|
||||
$ sirv start --foobar
|
||||
|
||||
ERROR
|
||||
Custom error message: --foobar
|
||||
|
||||
Run `$ sirv --help` for more info.
|
||||
*/
|
||||
```
|
||||
|
||||
#### opts.lazy
|
||||
|
||||
Type: `Boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
If true, Sade will not immediately execute the `action` handler. Instead, `parse()` will return an object of `{ name, args, handler }` shape, wherein the `name` is the command name, `args` is all arguments that _would be_ passed to the action handler, and `handler` is the function itself.
|
||||
|
||||
From this, you may choose when to run the `handler` function. You also have the option to further modify the `args` for any reason, if needed.
|
||||
|
||||
```js
|
||||
let { name, args, handler } = prog.parse(process.argv, { lazy:true });
|
||||
console.log('> Received command: ', name);
|
||||
|
||||
// later on...
|
||||
handler.apply(null, args);
|
||||
```
|
||||
|
||||
### prog.help(cmd)
|
||||
|
||||
Manually display the help text for a given command. If no command name is provided, the general/global help is printed.
|
||||
|
||||
Your general and command-specific help text is automatically attached to the `--help` and `-h` flags.
|
||||
|
||||
> **Note:** You don't have to call this directly! It's automatically run when you `bin --help`
|
||||
|
||||
#### cmd
|
||||
Type: `String`<br>
|
||||
Default: `null`
|
||||
|
||||
The name of the command for which to display help. Otherwise displays the general help.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Luke Edwards](https://lukeed.com)
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2020-Present [these people](https://github.com/sveltejs/language-tools/graphs/contributors)
|
||||
|
||||
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.
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
# Check your code with svelte-check
|
||||
|
||||
Provides CLI diagnostics checks for:
|
||||
|
||||
- Unused CSS
|
||||
- Svelte A11y hints
|
||||
- JavaScript/TypeScript compiler errors
|
||||
|
||||
Requires Node 16 or later.
|
||||
|
||||
### Usage:
|
||||
|
||||
#### Local / in your project
|
||||
|
||||
Installation:
|
||||
|
||||
`npm i svelte-check --save-dev`
|
||||
|
||||
Package.json:
|
||||
|
||||
```json
|
||||
{
|
||||
// ...
|
||||
"scripts": {
|
||||
"svelte-check": "svelte-check"
|
||||
// ...
|
||||
},
|
||||
// ...
|
||||
"devDependencies": {
|
||||
"svelte-check": "..."
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Usage:
|
||||
|
||||
`npm run svelte-check`
|
||||
|
||||
#### Global (not recommended)
|
||||
|
||||
Installation:
|
||||
|
||||
`npm i svelte-check svelte -g`
|
||||
|
||||
Usage:
|
||||
|
||||
1. Go to folder where to start checking
|
||||
2. `svelte-check`
|
||||
|
||||
### Args:
|
||||
|
||||
| Flag | Description |
|
||||
| --------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `--workspace <path>` | Path to your workspace. All subdirectories except node_modules and those listed in `--ignore` are checked |
|
||||
| `--output <human\|human-verbose\|machine\|machine-verbose>` |
|
||||
| `--watch` | Will not exit after one pass but keep watching files for changes and rerun diagnostics |
|
||||
| `--preserveWatchOutput` | Do not clear the screen in watch mode |
|
||||
| `--tsconfig <path>` | Pass a path to a tsconfig or jsconfig file. The path can be relative to the workspace path or absolute. Doing this means that only files matched by the files/include/exclude pattern of the config file are diagnosed. It also means that errors from TypeScript and JavaScript files are reported. If not given, will do an upwards traversal looking for the next jsconfig/tsconfig.json |
|
||||
| `--no-tsconfig` | Use this if you only want to check the Svelte files found in the current directory and below and ignore any JS/TS files (they will not be type-checked) |
|
||||
| `--ignore <path1,path2>` | Can only be used in conjunction with `--no-tsconfig`. Files/folders to ignore - relative to workspace root, comma-separated, inside quotes. Example: `--ignore "dist,build"`. |
|
||||
| `--fail-on-warnings` | Will also exit with error code when there are warnings |
|
||||
| `--compiler-warnings <code1:error\|ignore,code2:error\|ignore>` | A list of Svelte compiler warning codes. Each entry defines whether that warning should be ignored or treated as an error. Warnings are comma-separated, between warning code and error level is a colon; all inside quotes. Example: `--compiler-warnings "css-unused-selector:ignore,unused-export-let:error"` |
|
||||
| `--diagnostic-sources <js,svelte,css>` | A list of diagnostic sources which should run diagnostics on your code. Possible values are `js` (includes TS), `svelte`, `css`. Comma-separated, inside quotes. By default all are active. Example: `--diagnostic-sources "js,svelte"` |
|
||||
| `--threshold <error\|warning>` | Filters the diagnostics to display. `error` will output only errors while `warning` will output warnings and errors. |
|
||||
| `--incremental` | Opts into TypeScript's incremental build cache, which speeds up subsequent runs. Saved within `.svelte-kit` or if not available within `.svelte-check`. This might result in slightly different type check outcomes, and certain patterns are not supported. Specifically, anything that is not in the root dir of your tsconfig.json and is a Svelte file will not be properly loaded and type-checked. |
|
||||
| `--tsgo` | Use TypeScript's Go implementation. Needs to have `@typescript/native-preview` installed. Subject to the same limitations as `--incremental` |
|
||||
|
||||
### FAQ
|
||||
|
||||
#### Why is there no option to only check specific files (for example only staged files)?
|
||||
|
||||
`svelte-check` needs to know the whole project to do valid checks. Imagine you alter a component property `export let foo` to `export let bar`, but you don't update any of the component usages. They all have errors now but you would not catch them if you only run checks on changed files.
|
||||
|
||||
### More docs, preprocessor setup and troubleshooting
|
||||
|
||||
[See here](/docs/README.md).
|
||||
|
||||
### Machine-Readable Output
|
||||
|
||||
Setting the `--output` to `machine` or `machine-verbose` will format output in a way that is easier to read
|
||||
by machines, e.g. inside CI pipelines, for code quality checks, etc.
|
||||
|
||||
Each row corresponds to a new record. Rows are made up of columns that are separated by a
|
||||
single space character. The first column of every row contains a timestamp in milliseconds
|
||||
which can be used for monitoring purposes. The second column gives us the "row type", based
|
||||
on which the number and types of subsequent columns may differ.
|
||||
|
||||
The first row is of type `START` and contains the workspace folder (wrapped in quotes).
|
||||
|
||||
###### Example:
|
||||
|
||||
```
|
||||
1590680325583 START "/home/user/language-tools/packages/language-server/test/plugins/typescript/testfiles"
|
||||
```
|
||||
|
||||
Any number of `ERROR` or `WARNING` records may follow. Their structure is identical and depends on the output argoument.
|
||||
|
||||
If the argument is `machine` it will tell us the filename, the starting line and column numbers, and the error message. The filename is relative to the workspace directory. The filename and the message are both wrapped in quotes.
|
||||
|
||||
###### Example:
|
||||
|
||||
```
|
||||
1590680326283 ERROR "codeactions.svelte" 1:16 "Cannot find module 'blubb' or its corresponding type declarations."
|
||||
1590680326778 WARNING "imported-file.svelte" 0:37 "Component has unused export property 'prop'. If it is for external reference only, please consider using `export const prop`"
|
||||
```
|
||||
|
||||
If the argument is `machine-verbose` it will tell us the filename, the starting line and column numbers, the ending line and column numbers, the error message, the code of diagnostic, the human-friendly description of the code and the human-friendly source of the diagnostic (eg. svelte/typescript). The filename is relative to the workspace directory. Each diagnostic is represented as an [ndjson](https://en.wikipedia.org/wiki/JSON_streaming#Newline-Delimited_JSON) line prefixed by the timestamp of the log.
|
||||
|
||||
###### Example:
|
||||
|
||||
```
|
||||
1590680326283 {"type":"ERROR","fn":"codeaction.svelte","start":{"line":1,"character":16},"end":{"line":1,"character":23},"message":"Cannot find module 'blubb' or its corresponding type declarations.","code":2307,"source":"js"}
|
||||
1590680326778 {"type":"WARNING","filename":"imported-file.svelte","start":{"line":0,"character":37},"end":{"line":0,"character":51},"message":"Component has unused export property 'prop'. If it is for external reference only, please consider using `export
|
||||
const prop`","code":"unused-export-let","source":"svelte"}
|
||||
```
|
||||
|
||||
The output concludes with a `COMPLETED` message that summarizes total numbers of files, errors and warnings that were encountered during the check.
|
||||
|
||||
###### Example:
|
||||
|
||||
```
|
||||
1590680326807 COMPLETED 20 FILES 21 ERRORS 1 WARNINGS 3 FILES_WITH_PROBLEMS
|
||||
```
|
||||
|
||||
If the application experiences a runtime error, this error will appear as a `FAILURE` record.
|
||||
|
||||
###### Example:
|
||||
|
||||
```
|
||||
1590680328921 FAILURE "Connection closed"
|
||||
```
|
||||
|
||||
### Credits
|
||||
|
||||
- Vue's [VTI](https://github.com/vuejs/vetur/tree/master/vti) which laid the foundation for `svelte-check`
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
require('../dist/src/index.js');
|
||||
+134797
File diff suppressed because one or more lines are too long
+230
@@ -0,0 +1,230 @@
|
||||
/// <reference lib="dom" />
|
||||
|
||||
declare namespace svelteHTML {
|
||||
|
||||
// Every namespace eligible for use needs to implement the following two functions
|
||||
/**
|
||||
* @internal do not use
|
||||
*/
|
||||
function mapElementTag<K extends keyof ElementTagNameMap>(
|
||||
tag: K
|
||||
): ElementTagNameMap[K];
|
||||
function mapElementTag<K extends keyof SVGElementTagNameMap>(
|
||||
tag: K
|
||||
): SVGElementTagNameMap[K];
|
||||
function mapElementTag(
|
||||
tag: any
|
||||
): any; // needs to be any because used in context of <svelte:element>
|
||||
|
||||
/**
|
||||
* @internal do not use
|
||||
*/
|
||||
function createElement<Elements extends IntrinsicElements, Key extends keyof Elements>(
|
||||
// "undefined | null" because of <svelte:element>
|
||||
element: Key | undefined | null, attrs: string extends Key ? import('svelte/elements').HTMLAttributes<any> : Elements[Key]
|
||||
): Key extends keyof ElementTagNameMap ? ElementTagNameMap[Key] : Key extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[Key] : any;
|
||||
function createElement<Elements extends IntrinsicElements, Key extends keyof Elements, T>(
|
||||
// "undefined | null" because of <svelte:element>
|
||||
element: Key | undefined | null, attrsEnhancers: T, attrs: (string extends Key ? import('svelte/elements').HTMLAttributes<any> : Elements[Key]) & T
|
||||
): Key extends keyof ElementTagNameMap ? ElementTagNameMap[Key] : Key extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[Key] : any;
|
||||
|
||||
// For backwards-compatibility and ease-of-use, in case someone enhanced the typings from import('svelte/elements').HTMLAttributes/SVGAttributes
|
||||
interface HTMLAttributes<T extends EventTarget = any> {}
|
||||
interface SVGAttributes<T extends EventTarget = any> {}
|
||||
|
||||
/**
|
||||
* @internal do not use
|
||||
*/
|
||||
type HTMLProps<Property extends string, Override> =
|
||||
Omit<import('svelte/elements').SvelteHTMLElements[Property], keyof Override> & Override;
|
||||
|
||||
interface IntrinsicElements {
|
||||
a: HTMLProps<'a', HTMLAttributes>;
|
||||
abbr: HTMLProps<'abbr', HTMLAttributes>;
|
||||
address: HTMLProps<'address', HTMLAttributes>;
|
||||
area: HTMLProps<'area', HTMLAttributes>;
|
||||
article: HTMLProps<'article', HTMLAttributes>;
|
||||
aside: HTMLProps<'aside', HTMLAttributes>;
|
||||
audio: HTMLProps<'audio', HTMLAttributes>;
|
||||
b: HTMLProps<'b', HTMLAttributes>;
|
||||
base: HTMLProps<'base', HTMLAttributes>;
|
||||
bdi: HTMLProps<'bdi', HTMLAttributes>;
|
||||
bdo: HTMLProps<'bdo', HTMLAttributes>;
|
||||
big: HTMLProps<'big', HTMLAttributes>;
|
||||
blockquote: HTMLProps<'blockquote', HTMLAttributes>;
|
||||
body: HTMLProps<'body', HTMLAttributes>;
|
||||
br: HTMLProps<'br', HTMLAttributes>;
|
||||
button: HTMLProps<'button', HTMLAttributes>;
|
||||
canvas: HTMLProps<'canvas', HTMLAttributes>;
|
||||
caption: HTMLProps<'caption', HTMLAttributes>;
|
||||
cite: HTMLProps<'cite', HTMLAttributes>;
|
||||
code: HTMLProps<'code', HTMLAttributes>;
|
||||
col: HTMLProps<'col', HTMLAttributes>;
|
||||
colgroup: HTMLProps<'colgroup', HTMLAttributes>;
|
||||
data: HTMLProps<'data', HTMLAttributes>;
|
||||
datalist: HTMLProps<'datalist', HTMLAttributes>;
|
||||
dd: HTMLProps<'dd', HTMLAttributes>;
|
||||
del: HTMLProps<'del', HTMLAttributes>;
|
||||
details: HTMLProps<'details', HTMLAttributes>;
|
||||
dfn: HTMLProps<'dfn', HTMLAttributes>;
|
||||
dialog: HTMLProps<'dialog', HTMLAttributes>;
|
||||
div: HTMLProps<'div', HTMLAttributes>;
|
||||
dl: HTMLProps<'dl', HTMLAttributes>;
|
||||
dt: HTMLProps<'dt', HTMLAttributes>;
|
||||
em: HTMLProps<'em', HTMLAttributes>;
|
||||
embed: HTMLProps<'embed', HTMLAttributes>;
|
||||
fieldset: HTMLProps<'fieldset', HTMLAttributes>;
|
||||
figcaption: HTMLProps<'figcaption', HTMLAttributes>;
|
||||
figure: HTMLProps<'figure', HTMLAttributes>;
|
||||
footer: HTMLProps<'footer', HTMLAttributes>;
|
||||
form: HTMLProps<'form', HTMLAttributes>;
|
||||
h1: HTMLProps<'h1', HTMLAttributes>;
|
||||
h2: HTMLProps<'h2', HTMLAttributes>;
|
||||
h3: HTMLProps<'h3', HTMLAttributes>;
|
||||
h4: HTMLProps<'h4', HTMLAttributes>;
|
||||
h5: HTMLProps<'h5', HTMLAttributes>;
|
||||
h6: HTMLProps<'h6', HTMLAttributes>;
|
||||
head: HTMLProps<'head', HTMLAttributes>;
|
||||
header: HTMLProps<'header', HTMLAttributes>;
|
||||
hgroup: HTMLProps<'hgroup', HTMLAttributes>;
|
||||
hr: HTMLProps<'hr', HTMLAttributes>;
|
||||
html: HTMLProps<'html', HTMLAttributes>;
|
||||
i: HTMLProps<'i', HTMLAttributes>;
|
||||
iframe: HTMLProps<'iframe', HTMLAttributes>;
|
||||
img: HTMLProps<'img', HTMLAttributes>;
|
||||
input: HTMLProps<'input', HTMLAttributes>;
|
||||
ins: HTMLProps<'ins', HTMLAttributes>;
|
||||
kbd: HTMLProps<'kbd', HTMLAttributes>;
|
||||
keygen: HTMLProps<'keygen', HTMLAttributes>;
|
||||
label: HTMLProps<'label', HTMLAttributes>;
|
||||
legend: HTMLProps<'legend', HTMLAttributes>;
|
||||
li: HTMLProps<'li', HTMLAttributes>;
|
||||
link: HTMLProps<'link', HTMLAttributes>;
|
||||
main: HTMLProps<'main', HTMLAttributes>;
|
||||
map: HTMLProps<'map', HTMLAttributes>;
|
||||
mark: HTMLProps<'mark', HTMLAttributes>;
|
||||
menu: HTMLProps<'menu', HTMLAttributes>;
|
||||
menuitem: HTMLProps<'menuitem', HTMLAttributes>;
|
||||
meta: HTMLProps<'meta', HTMLAttributes>;
|
||||
meter: HTMLProps<'meter', HTMLAttributes>;
|
||||
nav: HTMLProps<'nav', HTMLAttributes>;
|
||||
noscript: HTMLProps<'noscript', HTMLAttributes>;
|
||||
object: HTMLProps<'object', HTMLAttributes>;
|
||||
ol: HTMLProps<'ol', HTMLAttributes>;
|
||||
optgroup: HTMLProps<'optgroup', HTMLAttributes>;
|
||||
option: HTMLProps<'option', HTMLAttributes>;
|
||||
output: HTMLProps<'output', HTMLAttributes>;
|
||||
p: HTMLProps<'p', HTMLAttributes>;
|
||||
param: HTMLProps<'param', HTMLAttributes>;
|
||||
picture: HTMLProps<'picture', HTMLAttributes>;
|
||||
pre: HTMLProps<'pre', HTMLAttributes>;
|
||||
progress: HTMLProps<'progress', HTMLAttributes>;
|
||||
q: HTMLProps<'q', HTMLAttributes>;
|
||||
rp: HTMLProps<'rp', HTMLAttributes>;
|
||||
rt: HTMLProps<'rt', HTMLAttributes>;
|
||||
ruby: HTMLProps<'ruby', HTMLAttributes>;
|
||||
s: HTMLProps<'s', HTMLAttributes>;
|
||||
samp: HTMLProps<'samp', HTMLAttributes>;
|
||||
slot: HTMLProps<'slot', HTMLAttributes>;
|
||||
script: HTMLProps<'script', HTMLAttributes>;
|
||||
section: HTMLProps<'section', HTMLAttributes>;
|
||||
select: HTMLProps<'select', HTMLAttributes>;
|
||||
small: HTMLProps<'small', HTMLAttributes>;
|
||||
source: HTMLProps<'source', HTMLAttributes>;
|
||||
span: HTMLProps<'span', HTMLAttributes>;
|
||||
strong: HTMLProps<'strong', HTMLAttributes>;
|
||||
style: HTMLProps<'style', HTMLAttributes>;
|
||||
sub: HTMLProps<'sub', HTMLAttributes>;
|
||||
summary: HTMLProps<'summary', HTMLAttributes>;
|
||||
sup: HTMLProps<'sup', HTMLAttributes>;
|
||||
table: HTMLProps<'table', HTMLAttributes>;
|
||||
template: HTMLProps<'template', HTMLAttributes>;
|
||||
tbody: HTMLProps<'tbody', HTMLAttributes>;
|
||||
td: HTMLProps<'td', HTMLAttributes>;
|
||||
textarea: HTMLProps<'textarea', HTMLAttributes>;
|
||||
tfoot: HTMLProps<'tfoot', HTMLAttributes>;
|
||||
th: HTMLProps<'th', HTMLAttributes>;
|
||||
thead: HTMLProps<'thead', HTMLAttributes>;
|
||||
time: HTMLProps<'time', HTMLAttributes>;
|
||||
title: HTMLProps<'title', HTMLAttributes>;
|
||||
tr: HTMLProps<'tr', HTMLAttributes>;
|
||||
track: HTMLProps<'track', HTMLAttributes>;
|
||||
u: HTMLProps<'u', HTMLAttributes>;
|
||||
ul: HTMLProps<'ul', HTMLAttributes>;
|
||||
var: HTMLProps<'var', HTMLAttributes>;
|
||||
video: HTMLProps<'video', HTMLAttributes>;
|
||||
wbr: HTMLProps<'wbr', HTMLAttributes>;
|
||||
webview: HTMLProps<'webview', HTMLAttributes>;
|
||||
// SVG
|
||||
svg: HTMLProps<'svg', SVGAttributes>;
|
||||
|
||||
animate: HTMLProps<'animate', SVGAttributes>;
|
||||
animateMotion: HTMLProps<'animateMotion', SVGAttributes>;
|
||||
animateTransform: HTMLProps<'animateTransform', SVGAttributes>;
|
||||
circle: HTMLProps<'circle', SVGAttributes>;
|
||||
clipPath: HTMLProps<'clipPath', SVGAttributes>;
|
||||
defs: HTMLProps<'defs', SVGAttributes>;
|
||||
desc: HTMLProps<'desc', SVGAttributes>;
|
||||
ellipse: HTMLProps<'ellipse', SVGAttributes>;
|
||||
feBlend: HTMLProps<'feBlend', SVGAttributes>;
|
||||
feColorMatrix: HTMLProps<'feColorMatrix', SVGAttributes>;
|
||||
feComponentTransfer: HTMLProps<'feComponentTransfer', SVGAttributes>;
|
||||
feComposite: HTMLProps<'feComposite', SVGAttributes>;
|
||||
feConvolveMatrix: HTMLProps<'feConvolveMatrix', SVGAttributes>;
|
||||
feDiffuseLighting: HTMLProps<'feDiffuseLighting', SVGAttributes>;
|
||||
feDisplacementMap: HTMLProps<'feDisplacementMap', SVGAttributes>;
|
||||
feDistantLight: HTMLProps<'feDistantLight', SVGAttributes>;
|
||||
feDropShadow: HTMLProps<'feDropShadow', SVGAttributes>;
|
||||
feFlood: HTMLProps<'feFlood', SVGAttributes>;
|
||||
feFuncA: HTMLProps<'feFuncA', SVGAttributes>;
|
||||
feFuncB: HTMLProps<'feFuncB', SVGAttributes>;
|
||||
feFuncG: HTMLProps<'feFuncG', SVGAttributes>;
|
||||
feFuncR: HTMLProps<'feFuncR', SVGAttributes>;
|
||||
feGaussianBlur: HTMLProps<'feGaussianBlur', SVGAttributes>;
|
||||
feImage: HTMLProps<'feImage', SVGAttributes>;
|
||||
feMerge: HTMLProps<'feMerge', SVGAttributes>;
|
||||
feMergeNode: HTMLProps<'feMergeNode', SVGAttributes>;
|
||||
feMorphology: HTMLProps<'feMorphology', SVGAttributes>;
|
||||
feOffset: HTMLProps<'feOffset', SVGAttributes>;
|
||||
fePointLight: HTMLProps<'fePointLight', SVGAttributes>;
|
||||
feSpecularLighting: HTMLProps<'feSpecularLighting', SVGAttributes>;
|
||||
feSpotLight: HTMLProps<'feSpotLight', SVGAttributes>;
|
||||
feTile: HTMLProps<'feTile', SVGAttributes>;
|
||||
feTurbulence: HTMLProps<'feTurbulence', SVGAttributes>;
|
||||
filter: HTMLProps<'filter', SVGAttributes>;
|
||||
foreignObject: HTMLProps<'foreignObject', SVGAttributes>;
|
||||
g: HTMLProps<'g', SVGAttributes>;
|
||||
image: HTMLProps<'image', SVGAttributes>;
|
||||
line: HTMLProps<'line', SVGAttributes>;
|
||||
linearGradient: HTMLProps<'linearGradient', SVGAttributes>;
|
||||
marker: HTMLProps<'marker', SVGAttributes>;
|
||||
mask: HTMLProps<'mask', SVGAttributes>;
|
||||
metadata: HTMLProps<'metadata', SVGAttributes>;
|
||||
mpath: HTMLProps<'mpath', SVGAttributes>;
|
||||
path: HTMLProps<'path', SVGAttributes>;
|
||||
pattern: HTMLProps<'pattern', SVGAttributes>;
|
||||
polygon: HTMLProps<'polygon', SVGAttributes>;
|
||||
polyline: HTMLProps<'polyline', SVGAttributes>;
|
||||
radialGradient: HTMLProps<'radialGradient', SVGAttributes>;
|
||||
rect: HTMLProps<'rect', SVGAttributes>;
|
||||
stop: HTMLProps<'stop', SVGAttributes>;
|
||||
switch: HTMLProps<'switch', SVGAttributes>;
|
||||
symbol: HTMLProps<'symbol', SVGAttributes>;
|
||||
text: HTMLProps<'text', SVGAttributes>;
|
||||
textPath: HTMLProps<'textPath', SVGAttributes>;
|
||||
tspan: HTMLProps<'tspan', SVGAttributes>;
|
||||
use: HTMLProps<'use', SVGAttributes>;
|
||||
view: HTMLProps<'view', SVGAttributes>;
|
||||
|
||||
// Svelte specific
|
||||
'svelte:window': HTMLProps<'svelte:window', HTMLAttributes>;
|
||||
'svelte:body': HTMLProps<'svelte:body', HTMLAttributes>;
|
||||
'svelte:document': HTMLProps<'svelte:document', HTMLAttributes>;
|
||||
'svelte:fragment': { slot?: string };
|
||||
'svelte:options': { [name: string]: any };
|
||||
'svelte:head': { [name: string]: any };
|
||||
|
||||
[name: string]: { [name: string]: any };
|
||||
}
|
||||
|
||||
}
|
||||
+1492
File diff suppressed because it is too large
Load Diff
+32
@@ -0,0 +1,32 @@
|
||||
declare namespace svelteNative.JSX {
|
||||
|
||||
// Every namespace eligible for use needs to implement the following two functions
|
||||
function mapElementTag(
|
||||
tag: string
|
||||
): any;
|
||||
|
||||
function createElement<Elements extends IntrinsicElements, Key extends keyof Elements>(
|
||||
element: Key | undefined | null, attrs: Elements[Key]
|
||||
): any;
|
||||
function createElement<Elements extends IntrinsicElements, Key extends keyof Elements, T>(
|
||||
element: Key | undefined | null, attrEnhancers: T, attrs: Elements[Key] & T
|
||||
): any;
|
||||
|
||||
|
||||
/* svelte specific */
|
||||
interface ElementClass {
|
||||
$$prop_def: any;
|
||||
}
|
||||
|
||||
interface ElementAttributesProperty {
|
||||
$$prop_def: any; // specify the property name to use
|
||||
}
|
||||
|
||||
// Add empty IntrinsicAttributes to prevent fallback to the one in the JSX namespace
|
||||
interface IntrinsicAttributes {
|
||||
}
|
||||
|
||||
interface IntrinsicElements {
|
||||
[name: string]: { [name: string]: any };
|
||||
}
|
||||
}
|
||||
+290
@@ -0,0 +1,290 @@
|
||||
// Whenever a ambient declaration changes, its number should be increased
|
||||
// This way, we avoid the situation where multiple ambient versions of svelte2tsx
|
||||
// are loaded and their declarations conflict each other
|
||||
// See https://github.com/sveltejs/language-tools/issues/1059 for an example bug that stems from it
|
||||
// If you change anything in this file, think about whether or not it should be backported to svelte-shims.d.ts
|
||||
|
||||
type AConstructorTypeOf<T, U extends any[] = any[]> = new (...args: U) => T;
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteActionReturnType = {
|
||||
update?: (args: any) => void,
|
||||
destroy?: () => void
|
||||
} | void
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteTransitionConfig = {
|
||||
delay?: number,
|
||||
duration?: number,
|
||||
easing?: (t: number) => number,
|
||||
css?: (t: number, u: number) => string,
|
||||
tick?: (t: number, u: number) => void
|
||||
}
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteTransitionReturnType = SvelteTransitionConfig | (() => SvelteTransitionConfig)
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteAnimationReturnType = {
|
||||
delay?: number,
|
||||
duration?: number,
|
||||
easing?: (t: number) => number,
|
||||
css?: (t: number, u: number) => string,
|
||||
tick?: (t: number, u: number) => void
|
||||
}
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteWithOptionalProps<Props, Keys extends keyof Props> = Omit<Props, Keys> & Partial<Pick<Props, Keys>>;
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteAllProps = { [index: string]: any }
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SveltePropsAnyFallback<Props> = {[K in keyof Props]: Props[K] extends never ? never : Props[K] extends undefined ? any : Props[K]}
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteSlotsAnyFallback<Slots> = {[K in keyof Slots]: {[S in keyof Slots[K]]: Slots[K][S] extends undefined ? any : Slots[K][S]}}
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteRestProps = { [index: string]: any }
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteSlots = { [index: string]: any }
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteStore<T> = { subscribe: (run: (value: T) => any, invalidate?: any) => any }
|
||||
|
||||
// Forces TypeScript to look into the type which results in a better representation of it
|
||||
// which helps for error messages and is necessary for d.ts file transformation so that
|
||||
// no ambient type references are left in the output
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type KeysMatching<Obj, V> = {[K in keyof Obj]-?: Obj[K] extends V ? K : never}[keyof Obj]
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
declare type __sveltets_2_CustomEvents<T> = {[K in KeysMatching<T, CustomEvent>]: T[K] extends CustomEvent ? T[K]['detail']: T[K]}
|
||||
|
||||
declare function __sveltets_2_ensureRightProps<Props>(props: Props): {};
|
||||
declare function __sveltets_2_instanceOf<T = any>(type: AConstructorTypeOf<T>): T;
|
||||
declare function __sveltets_2_allPropsType(): SvelteAllProps
|
||||
declare function __sveltets_2_restPropsType(): SvelteRestProps
|
||||
declare function __sveltets_2_slotsType<Slots, Key extends keyof Slots>(slots: Slots): Record<Key, boolean>;
|
||||
|
||||
// Overload of the following two functions is necessary.
|
||||
// An empty array of optionalProps makes OptionalProps type any, which means we lose the prop typing.
|
||||
// optionalProps need to be first or its type cannot be infered correctly.
|
||||
|
||||
declare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(
|
||||
render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
||||
): {props: Expand<SveltePropsAnyFallback<Props>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }
|
||||
declare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string, OptionalProps extends keyof Props = any>(
|
||||
optionalProps: OptionalProps[],
|
||||
render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
||||
): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }
|
||||
|
||||
declare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(
|
||||
render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
||||
): {props: Expand<SveltePropsAnyFallback<Props> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }
|
||||
declare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string, OptionalProps extends keyof Props = any>(
|
||||
optionalProps: OptionalProps[],
|
||||
render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
||||
): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }
|
||||
|
||||
|
||||
declare function __sveltets_2_with_any<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(
|
||||
render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
||||
): {props: Expand<Props & SvelteAllProps>, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
||||
|
||||
declare function __sveltets_2_with_any_event<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(
|
||||
render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
||||
): {props: Props, events: Events & {[evt: string]: CustomEvent<any>;}, slots: Slots, exports?: Exports, bindings?: Bindings }
|
||||
|
||||
declare function __sveltets_2_store_get<T = any>(store: SvelteStore<T>): T
|
||||
declare function __sveltets_2_store_get<Store extends SvelteStore<any> | undefined | null>(store: Store): Store extends SvelteStore<infer T> ? T : Store;
|
||||
declare function __sveltets_2_any(dummy: any): any;
|
||||
declare function __sveltets_2_invalidate<T>(getValue: () => T): T
|
||||
|
||||
declare function __sveltets_2_mapWindowEvent<K extends keyof HTMLBodyElementEventMap>(
|
||||
event: K
|
||||
): HTMLBodyElementEventMap[K];
|
||||
declare function __sveltets_2_mapBodyEvent<K extends keyof WindowEventMap>(
|
||||
event: K
|
||||
): WindowEventMap[K];
|
||||
declare function __sveltets_2_mapElementEvent<K extends keyof HTMLElementEventMap>(
|
||||
event: K
|
||||
): HTMLElementEventMap[K];
|
||||
|
||||
declare function __sveltets_2_bubbleEventDef<Events, K extends keyof Events>(
|
||||
events: Events, eventKey: K
|
||||
): Events[K];
|
||||
declare function __sveltets_2_bubbleEventDef(
|
||||
events: any, eventKey: string
|
||||
): any;
|
||||
|
||||
declare const __sveltets_2_customEvent: CustomEvent<any>;
|
||||
declare function __sveltets_2_toEventTypings<Typings>(): {[Key in keyof Typings]: CustomEvent<Typings[Key]>};
|
||||
|
||||
declare function __sveltets_2_unionType<T1, T2>(t1: T1, t2: T2): T1 | T2;
|
||||
declare function __sveltets_2_unionType<T1, T2, T3>(t1: T1, t2: T2, t3: T3): T1 | T2 | T3;
|
||||
declare function __sveltets_2_unionType<T1, T2, T3, T4>(t1: T1, t2: T2, t3: T3, t4: T4): T1 | T2 | T3 | T4;
|
||||
declare function __sveltets_2_unionType(...types: any[]): any;
|
||||
|
||||
declare function __sveltets_2_createSvelte2TsxComponent<Props extends {}, Events extends {}, Slots extends {}>(
|
||||
render: {props: Props, events: Events, slots: Slots }
|
||||
): typeof import("svelte").SvelteComponent<Props, Events, Slots>;
|
||||
|
||||
declare function __sveltets_2_unwrapArr<T>(arr: ArrayLike<T>): T
|
||||
declare function __sveltets_2_unwrapPromiseLike<T>(promise: PromiseLike<T> | T): T
|
||||
|
||||
// v2
|
||||
declare function __sveltets_2_createCreateSlot<Slots = Record<string, Record<string, any>>>(): <SlotName extends keyof Slots>(slotName: SlotName, attrs: Slots[SlotName]) => Record<string, any>;
|
||||
declare function __sveltets_2_createComponentAny(props: Record<string, any>): import("svelte").SvelteComponent<any, any, any>;
|
||||
|
||||
declare function __sveltets_2_any(...dummy: any[]): any;
|
||||
declare function __sveltets_2_empty(...dummy: any[]): {};
|
||||
declare function __sveltets_2_union<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>(t1:T1,t2?:T2,t3?:T3,t4?:T4,t5?:T5,t6?:T6,t7?:T7,t8?:T8,t9?:T9,t10?:T10): T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 & T9 & T10;
|
||||
declare function __sveltets_2_nonNullable<T>(type: T): NonNullable<T>;
|
||||
|
||||
declare function __sveltets_2_cssProp(prop: Record<string, any>): {};
|
||||
|
||||
// @ts-ignore Svelte v3/v4 don't have this
|
||||
declare function __sveltets_2_ensureSnippet(val: ReturnType<import('svelte').Snippet> | undefined | null): any;
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type __sveltets_2_SvelteAnimationReturnType = {
|
||||
delay?: number,
|
||||
duration?: number,
|
||||
easing?: (t: number) => number,
|
||||
css?: (t: number, u: number) => string,
|
||||
tick?: (t: number, u: number) => void
|
||||
}
|
||||
declare var __sveltets_2_AnimationMove: { from: DOMRect, to: DOMRect }
|
||||
declare function __sveltets_2_ensureAnimation(animationCall: __sveltets_2_SvelteAnimationReturnType): {};
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type __sveltets_2_SvelteActionReturnType = {
|
||||
update?: (args: any) => void,
|
||||
destroy?: () => void,
|
||||
$$_attributes?: Record<string, any>,
|
||||
} | void
|
||||
declare function __sveltets_2_ensureAction<T extends __sveltets_2_SvelteActionReturnType>(actionCall: T): T extends {$$_attributes?: any} ? T['$$_attributes'] : {};
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type __sveltets_2_SvelteTransitionConfig = {
|
||||
delay?: number,
|
||||
duration?: number,
|
||||
easing?: (t: number) => number,
|
||||
css?: (t: number, u: number) => string,
|
||||
tick?: (t: number, u: number) => void
|
||||
}
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type __sveltets_2_SvelteTransitionReturnType = __sveltets_2_SvelteTransitionConfig | (() => __sveltets_2_SvelteTransitionConfig)
|
||||
declare function __sveltets_2_ensureTransition(transitionCall: __sveltets_2_SvelteTransitionReturnType): {};
|
||||
|
||||
// Includes undefined and null for all types as all usages also allow these
|
||||
declare function __sveltets_2_ensureType<T>(type: AConstructorTypeOf<T>, el: T | undefined | null): {};
|
||||
declare function __sveltets_2_ensureType<T1, T2>(type1: AConstructorTypeOf<T1>, type2: AConstructorTypeOf<T2>, el: T1 | T2 | undefined | null): {};
|
||||
|
||||
// The following is necessary because there are two clashing errors that can't be solved at the same time
|
||||
// when using Svelte2TsxComponent, more precisely the event typings in
|
||||
// __sveltets_2_ensureComponent<T extends new (..) => _SvelteComponent<any,||any||<-this,any>>(type: T): T;
|
||||
// If we type it as "any", we have an error when using sth like {a: CustomEvent<any>}
|
||||
// If we type it as "{}", we have an error when using sth like {[evt: string]: CustomEvent<any>}
|
||||
// If we type it as "unknown", we get all kinds of follow up errors which we want to avoid
|
||||
// Therefore introduce two more base classes just for this case.
|
||||
/**
|
||||
* Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT
|
||||
*/
|
||||
declare type ATypedSvelteComponent = {
|
||||
/**
|
||||
* @internal This is for type checking capabilities only
|
||||
* and does not exist at runtime. Don't use this property.
|
||||
*/
|
||||
$$prop_def: any;
|
||||
/**
|
||||
* @internal This is for type checking capabilities only
|
||||
* and does not exist at runtime. Don't use this property.
|
||||
*/
|
||||
$$events_def: any;
|
||||
/**
|
||||
* @internal This is for type checking capabilities only
|
||||
* and does not exist at runtime. Don't use this property.
|
||||
*/
|
||||
$$slot_def: any;
|
||||
|
||||
$on(event: string, handler: any): () => void;
|
||||
}
|
||||
/**
|
||||
* Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT.
|
||||
*
|
||||
* If you're looking for the type of a Svelte Component, use `SvelteComponent` and `ComponentType` instead:
|
||||
*
|
||||
* ```ts
|
||||
* import type { ComponentType, SvelteComponent } from "svelte";
|
||||
* let myComponentConstructor: ComponentType<SvelteComponent> = ..;
|
||||
* ```
|
||||
*/
|
||||
declare type ConstructorOfATypedSvelteComponent = new (args: {target: any, props?: any}) => ATypedSvelteComponent
|
||||
// Usage note: Cannot properly transform generic function components to class components due to TypeScript limitations
|
||||
declare function __sveltets_2_ensureComponent<
|
||||
T extends
|
||||
| ConstructorOfATypedSvelteComponent
|
||||
| (typeof import('svelte') extends { mount: any }
|
||||
? // @ts-ignore svelte.Component doesn't exist in Svelte 4
|
||||
import('svelte').Component<any, any, any>
|
||||
: never)
|
||||
| null
|
||||
| undefined
|
||||
>(
|
||||
type: T
|
||||
): NonNullable<
|
||||
T extends ConstructorOfATypedSvelteComponent
|
||||
? T
|
||||
: typeof import('svelte') extends { mount: any }
|
||||
? // @ts-ignore svelte.Component doesn't exist in Svelte 4
|
||||
T extends import('svelte').Component<
|
||||
infer Props extends Record<string, any>,
|
||||
infer Exports extends Record<string, any>,
|
||||
infer Bindings extends string
|
||||
>
|
||||
? new (
|
||||
options: import('svelte').ComponentConstructorOptions<Props>
|
||||
) => import('svelte').SvelteComponent<Props, Props['$$events'], Props['$$slots']> &
|
||||
Exports & { $$bindings: Bindings }
|
||||
: never
|
||||
: never
|
||||
>;
|
||||
|
||||
declare function __sveltets_2_ensureArray<T extends ArrayLike<unknown> | Iterable<unknown>>(
|
||||
// Svelte 5 allows undefined or null here, Svelte 4 doesn't
|
||||
array: T | (typeof import('svelte') extends { mount: any } ? (undefined | null) : never)
|
||||
): T extends ArrayLike<infer U> ? U[] : T extends Iterable<infer U> ? Iterable<U> : any[];
|
||||
|
||||
type __sveltets_2_PropsWithChildren<Props, Slots> = Props &
|
||||
(Slots extends { default: any }
|
||||
// This is unfortunate because it means "accepts no props" turns into "accepts any prop"
|
||||
// but the alternative is non-fixable type errors because of the way TypeScript index
|
||||
// signatures work (they will always take precedence and make an impossible-to-satisfy children type).
|
||||
? Props extends Record<string, never>
|
||||
? any
|
||||
: { children?: any }
|
||||
: {});
|
||||
declare function __sveltets_2_runes_constructor<Props extends {}>(render: {props: Props }): import("svelte").ComponentConstructorOptions<Props>;
|
||||
|
||||
declare function __sveltets_2_get_set_binding<T>(get: (() => T) | null | undefined, set: (t: T) => void): T;
|
||||
|
||||
declare function __sveltets_$$bindings<Bindings extends string[]>(...bindings: Bindings): Bindings[number];
|
||||
|
||||
declare function __sveltets_2_fn_component<
|
||||
Props extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string
|
||||
// @ts-ignore Svelte 5 only
|
||||
>(klass: {props: Props, exports?: Exports, bindings?: Bindings }): import('svelte').Component<Props, Exports, Bindings>;
|
||||
|
||||
interface __sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
||||
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & { $$bindings?: Bindings } & Exports;
|
||||
(internal: unknown, props: Props extends Record<string, never> ? {$$events?: Events, $$slots?: Slots} : Props & {$$events?: Events, $$slots?: Slots}): Exports & { $set?: any, $on?: any };
|
||||
z_$$bindings?: Bindings;
|
||||
}
|
||||
|
||||
declare function __sveltets_2_isomorphic_component<
|
||||
Props extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string
|
||||
>(klass: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }): __sveltets_2_IsomorphicComponent<Props, Events, Slots, Exports, Bindings>;
|
||||
|
||||
declare function __sveltets_2_isomorphic_component_slots<
|
||||
Props extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string
|
||||
>(klass: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }): __sveltets_2_IsomorphicComponent<__sveltets_2_PropsWithChildren<Props, Slots>, Events, Slots, Exports, Bindings>;
|
||||
+305
@@ -0,0 +1,305 @@
|
||||
// @ts-nocheck
|
||||
// nocheck because we don't want to adjust this anymore (only used for Svelte 3)
|
||||
// Whenever a ambient declaration changes, its number should be increased
|
||||
// This way, we avoid the situation where multiple ambient versions of svelte2tsx
|
||||
// are loaded and their declarations conflict each other
|
||||
// See https://github.com/sveltejs/language-tools/issues/1059 for an example bug that stems from it
|
||||
// If you change anything in this file, think about whether or not it should also be added to svelte-shims-v4.d.ts
|
||||
|
||||
// -- start svelte-ls-remove --
|
||||
declare module '*.svelte' {
|
||||
type _SvelteComponent<Props=any,Events=any,Slots=any> = import("svelte").SvelteComponentTyped<Props,Events,Slots>;
|
||||
export default _SvelteComponent
|
||||
}
|
||||
// -- end svelte-ls-remove --
|
||||
|
||||
/**
|
||||
* @deprecated This will be removed soon. Use `SvelteComponentTyped` instead:
|
||||
* ```ts
|
||||
* import type { SvelteComponentTyped } from 'svelte';
|
||||
* ```
|
||||
*/
|
||||
declare class Svelte2TsxComponent<
|
||||
Props extends {} = {},
|
||||
Events extends {} = {},
|
||||
Slots extends {} = {}
|
||||
> {
|
||||
// svelte2tsx-specific
|
||||
/**
|
||||
* @internal This is for type checking capabilities only
|
||||
* and does not exist at runtime. Don't use this property.
|
||||
*/
|
||||
$$prop_def: Props;
|
||||
/**
|
||||
* @internal This is for type checking capabilities only
|
||||
* and does not exist at runtime. Don't use this property.
|
||||
*/
|
||||
$$events_def: Events;
|
||||
/**
|
||||
* @internal This is for type checking capabilities only
|
||||
* and does not exist at runtime. Don't use this property.
|
||||
*/
|
||||
$$slot_def: Slots;
|
||||
// https://svelte.dev/docs#Client-side_component_API
|
||||
constructor(options: Svelte2TsxComponentConstructorParameters<Props>);
|
||||
/**
|
||||
* Causes the callback function to be called whenever the component dispatches an event.
|
||||
* A function is returned that will remove the event listener when called.
|
||||
*/
|
||||
$on<K extends keyof Events & string>(event: K, handler: ((e: Events[K]) => any) | null | undefined): () => void;
|
||||
/**
|
||||
* Removes a component from the DOM and triggers any `onDestroy` handlers.
|
||||
*/
|
||||
$destroy(): void;
|
||||
/**
|
||||
* Programmatically sets props on an instance.
|
||||
* `component.$set({ x: 1 })` is equivalent to `x = 1` inside the component's `<script>` block.
|
||||
* Calling this method schedules an update for the next microtask — the DOM is __not__ updated synchronously.
|
||||
*/
|
||||
$set(props?: Partial<Props>): void;
|
||||
// From SvelteComponent(Dev) definition
|
||||
$$: any;
|
||||
$capture_state(): void;
|
||||
$inject_state(): void;
|
||||
}
|
||||
|
||||
/** @deprecated PRIVATE API, DO NOT USE, REMOVED SOON */
|
||||
interface Svelte2TsxComponentConstructorParameters<Props extends {}> {
|
||||
/**
|
||||
* An HTMLElement to render to. This option is required.
|
||||
*/
|
||||
target: Element | Document | ShadowRoot;
|
||||
/**
|
||||
* A child of `target` to render the component immediately before.
|
||||
*/
|
||||
anchor?: Element;
|
||||
/**
|
||||
* An object of properties to supply to the component.
|
||||
*/
|
||||
props?: Props;
|
||||
context?: Map<any, any>;
|
||||
hydrate?: boolean;
|
||||
intro?: boolean;
|
||||
$$inline?: boolean;
|
||||
}
|
||||
|
||||
type AConstructorTypeOf<T, U extends any[] = any[]> = new (...args: U) => T;
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteComponentConstructor<T, U extends import('svelte').ComponentConstructorOptions<any>> = new (options: U) => T;
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteActionReturnType = {
|
||||
update?: (args: any) => void,
|
||||
destroy?: () => void
|
||||
} | void
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteTransitionConfig = {
|
||||
delay?: number,
|
||||
duration?: number,
|
||||
easing?: (t: number) => number,
|
||||
css?: (t: number, u: number) => string,
|
||||
tick?: (t: number, u: number) => void
|
||||
}
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteTransitionReturnType = SvelteTransitionConfig | (() => SvelteTransitionConfig)
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteAnimationReturnType = {
|
||||
delay?: number,
|
||||
duration?: number,
|
||||
easing?: (t: number) => number,
|
||||
css?: (t: number, u: number) => string,
|
||||
tick?: (t: number, u: number) => void
|
||||
}
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteWithOptionalProps<Props, Keys extends keyof Props> = Omit<Props, Keys> & Partial<Pick<Props, Keys>>;
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteAllProps = { [index: string]: any }
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SveltePropsAnyFallback<Props> = {[K in keyof Props]: Props[K] extends never ? never : Props[K] extends undefined ? any : Props[K]}
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteSlotsAnyFallback<Slots> = {[K in keyof Slots]: {[S in keyof Slots[K]]: Slots[K][S] extends undefined ? any : Slots[K][S]}}
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteRestProps = { [index: string]: any }
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteSlots = { [index: string]: any }
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type SvelteStore<T> = { subscribe: (run: (value: T) => any, invalidate?: any) => any }
|
||||
|
||||
// Forces TypeScript to look into the type which results in a better representation of it
|
||||
// which helps for error messages and is necessary for d.ts file transformation so that
|
||||
// no ambient type references are left in the output
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type KeysMatching<Obj, V> = {[K in keyof Obj]-?: Obj[K] extends V ? K : never}[keyof Obj]
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
declare type __sveltets_2_CustomEvents<T> = {[K in KeysMatching<T, CustomEvent>]: T[K] extends CustomEvent ? T[K]['detail']: T[K]}
|
||||
|
||||
declare function __sveltets_2_ensureRightProps<Props>(props: Props): {};
|
||||
declare function __sveltets_2_instanceOf<T = any>(type: AConstructorTypeOf<T>): T;
|
||||
declare function __sveltets_2_allPropsType(): SvelteAllProps
|
||||
declare function __sveltets_2_restPropsType(): SvelteRestProps
|
||||
declare function __sveltets_2_slotsType<Slots, Key extends keyof Slots>(slots: Slots): Record<Key, boolean>;
|
||||
|
||||
// Overload of the following two functions is necessary.
|
||||
// An empty array of optionalProps makes OptionalProps type any, which means we lose the prop typing.
|
||||
// optionalProps need to be first or its type cannot be infered correctly.
|
||||
|
||||
declare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}>(
|
||||
render: {props: Props, events: Events, slots: Slots }
|
||||
): {props: Expand<SveltePropsAnyFallback<Props>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>> }
|
||||
declare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}, OptionalProps extends keyof Props = any>(
|
||||
optionalProps: OptionalProps[],
|
||||
render: {props: Props, events: Events, slots: Slots }
|
||||
): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>> }
|
||||
|
||||
declare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}>(
|
||||
render: {props: Props, events: Events, slots: Slots }
|
||||
): {props: Expand<SveltePropsAnyFallback<Props> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>> }
|
||||
declare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}, OptionalProps extends keyof Props = any>(
|
||||
optionalProps: OptionalProps[],
|
||||
render: {props: Props, events: Events, slots: Slots }
|
||||
): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>> }
|
||||
|
||||
|
||||
declare function __sveltets_2_with_any<Props = {}, Events = {}, Slots = {}>(
|
||||
render: {props: Props, events: Events, slots: Slots }
|
||||
): {props: Expand<Props & SvelteAllProps>, events: Events, slots: Slots }
|
||||
|
||||
declare function __sveltets_2_with_any_event<Props = {}, Events = {}, Slots = {}>(
|
||||
render: {props: Props, events: Events, slots: Slots }
|
||||
): {props: Props, events: Events & {[evt: string]: CustomEvent<any>;}, slots: Slots }
|
||||
|
||||
declare function __sveltets_2_store_get<T = any>(store: SvelteStore<T>): T
|
||||
declare function __sveltets_2_store_get<Store extends SvelteStore<any> | undefined | null>(store: Store): Store extends SvelteStore<infer T> ? T : Store;
|
||||
declare function __sveltets_2_any(dummy: any): any;
|
||||
// declare function __sveltets_1_empty(...dummy: any[]): {};
|
||||
// declare function __sveltets_1_componentType(): AConstructorTypeOf<import("svelte").SvelteComponentTyped<any, any, any>>
|
||||
declare function __sveltets_2_invalidate<T>(getValue: () => T): T
|
||||
|
||||
declare function __sveltets_2_mapWindowEvent<K extends keyof HTMLBodyElementEventMap>(
|
||||
event: K
|
||||
): HTMLBodyElementEventMap[K];
|
||||
declare function __sveltets_2_mapBodyEvent<K extends keyof WindowEventMap>(
|
||||
event: K
|
||||
): WindowEventMap[K];
|
||||
declare function __sveltets_2_mapElementEvent<K extends keyof HTMLElementEventMap>(
|
||||
event: K
|
||||
): HTMLElementEventMap[K];
|
||||
|
||||
declare function __sveltets_2_bubbleEventDef<Events, K extends keyof Events>(
|
||||
events: Events, eventKey: K
|
||||
): Events[K];
|
||||
declare function __sveltets_2_bubbleEventDef(
|
||||
events: any, eventKey: string
|
||||
): any;
|
||||
|
||||
declare const __sveltets_2_customEvent: CustomEvent<any>;
|
||||
declare function __sveltets_2_toEventTypings<Typings>(): {[Key in keyof Typings]: CustomEvent<Typings[Key]>};
|
||||
|
||||
declare function __sveltets_2_unionType<T1, T2>(t1: T1, t2: T2): T1 | T2;
|
||||
declare function __sveltets_2_unionType<T1, T2, T3>(t1: T1, t2: T2, t3: T3): T1 | T2 | T3;
|
||||
declare function __sveltets_2_unionType<T1, T2, T3, T4>(t1: T1, t2: T2, t3: T3, t4: T4): T1 | T2 | T3 | T4;
|
||||
declare function __sveltets_2_unionType(...types: any[]): any;
|
||||
|
||||
declare function __sveltets_2_createSvelte2TsxComponent<Props, Events, Slots>(
|
||||
render: {props: Props, events: Events, slots: Slots }
|
||||
): SvelteComponentConstructor<import("svelte").SvelteComponentTyped<Props, Events, Slots>,import('svelte').ComponentConstructorOptions<Props>>;
|
||||
|
||||
declare function __sveltets_2_unwrapArr<T>(arr: ArrayLike<T>): T
|
||||
declare function __sveltets_2_unwrapPromiseLike<T>(promise: PromiseLike<T> | T): T
|
||||
|
||||
// v2
|
||||
declare function __sveltets_2_createCreateSlot<Slots = Record<string, Record<string, any>>>(): <SlotName extends keyof Slots>(slotName: SlotName, attrs: Slots[SlotName]) => Record<string, any>;
|
||||
declare function __sveltets_2_createComponentAny(props: Record<string, any>): import("svelte").SvelteComponentTyped<any, any, any>;
|
||||
|
||||
declare function __sveltets_2_any(...dummy: any[]): any;
|
||||
declare function __sveltets_2_empty(...dummy: any[]): {};
|
||||
declare function __sveltets_2_union<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>(t1:T1,t2?:T2,t3?:T3,t4?:T4,t5?:T5,t6?:T6,t7?:T7,t8?:T8,t9?:T9,t10?:T10): T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 & T9 & T10;
|
||||
declare function __sveltets_2_nonNullable<T>(type: T): NonNullable<T>;
|
||||
|
||||
declare function __sveltets_2_cssProp(prop: Record<string, any>): {};
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type __sveltets_2_SvelteAnimationReturnType = {
|
||||
delay?: number,
|
||||
duration?: number,
|
||||
easing?: (t: number) => number,
|
||||
css?: (t: number, u: number) => string,
|
||||
tick?: (t: number, u: number) => void
|
||||
}
|
||||
declare var __sveltets_2_AnimationMove: { from: DOMRect, to: DOMRect }
|
||||
declare function __sveltets_2_ensureAnimation(animationCall: __sveltets_2_SvelteAnimationReturnType): {};
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type __sveltets_2_SvelteActionReturnType = {
|
||||
update?: (args: any) => void,
|
||||
destroy?: () => void,
|
||||
$$_attributes?: Record<string, any>,
|
||||
} | void
|
||||
declare function __sveltets_2_ensureAction<T extends __sveltets_2_SvelteActionReturnType>(actionCall: T): T extends {$$_attributes?: any} ? T['$$_attributes'] : {};
|
||||
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type __sveltets_2_SvelteTransitionConfig = {
|
||||
delay?: number,
|
||||
duration?: number,
|
||||
easing?: (t: number) => number,
|
||||
css?: (t: number, u: number) => string,
|
||||
tick?: (t: number, u: number) => void
|
||||
}
|
||||
/** @internal PRIVATE API, DO NOT USE */
|
||||
type __sveltets_2_SvelteTransitionReturnType = __sveltets_2_SvelteTransitionConfig | (() => __sveltets_2_SvelteTransitionConfig)
|
||||
declare function __sveltets_2_ensureTransition(transitionCall: __sveltets_2_SvelteTransitionReturnType): {};
|
||||
|
||||
// Includes undefined and null for all types as all usages also allow these
|
||||
declare function __sveltets_2_ensureType<T>(type: AConstructorTypeOf<T>, el: T | undefined | null): {};
|
||||
declare function __sveltets_2_ensureType<T1, T2>(type1: AConstructorTypeOf<T1>, type2: AConstructorTypeOf<T2>, el: T1 | T2 | undefined | null): {};
|
||||
|
||||
// The following is necessary because there are two clashing errors that can't be solved at the same time
|
||||
// when using Svelte2TsxComponent, more precisely the event typings in
|
||||
// __sveltets_2_ensureComponent<T extends new (..) => _SvelteComponent<any,||any||<-this,any>>(type: T): T;
|
||||
// If we type it as "any", we have an error when using sth like {a: CustomEvent<any>}
|
||||
// If we type it as "{}", we have an error when using sth like {[evt: string]: CustomEvent<any>}
|
||||
// If we type it as "unknown", we get all kinds of follow up errors which we want to avoid
|
||||
// Therefore introduce two more base classes just for this case.
|
||||
/**
|
||||
* Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT
|
||||
*/
|
||||
declare type ATypedSvelteComponent = {
|
||||
/**
|
||||
* @internal This is for type checking capabilities only
|
||||
* and does not exist at runtime. Don't use this property.
|
||||
*/
|
||||
$$prop_def: any;
|
||||
/**
|
||||
* @internal This is for type checking capabilities only
|
||||
* and does not exist at runtime. Don't use this property.
|
||||
*/
|
||||
$$events_def: any;
|
||||
/**
|
||||
* @internal This is for type checking capabilities only
|
||||
* and does not exist at runtime. Don't use this property.
|
||||
*/
|
||||
$$slot_def: any;
|
||||
|
||||
$on(event: string, handler: ((e: any) => any) | null | undefined): () => void;
|
||||
}
|
||||
/**
|
||||
* Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT.
|
||||
*
|
||||
* If you're looking for the type of a Svelte Component, use `SvelteComponentTyped` and `ComponentType` instead:
|
||||
*
|
||||
* ```ts
|
||||
* import type { ComponentType, SvelteComponentTyped } from "svelte";
|
||||
* let myComponentConstructor: ComponentType<SvelteComponentTyped> = ..;
|
||||
* ```
|
||||
*/
|
||||
declare type ConstructorOfATypedSvelteComponent = new (args: {target: any, props?: any}) => ATypedSvelteComponent
|
||||
declare function __sveltets_2_ensureComponent<T extends ConstructorOfATypedSvelteComponent | null | undefined>(type: T): NonNullable<T>;
|
||||
|
||||
declare function __sveltets_2_ensureArray<T extends ArrayLike<unknown>>(array: T): T extends ArrayLike<infer U> ? U[] : any[];
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"name": "svelte-check",
|
||||
"description": "Svelte Code Checker Terminal Interface",
|
||||
"version": "4.4.6",
|
||||
"main": "./dist/src/index.js",
|
||||
"bin": "./bin/svelte-check",
|
||||
"author": "The Svelte Community",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sveltejs/language-tools.git"
|
||||
},
|
||||
"keywords": [
|
||||
"svelte",
|
||||
"cli"
|
||||
],
|
||||
"files": [
|
||||
"bin",
|
||||
"dist"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/sveltejs/language-tools/issues"
|
||||
},
|
||||
"homepage": "https://github.com/sveltejs/language-tools#readme",
|
||||
"engines": {
|
||||
"node": ">= 18.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@jridgewell/trace-mapping": "^0.3.25",
|
||||
"chokidar": "^4.0.1",
|
||||
"fdir": "^6.2.0",
|
||||
"picocolors": "^1.0.0",
|
||||
"sade": "^1.7.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"svelte": "^4.0.0 || ^5.0.0-next.0",
|
||||
"typescript": ">=5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^24.0.0",
|
||||
"@rollup/plugin-json": "^6.0.0",
|
||||
"@rollup/plugin-node-resolve": "^15.0.0",
|
||||
"@rollup/plugin-replace": "5.0.2",
|
||||
"@rollup/plugin-typescript": "^10.0.0",
|
||||
"@types/sade": "^1.7.2",
|
||||
"rollup": "3.7.5",
|
||||
"rollup-plugin-cleanup": "^3.2.0",
|
||||
"rollup-plugin-copy": "^3.4.0",
|
||||
"svelte": "^4.2.19",
|
||||
"typescript": "^5.9.2",
|
||||
"vscode-languageserver": "8.0.2",
|
||||
"vscode-languageserver-protocol": "3.17.2",
|
||||
"vscode-languageserver-types": "3.17.2",
|
||||
"vscode-uri": "~3.1.0",
|
||||
"svelte2tsx": "0.7.53",
|
||||
"svelte-language-server": "0.17.30"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "cd ../svelte2tsx && pnpm build && cd ../language-server && pnpm build && cd ../svelte-check && rollup -c && pnpm test:sanity",
|
||||
"test": "pnpm build",
|
||||
"test:sanity": "node test-sanity.js"
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
Apache License
|
||||
|
||||
Version 2.0, January 2004
|
||||
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||
|
||||
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||
|
||||
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||
|
||||
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||
|
||||
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
|
||||
# TypeScript
|
||||
|
||||
[](https://github.com/microsoft/TypeScript/actions/workflows/ci.yml)
|
||||
[](https://www.npmjs.com/package/typescript)
|
||||
[](https://www.npmjs.com/package/typescript)
|
||||
[](https://securityscorecards.dev/viewer/?uri=github.com/microsoft/TypeScript)
|
||||
|
||||
|
||||
[TypeScript](https://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types to JavaScript that support tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](https://www.typescriptlang.org/play/), and stay up to date via [our blog](https://blogs.msdn.microsoft.com/typescript) and [Twitter account](https://twitter.com/typescript).
|
||||
|
||||
Find others who are using TypeScript at [our community page](https://www.typescriptlang.org/community/).
|
||||
|
||||
## Installing
|
||||
|
||||
For the latest stable version:
|
||||
|
||||
```bash
|
||||
npm install -D typescript
|
||||
```
|
||||
|
||||
For our nightly builds:
|
||||
|
||||
```bash
|
||||
npm install -D typescript@next
|
||||
```
|
||||
|
||||
## Contribute
|
||||
|
||||
There are many ways to [contribute](https://github.com/microsoft/TypeScript/blob/main/CONTRIBUTING.md) to TypeScript.
|
||||
* [Submit bugs](https://github.com/microsoft/TypeScript/issues) and help us verify fixes as they are checked in.
|
||||
* Review the [source code changes](https://github.com/microsoft/TypeScript/pulls).
|
||||
* Engage with other TypeScript users and developers on [StackOverflow](https://stackoverflow.com/questions/tagged/typescript).
|
||||
* Help each other in the [TypeScript Community Discord](https://discord.gg/typescript).
|
||||
* Join the [#typescript](https://twitter.com/search?q=%23TypeScript) discussion on Twitter.
|
||||
* [Contribute bug fixes](https://github.com/microsoft/TypeScript/blob/main/CONTRIBUTING.md).
|
||||
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see
|
||||
the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com)
|
||||
with any additional questions or comments.
|
||||
|
||||
## Documentation
|
||||
|
||||
* [TypeScript in 5 minutes](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html)
|
||||
* [Programming handbook](https://www.typescriptlang.org/docs/handbook/intro.html)
|
||||
* [Homepage](https://www.typescriptlang.org/)
|
||||
|
||||
## Roadmap
|
||||
|
||||
For details on our planned features and future direction, please refer to our [roadmap](https://github.com/microsoft/TypeScript/wiki/Roadmap).
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.9 BLOCK -->
|
||||
|
||||
## Security
|
||||
|
||||
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations.
|
||||
|
||||
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below.
|
||||
|
||||
## Reporting Security Issues
|
||||
|
||||
**Please do not report security vulnerabilities through public GitHub issues.**
|
||||
|
||||
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report).
|
||||
|
||||
You should receive a response within 24 hours. If for some reason you do not, please follow up using the messaging functionality found at the bottom of the Activity tab on your vulnerability report on [https://msrc.microsoft.com/report/vulnerability](https://msrc.microsoft.com/report/vulnerability/) or via email as described in the instructions at the bottom of [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report). Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc) or on MSRC's [FAQ page for reporting an issue](https://www.microsoft.com/en-us/msrc/faqs-report-an-issue).
|
||||
|
||||
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
||||
|
||||
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
||||
* Full paths of source file(s) related to the manifestation of the issue
|
||||
* The location of the affected source code (tag/branch/commit or direct URL)
|
||||
* Any special configuration required to reproduce the issue
|
||||
* Step-by-step instructions to reproduce the issue
|
||||
* Proof-of-concept or exploit code (if possible)
|
||||
* Impact of the issue, including how an attacker might exploit the issue
|
||||
|
||||
This information will help us triage your report more quickly.
|
||||
|
||||
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs.
|
||||
|
||||
## Preferred Languages
|
||||
|
||||
We prefer all communications to be in English.
|
||||
|
||||
## Policy
|
||||
|
||||
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd).
|
||||
|
||||
<!-- END MICROSOFT SECURITY.MD BLOCK -->
|
||||
+193
File diff suppressed because one or more lines are too long
+2
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
require('../lib/tsc.js')
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
require('../lib/tsserver.js')
|
||||
+134465
File diff suppressed because one or more lines are too long
+659
@@ -0,0 +1,659 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
|
||||
// src/tsserver/server.ts
|
||||
var import_os2 = __toESM(require("os"));
|
||||
|
||||
// src/typescript/typescript.ts
|
||||
var typescript_exports = {};
|
||||
__reExport(typescript_exports, require("./typescript.js"));
|
||||
|
||||
// src/tsserver/nodeServer.ts
|
||||
var import_child_process = __toESM(require("child_process"));
|
||||
var import_fs = __toESM(require("fs"));
|
||||
var import_net = __toESM(require("net"));
|
||||
var import_os = __toESM(require("os"));
|
||||
var import_readline = __toESM(require("readline"));
|
||||
|
||||
// src/tsserver/common.ts
|
||||
function getLogLevel(level) {
|
||||
if (level) {
|
||||
const l = level.toLowerCase();
|
||||
for (const name in typescript_exports.server.LogLevel) {
|
||||
if (isNaN(+name) && l === name.toLowerCase()) {
|
||||
return typescript_exports.server.LogLevel[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
|
||||
// src/tsserver/nodeServer.ts
|
||||
function parseLoggingEnvironmentString(logEnvStr) {
|
||||
if (!logEnvStr) {
|
||||
return {};
|
||||
}
|
||||
const logEnv = { logToFile: true };
|
||||
const args = logEnvStr.split(" ");
|
||||
const len = args.length - 1;
|
||||
for (let i = 0; i < len; i += 2) {
|
||||
const option = args[i];
|
||||
const { value, extraPartCounter } = getEntireValue(i + 1);
|
||||
i += extraPartCounter;
|
||||
if (option && value) {
|
||||
switch (option) {
|
||||
case "-file":
|
||||
logEnv.file = value;
|
||||
break;
|
||||
case "-level":
|
||||
const level = getLogLevel(value);
|
||||
logEnv.detailLevel = level !== void 0 ? level : typescript_exports.server.LogLevel.normal;
|
||||
break;
|
||||
case "-traceToConsole":
|
||||
logEnv.traceToConsole = value.toLowerCase() === "true";
|
||||
break;
|
||||
case "-logToFile":
|
||||
logEnv.logToFile = value.toLowerCase() === "true";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return logEnv;
|
||||
function getEntireValue(initialIndex) {
|
||||
let pathStart = args[initialIndex];
|
||||
let extraPartCounter = 0;
|
||||
if (pathStart.charCodeAt(0) === typescript_exports.CharacterCodes.doubleQuote && pathStart.charCodeAt(pathStart.length - 1) !== typescript_exports.CharacterCodes.doubleQuote) {
|
||||
for (let i = initialIndex + 1; i < args.length; i++) {
|
||||
pathStart += " ";
|
||||
pathStart += args[i];
|
||||
extraPartCounter++;
|
||||
if (pathStart.charCodeAt(pathStart.length - 1) === typescript_exports.CharacterCodes.doubleQuote) break;
|
||||
}
|
||||
}
|
||||
return { value: (0, typescript_exports.stripQuotes)(pathStart), extraPartCounter };
|
||||
}
|
||||
}
|
||||
function parseServerMode() {
|
||||
const mode = typescript_exports.server.findArgument("--serverMode");
|
||||
if (!mode) return void 0;
|
||||
switch (mode.toLowerCase()) {
|
||||
case "semantic":
|
||||
return typescript_exports.LanguageServiceMode.Semantic;
|
||||
case "partialsemantic":
|
||||
return typescript_exports.LanguageServiceMode.PartialSemantic;
|
||||
case "syntactic":
|
||||
return typescript_exports.LanguageServiceMode.Syntactic;
|
||||
default:
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
function initializeNodeSystem() {
|
||||
const sys4 = typescript_exports.Debug.checkDefined(typescript_exports.sys);
|
||||
class Logger {
|
||||
constructor(logFilename, traceToConsole, level) {
|
||||
this.logFilename = logFilename;
|
||||
this.traceToConsole = traceToConsole;
|
||||
this.level = level;
|
||||
this.seq = 0;
|
||||
this.inGroup = false;
|
||||
this.firstInGroup = true;
|
||||
this.fd = -1;
|
||||
if (this.logFilename) {
|
||||
try {
|
||||
this.fd = import_fs.default.openSync(this.logFilename, "w");
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
}
|
||||
static padStringRight(str, padding) {
|
||||
return (str + padding).slice(0, padding.length);
|
||||
}
|
||||
close() {
|
||||
if (this.fd >= 0) {
|
||||
import_fs.default.close(this.fd, typescript_exports.noop);
|
||||
}
|
||||
}
|
||||
getLogFileName() {
|
||||
return this.logFilename;
|
||||
}
|
||||
perftrc(s) {
|
||||
this.msg(s, typescript_exports.server.Msg.Perf);
|
||||
}
|
||||
info(s) {
|
||||
this.msg(s, typescript_exports.server.Msg.Info);
|
||||
}
|
||||
err(s) {
|
||||
this.msg(s, typescript_exports.server.Msg.Err);
|
||||
}
|
||||
startGroup() {
|
||||
this.inGroup = true;
|
||||
this.firstInGroup = true;
|
||||
}
|
||||
endGroup() {
|
||||
this.inGroup = false;
|
||||
}
|
||||
loggingEnabled() {
|
||||
return !!this.logFilename || this.traceToConsole;
|
||||
}
|
||||
hasLevel(level) {
|
||||
return this.loggingEnabled() && this.level >= level;
|
||||
}
|
||||
msg(s, type = typescript_exports.server.Msg.Err) {
|
||||
if (!this.canWrite()) return;
|
||||
s = `[${typescript_exports.server.nowString()}] ${s}
|
||||
`;
|
||||
if (!this.inGroup || this.firstInGroup) {
|
||||
const prefix = Logger.padStringRight(type + " " + this.seq.toString(), " ");
|
||||
s = prefix + s;
|
||||
}
|
||||
this.write(s, type);
|
||||
if (!this.inGroup) {
|
||||
this.seq++;
|
||||
}
|
||||
}
|
||||
canWrite() {
|
||||
return this.fd >= 0 || this.traceToConsole;
|
||||
}
|
||||
write(s, _type) {
|
||||
if (this.fd >= 0) {
|
||||
const buf = Buffer.from(s);
|
||||
import_fs.default.writeSync(
|
||||
this.fd,
|
||||
buf,
|
||||
0,
|
||||
buf.length,
|
||||
/*position*/
|
||||
null
|
||||
);
|
||||
}
|
||||
if (this.traceToConsole) {
|
||||
console.warn(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
const libDirectory = (0, typescript_exports.getDirectoryPath)((0, typescript_exports.normalizePath)(sys4.getExecutingFilePath()));
|
||||
const useWatchGuard = process.platform === "win32";
|
||||
const originalWatchDirectory = sys4.watchDirectory.bind(sys4);
|
||||
const logger = createLogger();
|
||||
typescript_exports.Debug.loggingHost = {
|
||||
log(level, s) {
|
||||
switch (level) {
|
||||
case typescript_exports.LogLevel.Error:
|
||||
case typescript_exports.LogLevel.Warning:
|
||||
return logger.msg(s, typescript_exports.server.Msg.Err);
|
||||
case typescript_exports.LogLevel.Info:
|
||||
case typescript_exports.LogLevel.Verbose:
|
||||
return logger.msg(s, typescript_exports.server.Msg.Info);
|
||||
}
|
||||
}
|
||||
};
|
||||
const pending = (0, typescript_exports.createQueue)();
|
||||
let canWrite = true;
|
||||
if (useWatchGuard) {
|
||||
const currentDrive = extractWatchDirectoryCacheKey(
|
||||
sys4.resolvePath(sys4.getCurrentDirectory()),
|
||||
/*currentDriveKey*/
|
||||
void 0
|
||||
);
|
||||
const statusCache = /* @__PURE__ */ new Map();
|
||||
sys4.watchDirectory = (path, callback, recursive, options) => {
|
||||
const cacheKey = extractWatchDirectoryCacheKey(path, currentDrive);
|
||||
let status = cacheKey && statusCache.get(cacheKey);
|
||||
if (status === void 0) {
|
||||
if (logger.hasLevel(typescript_exports.server.LogLevel.verbose)) {
|
||||
logger.info(`${cacheKey} for path ${path} not found in cache...`);
|
||||
}
|
||||
try {
|
||||
const args = [(0, typescript_exports.combinePaths)(libDirectory, "watchGuard.js"), path];
|
||||
if (logger.hasLevel(typescript_exports.server.LogLevel.verbose)) {
|
||||
logger.info(`Starting ${process.execPath} with args:${typescript_exports.server.stringifyIndented(args)}`);
|
||||
}
|
||||
import_child_process.default.execFileSync(process.execPath, args, { stdio: "ignore", env: { ELECTRON_RUN_AS_NODE: "1" } });
|
||||
status = true;
|
||||
if (logger.hasLevel(typescript_exports.server.LogLevel.verbose)) {
|
||||
logger.info(`WatchGuard for path ${path} returned: OK`);
|
||||
}
|
||||
} catch (e) {
|
||||
status = false;
|
||||
if (logger.hasLevel(typescript_exports.server.LogLevel.verbose)) {
|
||||
logger.info(`WatchGuard for path ${path} returned: ${e.message}`);
|
||||
}
|
||||
}
|
||||
if (cacheKey) {
|
||||
statusCache.set(cacheKey, status);
|
||||
}
|
||||
} else if (logger.hasLevel(typescript_exports.server.LogLevel.verbose)) {
|
||||
logger.info(`watchDirectory for ${path} uses cached drive information.`);
|
||||
}
|
||||
if (status) {
|
||||
return watchDirectorySwallowingException(path, callback, recursive, options);
|
||||
} else {
|
||||
return typescript_exports.noopFileWatcher;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
sys4.watchDirectory = watchDirectorySwallowingException;
|
||||
}
|
||||
sys4.write = (s) => writeMessage(Buffer.from(s, "utf8"));
|
||||
sys4.setTimeout = setTimeout;
|
||||
sys4.clearTimeout = clearTimeout;
|
||||
sys4.setImmediate = setImmediate;
|
||||
sys4.clearImmediate = clearImmediate;
|
||||
if (typeof global !== "undefined" && global.gc) {
|
||||
sys4.gc = () => {
|
||||
var _a;
|
||||
return (_a = global.gc) == null ? void 0 : _a.call(global);
|
||||
};
|
||||
}
|
||||
const cancellationToken = createCancellationToken(sys4.args);
|
||||
const localeStr = typescript_exports.server.findArgument("--locale");
|
||||
if (localeStr) {
|
||||
(0, typescript_exports.validateLocaleAndSetLanguage)(localeStr, sys4);
|
||||
}
|
||||
const modeOrUnknown = parseServerMode();
|
||||
let serverMode;
|
||||
let unknownServerMode;
|
||||
if (modeOrUnknown !== void 0) {
|
||||
if (typeof modeOrUnknown === "number") serverMode = modeOrUnknown;
|
||||
else unknownServerMode = modeOrUnknown;
|
||||
}
|
||||
return {
|
||||
args: process.argv,
|
||||
logger,
|
||||
cancellationToken,
|
||||
serverMode,
|
||||
unknownServerMode,
|
||||
startSession: startNodeSession
|
||||
};
|
||||
function createLogger() {
|
||||
const cmdLineLogFileName = typescript_exports.server.findArgument("--logFile");
|
||||
const cmdLineVerbosity = getLogLevel(typescript_exports.server.findArgument("--logVerbosity"));
|
||||
const envLogOptions = parseLoggingEnvironmentString(process.env.TSS_LOG);
|
||||
const unsubstitutedLogFileName = cmdLineLogFileName ? (0, typescript_exports.stripQuotes)(cmdLineLogFileName) : envLogOptions.logToFile ? envLogOptions.file || libDirectory + "/.log" + process.pid.toString() : void 0;
|
||||
const substitutedLogFileName = unsubstitutedLogFileName ? unsubstitutedLogFileName.replace("PID", process.pid.toString()) : void 0;
|
||||
const logVerbosity = cmdLineVerbosity || envLogOptions.detailLevel;
|
||||
return new Logger(substitutedLogFileName, envLogOptions.traceToConsole, logVerbosity);
|
||||
}
|
||||
function writeMessage(buf) {
|
||||
if (!canWrite) {
|
||||
pending.enqueue(buf);
|
||||
} else {
|
||||
canWrite = false;
|
||||
process.stdout.write(buf, setCanWriteFlagAndWriteMessageIfNecessary);
|
||||
}
|
||||
}
|
||||
function setCanWriteFlagAndWriteMessageIfNecessary() {
|
||||
canWrite = true;
|
||||
if (!pending.isEmpty()) {
|
||||
writeMessage(pending.dequeue());
|
||||
}
|
||||
}
|
||||
function extractWatchDirectoryCacheKey(path, currentDriveKey) {
|
||||
path = (0, typescript_exports.normalizeSlashes)(path);
|
||||
if (isUNCPath(path)) {
|
||||
const firstSlash = path.indexOf(typescript_exports.directorySeparator, 2);
|
||||
return firstSlash !== -1 ? (0, typescript_exports.toFileNameLowerCase)(path.substring(0, firstSlash)) : path;
|
||||
}
|
||||
const rootLength = (0, typescript_exports.getRootLength)(path);
|
||||
if (rootLength === 0) {
|
||||
return currentDriveKey;
|
||||
}
|
||||
if (path.charCodeAt(1) === typescript_exports.CharacterCodes.colon && path.charCodeAt(2) === typescript_exports.CharacterCodes.slash) {
|
||||
return (0, typescript_exports.toFileNameLowerCase)(path.charAt(0));
|
||||
}
|
||||
if (path.charCodeAt(0) === typescript_exports.CharacterCodes.slash && path.charCodeAt(1) !== typescript_exports.CharacterCodes.slash) {
|
||||
return currentDriveKey;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
function isUNCPath(s) {
|
||||
return s.length > 2 && s.charCodeAt(0) === typescript_exports.CharacterCodes.slash && s.charCodeAt(1) === typescript_exports.CharacterCodes.slash;
|
||||
}
|
||||
function watchDirectorySwallowingException(path, callback, recursive, options) {
|
||||
try {
|
||||
return originalWatchDirectory(path, callback, recursive, options);
|
||||
} catch (e) {
|
||||
logger.info(`Exception when creating directory watcher: ${e.message}`);
|
||||
return typescript_exports.noopFileWatcher;
|
||||
}
|
||||
}
|
||||
}
|
||||
function parseEventPort(eventPortStr) {
|
||||
const eventPort = eventPortStr === void 0 ? void 0 : parseInt(eventPortStr);
|
||||
return eventPort !== void 0 && !isNaN(eventPort) ? eventPort : void 0;
|
||||
}
|
||||
function startNodeSession(options, logger, cancellationToken) {
|
||||
const rl = import_readline.default.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
terminal: false
|
||||
});
|
||||
const _NodeTypingsInstallerAdapter = class _NodeTypingsInstallerAdapter extends typescript_exports.server.TypingsInstallerAdapter {
|
||||
constructor(telemetryEnabled2, logger2, host, globalTypingsCacheLocation, typingSafeListLocation2, typesMapLocation2, npmLocation2, validateDefaultNpmLocation2, event) {
|
||||
super(
|
||||
telemetryEnabled2,
|
||||
logger2,
|
||||
host,
|
||||
globalTypingsCacheLocation,
|
||||
event,
|
||||
_NodeTypingsInstallerAdapter.maxActiveRequestCount
|
||||
);
|
||||
this.typingSafeListLocation = typingSafeListLocation2;
|
||||
this.typesMapLocation = typesMapLocation2;
|
||||
this.npmLocation = npmLocation2;
|
||||
this.validateDefaultNpmLocation = validateDefaultNpmLocation2;
|
||||
}
|
||||
createInstallerProcess() {
|
||||
if (this.logger.hasLevel(typescript_exports.server.LogLevel.requestTime)) {
|
||||
this.logger.info("Binding...");
|
||||
}
|
||||
const args = [typescript_exports.server.Arguments.GlobalCacheLocation, this.globalTypingsCacheLocation];
|
||||
if (this.telemetryEnabled) {
|
||||
args.push(typescript_exports.server.Arguments.EnableTelemetry);
|
||||
}
|
||||
if (this.logger.loggingEnabled() && this.logger.getLogFileName()) {
|
||||
args.push(typescript_exports.server.Arguments.LogFile, (0, typescript_exports.combinePaths)((0, typescript_exports.getDirectoryPath)((0, typescript_exports.normalizeSlashes)(this.logger.getLogFileName())), `ti-${process.pid}.log`));
|
||||
}
|
||||
if (this.typingSafeListLocation) {
|
||||
args.push(typescript_exports.server.Arguments.TypingSafeListLocation, this.typingSafeListLocation);
|
||||
}
|
||||
if (this.typesMapLocation) {
|
||||
args.push(typescript_exports.server.Arguments.TypesMapLocation, this.typesMapLocation);
|
||||
}
|
||||
if (this.npmLocation) {
|
||||
args.push(typescript_exports.server.Arguments.NpmLocation, this.npmLocation);
|
||||
}
|
||||
if (this.validateDefaultNpmLocation) {
|
||||
args.push(typescript_exports.server.Arguments.ValidateDefaultNpmLocation);
|
||||
}
|
||||
const execArgv = [];
|
||||
for (const arg of process.execArgv) {
|
||||
const match = /^--((?:debug|inspect)(?:-brk)?)(?:=(\d+))?$/.exec(arg);
|
||||
if (match) {
|
||||
const currentPort = match[2] !== void 0 ? +match[2] : match[1].charAt(0) === "d" ? 5858 : 9229;
|
||||
execArgv.push(`--${match[1]}=${currentPort + 1}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
const typingsInstaller = (0, typescript_exports.combinePaths)((0, typescript_exports.getDirectoryPath)(typescript_exports.sys.getExecutingFilePath()), "typingsInstaller.js");
|
||||
this.installer = import_child_process.default.fork(typingsInstaller, args, { execArgv });
|
||||
this.installer.on("message", (m) => this.handleMessage(m));
|
||||
this.host.setImmediate(() => this.event({ pid: this.installer.pid }, "typingsInstallerPid"));
|
||||
process.on("exit", () => {
|
||||
this.installer.kill();
|
||||
});
|
||||
return this.installer;
|
||||
}
|
||||
};
|
||||
// This number is essentially arbitrary. Processing more than one typings request
|
||||
// at a time makes sense, but having too many in the pipe results in a hang
|
||||
// (see https://github.com/nodejs/node/issues/7657).
|
||||
// It would be preferable to base our limit on the amount of space left in the
|
||||
// buffer, but we have yet to find a way to retrieve that value.
|
||||
_NodeTypingsInstallerAdapter.maxActiveRequestCount = 10;
|
||||
let NodeTypingsInstallerAdapter = _NodeTypingsInstallerAdapter;
|
||||
class IOSession extends typescript_exports.server.Session {
|
||||
constructor() {
|
||||
const event = (body, eventName) => {
|
||||
this.event(body, eventName);
|
||||
};
|
||||
const host = typescript_exports.sys;
|
||||
const typingsInstaller = disableAutomaticTypingAcquisition ? void 0 : new NodeTypingsInstallerAdapter(telemetryEnabled, logger, host, getGlobalTypingsCacheLocation(), typingSafeListLocation, typesMapLocation, npmLocation, validateDefaultNpmLocation, event);
|
||||
super({
|
||||
host,
|
||||
cancellationToken,
|
||||
...options,
|
||||
typingsInstaller,
|
||||
byteLength: Buffer.byteLength,
|
||||
hrtime: process.hrtime,
|
||||
logger,
|
||||
canUseEvents: true,
|
||||
typesMapLocation
|
||||
});
|
||||
this.eventPort = eventPort;
|
||||
if (this.canUseEvents && this.eventPort) {
|
||||
const s = import_net.default.connect({ port: this.eventPort }, () => {
|
||||
this.eventSocket = s;
|
||||
if (this.socketEventQueue) {
|
||||
for (const event2 of this.socketEventQueue) {
|
||||
this.writeToEventSocket(event2.body, event2.eventName);
|
||||
}
|
||||
this.socketEventQueue = void 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
this.constructed = true;
|
||||
}
|
||||
event(body, eventName) {
|
||||
typescript_exports.Debug.assert(!!this.constructed, "Should only call `IOSession.prototype.event` on an initialized IOSession");
|
||||
if (this.canUseEvents && this.eventPort) {
|
||||
if (!this.eventSocket) {
|
||||
if (this.logger.hasLevel(typescript_exports.server.LogLevel.verbose)) {
|
||||
this.logger.info(`eventPort: event "${eventName}" queued, but socket not yet initialized`);
|
||||
}
|
||||
(this.socketEventQueue || (this.socketEventQueue = [])).push({ body, eventName });
|
||||
return;
|
||||
} else {
|
||||
typescript_exports.Debug.assert(this.socketEventQueue === void 0);
|
||||
this.writeToEventSocket(body, eventName);
|
||||
}
|
||||
} else {
|
||||
super.event(body, eventName);
|
||||
}
|
||||
}
|
||||
writeToEventSocket(body, eventName) {
|
||||
this.eventSocket.write(typescript_exports.server.formatMessage(typescript_exports.server.toEvent(eventName, body), this.logger, this.byteLength, this.host.newLine), "utf8");
|
||||
}
|
||||
exit() {
|
||||
var _a;
|
||||
this.logger.info("Exiting...");
|
||||
this.projectService.closeLog();
|
||||
(_a = typescript_exports.tracing) == null ? void 0 : _a.stopTracing();
|
||||
process.exit(0);
|
||||
}
|
||||
listen() {
|
||||
rl.on("line", (input) => {
|
||||
const message = input.trim();
|
||||
this.onMessage(message);
|
||||
});
|
||||
rl.on("close", () => {
|
||||
this.exit();
|
||||
});
|
||||
}
|
||||
}
|
||||
class IpcIOSession extends IOSession {
|
||||
writeMessage(msg) {
|
||||
const verboseLogging = logger.hasLevel(typescript_exports.server.LogLevel.verbose);
|
||||
if (verboseLogging) {
|
||||
const json = JSON.stringify(msg);
|
||||
logger.info(`${msg.type}:${typescript_exports.server.indent(json)}`);
|
||||
}
|
||||
process.send(msg);
|
||||
}
|
||||
parseMessage(message) {
|
||||
return message;
|
||||
}
|
||||
toStringMessage(message) {
|
||||
return JSON.stringify(message, void 0, 2);
|
||||
}
|
||||
listen() {
|
||||
process.on("message", (e) => {
|
||||
this.onMessage(e);
|
||||
});
|
||||
process.on("disconnect", () => {
|
||||
this.exit();
|
||||
});
|
||||
}
|
||||
}
|
||||
const eventPort = parseEventPort(typescript_exports.server.findArgument("--eventPort"));
|
||||
const typingSafeListLocation = typescript_exports.server.findArgument(typescript_exports.server.Arguments.TypingSafeListLocation);
|
||||
const typesMapLocation = typescript_exports.server.findArgument(typescript_exports.server.Arguments.TypesMapLocation) || (0, typescript_exports.combinePaths)((0, typescript_exports.getDirectoryPath)(typescript_exports.sys.getExecutingFilePath()), "typesMap.json");
|
||||
const npmLocation = typescript_exports.server.findArgument(typescript_exports.server.Arguments.NpmLocation);
|
||||
const validateDefaultNpmLocation = typescript_exports.server.hasArgument(typescript_exports.server.Arguments.ValidateDefaultNpmLocation);
|
||||
const disableAutomaticTypingAcquisition = typescript_exports.server.hasArgument("--disableAutomaticTypingAcquisition");
|
||||
const useNodeIpc = typescript_exports.server.hasArgument("--useNodeIpc");
|
||||
const telemetryEnabled = typescript_exports.server.hasArgument(typescript_exports.server.Arguments.EnableTelemetry);
|
||||
const commandLineTraceDir = typescript_exports.server.findArgument("--traceDirectory");
|
||||
const traceDir = commandLineTraceDir ? (0, typescript_exports.stripQuotes)(commandLineTraceDir) : process.env.TSS_TRACE;
|
||||
if (traceDir) {
|
||||
(0, typescript_exports.startTracing)("server", traceDir);
|
||||
}
|
||||
const ioSession = useNodeIpc ? new IpcIOSession() : new IOSession();
|
||||
process.on("uncaughtException", (err) => {
|
||||
ioSession.logError(err, "unknown");
|
||||
});
|
||||
process.noAsar = true;
|
||||
ioSession.listen();
|
||||
function getGlobalTypingsCacheLocation() {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
const basePath = process.env.LOCALAPPDATA || process.env.APPDATA || import_os.default.homedir && import_os.default.homedir() || process.env.USERPROFILE || process.env.HOMEDRIVE && process.env.HOMEPATH && (0, typescript_exports.normalizeSlashes)(process.env.HOMEDRIVE + process.env.HOMEPATH) || import_os.default.tmpdir();
|
||||
return (0, typescript_exports.combinePaths)((0, typescript_exports.combinePaths)((0, typescript_exports.normalizeSlashes)(basePath), "Microsoft/TypeScript"), typescript_exports.versionMajorMinor);
|
||||
}
|
||||
case "openbsd":
|
||||
case "freebsd":
|
||||
case "netbsd":
|
||||
case "darwin":
|
||||
case "linux":
|
||||
case "android": {
|
||||
const cacheLocation = getNonWindowsCacheLocation(process.platform === "darwin");
|
||||
return (0, typescript_exports.combinePaths)((0, typescript_exports.combinePaths)(cacheLocation, "typescript"), typescript_exports.versionMajorMinor);
|
||||
}
|
||||
default:
|
||||
return typescript_exports.Debug.fail(`unsupported platform '${process.platform}'`);
|
||||
}
|
||||
}
|
||||
function getNonWindowsCacheLocation(platformIsDarwin) {
|
||||
if (process.env.XDG_CACHE_HOME) {
|
||||
return process.env.XDG_CACHE_HOME;
|
||||
}
|
||||
const usersDir = platformIsDarwin ? "Users" : "home";
|
||||
const homePath = import_os.default.homedir && import_os.default.homedir() || process.env.HOME || (process.env.LOGNAME || process.env.USER) && `/${usersDir}/${process.env.LOGNAME || process.env.USER}` || import_os.default.tmpdir();
|
||||
const cacheFolder = platformIsDarwin ? "Library/Caches" : ".cache";
|
||||
return (0, typescript_exports.combinePaths)((0, typescript_exports.normalizeSlashes)(homePath), cacheFolder);
|
||||
}
|
||||
}
|
||||
function pipeExists(name) {
|
||||
return import_fs.default.existsSync(name);
|
||||
}
|
||||
function createCancellationToken(args) {
|
||||
let cancellationPipeName;
|
||||
for (let i = 0; i < args.length - 1; i++) {
|
||||
if (args[i] === "--cancellationPipeName") {
|
||||
cancellationPipeName = args[i + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!cancellationPipeName) {
|
||||
return typescript_exports.server.nullCancellationToken;
|
||||
}
|
||||
if (cancellationPipeName.charAt(cancellationPipeName.length - 1) === "*") {
|
||||
const namePrefix = cancellationPipeName.slice(0, -1);
|
||||
if (namePrefix.length === 0 || namePrefix.includes("*")) {
|
||||
throw new Error("Invalid name for template cancellation pipe: it should have length greater than 2 characters and contain only one '*'.");
|
||||
}
|
||||
let perRequestPipeName;
|
||||
let currentRequestId;
|
||||
return {
|
||||
isCancellationRequested: () => perRequestPipeName !== void 0 && pipeExists(perRequestPipeName),
|
||||
setRequest(requestId) {
|
||||
currentRequestId = requestId;
|
||||
perRequestPipeName = namePrefix + requestId;
|
||||
},
|
||||
resetRequest(requestId) {
|
||||
if (currentRequestId !== requestId) {
|
||||
throw new Error(`Mismatched request id, expected ${currentRequestId}, actual ${requestId}`);
|
||||
}
|
||||
perRequestPipeName = void 0;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
isCancellationRequested: () => pipeExists(cancellationPipeName),
|
||||
setRequest: (_requestId) => void 0,
|
||||
resetRequest: (_requestId) => void 0
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// src/tsserver/server.ts
|
||||
function findArgumentStringArray(argName) {
|
||||
const arg = typescript_exports.server.findArgument(argName);
|
||||
if (arg === void 0) {
|
||||
return typescript_exports.emptyArray;
|
||||
}
|
||||
return arg.split(",").filter((name) => name !== "");
|
||||
}
|
||||
function start({ args, logger, cancellationToken, serverMode, unknownServerMode, startSession: startServer }, platform) {
|
||||
logger.info(`Starting TS Server`);
|
||||
logger.info(`Version: ${typescript_exports.version}`);
|
||||
logger.info(`Arguments: ${args.join(" ")}`);
|
||||
logger.info(`Platform: ${platform} NodeVersion: ${process.version} CaseSensitive: ${typescript_exports.sys.useCaseSensitiveFileNames}`);
|
||||
logger.info(`ServerMode: ${serverMode} hasUnknownServerMode: ${unknownServerMode}`);
|
||||
typescript_exports.setStackTraceLimit();
|
||||
if (typescript_exports.Debug.isDebugging) {
|
||||
typescript_exports.Debug.enableDebugInfo();
|
||||
}
|
||||
if (typescript_exports.sys.tryEnableSourceMapsForHost && /^development$/i.test(typescript_exports.sys.getEnvironmentVariable("NODE_ENV"))) {
|
||||
typescript_exports.sys.tryEnableSourceMapsForHost();
|
||||
}
|
||||
console.log = (...args2) => logger.msg(args2.length === 1 ? args2[0] : args2.join(", "), typescript_exports.server.Msg.Info);
|
||||
console.warn = (...args2) => logger.msg(args2.length === 1 ? args2[0] : args2.join(", "), typescript_exports.server.Msg.Err);
|
||||
console.error = (...args2) => logger.msg(args2.length === 1 ? args2[0] : args2.join(", "), typescript_exports.server.Msg.Err);
|
||||
startServer(
|
||||
{
|
||||
globalPlugins: findArgumentStringArray("--globalPlugins"),
|
||||
pluginProbeLocations: findArgumentStringArray("--pluginProbeLocations"),
|
||||
allowLocalPluginLoads: typescript_exports.server.hasArgument("--allowLocalPluginLoads"),
|
||||
useSingleInferredProject: typescript_exports.server.hasArgument("--useSingleInferredProject"),
|
||||
useInferredProjectPerProjectRoot: typescript_exports.server.hasArgument("--useInferredProjectPerProjectRoot"),
|
||||
suppressDiagnosticEvents: typescript_exports.server.hasArgument("--suppressDiagnosticEvents"),
|
||||
noGetErrOnBackgroundUpdate: typescript_exports.server.hasArgument("--noGetErrOnBackgroundUpdate"),
|
||||
canUseWatchEvents: typescript_exports.server.hasArgument("--canUseWatchEvents"),
|
||||
serverMode
|
||||
},
|
||||
logger,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
typescript_exports.setStackTraceLimit();
|
||||
start(initializeNodeSystem(), import_os2.default.platform());
|
||||
//# sourceMappingURL=_tsserver.js.map
|
||||
+222
@@ -0,0 +1,222 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
|
||||
// src/typingsInstaller/nodeTypingsInstaller.ts
|
||||
var import_child_process = require("child_process");
|
||||
var fs = __toESM(require("fs"));
|
||||
var path = __toESM(require("path"));
|
||||
|
||||
// src/typescript/typescript.ts
|
||||
var typescript_exports = {};
|
||||
__reExport(typescript_exports, require("./typescript.js"));
|
||||
|
||||
// src/typingsInstaller/nodeTypingsInstaller.ts
|
||||
var FileLog = class {
|
||||
constructor(logFile) {
|
||||
this.logFile = logFile;
|
||||
this.isEnabled = () => {
|
||||
return typeof this.logFile === "string";
|
||||
};
|
||||
this.writeLine = (text) => {
|
||||
if (typeof this.logFile !== "string") return;
|
||||
try {
|
||||
fs.appendFileSync(this.logFile, `[${typescript_exports.server.nowString()}] ${text}${typescript_exports.sys.newLine}`);
|
||||
} catch {
|
||||
this.logFile = void 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
function getDefaultNPMLocation(processName, validateDefaultNpmLocation2, host) {
|
||||
if (path.basename(processName).indexOf("node") === 0) {
|
||||
const npmPath = path.join(path.dirname(process.argv[0]), "npm");
|
||||
if (!validateDefaultNpmLocation2) {
|
||||
return npmPath;
|
||||
}
|
||||
if (host.fileExists(npmPath)) {
|
||||
return `"${npmPath}"`;
|
||||
}
|
||||
}
|
||||
return "npm";
|
||||
}
|
||||
function loadTypesRegistryFile(typesRegistryFilePath, host, log2) {
|
||||
if (!host.fileExists(typesRegistryFilePath)) {
|
||||
if (log2.isEnabled()) {
|
||||
log2.writeLine(`Types registry file '${typesRegistryFilePath}' does not exist`);
|
||||
}
|
||||
return /* @__PURE__ */ new Map();
|
||||
}
|
||||
try {
|
||||
const content = JSON.parse(host.readFile(typesRegistryFilePath));
|
||||
return new Map(Object.entries(content.entries));
|
||||
} catch (e) {
|
||||
if (log2.isEnabled()) {
|
||||
log2.writeLine(`Error when loading types registry file '${typesRegistryFilePath}': ${e.message}, ${e.stack}`);
|
||||
}
|
||||
return /* @__PURE__ */ new Map();
|
||||
}
|
||||
}
|
||||
var typesRegistryPackageName = "types-registry";
|
||||
function getTypesRegistryFileLocation(globalTypingsCacheLocation2) {
|
||||
return (0, typescript_exports.combinePaths)((0, typescript_exports.normalizeSlashes)(globalTypingsCacheLocation2), `node_modules/${typesRegistryPackageName}/index.json`);
|
||||
}
|
||||
var NodeTypingsInstaller = class extends typescript_exports.server.typingsInstaller.TypingsInstaller {
|
||||
constructor(globalTypingsCacheLocation2, typingSafeListLocation2, typesMapLocation2, npmLocation2, validateDefaultNpmLocation2, throttleLimit, log2) {
|
||||
const libDirectory = (0, typescript_exports.getDirectoryPath)((0, typescript_exports.normalizePath)(typescript_exports.sys.getExecutingFilePath()));
|
||||
super(
|
||||
typescript_exports.sys,
|
||||
globalTypingsCacheLocation2,
|
||||
typingSafeListLocation2 ? (0, typescript_exports.toPath)(typingSafeListLocation2, "", (0, typescript_exports.createGetCanonicalFileName)(typescript_exports.sys.useCaseSensitiveFileNames)) : (0, typescript_exports.toPath)("typingSafeList.json", libDirectory, (0, typescript_exports.createGetCanonicalFileName)(typescript_exports.sys.useCaseSensitiveFileNames)),
|
||||
typesMapLocation2 ? (0, typescript_exports.toPath)(typesMapLocation2, "", (0, typescript_exports.createGetCanonicalFileName)(typescript_exports.sys.useCaseSensitiveFileNames)) : (0, typescript_exports.toPath)("typesMap.json", libDirectory, (0, typescript_exports.createGetCanonicalFileName)(typescript_exports.sys.useCaseSensitiveFileNames)),
|
||||
throttleLimit,
|
||||
log2
|
||||
);
|
||||
this.npmPath = npmLocation2 !== void 0 ? npmLocation2 : getDefaultNPMLocation(process.argv[0], validateDefaultNpmLocation2, this.installTypingHost);
|
||||
if (this.npmPath.includes(" ") && this.npmPath[0] !== `"`) {
|
||||
this.npmPath = `"${this.npmPath}"`;
|
||||
}
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Process id: ${process.pid}`);
|
||||
this.log.writeLine(`NPM location: ${this.npmPath} (explicit '${typescript_exports.server.Arguments.NpmLocation}' ${npmLocation2 === void 0 ? "not " : ""} provided)`);
|
||||
this.log.writeLine(`validateDefaultNpmLocation: ${validateDefaultNpmLocation2}`);
|
||||
}
|
||||
this.ensurePackageDirectoryExists(globalTypingsCacheLocation2);
|
||||
try {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Updating ${typesRegistryPackageName} npm package...`);
|
||||
}
|
||||
this.execSyncAndLog(`${this.npmPath} install --ignore-scripts ${typesRegistryPackageName}@${this.latestDistTag}`, { cwd: globalTypingsCacheLocation2 });
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Updated ${typesRegistryPackageName} npm package`);
|
||||
}
|
||||
} catch (e) {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Error updating ${typesRegistryPackageName} package: ${e.message}`);
|
||||
}
|
||||
this.delayedInitializationError = {
|
||||
kind: "event::initializationFailed",
|
||||
message: e.message,
|
||||
stack: e.stack
|
||||
};
|
||||
}
|
||||
this.typesRegistry = loadTypesRegistryFile(getTypesRegistryFileLocation(globalTypingsCacheLocation2), this.installTypingHost, this.log);
|
||||
}
|
||||
handleRequest(req) {
|
||||
if (this.delayedInitializationError) {
|
||||
this.sendResponse(this.delayedInitializationError);
|
||||
this.delayedInitializationError = void 0;
|
||||
}
|
||||
super.handleRequest(req);
|
||||
}
|
||||
sendResponse(response) {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Sending response:${typescript_exports.server.stringifyIndented(response)}`);
|
||||
}
|
||||
process.send(response);
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Response has been sent.`);
|
||||
}
|
||||
}
|
||||
installWorker(requestId, packageNames, cwd, onRequestCompleted) {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`#${requestId} with cwd: ${cwd} arguments: ${JSON.stringify(packageNames)}`);
|
||||
}
|
||||
const start = Date.now();
|
||||
const hasError = typescript_exports.server.typingsInstaller.installNpmPackages(this.npmPath, typescript_exports.version, packageNames, (command) => this.execSyncAndLog(command, { cwd }));
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms`);
|
||||
}
|
||||
onRequestCompleted(!hasError);
|
||||
}
|
||||
/** Returns 'true' in case of error. */
|
||||
execSyncAndLog(command, options) {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Exec: ${command}`);
|
||||
}
|
||||
try {
|
||||
const stdout = (0, import_child_process.execSync)(command, { ...options, encoding: "utf-8" });
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(` Succeeded. stdout:${indent(typescript_exports.sys.newLine, stdout)}`);
|
||||
}
|
||||
return false;
|
||||
} catch (error) {
|
||||
const { stdout, stderr } = error;
|
||||
this.log.writeLine(` Failed. stdout:${indent(typescript_exports.sys.newLine, stdout)}${typescript_exports.sys.newLine} stderr:${indent(typescript_exports.sys.newLine, stderr)}`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
var logFilePath = typescript_exports.server.findArgument(typescript_exports.server.Arguments.LogFile);
|
||||
var globalTypingsCacheLocation = typescript_exports.server.findArgument(typescript_exports.server.Arguments.GlobalCacheLocation);
|
||||
var typingSafeListLocation = typescript_exports.server.findArgument(typescript_exports.server.Arguments.TypingSafeListLocation);
|
||||
var typesMapLocation = typescript_exports.server.findArgument(typescript_exports.server.Arguments.TypesMapLocation);
|
||||
var npmLocation = typescript_exports.server.findArgument(typescript_exports.server.Arguments.NpmLocation);
|
||||
var validateDefaultNpmLocation = typescript_exports.server.hasArgument(typescript_exports.server.Arguments.ValidateDefaultNpmLocation);
|
||||
var log = new FileLog(logFilePath);
|
||||
if (log.isEnabled()) {
|
||||
process.on("uncaughtException", (e) => {
|
||||
log.writeLine(`Unhandled exception: ${e} at ${e.stack}`);
|
||||
});
|
||||
}
|
||||
process.on("disconnect", () => {
|
||||
if (log.isEnabled()) {
|
||||
log.writeLine(`Parent process has exited, shutting down...`);
|
||||
}
|
||||
process.exit(0);
|
||||
});
|
||||
var installer;
|
||||
process.on("message", (req) => {
|
||||
installer ?? (installer = new NodeTypingsInstaller(
|
||||
globalTypingsCacheLocation,
|
||||
typingSafeListLocation,
|
||||
typesMapLocation,
|
||||
npmLocation,
|
||||
validateDefaultNpmLocation,
|
||||
/*throttleLimit*/
|
||||
5,
|
||||
log
|
||||
));
|
||||
installer.handleRequest(req);
|
||||
});
|
||||
function indent(newline, str) {
|
||||
return str && str.length ? `${newline} ` + str.replace(/\r?\n/, `${newline} `) : "";
|
||||
}
|
||||
//# sourceMappingURL=_typingsInstaller.js.map
|
||||
+2129
File diff suppressed because it is too large
Load Diff
+2125
File diff suppressed because it is too large
Load Diff
+2129
File diff suppressed because it is too large
Load Diff
+2129
File diff suppressed because it is too large
Load Diff
+2125
File diff suppressed because it is too large
Load Diff
+2129
File diff suppressed because it is too large
Load Diff
+2129
File diff suppressed because it is too large
Load Diff
+20
@@ -0,0 +1,20 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es5" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="webworker.importscripts" />
|
||||
/// <reference lib="scripthost" />
|
||||
+382
@@ -0,0 +1,382 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/**
|
||||
* The decorator context types provided to class element decorators.
|
||||
*/
|
||||
type ClassMemberDecoratorContext =
|
||||
| ClassMethodDecoratorContext
|
||||
| ClassGetterDecoratorContext
|
||||
| ClassSetterDecoratorContext
|
||||
| ClassFieldDecoratorContext
|
||||
| ClassAccessorDecoratorContext;
|
||||
|
||||
/**
|
||||
* The decorator context types provided to any decorator.
|
||||
*/
|
||||
type DecoratorContext =
|
||||
| ClassDecoratorContext
|
||||
| ClassMemberDecoratorContext;
|
||||
|
||||
type DecoratorMetadataObject = Record<PropertyKey, unknown> & object;
|
||||
|
||||
type DecoratorMetadata = typeof globalThis extends { Symbol: { readonly metadata: symbol; }; } ? DecoratorMetadataObject : DecoratorMetadataObject | undefined;
|
||||
|
||||
/**
|
||||
* Context provided to a class decorator.
|
||||
* @template Class The type of the decorated class associated with this context.
|
||||
*/
|
||||
interface ClassDecoratorContext<
|
||||
Class extends abstract new (...args: any) => any = abstract new (...args: any) => any,
|
||||
> {
|
||||
/** The kind of element that was decorated. */
|
||||
readonly kind: "class";
|
||||
|
||||
/** The name of the decorated class. */
|
||||
readonly name: string | undefined;
|
||||
|
||||
/**
|
||||
* Adds a callback to be invoked after the class definition has been finalized.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* function customElement(name: string): ClassDecoratorFunction {
|
||||
* return (target, context) => {
|
||||
* context.addInitializer(function () {
|
||||
* customElements.define(name, this);
|
||||
* });
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @customElement("my-element")
|
||||
* class MyElement {}
|
||||
* ```
|
||||
*/
|
||||
addInitializer(initializer: (this: Class) => void): void;
|
||||
|
||||
readonly metadata: DecoratorMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context provided to a class method decorator.
|
||||
* @template This The type on which the class element will be defined. For a static class element, this will be
|
||||
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
||||
* @template Value The type of the decorated class method.
|
||||
*/
|
||||
interface ClassMethodDecoratorContext<
|
||||
This = unknown,
|
||||
Value extends (this: This, ...args: any) => any = (this: This, ...args: any) => any,
|
||||
> {
|
||||
/** The kind of class element that was decorated. */
|
||||
readonly kind: "method";
|
||||
|
||||
/** The name of the decorated class element. */
|
||||
readonly name: string | symbol;
|
||||
|
||||
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
||||
readonly static: boolean;
|
||||
|
||||
/** A value indicating whether the class element has a private name. */
|
||||
readonly private: boolean;
|
||||
|
||||
/** An object that can be used to access the current value of the class element at runtime. */
|
||||
readonly access: {
|
||||
/**
|
||||
* Determines whether an object has a property with the same name as the decorated element.
|
||||
*/
|
||||
has(object: This): boolean;
|
||||
/**
|
||||
* Gets the current value of the method from the provided object.
|
||||
*
|
||||
* @example
|
||||
* let fn = context.access.get(instance);
|
||||
*/
|
||||
get(object: This): Value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a callback to be invoked either after static methods are defined but before
|
||||
* static initializers are run (when decorating a `static` element), or before instance
|
||||
* initializers are run (when decorating a non-`static` element).
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const bound: ClassMethodDecoratorFunction = (value, context) {
|
||||
* if (context.private) throw new TypeError("Not supported on private methods.");
|
||||
* context.addInitializer(function () {
|
||||
* this[context.name] = this[context.name].bind(this);
|
||||
* });
|
||||
* }
|
||||
*
|
||||
* class C {
|
||||
* message = "Hello";
|
||||
*
|
||||
* @bound
|
||||
* m() {
|
||||
* console.log(this.message);
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
addInitializer(initializer: (this: This) => void): void;
|
||||
|
||||
readonly metadata: DecoratorMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context provided to a class getter decorator.
|
||||
* @template This The type on which the class element will be defined. For a static class element, this will be
|
||||
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
||||
* @template Value The property type of the decorated class getter.
|
||||
*/
|
||||
interface ClassGetterDecoratorContext<
|
||||
This = unknown,
|
||||
Value = unknown,
|
||||
> {
|
||||
/** The kind of class element that was decorated. */
|
||||
readonly kind: "getter";
|
||||
|
||||
/** The name of the decorated class element. */
|
||||
readonly name: string | symbol;
|
||||
|
||||
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
||||
readonly static: boolean;
|
||||
|
||||
/** A value indicating whether the class element has a private name. */
|
||||
readonly private: boolean;
|
||||
|
||||
/** An object that can be used to access the current value of the class element at runtime. */
|
||||
readonly access: {
|
||||
/**
|
||||
* Determines whether an object has a property with the same name as the decorated element.
|
||||
*/
|
||||
has(object: This): boolean;
|
||||
/**
|
||||
* Invokes the getter on the provided object.
|
||||
*
|
||||
* @example
|
||||
* let value = context.access.get(instance);
|
||||
*/
|
||||
get(object: This): Value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a callback to be invoked either after static methods are defined but before
|
||||
* static initializers are run (when decorating a `static` element), or before instance
|
||||
* initializers are run (when decorating a non-`static` element).
|
||||
*/
|
||||
addInitializer(initializer: (this: This) => void): void;
|
||||
|
||||
readonly metadata: DecoratorMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context provided to a class setter decorator.
|
||||
* @template This The type on which the class element will be defined. For a static class element, this will be
|
||||
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
||||
* @template Value The type of the decorated class setter.
|
||||
*/
|
||||
interface ClassSetterDecoratorContext<
|
||||
This = unknown,
|
||||
Value = unknown,
|
||||
> {
|
||||
/** The kind of class element that was decorated. */
|
||||
readonly kind: "setter";
|
||||
|
||||
/** The name of the decorated class element. */
|
||||
readonly name: string | symbol;
|
||||
|
||||
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
||||
readonly static: boolean;
|
||||
|
||||
/** A value indicating whether the class element has a private name. */
|
||||
readonly private: boolean;
|
||||
|
||||
/** An object that can be used to access the current value of the class element at runtime. */
|
||||
readonly access: {
|
||||
/**
|
||||
* Determines whether an object has a property with the same name as the decorated element.
|
||||
*/
|
||||
has(object: This): boolean;
|
||||
/**
|
||||
* Invokes the setter on the provided object.
|
||||
*
|
||||
* @example
|
||||
* context.access.set(instance, value);
|
||||
*/
|
||||
set(object: This, value: Value): void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a callback to be invoked either after static methods are defined but before
|
||||
* static initializers are run (when decorating a `static` element), or before instance
|
||||
* initializers are run (when decorating a non-`static` element).
|
||||
*/
|
||||
addInitializer(initializer: (this: This) => void): void;
|
||||
|
||||
readonly metadata: DecoratorMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context provided to a class `accessor` field decorator.
|
||||
* @template This The type on which the class element will be defined. For a static class element, this will be
|
||||
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
||||
* @template Value The type of decorated class field.
|
||||
*/
|
||||
interface ClassAccessorDecoratorContext<
|
||||
This = unknown,
|
||||
Value = unknown,
|
||||
> {
|
||||
/** The kind of class element that was decorated. */
|
||||
readonly kind: "accessor";
|
||||
|
||||
/** The name of the decorated class element. */
|
||||
readonly name: string | symbol;
|
||||
|
||||
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
||||
readonly static: boolean;
|
||||
|
||||
/** A value indicating whether the class element has a private name. */
|
||||
readonly private: boolean;
|
||||
|
||||
/** An object that can be used to access the current value of the class element at runtime. */
|
||||
readonly access: {
|
||||
/**
|
||||
* Determines whether an object has a property with the same name as the decorated element.
|
||||
*/
|
||||
has(object: This): boolean;
|
||||
|
||||
/**
|
||||
* Invokes the getter on the provided object.
|
||||
*
|
||||
* @example
|
||||
* let value = context.access.get(instance);
|
||||
*/
|
||||
get(object: This): Value;
|
||||
|
||||
/**
|
||||
* Invokes the setter on the provided object.
|
||||
*
|
||||
* @example
|
||||
* context.access.set(instance, value);
|
||||
*/
|
||||
set(object: This, value: Value): void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a callback to be invoked immediately after the auto `accessor` being
|
||||
* decorated is initialized (regardless if the `accessor` is `static` or not).
|
||||
*/
|
||||
addInitializer(initializer: (this: This) => void): void;
|
||||
|
||||
readonly metadata: DecoratorMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the target provided to class `accessor` field decorators.
|
||||
* @template This The `this` type to which the target applies.
|
||||
* @template Value The property type for the class `accessor` field.
|
||||
*/
|
||||
interface ClassAccessorDecoratorTarget<This, Value> {
|
||||
/**
|
||||
* Invokes the getter that was defined prior to decorator application.
|
||||
*
|
||||
* @example
|
||||
* let value = target.get.call(instance);
|
||||
*/
|
||||
get(this: This): Value;
|
||||
|
||||
/**
|
||||
* Invokes the setter that was defined prior to decorator application.
|
||||
*
|
||||
* @example
|
||||
* target.set.call(instance, value);
|
||||
*/
|
||||
set(this: This, value: Value): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the allowed return value from a class `accessor` field decorator.
|
||||
* @template This The `this` type to which the target applies.
|
||||
* @template Value The property type for the class `accessor` field.
|
||||
*/
|
||||
interface ClassAccessorDecoratorResult<This, Value> {
|
||||
/**
|
||||
* An optional replacement getter function. If not provided, the existing getter function is used instead.
|
||||
*/
|
||||
get?(this: This): Value;
|
||||
|
||||
/**
|
||||
* An optional replacement setter function. If not provided, the existing setter function is used instead.
|
||||
*/
|
||||
set?(this: This, value: Value): void;
|
||||
|
||||
/**
|
||||
* An optional initializer mutator that is invoked when the underlying field initializer is evaluated.
|
||||
* @param value The incoming initializer value.
|
||||
* @returns The replacement initializer value.
|
||||
*/
|
||||
init?(this: This, value: Value): Value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context provided to a class field decorator.
|
||||
* @template This The type on which the class element will be defined. For a static class element, this will be
|
||||
* the type of the constructor. For a non-static class element, this will be the type of the instance.
|
||||
* @template Value The type of the decorated class field.
|
||||
*/
|
||||
interface ClassFieldDecoratorContext<
|
||||
This = unknown,
|
||||
Value = unknown,
|
||||
> {
|
||||
/** The kind of class element that was decorated. */
|
||||
readonly kind: "field";
|
||||
|
||||
/** The name of the decorated class element. */
|
||||
readonly name: string | symbol;
|
||||
|
||||
/** A value indicating whether the class element is a static (`true`) or instance (`false`) element. */
|
||||
readonly static: boolean;
|
||||
|
||||
/** A value indicating whether the class element has a private name. */
|
||||
readonly private: boolean;
|
||||
|
||||
/** An object that can be used to access the current value of the class element at runtime. */
|
||||
readonly access: {
|
||||
/**
|
||||
* Determines whether an object has a property with the same name as the decorated element.
|
||||
*/
|
||||
has(object: This): boolean;
|
||||
|
||||
/**
|
||||
* Gets the value of the field on the provided object.
|
||||
*/
|
||||
get(object: This): Value;
|
||||
|
||||
/**
|
||||
* Sets the value of the field on the provided object.
|
||||
*/
|
||||
set(object: This, value: Value): void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a callback to be invoked immediately after the field being decorated
|
||||
* is initialized (regardless if the field is `static` or not).
|
||||
*/
|
||||
addInitializer(initializer: (this: This) => void): void;
|
||||
|
||||
readonly metadata: DecoratorMetadata;
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
|
||||
declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;
|
||||
declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
|
||||
declare type ParameterDecorator = (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
// This file's contents are now included in the main types file.
|
||||
// The file has been left for backward compatibility.
|
||||
+45125
File diff suppressed because it is too large
Load Diff
+18
@@ -0,0 +1,18 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
// This file's contents are now included in the main types file.
|
||||
// The file has been left for backward compatibility.
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface Map<K, V> {
|
||||
/**
|
||||
* Removes all elements from the Map.
|
||||
*/
|
||||
clear(): void;
|
||||
/**
|
||||
* @returns true if an element in the Map existed and has been removed, or false if the element does not exist.
|
||||
*/
|
||||
delete(key: K): boolean;
|
||||
/**
|
||||
* Executes a provided function once per each key/value pair in the Map, in insertion order.
|
||||
*/
|
||||
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
|
||||
/**
|
||||
* Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
|
||||
* @returns Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.
|
||||
*/
|
||||
get(key: K): V | undefined;
|
||||
/**
|
||||
* @returns boolean indicating whether an element with the specified key exists or not.
|
||||
*/
|
||||
has(key: K): boolean;
|
||||
/**
|
||||
* Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
|
||||
*/
|
||||
set(key: K, value: V): this;
|
||||
/**
|
||||
* @returns the number of elements in the Map.
|
||||
*/
|
||||
readonly size: number;
|
||||
}
|
||||
|
||||
interface MapConstructor {
|
||||
new (): Map<any, any>;
|
||||
new <K, V>(entries?: readonly (readonly [K, V])[] | null): Map<K, V>;
|
||||
readonly prototype: Map<any, any>;
|
||||
}
|
||||
declare var Map: MapConstructor;
|
||||
|
||||
interface ReadonlyMap<K, V> {
|
||||
forEach(callbackfn: (value: V, key: K, map: ReadonlyMap<K, V>) => void, thisArg?: any): void;
|
||||
get(key: K): V | undefined;
|
||||
has(key: K): boolean;
|
||||
readonly size: number;
|
||||
}
|
||||
|
||||
interface WeakMap<K extends WeakKey, V> {
|
||||
/**
|
||||
* Removes the specified element from the WeakMap.
|
||||
* @returns true if the element was successfully removed, or false if it was not present.
|
||||
*/
|
||||
delete(key: K): boolean;
|
||||
/**
|
||||
* @returns a specified element.
|
||||
*/
|
||||
get(key: K): V | undefined;
|
||||
/**
|
||||
* @returns a boolean indicating whether an element with the specified key exists or not.
|
||||
*/
|
||||
has(key: K): boolean;
|
||||
/**
|
||||
* Adds a new element with a specified key and value.
|
||||
* @param key Must be an object or symbol.
|
||||
*/
|
||||
set(key: K, value: V): this;
|
||||
}
|
||||
|
||||
interface WeakMapConstructor {
|
||||
new <K extends WeakKey = WeakKey, V = any>(entries?: readonly (readonly [K, V])[] | null): WeakMap<K, V>;
|
||||
readonly prototype: WeakMap<WeakKey, any>;
|
||||
}
|
||||
declare var WeakMap: WeakMapConstructor;
|
||||
|
||||
interface Set<T> {
|
||||
/**
|
||||
* Appends a new element with a specified value to the end of the Set.
|
||||
*/
|
||||
add(value: T): this;
|
||||
/**
|
||||
* Removes all elements from the Set.
|
||||
*/
|
||||
clear(): void;
|
||||
/**
|
||||
* Removes a specified value from the Set.
|
||||
* @returns Returns true if an element in the Set existed and has been removed, or false if the element does not exist.
|
||||
*/
|
||||
delete(value: T): boolean;
|
||||
/**
|
||||
* Executes a provided function once per each value in the Set object, in insertion order.
|
||||
*/
|
||||
forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void;
|
||||
/**
|
||||
* @returns a boolean indicating whether an element with the specified value exists in the Set or not.
|
||||
*/
|
||||
has(value: T): boolean;
|
||||
/**
|
||||
* @returns the number of (unique) elements in Set.
|
||||
*/
|
||||
readonly size: number;
|
||||
}
|
||||
|
||||
interface SetConstructor {
|
||||
new <T = any>(values?: readonly T[] | null): Set<T>;
|
||||
readonly prototype: Set<any>;
|
||||
}
|
||||
declare var Set: SetConstructor;
|
||||
|
||||
interface ReadonlySet<T> {
|
||||
forEach(callbackfn: (value: T, value2: T, set: ReadonlySet<T>) => void, thisArg?: any): void;
|
||||
has(value: T): boolean;
|
||||
readonly size: number;
|
||||
}
|
||||
|
||||
interface WeakSet<T extends WeakKey> {
|
||||
/**
|
||||
* Appends a new value to the end of the WeakSet.
|
||||
*/
|
||||
add(value: T): this;
|
||||
/**
|
||||
* Removes the specified element from the WeakSet.
|
||||
* @returns Returns true if the element existed and has been removed, or false if the element does not exist.
|
||||
*/
|
||||
delete(value: T): boolean;
|
||||
/**
|
||||
* @returns a boolean indicating whether a value exists in the WeakSet or not.
|
||||
*/
|
||||
has(value: T): boolean;
|
||||
}
|
||||
|
||||
interface WeakSetConstructor {
|
||||
new <T extends WeakKey = WeakKey>(values?: readonly T[] | null): WeakSet<T>;
|
||||
readonly prototype: WeakSet<WeakKey>;
|
||||
}
|
||||
declare var WeakSet: WeakSetConstructor;
|
||||
+595
@@ -0,0 +1,595 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface Array<T> {
|
||||
/**
|
||||
* Returns the value of the first element in the array where predicate is true, and undefined
|
||||
* otherwise.
|
||||
* @param predicate find calls predicate once for each element of the array, in ascending
|
||||
* order, until it finds one where predicate returns true. If such an element is found, find
|
||||
* immediately returns that element value. Otherwise, find returns undefined.
|
||||
* @param thisArg If provided, it will be used as the this value for each invocation of
|
||||
* predicate. If it is not provided, undefined is used instead.
|
||||
*/
|
||||
find<S extends T>(predicate: (value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined;
|
||||
find(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined;
|
||||
|
||||
/**
|
||||
* Returns the index of the first element in the array where predicate is true, and -1
|
||||
* otherwise.
|
||||
* @param predicate find calls predicate once for each element of the array, in ascending
|
||||
* order, until it finds one where predicate returns true. If such an element is found,
|
||||
* findIndex immediately returns that element index. Otherwise, findIndex returns -1.
|
||||
* @param thisArg If provided, it will be used as the this value for each invocation of
|
||||
* predicate. If it is not provided, undefined is used instead.
|
||||
*/
|
||||
findIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number;
|
||||
|
||||
/**
|
||||
* Changes all array elements from `start` to `end` index to a static `value` and returns the modified array
|
||||
* @param value value to fill array section with
|
||||
* @param start index to start filling the array at. If start is negative, it is treated as
|
||||
* length+start where length is the length of the array.
|
||||
* @param end index to stop filling the array at. If end is negative, it is treated as
|
||||
* length+end.
|
||||
*/
|
||||
fill(value: T, start?: number, end?: number): this;
|
||||
|
||||
/**
|
||||
* Returns the this object after copying a section of the array identified by start and end
|
||||
* to the same array starting at position target
|
||||
* @param target If target is negative, it is treated as length+target where length is the
|
||||
* length of the array.
|
||||
* @param start If start is negative, it is treated as length+start. If end is negative, it
|
||||
* is treated as length+end.
|
||||
* @param end If not specified, length of the this object is used as its default value.
|
||||
*/
|
||||
copyWithin(target: number, start: number, end?: number): this;
|
||||
|
||||
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string;
|
||||
}
|
||||
|
||||
interface ArrayConstructor {
|
||||
/**
|
||||
* Creates an array from an array-like object.
|
||||
* @param arrayLike An array-like object to convert to an array.
|
||||
*/
|
||||
from<T>(arrayLike: ArrayLike<T>): T[];
|
||||
|
||||
/**
|
||||
* Creates an array from an iterable object.
|
||||
* @param arrayLike An array-like object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
|
||||
|
||||
/**
|
||||
* Returns a new array from a set of elements.
|
||||
* @param items A set of elements to include in the new array object.
|
||||
*/
|
||||
of<T>(...items: T[]): T[];
|
||||
}
|
||||
|
||||
interface DateConstructor {
|
||||
new (value: number | string | Date): Date;
|
||||
}
|
||||
|
||||
interface Function {
|
||||
/**
|
||||
* Returns the name of the function. Function names are read-only and can not be changed.
|
||||
*/
|
||||
readonly name: string;
|
||||
}
|
||||
|
||||
interface Math {
|
||||
/**
|
||||
* Returns the number of leading zero bits in the 32-bit binary representation of a number.
|
||||
* @param x A numeric expression.
|
||||
*/
|
||||
clz32(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the result of 32-bit multiplication of two numbers.
|
||||
* @param x First number
|
||||
* @param y Second number
|
||||
*/
|
||||
imul(x: number, y: number): number;
|
||||
|
||||
/**
|
||||
* Returns the sign of the x, indicating whether x is positive, negative or zero.
|
||||
* @param x The numeric expression to test
|
||||
*/
|
||||
sign(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the base 10 logarithm of a number.
|
||||
* @param x A numeric expression.
|
||||
*/
|
||||
log10(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the base 2 logarithm of a number.
|
||||
* @param x A numeric expression.
|
||||
*/
|
||||
log2(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the natural logarithm of 1 + x.
|
||||
* @param x A numeric expression.
|
||||
*/
|
||||
log1p(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the result of (e^x - 1), which is an implementation-dependent approximation to
|
||||
* subtracting 1 from the exponential function of x (e raised to the power of x, where e
|
||||
* is the base of the natural logarithms).
|
||||
* @param x A numeric expression.
|
||||
*/
|
||||
expm1(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the hyperbolic cosine of a number.
|
||||
* @param x A numeric expression that contains an angle measured in radians.
|
||||
*/
|
||||
cosh(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the hyperbolic sine of a number.
|
||||
* @param x A numeric expression that contains an angle measured in radians.
|
||||
*/
|
||||
sinh(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the hyperbolic tangent of a number.
|
||||
* @param x A numeric expression that contains an angle measured in radians.
|
||||
*/
|
||||
tanh(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the inverse hyperbolic cosine of a number.
|
||||
* @param x A numeric expression that contains an angle measured in radians.
|
||||
*/
|
||||
acosh(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the inverse hyperbolic sine of a number.
|
||||
* @param x A numeric expression that contains an angle measured in radians.
|
||||
*/
|
||||
asinh(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the inverse hyperbolic tangent of a number.
|
||||
* @param x A numeric expression that contains an angle measured in radians.
|
||||
*/
|
||||
atanh(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the square root of the sum of squares of its arguments.
|
||||
* @param values Values to compute the square root for.
|
||||
* If no arguments are passed, the result is +0.
|
||||
* If there is only one argument, the result is the absolute value.
|
||||
* If any argument is +Infinity or -Infinity, the result is +Infinity.
|
||||
* If any argument is NaN, the result is NaN.
|
||||
* If all arguments are either +0 or −0, the result is +0.
|
||||
*/
|
||||
hypot(...values: number[]): number;
|
||||
|
||||
/**
|
||||
* Returns the integral part of the numeric expression x, removing any fractional digits.
|
||||
* If x is already an integer, the result is x.
|
||||
* @param x A numeric expression.
|
||||
*/
|
||||
trunc(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns the nearest single precision float representation of a number.
|
||||
* @param x A numeric expression.
|
||||
*/
|
||||
fround(x: number): number;
|
||||
|
||||
/**
|
||||
* Returns an implementation-dependent approximation to the cube root of number.
|
||||
* @param x A numeric expression.
|
||||
*/
|
||||
cbrt(x: number): number;
|
||||
}
|
||||
|
||||
interface NumberConstructor {
|
||||
/**
|
||||
* The value of Number.EPSILON is the difference between 1 and the smallest value greater than 1
|
||||
* that is representable as a Number value, which is approximately:
|
||||
* 2.2204460492503130808472633361816 x 10−16.
|
||||
*/
|
||||
readonly EPSILON: number;
|
||||
|
||||
/**
|
||||
* Returns true if passed value is finite.
|
||||
* Unlike the global isFinite, Number.isFinite doesn't forcibly convert the parameter to a
|
||||
* number. Only finite values of the type number, result in true.
|
||||
* @param number A numeric value.
|
||||
*/
|
||||
isFinite(number: unknown): boolean;
|
||||
|
||||
/**
|
||||
* Returns true if the value passed is an integer, false otherwise.
|
||||
* @param number A numeric value.
|
||||
*/
|
||||
isInteger(number: unknown): boolean;
|
||||
|
||||
/**
|
||||
* Returns a Boolean value that indicates whether a value is the reserved value NaN (not a
|
||||
* number). Unlike the global isNaN(), Number.isNaN() doesn't forcefully convert the parameter
|
||||
* to a number. Only values of the type number, that are also NaN, result in true.
|
||||
* @param number A numeric value.
|
||||
*/
|
||||
isNaN(number: unknown): boolean;
|
||||
|
||||
/**
|
||||
* Returns true if the value passed is a safe integer.
|
||||
* @param number A numeric value.
|
||||
*/
|
||||
isSafeInteger(number: unknown): boolean;
|
||||
|
||||
/**
|
||||
* The value of the largest integer n such that n and n + 1 are both exactly representable as
|
||||
* a Number value.
|
||||
* The value of Number.MAX_SAFE_INTEGER is 9007199254740991 2^53 − 1.
|
||||
*/
|
||||
readonly MAX_SAFE_INTEGER: number;
|
||||
|
||||
/**
|
||||
* The value of the smallest integer n such that n and n − 1 are both exactly representable as
|
||||
* a Number value.
|
||||
* The value of Number.MIN_SAFE_INTEGER is −9007199254740991 (−(2^53 − 1)).
|
||||
*/
|
||||
readonly MIN_SAFE_INTEGER: number;
|
||||
|
||||
/**
|
||||
* Converts a string to a floating-point number.
|
||||
* @param string A string that contains a floating-point number.
|
||||
*/
|
||||
parseFloat(string: string): number;
|
||||
|
||||
/**
|
||||
* Converts A string to an integer.
|
||||
* @param string A string to convert into a number.
|
||||
* @param radix A value between 2 and 36 that specifies the base of the number in `string`.
|
||||
* If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.
|
||||
* All other strings are considered decimal.
|
||||
*/
|
||||
parseInt(string: string, radix?: number): number;
|
||||
}
|
||||
|
||||
interface ObjectConstructor {
|
||||
/**
|
||||
* Copy the values of all of the enumerable own properties from one or more source objects to a
|
||||
* target object. Returns the target object.
|
||||
* @param target The target object to copy to.
|
||||
* @param source The source object from which to copy properties.
|
||||
*/
|
||||
assign<T extends {}, U>(target: T, source: U): T & U;
|
||||
|
||||
/**
|
||||
* Copy the values of all of the enumerable own properties from one or more source objects to a
|
||||
* target object. Returns the target object.
|
||||
* @param target The target object to copy to.
|
||||
* @param source1 The first source object from which to copy properties.
|
||||
* @param source2 The second source object from which to copy properties.
|
||||
*/
|
||||
assign<T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V;
|
||||
|
||||
/**
|
||||
* Copy the values of all of the enumerable own properties from one or more source objects to a
|
||||
* target object. Returns the target object.
|
||||
* @param target The target object to copy to.
|
||||
* @param source1 The first source object from which to copy properties.
|
||||
* @param source2 The second source object from which to copy properties.
|
||||
* @param source3 The third source object from which to copy properties.
|
||||
*/
|
||||
assign<T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
|
||||
|
||||
/**
|
||||
* Copy the values of all of the enumerable own properties from one or more source objects to a
|
||||
* target object. Returns the target object.
|
||||
* @param target The target object to copy to.
|
||||
* @param sources One or more source objects from which to copy properties
|
||||
*/
|
||||
assign(target: object, ...sources: any[]): any;
|
||||
|
||||
/**
|
||||
* Returns an array of all symbol properties found directly on object o.
|
||||
* @param o Object to retrieve the symbols from.
|
||||
*/
|
||||
getOwnPropertySymbols(o: any): symbol[];
|
||||
|
||||
/**
|
||||
* Returns the names of the enumerable string properties and methods of an object.
|
||||
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
|
||||
*/
|
||||
keys(o: {}): string[];
|
||||
|
||||
/**
|
||||
* Returns true if the values are the same value, false otherwise.
|
||||
* @param value1 The first value.
|
||||
* @param value2 The second value.
|
||||
*/
|
||||
is(value1: any, value2: any): boolean;
|
||||
|
||||
/**
|
||||
* Sets the prototype of a specified object o to object proto or null. Returns the object o.
|
||||
* @param o The object to change its prototype.
|
||||
* @param proto The value of the new prototype or null.
|
||||
*/
|
||||
setPrototypeOf(o: any, proto: object | null): any;
|
||||
}
|
||||
|
||||
interface ReadonlyArray<T> {
|
||||
/**
|
||||
* Returns the value of the first element in the array where predicate is true, and undefined
|
||||
* otherwise.
|
||||
* @param predicate find calls predicate once for each element of the array, in ascending
|
||||
* order, until it finds one where predicate returns true. If such an element is found, find
|
||||
* immediately returns that element value. Otherwise, find returns undefined.
|
||||
* @param thisArg If provided, it will be used as the this value for each invocation of
|
||||
* predicate. If it is not provided, undefined is used instead.
|
||||
*/
|
||||
find<S extends T>(predicate: (value: T, index: number, obj: readonly T[]) => value is S, thisArg?: any): S | undefined;
|
||||
find(predicate: (value: T, index: number, obj: readonly T[]) => unknown, thisArg?: any): T | undefined;
|
||||
|
||||
/**
|
||||
* Returns the index of the first element in the array where predicate is true, and -1
|
||||
* otherwise.
|
||||
* @param predicate find calls predicate once for each element of the array, in ascending
|
||||
* order, until it finds one where predicate returns true. If such an element is found,
|
||||
* findIndex immediately returns that element index. Otherwise, findIndex returns -1.
|
||||
* @param thisArg If provided, it will be used as the this value for each invocation of
|
||||
* predicate. If it is not provided, undefined is used instead.
|
||||
*/
|
||||
findIndex(predicate: (value: T, index: number, obj: readonly T[]) => unknown, thisArg?: any): number;
|
||||
|
||||
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string;
|
||||
}
|
||||
|
||||
interface RegExp {
|
||||
/**
|
||||
* Returns a string indicating the flags of the regular expression in question. This field is read-only.
|
||||
* The characters in this string are sequenced and concatenated in the following order:
|
||||
*
|
||||
* - "g" for global
|
||||
* - "i" for ignoreCase
|
||||
* - "m" for multiline
|
||||
* - "u" for unicode
|
||||
* - "y" for sticky
|
||||
*
|
||||
* If no flags are set, the value is the empty string.
|
||||
*/
|
||||
readonly flags: string;
|
||||
|
||||
/**
|
||||
* Returns a Boolean value indicating the state of the sticky flag (y) used with a regular
|
||||
* expression. Default is false. Read-only.
|
||||
*/
|
||||
readonly sticky: boolean;
|
||||
|
||||
/**
|
||||
* Returns a Boolean value indicating the state of the Unicode flag (u) used with a regular
|
||||
* expression. Default is false. Read-only.
|
||||
*/
|
||||
readonly unicode: boolean;
|
||||
}
|
||||
|
||||
interface RegExpConstructor {
|
||||
new (pattern: RegExp | string, flags?: string): RegExp;
|
||||
(pattern: RegExp | string, flags?: string): RegExp;
|
||||
}
|
||||
|
||||
interface String {
|
||||
/**
|
||||
* Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point
|
||||
* value of the UTF-16 encoded code point starting at the string element at position pos in
|
||||
* the String resulting from converting this object to a String.
|
||||
* If there is no element at that position, the result is undefined.
|
||||
* If a valid UTF-16 surrogate pair does not begin at pos, the result is the code unit at pos.
|
||||
*/
|
||||
codePointAt(pos: number): number | undefined;
|
||||
|
||||
/**
|
||||
* Returns true if searchString appears as a substring of the result of converting this
|
||||
* object to a String, at one or more positions that are
|
||||
* greater than or equal to position; otherwise, returns false.
|
||||
* @param searchString search string
|
||||
* @param position If position is undefined, 0 is assumed, so as to search all of the String.
|
||||
*/
|
||||
includes(searchString: string, position?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns true if the sequence of elements of searchString converted to a String is the
|
||||
* same as the corresponding elements of this object (converted to a String) starting at
|
||||
* endPosition – length(this). Otherwise returns false.
|
||||
*/
|
||||
endsWith(searchString: string, endPosition?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns the String value result of normalizing the string into the normalization form
|
||||
* named by form as specified in Unicode Standard Annex #15, Unicode Normalization Forms.
|
||||
* @param form Applicable values: "NFC", "NFD", "NFKC", or "NFKD", If not specified default
|
||||
* is "NFC"
|
||||
*/
|
||||
normalize(form: "NFC" | "NFD" | "NFKC" | "NFKD"): string;
|
||||
|
||||
/**
|
||||
* Returns the String value result of normalizing the string into the normalization form
|
||||
* named by form as specified in Unicode Standard Annex #15, Unicode Normalization Forms.
|
||||
* @param form Applicable values: "NFC", "NFD", "NFKC", or "NFKD", If not specified default
|
||||
* is "NFC"
|
||||
*/
|
||||
normalize(form?: string): string;
|
||||
|
||||
/**
|
||||
* Returns a String value that is made from count copies appended together. If count is 0,
|
||||
* the empty string is returned.
|
||||
* @param count number of copies to append
|
||||
*/
|
||||
repeat(count: number): string;
|
||||
|
||||
/**
|
||||
* Returns true if the sequence of elements of searchString converted to a String is the
|
||||
* same as the corresponding elements of this object (converted to a String) starting at
|
||||
* position. Otherwise returns false.
|
||||
*/
|
||||
startsWith(searchString: string, position?: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns an `<a>` HTML anchor element and sets the name attribute to the text value
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
* @param name
|
||||
*/
|
||||
anchor(name: string): string;
|
||||
|
||||
/**
|
||||
* Returns a `<big>` HTML element
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
*/
|
||||
big(): string;
|
||||
|
||||
/**
|
||||
* Returns a `<blink>` HTML element
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
*/
|
||||
blink(): string;
|
||||
|
||||
/**
|
||||
* Returns a `<b>` HTML element
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
*/
|
||||
bold(): string;
|
||||
|
||||
/**
|
||||
* Returns a `<tt>` HTML element
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
*/
|
||||
fixed(): string;
|
||||
|
||||
/**
|
||||
* Returns a `<font>` HTML element and sets the color attribute value
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
*/
|
||||
fontcolor(color: string): string;
|
||||
|
||||
/**
|
||||
* Returns a `<font>` HTML element and sets the size attribute value
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
*/
|
||||
fontsize(size: number): string;
|
||||
|
||||
/**
|
||||
* Returns a `<font>` HTML element and sets the size attribute value
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
*/
|
||||
fontsize(size: string): string;
|
||||
|
||||
/**
|
||||
* Returns an `<i>` HTML element
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
*/
|
||||
italics(): string;
|
||||
|
||||
/**
|
||||
* Returns an `<a>` HTML element and sets the href attribute value
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
*/
|
||||
link(url: string): string;
|
||||
|
||||
/**
|
||||
* Returns a `<small>` HTML element
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
*/
|
||||
small(): string;
|
||||
|
||||
/**
|
||||
* Returns a `<strike>` HTML element
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
*/
|
||||
strike(): string;
|
||||
|
||||
/**
|
||||
* Returns a `<sub>` HTML element
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
*/
|
||||
sub(): string;
|
||||
|
||||
/**
|
||||
* Returns a `<sup>` HTML element
|
||||
* @deprecated A legacy feature for browser compatibility
|
||||
*/
|
||||
sup(): string;
|
||||
}
|
||||
|
||||
interface StringConstructor {
|
||||
/**
|
||||
* Return the String value whose elements are, in order, the elements in the List elements.
|
||||
* If length is 0, the empty string is returned.
|
||||
*/
|
||||
fromCodePoint(...codePoints: number[]): string;
|
||||
|
||||
/**
|
||||
* String.raw is usually used as a tag function of a Tagged Template String. When called as
|
||||
* such, the first argument will be a well formed template call site object and the rest
|
||||
* parameter will contain the substitution values. It can also be called directly, for example,
|
||||
* to interleave strings and values from your own tag function, and in this case the only thing
|
||||
* it needs from the first argument is the raw property.
|
||||
* @param template A well-formed template string call site representation.
|
||||
* @param substitutions A set of substitution values.
|
||||
*/
|
||||
raw(template: { raw: readonly string[] | ArrayLike<string>; }, ...substitutions: any[]): string;
|
||||
}
|
||||
|
||||
interface Int8Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
|
||||
}
|
||||
|
||||
interface Uint8Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
|
||||
}
|
||||
|
||||
interface Uint8ClampedArray<TArrayBuffer extends ArrayBufferLike> {
|
||||
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
|
||||
}
|
||||
|
||||
interface Int16Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
|
||||
}
|
||||
|
||||
interface Uint16Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
|
||||
}
|
||||
|
||||
interface Int32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
|
||||
}
|
||||
|
||||
interface Uint32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
|
||||
}
|
||||
|
||||
interface Float32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
|
||||
}
|
||||
|
||||
interface Float64Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es5" />
|
||||
/// <reference lib="es2015.core" />
|
||||
/// <reference lib="es2015.collection" />
|
||||
/// <reference lib="es2015.iterable" />
|
||||
/// <reference lib="es2015.generator" />
|
||||
/// <reference lib="es2015.promise" />
|
||||
/// <reference lib="es2015.proxy" />
|
||||
/// <reference lib="es2015.reflect" />
|
||||
/// <reference lib="es2015.symbol" />
|
||||
/// <reference lib="es2015.symbol.wellknown" />
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2015.iterable" />
|
||||
|
||||
interface Generator<T = unknown, TReturn = any, TNext = any> extends IteratorObject<T, TReturn, TNext> {
|
||||
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
|
||||
next(...[value]: [] | [TNext]): IteratorResult<T, TReturn>;
|
||||
return(value: TReturn): IteratorResult<T, TReturn>;
|
||||
throw(e: any): IteratorResult<T, TReturn>;
|
||||
[Symbol.iterator](): Generator<T, TReturn, TNext>;
|
||||
}
|
||||
|
||||
interface GeneratorFunction {
|
||||
/**
|
||||
* Creates a new Generator object.
|
||||
* @param args A list of arguments the function accepts.
|
||||
*/
|
||||
new (...args: any[]): Generator;
|
||||
/**
|
||||
* Creates a new Generator object.
|
||||
* @param args A list of arguments the function accepts.
|
||||
*/
|
||||
(...args: any[]): Generator;
|
||||
/**
|
||||
* The length of the arguments.
|
||||
*/
|
||||
readonly length: number;
|
||||
/**
|
||||
* Returns the name of the function.
|
||||
*/
|
||||
readonly name: string;
|
||||
/**
|
||||
* A reference to the prototype.
|
||||
*/
|
||||
readonly prototype: Generator;
|
||||
}
|
||||
|
||||
interface GeneratorFunctionConstructor {
|
||||
/**
|
||||
* Creates a new Generator function.
|
||||
* @param args A list of arguments the function accepts.
|
||||
*/
|
||||
new (...args: string[]): GeneratorFunction;
|
||||
/**
|
||||
* Creates a new Generator function.
|
||||
* @param args A list of arguments the function accepts.
|
||||
*/
|
||||
(...args: string[]): GeneratorFunction;
|
||||
/**
|
||||
* The length of the arguments.
|
||||
*/
|
||||
readonly length: number;
|
||||
/**
|
||||
* Returns the name of the function.
|
||||
*/
|
||||
readonly name: string;
|
||||
/**
|
||||
* A reference to the prototype.
|
||||
*/
|
||||
readonly prototype: GeneratorFunction;
|
||||
}
|
||||
+603
@@ -0,0 +1,603 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2015.symbol" />
|
||||
|
||||
interface SymbolConstructor {
|
||||
/**
|
||||
* A method that returns the default iterator for an object. Called by the semantics of the
|
||||
* for-of statement.
|
||||
*/
|
||||
readonly iterator: unique symbol;
|
||||
}
|
||||
|
||||
interface IteratorYieldResult<TYield> {
|
||||
done?: false;
|
||||
value: TYield;
|
||||
}
|
||||
|
||||
interface IteratorReturnResult<TReturn> {
|
||||
done: true;
|
||||
value: TReturn;
|
||||
}
|
||||
|
||||
type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
|
||||
|
||||
interface Iterator<T, TReturn = any, TNext = any> {
|
||||
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
|
||||
next(...[value]: [] | [TNext]): IteratorResult<T, TReturn>;
|
||||
return?(value?: TReturn): IteratorResult<T, TReturn>;
|
||||
throw?(e?: any): IteratorResult<T, TReturn>;
|
||||
}
|
||||
|
||||
interface Iterable<T, TReturn = any, TNext = any> {
|
||||
[Symbol.iterator](): Iterator<T, TReturn, TNext>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes a user-defined {@link Iterator} that is also iterable.
|
||||
*/
|
||||
interface IterableIterator<T, TReturn = any, TNext = any> extends Iterator<T, TReturn, TNext> {
|
||||
[Symbol.iterator](): IterableIterator<T, TReturn, TNext>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes an {@link Iterator} produced by the runtime that inherits from the intrinsic `Iterator.prototype`.
|
||||
*/
|
||||
interface IteratorObject<T, TReturn = unknown, TNext = unknown> extends Iterator<T, TReturn, TNext> {
|
||||
[Symbol.iterator](): IteratorObject<T, TReturn, TNext>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the `TReturn` type used for built-in iterators produced by `Array`, `Map`, `Set`, and others.
|
||||
* This is `undefined` when `strictBuiltInIteratorReturn` is `true`; otherwise, this is `any`.
|
||||
*/
|
||||
type BuiltinIteratorReturn = intrinsic;
|
||||
|
||||
interface ArrayIterator<T> extends IteratorObject<T, BuiltinIteratorReturn, unknown> {
|
||||
[Symbol.iterator](): ArrayIterator<T>;
|
||||
}
|
||||
|
||||
interface Array<T> {
|
||||
/** Iterator */
|
||||
[Symbol.iterator](): ArrayIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, T]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<T>;
|
||||
}
|
||||
|
||||
interface ArrayConstructor {
|
||||
/**
|
||||
* Creates an array from an iterable object.
|
||||
* @param iterable An iterable object to convert to an array.
|
||||
*/
|
||||
from<T>(iterable: Iterable<T> | ArrayLike<T>): T[];
|
||||
|
||||
/**
|
||||
* Creates an array from an iterable object.
|
||||
* @param iterable An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
|
||||
}
|
||||
|
||||
interface ReadonlyArray<T> {
|
||||
/** Iterator of values in the array. */
|
||||
[Symbol.iterator](): ArrayIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, T]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<T>;
|
||||
}
|
||||
|
||||
interface IArguments {
|
||||
/** Iterator */
|
||||
[Symbol.iterator](): ArrayIterator<any>;
|
||||
}
|
||||
|
||||
interface MapIterator<T> extends IteratorObject<T, BuiltinIteratorReturn, unknown> {
|
||||
[Symbol.iterator](): MapIterator<T>;
|
||||
}
|
||||
|
||||
interface Map<K, V> {
|
||||
/** Returns an iterable of entries in the map. */
|
||||
[Symbol.iterator](): MapIterator<[K, V]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of key, value pairs for every entry in the map.
|
||||
*/
|
||||
entries(): MapIterator<[K, V]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of keys in the map
|
||||
*/
|
||||
keys(): MapIterator<K>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the map
|
||||
*/
|
||||
values(): MapIterator<V>;
|
||||
}
|
||||
|
||||
interface ReadonlyMap<K, V> {
|
||||
/** Returns an iterable of entries in the map. */
|
||||
[Symbol.iterator](): MapIterator<[K, V]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of key, value pairs for every entry in the map.
|
||||
*/
|
||||
entries(): MapIterator<[K, V]>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of keys in the map
|
||||
*/
|
||||
keys(): MapIterator<K>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the map
|
||||
*/
|
||||
values(): MapIterator<V>;
|
||||
}
|
||||
|
||||
interface MapConstructor {
|
||||
new (): Map<any, any>;
|
||||
new <K, V>(iterable?: Iterable<readonly [K, V]> | null): Map<K, V>;
|
||||
}
|
||||
|
||||
interface WeakMap<K extends WeakKey, V> {}
|
||||
|
||||
interface WeakMapConstructor {
|
||||
new <K extends WeakKey = WeakKey, V = any>(iterable?: Iterable<readonly [K, V]> | null): WeakMap<K, V>;
|
||||
}
|
||||
|
||||
interface SetIterator<T> extends IteratorObject<T, BuiltinIteratorReturn, unknown> {
|
||||
[Symbol.iterator](): SetIterator<T>;
|
||||
}
|
||||
|
||||
interface Set<T> {
|
||||
/** Iterates over values in the set. */
|
||||
[Symbol.iterator](): SetIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of [v,v] pairs for every value `v` in the set.
|
||||
*/
|
||||
entries(): SetIterator<[T, T]>;
|
||||
|
||||
/**
|
||||
* Despite its name, returns an iterable of the values in the set.
|
||||
*/
|
||||
keys(): SetIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the set.
|
||||
*/
|
||||
values(): SetIterator<T>;
|
||||
}
|
||||
|
||||
interface ReadonlySet<T> {
|
||||
/** Iterates over values in the set. */
|
||||
[Symbol.iterator](): SetIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of [v,v] pairs for every value `v` in the set.
|
||||
*/
|
||||
entries(): SetIterator<[T, T]>;
|
||||
|
||||
/**
|
||||
* Despite its name, returns an iterable of the values in the set.
|
||||
*/
|
||||
keys(): SetIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an iterable of values in the set.
|
||||
*/
|
||||
values(): SetIterator<T>;
|
||||
}
|
||||
|
||||
interface SetConstructor {
|
||||
new <T>(iterable?: Iterable<T> | null): Set<T>;
|
||||
}
|
||||
|
||||
interface WeakSet<T extends WeakKey> {}
|
||||
|
||||
interface WeakSetConstructor {
|
||||
new <T extends WeakKey = WeakKey>(iterable: Iterable<T>): WeakSet<T>;
|
||||
}
|
||||
|
||||
interface Promise<T> {}
|
||||
|
||||
interface PromiseConstructor {
|
||||
/**
|
||||
* Creates a Promise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any Promise is rejected.
|
||||
* @param values An iterable of Promises.
|
||||
* @returns A new Promise.
|
||||
*/
|
||||
all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>;
|
||||
|
||||
/**
|
||||
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An iterable of Promises.
|
||||
* @returns A new Promise.
|
||||
*/
|
||||
race<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
|
||||
}
|
||||
|
||||
interface StringIterator<T> extends IteratorObject<T, BuiltinIteratorReturn, unknown> {
|
||||
[Symbol.iterator](): StringIterator<T>;
|
||||
}
|
||||
|
||||
interface String {
|
||||
/** Iterator */
|
||||
[Symbol.iterator](): StringIterator<string>;
|
||||
}
|
||||
|
||||
interface Int8Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Int8ArrayConstructor {
|
||||
new (elements: Iterable<number>): Int8Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Int8Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Int8Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Uint8Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Uint8ArrayConstructor {
|
||||
new (elements: Iterable<number>): Uint8Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Uint8Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Uint8Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Uint8ClampedArray<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Uint8ClampedArrayConstructor {
|
||||
new (elements: Iterable<number>): Uint8ClampedArray<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Uint8ClampedArray<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Uint8ClampedArray<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Int16Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Int16ArrayConstructor {
|
||||
new (elements: Iterable<number>): Int16Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Int16Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Int16Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Uint16Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Uint16ArrayConstructor {
|
||||
new (elements: Iterable<number>): Uint16Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Uint16Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Uint16Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Int32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Int32ArrayConstructor {
|
||||
new (elements: Iterable<number>): Int32Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Int32Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Int32Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Uint32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Uint32ArrayConstructor {
|
||||
new (elements: Iterable<number>): Uint32Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Uint32Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Uint32Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Float32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Float32ArrayConstructor {
|
||||
new (elements: Iterable<number>): Float32Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Float32Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Float32Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Float64Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
[Symbol.iterator](): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): ArrayIterator<[number, number]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): ArrayIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): ArrayIterator<number>;
|
||||
}
|
||||
|
||||
interface Float64ArrayConstructor {
|
||||
new (elements: Iterable<number>): Float64Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
*/
|
||||
from(elements: Iterable<number>): Float64Array<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Creates an array from an array-like or iterable object.
|
||||
* @param elements An iterable object to convert to an array.
|
||||
* @param mapfn A mapping function to call on every element of the array.
|
||||
* @param thisArg Value of 'this' used to invoke the mapfn.
|
||||
*/
|
||||
from<T>(elements: Iterable<T>, mapfn?: (v: T, k: number) => number, thisArg?: any): Float64Array<ArrayBuffer>;
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface PromiseConstructor {
|
||||
/**
|
||||
* A reference to the prototype.
|
||||
*/
|
||||
readonly prototype: Promise<any>;
|
||||
|
||||
/**
|
||||
* Creates a new Promise.
|
||||
* @param executor A callback used to initialize the promise. This callback is passed two arguments:
|
||||
* a resolve callback used to resolve the promise with a value or the result of another promise,
|
||||
* and a reject callback used to reject the promise with a provided reason or error.
|
||||
*/
|
||||
new <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
|
||||
|
||||
/**
|
||||
* Creates a Promise that is resolved with an array of results when all of the provided Promises
|
||||
* resolve, or rejected when any Promise is rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new Promise.
|
||||
*/
|
||||
all<T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>;
|
||||
|
||||
// see: lib.es2015.iterable.d.ts
|
||||
// all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>;
|
||||
|
||||
/**
|
||||
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
|
||||
* or rejected.
|
||||
* @param values An array of Promises.
|
||||
* @returns A new Promise.
|
||||
*/
|
||||
race<T extends readonly unknown[] | []>(values: T): Promise<Awaited<T[number]>>;
|
||||
|
||||
// see: lib.es2015.iterable.d.ts
|
||||
// race<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>>;
|
||||
|
||||
/**
|
||||
* Creates a new rejected promise for the provided reason.
|
||||
* @param reason The reason the promise was rejected.
|
||||
* @returns A new rejected Promise.
|
||||
*/
|
||||
reject<T = never>(reason?: any): Promise<T>;
|
||||
|
||||
/**
|
||||
* Creates a new resolved promise.
|
||||
* @returns A resolved promise.
|
||||
*/
|
||||
resolve(): Promise<void>;
|
||||
/**
|
||||
* Creates a new resolved promise for the provided value.
|
||||
* @param value A promise.
|
||||
* @returns A promise whose internal state matches the provided promise.
|
||||
*/
|
||||
resolve<T>(value: T): Promise<Awaited<T>>;
|
||||
/**
|
||||
* Creates a new resolved promise for the provided value.
|
||||
* @param value A promise.
|
||||
* @returns A promise whose internal state matches the provided promise.
|
||||
*/
|
||||
resolve<T>(value: T | PromiseLike<T>): Promise<Awaited<T>>;
|
||||
}
|
||||
|
||||
declare var Promise: PromiseConstructor;
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface ProxyHandler<T extends object> {
|
||||
/**
|
||||
* A trap method for a function call.
|
||||
* @param target The original callable object which is being proxied.
|
||||
*/
|
||||
apply?(target: T, thisArg: any, argArray: any[]): any;
|
||||
|
||||
/**
|
||||
* A trap for the `new` operator.
|
||||
* @param target The original object which is being proxied.
|
||||
* @param newTarget The constructor that was originally called.
|
||||
*/
|
||||
construct?(target: T, argArray: any[], newTarget: Function): object;
|
||||
|
||||
/**
|
||||
* A trap for `Object.defineProperty()`.
|
||||
* @param target The original object which is being proxied.
|
||||
* @returns A `Boolean` indicating whether or not the property has been defined.
|
||||
*/
|
||||
defineProperty?(target: T, property: string | symbol, attributes: PropertyDescriptor): boolean;
|
||||
|
||||
/**
|
||||
* A trap for the `delete` operator.
|
||||
* @param target The original object which is being proxied.
|
||||
* @param p The name or `Symbol` of the property to delete.
|
||||
* @returns A `Boolean` indicating whether or not the property was deleted.
|
||||
*/
|
||||
deleteProperty?(target: T, p: string | symbol): boolean;
|
||||
|
||||
/**
|
||||
* A trap for getting a property value.
|
||||
* @param target The original object which is being proxied.
|
||||
* @param p The name or `Symbol` of the property to get.
|
||||
* @param receiver The proxy or an object that inherits from the proxy.
|
||||
*/
|
||||
get?(target: T, p: string | symbol, receiver: any): any;
|
||||
|
||||
/**
|
||||
* A trap for `Object.getOwnPropertyDescriptor()`.
|
||||
* @param target The original object which is being proxied.
|
||||
* @param p The name of the property whose description should be retrieved.
|
||||
*/
|
||||
getOwnPropertyDescriptor?(target: T, p: string | symbol): PropertyDescriptor | undefined;
|
||||
|
||||
/**
|
||||
* A trap for the `[[GetPrototypeOf]]` internal method.
|
||||
* @param target The original object which is being proxied.
|
||||
*/
|
||||
getPrototypeOf?(target: T): object | null;
|
||||
|
||||
/**
|
||||
* A trap for the `in` operator.
|
||||
* @param target The original object which is being proxied.
|
||||
* @param p The name or `Symbol` of the property to check for existence.
|
||||
*/
|
||||
has?(target: T, p: string | symbol): boolean;
|
||||
|
||||
/**
|
||||
* A trap for `Object.isExtensible()`.
|
||||
* @param target The original object which is being proxied.
|
||||
*/
|
||||
isExtensible?(target: T): boolean;
|
||||
|
||||
/**
|
||||
* A trap for `Reflect.ownKeys()`.
|
||||
* @param target The original object which is being proxied.
|
||||
*/
|
||||
ownKeys?(target: T): ArrayLike<string | symbol>;
|
||||
|
||||
/**
|
||||
* A trap for `Object.preventExtensions()`.
|
||||
* @param target The original object which is being proxied.
|
||||
*/
|
||||
preventExtensions?(target: T): boolean;
|
||||
|
||||
/**
|
||||
* A trap for setting a property value.
|
||||
* @param target The original object which is being proxied.
|
||||
* @param p The name or `Symbol` of the property to set.
|
||||
* @param receiver The object to which the assignment was originally directed.
|
||||
* @returns A `Boolean` indicating whether or not the property was set.
|
||||
*/
|
||||
set?(target: T, p: string | symbol, newValue: any, receiver: any): boolean;
|
||||
|
||||
/**
|
||||
* A trap for `Object.setPrototypeOf()`.
|
||||
* @param target The original object which is being proxied.
|
||||
* @param newPrototype The object's new prototype or `null`.
|
||||
*/
|
||||
setPrototypeOf?(target: T, v: object | null): boolean;
|
||||
}
|
||||
|
||||
interface ProxyConstructor {
|
||||
/**
|
||||
* Creates a revocable Proxy object.
|
||||
* @param target A target object to wrap with Proxy.
|
||||
* @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it.
|
||||
*/
|
||||
revocable<T extends object>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; };
|
||||
|
||||
/**
|
||||
* Creates a Proxy object. The Proxy object allows you to create an object that can be used in place of the
|
||||
* original object, but which may redefine fundamental Object operations like getting, setting, and defining
|
||||
* properties. Proxy objects are commonly used to log property accesses, validate, format, or sanitize inputs.
|
||||
* @param target A target object to wrap with Proxy.
|
||||
* @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it.
|
||||
*/
|
||||
new <T extends object>(target: T, handler: ProxyHandler<T>): T;
|
||||
}
|
||||
declare var Proxy: ProxyConstructor;
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
declare namespace Reflect {
|
||||
/**
|
||||
* Calls the function with the specified object as the this value
|
||||
* and the elements of specified array as the arguments.
|
||||
* @param target The function to call.
|
||||
* @param thisArgument The object to be used as the this object.
|
||||
* @param argumentsList An array of argument values to be passed to the function.
|
||||
*/
|
||||
function apply<T, A extends readonly any[], R>(
|
||||
target: (this: T, ...args: A) => R,
|
||||
thisArgument: T,
|
||||
argumentsList: Readonly<A>,
|
||||
): R;
|
||||
function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
|
||||
|
||||
/**
|
||||
* Constructs the target with the elements of specified array as the arguments
|
||||
* and the specified constructor as the `new.target` value.
|
||||
* @param target The constructor to invoke.
|
||||
* @param argumentsList An array of argument values to be passed to the constructor.
|
||||
* @param newTarget The constructor to be used as the `new.target` object.
|
||||
*/
|
||||
function construct<A extends readonly any[], R>(
|
||||
target: new (...args: A) => R,
|
||||
argumentsList: Readonly<A>,
|
||||
newTarget?: new (...args: any) => any,
|
||||
): R;
|
||||
function construct(target: Function, argumentsList: ArrayLike<any>, newTarget?: Function): any;
|
||||
|
||||
/**
|
||||
* Adds a property to an object, or modifies attributes of an existing property.
|
||||
* @param target Object on which to add or modify the property. This can be a native JavaScript object
|
||||
* (that is, a user-defined object or a built in object) or a DOM object.
|
||||
* @param propertyKey The property name.
|
||||
* @param attributes Descriptor for the property. It can be for a data property or an accessor property.
|
||||
*/
|
||||
function defineProperty(target: object, propertyKey: PropertyKey, attributes: PropertyDescriptor & ThisType<any>): boolean;
|
||||
|
||||
/**
|
||||
* Removes a property from an object, equivalent to `delete target[propertyKey]`,
|
||||
* except it won't throw if `target[propertyKey]` is non-configurable.
|
||||
* @param target Object from which to remove the own property.
|
||||
* @param propertyKey The property name.
|
||||
*/
|
||||
function deleteProperty(target: object, propertyKey: PropertyKey): boolean;
|
||||
|
||||
/**
|
||||
* Gets the property of target, equivalent to `target[propertyKey]` when `receiver === target`.
|
||||
* @param target Object that contains the property on itself or in its prototype chain.
|
||||
* @param propertyKey The property name.
|
||||
* @param receiver The reference to use as the `this` value in the getter function,
|
||||
* if `target[propertyKey]` is an accessor property.
|
||||
*/
|
||||
function get<T extends object, P extends PropertyKey>(
|
||||
target: T,
|
||||
propertyKey: P,
|
||||
receiver?: unknown,
|
||||
): P extends keyof T ? T[P] : any;
|
||||
|
||||
/**
|
||||
* Gets the own property descriptor of the specified object.
|
||||
* An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype.
|
||||
* @param target Object that contains the property.
|
||||
* @param propertyKey The property name.
|
||||
*/
|
||||
function getOwnPropertyDescriptor<T extends object, P extends PropertyKey>(
|
||||
target: T,
|
||||
propertyKey: P,
|
||||
): TypedPropertyDescriptor<P extends keyof T ? T[P] : any> | undefined;
|
||||
|
||||
/**
|
||||
* Returns the prototype of an object.
|
||||
* @param target The object that references the prototype.
|
||||
*/
|
||||
function getPrototypeOf(target: object): object | null;
|
||||
|
||||
/**
|
||||
* Equivalent to `propertyKey in target`.
|
||||
* @param target Object that contains the property on itself or in its prototype chain.
|
||||
* @param propertyKey Name of the property.
|
||||
*/
|
||||
function has(target: object, propertyKey: PropertyKey): boolean;
|
||||
|
||||
/**
|
||||
* Returns a value that indicates whether new properties can be added to an object.
|
||||
* @param target Object to test.
|
||||
*/
|
||||
function isExtensible(target: object): boolean;
|
||||
|
||||
/**
|
||||
* Returns the string and symbol keys of the own properties of an object. The own properties of an object
|
||||
* are those that are defined directly on that object, and are not inherited from the object's prototype.
|
||||
* @param target Object that contains the own properties.
|
||||
*/
|
||||
function ownKeys(target: object): (string | symbol)[];
|
||||
|
||||
/**
|
||||
* Prevents the addition of new properties to an object.
|
||||
* @param target Object to make non-extensible.
|
||||
* @return Whether the object has been made non-extensible.
|
||||
*/
|
||||
function preventExtensions(target: object): boolean;
|
||||
|
||||
/**
|
||||
* Sets the property of target, equivalent to `target[propertyKey] = value` when `receiver === target`.
|
||||
* @param target Object that contains the property on itself or in its prototype chain.
|
||||
* @param propertyKey Name of the property.
|
||||
* @param receiver The reference to use as the `this` value in the setter function,
|
||||
* if `target[propertyKey]` is an accessor property.
|
||||
*/
|
||||
function set<T extends object, P extends PropertyKey>(
|
||||
target: T,
|
||||
propertyKey: P,
|
||||
value: P extends keyof T ? T[P] : any,
|
||||
receiver?: any,
|
||||
): boolean;
|
||||
function set(target: object, propertyKey: PropertyKey, value: any, receiver?: any): boolean;
|
||||
|
||||
/**
|
||||
* Sets the prototype of a specified object o to object proto or null.
|
||||
* @param target The object to change its prototype.
|
||||
* @param proto The value of the new prototype or null.
|
||||
* @return Whether setting the prototype was successful.
|
||||
*/
|
||||
function setPrototypeOf(target: object, proto: object | null): boolean;
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface SymbolConstructor {
|
||||
/**
|
||||
* A reference to the prototype.
|
||||
*/
|
||||
readonly prototype: Symbol;
|
||||
|
||||
/**
|
||||
* Returns a new unique Symbol value.
|
||||
* @param description Description of the new Symbol object.
|
||||
*/
|
||||
(description?: string | number): symbol;
|
||||
|
||||
/**
|
||||
* Returns a Symbol object from the global symbol registry matching the given key if found.
|
||||
* Otherwise, returns a new symbol with this key.
|
||||
* @param key key to search for.
|
||||
*/
|
||||
for(key: string): symbol;
|
||||
|
||||
/**
|
||||
* Returns a key from the global symbol registry matching the given Symbol if found.
|
||||
* Otherwise, returns a undefined.
|
||||
* @param sym Symbol to find the key for.
|
||||
*/
|
||||
keyFor(sym: symbol): string | undefined;
|
||||
}
|
||||
|
||||
declare var Symbol: SymbolConstructor;
|
||||
+324
@@ -0,0 +1,324 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2015.symbol" />
|
||||
|
||||
interface SymbolConstructor {
|
||||
/**
|
||||
* A method that determines if a constructor object recognizes an object as one of the
|
||||
* constructor’s instances. Called by the semantics of the instanceof operator.
|
||||
*/
|
||||
readonly hasInstance: unique symbol;
|
||||
|
||||
/**
|
||||
* A Boolean value that if true indicates that an object should flatten to its array elements
|
||||
* by Array.prototype.concat.
|
||||
*/
|
||||
readonly isConcatSpreadable: unique symbol;
|
||||
|
||||
/**
|
||||
* A regular expression method that matches the regular expression against a string. Called
|
||||
* by the String.prototype.match method.
|
||||
*/
|
||||
readonly match: unique symbol;
|
||||
|
||||
/**
|
||||
* A regular expression method that replaces matched substrings of a string. Called by the
|
||||
* String.prototype.replace method.
|
||||
*/
|
||||
readonly replace: unique symbol;
|
||||
|
||||
/**
|
||||
* A regular expression method that returns the index within a string that matches the
|
||||
* regular expression. Called by the String.prototype.search method.
|
||||
*/
|
||||
readonly search: unique symbol;
|
||||
|
||||
/**
|
||||
* A function valued property that is the constructor function that is used to create
|
||||
* derived objects.
|
||||
*/
|
||||
readonly species: unique symbol;
|
||||
|
||||
/**
|
||||
* A regular expression method that splits a string at the indices that match the regular
|
||||
* expression. Called by the String.prototype.split method.
|
||||
*/
|
||||
readonly split: unique symbol;
|
||||
|
||||
/**
|
||||
* A method that converts an object to a corresponding primitive value.
|
||||
* Called by the ToPrimitive abstract operation.
|
||||
*/
|
||||
readonly toPrimitive: unique symbol;
|
||||
|
||||
/**
|
||||
* A String value that is used in the creation of the default string description of an object.
|
||||
* Called by the built-in method Object.prototype.toString.
|
||||
*/
|
||||
readonly toStringTag: unique symbol;
|
||||
|
||||
/**
|
||||
* An Object whose truthy properties are properties that are excluded from the 'with'
|
||||
* environment bindings of the associated objects.
|
||||
*/
|
||||
readonly unscopables: unique symbol;
|
||||
}
|
||||
|
||||
interface Symbol {
|
||||
/**
|
||||
* Converts a Symbol object to a symbol.
|
||||
*/
|
||||
[Symbol.toPrimitive](hint: string): symbol;
|
||||
|
||||
readonly [Symbol.toStringTag]: string;
|
||||
}
|
||||
|
||||
interface Array<T> {
|
||||
/**
|
||||
* Is an object whose properties have the value 'true'
|
||||
* when they will be absent when used in a 'with' statement.
|
||||
*/
|
||||
readonly [Symbol.unscopables]: {
|
||||
[K in keyof any[]]?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
interface ReadonlyArray<T> {
|
||||
/**
|
||||
* Is an object whose properties have the value 'true'
|
||||
* when they will be absent when used in a 'with' statement.
|
||||
*/
|
||||
readonly [Symbol.unscopables]: {
|
||||
[K in keyof readonly any[]]?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
interface Date {
|
||||
/**
|
||||
* Converts a Date object to a string.
|
||||
*/
|
||||
[Symbol.toPrimitive](hint: "default"): string;
|
||||
/**
|
||||
* Converts a Date object to a string.
|
||||
*/
|
||||
[Symbol.toPrimitive](hint: "string"): string;
|
||||
/**
|
||||
* Converts a Date object to a number.
|
||||
*/
|
||||
[Symbol.toPrimitive](hint: "number"): number;
|
||||
/**
|
||||
* Converts a Date object to a string or number.
|
||||
*
|
||||
* @param hint The strings "number", "string", or "default" to specify what primitive to return.
|
||||
*
|
||||
* @throws {TypeError} If 'hint' was given something other than "number", "string", or "default".
|
||||
* @returns A number if 'hint' was "number", a string if 'hint' was "string" or "default".
|
||||
*/
|
||||
[Symbol.toPrimitive](hint: string): string | number;
|
||||
}
|
||||
|
||||
interface Map<K, V> {
|
||||
readonly [Symbol.toStringTag]: string;
|
||||
}
|
||||
|
||||
interface WeakMap<K extends WeakKey, V> {
|
||||
readonly [Symbol.toStringTag]: string;
|
||||
}
|
||||
|
||||
interface Set<T> {
|
||||
readonly [Symbol.toStringTag]: string;
|
||||
}
|
||||
|
||||
interface WeakSet<T extends WeakKey> {
|
||||
readonly [Symbol.toStringTag]: string;
|
||||
}
|
||||
|
||||
interface JSON {
|
||||
readonly [Symbol.toStringTag]: string;
|
||||
}
|
||||
|
||||
interface Function {
|
||||
/**
|
||||
* Determines whether the given value inherits from this function if this function was used
|
||||
* as a constructor function.
|
||||
*
|
||||
* A constructor function can control which objects are recognized as its instances by
|
||||
* 'instanceof' by overriding this method.
|
||||
*/
|
||||
[Symbol.hasInstance](value: any): boolean;
|
||||
}
|
||||
|
||||
interface GeneratorFunction {
|
||||
readonly [Symbol.toStringTag]: string;
|
||||
}
|
||||
|
||||
interface Math {
|
||||
readonly [Symbol.toStringTag]: string;
|
||||
}
|
||||
|
||||
interface Promise<T> {
|
||||
readonly [Symbol.toStringTag]: string;
|
||||
}
|
||||
|
||||
interface PromiseConstructor {
|
||||
readonly [Symbol.species]: PromiseConstructor;
|
||||
}
|
||||
|
||||
interface RegExp {
|
||||
/**
|
||||
* Matches a string with this regular expression, and returns an array containing the results of
|
||||
* that search.
|
||||
* @param string A string to search within.
|
||||
*/
|
||||
[Symbol.match](string: string): RegExpMatchArray | null;
|
||||
|
||||
/**
|
||||
* Replaces text in a string, using this regular expression.
|
||||
* @param string A String object or string literal whose contents matching against
|
||||
* this regular expression will be replaced
|
||||
* @param replaceValue A String object or string literal containing the text to replace for every
|
||||
* successful match of this regular expression.
|
||||
*/
|
||||
[Symbol.replace](string: string, replaceValue: string): string;
|
||||
|
||||
/**
|
||||
* Replaces text in a string, using this regular expression.
|
||||
* @param string A String object or string literal whose contents matching against
|
||||
* this regular expression will be replaced
|
||||
* @param replacer A function that returns the replacement text.
|
||||
*/
|
||||
[Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string;
|
||||
|
||||
/**
|
||||
* Finds the position beginning first substring match in a regular expression search
|
||||
* using this regular expression.
|
||||
*
|
||||
* @param string The string to search within.
|
||||
*/
|
||||
[Symbol.search](string: string): number;
|
||||
|
||||
/**
|
||||
* Returns an array of substrings that were delimited by strings in the original input that
|
||||
* match against this regular expression.
|
||||
*
|
||||
* If the regular expression contains capturing parentheses, then each time this
|
||||
* regular expression matches, the results (including any undefined results) of the
|
||||
* capturing parentheses are spliced.
|
||||
*
|
||||
* @param string string value to split
|
||||
* @param limit if not undefined, the output array is truncated so that it contains no more
|
||||
* than 'limit' elements.
|
||||
*/
|
||||
[Symbol.split](string: string, limit?: number): string[];
|
||||
}
|
||||
|
||||
interface RegExpConstructor {
|
||||
readonly [Symbol.species]: RegExpConstructor;
|
||||
}
|
||||
|
||||
interface String {
|
||||
/**
|
||||
* Matches a string or an object that supports being matched against, and returns an array
|
||||
* containing the results of that search, or null if no matches are found.
|
||||
* @param matcher An object that supports being matched against.
|
||||
*/
|
||||
match(matcher: { [Symbol.match](string: string): RegExpMatchArray | null; }): RegExpMatchArray | null;
|
||||
|
||||
/**
|
||||
* Passes a string and {@linkcode replaceValue} to the `[Symbol.replace]` method on {@linkcode searchValue}. This method is expected to implement its own replacement algorithm.
|
||||
* @param searchValue An object that supports searching for and replacing matches within a string.
|
||||
* @param replaceValue The replacement text.
|
||||
*/
|
||||
replace(searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string): string;
|
||||
|
||||
/**
|
||||
* Replaces text in a string, using an object that supports replacement within a string.
|
||||
* @param searchValue A object can search for and replace matches within a string.
|
||||
* @param replacer A function that returns the replacement text.
|
||||
*/
|
||||
replace(searchValue: { [Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string; }, replacer: (substring: string, ...args: any[]) => string): string;
|
||||
|
||||
/**
|
||||
* Finds the first substring match in a regular expression search.
|
||||
* @param searcher An object which supports searching within a string.
|
||||
*/
|
||||
search(searcher: { [Symbol.search](string: string): number; }): number;
|
||||
|
||||
/**
|
||||
* Split a string into substrings using the specified separator and return them as an array.
|
||||
* @param splitter An object that can split a string.
|
||||
* @param limit A value used to limit the number of elements returned in the array.
|
||||
*/
|
||||
split(splitter: { [Symbol.split](string: string, limit?: number): string[]; }, limit?: number): string[];
|
||||
}
|
||||
|
||||
interface ArrayBuffer {
|
||||
readonly [Symbol.toStringTag]: "ArrayBuffer";
|
||||
}
|
||||
|
||||
interface DataView<TArrayBuffer extends ArrayBufferLike> {
|
||||
readonly [Symbol.toStringTag]: string;
|
||||
}
|
||||
|
||||
interface Int8Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
readonly [Symbol.toStringTag]: "Int8Array";
|
||||
}
|
||||
|
||||
interface Uint8Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
readonly [Symbol.toStringTag]: "Uint8Array";
|
||||
}
|
||||
|
||||
interface Uint8ClampedArray<TArrayBuffer extends ArrayBufferLike> {
|
||||
readonly [Symbol.toStringTag]: "Uint8ClampedArray";
|
||||
}
|
||||
|
||||
interface Int16Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
readonly [Symbol.toStringTag]: "Int16Array";
|
||||
}
|
||||
|
||||
interface Uint16Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
readonly [Symbol.toStringTag]: "Uint16Array";
|
||||
}
|
||||
|
||||
interface Int32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
readonly [Symbol.toStringTag]: "Int32Array";
|
||||
}
|
||||
|
||||
interface Uint32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
readonly [Symbol.toStringTag]: "Uint32Array";
|
||||
}
|
||||
|
||||
interface Float32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
readonly [Symbol.toStringTag]: "Float32Array";
|
||||
}
|
||||
|
||||
interface Float64Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
readonly [Symbol.toStringTag]: "Float64Array";
|
||||
}
|
||||
|
||||
interface ArrayConstructor {
|
||||
readonly [Symbol.species]: ArrayConstructor;
|
||||
}
|
||||
interface MapConstructor {
|
||||
readonly [Symbol.species]: MapConstructor;
|
||||
}
|
||||
interface SetConstructor {
|
||||
readonly [Symbol.species]: SetConstructor;
|
||||
}
|
||||
interface ArrayBufferConstructor {
|
||||
readonly [Symbol.species]: ArrayBufferConstructor;
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface Array<T> {
|
||||
/**
|
||||
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
||||
* @param searchElement The element to search for.
|
||||
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
||||
*/
|
||||
includes(searchElement: T, fromIndex?: number): boolean;
|
||||
}
|
||||
|
||||
interface ReadonlyArray<T> {
|
||||
/**
|
||||
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
||||
* @param searchElement The element to search for.
|
||||
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
||||
*/
|
||||
includes(searchElement: T, fromIndex?: number): boolean;
|
||||
}
|
||||
|
||||
interface Int8Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
/**
|
||||
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
||||
* @param searchElement The element to search for.
|
||||
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
||||
*/
|
||||
includes(searchElement: number, fromIndex?: number): boolean;
|
||||
}
|
||||
|
||||
interface Uint8Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
/**
|
||||
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
||||
* @param searchElement The element to search for.
|
||||
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
||||
*/
|
||||
includes(searchElement: number, fromIndex?: number): boolean;
|
||||
}
|
||||
|
||||
interface Uint8ClampedArray<TArrayBuffer extends ArrayBufferLike> {
|
||||
/**
|
||||
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
||||
* @param searchElement The element to search for.
|
||||
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
||||
*/
|
||||
includes(searchElement: number, fromIndex?: number): boolean;
|
||||
}
|
||||
|
||||
interface Int16Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
/**
|
||||
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
||||
* @param searchElement The element to search for.
|
||||
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
||||
*/
|
||||
includes(searchElement: number, fromIndex?: number): boolean;
|
||||
}
|
||||
|
||||
interface Uint16Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
/**
|
||||
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
||||
* @param searchElement The element to search for.
|
||||
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
||||
*/
|
||||
includes(searchElement: number, fromIndex?: number): boolean;
|
||||
}
|
||||
|
||||
interface Int32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
/**
|
||||
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
||||
* @param searchElement The element to search for.
|
||||
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
||||
*/
|
||||
includes(searchElement: number, fromIndex?: number): boolean;
|
||||
}
|
||||
|
||||
interface Uint32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
/**
|
||||
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
||||
* @param searchElement The element to search for.
|
||||
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
||||
*/
|
||||
includes(searchElement: number, fromIndex?: number): boolean;
|
||||
}
|
||||
|
||||
interface Float32Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
/**
|
||||
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
||||
* @param searchElement The element to search for.
|
||||
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
||||
*/
|
||||
includes(searchElement: number, fromIndex?: number): boolean;
|
||||
}
|
||||
|
||||
interface Float64Array<TArrayBuffer extends ArrayBufferLike> {
|
||||
/**
|
||||
* Determines whether an array includes a certain element, returning true or false as appropriate.
|
||||
* @param searchElement The element to search for.
|
||||
* @param fromIndex The position in this array at which to begin searching for searchElement.
|
||||
*/
|
||||
includes(searchElement: number, fromIndex?: number): boolean;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2015" />
|
||||
/// <reference lib="es2016.array.include" />
|
||||
/// <reference lib="es2016.intl" />
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2016" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="webworker.importscripts" />
|
||||
/// <reference lib="scripthost" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
declare namespace Intl {
|
||||
/**
|
||||
* The `Intl.getCanonicalLocales()` method returns an array containing
|
||||
* the canonical locale names. Duplicates will be omitted and elements
|
||||
* will be validated as structurally valid language tags.
|
||||
*
|
||||
* [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
|
||||
*
|
||||
* @param locale A list of String values for which to get the canonical locale names
|
||||
* @returns An array containing the canonical and validated locale names.
|
||||
*/
|
||||
function getCanonicalLocales(locale?: string | readonly string[]): string[];
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface ArrayBufferConstructor {
|
||||
new (): ArrayBuffer;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2016" />
|
||||
/// <reference lib="es2017.arraybuffer" />
|
||||
/// <reference lib="es2017.date" />
|
||||
/// <reference lib="es2017.intl" />
|
||||
/// <reference lib="es2017.object" />
|
||||
/// <reference lib="es2017.sharedmemory" />
|
||||
/// <reference lib="es2017.string" />
|
||||
/// <reference lib="es2017.typedarrays" />
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface DateConstructor {
|
||||
/**
|
||||
* Returns the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date.
|
||||
* @param year The full year designation is required for cross-century date accuracy. If year is between 0 and 99 is used, then year is assumed to be 1900 + year.
|
||||
* @param monthIndex The month as a number between 0 and 11 (January to December).
|
||||
* @param date The date as a number between 1 and 31.
|
||||
* @param hours Must be supplied if minutes is supplied. A number from 0 to 23 (midnight to 11pm) that specifies the hour.
|
||||
* @param minutes Must be supplied if seconds is supplied. A number from 0 to 59 that specifies the minutes.
|
||||
* @param seconds Must be supplied if milliseconds is supplied. A number from 0 to 59 that specifies the seconds.
|
||||
* @param ms A number from 0 to 999 that specifies the milliseconds.
|
||||
*/
|
||||
UTC(year: number, monthIndex?: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number;
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2017" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="webworker.importscripts" />
|
||||
/// <reference lib="scripthost" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
declare namespace Intl {
|
||||
interface DateTimeFormatPartTypesRegistry {
|
||||
day: any;
|
||||
dayPeriod: any;
|
||||
era: any;
|
||||
hour: any;
|
||||
literal: any;
|
||||
minute: any;
|
||||
month: any;
|
||||
second: any;
|
||||
timeZoneName: any;
|
||||
weekday: any;
|
||||
year: any;
|
||||
}
|
||||
|
||||
type DateTimeFormatPartTypes = keyof DateTimeFormatPartTypesRegistry;
|
||||
|
||||
interface DateTimeFormatPart {
|
||||
type: DateTimeFormatPartTypes;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface DateTimeFormat {
|
||||
formatToParts(date?: Date | number): DateTimeFormatPart[];
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface ObjectConstructor {
|
||||
/**
|
||||
* Returns an array of values of the enumerable own properties of an object
|
||||
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
|
||||
*/
|
||||
values<T>(o: { [s: string]: T; } | ArrayLike<T>): T[];
|
||||
|
||||
/**
|
||||
* Returns an array of values of the enumerable own properties of an object
|
||||
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
|
||||
*/
|
||||
values(o: {}): any[];
|
||||
|
||||
/**
|
||||
* Returns an array of key/values of the enumerable own properties of an object
|
||||
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
|
||||
*/
|
||||
entries<T>(o: { [s: string]: T; } | ArrayLike<T>): [string, T][];
|
||||
|
||||
/**
|
||||
* Returns an array of key/values of the enumerable own properties of an object
|
||||
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
|
||||
*/
|
||||
entries(o: {}): [string, any][];
|
||||
|
||||
/**
|
||||
* Returns an object containing all own property descriptors of an object
|
||||
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
|
||||
*/
|
||||
getOwnPropertyDescriptors<T>(o: T): { [P in keyof T]: TypedPropertyDescriptor<T[P]>; } & { [x: string]: PropertyDescriptor; };
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2015.symbol" />
|
||||
/// <reference lib="es2015.symbol.wellknown" />
|
||||
|
||||
interface SharedArrayBuffer {
|
||||
/**
|
||||
* Read-only. The length of the ArrayBuffer (in bytes).
|
||||
*/
|
||||
readonly byteLength: number;
|
||||
|
||||
/**
|
||||
* Returns a section of an SharedArrayBuffer.
|
||||
*/
|
||||
slice(begin?: number, end?: number): SharedArrayBuffer;
|
||||
readonly [Symbol.toStringTag]: "SharedArrayBuffer";
|
||||
}
|
||||
|
||||
interface SharedArrayBufferConstructor {
|
||||
readonly prototype: SharedArrayBuffer;
|
||||
new (byteLength?: number): SharedArrayBuffer;
|
||||
readonly [Symbol.species]: SharedArrayBufferConstructor;
|
||||
}
|
||||
declare var SharedArrayBuffer: SharedArrayBufferConstructor;
|
||||
|
||||
interface ArrayBufferTypes {
|
||||
SharedArrayBuffer: SharedArrayBuffer;
|
||||
}
|
||||
|
||||
interface Atomics {
|
||||
/**
|
||||
* Adds a value to the value at the given position in the array, returning the original value.
|
||||
* Until this atomic operation completes, any other read or write operation against the array
|
||||
* will block.
|
||||
*/
|
||||
add(typedArray: Int8Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>, index: number, value: number): number;
|
||||
|
||||
/**
|
||||
* Stores the bitwise AND of a value with the value at the given position in the array,
|
||||
* returning the original value. Until this atomic operation completes, any other read or
|
||||
* write operation against the array will block.
|
||||
*/
|
||||
and(typedArray: Int8Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>, index: number, value: number): number;
|
||||
|
||||
/**
|
||||
* Replaces the value at the given position in the array if the original value equals the given
|
||||
* expected value, returning the original value. Until this atomic operation completes, any
|
||||
* other read or write operation against the array will block.
|
||||
*/
|
||||
compareExchange(typedArray: Int8Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>, index: number, expectedValue: number, replacementValue: number): number;
|
||||
|
||||
/**
|
||||
* Replaces the value at the given position in the array, returning the original value. Until
|
||||
* this atomic operation completes, any other read or write operation against the array will
|
||||
* block.
|
||||
*/
|
||||
exchange(typedArray: Int8Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>, index: number, value: number): number;
|
||||
|
||||
/**
|
||||
* Returns a value indicating whether high-performance algorithms can use atomic operations
|
||||
* (`true`) or must use locks (`false`) for the given number of bytes-per-element of a typed
|
||||
* array.
|
||||
*/
|
||||
isLockFree(size: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns the value at the given position in the array. Until this atomic operation completes,
|
||||
* any other read or write operation against the array will block.
|
||||
*/
|
||||
load(typedArray: Int8Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>, index: number): number;
|
||||
|
||||
/**
|
||||
* Stores the bitwise OR of a value with the value at the given position in the array,
|
||||
* returning the original value. Until this atomic operation completes, any other read or write
|
||||
* operation against the array will block.
|
||||
*/
|
||||
or(typedArray: Int8Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>, index: number, value: number): number;
|
||||
|
||||
/**
|
||||
* Stores a value at the given position in the array, returning the new value. Until this
|
||||
* atomic operation completes, any other read or write operation against the array will block.
|
||||
*/
|
||||
store(typedArray: Int8Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>, index: number, value: number): number;
|
||||
|
||||
/**
|
||||
* Subtracts a value from the value at the given position in the array, returning the original
|
||||
* value. Until this atomic operation completes, any other read or write operation against the
|
||||
* array will block.
|
||||
*/
|
||||
sub(typedArray: Int8Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>, index: number, value: number): number;
|
||||
|
||||
/**
|
||||
* If the value at the given position in the array is equal to the provided value, the current
|
||||
* agent is put to sleep causing execution to suspend until the timeout expires (returning
|
||||
* `"timed-out"`) or until the agent is awoken (returning `"ok"`); otherwise, returns
|
||||
* `"not-equal"`.
|
||||
*/
|
||||
wait(typedArray: Int32Array<ArrayBufferLike>, index: number, value: number, timeout?: number): "ok" | "not-equal" | "timed-out";
|
||||
|
||||
/**
|
||||
* Wakes up sleeping agents that are waiting on the given index of the array, returning the
|
||||
* number of agents that were awoken.
|
||||
* @param typedArray A shared Int32Array<ArrayBufferLike>.
|
||||
* @param index The position in the typedArray to wake up on.
|
||||
* @param count The number of sleeping agents to notify. Defaults to +Infinity.
|
||||
*/
|
||||
notify(typedArray: Int32Array<ArrayBufferLike>, index: number, count?: number): number;
|
||||
|
||||
/**
|
||||
* Stores the bitwise XOR of a value with the value at the given position in the array,
|
||||
* returning the original value. Until this atomic operation completes, any other read or write
|
||||
* operation against the array will block.
|
||||
*/
|
||||
xor(typedArray: Int8Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>, index: number, value: number): number;
|
||||
|
||||
readonly [Symbol.toStringTag]: "Atomics";
|
||||
}
|
||||
|
||||
declare var Atomics: Atomics;
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface String {
|
||||
/**
|
||||
* Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
|
||||
* The padding is applied from the start (left) of the current string.
|
||||
*
|
||||
* @param maxLength The length of the resulting string once the current string has been padded.
|
||||
* If this parameter is smaller than the current string's length, the current string will be returned as it is.
|
||||
*
|
||||
* @param fillString The string to pad the current string with.
|
||||
* If this string is too long, it will be truncated and the left-most part will be applied.
|
||||
* The default value for this parameter is " " (U+0020).
|
||||
*/
|
||||
padStart(maxLength: number, fillString?: string): string;
|
||||
|
||||
/**
|
||||
* Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
|
||||
* The padding is applied from the end (right) of the current string.
|
||||
*
|
||||
* @param maxLength The length of the resulting string once the current string has been padded.
|
||||
* If this parameter is smaller than the current string's length, the current string will be returned as it is.
|
||||
*
|
||||
* @param fillString The string to pad the current string with.
|
||||
* If this string is too long, it will be truncated and the left-most part will be applied.
|
||||
* The default value for this parameter is " " (U+0020).
|
||||
*/
|
||||
padEnd(maxLength: number, fillString?: string): string;
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface Int8ArrayConstructor {
|
||||
new (): Int8Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Uint8ArrayConstructor {
|
||||
new (): Uint8Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Uint8ClampedArrayConstructor {
|
||||
new (): Uint8ClampedArray<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Int16ArrayConstructor {
|
||||
new (): Int16Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Uint16ArrayConstructor {
|
||||
new (): Uint16Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Int32ArrayConstructor {
|
||||
new (): Int32Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Uint32ArrayConstructor {
|
||||
new (): Uint32Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Float32ArrayConstructor {
|
||||
new (): Float32Array<ArrayBuffer>;
|
||||
}
|
||||
|
||||
interface Float64ArrayConstructor {
|
||||
new (): Float64Array<ArrayBuffer>;
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2018.asynciterable" />
|
||||
|
||||
interface AsyncGenerator<T = unknown, TReturn = any, TNext = any> extends AsyncIteratorObject<T, TReturn, TNext> {
|
||||
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
|
||||
next(...[value]: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
|
||||
return(value: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T, TReturn>>;
|
||||
throw(e: any): Promise<IteratorResult<T, TReturn>>;
|
||||
[Symbol.asyncIterator](): AsyncGenerator<T, TReturn, TNext>;
|
||||
}
|
||||
|
||||
interface AsyncGeneratorFunction {
|
||||
/**
|
||||
* Creates a new AsyncGenerator object.
|
||||
* @param args A list of arguments the function accepts.
|
||||
*/
|
||||
new (...args: any[]): AsyncGenerator;
|
||||
/**
|
||||
* Creates a new AsyncGenerator object.
|
||||
* @param args A list of arguments the function accepts.
|
||||
*/
|
||||
(...args: any[]): AsyncGenerator;
|
||||
/**
|
||||
* The length of the arguments.
|
||||
*/
|
||||
readonly length: number;
|
||||
/**
|
||||
* Returns the name of the function.
|
||||
*/
|
||||
readonly name: string;
|
||||
/**
|
||||
* A reference to the prototype.
|
||||
*/
|
||||
readonly prototype: AsyncGenerator;
|
||||
}
|
||||
|
||||
interface AsyncGeneratorFunctionConstructor {
|
||||
/**
|
||||
* Creates a new AsyncGenerator function.
|
||||
* @param args A list of arguments the function accepts.
|
||||
*/
|
||||
new (...args: string[]): AsyncGeneratorFunction;
|
||||
/**
|
||||
* Creates a new AsyncGenerator function.
|
||||
* @param args A list of arguments the function accepts.
|
||||
*/
|
||||
(...args: string[]): AsyncGeneratorFunction;
|
||||
/**
|
||||
* The length of the arguments.
|
||||
*/
|
||||
readonly length: number;
|
||||
/**
|
||||
* Returns the name of the function.
|
||||
*/
|
||||
readonly name: string;
|
||||
/**
|
||||
* A reference to the prototype.
|
||||
*/
|
||||
readonly prototype: AsyncGeneratorFunction;
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2015.symbol" />
|
||||
/// <reference lib="es2015.iterable" />
|
||||
|
||||
interface SymbolConstructor {
|
||||
/**
|
||||
* A method that returns the default async iterator for an object. Called by the semantics of
|
||||
* the for-await-of statement.
|
||||
*/
|
||||
readonly asyncIterator: unique symbol;
|
||||
}
|
||||
|
||||
interface AsyncIterator<T, TReturn = any, TNext = any> {
|
||||
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
|
||||
next(...[value]: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
|
||||
return?(value?: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T, TReturn>>;
|
||||
throw?(e?: any): Promise<IteratorResult<T, TReturn>>;
|
||||
}
|
||||
|
||||
interface AsyncIterable<T, TReturn = any, TNext = any> {
|
||||
[Symbol.asyncIterator](): AsyncIterator<T, TReturn, TNext>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes a user-defined {@link AsyncIterator} that is also async iterable.
|
||||
*/
|
||||
interface AsyncIterableIterator<T, TReturn = any, TNext = any> extends AsyncIterator<T, TReturn, TNext> {
|
||||
[Symbol.asyncIterator](): AsyncIterableIterator<T, TReturn, TNext>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes an {@link AsyncIterator} produced by the runtime that inherits from the intrinsic `AsyncIterator.prototype`.
|
||||
*/
|
||||
interface AsyncIteratorObject<T, TReturn = unknown, TNext = unknown> extends AsyncIterator<T, TReturn, TNext> {
|
||||
[Symbol.asyncIterator](): AsyncIteratorObject<T, TReturn, TNext>;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2017" />
|
||||
/// <reference lib="es2018.asynciterable" />
|
||||
/// <reference lib="es2018.asyncgenerator" />
|
||||
/// <reference lib="es2018.promise" />
|
||||
/// <reference lib="es2018.regexp" />
|
||||
/// <reference lib="es2018.intl" />
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2018" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="webworker.importscripts" />
|
||||
/// <reference lib="scripthost" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
declare namespace Intl {
|
||||
// http://cldr.unicode.org/index/cldr-spec/plural-rules#TOC-Determining-Plural-Categories
|
||||
type LDMLPluralRule = "zero" | "one" | "two" | "few" | "many" | "other";
|
||||
type PluralRuleType = "cardinal" | "ordinal";
|
||||
|
||||
interface PluralRulesOptions {
|
||||
localeMatcher?: "lookup" | "best fit" | undefined;
|
||||
type?: PluralRuleType | undefined;
|
||||
minimumIntegerDigits?: number | undefined;
|
||||
minimumFractionDigits?: number | undefined;
|
||||
maximumFractionDigits?: number | undefined;
|
||||
minimumSignificantDigits?: number | undefined;
|
||||
maximumSignificantDigits?: number | undefined;
|
||||
}
|
||||
|
||||
interface ResolvedPluralRulesOptions {
|
||||
locale: string;
|
||||
pluralCategories: LDMLPluralRule[];
|
||||
type: PluralRuleType;
|
||||
minimumIntegerDigits: number;
|
||||
minimumFractionDigits: number;
|
||||
maximumFractionDigits: number;
|
||||
minimumSignificantDigits?: number;
|
||||
maximumSignificantDigits?: number;
|
||||
}
|
||||
|
||||
interface PluralRules {
|
||||
resolvedOptions(): ResolvedPluralRulesOptions;
|
||||
select(n: number): LDMLPluralRule;
|
||||
}
|
||||
|
||||
interface PluralRulesConstructor {
|
||||
new (locales?: string | readonly string[], options?: PluralRulesOptions): PluralRules;
|
||||
(locales?: string | readonly string[], options?: PluralRulesOptions): PluralRules;
|
||||
supportedLocalesOf(locales: string | readonly string[], options?: { localeMatcher?: "lookup" | "best fit"; }): string[];
|
||||
}
|
||||
|
||||
const PluralRules: PluralRulesConstructor;
|
||||
|
||||
interface NumberFormatPartTypeRegistry {
|
||||
literal: never;
|
||||
nan: never;
|
||||
infinity: never;
|
||||
percent: never;
|
||||
integer: never;
|
||||
group: never;
|
||||
decimal: never;
|
||||
fraction: never;
|
||||
plusSign: never;
|
||||
minusSign: never;
|
||||
percentSign: never;
|
||||
currency: never;
|
||||
}
|
||||
|
||||
type NumberFormatPartTypes = keyof NumberFormatPartTypeRegistry;
|
||||
|
||||
interface NumberFormatPart {
|
||||
type: NumberFormatPartTypes;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface NumberFormat {
|
||||
formatToParts(number?: number | bigint): NumberFormatPart[];
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/**
|
||||
* Represents the completion of an asynchronous operation
|
||||
*/
|
||||
interface Promise<T> {
|
||||
/**
|
||||
* Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
|
||||
* resolved value cannot be modified from the callback.
|
||||
* @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
|
||||
* @returns A Promise for the completion of the callback.
|
||||
*/
|
||||
finally(onfinally?: (() => void) | undefined | null): Promise<T>;
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface RegExpMatchArray {
|
||||
groups?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface RegExpExecArray {
|
||||
groups?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface RegExp {
|
||||
/**
|
||||
* Returns a Boolean value indicating the state of the dotAll flag (s) used with a regular expression.
|
||||
* Default is false. Read-only.
|
||||
*/
|
||||
readonly dotAll: boolean;
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
type FlatArray<Arr, Depth extends number> = {
|
||||
done: Arr;
|
||||
recur: Arr extends ReadonlyArray<infer InnerArr> ? FlatArray<InnerArr, [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20][Depth]>
|
||||
: Arr;
|
||||
}[Depth extends -1 ? "done" : "recur"];
|
||||
|
||||
interface ReadonlyArray<T> {
|
||||
/**
|
||||
* Calls a defined callback function on each element of an array. Then, flattens the result into
|
||||
* a new array.
|
||||
* This is identical to a map followed by flat with depth 1.
|
||||
*
|
||||
* @param callback A function that accepts up to three arguments. The flatMap method calls the
|
||||
* callback function one time for each element in the array.
|
||||
* @param thisArg An object to which the this keyword can refer in the callback function. If
|
||||
* thisArg is omitted, undefined is used as the this value.
|
||||
*/
|
||||
flatMap<U, This = undefined>(
|
||||
callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>,
|
||||
thisArg?: This,
|
||||
): U[];
|
||||
|
||||
/**
|
||||
* Returns a new array with all sub-array elements concatenated into it recursively up to the
|
||||
* specified depth.
|
||||
*
|
||||
* @param depth The maximum recursion depth
|
||||
*/
|
||||
flat<A, D extends number = 1>(
|
||||
this: A,
|
||||
depth?: D,
|
||||
): FlatArray<A, D>[];
|
||||
}
|
||||
|
||||
interface Array<T> {
|
||||
/**
|
||||
* Calls a defined callback function on each element of an array. Then, flattens the result into
|
||||
* a new array.
|
||||
* This is identical to a map followed by flat with depth 1.
|
||||
*
|
||||
* @param callback A function that accepts up to three arguments. The flatMap method calls the
|
||||
* callback function one time for each element in the array.
|
||||
* @param thisArg An object to which the this keyword can refer in the callback function. If
|
||||
* thisArg is omitted, undefined is used as the this value.
|
||||
*/
|
||||
flatMap<U, This = undefined>(
|
||||
callback: (this: This, value: T, index: number, array: T[]) => U | ReadonlyArray<U>,
|
||||
thisArg?: This,
|
||||
): U[];
|
||||
|
||||
/**
|
||||
* Returns a new array with all sub-array elements concatenated into it recursively up to the
|
||||
* specified depth.
|
||||
*
|
||||
* @param depth The maximum recursion depth
|
||||
*/
|
||||
flat<A, D extends number = 1>(
|
||||
this: A,
|
||||
depth?: D,
|
||||
): FlatArray<A, D>[];
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2018" />
|
||||
/// <reference lib="es2019.array" />
|
||||
/// <reference lib="es2019.object" />
|
||||
/// <reference lib="es2019.string" />
|
||||
/// <reference lib="es2019.symbol" />
|
||||
/// <reference lib="es2019.intl" />
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user