initial commit
This commit is contained in:
21
node_modules/externality/LICENSE
generated
vendored
Normal file
21
node_modules/externality/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Pooya Parsa <pooya@pi0.io> - Daniel Roe <daniel@roe.dev>
|
||||
|
||||
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.
|
||||
82
node_modules/externality/README.md
generated
vendored
Normal file
82
node_modules/externality/README.md
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
[![npm version][npm-version-src]][npm-version-href]
|
||||
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
||||
[![Github Actions][github-actions-src]][github-actions-href]
|
||||
[![Codecov][codecov-src]][codecov-href]
|
||||
[![bundle][bundle-src]][bundle-href]
|
||||
|
||||
# Externality
|
||||
|
||||
Externality is a set of utilities for handling identifying whether a given package or path should be considered an external package that can be imported at runtime, or whether is should be bundled in a build step.
|
||||
|
||||
It also contains a webpack and rollup plugin for encapsulating this functionality.
|
||||
|
||||
## Install
|
||||
|
||||
Install using npm or yarn:
|
||||
|
||||
```bash
|
||||
npm i externality
|
||||
# or
|
||||
yarn add externality
|
||||
```
|
||||
|
||||
## Rollup plugin
|
||||
|
||||
```js
|
||||
import { rollupExternals } from 'externality'
|
||||
```
|
||||
|
||||
## Webpack plugin
|
||||
|
||||
```js
|
||||
import { webpackExternals } from 'externality'
|
||||
```
|
||||
|
||||
## Utils
|
||||
|
||||
### `resolveId`
|
||||
|
||||
This utility is powered by [`enhanced-resolve`](https://github.com/webpack/enhanced-resolve) and will resolve a given module/path with support for extensions, CJS/ESM and more.
|
||||
|
||||
```js
|
||||
import { resolveId } from 'externality'
|
||||
|
||||
await resolveId('my-lib', { type: 'commonjs' })
|
||||
// {
|
||||
// id: 'my-lib',
|
||||
// path: '/path/to/node_modules/my-lib/index.js',
|
||||
// type: 'commonjs'
|
||||
// }
|
||||
```
|
||||
|
||||
### `isExternal`
|
||||
|
||||
```js
|
||||
import { isExternal } from 'externality'
|
||||
|
||||
await isExternal('my-lib', '.')
|
||||
// {
|
||||
// id: 'my-lib',
|
||||
// external: true
|
||||
// }
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](./LICENSE)
|
||||
|
||||
<!-- Badges -->
|
||||
[npm-version-src]: https://img.shields.io/npm/v/externality?style=flat-square
|
||||
[npm-version-href]: https://npmjs.com/package/externality
|
||||
|
||||
[npm-downloads-src]: https://img.shields.io/npm/dm/externality?style=flat-square
|
||||
[npm-downloads-href]: https://npmjs.com/package/externality
|
||||
|
||||
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/externality/ci/main?style=flat-square
|
||||
[github-actions-href]: https://github.com/unjs/externality/actions?query=workflow%3Aci
|
||||
|
||||
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/externality/main?style=flat-square
|
||||
[codecov-href]: https://codecov.io/gh/unjs/externality
|
||||
|
||||
[bundle-src]: https://img.shields.io/bundlephobia/minzip/externality?style=flat-square
|
||||
[bundle-href]: https://bundlephobia.com/result?p=externality
|
||||
161
node_modules/externality/dist/index.cjs
generated
vendored
Normal file
161
node_modules/externality/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
'use strict';
|
||||
|
||||
const node_url = require('node:url');
|
||||
const node_util = require('node:util');
|
||||
const ufo = require('ufo');
|
||||
const enhancedResolve = require('enhanced-resolve');
|
||||
const mlly = require('mlly');
|
||||
const pathe = require('pathe');
|
||||
|
||||
const ProtocolRegex = /^(?<proto>.{2,}):.+$/;
|
||||
function getProtocol(id) {
|
||||
const proto = id.match(ProtocolRegex);
|
||||
return proto ? proto.groups.proto : null;
|
||||
}
|
||||
function matches(input, matchers, context) {
|
||||
return matchers.some((matcher) => {
|
||||
if (matcher instanceof RegExp) {
|
||||
return matcher.test(input);
|
||||
}
|
||||
if (typeof matcher === "function") {
|
||||
return matcher(input, context);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
function toMatcher(pattern) {
|
||||
if (typeof pattern !== "string") {
|
||||
return pattern;
|
||||
}
|
||||
pattern = pattern.replace(/\//g, "[\\\\/+]");
|
||||
return new RegExp(`([\\/]|^)${pattern}(@[^\\/]*)?([\\/](?!node_modules)|$)`);
|
||||
}
|
||||
function getType(id, fallback = "commonjs") {
|
||||
if (id.endsWith(".cjs")) {
|
||||
return "commonjs";
|
||||
}
|
||||
if (id.endsWith(".mjs")) {
|
||||
return "module";
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const DefaultResolveOptions = {
|
||||
extensions: [".ts", ".mjs", ".cjs", ".js", ".json"],
|
||||
type: "commonjs"
|
||||
};
|
||||
async function resolveId(id, base = ".", options = {}) {
|
||||
options = { ...DefaultResolveOptions, ...options };
|
||||
if (!options.conditionNames) {
|
||||
options.conditionNames = [options.type === "commonjs" ? "require" : "import"];
|
||||
}
|
||||
if (mlly.isNodeBuiltin(id)) {
|
||||
return {
|
||||
id: id.replace(/^node:/, ""),
|
||||
path: id,
|
||||
type: options.type,
|
||||
external: true
|
||||
};
|
||||
}
|
||||
if (id.startsWith("file:/")) {
|
||||
id = node_url.fileURLToPath(id);
|
||||
}
|
||||
if (ufo.hasProtocol(id)) {
|
||||
const url = new URL(id);
|
||||
return {
|
||||
id: url.href,
|
||||
path: url.pathname,
|
||||
type: getType(id, options.type),
|
||||
external: true
|
||||
};
|
||||
}
|
||||
if (base.includes("\0")) {
|
||||
base = options.roots?.[0] || ".";
|
||||
}
|
||||
const _resolve = node_util.promisify(enhancedResolve.create(options));
|
||||
const resolvedModule = await _resolve(base, id);
|
||||
return {
|
||||
id,
|
||||
path: resolvedModule,
|
||||
type: getType(resolvedModule, "unknown")
|
||||
};
|
||||
}
|
||||
|
||||
const ExternalsDefaults = {
|
||||
inline: [
|
||||
/\u0000/,
|
||||
/^!/,
|
||||
/^-!/,
|
||||
/^#/,
|
||||
/\?/
|
||||
],
|
||||
external: [],
|
||||
externalProtocols: ["node", "file", "data"],
|
||||
externalExtensions: [".js", ".mjs", ".cjs", ".node"],
|
||||
resolve: {},
|
||||
detectInvalidNodeImports: true
|
||||
};
|
||||
async function isExternal(id, importer, options = {}) {
|
||||
options = { ...ExternalsDefaults, ...options };
|
||||
const inlineMatchers = options.inline.map((p) => toMatcher(p));
|
||||
const externalMatchers = options.external.map((p) => toMatcher(p));
|
||||
const context = { opts: options, id, resolved: null };
|
||||
if (!id || matches(id, inlineMatchers, context)) {
|
||||
return null;
|
||||
}
|
||||
const proto = getProtocol(id);
|
||||
if (proto && !options.externalProtocols.includes(proto)) {
|
||||
return null;
|
||||
}
|
||||
if (proto === "data") {
|
||||
return { id, external: true };
|
||||
}
|
||||
const r = context.resolved = await resolveId(id, importer, options.resolve).catch(() => {
|
||||
return { id, path: id, external: null };
|
||||
});
|
||||
const idExtension = pathe.extname(r.path);
|
||||
if (idExtension && !options.externalExtensions.includes(idExtension)) {
|
||||
return null;
|
||||
}
|
||||
if (matches(r.id, inlineMatchers, context) || matches(r.path, inlineMatchers, context)) {
|
||||
return null;
|
||||
}
|
||||
if (r.external || matches(id, externalMatchers, context) || matches(r.id, externalMatchers, context) || matches(r.path, externalMatchers, context)) {
|
||||
if (options.detectInvalidNodeImports && !await mlly.isValidNodeImport(r.path)) {
|
||||
return null;
|
||||
}
|
||||
return { id: r.id, external: true };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function rollupExternals(options) {
|
||||
return {
|
||||
name: "node-externals",
|
||||
resolveId(id, importer) {
|
||||
return isExternal(id, importer, options);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function webpackExternals(options) {
|
||||
const _isExternal = async ({ request }, callback) => {
|
||||
try {
|
||||
const res = await isExternal(request, ".", options);
|
||||
callback(void 0, res && res.id);
|
||||
} catch (error) {
|
||||
callback(error, null);
|
||||
}
|
||||
};
|
||||
return _isExternal;
|
||||
}
|
||||
|
||||
exports.ExternalsDefaults = ExternalsDefaults;
|
||||
exports.getProtocol = getProtocol;
|
||||
exports.getType = getType;
|
||||
exports.isExternal = isExternal;
|
||||
exports.matches = matches;
|
||||
exports.resolveId = resolveId;
|
||||
exports.rollupExternals = rollupExternals;
|
||||
exports.toMatcher = toMatcher;
|
||||
exports.webpackExternals = webpackExternals;
|
||||
70
node_modules/externality/dist/index.d.ts
generated
vendored
Normal file
70
node_modules/externality/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
import { ResolveOptions as ResolveOptions$1 } from 'enhanced-resolve';
|
||||
import { Plugin } from 'rollup';
|
||||
|
||||
declare type ModuleType = "commonjs" | "module" | "unknown";
|
||||
interface ResolveOptions extends Partial<ResolveOptions$1> {
|
||||
/**
|
||||
* Whether to resolve esm or cjs by default
|
||||
* @default 'commonjs'
|
||||
*/
|
||||
type?: ModuleType;
|
||||
}
|
||||
interface ResolvedId {
|
||||
id: string;
|
||||
path: string;
|
||||
type?: ModuleType;
|
||||
external?: boolean;
|
||||
}
|
||||
declare function resolveId(id: string, base?: string, options?: ResolveOptions): Promise<ResolvedId>;
|
||||
|
||||
declare type Matcher<T = any> = RegExp | ((input: string, context?: T) => boolean);
|
||||
declare function getProtocol(id: string): string | null;
|
||||
declare function matches<T = any>(input: string, matchers: Matcher<T>[], context?: T): boolean;
|
||||
declare function toMatcher(pattern: string): RegExp;
|
||||
declare function toMatcher<T>(pattern: Matcher<T>): Matcher<T>;
|
||||
declare function getType(id: string, fallback?: ModuleType): ModuleType;
|
||||
|
||||
interface ExternalsOptions {
|
||||
/**
|
||||
* Patterns that always will be excluded from externals
|
||||
*/
|
||||
inline?: Array<string | Matcher>;
|
||||
/**
|
||||
* Patterns that match if an id/module is external
|
||||
*/
|
||||
external?: Array<string | Matcher>;
|
||||
/**
|
||||
* Protocols that are allowed to be externalized.
|
||||
* Any other matched protocol will be inlined.
|
||||
*
|
||||
* Default: ['node', 'file', 'data']
|
||||
*/
|
||||
externalProtocols?: Array<string>;
|
||||
/**
|
||||
* Extensions that are allowed to be externalized.
|
||||
* Any other matched extension will be inlined.
|
||||
*
|
||||
* Default: ['.js', '.mjs', '.cjs', '.node']
|
||||
*/
|
||||
externalExtensions?: Array<string>;
|
||||
/**
|
||||
* Resolve options (passed directly to [`enhanced-resolve`](https://github.com/webpack/enhanced-resolve))
|
||||
*/
|
||||
resolve?: Partial<ResolveOptions>;
|
||||
/**
|
||||
* Try to automatically detect and inline invalid node imports
|
||||
* matching file name (at first) and then loading code.
|
||||
*/
|
||||
detectInvalidNodeImports?: boolean;
|
||||
}
|
||||
declare const ExternalsDefaults: ExternalsOptions;
|
||||
declare function isExternal(id: string, importer: string, options?: ExternalsOptions): Promise<null | {
|
||||
id: string;
|
||||
external: true;
|
||||
}>;
|
||||
|
||||
declare function rollupExternals(options: ExternalsOptions): Plugin;
|
||||
|
||||
declare function webpackExternals(options: ExternalsOptions): any;
|
||||
|
||||
export { ExternalsDefaults, ExternalsOptions, Matcher, ModuleType, ResolveOptions, ResolvedId, getProtocol, getType, isExternal, matches, resolveId, rollupExternals, toMatcher, webpackExternals };
|
||||
151
node_modules/externality/dist/index.mjs
generated
vendored
Normal file
151
node_modules/externality/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { promisify } from 'node:util';
|
||||
import { hasProtocol } from 'ufo';
|
||||
import enhancedResolve from 'enhanced-resolve';
|
||||
import { isNodeBuiltin, isValidNodeImport } from 'mlly';
|
||||
import { extname } from 'pathe';
|
||||
|
||||
const ProtocolRegex = /^(?<proto>.{2,}):.+$/;
|
||||
function getProtocol(id) {
|
||||
const proto = id.match(ProtocolRegex);
|
||||
return proto ? proto.groups.proto : null;
|
||||
}
|
||||
function matches(input, matchers, context) {
|
||||
return matchers.some((matcher) => {
|
||||
if (matcher instanceof RegExp) {
|
||||
return matcher.test(input);
|
||||
}
|
||||
if (typeof matcher === "function") {
|
||||
return matcher(input, context);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
function toMatcher(pattern) {
|
||||
if (typeof pattern !== "string") {
|
||||
return pattern;
|
||||
}
|
||||
pattern = pattern.replace(/\//g, "[\\\\/+]");
|
||||
return new RegExp(`([\\/]|^)${pattern}(@[^\\/]*)?([\\/](?!node_modules)|$)`);
|
||||
}
|
||||
function getType(id, fallback = "commonjs") {
|
||||
if (id.endsWith(".cjs")) {
|
||||
return "commonjs";
|
||||
}
|
||||
if (id.endsWith(".mjs")) {
|
||||
return "module";
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const DefaultResolveOptions = {
|
||||
extensions: [".ts", ".mjs", ".cjs", ".js", ".json"],
|
||||
type: "commonjs"
|
||||
};
|
||||
async function resolveId(id, base = ".", options = {}) {
|
||||
options = { ...DefaultResolveOptions, ...options };
|
||||
if (!options.conditionNames) {
|
||||
options.conditionNames = [options.type === "commonjs" ? "require" : "import"];
|
||||
}
|
||||
if (isNodeBuiltin(id)) {
|
||||
return {
|
||||
id: id.replace(/^node:/, ""),
|
||||
path: id,
|
||||
type: options.type,
|
||||
external: true
|
||||
};
|
||||
}
|
||||
if (id.startsWith("file:/")) {
|
||||
id = fileURLToPath(id);
|
||||
}
|
||||
if (hasProtocol(id)) {
|
||||
const url = new URL(id);
|
||||
return {
|
||||
id: url.href,
|
||||
path: url.pathname,
|
||||
type: getType(id, options.type),
|
||||
external: true
|
||||
};
|
||||
}
|
||||
if (base.includes("\0")) {
|
||||
base = options.roots?.[0] || ".";
|
||||
}
|
||||
const _resolve = promisify(enhancedResolve.create(options));
|
||||
const resolvedModule = await _resolve(base, id);
|
||||
return {
|
||||
id,
|
||||
path: resolvedModule,
|
||||
type: getType(resolvedModule, "unknown")
|
||||
};
|
||||
}
|
||||
|
||||
const ExternalsDefaults = {
|
||||
inline: [
|
||||
/\u0000/,
|
||||
/^!/,
|
||||
/^-!/,
|
||||
/^#/,
|
||||
/\?/
|
||||
],
|
||||
external: [],
|
||||
externalProtocols: ["node", "file", "data"],
|
||||
externalExtensions: [".js", ".mjs", ".cjs", ".node"],
|
||||
resolve: {},
|
||||
detectInvalidNodeImports: true
|
||||
};
|
||||
async function isExternal(id, importer, options = {}) {
|
||||
options = { ...ExternalsDefaults, ...options };
|
||||
const inlineMatchers = options.inline.map((p) => toMatcher(p));
|
||||
const externalMatchers = options.external.map((p) => toMatcher(p));
|
||||
const context = { opts: options, id, resolved: null };
|
||||
if (!id || matches(id, inlineMatchers, context)) {
|
||||
return null;
|
||||
}
|
||||
const proto = getProtocol(id);
|
||||
if (proto && !options.externalProtocols.includes(proto)) {
|
||||
return null;
|
||||
}
|
||||
if (proto === "data") {
|
||||
return { id, external: true };
|
||||
}
|
||||
const r = context.resolved = await resolveId(id, importer, options.resolve).catch(() => {
|
||||
return { id, path: id, external: null };
|
||||
});
|
||||
const idExtension = extname(r.path);
|
||||
if (idExtension && !options.externalExtensions.includes(idExtension)) {
|
||||
return null;
|
||||
}
|
||||
if (matches(r.id, inlineMatchers, context) || matches(r.path, inlineMatchers, context)) {
|
||||
return null;
|
||||
}
|
||||
if (r.external || matches(id, externalMatchers, context) || matches(r.id, externalMatchers, context) || matches(r.path, externalMatchers, context)) {
|
||||
if (options.detectInvalidNodeImports && !await isValidNodeImport(r.path)) {
|
||||
return null;
|
||||
}
|
||||
return { id: r.id, external: true };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function rollupExternals(options) {
|
||||
return {
|
||||
name: "node-externals",
|
||||
resolveId(id, importer) {
|
||||
return isExternal(id, importer, options);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function webpackExternals(options) {
|
||||
const _isExternal = async ({ request }, callback) => {
|
||||
try {
|
||||
const res = await isExternal(request, ".", options);
|
||||
callback(void 0, res && res.id);
|
||||
} catch (error) {
|
||||
callback(error, null);
|
||||
}
|
||||
};
|
||||
return _isExternal;
|
||||
}
|
||||
|
||||
export { ExternalsDefaults, getProtocol, getType, isExternal, matches, resolveId, rollupExternals, toMatcher, webpackExternals };
|
||||
55
node_modules/externality/package.json
generated
vendored
Normal file
55
node_modules/externality/package.json
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"name": "externality",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./dist/index.cjs",
|
||||
"import": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"./*": "./*"
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "vitest",
|
||||
"lint": "eslint --ext .ts .",
|
||||
"prepack": "pnpm build",
|
||||
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
|
||||
"test": "pnpm lint && vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"enhanced-resolve": "^5.10.0",
|
||||
"mlly": "^1.0.0",
|
||||
"pathe": "^1.0.0",
|
||||
"ufo": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.9",
|
||||
"@vitest/coverage-c8": "^0.25.2",
|
||||
"allowlist": "^0.1.1",
|
||||
"c8": "^7.12.0",
|
||||
"eslint": "^8.27.0",
|
||||
"eslint-config-unjs": "^0.0.2",
|
||||
"rollup": "^3.3.0",
|
||||
"standard-version": "^9.3.2",
|
||||
"typescript": "^4.8.4",
|
||||
"unbuild": "^0.9.4",
|
||||
"vite": "^3.2.3",
|
||||
"vitest": "^0.25.2",
|
||||
"webpack": "^5.75.0"
|
||||
},
|
||||
"build": {
|
||||
"externals": [
|
||||
"rollup"
|
||||
]
|
||||
},
|
||||
"packageManager": "pnpm@7.16.0"
|
||||
}
|
||||
Reference in New Issue
Block a user