This commit is contained in:
2025-09-19 14:25:20 +08:00
parent 269893a435
commit fbf3f77229
24949 changed files with 2839404 additions and 0 deletions

8
node_modules/is-file-esm/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,8 @@
language: node_js
sudo: false
node_js:
- 12
- 14
- 15
script:
- npm run ci

21
node_modules/is-file-esm/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License Copyright (c) 2020 David Mark Clements
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
(including the next paragraph) 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.

104
node_modules/is-file-esm/index.js generated vendored Normal file
View File

@@ -0,0 +1,104 @@
'use strict'
const { extname, isAbsolute, dirname } = require('path')
const { access, accessSync, constants: { F_OK } } = require('fs')
const { promisify, callbackify } = require('util')
const readPkgUp = callbackify(require('read-pkg-up'))
const isFileEsmPromise = promisify(isFileEsm)
const tick = queueMicrotask
const ERR_PATH_MUST_BE_STRING = 'is-esm: path must be a string'
const ERR_PATH_MUST_BE_ABSOLUTE = 'is-esm: absolute paths only'
const ERR_PATH_MUST_EXIST = 'is-esm: path does not exist'
const ERR_PATH_MUST_HAVE_VALID_EXT = 'is-esm: path must be to a file with an extension of .js, .mjs or .cjs'
function isFileEsm (path, cb) {
if (arguments.length <= 1) return isFileEsmPromise(path)
if (typeof path !== 'string') return void tick(() => cb(Error(ERR_PATH_MUST_BE_STRING)))
if (isAbsolute(path) === false) return void tick(() => cb(Error(ERR_PATH_MUST_BE_ABSOLUTE)))
const extMatch = /\.(c|m)?js/.exec(extname(path))
if (extMatch === null) return void tick(() => cb(Error(ERR_PATH_MUST_HAVE_VALID_EXT)))
access(path, F_OK, (err) => {
if (err) return void cb(Error(ERR_PATH_MUST_EXIST))
const [, extType = 'j'] = extMatch
const cwd = dirname(path)
readPkgUp({ cwd }, (err, pkg) => {
if (err) return void cb(err)
const { type } = pkg.packageJson
switch (type) {
case undefined: {
if (extType === 'j') return void cb(null, { esm: false, type, extType, path, pkgPath: pkg.path })
if (extType === 'm') return void cb(null, { esm: true, type, extType, path, pkgPath: pkg.path })
/* istanbul ignore else */
if (extType === 'c') return void cb(null, { esm: false, type, extType, path, pkgPath: pkg.path })
// unreachable
}
case 'commonjs': {
if (extType === 'j') return void cb(null, { esm: false, type, extType, path, pkgPath: pkg.path })
if (extType === 'm') return void cb(null, { esm: true, type, extType, path, pkgPath: pkg.path })
/* istanbul ignore else */
if (extType === 'c') return void cb(null, { esm: false, type, extType, path, pkgPath: pkg.path })
// unreachable
}
case 'module': {
if (extType === 'j') return void cb(null, { esm: true, type, extType, path, pkgPath: pkg.path })
if (extType === 'm') return void cb(null, { esm: true, type, extType, path, pkgPath: pkg.path })
/* istanbul ignore else */
if (extType === 'c') return void cb(null, { esm: false, type, extType, path, pkgPath: pkg.path })
// unreachable
}
default: return void cb(Object.assign(Error(`package.json type "${type}" not recognized`), { meta: { type, extType, path, pkgPath: pkg.path } }))
}
})
})
}
isFileEsm.sync = function isFileEsmSync (path) {
if (typeof path !== 'string') throw Error(ERR_PATH_MUST_BE_STRING)
if (isAbsolute(path) === false) throw Error(ERR_PATH_MUST_BE_ABSOLUTE)
const extMatch = /\.(c|m)?js/.exec(extname(path))
if (extMatch === null) throw Error(ERR_PATH_MUST_HAVE_VALID_EXT)
try {
accessSync(path, F_OK)
} catch (err) {
throw Error(ERR_PATH_MUST_EXIST)
}
const [, extType = 'j'] = extMatch
const cwd = dirname(path)
const pkg = readPkgUp.sync({ cwd })
const { type } = pkg.packageJson
switch (type) {
case undefined: {
if (extType === 'j') return { esm: false, type, extType, path, pkgPath: pkg.path }
if (extType === 'm') return { esm: true, type, extType, path, pkgPath: pkg.path }
/* istanbul ignore else */
if (extType === 'c') return { esm: false, type, extType, path, pkgPath: pkg.path }
// unreachable
}
case 'commonjs': {
if (extType === 'j') return { esm: false, type, extType, path, pkgPath: pkg.path }
if (extType === 'm') return { esm: true, type, extType, path, pkgPath: pkg.path }
/* istanbul ignore else */
if (extType === 'c') return { esm: false, type, extType, path, pkgPath: pkg.path }
// unreachable
}
case 'module': {
if (extType === 'j') return { esm: true, type, extType, path, pkgPath: pkg.path }
if (extType === 'm') return { esm: true, type, extType, path, pkgPath: pkg.path }
/* istanbul ignore else */
if (extType === 'c') return { esm: false, type, extType, path, pkgPath: pkg.path }
// unreachable
}
default: throw Object.assign(Error(`package.json type "${type}" not recognized`), { meta: { type, extType, path, pkgPath: pkg.path } })
}
}
isFileEsm.constants = {
ERR_PATH_MUST_BE_STRING,
ERR_PATH_MUST_BE_ABSOLUTE,
ERR_PATH_MUST_EXIST,
ERR_PATH_MUST_HAVE_VALID_EXT
}
module.exports = isFileEsm

