This commit is contained in:
2023-08-11 10:45:20 +08:00
commit 161ca982f3
31850 changed files with 2706500 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

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

@ -0,0 +1,72 @@
{
"_from": "is-file-esm@^1.0.0",
"_id": "is-file-esm@1.0.0",
"_inBundle": false,
"_integrity": "sha512-rZlaNKb4Mr8WlRu2A9XdeoKgnO5aA53XdPHgCKVyCrQ/rWi89RET1+bq37Ru46obaQXeiX4vmFIm1vks41hoSA==",
"_location": "/is-file-esm",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "is-file-esm@^1.0.0",
"name": "is-file-esm",
"escapedName": "is-file-esm",
"rawSpec": "^1.0.0",
"saveSpec": null,
"fetchSpec": "^1.0.0"
},
"_requiredBy": [
"/@vue/cli-service"
],
"_resolved": "https://registry.npmjs.org/is-file-esm/-/is-file-esm-1.0.0.tgz",
"_shasum": "987086b0f5a5318179e9d30f4f2f8d37321e1b5f",
"_spec": "is-file-esm@^1.0.0",
"_where": "C:\\Users\\zhouxueli\\Desktop\\scheduling-app\\node_modules\\@vue\\cli-service",
"author": {
"name": "David Mark Clements",
"url": "@davidmarkclem"
},
"bugs": {
"url": "https://github.com/davidmarkclements/is-file-esm/issues"
},
"bundleDependencies": false,
"dependencies": {
"read-pkg-up": "^7.0.1"
},
"deprecated": false,
"description": "Determines whether a Node file is a Module (`import`) or a Script (`require`)",
"devDependencies": {
"nonsynchronous": "^1.2.0",
"standard": "^14.3.4",
"tap": "^14.10.8"
},
"directories": {
"test": "test"
},
"engine": {
"node": ">= 12.4.0"
},
"engineStrict": true,
"homepage": "https://github.com/davidmarkclements/is-file-esm#readme",
"keywords": [
"esm",
"cjs",
"package.json",
"module",
"ecmascript modules",
"native modules",
"native ecmascript modules"
],
"license": "MIT",
"main": "index.js",
"name": "is-file-esm",
"repository": {
"type": "git",
"url": "git+https://github.com/davidmarkclements/is-file-esm.git"
},
"scripts": {
"ci": "npm test",
"test": "tap -R classic --100"
},
"version": "1.0.0"
}

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

View File

View File

