@lopatnov/express-reverse-proxy 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/.git/COMMIT_EDITMSG +1 -1
  2. package/.git/FETCH_HEAD +1 -5
  3. package/.git/ORIG_HEAD +1 -1
  4. package/.git/index +0 -0
  5. package/.git/logs/HEAD +2 -0
  6. package/.git/logs/refs/heads/master +2 -0
  7. package/.git/logs/refs/remotes/origin/dependabot/npm_and_yarn/moment-timezone-0.5.37 +1 -0
  8. package/.git/logs/refs/remotes/origin/master +2 -0
  9. package/.git/objects/0f/981da089a027ab4deb1f0c7864dfcee50bd0f1 +0 -0
  10. package/.git/objects/10/eee3c8fa2c12b77e0fed1f2fad1b967c267b53 +0 -0
  11. package/.git/objects/15/2c053b9a24234f6bec33280204f11e5d9dda6b +0 -0
  12. package/.git/objects/3b/2d52de53f2b2dd1e2ea057a01c0d0553236d21 +0 -0
  13. package/.git/objects/3c/43aaf00d26ff1acbc0a237198fc30baa6e25be +0 -0
  14. package/.git/objects/46/6d53dd4e6463d5e899cd61b80077af9100e3a8 +0 -0
  15. package/.git/objects/4e/3353916674e6e2d72452b43f1706f5916d2c89 +2 -0
  16. package/.git/objects/54/e5124ded8dd3a8ed0b19720474203dbc5c52be +0 -0
  17. package/.git/objects/58/2cf7a6f56fd9e6f5084a88c953da4013167b94 +0 -0
  18. package/.git/objects/6c/ef2f57e30fc6bc765e9ebfe3bf096e84101cc1 +0 -0
  19. package/.git/objects/70/ad2e555e35eb73420e7f7edd4177a20635e795 +0 -0
  20. package/.git/objects/84/b568065a1ee10c396c790029aef4fc7e990dcb +0 -0
  21. package/.git/objects/b6/b55dd9c407d6e3de1075ecf67a7f229496d75e +0 -0
  22. package/.git/objects/c0/7164be325d2c63ae2d899f18569a83e7b4ba67 +0 -0
  23. package/.git/objects/e9/94cd70c55ab2bbd98761c2e607daf9b2e97f8f +1 -0
  24. package/.git/refs/heads/master +1 -1
  25. package/.git/refs/remotes/origin/dependabot/npm_and_yarn/moment-timezone-0.5.37 +1 -0
  26. package/.git/refs/remotes/origin/master +1 -1
  27. package/.vscode/launch.json +14 -16
  28. package/LICENSE +185 -185
  29. package/README.md +3 -2
  30. package/node_modules/@eslint/eslintrc/LICENSE +5 -7
  31. package/node_modules/@eslint/eslintrc/README.md +4 -1
  32. package/node_modules/@eslint/eslintrc/conf/environments.js +24 -0
  33. package/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js +18 -5
  34. package/node_modules/@eslint/eslintrc/lib/config-array/ignore-pattern.js +2 -2
  35. package/node_modules/@eslint/eslintrc/lib/config-array-factory.js +43 -13
  36. package/node_modules/@eslint/eslintrc/lib/flat-compat.js +4 -7
  37. package/node_modules/@eslint/eslintrc/package.json +7 -6
  38. package/node_modules/@humanwhocodes/config-array/CHANGELOG.md +98 -0
  39. package/node_modules/@humanwhocodes/config-array/README.md +41 -4
  40. package/node_modules/@humanwhocodes/config-array/api.js +372 -134
  41. package/node_modules/@humanwhocodes/config-array/package.json +11 -12
  42. package/node_modules/@humanwhocodes/gitignore-to-minimatch/LICENSE +201 -0
  43. package/node_modules/@humanwhocodes/gitignore-to-minimatch/README.md +78 -0
  44. package/node_modules/@humanwhocodes/gitignore-to-minimatch/package.json +61 -0
  45. package/node_modules/@humanwhocodes/module-importer/CHANGELOG.md +15 -0
  46. package/node_modules/@humanwhocodes/module-importer/LICENSE +201 -0
  47. package/node_modules/@humanwhocodes/module-importer/README.md +80 -0
  48. package/node_modules/@humanwhocodes/module-importer/package.json +65 -0
  49. package/node_modules/@humanwhocodes/module-importer/src/module-importer.cjs +81 -0
  50. package/node_modules/@humanwhocodes/module-importer/src/module-importer.js +22 -0
  51. package/node_modules/@nodelib/fs.scandir/LICENSE +21 -0
  52. package/node_modules/@nodelib/fs.scandir/README.md +171 -0
  53. package/node_modules/@nodelib/fs.scandir/out/adapters/fs.d.ts +20 -0
  54. package/node_modules/@nodelib/fs.scandir/out/adapters/fs.js +19 -0
  55. package/node_modules/@nodelib/fs.scandir/out/constants.d.ts +4 -0
  56. package/node_modules/@nodelib/fs.scandir/out/constants.js +17 -0
  57. package/node_modules/@nodelib/fs.scandir/out/index.d.ts +12 -0
  58. package/node_modules/@nodelib/fs.scandir/out/index.js +26 -0
  59. package/node_modules/@nodelib/fs.scandir/out/providers/async.d.ts +7 -0
  60. package/node_modules/@nodelib/fs.scandir/out/providers/async.js +104 -0
  61. package/node_modules/@nodelib/fs.scandir/out/providers/common.d.ts +1 -0
  62. package/node_modules/@nodelib/fs.scandir/out/providers/common.js +13 -0
  63. package/node_modules/@nodelib/fs.scandir/out/providers/sync.d.ts +5 -0
  64. package/node_modules/@nodelib/fs.scandir/out/providers/sync.js +54 -0
  65. package/node_modules/@nodelib/fs.scandir/out/settings.d.ts +20 -0
  66. package/node_modules/@nodelib/fs.scandir/out/settings.js +24 -0
  67. package/node_modules/@nodelib/fs.scandir/out/types/index.d.ts +20 -0
  68. package/node_modules/@nodelib/fs.scandir/out/types/index.js +2 -0
  69. package/node_modules/@nodelib/fs.scandir/out/utils/fs.d.ts +2 -0
  70. package/node_modules/@nodelib/fs.scandir/out/utils/fs.js +19 -0
  71. package/node_modules/@nodelib/fs.scandir/out/utils/index.d.ts +2 -0
  72. package/node_modules/@nodelib/fs.scandir/out/utils/index.js +5 -0
  73. package/node_modules/@nodelib/fs.scandir/package.json +44 -0
  74. package/node_modules/@nodelib/fs.stat/LICENSE +21 -0
  75. package/node_modules/@nodelib/fs.stat/README.md +126 -0
  76. package/node_modules/@nodelib/fs.stat/out/adapters/fs.d.ts +13 -0
  77. package/node_modules/@nodelib/fs.stat/out/adapters/fs.js +17 -0
  78. package/node_modules/@nodelib/fs.stat/out/index.d.ts +12 -0
  79. package/node_modules/@nodelib/fs.stat/out/index.js +26 -0
  80. package/node_modules/@nodelib/fs.stat/out/providers/async.d.ts +4 -0
  81. package/node_modules/@nodelib/fs.stat/out/providers/async.js +36 -0
  82. package/node_modules/@nodelib/fs.stat/out/providers/sync.d.ts +3 -0
  83. package/node_modules/@nodelib/fs.stat/out/providers/sync.js +23 -0
  84. package/node_modules/@nodelib/fs.stat/out/settings.d.ts +16 -0
  85. package/node_modules/@nodelib/fs.stat/out/settings.js +16 -0
  86. package/node_modules/@nodelib/fs.stat/out/types/index.d.ts +4 -0
  87. package/node_modules/@nodelib/fs.stat/out/types/index.js +2 -0
  88. package/node_modules/@nodelib/fs.stat/package.json +37 -0
  89. package/node_modules/@nodelib/fs.walk/LICENSE +21 -0
  90. package/node_modules/@nodelib/fs.walk/README.md +215 -0
  91. package/node_modules/@nodelib/fs.walk/out/index.d.ts +14 -0
  92. package/node_modules/@nodelib/fs.walk/out/index.js +34 -0
  93. package/node_modules/@nodelib/fs.walk/out/providers/async.d.ts +12 -0
  94. package/node_modules/@nodelib/fs.walk/out/providers/async.js +30 -0
  95. package/node_modules/@nodelib/fs.walk/out/providers/index.d.ts +4 -0
  96. package/node_modules/@nodelib/fs.walk/out/providers/index.js +9 -0
  97. package/node_modules/@nodelib/fs.walk/out/providers/stream.d.ts +12 -0
  98. package/node_modules/@nodelib/fs.walk/out/providers/stream.js +34 -0
  99. package/node_modules/@nodelib/fs.walk/out/providers/sync.d.ts +10 -0
  100. package/node_modules/@nodelib/fs.walk/out/providers/sync.js +14 -0
  101. package/node_modules/@nodelib/fs.walk/out/readers/async.d.ts +30 -0
  102. package/node_modules/@nodelib/fs.walk/out/readers/async.js +97 -0
  103. package/node_modules/@nodelib/fs.walk/out/readers/common.d.ts +7 -0
  104. package/node_modules/@nodelib/fs.walk/out/readers/common.js +31 -0
  105. package/node_modules/@nodelib/fs.walk/out/readers/reader.d.ts +6 -0
  106. package/node_modules/@nodelib/fs.walk/out/readers/reader.js +11 -0
  107. package/node_modules/@nodelib/fs.walk/out/readers/sync.d.ts +15 -0
  108. package/node_modules/@nodelib/fs.walk/out/readers/sync.js +59 -0
  109. package/node_modules/@nodelib/fs.walk/out/settings.d.ts +30 -0
  110. package/node_modules/@nodelib/fs.walk/out/settings.js +26 -0
  111. package/node_modules/@nodelib/fs.walk/out/types/index.d.ts +8 -0
  112. package/node_modules/@nodelib/fs.walk/out/types/index.js +2 -0
  113. package/node_modules/@nodelib/fs.walk/package.json +44 -0
  114. package/node_modules/@pm2/io/node_modules/async/CHANGELOG.md +3 -0
  115. package/node_modules/@pm2/io/node_modules/async/internal/iterator.js +3 -0
  116. package/node_modules/@pm2/io/node_modules/async/package.json +1 -1
  117. package/node_modules/@pm2/js-api/node_modules/async/CHANGELOG.md +3 -0
  118. package/node_modules/@pm2/js-api/node_modules/async/internal/iterator.js +3 -0
  119. package/node_modules/@pm2/js-api/node_modules/async/package.json +1 -1
  120. package/package.json +10 -9
  121. package/server.js +85 -26
  122. package/node_modules/@eslint/eslintrc/conf/eslint-all.cjs +0 -12
  123. package/node_modules/@eslint/eslintrc/conf/eslint-recommended.cjs +0 -12