44
node_modules/is-file-esm/package.json generated vendored Normal file
View File

@@ -0,0 +1,44 @@
{
"name": "is-file-esm",
"version": "1.0.0",
"description": "Determines whether a Node file is a Module (`import`) or a Script (`require`)",
"main": "index.js",
"scripts": {
"test": "tap -R classic --100",
"ci": "npm test"
},
"keywords": [
"esm",
"cjs",
"package.json",
"module",
"ecmascript modules",
"native modules",
"native ecmascript modules"
],
"author": "David Mark Clements (@davidmarkclem)",
"license": "MIT",
"engineStrict": true,
"engine": {
"node": ">= 12.4.0"
},
"devDependencies": {
"nonsynchronous": "^1.2.0",
"standard": "^14.3.4",
"tap": "^14.10.8"
},
"dependencies": {
"read-pkg-up": "^7.0.1"
},
"directories": {
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/davidmarkclements/is-file-esm.git"
},
"bugs": {
"url": "https://github.com/davidmarkclements/is-file-esm/issues"
},
"homepage": "https://github.com/davidmarkclements/is-file-esm#readme"
}

108
node_modules/is-file-esm/readme.md generated vendored Normal file
View File

@@ -0,0 +1,108 @@
# is-file-esm
> Determines whether a Node file is a Module (`import`) or a Script (`require`)
## Algorithm
Determining the module system of a file comes from three inputs, the `type` field
of the closest `package.json` to that file, the file extension (`.js`, `.mjs` or `.cjs`)
and the lesser know `--input-type` command-line flag. The latter only applies to
dyamic input (via STDIN, `--eval` or `--print` flags) so is not considered with this library.
So to determine whether a file is an esm file (e.g. native EcmaScript modules) or not,
we use the following procedure:
```
read package.json for "type" field,
if type is "module"
if answer.mjs -> module
if answer.js -> module
if answer.cjs -> script
if type is "commonjs"
if answer.mjs -> module
if answer.js -> script
if answer.cjs -> script
if type is not set
if answer.mjs -> module
if answer.js -> script
if answer.cjs -> script
```
## API
The `is-file-esm` module provides synchronous, awaitable (promise-based) and callback based APIs.
In each case the Result object has the following shape:
```js
{
esm: Boolean, // true if file is a Module, false if it is a Script
type: String, // the determined package.json type, may be undefined, 'module', or 'commonjs'
extType: String, // the file extension type, may be 'c', 'm' or 'j'
path: String, // the input path
pkgPath: String // the path to the package.json from which the type was determined
}
```
### Awaitable (promise-based)
#### `await isFileEsm(path) => Result`
```js
import isFileEsm from 'is-file-esm'
const { esm, path } = await isFileEsm('/path/to/file.js')
if (esm) console.log(`File ${path} is a Module`)
else console.log(`File ${path} is a Script`)
```
### Callback-style
#### `isFileEsm(path, cb(err, Result))`
```js
const isFileEsm = require('is-file-esm')
isFileEsm('/path/to/file.js', (err, result) => {
if (err) {
console.error(err)
return
}
if (result.esm) console.log(`File ${result.path} is a Module`)
else console.log(`File ${result.path} is a Script`)
})
```
### Synchronous
#### `isFileEsm.sync(path) => Result`
```js
import isFileEsm from 'is-file-esm'
const { esm, path } = isFileEsm.sync('/path/to/file.js')
if (esm) console.log(`File ${path} is a Module`)
else console.log(`File ${path} is a Script`)
```
### Test
```sh
npm test
```
```
test/index.js ..................................... 213/213
total ............................................. 213/213
213 passing (927.584ms)
ok
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|-------------------|
```
### License
MIT