@ -0,0 +1,13 @@
{
"name": "type-module-cjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "bad",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

View File

@ -0,0 +1,13 @@
{
"name": "type-module-js",
"version": "1.0.0",
"description": "",
"main": "file.js",
"type": "bad",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

View File

@ -0,0 +1,13 @@
{
"name": "type-module-mjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "bad",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

View File

@ -0,0 +1,12 @@
{
"name": "type-commonjs-cjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "commonjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

View File

View File

@ -0,0 +1,13 @@
{
"name": "type-commonjs-js",
"version": "1.0.0",
"description": "",
"main": "file.js",
"type": "commonjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

View File

@ -0,0 +1,13 @@
{
"name": "type-commonjs-mjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "commonjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

View File

@ -0,0 +1,13 @@
{
"name": "type-module-cjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

View File

@ -0,0 +1,13 @@
{
"name": "type-module-js",
"version": "1.0.0",
"description": "",
"main": "file.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

View File

@ -0,0 +1,13 @@
{
"name": "type-module-mjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

View File

@ -0,0 +1,12 @@
{
"name": "type-undefined-cjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

View File

@ -0,0 +1,12 @@
{
"name": "type-undefined-js",
"version": "1.0.0",
"description": "",
"main": "file.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

View File

@ -0,0 +1,12 @@
{
"name": "type-undefined-mjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

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

@ -0,0 +1,649 @@
'use strict'
const { join } = require('path')
const { test } = require('tap')
const { when } = require('nonsynchronous')
const { chmodSync } = require('fs')
const isFileEsm = require('..')
const {
ERR_PATH_MUST_BE_STRING,
ERR_PATH_MUST_BE_ABSOLUTE,
ERR_PATH_MUST_EXIST,
ERR_PATH_MUST_HAVE_VALID_EXT
} = isFileEsm.constants
const ERR_BAD_TYPE = 'package.json type "bad" not recognized'
const ERR_PERMISSION_DENIED = /EACCES: permission denied/
const fixtures = join(__dirname, 'fixtures')
test('path must be string (promise)', async ({ rejects }) => {
await rejects(() => isFileEsm(), Error(ERR_PATH_MUST_BE_STRING))
await rejects(() => isFileEsm({}), Error(ERR_PATH_MUST_BE_STRING))
})
test('path must be absolute (promise)', async ({ rejects }) => {
await rejects(() => isFileEsm('../foo.js'), Error(ERR_PATH_MUST_BE_ABSOLUTE))
await rejects(() => isFileEsm('./bar/foo.mjs'), Error(ERR_PATH_MUST_BE_ABSOLUTE))
})
test('path must have ext (promise)', async ({ rejects }) => {
await rejects(() => isFileEsm('/bar/foo'), Error(ERR_PATH_MUST_HAVE_VALID_EXT))
})
test('path must have valid ext (promise)', async ({ rejects }) => {
await rejects(() => isFileEsm('/bar/foo.ext'), Error(ERR_PATH_MUST_HAVE_VALID_EXT))
})
test('path must exist (promise)', async ({ rejects }) => {
await rejects(() => isFileEsm(join(fixtures, 'bar', 'foo.js')), Error(ERR_PATH_MUST_EXIST))
})
test('type-commonjs-cjs promise', async ({ is }) => {
const inputPath = join(fixtures, 'type-commonjs-cjs', 'file.cjs')
const expectedPkgPath = join(fixtures, 'type-commonjs-cjs', 'package.json')
const { esm, path, type, extType, pkgPath } = await isFileEsm(inputPath)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'commonjs')
is(extType, 'c')
})
test('type-commonjs-js promise', async ({ is }) => {
const inputPath = join(fixtures, 'type-commonjs-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-commonjs-js', 'package.json')
const { esm, path, type, extType, pkgPath } = await isFileEsm(inputPath)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'commonjs')
is(extType, 'j')
})
test('type-commonjs-mjs promise', async ({ is }) => {
const inputPath = join(fixtures, 'type-commonjs-mjs', 'file.mjs')
const expectedPkgPath = join(fixtures, 'type-commonjs-mjs', 'package.json')
const { esm, path, type, extType, pkgPath } = await isFileEsm(inputPath)
is(esm, true)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'commonjs')
is(extType, 'm')
})
test('type-module-cjs promise', async ({ is }) => {
const inputPath = join(fixtures, 'type-module-cjs', 'file.cjs')
const expectedPkgPath = join(fixtures, 'type-module-cjs', 'package.json')
const { esm, path, type, extType, pkgPath } = await isFileEsm(inputPath)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'module')
is(extType, 'c')
})
test('type-module-js promise', async ({ is }) => {
const inputPath = join(fixtures, 'type-module-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-module-js', 'package.json')
const { esm, path, type, extType, pkgPath } = await isFileEsm(inputPath)
is(esm, true)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'module')
is(extType, 'j')
})
test('type-module-mjs promise', async ({ is }) => {
const inputPath = join(fixtures, 'type-module-mjs', 'file.mjs')
const expectedPkgPath = join(fixtures, 'type-module-mjs', 'package.json')
const { esm, path, type, extType, pkgPath } = await isFileEsm(inputPath)
is(esm, true)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'module')
is(extType, 'm')
})
test('type-undefined-cjs promise', async ({ is }) => {
const inputPath = join(fixtures, 'type-undefined-cjs', 'file.cjs')
const expectedPkgPath = join(fixtures, 'type-undefined-cjs', 'package.json')
const { esm, path, type, extType, pkgPath } = await isFileEsm(inputPath)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, undefined)
is(extType, 'c')
})
test('type-undefined-js promise', async ({ is }) => {
const inputPath = join(fixtures, 'type-undefined-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-undefined-js', 'package.json')
const { esm, path, type, extType, pkgPath } = await isFileEsm(inputPath)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, undefined)
is(extType, 'j')
})
test('type-undefined-mjs promise', async ({ is }) => {
const inputPath = join(fixtures, 'type-undefined-mjs', 'file.mjs')
const expectedPkgPath = join(fixtures, 'type-undefined-mjs', 'package.json')
const { esm, path, type, extType, pkgPath } = await isFileEsm(inputPath)
is(esm, true)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, undefined)
is(extType, 'm')
})
test('type-bad-cjs promise', async ({ is, rejects }) => {
const inputPath = join(fixtures, 'type-bad-cjs', 'file.cjs')
const expectedPkgPath = join(fixtures, 'type-bad-cjs', 'package.json')
let error = null
await rejects(async () => {
try {
await isFileEsm(inputPath)
} catch (err) {
error = err
throw err
}
}, ERR_BAD_TYPE)
const { path, type, extType, pkgPath } = error.meta
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'bad')
is(extType, 'c')
})
test('type-bad-js promise', async ({ is, rejects }) => {
const inputPath = join(fixtures, 'type-bad-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-bad-js', 'package.json')
let error = null
await rejects(async () => {
try {
await isFileEsm(inputPath)
} catch (err) {
error = err
throw err
}
}, ERR_BAD_TYPE)
const { path, type, extType, pkgPath } = error.meta
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'bad')
is(extType, 'j')
})
test('type-bad-mjs promise', async ({ is, rejects }) => {
const inputPath = join(fixtures, 'type-bad-mjs', 'file.mjs')
const expectedPkgPath = join(fixtures, 'type-bad-mjs', 'package.json')
let error = null
await rejects(async () => {
try {
await isFileEsm(inputPath)
} catch (err) {
error = err
throw err
}
}, ERR_BAD_TYPE)
const { path, type, extType, pkgPath } = error.meta
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'bad')
is(extType, 'm')
})
test('package.json read error propagation (promise)', async ({ rejects, tearDown }) => {
const inputPath = join(fixtures, 'type-bad-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-bad-js', 'package.json')
tearDown(() => chmodSync(expectedPkgPath, 0o644))
chmodSync(expectedPkgPath, 0o000)
await rejects(() => isFileEsm(inputPath), ERR_PERMISSION_DENIED)
})
test('type-commonjs-cjs sync', async ({ is }) => {
const inputPath = join(fixtures, 'type-commonjs-cjs', 'file.cjs')
const expectedPkgPath = join(fixtures, 'type-commonjs-cjs', 'package.json')
const { esm, path, type, extType, pkgPath } = isFileEsm.sync(inputPath)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'commonjs')
is(extType, 'c')
})
test('type-commonjs-js sync', async ({ is }) => {
const inputPath = join(fixtures, 'type-commonjs-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-commonjs-js', 'package.json')
const { esm, path, type, extType, pkgPath } = isFileEsm.sync(inputPath)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'commonjs')
is(extType, 'j')
})
test('type-commonjs-mjs sync', async ({ is }) => {
const inputPath = join(fixtures, 'type-commonjs-mjs', 'file.mjs')
const expectedPkgPath = join(fixtures, 'type-commonjs-mjs', 'package.json')
const { esm, path, type, extType, pkgPath } = isFileEsm.sync(inputPath)
is(esm, true)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'commonjs')
is(extType, 'm')
})
test('type-module-cjs sync', async ({ is }) => {
const inputPath = join(fixtures, 'type-module-cjs', 'file.cjs')
const expectedPkgPath = join(fixtures, 'type-module-cjs', 'package.json')
const { esm, path, type, extType, pkgPath } = isFileEsm.sync(inputPath)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'module')
is(extType, 'c')
})
test('type-module-js sync', async ({ is }) => {
const inputPath = join(fixtures, 'type-module-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-module-js', 'package.json')
const { esm, path, type, extType, pkgPath } = isFileEsm.sync(inputPath)
is(esm, true)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'module')
is(extType, 'j')
})
test('type-module-mjs sync', async ({ is }) => {
const inputPath = join(fixtures, 'type-module-mjs', 'file.mjs')
const expectedPkgPath = join(fixtures, 'type-module-mjs', 'package.json')
const { esm, path, type, extType, pkgPath } = isFileEsm.sync(inputPath)
is(esm, true)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'module')
is(extType, 'm')
})
test('type-undefined-cjs sync', async ({ is }) => {
const inputPath = join(fixtures, 'type-undefined-cjs', 'file.cjs')
const expectedPkgPath = join(fixtures, 'type-undefined-cjs', 'package.json')
const { esm, path, type, extType, pkgPath } = isFileEsm.sync(inputPath)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, undefined)
is(extType, 'c')
})
test('type-undefined-js sync', async ({ is }) => {
const inputPath = join(fixtures, 'type-undefined-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-undefined-js', 'package.json')
const { esm, path, type, extType, pkgPath } = isFileEsm.sync(inputPath)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, undefined)
is(extType, 'j')
})
test('type-undefined-mjs sync', async ({ is }) => {
const inputPath = join(fixtures, 'type-undefined-mjs', 'file.mjs')
const expectedPkgPath = join(fixtures, 'type-undefined-mjs', 'package.json')
const { esm, path, type, extType, pkgPath } = isFileEsm.sync(inputPath)
is(esm, true)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, undefined)
is(extType, 'm')
})
test('path must be string (sync)', async ({ throws }) => {
throws(() => isFileEsm.sync(), Error(ERR_PATH_MUST_BE_STRING))
throws(() => isFileEsm.sync({}), Error(ERR_PATH_MUST_BE_STRING))
})
test('path must be absolute (sync)', async ({ throws }) => {
throws(() => isFileEsm.sync('../foo.js'), Error(ERR_PATH_MUST_BE_ABSOLUTE))
throws(() => isFileEsm.sync('./bar/foo.mjs'), Error(ERR_PATH_MUST_BE_ABSOLUTE))
})
test('path must have ext (sync)', async ({ throws }) => {
throws(() => isFileEsm.sync('/bar/foo'), Error(ERR_PATH_MUST_HAVE_VALID_EXT))
})
test('path must have valid ext (sync)', async ({ throws }) => {
throws(() => isFileEsm.sync('/bar/foo.ext'), Error(ERR_PATH_MUST_HAVE_VALID_EXT))
})
test('path must exist (promise)', async ({ throws }) => {
throws(() => isFileEsm.sync(join(fixtures, 'bar', 'foo.js')), Error(ERR_PATH_MUST_EXIST))
})
test('type-bad-cjs sync', async ({ is, throws }) => {
const inputPath = join(fixtures, 'type-bad-cjs', 'file.cjs')
const expectedPkgPath = join(fixtures, 'type-bad-cjs', 'package.json')
let error = null
throws(() => {
try {
isFileEsm.sync(inputPath)
} catch (err) {
error = err
throw err
}
}, ERR_BAD_TYPE)
const { path, type, extType, pkgPath } = error.meta
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'bad')
is(extType, 'c')
})
test('type-bad-js sync', async ({ is, throws }) => {
const inputPath = join(fixtures, 'type-bad-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-bad-js', 'package.json')
let error = null
throws(() => {
try {
isFileEsm.sync(inputPath)
} catch (err) {
error = err
throw err
}
}, ERR_BAD_TYPE)
const { path, type, extType, pkgPath } = error.meta
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'bad')
is(extType, 'j')
})
test('type-bad-mjs sync', async ({ is, throws }) => {
const inputPath = join(fixtures, 'type-bad-mjs', 'file.mjs')
const expectedPkgPath = join(fixtures, 'type-bad-mjs', 'package.json')
let error = null
throws(() => {
try {
isFileEsm.sync(inputPath)
} catch (err) {
error = err
throw err
}
}, ERR_BAD_TYPE)
const { path, type, extType, pkgPath } = error.meta
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'bad')
is(extType, 'm')
})
test('package.json read error propagation (sync)', async ({ throws, tearDown }) => {
const inputPath = join(fixtures, 'type-bad-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-bad-js', 'package.json')
tearDown(() => chmodSync(expectedPkgPath, 0o644))
chmodSync(expectedPkgPath, 0o000)
throws(() => isFileEsm.sync(inputPath), ERR_PERMISSION_DENIED)
})
test('type-commonjs-cjs callback', async ({ is, error }) => {
const inputPath = join(fixtures, 'type-commonjs-cjs', 'file.cjs')
const expectedPkgPath = join(fixtures, 'type-commonjs-cjs', 'package.json')
const until = when()
isFileEsm(inputPath, (err, { esm, path, type, extType, pkgPath }) => {
error(err)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'commonjs')
is(extType, 'c')
until()
})
await until.done()
})
test('type-commonjs-js callback', async ({ is, error }) => {
const inputPath = join(fixtures, 'type-commonjs-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-commonjs-js', 'package.json')
const until = when()
isFileEsm(inputPath, (err, { esm, path, type, extType, pkgPath }) => {
error(err)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'commonjs')
is(extType, 'j')
until()
})
await until.done()
})
test('type-commonjs-mjs callback', async ({ is, error }) => {
const inputPath = join(fixtures, 'type-commonjs-mjs', 'file.mjs')
const expectedPkgPath = join(fixtures, 'type-commonjs-mjs', 'package.json')
const until = when()
isFileEsm(inputPath, (err, { esm, path, type, extType, pkgPath }) => {
error(err)
is(esm, true)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'commonjs')
is(extType, 'm')
until()
})
await until.done()
})
test('type-module-cjs callback', async ({ is, error }) => {
const inputPath = join(fixtures, 'type-module-cjs', 'file.cjs')
const expectedPkgPath = join(fixtures, 'type-module-cjs', 'package.json')
const until = when()
isFileEsm(inputPath, (err, { esm, path, type, extType, pkgPath }) => {
error(err)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'module')
is(extType, 'c')
until()
})
await until.done()
})
test('type-module-js callback', async ({ is, error }) => {
const inputPath = join(fixtures, 'type-module-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-module-js', 'package.json')
const until = when()
isFileEsm(inputPath, (err, { esm, path, type, extType, pkgPath }) => {
error(err)
is(esm, true)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'module')
is(extType, 'j')
until()
})
await until.done()
})
test('type-module-mjs callback', async ({ is, error }) => {
const inputPath = join(fixtures, 'type-module-mjs', 'file.mjs')
const expectedPkgPath = join(fixtures, 'type-module-mjs', 'package.json')
const until = when()
isFileEsm(inputPath, (err, { esm, path, type, extType, pkgPath }) => {
error(err)
is(esm, true)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'module')
is(extType, 'm')
until()
})
await until.done()
})
test('type-undefined-cjs callback', async ({ is, error }) => {
const inputPath = join(fixtures, 'type-undefined-cjs', 'file.cjs')
const expectedPkgPath = join(fixtures, 'type-undefined-cjs', 'package.json')
const until = when()
isFileEsm(inputPath, (err, { esm, path, type, extType, pkgPath }) => {
error(err)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, undefined)
is(extType, 'c')
until()
})
await until.done()
})
test('type-undefined-js callback', async ({ is, error }) => {
const inputPath = join(fixtures, 'type-undefined-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-undefined-js', 'package.json')
const until = when()
isFileEsm(inputPath, (err, { esm, path, type, extType, pkgPath }) => {
error(err)
is(esm, false)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, undefined)
is(extType, 'j')
until()
})
await until.done()
})
test('type-undefined-mjs callback', async ({ is, error }) => {
const inputPath = join(fixtures, 'type-undefined-mjs', 'file.mjs')
const expectedPkgPath = join(fixtures, 'type-undefined-mjs', 'package.json')
const until = when()
isFileEsm(inputPath, (err, { esm, path, type, extType, pkgPath }) => {
error(err)
is(esm, true)
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, undefined)
is(extType, 'm')
until()
})
await until.done()
})
test('path must be string (callback)', async ({ match }) => {
const until1 = when()
isFileEsm(undefined, (err) => {
match(err, Error(ERR_PATH_MUST_BE_STRING))
until1()
})
const until2 = when()
isFileEsm({}, (err) => {
match(err, Error(ERR_PATH_MUST_BE_STRING))
until2()
})
await Promise.all([until1.done(), until2.done()])
})
test('path must be absolute (callback)', async ({ match }) => {
const until1 = when()
isFileEsm('../foo.js', (err) => {
match(err, Error(ERR_PATH_MUST_BE_ABSOLUTE))
until1()
})
const until2 = when()
isFileEsm('./bar/foo.mjs', (err) => {
match(err, Error(ERR_PATH_MUST_BE_ABSOLUTE))
until2()
})
await Promise.all([until1.done(), until2.done()])
})
test('path must have ext (callback)', async ({ match }) => {
const until = when()
isFileEsm('/bar/foo', (err) => {
match(err, Error(ERR_PATH_MUST_HAVE_VALID_EXT))
until()
})
await until.done()
})
test('path must have valid ext (callback)', async ({ match }) => {
const until = when()
isFileEsm('/bar/foo.ext', (err) => {
match(err, Error(ERR_PATH_MUST_HAVE_VALID_EXT))
until()
})
await until.done()
})
test('path must exist (callback)', async ({ match }) => {
const until = when()
isFileEsm(join(fixtures, 'bar', 'foo.js'), (err) => {
match(err, Error(ERR_PATH_MUST_EXIST))
until()
})
await until.done()
})
test('type-bad-cjs callback', async ({ is }) => {
const inputPath = join(fixtures, 'type-bad-cjs', 'file.cjs')
const expectedPkgPath = join(fixtures, 'type-bad-cjs', 'package.json')
const until = when()
isFileEsm(inputPath, (err) => {
is(err.message, ERR_BAD_TYPE)
const { path, type, extType, pkgPath } = err.meta
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'bad')
is(extType, 'c')
until()
})
await until.done()
})
test('type-bad-js callback', async ({ is }) => {
const inputPath = join(fixtures, 'type-bad-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-bad-js', 'package.json')
const until = when()
isFileEsm(inputPath, (err) => {
is(err.message, ERR_BAD_TYPE)
const { path, type, extType, pkgPath } = err.meta
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'bad')
is(extType, 'j')
until()
})
await until.done()
})
test('type-bad-mjs callback', async ({ is }) => {
const inputPath = join(fixtures, 'type-bad-mjs', 'file.mjs')
const expectedPkgPath = join(fixtures, 'type-bad-mjs', 'package.json')
const until = when()
isFileEsm(inputPath, (err) => {
is(err.message, ERR_BAD_TYPE)
const { path, type, extType, pkgPath } = err.meta
is(path, inputPath)
is(expectedPkgPath, pkgPath)
is(type, 'bad')
is(extType, 'm')
until()
})
await until.done()
})
test('package.json read error propagation (callback)', async ({ match, tearDown }) => {
const inputPath = join(fixtures, 'type-bad-js', 'file.js')
const expectedPkgPath = join(fixtures, 'type-bad-js', 'package.json')
tearDown(() => chmodSync(expectedPkgPath, 0o644))
chmodSync(expectedPkgPath, 0o000)
const until = when()
isFileEsm(inputPath, (err) => {
match(err, ERR_PERMISSION_DENIED)
until()
})
await until.done()
})