@@ -0,0 +1,80 @@
1
+ # ModuleImporter
2
+
3
+ by [Nicholas C. Zakas](https://humanwhocodes.com)
4
+
5
+ If you find this useful, please consider supporting my work with a [donation](https://humanwhocodes.com/donate).
6
+
7
+ ## Description
8
+
9
+ A utility for seamlessly importing modules in Node.js regardless if they are CommonJS or ESM format. Under the hood, this uses `import()` and relies on Node.js's CommonJS compatibility to work correctly. This ensures that the correct locations and formats are used for CommonJS so you can call one method and not worry about any compatibility issues.
10
+
11
+ The problem with the default `import()` is that it always resolves relative to the file location in which it is called. If you want to resolve from a different location, you need to jump through a few hoops to achieve that. This package makes it easy to both resolve and import modules from any directory.
12
+
13
+ ## Usage
14
+
15
+ ### Node.js
16
+
17
+ Install using [npm][npm] or [yarn][yarn]:
18
+
19
+ ```
20
+ npm install @humanwhocodes/module-importer
21
+
22
+ # or
23
+
24
+ yarn add @humanwhocodes/module-importer
25
+ ```
26
+
27
+ Import into your Node.js project:
28
+
29
+ ```js
30
+ // CommonJS
31
+ const { ModuleImporter } = require("@humanwhocodes/module-importer");
32
+
33
+ // ESM
34
+ import { ModuleImporter } from "@humanwhocodes/module-importer";
35
+ ```
36
+
37
+ ### Bun
38
+
39
+ Install using this command:
40
+
41
+ ```
42
+ bun add @humanwhocodes/module-importer
43
+ ```
44
+
45
+ Import into your Bun project:
46
+
47
+ ```js
48
+ import { ModuleImporter } from "@humanwhocodes/module-importer";
49
+ ```
50
+
51
+ ## API
52
+
53
+ After importing, create a new instance of `ModuleImporter` to start emitting events:
54
+
55
+ ```js
56
+ // cwd can be omitted to use process.cwd()
57
+ const importer = new ModuleImporter(cwd);
58
+
59
+ // you can resolve the location of any package
60
+ const location = importer.resolve("./some-file.cjs");
61
+
62
+ // you can also import directly
63
+ const module = importer.import("./some-file.cjs");
64
+ ```
65
+
66
+ For both `resolve()` and `import()`, you can pass in package names and filenames.
67
+
68
+ ## Developer Setup
69
+
70
+ 1. Fork the repository
71
+ 2. Clone your fork
72
+ 3. Run `npm install` to setup dependencies
73
+ 4. Run `npm test` to run tests
74
+
75
+ ## License
76
+
77
+ Apache 2.0
78
+
79
+ [npm]: https://npmjs.com/
80
+ [yarn]: https://yarnpkg.com/
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@humanwhocodes/module-importer",
3
+ "version": "1.0.1",
4
+ "description": "Universal module importer for Node.js",
5
+ "main": "src/module-importer.cjs",
6
+ "module": "src/module-importer.js",
7
+ "type": "module",
8
+ "types": "dist/module-importer.d.ts",
9
+ "exports": {
10
+ "require": "./src/module-importer.cjs",
11
+ "import": "./src/module-importer.js"
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "src"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "gitHooks": {
21
+ "pre-commit": "lint-staged"
22
+ },
23
+ "lint-staged": {
24
+ "*.js": [
25
+ "eslint --fix"
26
+ ]
27
+ },
28
+ "funding": {
29
+ "type": "github",
30
+ "url": "https://github.com/sponsors/nzakas"
31
+ },
32
+ "scripts": {
33
+ "build": "rollup -c && tsc",
34
+ "prepare": "npm run build",
35
+ "lint": "eslint src/ tests/",
36
+ "test:unit": "c8 mocha tests/module-importer.test.js",
37
+ "test:build": "node tests/pkg.test.cjs && node tests/pkg.test.mjs",
38
+ "test": "npm run test:unit && npm run test:build"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/humanwhocodes/module-importer.git"
43
+ },
44
+ "keywords": [
45
+ "modules",
46
+ "esm",
47
+ "commonjs"
48
+ ],
49
+ "engines": {
50
+ "node": ">=12.22"
51
+ },
52
+ "author": "Nicholas C. Zaks",
53
+ "license": "Apache-2.0",
54
+ "devDependencies": {
55
+ "@types/node": "^18.7.6",
56
+ "c8": "7.12.0",
57
+ "chai": "4.3.6",
58
+ "eslint": "8.22.0",
59
+ "lint-staged": "13.0.3",
60
+ "mocha": "9.2.2",
61
+ "rollup": "2.78.0",
62
+ "typescript": "4.7.4",
63
+ "yorkie": "2.0.0"
64
+ }
65
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @fileoverview Universal module importer
3
+ */
4
+
5
+ //-----------------------------------------------------------------------------
6
+ // Imports
7
+ //-----------------------------------------------------------------------------
8
+
9
+ const { createRequire } = require("module");
10
+ const { pathToFileURL } = require("url");
11
+
12
+ //-----------------------------------------------------------------------------
13
+ // Helpers
14
+ //-----------------------------------------------------------------------------
15
+
16
+ const SLASHES = new Set(["/", "\\"]);
17
+
18
+ /**
19
+ * Normalizes directories to have a trailing slash.
20
+ * Resolve is pretty finicky -- if the directory name doesn't have
21
+ * a trailing slash then it tries to look in the parent directory.
22
+ * i.e., if the directory is "/usr/nzakas/foo" it will start the
23
+ * search in /usr/nzakas. However, if the directory is "/user/nzakas/foo/",
24
+ * then it will start the search in /user/nzakas/foo.
25
+ * @param {string} directory The directory to check.
26
+ * @returns {string} The normalized directory.
27
+ */
28
+ function normalizeDirectory(directory) {
29
+ if (!SLASHES.has(directory[directory.length-1])) {
30
+ return directory + "/";
31
+ }
32
+
33
+ return directory;
34
+ }
35
+
36
+ //-----------------------------------------------------------------------------
37
+ // Exports
38
+ //-----------------------------------------------------------------------------
39
+
40
+ /**
41
+ * Class for importing both CommonJS and ESM modules in Node.js.
42
+ */
43
+ exports.ModuleImporter = class ModuleImporter {
44
+
45
+ /**
46
+ * Creates a new instance.
47
+ * @param {string} [cwd] The current working directory to resolve from.
48
+ */
49
+ constructor(cwd = process.cwd()) {
50
+
51
+ /**
52
+ * The base directory from which paths should be resolved.
53
+ * @type {string}
54
+ */
55
+ this.cwd = normalizeDirectory(cwd);
56
+ }
57
+
58
+ /**
59
+ * Resolves a module based on its name or location.
60
+ * @param {string} specifier Either an npm package name or
61
+ * relative file path.
62
+ * @returns {string|undefined} The location of the import.
63
+ * @throws {Error} If specifier cannot be located.
64
+ */
65
+ resolve(specifier) {
66
+ const require = createRequire(this.cwd);
67
+ return require.resolve(specifier);
68
+ }
69
+
70
+ /**
71
+ * Imports a module based on its name or location.
72
+ * @param {string} specifier Either an npm package name or
73
+ * relative file path.
74
+ * @returns {Promise<object>} The module's object.
75
+ */
76
+ import(specifier) {
77
+ const location = this.resolve(specifier);
78
+ return import(pathToFileURL(location).href);
79
+ }
80
+
81
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @fileoverview Universal module importer
3
+ */
4
+
5
+ //-----------------------------------------------------------------------------
6
+ // Imports
7
+ //-----------------------------------------------------------------------------
8
+
9
+ import { createRequire } from "module";
10
+ import { fileURLToPath } from "url";
11
+ import { dirname } from "path";
12
+
13
+ //-----------------------------------------------------------------------------
14
+ // Helpers
15
+ //-----------------------------------------------------------------------------
16
+
17
+ const __filename = fileURLToPath(import.meta.url);
18
+ const __dirname = dirname(__filename);
19
+ const require = createRequire(__dirname + "/");
20
+ const { ModuleImporter } = require("./module-importer.cjs");
21
+
22
+ export { ModuleImporter };
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Denis Malinochkin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,171 @@
1
+ # @nodelib/fs.scandir
2
+
3
+ > List files and directories inside the specified directory.
4
+
5
+ ## :bulb: Highlights
6
+
7
+ The package is aimed at obtaining information about entries in the directory.
8
+
9
+ * :moneybag: Returns useful information: `name`, `path`, `dirent` and `stats` (optional).
10
+ * :gear: On Node.js 10.10+ uses the mechanism without additional calls to determine the entry type. See [`old` and `modern` mode](#old-and-modern-mode).
11
+ * :link: Can safely work with broken symbolic links.
12
+
13
+ ## Install
14
+
15
+ ```console
16
+ npm install @nodelib/fs.scandir
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```ts
22
+ import * as fsScandir from '@nodelib/fs.scandir';
23
+
24
+ fsScandir.scandir('path', (error, stats) => { /* … */ });
25
+ ```
26
+
27
+ ## API
28
+
29
+ ### .scandir(path, [optionsOrSettings], callback)
30
+
31
+ Returns an array of plain objects ([`Entry`](#entry)) with information about entry for provided path with standard callback-style.
32
+
33
+ ```ts
34
+ fsScandir.scandir('path', (error, entries) => { /* … */ });
35
+ fsScandir.scandir('path', {}, (error, entries) => { /* … */ });
36
+ fsScandir.scandir('path', new fsScandir.Settings(), (error, entries) => { /* … */ });
37
+ ```
38
+
39
+ ### .scandirSync(path, [optionsOrSettings])
40
+
41
+ Returns an array of plain objects ([`Entry`](#entry)) with information about entry for provided path.
42
+
43
+ ```ts
44
+ const entries = fsScandir.scandirSync('path');
45
+ const entries = fsScandir.scandirSync('path', {});
46
+ const entries = fsScandir.scandirSync(('path', new fsScandir.Settings());
47
+ ```
48
+
49
+ #### path
50
+
51
+ * Required: `true`
52
+ * Type: `string | Buffer | URL`
53
+
54
+ A path to a file. If a URL is provided, it must use the `file:` protocol.
55
+
56
+ #### optionsOrSettings
57
+
58
+ * Required: `false`
59
+ * Type: `Options | Settings`
60
+ * Default: An instance of `Settings` class
61
+
62
+ An [`Options`](#options) object or an instance of [`Settings`](#settingsoptions) class.
63
+
64
+ > :book: When you pass a plain object, an instance of the `Settings` class will be created automatically. If you plan to call the method frequently, use a pre-created instance of the `Settings` class.
65
+
66
+ ### Settings([options])
67
+
68
+ A class of full settings of the package.
69
+
70
+ ```ts
71
+ const settings = new fsScandir.Settings({ followSymbolicLinks: false });
72
+
73
+ const entries = fsScandir.scandirSync('path', settings);
74
+ ```
75
+
76
+ ## Entry
77
+
78
+ * `name` — The name of the entry (`unknown.txt`).
79
+ * `path` — The path of the entry relative to call directory (`root/unknown.txt`).
80
+ * `dirent` — An instance of [`fs.Dirent`](./src/types/index.ts) class. On Node.js below 10.10 will be emulated by [`DirentFromStats`](./src/utils/fs.ts) class.
81
+ * `stats` (optional) — An instance of `fs.Stats` class.
82
+
83
+ For example, the `scandir` call for `tools` directory with one directory inside:
84
+
85
+ ```ts
86
+ {
87
+ dirent: Dirent { name: 'typedoc', /* … */ },
88
+ name: 'typedoc',
89
+ path: 'tools/typedoc'
90
+ }
91
+ ```
92
+
93
+ ## Options
94
+
95
+ ### stats
96
+
97
+ * Type: `boolean`
98
+ * Default: `false`
99
+
100
+ Adds an instance of `fs.Stats` class to the [`Entry`](#entry).
101
+
102
+ > :book: Always use `fs.readdir` without the `withFileTypes` option. ??TODO??
103
+
104
+ ### followSymbolicLinks
105
+
106
+ * Type: `boolean`
107
+ * Default: `false`
108
+
109
+ Follow symbolic links or not. Call `fs.stat` on symbolic link if `true`.
110
+
111
+ ### `throwErrorOnBrokenSymbolicLink`
112
+
113
+ * Type: `boolean`
114
+ * Default: `true`
115
+
116
+ Throw an error when symbolic link is broken if `true` or safely use `lstat` call if `false`.
117
+
118
+ ### `pathSegmentSeparator`
119
+
120
+ * Type: `string`
121
+ * Default: `path.sep`
122
+
123
+ By default, this package uses the correct path separator for your OS (`\` on Windows, `/` on Unix-like systems). But you can set this option to any separator character(s) that you want to use instead.
124
+
125
+ ### `fs`
126
+
127
+ * Type: [`FileSystemAdapter`](./src/adapters/fs.ts)
128
+ * Default: A default FS methods
129
+
130
+ By default, the built-in Node.js module (`fs`) is used to work with the file system. You can replace any method with your own.
131
+
132
+ ```ts
133
+ interface FileSystemAdapter {
134
+ lstat?: typeof fs.lstat;
135
+ stat?: typeof fs.stat;
136
+ lstatSync?: typeof fs.lstatSync;
137
+ statSync?: typeof fs.statSync;
138
+ readdir?: typeof fs.readdir;
139
+ readdirSync?: typeof fs.readdirSync;
140
+ }
141
+
142
+ const settings = new fsScandir.Settings({
143
+ fs: { lstat: fakeLstat }
144
+ });
145
+ ```
146
+
147
+ ## `old` and `modern` mode
148
+
149
+ This package has two modes that are used depending on the environment and parameters of use.
150
+
151
+ ### old
152
+
153
+ * Node.js below `10.10` or when the `stats` option is enabled
154
+
155
+ When working in the old mode, the directory is read first (`fs.readdir`), then the type of entries is determined (`fs.lstat` and/or `fs.stat` for symbolic links).
156
+
157
+ ### modern
158
+
159
+ * Node.js 10.10+ and the `stats` option is disabled
160
+
161
+ In the modern mode, reading the directory (`fs.readdir` with the `withFileTypes` option) is combined with obtaining information about its entries. An additional call for symbolic links (`fs.stat`) is still present.
162
+
163
+ This mode makes fewer calls to the file system. It's faster.
164
+
165
+ ## Changelog
166
+
167
+ See the [Releases section of our GitHub project](https://github.com/nodelib/nodelib/releases) for changelog for each release version.
168
+
169
+ ## License
170
+
171
+ This software is released under the terms of the MIT license.
@@ -0,0 +1,20 @@
1
+ import type * as fsStat from '@nodelib/fs.stat';
2
+ import type { Dirent, ErrnoException } from '../types';
3
+ export interface ReaddirAsynchronousMethod {
4
+ (filepath: string, options: {
5
+ withFileTypes: true;
6
+ }, callback: (error: ErrnoException | null, files: Dirent[]) => void): void;
7
+ (filepath: string, callback: (error: ErrnoException | null, files: string[]) => void): void;
8
+ }
9
+ export interface ReaddirSynchronousMethod {
10
+ (filepath: string, options: {
11
+ withFileTypes: true;
12
+ }): Dirent[];
13
+ (filepath: string): string[];
14
+ }
15
+ export declare type FileSystemAdapter = fsStat.FileSystemAdapter & {
16
+ readdir: ReaddirAsynchronousMethod;
17
+ readdirSync: ReaddirSynchronousMethod;
18
+ };
19
+ export declare const FILE_SYSTEM_ADAPTER: FileSystemAdapter;
20
+ export declare function createFileSystemAdapter(fsMethods?: Partial<FileSystemAdapter>): FileSystemAdapter;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
4
+ const fs = require("fs");
5
+ exports.FILE_SYSTEM_ADAPTER = {
6
+ lstat: fs.lstat,
7
+ stat: fs.stat,
8
+ lstatSync: fs.lstatSync,
9
+ statSync: fs.statSync,
10
+ readdir: fs.readdir,
11
+ readdirSync: fs.readdirSync
12
+ };
13
+ function createFileSystemAdapter(fsMethods) {
14
+ if (fsMethods === undefined) {
15
+ return exports.FILE_SYSTEM_ADAPTER;
16
+ }
17
+ return Object.assign(Object.assign({}, exports.FILE_SYSTEM_ADAPTER), fsMethods);
18
+ }
19
+ exports.createFileSystemAdapter = createFileSystemAdapter;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * IS `true` for Node.js 10.10 and greater.
3
+ */
4
+ export declare const IS_SUPPORT_READDIR_WITH_FILE_TYPES: boolean;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IS_SUPPORT_READDIR_WITH_FILE_TYPES = void 0;
4
+ const NODE_PROCESS_VERSION_PARTS = process.versions.node.split('.');
5
+ if (NODE_PROCESS_VERSION_PARTS[0] === undefined || NODE_PROCESS_VERSION_PARTS[1] === undefined) {
6
+ throw new Error(`Unexpected behavior. The 'process.versions.node' variable has invalid value: ${process.versions.node}`);
7
+ }
8
+ const MAJOR_VERSION = Number.parseInt(NODE_PROCESS_VERSION_PARTS[0], 10);
9
+ const MINOR_VERSION = Number.parseInt(NODE_PROCESS_VERSION_PARTS[1], 10);
10
+ const SUPPORTED_MAJOR_VERSION = 10;
11
+ const SUPPORTED_MINOR_VERSION = 10;
12
+ const IS_MATCHED_BY_MAJOR = MAJOR_VERSION > SUPPORTED_MAJOR_VERSION;
13
+ const IS_MATCHED_BY_MAJOR_AND_MINOR = MAJOR_VERSION === SUPPORTED_MAJOR_VERSION && MINOR_VERSION >= SUPPORTED_MINOR_VERSION;
14
+ /**
15
+ * IS `true` for Node.js 10.10 and greater.
16
+ */
17
+ exports.IS_SUPPORT_READDIR_WITH_FILE_TYPES = IS_MATCHED_BY_MAJOR || IS_MATCHED_BY_MAJOR_AND_MINOR;
@@ -0,0 +1,12 @@
1
+ import type { FileSystemAdapter, ReaddirAsynchronousMethod, ReaddirSynchronousMethod } from './adapters/fs';
2
+ import * as async from './providers/async';
3
+ import Settings, { Options } from './settings';
4
+ import type { Dirent, Entry } from './types';
5
+ declare type AsyncCallback = async.AsyncCallback;
6
+ declare function scandir(path: string, callback: AsyncCallback): void;
7
+ declare function scandir(path: string, optionsOrSettings: Options | Settings, callback: AsyncCallback): void;
8
+ declare namespace scandir {
9
+ function __promisify__(path: string, optionsOrSettings?: Options | Settings): Promise<Entry[]>;
10
+ }
11
+ declare function scandirSync(path: string, optionsOrSettings?: Options | Settings): Entry[];
12
+ export { scandir, scandirSync, Settings, AsyncCallback, Dirent, Entry, FileSystemAdapter, ReaddirAsynchronousMethod, ReaddirSynchronousMethod, Options };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Settings = exports.scandirSync = exports.scandir = void 0;
4
+ const async = require("./providers/async");
5
+ const sync = require("./providers/sync");
6
+ const settings_1 = require("./settings");
7
+ exports.Settings = settings_1.default;
8
+ function scandir(path, optionsOrSettingsOrCallback, callback) {
9
+ if (typeof optionsOrSettingsOrCallback === 'function') {
10
+ async.read(path, getSettings(), optionsOrSettingsOrCallback);
11
+ return;
12
+ }
13
+ async.read(path, getSettings(optionsOrSettingsOrCallback), callback);
14
+ }
15
+ exports.scandir = scandir;
16
+ function scandirSync(path, optionsOrSettings) {
17
+ const settings = getSettings(optionsOrSettings);
18
+ return sync.read(path, settings);
19
+ }
20
+ exports.scandirSync = scandirSync;
21
+ function getSettings(settingsOrOptions = {}) {
22
+ if (settingsOrOptions instanceof settings_1.default) {
23
+ return settingsOrOptions;
24
+ }
25
+ return new settings_1.default(settingsOrOptions);
26
+ }
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ import type Settings from '../settings';
3
+ import type { Entry } from '../types';
4
+ export declare type AsyncCallback = (error: NodeJS.ErrnoException, entries: Entry[]) => void;
5
+ export declare function read(directory: string, settings: Settings, callback: AsyncCallback): void;
6
+ export declare function readdirWithFileTypes(directory: string, settings: Settings, callback: AsyncCallback): void;
7
+ export declare function readdir(directory: string, settings: Settings, callback: AsyncCallback): void;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readdir = exports.readdirWithFileTypes = exports.read = void 0;
4
+ const fsStat = require("@nodelib/fs.stat");
5
+ const rpl = require("run-parallel");
6
+ const constants_1 = require("../constants");
7
+ const utils = require("../utils");
8
+ const common = require("./common");
9
+ function read(directory, settings, callback) {
10
+ if (!settings.stats && constants_1.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
11
+ readdirWithFileTypes(directory, settings, callback);
12
+ return;
13
+ }
14
+ readdir(directory, settings, callback);
15
+ }
16
+ exports.read = read;
17
+ function readdirWithFileTypes(directory, settings, callback) {
18
+ settings.fs.readdir(directory, { withFileTypes: true }, (readdirError, dirents) => {
19
+ if (readdirError !== null) {
20
+ callFailureCallback(callback, readdirError);
21
+ return;
22
+ }
23
+ const entries = dirents.map((dirent) => ({
24
+ dirent,
25
+ name: dirent.name,
26
+ path: common.joinPathSegments(directory, dirent.name, settings.pathSegmentSeparator)
27
+ }));
28
+ if (!settings.followSymbolicLinks) {
29
+ callSuccessCallback(callback, entries);
30
+ return;
31
+ }
32
+ const tasks = entries.map((entry) => makeRplTaskEntry(entry, settings));
33
+ rpl(tasks, (rplError, rplEntries) => {
34
+ if (rplError !== null) {
35
+ callFailureCallback(callback, rplError);
36
+ return;
37
+ }
38
+ callSuccessCallback(callback, rplEntries);
39
+ });
40
+ });
41
+ }
42
+ exports.readdirWithFileTypes = readdirWithFileTypes;
43
+ function makeRplTaskEntry(entry, settings) {
44
+ return (done) => {
45
+ if (!entry.dirent.isSymbolicLink()) {
46
+ done(null, entry);
47
+ return;
48
+ }
49
+ settings.fs.stat(entry.path, (statError, stats) => {
50
+ if (statError !== null) {
51
+ if (settings.throwErrorOnBrokenSymbolicLink) {
52
+ done(statError);
53
+ return;
54
+ }
55
+ done(null, entry);
56
+ return;
57
+ }
58
+ entry.dirent = utils.fs.createDirentFromStats(entry.name, stats);
59
+ done(null, entry);
60
+ });
61
+ };
62
+ }
63
+ function readdir(directory, settings, callback) {
64
+ settings.fs.readdir(directory, (readdirError, names) => {
65
+ if (readdirError !== null) {
66
+ callFailureCallback(callback, readdirError);
67
+ return;
68
+ }
69
+ const tasks = names.map((name) => {
70
+ const path = common.joinPathSegments(directory, name, settings.pathSegmentSeparator);
71
+ return (done) => {
72
+ fsStat.stat(path, settings.fsStatSettings, (error, stats) => {
73
+ if (error !== null) {
74
+ done(error);
75
+ return;
76
+ }
77
+ const entry = {
78
+ name,
79
+ path,
80
+ dirent: utils.fs.createDirentFromStats(name, stats)
81
+ };
82
+ if (settings.stats) {
83
+ entry.stats = stats;
84
+ }
85
+ done(null, entry);
86
+ });
87
+ };
88
+ });
89
+ rpl(tasks, (rplError, entries) => {
90
+ if (rplError !== null) {
91
+ callFailureCallback(callback, rplError);
92
+ return;
93
+ }
94
+ callSuccessCallback(callback, entries);
95
+ });
96
+ });
97
+ }
98
+ exports.readdir = readdir;
99
+ function callFailureCallback(callback, error) {
100
+ callback(error);
101
+ }
102
+ function callSuccessCallback(callback, result) {
103
+ callback(null, result);
104
+ }
@@ -0,0 +1 @@
1
+ export declare function joinPathSegments(a: string, b: string, separator: string): string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.joinPathSegments = void 0;
4
+ function joinPathSegments(a, b, separator) {
5
+ /**
6
+ * The correct handling of cases when the first segment is a root (`/`, `C:/`) or UNC path (`//?/C:/`).
7
+ */
8
+ if (a.endsWith(separator)) {
9
+ return a + b;
10
+ }
11
+ return a + separator + b;
12
+ }
13
+ exports.joinPathSegments = joinPathSegments;