feat: init
This commit is contained in:
21
node_modules/unctx/LICENSE
generated
vendored
Normal file
21
node_modules/unctx/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 - Pooya Parsa <pooya@pi0.io>
|
||||
|
||||
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.
|
||||
225
node_modules/unctx/README.md
generated
vendored
Normal file
225
node_modules/unctx/README.md
generated
vendored
Normal file
@@ -0,0 +1,225 @@
|
||||
# 🍦 unctx
|
||||
|
||||
> Composition-API in Vanilla js
|
||||
|
||||
[![npm version][npm-v-src]][npm-v-href]
|
||||
[![npm downloads][npm-dm-src]][npm-dm-href]
|
||||
[![package phobia][packagephobia-src]][packagephobia-href]
|
||||
[![bundle phobia][bundlephobia-src]][bundlephobia-href]
|
||||
[![codecov][codecov-src]][codecov-href]
|
||||
|
||||
## What is unctx?
|
||||
|
||||
[Vue.js](https://vuejs.org) introduced an amazing pattern called [Composition API](https://v3.vuejs.org/guide/composition-api-introduction.html) that allows organizing complex logic by splitting it into reusable functions and grouping in logical order. `unctx` allows easily implementing composition API pattern in your javascript libraries without hassle.
|
||||
|
||||
## Usage
|
||||
|
||||
In your **awesome** library:
|
||||
|
||||
```bash
|
||||
yarn add unctx
|
||||
# or
|
||||
npm install unctx
|
||||
```
|
||||
|
||||
```js
|
||||
import { createContext } from "unctx";
|
||||
|
||||
const ctx = createContext();
|
||||
|
||||
export const useAwesome = ctx.use;
|
||||
|
||||
// ...
|
||||
ctx.call({ test: 1 }, () => {
|
||||
// This is similar to the vue setup function
|
||||
// Any function called here can use `useAwesome` to get { test: 1 }
|
||||
});
|
||||
```
|
||||
|
||||
User code:
|
||||
|
||||
```js
|
||||
import { useAwesome } from "awesome-lib";
|
||||
|
||||
// ...
|
||||
function setup() {
|
||||
const ctx = useAwesome();
|
||||
}
|
||||
```
|
||||
|
||||
**Note:** When no context is presented `ctx.use` will throw an error. Use `ctx.tryUse` for tolerant usages (return nullable context).
|
||||
|
||||
### Using Namespaces
|
||||
|
||||
To avoid issues with multiple version of the library, `unctx` provides a safe global namespace to access context by key (kept in [`globalThis`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis)). **Important:** Please use a verbose name for the key to avoid conflict with other js libraries. Using the npm package name is recommended. Using symbols has no effect since it still causes multiple context issues.
|
||||
|
||||
```js
|
||||
import { useContext, getContext } from "unctx";
|
||||
|
||||
const useAwesome = useContext("awesome-lib");
|
||||
|
||||
// or
|
||||
// const awesomeContext = getContext('awesome-lib')
|
||||
```
|
||||
|
||||
You can also create your internal namespace with `createNamespace` utility for more advanced use cases.
|
||||
|
||||
## Async Context
|
||||
|
||||
Using context is only possible in non-async usages and only before the first await statement. This is to make sure context is not shared between concurrent calls.
|
||||
|
||||
```js
|
||||
async function setup() {
|
||||
console.log(useAwesome()); // Returns context
|
||||
setTimeout(() => {
|
||||
console.log(useAwesome());
|
||||
}, 1); // Returns null
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
console.log(useAwesome()); // Returns null
|
||||
}
|
||||
```
|
||||
|
||||
A simple workaround is caching context into a local variable:
|
||||
|
||||
```js
|
||||
async function setup() {
|
||||
const ctx = useAwesome(); // We can directly access cached version of ctx
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
console.log(ctx);
|
||||
}
|
||||
```
|
||||
|
||||
This is not always an elegant and easy way by making a variable and passing it around. After all, this is the purpose of unctx to make sure context is magically available everywhere in composables!
|
||||
|
||||
### Native Async Context
|
||||
|
||||
Unctx supports Node.js [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage) as a native way to preserve and track async contexts. To enable this mode, you need to set `asyncContext: true` option and also provides an implementation for `AsyncLocalStorage` (or provide `globalThis.AsyncLocalStorage` polyfill).
|
||||
|
||||
See [tc39 proposal for async context](https://github.com/tc39/proposal-async-context) and [cloudflare docs](https://developers.cloudflare.com/workers/runtime-apis/nodejs/asynclocalstorage/) for relevant platform specific docs.
|
||||
|
||||
```ts
|
||||
import { createContext } from "unctx";
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
|
||||
const ctx = createContext({
|
||||
asyncContext: true,
|
||||
AsyncLocalStorage,
|
||||
});
|
||||
|
||||
ctx.call("123", () => {
|
||||
setTimeout(() => {
|
||||
// Prints 123
|
||||
console.log(ctx.use());
|
||||
}, 100);
|
||||
});
|
||||
```
|
||||
|
||||
### Async Transform
|
||||
|
||||
Since native async context is not supported in all platforms yet, unctx provides a build-time solution that transforms async syntax to automatically restore context after each async/await statement. This requires using a bundler such as Rollup, Vite, or Webpack.
|
||||
|
||||
Import and register transform plugin:
|
||||
|
||||
```js
|
||||
import { unctxPlugin } from "unctx/plugin";
|
||||
|
||||
// Rollup
|
||||
// TODO: Add to rollup configuration
|
||||
unctxPlugin.rollup();
|
||||
|
||||
// Vite
|
||||
// TODO: Add to vite configuration
|
||||
unctxPlugin.vite();
|
||||
|
||||
// Webpack
|
||||
// TODO: Add to webpack configuration
|
||||
unctxPlugin.webpack();
|
||||
```
|
||||
|
||||
Use `ctx.callAsync` instead of `ctx.call`:
|
||||
|
||||
```js
|
||||
await ctx.callAsync("test", setup);
|
||||
```
|
||||
|
||||
**_NOTE:_** `callAsync` is not transformed by default. You need to add it to the plugin's `asyncFunctions: []` option to transform it.
|
||||
|
||||
Any async function that requires context, should be wrapped with `withAsyncContext`:
|
||||
|
||||
```js
|
||||
import { withAsyncContext } from "unctx";
|
||||
|
||||
const setup = withAsyncContext(async () => {
|
||||
console.log(useAwesome()); // Returns context
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
console.log(useAwesome()); // Still returns context with dark magic!
|
||||
});
|
||||
```
|
||||
|
||||
## Singleton Pattern
|
||||
|
||||
If you are sure it is safe to use a shared instance (not depending to request), you can also use `ctx.set` and `ctx.unset` for a [singleton pattern](https://en.wikipedia.org/wiki/Singleton_pattern).
|
||||
|
||||
**Note:** You cannot combine `set` with `call`. Always use `unset` before replacing the instance otherwise you will get `Context conflict` error.
|
||||
|
||||
```js
|
||||
import { createContext } from "unctx";
|
||||
|
||||
const ctx = createContext();
|
||||
ctx.set(new Awesome());
|
||||
|
||||
// Replacing instance without unset
|
||||
// ctx.set(new Awesome(), true)
|
||||
|
||||
export const useAwesome = ctx.use;
|
||||
```
|
||||
|
||||
## Typed Context
|
||||
|
||||
A generic type exists on all utilities to be set for instance/context type for typescript support.
|
||||
|
||||
```ts
|
||||
// Return type of useAwesome is Awesome | null
|
||||
const { use: useAwesome } = createContext<Awesome>();
|
||||
```
|
||||
|
||||
## Under the hood
|
||||
|
||||
The composition of functions is possible using temporary context injection. When calling `ctx.call(instance, cb)`, `instance` argument will be stored in a temporary variable then `cb` is called. Any function inside `cb`, can then implicitly access the instance by using `ctx.use` (or `useAwesome`)
|
||||
|
||||
## Pitfalls
|
||||
|
||||
**context can be only used before first await**:
|
||||
|
||||
Please check [Async Context](#async-context) section.
|
||||
|
||||
**`Context conflict` error**:
|
||||
|
||||
In your library, you should only keep one `call()` running at a time (unless calling with the same reference for the first argument)
|
||||
|
||||
For instance, this makes an error:
|
||||
|
||||
```js
|
||||
ctx.call({ test: 1 }, () => {
|
||||
ctx.call({ test: 2 }, () => {
|
||||
// Throws error!
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT. Made with 💖
|
||||
|
||||
<!-- Refs -->
|
||||
|
||||
[npm-v-src]: https://flat.badgen.net/npm/v/unctx/latest
|
||||
[npm-v-href]: https://npmjs.com/package/unctx
|
||||
[npm-dm-src]: https://flat.badgen.net/npm/dm/unctx
|
||||
[npm-dm-href]: https://npmjs.com/package/unctx
|
||||
[packagephobia-src]: https://flat.badgen.net/packagephobia/install/unctx
|
||||
[packagephobia-href]: https://packagephobia.now.sh/result?p=unctx
|
||||
[bundlephobia-src]: https://flat.badgen.net/bundlephobia/min/unctx
|
||||
[bundlephobia-href]: https://bundlephobia.com/result?p=unctx
|
||||
[codecov-src]: https://flat.badgen.net/codecov/c/github/unjs/unctx/master
|
||||
[codecov-href]: https://codecov.io/gh/unjs/unctx
|
||||
139
node_modules/unctx/dist/index.cjs
generated
vendored
Normal file
139
node_modules/unctx/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
'use strict';
|
||||
|
||||
function createContext(opts = {}) {
|
||||
let currentInstance;
|
||||
let isSingleton = false;
|
||||
const checkConflict = (instance) => {
|
||||
if (currentInstance && currentInstance !== instance) {
|
||||
throw new Error("Context conflict");
|
||||
}
|
||||
};
|
||||
let als;
|
||||
if (opts.asyncContext) {
|
||||
const _AsyncLocalStorage = opts.AsyncLocalStorage || globalThis.AsyncLocalStorage;
|
||||
if (_AsyncLocalStorage) {
|
||||
als = new _AsyncLocalStorage();
|
||||
} else {
|
||||
console.warn("[unctx] `AsyncLocalStorage` is not provided.");
|
||||
}
|
||||
}
|
||||
const _getCurrentInstance = () => {
|
||||
if (als) {
|
||||
const instance = als.getStore();
|
||||
if (instance !== void 0) {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
return currentInstance;
|
||||
};
|
||||
return {
|
||||
use: () => {
|
||||
const _instance = _getCurrentInstance();
|
||||
if (_instance === void 0) {
|
||||
throw new Error("Context is not available");
|
||||
}
|
||||
return _instance;
|
||||
},
|
||||
tryUse: () => {
|
||||
return _getCurrentInstance();
|
||||
},
|
||||
set: (instance, replace) => {
|
||||
if (!replace) {
|
||||
checkConflict(instance);
|
||||
}
|
||||
currentInstance = instance;
|
||||
isSingleton = true;
|
||||
},
|
||||
unset: () => {
|
||||
currentInstance = void 0;
|
||||
isSingleton = false;
|
||||
},
|
||||
call: (instance, callback) => {
|
||||
checkConflict(instance);
|
||||
currentInstance = instance;
|
||||
try {
|
||||
return als ? als.run(instance, callback) : callback();
|
||||
} finally {
|
||||
if (!isSingleton) {
|
||||
currentInstance = void 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
async callAsync(instance, callback) {
|
||||
currentInstance = instance;
|
||||
const onRestore = () => {
|
||||
currentInstance = instance;
|
||||
};
|
||||
const onLeave = () => currentInstance === instance ? onRestore : void 0;
|
||||
asyncHandlers.add(onLeave);
|
||||
try {
|
||||
const r = als ? als.run(instance, callback) : callback();
|
||||
if (!isSingleton) {
|
||||
currentInstance = void 0;
|
||||
}
|
||||
return await r;
|
||||
} finally {
|
||||
asyncHandlers.delete(onLeave);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function createNamespace(defaultOpts = {}) {
|
||||
const contexts = {};
|
||||
return {
|
||||
get(key, opts = {}) {
|
||||
if (!contexts[key]) {
|
||||
contexts[key] = createContext({ ...defaultOpts, ...opts });
|
||||
}
|
||||
return contexts[key];
|
||||
}
|
||||
};
|
||||
}
|
||||
const _globalThis = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : {};
|
||||
const globalKey = "__unctx__";
|
||||
const defaultNamespace = _globalThis[globalKey] || (_globalThis[globalKey] = createNamespace());
|
||||
const getContext = (key, opts = {}) => defaultNamespace.get(key, opts);
|
||||
const useContext = (key, opts = {}) => getContext(key, opts).use;
|
||||
const asyncHandlersKey = "__unctx_async_handlers__";
|
||||
const asyncHandlers = _globalThis[asyncHandlersKey] || (_globalThis[asyncHandlersKey] = /* @__PURE__ */ new Set());
|
||||
function executeAsync(function_) {
|
||||
const restores = [];
|
||||
for (const leaveHandler of asyncHandlers) {
|
||||
const restore2 = leaveHandler();
|
||||
if (restore2) {
|
||||
restores.push(restore2);
|
||||
}
|
||||
}
|
||||
const restore = () => {
|
||||
for (const restore2 of restores) {
|
||||
restore2();
|
||||
}
|
||||
};
|
||||
let awaitable = function_();
|
||||
if (awaitable && typeof awaitable === "object" && "catch" in awaitable) {
|
||||
awaitable = awaitable.catch((error) => {
|
||||
restore();
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
return [awaitable, restore];
|
||||
}
|
||||
function withAsyncContext(function_, transformed) {
|
||||
if (!transformed) {
|
||||
console.warn(
|
||||
"[unctx] `withAsyncContext` needs transformation for async context support in",
|
||||
function_,
|
||||
"\n",
|
||||
function_.toString()
|
||||
);
|
||||
}
|
||||
return function_;
|
||||
}
|
||||
|
||||
exports.createContext = createContext;
|
||||
exports.createNamespace = createNamespace;
|
||||
exports.defaultNamespace = defaultNamespace;
|
||||
exports.executeAsync = executeAsync;
|
||||
exports.getContext = getContext;
|
||||
exports.useContext = useContext;
|
||||
exports.withAsyncContext = withAsyncContext;
|
||||
49
node_modules/unctx/dist/index.d.cts
generated
vendored
Normal file
49
node_modules/unctx/dist/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import { AsyncLocalStorage } from 'node:async_hooks';
|
||||
|
||||
interface UseContext<T> {
|
||||
/**
|
||||
* Get the current context. Throws if no context is set.
|
||||
*/
|
||||
use: () => T;
|
||||
/**
|
||||
* Get the current context. Returns `null` when no context is set.
|
||||
*/
|
||||
tryUse: () => T | null;
|
||||
/**
|
||||
* Set the context as Singleton Pattern.
|
||||
*/
|
||||
set: (instance?: T, replace?: boolean) => void;
|
||||
/**
|
||||
* Clear current context.
|
||||
*/
|
||||
unset: () => void;
|
||||
/**
|
||||
* Exclude a synchronous function with the provided context.
|
||||
*/
|
||||
call: <R>(instance: T, callback: () => R) => R;
|
||||
/**
|
||||
* Exclude an asynchronous function with the provided context.
|
||||
* Requires installing the transform plugin to work properly.
|
||||
*/
|
||||
callAsync: <R>(instance: T, callback: () => R | Promise<R>) => Promise<R>;
|
||||
}
|
||||
interface ContextOptions {
|
||||
asyncContext?: boolean;
|
||||
AsyncLocalStorage?: typeof AsyncLocalStorage;
|
||||
}
|
||||
declare function createContext<T = any>(opts?: ContextOptions): UseContext<T>;
|
||||
interface ContextNamespace {
|
||||
get: <T>(key: string, opts?: ContextOptions) => UseContext<T>;
|
||||
}
|
||||
declare function createNamespace<T = any>(defaultOpts?: ContextOptions): {
|
||||
get(key: string, opts?: ContextOptions): UseContext<T>;
|
||||
};
|
||||
declare const defaultNamespace: ContextNamespace;
|
||||
declare const getContext: <T>(key: string, opts?: ContextOptions) => UseContext<T>;
|
||||
declare const useContext: <T>(key: string, opts?: ContextOptions) => () => T;
|
||||
type AsyncFunction<T> = () => Promise<T>;
|
||||
declare function executeAsync<T>(function_: AsyncFunction<T>): [Promise<T>, () => void];
|
||||
declare function withAsyncContext<T = any>(function_: AsyncFunction<T>, transformed?: boolean): AsyncFunction<T>;
|
||||
|
||||
export { createContext, createNamespace, defaultNamespace, executeAsync, getContext, useContext, withAsyncContext };
|
||||
export type { ContextNamespace, ContextOptions, UseContext };
|
||||
49
node_modules/unctx/dist/index.d.mts
generated
vendored
Normal file
49
node_modules/unctx/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import { AsyncLocalStorage } from 'node:async_hooks';
|
||||
|
||||
interface UseContext<T> {
|
||||
/**
|
||||
* Get the current context. Throws if no context is set.
|
||||
*/
|
||||
use: () => T;
|
||||
/**
|
||||
* Get the current context. Returns `null` when no context is set.
|
||||
*/
|
||||
tryUse: () => T | null;
|
||||
/**
|
||||
* Set the context as Singleton Pattern.
|
||||
*/
|
||||
set: (instance?: T, replace?: boolean) => void;
|
||||
/**
|
||||
* Clear current context.
|
||||
*/
|
||||
unset: () => void;
|
||||
/**
|
||||
* Exclude a synchronous function with the provided context.
|
||||
*/
|
||||
call: <R>(instance: T, callback: () => R) => R;
|
||||
/**
|
||||
* Exclude an asynchronous function with the provided context.
|
||||
* Requires installing the transform plugin to work properly.
|
||||
*/
|
||||
callAsync: <R>(instance: T, callback: () => R | Promise<R>) => Promise<R>;
|
||||
}
|
||||
interface ContextOptions {
|
||||
asyncContext?: boolean;
|
||||
AsyncLocalStorage?: typeof AsyncLocalStorage;
|
||||
}
|
||||
declare function createContext<T = any>(opts?: ContextOptions): UseContext<T>;
|
||||
interface ContextNamespace {
|
||||
get: <T>(key: string, opts?: ContextOptions) => UseContext<T>;
|
||||
}
|
||||
declare function createNamespace<T = any>(defaultOpts?: ContextOptions): {
|
||||
get(key: string, opts?: ContextOptions): UseContext<T>;
|
||||
};
|
||||
declare const defaultNamespace: ContextNamespace;
|
||||
declare const getContext: <T>(key: string, opts?: ContextOptions) => UseContext<T>;
|
||||
declare const useContext: <T>(key: string, opts?: ContextOptions) => () => T;
|
||||
type AsyncFunction<T> = () => Promise<T>;
|
||||
declare function executeAsync<T>(function_: AsyncFunction<T>): [Promise<T>, () => void];
|
||||
declare function withAsyncContext<T = any>(function_: AsyncFunction<T>, transformed?: boolean): AsyncFunction<T>;
|
||||
|
||||
export { createContext, createNamespace, defaultNamespace, executeAsync, getContext, useContext, withAsyncContext };
|
||||
export type { ContextNamespace, ContextOptions, UseContext };
|
||||
49
node_modules/unctx/dist/index.d.ts
generated
vendored
Normal file
49
node_modules/unctx/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import { AsyncLocalStorage } from 'node:async_hooks';
|
||||
|
||||
interface UseContext<T> {
|
||||
/**
|
||||
* Get the current context. Throws if no context is set.
|
||||
*/
|
||||
use: () => T;
|
||||
/**
|
||||
* Get the current context. Returns `null` when no context is set.
|
||||
*/
|
||||
tryUse: () => T | null;
|
||||
/**
|
||||
* Set the context as Singleton Pattern.
|
||||
*/
|
||||
set: (instance?: T, replace?: boolean) => void;
|
||||
/**
|
||||
* Clear current context.
|
||||
*/
|
||||
unset: () => void;
|
||||
/**
|
||||
* Exclude a synchronous function with the provided context.
|
||||
*/
|
||||
call: <R>(instance: T, callback: () => R) => R;
|
||||
/**
|
||||
* Exclude an asynchronous function with the provided context.
|
||||
* Requires installing the transform plugin to work properly.
|
||||
*/
|
||||
callAsync: <R>(instance: T, callback: () => R | Promise<R>) => Promise<R>;
|
||||
}
|
||||
interface ContextOptions {
|
||||
asyncContext?: boolean;
|
||||
AsyncLocalStorage?: typeof AsyncLocalStorage;
|
||||
}
|
||||
declare function createContext<T = any>(opts?: ContextOptions): UseContext<T>;
|
||||
interface ContextNamespace {
|
||||
get: <T>(key: string, opts?: ContextOptions) => UseContext<T>;
|
||||
}
|
||||
declare function createNamespace<T = any>(defaultOpts?: ContextOptions): {
|
||||
get(key: string, opts?: ContextOptions): UseContext<T>;
|
||||
};
|
||||
declare const defaultNamespace: ContextNamespace;
|
||||
declare const getContext: <T>(key: string, opts?: ContextOptions) => UseContext<T>;
|
||||
declare const useContext: <T>(key: string, opts?: ContextOptions) => () => T;
|
||||
type AsyncFunction<T> = () => Promise<T>;
|
||||
declare function executeAsync<T>(function_: AsyncFunction<T>): [Promise<T>, () => void];
|
||||
declare function withAsyncContext<T = any>(function_: AsyncFunction<T>, transformed?: boolean): AsyncFunction<T>;
|
||||
|
||||
export { createContext, createNamespace, defaultNamespace, executeAsync, getContext, useContext, withAsyncContext };
|
||||
export type { ContextNamespace, ContextOptions, UseContext };
|
||||
131
node_modules/unctx/dist/index.mjs
generated
vendored
Normal file
131
node_modules/unctx/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
function createContext(opts = {}) {
|
||||
let currentInstance;
|
||||
let isSingleton = false;
|
||||
const checkConflict = (instance) => {
|
||||
if (currentInstance && currentInstance !== instance) {
|
||||
throw new Error("Context conflict");
|
||||
}
|
||||
};
|
||||
let als;
|
||||
if (opts.asyncContext) {
|
||||
const _AsyncLocalStorage = opts.AsyncLocalStorage || globalThis.AsyncLocalStorage;
|
||||
if (_AsyncLocalStorage) {
|
||||
als = new _AsyncLocalStorage();
|
||||
} else {
|
||||
console.warn("[unctx] `AsyncLocalStorage` is not provided.");
|
||||
}
|
||||
}
|
||||
const _getCurrentInstance = () => {
|
||||
if (als) {
|
||||
const instance = als.getStore();
|
||||
if (instance !== void 0) {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
return currentInstance;
|
||||
};
|
||||
return {
|
||||
use: () => {
|
||||
const _instance = _getCurrentInstance();
|
||||
if (_instance === void 0) {
|
||||
throw new Error("Context is not available");
|
||||
}
|
||||
return _instance;
|
||||
},
|
||||
tryUse: () => {
|
||||
return _getCurrentInstance();
|
||||
},
|
||||
set: (instance, replace) => {
|
||||
if (!replace) {
|
||||
checkConflict(instance);
|
||||
}
|
||||
currentInstance = instance;
|
||||
isSingleton = true;
|
||||
},
|
||||
unset: () => {
|
||||
currentInstance = void 0;
|
||||
isSingleton = false;
|
||||
},
|
||||
call: (instance, callback) => {
|
||||
checkConflict(instance);
|
||||
currentInstance = instance;
|
||||
try {
|
||||
return als ? als.run(instance, callback) : callback();
|
||||
} finally {
|
||||
if (!isSingleton) {
|
||||
currentInstance = void 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
async callAsync(instance, callback) {
|
||||
currentInstance = instance;
|
||||
const onRestore = () => {
|
||||
currentInstance = instance;
|
||||
};
|
||||
const onLeave = () => currentInstance === instance ? onRestore : void 0;
|
||||
asyncHandlers.add(onLeave);
|
||||
try {
|
||||
const r = als ? als.run(instance, callback) : callback();
|
||||
if (!isSingleton) {
|
||||
currentInstance = void 0;
|
||||
}
|
||||
return await r;
|
||||
} finally {
|
||||
asyncHandlers.delete(onLeave);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function createNamespace(defaultOpts = {}) {
|
||||
const contexts = {};
|
||||
return {
|
||||
get(key, opts = {}) {
|
||||
if (!contexts[key]) {
|
||||
contexts[key] = createContext({ ...defaultOpts, ...opts });
|
||||
}
|
||||
return contexts[key];
|
||||
}
|
||||
};
|
||||
}
|
||||
const _globalThis = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : {};
|
||||
const globalKey = "__unctx__";
|
||||
const defaultNamespace = _globalThis[globalKey] || (_globalThis[globalKey] = createNamespace());
|
||||
const getContext = (key, opts = {}) => defaultNamespace.get(key, opts);
|
||||
const useContext = (key, opts = {}) => getContext(key, opts).use;
|
||||
const asyncHandlersKey = "__unctx_async_handlers__";
|
||||
const asyncHandlers = _globalThis[asyncHandlersKey] || (_globalThis[asyncHandlersKey] = /* @__PURE__ */ new Set());
|
||||
function executeAsync(function_) {
|
||||
const restores = [];
|
||||
for (const leaveHandler of asyncHandlers) {
|
||||
const restore2 = leaveHandler();
|
||||
if (restore2) {
|
||||
restores.push(restore2);
|
||||
}
|
||||
}
|
||||
const restore = () => {
|
||||
for (const restore2 of restores) {
|
||||
restore2();
|
||||
}
|
||||
};
|
||||
let awaitable = function_();
|
||||
if (awaitable && typeof awaitable === "object" && "catch" in awaitable) {
|
||||
awaitable = awaitable.catch((error) => {
|
||||
restore();
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
return [awaitable, restore];
|
||||
}
|
||||
function withAsyncContext(function_, transformed) {
|
||||
if (!transformed) {
|
||||
console.warn(
|
||||
"[unctx] `withAsyncContext` needs transformation for async context support in",
|
||||
function_,
|
||||
"\n",
|
||||
function_.toString()
|
||||
);
|
||||
}
|
||||
return function_;
|
||||
}
|
||||
|
||||
export { createContext, createNamespace, defaultNamespace, executeAsync, getContext, useContext, withAsyncContext };
|
||||
35
node_modules/unctx/dist/plugin.cjs
generated
vendored
Normal file
35
node_modules/unctx/dist/plugin.cjs
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const unplugin = require('unplugin');
|
||||
const transform = require('./transform.cjs');
|
||||
require('acorn');
|
||||
require('magic-string');
|
||||
require('estree-walker');
|
||||
|
||||
const unctxPlugin = unplugin.createUnplugin(
|
||||
(options = {}) => {
|
||||
const transformer = transform.createTransformer(options);
|
||||
return {
|
||||
name: "unctx:transform",
|
||||
enforce: "post",
|
||||
transformInclude: options.transformInclude,
|
||||
transform: {
|
||||
filter: options.transformFilter ?? transformer.filter,
|
||||
handler(code, id) {
|
||||
const result = transformer.transform(code);
|
||||
if (result) {
|
||||
return {
|
||||
code: result.code,
|
||||
map: result.magicString.generateMap({
|
||||
source: id,
|
||||
includeContent: true
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
exports.unctxPlugin = unctxPlugin;
|
||||
17
node_modules/unctx/dist/plugin.d.cts
generated
vendored
Normal file
17
node_modules/unctx/dist/plugin.d.cts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import * as unplugin from 'unplugin';
|
||||
import { HookFilter } from 'unplugin';
|
||||
import { TransformerOptions } from './transform.cjs';
|
||||
import 'magic-string';
|
||||
|
||||
interface UnctxPluginOptions extends TransformerOptions {
|
||||
/** Plugin Hook Filter for the transform hook
|
||||
* @see https://unplugin.unjs.io/guide/#filters
|
||||
*/
|
||||
transformFilter?: HookFilter;
|
||||
/** Function to determine whether a file should be transformed. If possible, use `transformFilter` instead for better performance. */
|
||||
transformInclude?: (id: string) => boolean;
|
||||
}
|
||||
declare const unctxPlugin: unplugin.UnpluginInstance<UnctxPluginOptions, boolean>;
|
||||
|
||||
export { unctxPlugin };
|
||||
export type { UnctxPluginOptions };
|
||||
17
node_modules/unctx/dist/plugin.d.mts
generated
vendored
Normal file
17
node_modules/unctx/dist/plugin.d.mts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import * as unplugin from 'unplugin';
|
||||
import { HookFilter } from 'unplugin';
|
||||
import { TransformerOptions } from './transform.mjs';
|
||||
import 'magic-string';
|
||||
|
||||
interface UnctxPluginOptions extends TransformerOptions {
|
||||
/** Plugin Hook Filter for the transform hook
|
||||
* @see https://unplugin.unjs.io/guide/#filters
|
||||
*/
|
||||
transformFilter?: HookFilter;
|
||||
/** Function to determine whether a file should be transformed. If possible, use `transformFilter` instead for better performance. */
|
||||
transformInclude?: (id: string) => boolean;
|
||||
}
|
||||
declare const unctxPlugin: unplugin.UnpluginInstance<UnctxPluginOptions, boolean>;
|
||||
|
||||
export { unctxPlugin };
|
||||
export type { UnctxPluginOptions };
|
||||
17
node_modules/unctx/dist/plugin.d.ts
generated
vendored
Normal file
17
node_modules/unctx/dist/plugin.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import * as unplugin from 'unplugin';
|
||||
import { HookFilter } from 'unplugin';
|
||||
import { TransformerOptions } from './transform.js';
|
||||
import 'magic-string';
|
||||
|
||||
interface UnctxPluginOptions extends TransformerOptions {
|
||||
/** Plugin Hook Filter for the transform hook
|
||||
* @see https://unplugin.unjs.io/guide/#filters
|
||||
*/
|
||||
transformFilter?: HookFilter;
|
||||
/** Function to determine whether a file should be transformed. If possible, use `transformFilter` instead for better performance. */
|
||||
transformInclude?: (id: string) => boolean;
|
||||
}
|
||||
declare const unctxPlugin: unplugin.UnpluginInstance<UnctxPluginOptions, boolean>;
|
||||
|
||||
export { unctxPlugin };
|
||||
export type { UnctxPluginOptions };
|
||||
33
node_modules/unctx/dist/plugin.mjs
generated
vendored
Normal file
33
node_modules/unctx/dist/plugin.mjs
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createUnplugin } from 'unplugin';
|
||||
import { createTransformer } from './transform.mjs';
|
||||
import 'acorn';
|
||||
import 'magic-string';
|
||||
import 'estree-walker';
|
||||
|
||||
const unctxPlugin = createUnplugin(
|
||||
(options = {}) => {
|
||||
const transformer = createTransformer(options);
|
||||
return {
|
||||
name: "unctx:transform",
|
||||
enforce: "post",
|
||||
transformInclude: options.transformInclude,
|
||||
transform: {
|
||||
filter: options.transformFilter ?? transformer.filter,
|
||||
handler(code, id) {
|
||||
const result = transformer.transform(code);
|
||||
if (result) {
|
||||
return {
|
||||
code: result.code,
|
||||
map: result.magicString.generateMap({
|
||||
source: id,
|
||||
includeContent: true
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
export { unctxPlugin };
|
||||
171
node_modules/unctx/dist/transform.cjs
generated
vendored
Normal file
171
node_modules/unctx/dist/transform.cjs
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
'use strict';
|
||||
|
||||
const acorn = require('acorn');
|
||||
const MagicString = require('magic-string');
|
||||
const estreeWalker = require('estree-walker');
|
||||
|
||||
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
||||
|
||||
function _interopNamespaceCompat(e) {
|
||||
if (e && typeof e === 'object' && 'default' in e) return e;
|
||||
const n = Object.create(null);
|
||||
if (e) {
|
||||
for (const k in e) {
|
||||
n[k] = e[k];
|
||||
}
|
||||
}
|
||||
n.default = e;
|
||||
return n;
|
||||
}
|
||||
|
||||
const acorn__namespace = /*#__PURE__*/_interopNamespaceCompat(acorn);
|
||||
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
||||
|
||||
const kInjected = "__unctx_injected__";
|
||||
function createTransformer(options = {}) {
|
||||
options = {
|
||||
asyncFunctions: ["withAsyncContext"],
|
||||
helperModule: "unctx",
|
||||
helperName: "executeAsync",
|
||||
objectDefinitions: {},
|
||||
...options
|
||||
};
|
||||
const objectDefinitionFunctions = Object.keys(options.objectDefinitions);
|
||||
const matchRE = new RegExp(
|
||||
`\\b(${[...options.asyncFunctions, ...objectDefinitionFunctions].join(
|
||||
"|"
|
||||
)})\\(`
|
||||
);
|
||||
function shouldTransform(code) {
|
||||
return typeof code === "string" && matchRE.test(code);
|
||||
}
|
||||
const filter = {
|
||||
code: matchRE
|
||||
};
|
||||
function transform(code, options_ = {}) {
|
||||
if (!options_.force && !shouldTransform(code)) {
|
||||
return;
|
||||
}
|
||||
const ast = acorn__namespace.parse(code, {
|
||||
sourceType: "module",
|
||||
ecmaVersion: "latest",
|
||||
locations: true
|
||||
});
|
||||
const s = new MagicString__default(code);
|
||||
const lines = code.split("\n");
|
||||
let detected = false;
|
||||
estreeWalker.walk(ast, {
|
||||
enter(node) {
|
||||
if (node.type === "CallExpression") {
|
||||
const functionName = _getFunctionName(node.callee);
|
||||
if (options.asyncFunctions.includes(functionName)) {
|
||||
transformFunctionArguments(node);
|
||||
if (functionName !== "callAsync") {
|
||||
const lastArgument = node.arguments[node.arguments.length - 1];
|
||||
if (lastArgument && lastArgument.loc) {
|
||||
s.appendRight(toIndex(lastArgument.loc.end), ",1");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (objectDefinitionFunctions.includes(functionName)) {
|
||||
for (const argument of node.arguments) {
|
||||
if (argument.type !== "ObjectExpression") {
|
||||
continue;
|
||||
}
|
||||
for (const property of argument.properties) {
|
||||
if (property.type !== "Property" || property.key.type !== "Identifier") {
|
||||
continue;
|
||||
}
|
||||
if (options.objectDefinitions[functionName]?.includes(
|
||||
property.key?.name
|
||||
)) {
|
||||
transformFunctionBody(property.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!detected) {
|
||||
return;
|
||||
}
|
||||
s.appendLeft(
|
||||
0,
|
||||
`import { ${options.helperName} as __executeAsync } from "${options.helperModule}";`
|
||||
);
|
||||
return {
|
||||
code: s.toString(),
|
||||
magicString: s
|
||||
};
|
||||
function toIndex(pos) {
|
||||
return lines.slice(0, pos.line - 1).join("\n").length + pos.column + 1;
|
||||
}
|
||||
function transformFunctionBody(function_) {
|
||||
if (function_.type !== "ArrowFunctionExpression" && function_.type !== "FunctionExpression") {
|
||||
return;
|
||||
}
|
||||
if (!function_.async) {
|
||||
return;
|
||||
}
|
||||
const body = function_.body;
|
||||
let injectVariable = false;
|
||||
estreeWalker.walk(body, {
|
||||
enter(node, parent) {
|
||||
if (node.type === "AwaitExpression" && !node[kInjected]) {
|
||||
detected = true;
|
||||
injectVariable = true;
|
||||
injectForNode(node, parent);
|
||||
} else if (node.type === "IfStatement" && node.consequent.type === "ExpressionStatement" && node.consequent.expression.type === "AwaitExpression") {
|
||||
detected = true;
|
||||
injectVariable = true;
|
||||
node.consequent.expression[kInjected] = true;
|
||||
injectForNode(node.consequent.expression, node);
|
||||
}
|
||||
if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration") {
|
||||
return this.skip();
|
||||
}
|
||||
}
|
||||
});
|
||||
if (injectVariable && body.loc) {
|
||||
s.appendLeft(toIndex(body.loc.start) + 1, "let __temp, __restore;");
|
||||
}
|
||||
}
|
||||
function transformFunctionArguments(node) {
|
||||
for (const function_ of node.arguments) {
|
||||
transformFunctionBody(function_);
|
||||
}
|
||||
}
|
||||
function injectForNode(node, parent) {
|
||||
const isStatement = parent?.type === "ExpressionStatement";
|
||||
if (!node.loc || !node.argument.loc) {
|
||||
return;
|
||||
}
|
||||
s.remove(toIndex(node.loc.start), toIndex(node.argument.loc.start));
|
||||
s.remove(toIndex(node.loc.end), toIndex(node.argument.loc.end));
|
||||
s.appendLeft(
|
||||
toIndex(node.argument.loc.start),
|
||||
isStatement ? `;(([__temp,__restore]=__executeAsync(()=>` : `(([__temp,__restore]=__executeAsync(()=>`
|
||||
);
|
||||
s.appendRight(
|
||||
toIndex(node.argument.loc.end),
|
||||
isStatement ? `)),await __temp,__restore());` : `)),__temp=await __temp,__restore(),__temp)`
|
||||
);
|
||||
}
|
||||
}
|
||||
return {
|
||||
transform,
|
||||
filter,
|
||||
shouldTransform
|
||||
};
|
||||
}
|
||||
function _getFunctionName(node) {
|
||||
if (node.type === "Identifier") {
|
||||
return node.name;
|
||||
} else if (node.type === "MemberExpression") {
|
||||
return _getFunctionName(node.property);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
exports.createTransformer = createTransformer;
|
||||
40
node_modules/unctx/dist/transform.d.cts
generated
vendored
Normal file
40
node_modules/unctx/dist/transform.d.cts
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import MagicString from 'magic-string';
|
||||
|
||||
interface TransformerOptions {
|
||||
/**
|
||||
* The function names to be transformed.
|
||||
*
|
||||
* @default ['withAsyncContext']
|
||||
*/
|
||||
asyncFunctions?: string[];
|
||||
/**
|
||||
* @default 'unctx'
|
||||
*/
|
||||
helperModule?: string;
|
||||
/**
|
||||
* @default 'executeAsync'
|
||||
*/
|
||||
helperName?: string;
|
||||
/**
|
||||
* Whether to transform properties of an object defined with a helper function. For example,
|
||||
* to transform key `middleware` within the object defined with function `defineMeta`, you would pass:
|
||||
* `{ defineMeta: ['middleware'] }`.
|
||||
* @default {}
|
||||
*/
|
||||
objectDefinitions?: Record<string, string[]>;
|
||||
}
|
||||
declare function createTransformer(options?: TransformerOptions): {
|
||||
transform: (code: string, options_?: {
|
||||
force?: false;
|
||||
}) => {
|
||||
code: string;
|
||||
magicString: MagicString;
|
||||
} | undefined;
|
||||
filter: {
|
||||
code: RegExp;
|
||||
};
|
||||
shouldTransform: (code: string) => boolean;
|
||||
};
|
||||
|
||||
export { createTransformer };
|
||||
export type { TransformerOptions };
|
||||
40
node_modules/unctx/dist/transform.d.mts
generated
vendored
Normal file
40
node_modules/unctx/dist/transform.d.mts
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import MagicString from 'magic-string';
|
||||
|
||||
interface TransformerOptions {
|
||||
/**
|
||||
* The function names to be transformed.
|
||||
*
|
||||
* @default ['withAsyncContext']
|
||||
*/
|
||||
asyncFunctions?: string[];
|
||||
/**
|
||||
* @default 'unctx'
|
||||
*/
|
||||
helperModule?: string;
|
||||
/**
|
||||
* @default 'executeAsync'
|
||||
*/
|
||||
helperName?: string;
|
||||
/**
|
||||
* Whether to transform properties of an object defined with a helper function. For example,
|
||||
* to transform key `middleware` within the object defined with function `defineMeta`, you would pass:
|
||||
* `{ defineMeta: ['middleware'] }`.
|
||||
* @default {}
|
||||
*/
|
||||
objectDefinitions?: Record<string, string[]>;
|
||||
}
|
||||
declare function createTransformer(options?: TransformerOptions): {
|
||||
transform: (code: string, options_?: {
|
||||
force?: false;
|
||||
}) => {
|
||||
code: string;
|
||||
magicString: MagicString;
|
||||
} | undefined;
|
||||
filter: {
|
||||
code: RegExp;
|
||||
};
|
||||
shouldTransform: (code: string) => boolean;
|
||||
};
|
||||
|
||||
export { createTransformer };
|
||||
export type { TransformerOptions };
|
||||
40
node_modules/unctx/dist/transform.d.ts
generated
vendored
Normal file
40
node_modules/unctx/dist/transform.d.ts
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import MagicString from 'magic-string';
|
||||
|
||||
interface TransformerOptions {
|
||||
/**
|
||||
* The function names to be transformed.
|
||||
*
|
||||
* @default ['withAsyncContext']
|
||||
*/
|
||||
asyncFunctions?: string[];
|
||||
/**
|
||||
* @default 'unctx'
|
||||
*/
|
||||
helperModule?: string;
|
||||
/**
|
||||
* @default 'executeAsync'
|
||||
*/
|
||||
helperName?: string;
|
||||
/**
|
||||
* Whether to transform properties of an object defined with a helper function. For example,
|
||||
* to transform key `middleware` within the object defined with function `defineMeta`, you would pass:
|
||||
* `{ defineMeta: ['middleware'] }`.
|
||||
* @default {}
|
||||
*/
|
||||
objectDefinitions?: Record<string, string[]>;
|
||||
}
|
||||
declare function createTransformer(options?: TransformerOptions): {
|
||||
transform: (code: string, options_?: {
|
||||
force?: false;
|
||||
}) => {
|
||||
code: string;
|
||||
magicString: MagicString;
|
||||
} | undefined;
|
||||
filter: {
|
||||
code: RegExp;
|
||||
};
|
||||
shouldTransform: (code: string) => boolean;
|
||||
};
|
||||
|
||||
export { createTransformer };
|
||||
export type { TransformerOptions };
|
||||
152
node_modules/unctx/dist/transform.mjs
generated
vendored
Normal file
152
node_modules/unctx/dist/transform.mjs
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
import * as acorn from 'acorn';
|
||||
import MagicString from 'magic-string';
|
||||
import { walk } from 'estree-walker';
|
||||
|
||||
const kInjected = "__unctx_injected__";
|
||||
function createTransformer(options = {}) {
|
||||
options = {
|
||||
asyncFunctions: ["withAsyncContext"],
|
||||
helperModule: "unctx",
|
||||
helperName: "executeAsync",
|
||||
objectDefinitions: {},
|
||||
...options
|
||||
};
|
||||
const objectDefinitionFunctions = Object.keys(options.objectDefinitions);
|
||||
const matchRE = new RegExp(
|
||||
`\\b(${[...options.asyncFunctions, ...objectDefinitionFunctions].join(
|
||||
"|"
|
||||
)})\\(`
|
||||
);
|
||||
function shouldTransform(code) {
|
||||
return typeof code === "string" && matchRE.test(code);
|
||||
}
|
||||
const filter = {
|
||||
code: matchRE
|
||||
};
|
||||
function transform(code, options_ = {}) {
|
||||
if (!options_.force && !shouldTransform(code)) {
|
||||
return;
|
||||
}
|
||||
const ast = acorn.parse(code, {
|
||||
sourceType: "module",
|
||||
ecmaVersion: "latest",
|
||||
locations: true
|
||||
});
|
||||
const s = new MagicString(code);
|
||||
const lines = code.split("\n");
|
||||
let detected = false;
|
||||
walk(ast, {
|
||||
enter(node) {
|
||||
if (node.type === "CallExpression") {
|
||||
const functionName = _getFunctionName(node.callee);
|
||||
if (options.asyncFunctions.includes(functionName)) {
|
||||
transformFunctionArguments(node);
|
||||
if (functionName !== "callAsync") {
|
||||
const lastArgument = node.arguments[node.arguments.length - 1];
|
||||
if (lastArgument && lastArgument.loc) {
|
||||
s.appendRight(toIndex(lastArgument.loc.end), ",1");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (objectDefinitionFunctions.includes(functionName)) {
|
||||
for (const argument of node.arguments) {
|
||||
if (argument.type !== "ObjectExpression") {
|
||||
continue;
|
||||
}
|
||||
for (const property of argument.properties) {
|
||||
if (property.type !== "Property" || property.key.type !== "Identifier") {
|
||||
continue;
|
||||
}
|
||||
if (options.objectDefinitions[functionName]?.includes(
|
||||
property.key?.name
|
||||
)) {
|
||||
transformFunctionBody(property.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!detected) {
|
||||
return;
|
||||
}
|
||||
s.appendLeft(
|
||||
0,
|
||||
`import { ${options.helperName} as __executeAsync } from "${options.helperModule}";`
|
||||
);
|
||||
return {
|
||||
code: s.toString(),
|
||||
magicString: s
|
||||
};
|
||||
function toIndex(pos) {
|
||||
return lines.slice(0, pos.line - 1).join("\n").length + pos.column + 1;
|
||||
}
|
||||
function transformFunctionBody(function_) {
|
||||
if (function_.type !== "ArrowFunctionExpression" && function_.type !== "FunctionExpression") {
|
||||
return;
|
||||
}
|
||||
if (!function_.async) {
|
||||
return;
|
||||
}
|
||||
const body = function_.body;
|
||||
let injectVariable = false;
|
||||
walk(body, {
|
||||
enter(node, parent) {
|
||||
if (node.type === "AwaitExpression" && !node[kInjected]) {
|
||||
detected = true;
|
||||
injectVariable = true;
|
||||
injectForNode(node, parent);
|
||||
} else if (node.type === "IfStatement" && node.consequent.type === "ExpressionStatement" && node.consequent.expression.type === "AwaitExpression") {
|
||||
detected = true;
|
||||
injectVariable = true;
|
||||
node.consequent.expression[kInjected] = true;
|
||||
injectForNode(node.consequent.expression, node);
|
||||
}
|
||||
if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration") {
|
||||
return this.skip();
|
||||
}
|
||||
}
|
||||
});
|
||||
if (injectVariable && body.loc) {
|
||||
s.appendLeft(toIndex(body.loc.start) + 1, "let __temp, __restore;");
|
||||
}
|
||||
}
|
||||
function transformFunctionArguments(node) {
|
||||
for (const function_ of node.arguments) {
|
||||
transformFunctionBody(function_);
|
||||
}
|
||||
}
|
||||
function injectForNode(node, parent) {
|
||||
const isStatement = parent?.type === "ExpressionStatement";
|
||||
if (!node.loc || !node.argument.loc) {
|
||||
return;
|
||||
}
|
||||
s.remove(toIndex(node.loc.start), toIndex(node.argument.loc.start));
|
||||
s.remove(toIndex(node.loc.end), toIndex(node.argument.loc.end));
|
||||
s.appendLeft(
|
||||
toIndex(node.argument.loc.start),
|
||||
isStatement ? `;(([__temp,__restore]=__executeAsync(()=>` : `(([__temp,__restore]=__executeAsync(()=>`
|
||||
);
|
||||
s.appendRight(
|
||||
toIndex(node.argument.loc.end),
|
||||
isStatement ? `)),await __temp,__restore());` : `)),__temp=await __temp,__restore(),__temp)`
|
||||
);
|
||||
}
|
||||
}
|
||||
return {
|
||||
transform,
|
||||
filter,
|
||||
shouldTransform
|
||||
};
|
||||
}
|
||||
function _getFunctionName(node) {
|
||||
if (node.type === "Identifier") {
|
||||
return node.name;
|
||||
} else if (node.type === "MemberExpression") {
|
||||
return _getFunctionName(node.property);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
export { createTransformer };
|
||||
7
node_modules/unctx/node_modules/estree-walker/LICENSE
generated
vendored
Normal file
7
node_modules/unctx/node_modules/estree-walker/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2015-20 [these people](https://github.com/Rich-Harris/estree-walker/graphs/contributors)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
48
node_modules/unctx/node_modules/estree-walker/README.md
generated
vendored
Normal file
48
node_modules/unctx/node_modules/estree-walker/README.md
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
# estree-walker
|
||||
|
||||
Simple utility for walking an [ESTree](https://github.com/estree/estree)-compliant AST, such as one generated by [acorn](https://github.com/marijnh/acorn).
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm i estree-walker
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var walk = require('estree-walker').walk;
|
||||
var acorn = require('acorn');
|
||||
|
||||
ast = acorn.parse(sourceCode, options); // https://github.com/acornjs/acorn
|
||||
|
||||
walk(ast, {
|
||||
enter(node, parent, prop, index) {
|
||||
// some code happens
|
||||
},
|
||||
leave(node, parent, prop, index) {
|
||||
// some code happens
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Inside the `enter` function, calling `this.skip()` will prevent the node's children being walked, or the `leave` function (which is optional) being called.
|
||||
|
||||
Call `this.replace(new_node)` in either `enter` or `leave` to replace the current node with a new one.
|
||||
|
||||
Call `this.remove()` in either `enter` or `leave` to remove the current node.
|
||||
|
||||
## Why not use estraverse?
|
||||
|
||||
The ESTree spec is evolving to accommodate ES6/7. I've had a couple of experiences where [estraverse](https://github.com/estools/estraverse) was unable to handle an AST generated by recent versions of acorn, because it hard-codes visitor keys.
|
||||
|
||||
estree-walker, by contrast, simply enumerates a node's properties to find child nodes (and child lists of nodes), and is therefore resistant to spec changes. It's also much smaller. (The performance, if you're wondering, is basically identical.)
|
||||
|
||||
None of which should be taken as criticism of estraverse, which has more features and has been battle-tested in many more situations, and for which I'm very grateful.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
38
node_modules/unctx/node_modules/estree-walker/package.json
generated
vendored
Normal file
38
node_modules/unctx/node_modules/estree-walker/package.json
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "estree-walker",
|
||||
"description": "Traverse an ESTree-compliant AST",
|
||||
"version": "3.0.3",
|
||||
"private": false,
|
||||
"author": "Rich Harris",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Rich-Harris/estree-walker"
|
||||
},
|
||||
"type": "module",
|
||||
"module": "./src/index.js",
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
"types": "./types/index.d.ts",
|
||||
"import": "./src/index.js"
|
||||
}
|
||||
},
|
||||
"types": "types/index.d.ts",
|
||||
"scripts": {
|
||||
"prepublishOnly": "tsc && npm test",
|
||||
"test": "uvu test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/estree": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^4.9.0",
|
||||
"uvu": "^0.5.1"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
"types",
|
||||
"README.md"
|
||||
]
|
||||
}
|
||||
152
node_modules/unctx/node_modules/estree-walker/src/async.js
generated
vendored
Normal file
152
node_modules/unctx/node_modules/estree-walker/src/async.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
import { WalkerBase } from './walker.js';
|
||||
|
||||
/**
|
||||
* @typedef { import('estree').Node} Node
|
||||
* @typedef { import('./walker.js').WalkerContext} WalkerContext
|
||||
* @typedef {(
|
||||
* this: WalkerContext,
|
||||
* node: Node,
|
||||
* parent: Node | null,
|
||||
* key: string | number | symbol | null | undefined,
|
||||
* index: number | null | undefined
|
||||
* ) => Promise<void>} AsyncHandler
|
||||
*/
|
||||
|
||||
export class AsyncWalker extends WalkerBase {
|
||||
/**
|
||||
*
|
||||
* @param {AsyncHandler} [enter]
|
||||
* @param {AsyncHandler} [leave]
|
||||
*/
|
||||
constructor(enter, leave) {
|
||||
super();
|
||||
|
||||
/** @type {boolean} */
|
||||
this.should_skip = false;
|
||||
|
||||
/** @type {boolean} */
|
||||
this.should_remove = false;
|
||||
|
||||
/** @type {Node | null} */
|
||||
this.replacement = null;
|
||||
|
||||
/** @type {WalkerContext} */
|
||||
this.context = {
|
||||
skip: () => (this.should_skip = true),
|
||||
remove: () => (this.should_remove = true),
|
||||
replace: (node) => (this.replacement = node)
|
||||
};
|
||||
|
||||
/** @type {AsyncHandler | undefined} */
|
||||
this.enter = enter;
|
||||
|
||||
/** @type {AsyncHandler | undefined} */
|
||||
this.leave = leave;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Node} node
|
||||
* @param {Parent | null} parent
|
||||
* @param {keyof Parent} [prop]
|
||||
* @param {number | null} [index]
|
||||
* @returns {Promise<Node | null>}
|
||||
*/
|
||||
async visit(node, parent, prop, index) {
|
||||
if (node) {
|
||||
if (this.enter) {
|
||||
const _should_skip = this.should_skip;
|
||||
const _should_remove = this.should_remove;
|
||||
const _replacement = this.replacement;
|
||||
this.should_skip = false;
|
||||
this.should_remove = false;
|
||||
this.replacement = null;
|
||||
|
||||
await this.enter.call(this.context, node, parent, prop, index);
|
||||
|
||||
if (this.replacement) {
|
||||
node = this.replacement;
|
||||
this.replace(parent, prop, index, node);
|
||||
}
|
||||
|
||||
if (this.should_remove) {
|
||||
this.remove(parent, prop, index);
|
||||
}
|
||||
|
||||
const skipped = this.should_skip;
|
||||
const removed = this.should_remove;
|
||||
|
||||
this.should_skip = _should_skip;
|
||||
this.should_remove = _should_remove;
|
||||
this.replacement = _replacement;
|
||||
|
||||
if (skipped) return node;
|
||||
if (removed) return null;
|
||||
}
|
||||
|
||||
/** @type {keyof Node} */
|
||||
let key;
|
||||
|
||||
for (key in node) {
|
||||
/** @type {unknown} */
|
||||
const value = node[key];
|
||||
|
||||
if (value && typeof value === 'object') {
|
||||
if (Array.isArray(value)) {
|
||||
const nodes = /** @type {Array<unknown>} */ (value);
|
||||
for (let i = 0; i < nodes.length; i += 1) {
|
||||
const item = nodes[i];
|
||||
if (isNode(item)) {
|
||||
if (!(await this.visit(item, node, key, i))) {
|
||||
// removed
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (isNode(value)) {
|
||||
await this.visit(value, node, key, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.leave) {
|
||||
const _replacement = this.replacement;
|
||||
const _should_remove = this.should_remove;
|
||||
this.replacement = null;
|
||||
this.should_remove = false;
|
||||
|
||||
await this.leave.call(this.context, node, parent, prop, index);
|
||||
|
||||
if (this.replacement) {
|
||||
node = this.replacement;
|
||||
this.replace(parent, prop, index, node);
|
||||
}
|
||||
|
||||
if (this.should_remove) {
|
||||
this.remove(parent, prop, index);
|
||||
}
|
||||
|
||||
const removed = this.should_remove;
|
||||
|
||||
this.replacement = _replacement;
|
||||
this.should_remove = _should_remove;
|
||||
|
||||
if (removed) return null;
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ducktype a node.
|
||||
*
|
||||
* @param {unknown} value
|
||||
* @returns {value is Node}
|
||||
*/
|
||||
function isNode(value) {
|
||||
return (
|
||||
value !== null && typeof value === 'object' && 'type' in value && typeof value.type === 'string'
|
||||
);
|
||||
}
|
||||
34
node_modules/unctx/node_modules/estree-walker/src/index.js
generated
vendored
Normal file
34
node_modules/unctx/node_modules/estree-walker/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { SyncWalker } from './sync.js';
|
||||
import { AsyncWalker } from './async.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('estree').Node} Node
|
||||
* @typedef {import('./sync.js').SyncHandler} SyncHandler
|
||||
* @typedef {import('./async.js').AsyncHandler} AsyncHandler
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Node} ast
|
||||
* @param {{
|
||||
* enter?: SyncHandler
|
||||
* leave?: SyncHandler
|
||||
* }} walker
|
||||
* @returns {Node | null}
|
||||
*/
|
||||
export function walk(ast, { enter, leave }) {
|
||||
const instance = new SyncWalker(enter, leave);
|
||||
return instance.visit(ast, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} ast
|
||||
* @param {{
|
||||
* enter?: AsyncHandler
|
||||
* leave?: AsyncHandler
|
||||
* }} walker
|
||||
* @returns {Promise<Node | null>}
|
||||
*/
|
||||
export async function asyncWalk(ast, { enter, leave }) {
|
||||
const instance = new AsyncWalker(enter, leave);
|
||||
return await instance.visit(ast, null);
|
||||
}
|
||||
152
node_modules/unctx/node_modules/estree-walker/src/sync.js
generated
vendored
Normal file
152
node_modules/unctx/node_modules/estree-walker/src/sync.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
import { WalkerBase } from './walker.js';
|
||||
|
||||
/**
|
||||
* @typedef { import('estree').Node} Node
|
||||
* @typedef { import('./walker.js').WalkerContext} WalkerContext
|
||||
* @typedef {(
|
||||
* this: WalkerContext,
|
||||
* node: Node,
|
||||
* parent: Node | null,
|
||||
* key: string | number | symbol | null | undefined,
|
||||
* index: number | null | undefined
|
||||
* ) => void} SyncHandler
|
||||
*/
|
||||
|
||||
export class SyncWalker extends WalkerBase {
|
||||
/**
|
||||
*
|
||||
* @param {SyncHandler} [enter]
|
||||
* @param {SyncHandler} [leave]
|
||||
*/
|
||||
constructor(enter, leave) {
|
||||
super();
|
||||
|
||||
/** @type {boolean} */
|
||||
this.should_skip = false;
|
||||
|
||||
/** @type {boolean} */
|
||||
this.should_remove = false;
|
||||
|
||||
/** @type {Node | null} */
|
||||
this.replacement = null;
|
||||
|
||||
/** @type {WalkerContext} */
|
||||
this.context = {
|
||||
skip: () => (this.should_skip = true),
|
||||
remove: () => (this.should_remove = true),
|
||||
replace: (node) => (this.replacement = node)
|
||||
};
|
||||
|
||||
/** @type {SyncHandler | undefined} */
|
||||
this.enter = enter;
|
||||
|
||||
/** @type {SyncHandler | undefined} */
|
||||
this.leave = leave;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Node} node
|
||||
* @param {Parent | null} parent
|
||||
* @param {keyof Parent} [prop]
|
||||
* @param {number | null} [index]
|
||||
* @returns {Node | null}
|
||||
*/
|
||||
visit(node, parent, prop, index) {
|
||||
if (node) {
|
||||
if (this.enter) {
|
||||
const _should_skip = this.should_skip;
|
||||
const _should_remove = this.should_remove;
|
||||
const _replacement = this.replacement;
|
||||
this.should_skip = false;
|
||||
this.should_remove = false;
|
||||
this.replacement = null;
|
||||
|
||||
this.enter.call(this.context, node, parent, prop, index);
|
||||
|
||||
if (this.replacement) {
|
||||
node = this.replacement;
|
||||
this.replace(parent, prop, index, node);
|
||||
}
|
||||
|
||||
if (this.should_remove) {
|
||||
this.remove(parent, prop, index);
|
||||
}
|
||||
|
||||
const skipped = this.should_skip;
|
||||
const removed = this.should_remove;
|
||||
|
||||
this.should_skip = _should_skip;
|
||||
this.should_remove = _should_remove;
|
||||
this.replacement = _replacement;
|
||||
|
||||
if (skipped) return node;
|
||||
if (removed) return null;
|
||||
}
|
||||
|
||||
/** @type {keyof Node} */
|
||||
let key;
|
||||
|
||||
for (key in node) {
|
||||
/** @type {unknown} */
|
||||
const value = node[key];
|
||||
|
||||
if (value && typeof value === 'object') {
|
||||
if (Array.isArray(value)) {
|
||||
const nodes = /** @type {Array<unknown>} */ (value);
|
||||
for (let i = 0; i < nodes.length; i += 1) {
|
||||
const item = nodes[i];
|
||||
if (isNode(item)) {
|
||||
if (!this.visit(item, node, key, i)) {
|
||||
// removed
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (isNode(value)) {
|
||||
this.visit(value, node, key, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.leave) {
|
||||
const _replacement = this.replacement;
|
||||
const _should_remove = this.should_remove;
|
||||
this.replacement = null;
|
||||
this.should_remove = false;
|
||||
|
||||
this.leave.call(this.context, node, parent, prop, index);
|
||||
|
||||
if (this.replacement) {
|
||||
node = this.replacement;
|
||||
this.replace(parent, prop, index, node);
|
||||
}
|
||||
|
||||
if (this.should_remove) {
|
||||
this.remove(parent, prop, index);
|
||||
}
|
||||
|
||||
const removed = this.should_remove;
|
||||
|
||||
this.replacement = _replacement;
|
||||
this.should_remove = _should_remove;
|
||||
|
||||
if (removed) return null;
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ducktype a node.
|
||||
*
|
||||
* @param {unknown} value
|
||||
* @returns {value is Node}
|
||||
*/
|
||||
function isNode(value) {
|
||||
return (
|
||||
value !== null && typeof value === 'object' && 'type' in value && typeof value.type === 'string'
|
||||
);
|
||||
}
|
||||
61
node_modules/unctx/node_modules/estree-walker/src/walker.js
generated
vendored
Normal file
61
node_modules/unctx/node_modules/estree-walker/src/walker.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @typedef { import('estree').Node} Node
|
||||
* @typedef {{
|
||||
* skip: () => void;
|
||||
* remove: () => void;
|
||||
* replace: (node: Node) => void;
|
||||
* }} WalkerContext
|
||||
*/
|
||||
|
||||
export class WalkerBase {
|
||||
constructor() {
|
||||
/** @type {boolean} */
|
||||
this.should_skip = false;
|
||||
|
||||
/** @type {boolean} */
|
||||
this.should_remove = false;
|
||||
|
||||
/** @type {Node | null} */
|
||||
this.replacement = null;
|
||||
|
||||
/** @type {WalkerContext} */
|
||||
this.context = {
|
||||
skip: () => (this.should_skip = true),
|
||||
remove: () => (this.should_remove = true),
|
||||
replace: (node) => (this.replacement = node)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Parent | null | undefined} parent
|
||||
* @param {keyof Parent | null | undefined} prop
|
||||
* @param {number | null | undefined} index
|
||||
* @param {Node} node
|
||||
*/
|
||||
replace(parent, prop, index, node) {
|
||||
if (parent && prop) {
|
||||
if (index != null) {
|
||||
/** @type {Array<Node>} */ (parent[prop])[index] = node;
|
||||
} else {
|
||||
/** @type {Node} */ (parent[prop]) = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Parent | null | undefined} parent
|
||||
* @param {keyof Parent | null | undefined} prop
|
||||
* @param {number | null | undefined} index
|
||||
*/
|
||||
remove(parent, prop, index) {
|
||||
if (parent && prop) {
|
||||
if (index !== null && index !== undefined) {
|
||||
/** @type {Array<Node>} */ (parent[prop]).splice(index, 1);
|
||||
} else {
|
||||
delete parent[prop];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
node_modules/unctx/node_modules/estree-walker/types/async.d.ts
generated
vendored
Normal file
36
node_modules/unctx/node_modules/estree-walker/types/async.d.ts
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @typedef { import('estree').Node} Node
|
||||
* @typedef { import('./walker.js').WalkerContext} WalkerContext
|
||||
* @typedef {(
|
||||
* this: WalkerContext,
|
||||
* node: Node,
|
||||
* parent: Node | null,
|
||||
* key: string | number | symbol | null | undefined,
|
||||
* index: number | null | undefined
|
||||
* ) => Promise<void>} AsyncHandler
|
||||
*/
|
||||
export class AsyncWalker extends WalkerBase {
|
||||
/**
|
||||
*
|
||||
* @param {AsyncHandler} [enter]
|
||||
* @param {AsyncHandler} [leave]
|
||||
*/
|
||||
constructor(enter?: AsyncHandler | undefined, leave?: AsyncHandler | undefined);
|
||||
/** @type {AsyncHandler | undefined} */
|
||||
enter: AsyncHandler | undefined;
|
||||
/** @type {AsyncHandler | undefined} */
|
||||
leave: AsyncHandler | undefined;
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Node} node
|
||||
* @param {Parent | null} parent
|
||||
* @param {keyof Parent} [prop]
|
||||
* @param {number | null} [index]
|
||||
* @returns {Promise<Node | null>}
|
||||
*/
|
||||
visit<Parent extends import("estree").Node>(node: Node, parent: Parent | null, prop?: keyof Parent | undefined, index?: number | null | undefined): Promise<Node | null>;
|
||||
}
|
||||
export type Node = import('estree').Node;
|
||||
export type WalkerContext = import('./walker.js').WalkerContext;
|
||||
export type AsyncHandler = (this: WalkerContext, node: Node, parent: Node | null, key: string | number | symbol | null | undefined, index: number | null | undefined) => Promise<void>;
|
||||
import { WalkerBase } from "./walker.js";
|
||||
32
node_modules/unctx/node_modules/estree-walker/types/index.d.ts
generated
vendored
Normal file
32
node_modules/unctx/node_modules/estree-walker/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @typedef {import('estree').Node} Node
|
||||
* @typedef {import('./sync.js').SyncHandler} SyncHandler
|
||||
* @typedef {import('./async.js').AsyncHandler} AsyncHandler
|
||||
*/
|
||||
/**
|
||||
* @param {Node} ast
|
||||
* @param {{
|
||||
* enter?: SyncHandler
|
||||
* leave?: SyncHandler
|
||||
* }} walker
|
||||
* @returns {Node | null}
|
||||
*/
|
||||
export function walk(ast: Node, { enter, leave }: {
|
||||
enter?: SyncHandler;
|
||||
leave?: SyncHandler;
|
||||
}): Node | null;
|
||||
/**
|
||||
* @param {Node} ast
|
||||
* @param {{
|
||||
* enter?: AsyncHandler
|
||||
* leave?: AsyncHandler
|
||||
* }} walker
|
||||
* @returns {Promise<Node | null>}
|
||||
*/
|
||||
export function asyncWalk(ast: Node, { enter, leave }: {
|
||||
enter?: AsyncHandler;
|
||||
leave?: AsyncHandler;
|
||||
}): Promise<Node | null>;
|
||||
export type Node = import('estree').Node;
|
||||
export type SyncHandler = import('./sync.js').SyncHandler;
|
||||
export type AsyncHandler = import('./async.js').AsyncHandler;
|
||||
36
node_modules/unctx/node_modules/estree-walker/types/sync.d.ts
generated
vendored
Normal file
36
node_modules/unctx/node_modules/estree-walker/types/sync.d.ts
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @typedef { import('estree').Node} Node
|
||||
* @typedef { import('./walker.js').WalkerContext} WalkerContext
|
||||
* @typedef {(
|
||||
* this: WalkerContext,
|
||||
* node: Node,
|
||||
* parent: Node | null,
|
||||
* key: string | number | symbol | null | undefined,
|
||||
* index: number | null | undefined
|
||||
* ) => void} SyncHandler
|
||||
*/
|
||||
export class SyncWalker extends WalkerBase {
|
||||
/**
|
||||
*
|
||||
* @param {SyncHandler} [enter]
|
||||
* @param {SyncHandler} [leave]
|
||||
*/
|
||||
constructor(enter?: SyncHandler | undefined, leave?: SyncHandler | undefined);
|
||||
/** @type {SyncHandler | undefined} */
|
||||
enter: SyncHandler | undefined;
|
||||
/** @type {SyncHandler | undefined} */
|
||||
leave: SyncHandler | undefined;
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Node} node
|
||||
* @param {Parent | null} parent
|
||||
* @param {keyof Parent} [prop]
|
||||
* @param {number | null} [index]
|
||||
* @returns {Node | null}
|
||||
*/
|
||||
visit<Parent extends import("estree").Node>(node: Node, parent: Parent | null, prop?: keyof Parent | undefined, index?: number | null | undefined): Node | null;
|
||||
}
|
||||
export type Node = import('estree').Node;
|
||||
export type WalkerContext = import('./walker.js').WalkerContext;
|
||||
export type SyncHandler = (this: WalkerContext, node: Node, parent: Node | null, key: string | number | symbol | null | undefined, index: number | null | undefined) => void;
|
||||
import { WalkerBase } from "./walker.js";
|
||||
39
node_modules/unctx/node_modules/estree-walker/types/walker.d.ts
generated
vendored
Normal file
39
node_modules/unctx/node_modules/estree-walker/types/walker.d.ts
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @typedef { import('estree').Node} Node
|
||||
* @typedef {{
|
||||
* skip: () => void;
|
||||
* remove: () => void;
|
||||
* replace: (node: Node) => void;
|
||||
* }} WalkerContext
|
||||
*/
|
||||
export class WalkerBase {
|
||||
/** @type {boolean} */
|
||||
should_skip: boolean;
|
||||
/** @type {boolean} */
|
||||
should_remove: boolean;
|
||||
/** @type {Node | null} */
|
||||
replacement: Node | null;
|
||||
/** @type {WalkerContext} */
|
||||
context: WalkerContext;
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Parent | null | undefined} parent
|
||||
* @param {keyof Parent | null | undefined} prop
|
||||
* @param {number | null | undefined} index
|
||||
* @param {Node} node
|
||||
*/
|
||||
replace<Parent extends import("estree").Node>(parent: Parent | null | undefined, prop: keyof Parent | null | undefined, index: number | null | undefined, node: Node): void;
|
||||
/**
|
||||
* @template {Node} Parent
|
||||
* @param {Parent | null | undefined} parent
|
||||
* @param {keyof Parent | null | undefined} prop
|
||||
* @param {number | null | undefined} index
|
||||
*/
|
||||
remove<Parent_1 extends import("estree").Node>(parent: Parent_1 | null | undefined, prop: keyof Parent_1 | null | undefined, index: number | null | undefined): void;
|
||||
}
|
||||
export type Node = import('estree').Node;
|
||||
export type WalkerContext = {
|
||||
skip: () => void;
|
||||
remove: () => void;
|
||||
replace: (node: Node) => void;
|
||||
};
|
||||
21
node_modules/unctx/node_modules/unplugin/LICENSE
generated
vendored
Normal file
21
node_modules/unctx/node_modules/unplugin/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-PRESENT Nuxt Contrib
|
||||
|
||||
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.
|
||||
35
node_modules/unctx/node_modules/unplugin/README.md
generated
vendored
Normal file
35
node_modules/unctx/node_modules/unplugin/README.md
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# Unplugin
|
||||
|
||||
[![npm version][npm-version-src]][npm-version-href]
|
||||
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
||||
[![License][license-src]][license-href]
|
||||
|
||||
Unified plugin system for build tools.
|
||||
|
||||
Currently supports:
|
||||
|
||||
- [Vite](https://vite.dev/)
|
||||
- [Rollup](https://rollupjs.org/)
|
||||
- [Webpack](https://webpack.js.org/)
|
||||
- [esbuild](https://esbuild.github.io/)
|
||||
- [Rspack](https://www.rspack.dev/)
|
||||
- [Rolldown](https://rolldown.rs/)
|
||||
- [Farm](https://www.farmfe.org/)
|
||||
- And every framework built on top of them.
|
||||
|
||||
## Documentations
|
||||
|
||||
Learn more on the [Documentation](https://unplugin.unjs.io/)
|
||||
|
||||
## License
|
||||
|
||||
[MIT](./LICENSE) License © 2021-PRESENT Nuxt Contrib
|
||||
|
||||
<!-- Badges -->
|
||||
|
||||
[npm-version-src]: https://img.shields.io/npm/v/unplugin?style=flat&colorA=18181B&colorB=F0DB4F
|
||||
[npm-version-href]: https://npmjs.com/package/unplugin
|
||||
[npm-downloads-src]: https://img.shields.io/npm/dm/unplugin?style=flat&colorA=18181B&colorB=F0DB4F
|
||||
[npm-downloads-href]: https://npmjs.com/package/unplugin
|
||||
[license-src]: https://img.shields.io/github/license/unjs/unplugin.svg?style=flat&colorA=18181B&colorB=F0DB4F
|
||||
[license-href]: https://github.com/unjs/unplugin/blob/main/LICENSE
|
||||
169
node_modules/unctx/node_modules/unplugin/dist/context-CQfDPcdE.cjs
generated
vendored
Normal file
169
node_modules/unctx/node_modules/unplugin/dist/context-CQfDPcdE.cjs
generated
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
//#region rolldown:runtime
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
||||
key = keys[i];
|
||||
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
||||
get: ((k) => from[k]).bind(null, key),
|
||||
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
||||
});
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
||||
value: mod,
|
||||
enumerable: true
|
||||
}) : target, mod));
|
||||
|
||||
//#endregion
|
||||
let node_path = require("node:path");
|
||||
node_path = __toESM(node_path);
|
||||
let picomatch = require("picomatch");
|
||||
picomatch = __toESM(picomatch);
|
||||
let acorn = require("acorn");
|
||||
acorn = __toESM(acorn);
|
||||
|
||||
//#region src/utils/general.ts
|
||||
function toArray(array) {
|
||||
array = array || [];
|
||||
if (Array.isArray(array)) return array;
|
||||
return [array];
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/filter.ts
|
||||
const BACKSLASH_REGEX = /\\/g;
|
||||
function normalize(path) {
|
||||
return path.replace(BACKSLASH_REGEX, "/");
|
||||
}
|
||||
const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Z]:)?[/\\|])/i;
|
||||
function isAbsolute(path) {
|
||||
return ABSOLUTE_PATH_REGEX.test(path);
|
||||
}
|
||||
function getMatcherString(glob, cwd) {
|
||||
if (glob.startsWith("**") || isAbsolute(glob)) return normalize(glob);
|
||||
return normalize((0, node_path.resolve)(cwd, glob));
|
||||
}
|
||||
function patternToIdFilter(pattern) {
|
||||
if (pattern instanceof RegExp) return (id) => {
|
||||
const normalizedId = normalize(id);
|
||||
const result = pattern.test(normalizedId);
|
||||
pattern.lastIndex = 0;
|
||||
return result;
|
||||
};
|
||||
const matcher = (0, picomatch.default)(getMatcherString(pattern, process.cwd()), { dot: true });
|
||||
return (id) => {
|
||||
return matcher(normalize(id));
|
||||
};
|
||||
}
|
||||
function patternToCodeFilter(pattern) {
|
||||
if (pattern instanceof RegExp) return (code) => {
|
||||
const result = pattern.test(code);
|
||||
pattern.lastIndex = 0;
|
||||
return result;
|
||||
};
|
||||
return (code) => code.includes(pattern);
|
||||
}
|
||||
function createFilter(exclude, include) {
|
||||
if (!exclude && !include) return;
|
||||
return (input) => {
|
||||
if (exclude?.some((filter) => filter(input))) return false;
|
||||
if (include?.some((filter) => filter(input))) return true;
|
||||
return !(include && include.length > 0);
|
||||
};
|
||||
}
|
||||
function normalizeFilter(filter) {
|
||||
if (typeof filter === "string" || filter instanceof RegExp) return { include: [filter] };
|
||||
if (Array.isArray(filter)) return { include: filter };
|
||||
return {
|
||||
exclude: filter.exclude ? toArray(filter.exclude) : void 0,
|
||||
include: filter.include ? toArray(filter.include) : void 0
|
||||
};
|
||||
}
|
||||
function createIdFilter(filter) {
|
||||
if (!filter) return;
|
||||
const { exclude, include } = normalizeFilter(filter);
|
||||
const excludeFilter = exclude?.map(patternToIdFilter);
|
||||
const includeFilter = include?.map(patternToIdFilter);
|
||||
return createFilter(excludeFilter, includeFilter);
|
||||
}
|
||||
function createCodeFilter(filter) {
|
||||
if (!filter) return;
|
||||
const { exclude, include } = normalizeFilter(filter);
|
||||
const excludeFilter = exclude?.map(patternToCodeFilter);
|
||||
const includeFilter = include?.map(patternToCodeFilter);
|
||||
return createFilter(excludeFilter, includeFilter);
|
||||
}
|
||||
function createFilterForId(filter) {
|
||||
const filterFunction = createIdFilter(filter);
|
||||
return filterFunction ? (id) => !!filterFunction(id) : void 0;
|
||||
}
|
||||
function createFilterForTransform(idFilter, codeFilter) {
|
||||
if (!idFilter && !codeFilter) return;
|
||||
const idFilterFunction = createIdFilter(idFilter);
|
||||
const codeFilterFunction = createCodeFilter(codeFilter);
|
||||
return (id, code) => {
|
||||
let fallback = true;
|
||||
if (idFilterFunction) fallback &&= idFilterFunction(id);
|
||||
if (!fallback) return false;
|
||||
if (codeFilterFunction) fallback &&= codeFilterFunction(code);
|
||||
return fallback;
|
||||
};
|
||||
}
|
||||
function normalizeObjectHook(name, hook) {
|
||||
let handler;
|
||||
let filter;
|
||||
if (typeof hook === "function") handler = hook;
|
||||
else {
|
||||
handler = hook.handler;
|
||||
const hookFilter = hook.filter;
|
||||
if (name === "resolveId" || name === "load") filter = createFilterForId(hookFilter?.id);
|
||||
else filter = createFilterForTransform(hookFilter?.id, hookFilter?.code);
|
||||
}
|
||||
return {
|
||||
handler,
|
||||
filter: filter || (() => true)
|
||||
};
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/context.ts
|
||||
function parse(code, opts = {}) {
|
||||
return acorn.Parser.parse(code, {
|
||||
sourceType: "module",
|
||||
ecmaVersion: "latest",
|
||||
locations: true,
|
||||
...opts
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, '__toESM', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return __toESM;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'normalizeObjectHook', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return normalizeObjectHook;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'parse', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return parse;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'toArray', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return toArray;
|
||||
}
|
||||
});
|
||||
69
node_modules/unctx/node_modules/unplugin/dist/context-CrbHoDid.cjs
generated
vendored
Normal file
69
node_modules/unctx/node_modules/unplugin/dist/context-CrbHoDid.cjs
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
const require_context = require('./context-CQfDPcdE.cjs');
|
||||
let node_path = require("node:path");
|
||||
node_path = require_context.__toESM(node_path);
|
||||
let node_buffer = require("node:buffer");
|
||||
node_buffer = require_context.__toESM(node_buffer);
|
||||
|
||||
//#region src/rspack/context.ts
|
||||
function createBuildContext(compiler, compilation, loaderContext, inputSourceMap) {
|
||||
return {
|
||||
getNativeBuildContext() {
|
||||
return {
|
||||
framework: "rspack",
|
||||
compiler,
|
||||
compilation,
|
||||
loaderContext,
|
||||
inputSourceMap
|
||||
};
|
||||
},
|
||||
addWatchFile(file) {
|
||||
const cwd = process.cwd();
|
||||
compilation.fileDependencies.add((0, node_path.resolve)(cwd, file));
|
||||
},
|
||||
getWatchFiles() {
|
||||
return Array.from(compilation.fileDependencies);
|
||||
},
|
||||
parse: require_context.parse,
|
||||
emitFile(emittedFile) {
|
||||
const outFileName = emittedFile.fileName || emittedFile.name;
|
||||
if (emittedFile.source && outFileName) {
|
||||
const { sources } = compilation.compiler.webpack;
|
||||
compilation.emitAsset(outFileName, new sources.RawSource(typeof emittedFile.source === "string" ? emittedFile.source : node_buffer.Buffer.from(emittedFile.source)));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function createContext(loader) {
|
||||
return {
|
||||
error: (error) => loader.emitError(normalizeMessage(error)),
|
||||
warn: (message) => loader.emitWarning(normalizeMessage(message))
|
||||
};
|
||||
}
|
||||
function normalizeMessage(error) {
|
||||
const err = new Error(typeof error === "string" ? error : error.message);
|
||||
if (typeof error === "object") {
|
||||
err.stack = error.stack;
|
||||
err.cause = error.meta;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'createBuildContext', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return createBuildContext;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'createContext', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return createContext;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'normalizeMessage', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return normalizeMessage;
|
||||
}
|
||||
});
|
||||
120
node_modules/unctx/node_modules/unplugin/dist/context-Csj9j3eN.js
generated
vendored
Normal file
120
node_modules/unctx/node_modules/unplugin/dist/context-Csj9j3eN.js
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
import { resolve } from "node:path";
|
||||
import picomatch from "picomatch";
|
||||
import { Parser } from "acorn";
|
||||
|
||||
//#region src/utils/general.ts
|
||||
function toArray(array) {
|
||||
array = array || [];
|
||||
if (Array.isArray(array)) return array;
|
||||
return [array];
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/filter.ts
|
||||
const BACKSLASH_REGEX = /\\/g;
|
||||
function normalize$1(path$1) {
|
||||
return path$1.replace(BACKSLASH_REGEX, "/");
|
||||
}
|
||||
const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Z]:)?[/\\|])/i;
|
||||
function isAbsolute$1(path$1) {
|
||||
return ABSOLUTE_PATH_REGEX.test(path$1);
|
||||
}
|
||||
function getMatcherString(glob, cwd) {
|
||||
if (glob.startsWith("**") || isAbsolute$1(glob)) return normalize$1(glob);
|
||||
return normalize$1(resolve(cwd, glob));
|
||||
}
|
||||
function patternToIdFilter(pattern) {
|
||||
if (pattern instanceof RegExp) return (id) => {
|
||||
const normalizedId = normalize$1(id);
|
||||
const result = pattern.test(normalizedId);
|
||||
pattern.lastIndex = 0;
|
||||
return result;
|
||||
};
|
||||
const matcher = picomatch(getMatcherString(pattern, process.cwd()), { dot: true });
|
||||
return (id) => {
|
||||
return matcher(normalize$1(id));
|
||||
};
|
||||
}
|
||||
function patternToCodeFilter(pattern) {
|
||||
if (pattern instanceof RegExp) return (code) => {
|
||||
const result = pattern.test(code);
|
||||
pattern.lastIndex = 0;
|
||||
return result;
|
||||
};
|
||||
return (code) => code.includes(pattern);
|
||||
}
|
||||
function createFilter(exclude, include) {
|
||||
if (!exclude && !include) return;
|
||||
return (input) => {
|
||||
if (exclude?.some((filter) => filter(input))) return false;
|
||||
if (include?.some((filter) => filter(input))) return true;
|
||||
return !(include && include.length > 0);
|
||||
};
|
||||
}
|
||||
function normalizeFilter(filter) {
|
||||
if (typeof filter === "string" || filter instanceof RegExp) return { include: [filter] };
|
||||
if (Array.isArray(filter)) return { include: filter };
|
||||
return {
|
||||
exclude: filter.exclude ? toArray(filter.exclude) : void 0,
|
||||
include: filter.include ? toArray(filter.include) : void 0
|
||||
};
|
||||
}
|
||||
function createIdFilter(filter) {
|
||||
if (!filter) return;
|
||||
const { exclude, include } = normalizeFilter(filter);
|
||||
const excludeFilter = exclude?.map(patternToIdFilter);
|
||||
const includeFilter = include?.map(patternToIdFilter);
|
||||
return createFilter(excludeFilter, includeFilter);
|
||||
}
|
||||
function createCodeFilter(filter) {
|
||||
if (!filter) return;
|
||||
const { exclude, include } = normalizeFilter(filter);
|
||||
const excludeFilter = exclude?.map(patternToCodeFilter);
|
||||
const includeFilter = include?.map(patternToCodeFilter);
|
||||
return createFilter(excludeFilter, includeFilter);
|
||||
}
|
||||
function createFilterForId(filter) {
|
||||
const filterFunction = createIdFilter(filter);
|
||||
return filterFunction ? (id) => !!filterFunction(id) : void 0;
|
||||
}
|
||||
function createFilterForTransform(idFilter, codeFilter) {
|
||||
if (!idFilter && !codeFilter) return;
|
||||
const idFilterFunction = createIdFilter(idFilter);
|
||||
const codeFilterFunction = createCodeFilter(codeFilter);
|
||||
return (id, code) => {
|
||||
let fallback = true;
|
||||
if (idFilterFunction) fallback &&= idFilterFunction(id);
|
||||
if (!fallback) return false;
|
||||
if (codeFilterFunction) fallback &&= codeFilterFunction(code);
|
||||
return fallback;
|
||||
};
|
||||
}
|
||||
function normalizeObjectHook(name, hook) {
|
||||
let handler;
|
||||
let filter;
|
||||
if (typeof hook === "function") handler = hook;
|
||||
else {
|
||||
handler = hook.handler;
|
||||
const hookFilter = hook.filter;
|
||||
if (name === "resolveId" || name === "load") filter = createFilterForId(hookFilter?.id);
|
||||
else filter = createFilterForTransform(hookFilter?.id, hookFilter?.code);
|
||||
}
|
||||
return {
|
||||
handler,
|
||||
filter: filter || (() => true)
|
||||
};
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/context.ts
|
||||
function parse(code, opts = {}) {
|
||||
return Parser.parse(code, {
|
||||
sourceType: "module",
|
||||
ecmaVersion: "latest",
|
||||
locations: true,
|
||||
...opts
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { normalizeObjectHook as n, toArray as r, parse as t };
|
||||
92
node_modules/unctx/node_modules/unplugin/dist/context-D7WFmOmt.cjs
generated
vendored
Normal file
92
node_modules/unctx/node_modules/unplugin/dist/context-D7WFmOmt.cjs
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
const require_context = require('./context-CQfDPcdE.cjs');
|
||||
let node_path = require("node:path");
|
||||
node_path = require_context.__toESM(node_path);
|
||||
let node_buffer = require("node:buffer");
|
||||
node_buffer = require_context.__toESM(node_buffer);
|
||||
let node_process = require("node:process");
|
||||
node_process = require_context.__toESM(node_process);
|
||||
let node_module = require("node:module");
|
||||
node_module = require_context.__toESM(node_module);
|
||||
|
||||
//#region src/webpack/context.ts
|
||||
function contextOptionsFromCompilation(compilation) {
|
||||
return {
|
||||
addWatchFile(file) {
|
||||
(compilation.fileDependencies ?? compilation.compilationDependencies).add(file);
|
||||
},
|
||||
getWatchFiles() {
|
||||
return Array.from(compilation.fileDependencies ?? compilation.compilationDependencies);
|
||||
}
|
||||
};
|
||||
}
|
||||
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
||||
function getSource(fileSource) {
|
||||
return new (require$1("webpack")).sources.RawSource(typeof fileSource === "string" ? fileSource : node_buffer.Buffer.from(fileSource.buffer));
|
||||
}
|
||||
function createBuildContext(options, compiler, compilation, loaderContext, inputSourceMap) {
|
||||
return {
|
||||
parse: require_context.parse,
|
||||
addWatchFile(id) {
|
||||
options.addWatchFile((0, node_path.resolve)(node_process.default.cwd(), id));
|
||||
},
|
||||
emitFile(emittedFile) {
|
||||
const outFileName = emittedFile.fileName || emittedFile.name;
|
||||
if (emittedFile.source && outFileName) {
|
||||
if (!compilation) throw new Error("unplugin/webpack: emitFile outside supported hooks (buildStart, buildEnd, load, transform, watchChange)");
|
||||
compilation.emitAsset(outFileName, getSource(emittedFile.source));
|
||||
}
|
||||
},
|
||||
getWatchFiles() {
|
||||
return options.getWatchFiles();
|
||||
},
|
||||
getNativeBuildContext() {
|
||||
return {
|
||||
framework: "webpack",
|
||||
compiler,
|
||||
compilation,
|
||||
loaderContext,
|
||||
inputSourceMap
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
function createContext(loader) {
|
||||
return {
|
||||
error: (error) => loader.emitError(normalizeMessage(error)),
|
||||
warn: (message) => loader.emitWarning(normalizeMessage(message))
|
||||
};
|
||||
}
|
||||
function normalizeMessage(error) {
|
||||
const err = new Error(typeof error === "string" ? error : error.message);
|
||||
if (typeof error === "object") {
|
||||
err.stack = error.stack;
|
||||
err.cause = error.meta;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'contextOptionsFromCompilation', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return contextOptionsFromCompilation;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'createBuildContext', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return createBuildContext;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'createContext', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return createContext;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'normalizeMessage', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return normalizeMessage;
|
||||
}
|
||||
});
|
||||
50
node_modules/unctx/node_modules/unplugin/dist/context-DkYlx1xL.js
generated
vendored
Normal file
50
node_modules/unctx/node_modules/unplugin/dist/context-DkYlx1xL.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import { t as parse } from "./context-Csj9j3eN.js";
|
||||
import { resolve } from "node:path";
|
||||
import { Buffer } from "node:buffer";
|
||||
|
||||
//#region src/rspack/context.ts
|
||||
function createBuildContext(compiler, compilation, loaderContext, inputSourceMap) {
|
||||
return {
|
||||
getNativeBuildContext() {
|
||||
return {
|
||||
framework: "rspack",
|
||||
compiler,
|
||||
compilation,
|
||||
loaderContext,
|
||||
inputSourceMap
|
||||
};
|
||||
},
|
||||
addWatchFile(file) {
|
||||
const cwd = process.cwd();
|
||||
compilation.fileDependencies.add(resolve(cwd, file));
|
||||
},
|
||||
getWatchFiles() {
|
||||
return Array.from(compilation.fileDependencies);
|
||||
},
|
||||
parse,
|
||||
emitFile(emittedFile) {
|
||||
const outFileName = emittedFile.fileName || emittedFile.name;
|
||||
if (emittedFile.source && outFileName) {
|
||||
const { sources } = compilation.compiler.webpack;
|
||||
compilation.emitAsset(outFileName, new sources.RawSource(typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source)));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function createContext(loader) {
|
||||
return {
|
||||
error: (error) => loader.emitError(normalizeMessage(error)),
|
||||
warn: (message) => loader.emitWarning(normalizeMessage(message))
|
||||
};
|
||||
}
|
||||
function normalizeMessage(error) {
|
||||
const err = new Error(typeof error === "string" ? error : error.message);
|
||||
if (typeof error === "object") {
|
||||
err.stack = error.stack;
|
||||
err.cause = error.meta;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { createContext as n, normalizeMessage as r, createBuildContext as t };
|
||||
65
node_modules/unctx/node_modules/unplugin/dist/context-OCFO8EW1.js
generated
vendored
Normal file
65
node_modules/unctx/node_modules/unplugin/dist/context-OCFO8EW1.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
import { t as parse } from "./context-Csj9j3eN.js";
|
||||
import { createRequire } from "node:module";
|
||||
import { resolve } from "node:path";
|
||||
import { Buffer } from "node:buffer";
|
||||
import process from "node:process";
|
||||
|
||||
//#region src/webpack/context.ts
|
||||
function contextOptionsFromCompilation(compilation) {
|
||||
return {
|
||||
addWatchFile(file) {
|
||||
(compilation.fileDependencies ?? compilation.compilationDependencies).add(file);
|
||||
},
|
||||
getWatchFiles() {
|
||||
return Array.from(compilation.fileDependencies ?? compilation.compilationDependencies);
|
||||
}
|
||||
};
|
||||
}
|
||||
const require = createRequire(import.meta.url);
|
||||
function getSource(fileSource) {
|
||||
return new (require("webpack")).sources.RawSource(typeof fileSource === "string" ? fileSource : Buffer.from(fileSource.buffer));
|
||||
}
|
||||
function createBuildContext(options, compiler, compilation, loaderContext, inputSourceMap) {
|
||||
return {
|
||||
parse,
|
||||
addWatchFile(id) {
|
||||
options.addWatchFile(resolve(process.cwd(), id));
|
||||
},
|
||||
emitFile(emittedFile) {
|
||||
const outFileName = emittedFile.fileName || emittedFile.name;
|
||||
if (emittedFile.source && outFileName) {
|
||||
if (!compilation) throw new Error("unplugin/webpack: emitFile outside supported hooks (buildStart, buildEnd, load, transform, watchChange)");
|
||||
compilation.emitAsset(outFileName, getSource(emittedFile.source));
|
||||
}
|
||||
},
|
||||
getWatchFiles() {
|
||||
return options.getWatchFiles();
|
||||
},
|
||||
getNativeBuildContext() {
|
||||
return {
|
||||
framework: "webpack",
|
||||
compiler,
|
||||
compilation,
|
||||
loaderContext,
|
||||
inputSourceMap
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
function createContext(loader) {
|
||||
return {
|
||||
error: (error) => loader.emitError(normalizeMessage(error)),
|
||||
warn: (message) => loader.emitWarning(normalizeMessage(message))
|
||||
};
|
||||
}
|
||||
function normalizeMessage(error) {
|
||||
const err = new Error(typeof error === "string" ? error : error.message);
|
||||
if (typeof error === "object") {
|
||||
err.stack = error.stack;
|
||||
err.cause = error.meta;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { normalizeMessage as i, createBuildContext as n, createContext as r, contextOptionsFromCompilation as t };
|
||||
1013
node_modules/unctx/node_modules/unplugin/dist/index.cjs
generated
vendored
Normal file
1013
node_modules/unctx/node_modules/unplugin/dist/index.cjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
198
node_modules/unctx/node_modules/unplugin/dist/index.d.cts
generated
vendored
Normal file
198
node_modules/unctx/node_modules/unplugin/dist/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
import { CompilationContext, JsPlugin } from "@farmfe/core";
|
||||
import { Compilation, Compiler as RspackCompiler, LoaderContext, RspackPluginInstance } from "@rspack/core";
|
||||
import { BuildOptions, Loader, Plugin as EsbuildPlugin, PluginBuild } from "esbuild";
|
||||
import { Plugin as RolldownPlugin } from "rolldown";
|
||||
import { AstNode, EmittedAsset, Plugin as RollupPlugin, PluginContextMeta, SourceMapInput } from "rollup";
|
||||
import { Plugin as UnloaderPlugin } from "unloader";
|
||||
import { Plugin as VitePlugin } from "vite";
|
||||
import { Compilation as Compilation$1, Compiler as WebpackCompiler, LoaderContext as LoaderContext$1, WebpackPluginInstance } from "webpack";
|
||||
import VirtualModulesPlugin from "webpack-virtual-modules";
|
||||
|
||||
//#region src/types.d.ts
|
||||
type Thenable<T> = T | Promise<T>;
|
||||
/**
|
||||
* Null or whatever
|
||||
*/
|
||||
type Nullable<T> = T | null | undefined;
|
||||
/**
|
||||
* Array, or not yet
|
||||
*/
|
||||
type Arrayable<T> = T | Array<T>;
|
||||
interface SourceMapCompact {
|
||||
file?: string | undefined;
|
||||
mappings: string;
|
||||
names: string[];
|
||||
sourceRoot?: string | undefined;
|
||||
sources: string[];
|
||||
sourcesContent?: (string | null)[] | undefined;
|
||||
version: number;
|
||||
}
|
||||
type TransformResult = string | {
|
||||
code: string;
|
||||
map?: SourceMapInput | SourceMapCompact | null | undefined;
|
||||
} | null | undefined | void;
|
||||
interface ExternalIdResult {
|
||||
id: string;
|
||||
external?: boolean | undefined;
|
||||
}
|
||||
type NativeBuildContext = {
|
||||
framework: "webpack";
|
||||
compiler: WebpackCompiler;
|
||||
compilation?: Compilation$1 | undefined;
|
||||
loaderContext?: LoaderContext$1<{
|
||||
unpluginName: string;
|
||||
}> | undefined;
|
||||
inputSourceMap?: any;
|
||||
} | {
|
||||
framework: "esbuild";
|
||||
build: PluginBuild;
|
||||
} | {
|
||||
framework: "rspack";
|
||||
compiler: RspackCompiler;
|
||||
compilation: Compilation;
|
||||
loaderContext?: LoaderContext | undefined;
|
||||
inputSourceMap?: any;
|
||||
} | {
|
||||
framework: "farm";
|
||||
context: CompilationContext;
|
||||
};
|
||||
interface UnpluginBuildContext {
|
||||
addWatchFile: (id: string) => void;
|
||||
emitFile: (emittedFile: EmittedAsset) => void;
|
||||
getWatchFiles: () => string[];
|
||||
parse: (input: string, options?: any) => AstNode;
|
||||
getNativeBuildContext?: (() => NativeBuildContext) | undefined;
|
||||
}
|
||||
type StringOrRegExp = string | RegExp;
|
||||
type FilterPattern = Arrayable<StringOrRegExp>;
|
||||
type StringFilter = FilterPattern | {
|
||||
include?: FilterPattern | undefined;
|
||||
exclude?: FilterPattern | undefined;
|
||||
};
|
||||
interface HookFilter {
|
||||
id?: StringFilter | undefined;
|
||||
code?: StringFilter | undefined;
|
||||
}
|
||||
interface ObjectHook<T extends HookFnMap[keyof HookFnMap], F extends keyof HookFilter> {
|
||||
filter?: Pick<HookFilter, F> | undefined;
|
||||
handler: T;
|
||||
}
|
||||
type Hook<T extends HookFnMap[keyof HookFnMap], F extends keyof HookFilter> = T | ObjectHook<T, F>;
|
||||
interface HookFnMap {
|
||||
buildStart: (this: UnpluginBuildContext) => Thenable<void>;
|
||||
buildEnd: (this: UnpluginBuildContext) => Thenable<void>;
|
||||
transform: (this: UnpluginBuildContext & UnpluginContext, code: string, id: string) => Thenable<TransformResult>;
|
||||
load: (this: UnpluginBuildContext & UnpluginContext, id: string) => Thenable<TransformResult>;
|
||||
resolveId: (this: UnpluginBuildContext & UnpluginContext, id: string, importer: string | undefined, options: {
|
||||
isEntry: boolean;
|
||||
}) => Thenable<string | ExternalIdResult | null | undefined>;
|
||||
writeBundle: (this: void) => Thenable<void>;
|
||||
}
|
||||
interface UnpluginOptions {
|
||||
name: string;
|
||||
enforce?: "post" | "pre" | undefined;
|
||||
buildStart?: HookFnMap["buildStart"] | undefined;
|
||||
buildEnd?: HookFnMap["buildEnd"] | undefined;
|
||||
transform?: Hook<HookFnMap["transform"], "code" | "id"> | undefined;
|
||||
load?: Hook<HookFnMap["load"], "id"> | undefined;
|
||||
resolveId?: Hook<HookFnMap["resolveId"], "id"> | undefined;
|
||||
writeBundle?: HookFnMap["writeBundle"] | undefined;
|
||||
watchChange?: ((this: UnpluginBuildContext, id: string, change: {
|
||||
event: "create" | "update" | "delete";
|
||||
}) => void) | undefined;
|
||||
/**
|
||||
* Custom predicate function to filter modules to be loaded.
|
||||
* When omitted, all modules will be included (might have potential perf impact on Webpack).
|
||||
*
|
||||
* @deprecated Use `load.filter` instead.
|
||||
*/
|
||||
loadInclude?: ((id: string) => boolean | null | undefined) | undefined;
|
||||
/**
|
||||
* Custom predicate function to filter modules to be transformed.
|
||||
* When omitted, all modules will be included (might have potential perf impact on Webpack).
|
||||
*
|
||||
* @deprecated Use `transform.filter` instead.
|
||||
*/
|
||||
transformInclude?: ((id: string) => boolean | null | undefined) | undefined;
|
||||
rollup?: Partial<RollupPlugin> | undefined;
|
||||
webpack?: ((compiler: WebpackCompiler) => void) | undefined;
|
||||
rspack?: ((compiler: RspackCompiler) => void) | undefined;
|
||||
vite?: Partial<VitePlugin> | undefined;
|
||||
unloader?: Partial<UnloaderPlugin> | undefined;
|
||||
rolldown?: Partial<RolldownPlugin> | undefined;
|
||||
esbuild?: {
|
||||
onResolveFilter?: RegExp | undefined;
|
||||
onLoadFilter?: RegExp | undefined;
|
||||
loader?: Loader | ((code: string, id: string) => Loader) | undefined;
|
||||
setup?: ((build: PluginBuild) => void | Promise<void>) | undefined;
|
||||
config?: ((options: BuildOptions) => void) | undefined;
|
||||
} | undefined;
|
||||
farm?: Partial<JsPlugin> | undefined;
|
||||
}
|
||||
interface ResolvedUnpluginOptions extends UnpluginOptions {
|
||||
__vfs?: VirtualModulesPlugin | undefined;
|
||||
__vfsModules?: Map<string, Promise<unknown>> | Set<string> | undefined;
|
||||
__virtualModulePrefix: string;
|
||||
}
|
||||
type UnpluginFactory<UserOptions, Nested extends boolean = boolean> = (options: UserOptions, meta: UnpluginContextMeta) => Nested extends true ? Array<UnpluginOptions> : UnpluginOptions;
|
||||
type UnpluginFactoryOutput<UserOptions, Return> = undefined extends UserOptions ? (options?: UserOptions | undefined) => Return : (options: UserOptions) => Return;
|
||||
interface UnpluginInstance<UserOptions, Nested extends boolean = boolean> {
|
||||
rollup: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<RollupPlugin> : RollupPlugin>;
|
||||
vite: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<VitePlugin> : VitePlugin>;
|
||||
rolldown: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<RolldownPlugin> : RolldownPlugin>;
|
||||
webpack: UnpluginFactoryOutput<UserOptions, WebpackPluginInstance>;
|
||||
rspack: UnpluginFactoryOutput<UserOptions, RspackPluginInstance>;
|
||||
esbuild: UnpluginFactoryOutput<UserOptions, EsbuildPlugin>;
|
||||
unloader: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<UnloaderPlugin> : UnloaderPlugin>;
|
||||
farm: UnpluginFactoryOutput<UserOptions, JsPlugin>;
|
||||
raw: UnpluginFactory<UserOptions, Nested>;
|
||||
}
|
||||
type UnpluginContextMeta = Partial<PluginContextMeta> & ({
|
||||
framework: "rollup" | "vite" | "rolldown" | "farm" | "unloader";
|
||||
} | {
|
||||
framework: "webpack";
|
||||
webpack: {
|
||||
compiler: WebpackCompiler;
|
||||
};
|
||||
} | {
|
||||
framework: "esbuild";
|
||||
/** Set the host plugin name of esbuild when returning multiple plugins */
|
||||
esbuildHostName?: string | undefined;
|
||||
} | {
|
||||
framework: "rspack";
|
||||
rspack: {
|
||||
compiler: RspackCompiler;
|
||||
};
|
||||
});
|
||||
interface UnpluginMessage {
|
||||
name?: string | undefined;
|
||||
id?: string | undefined;
|
||||
message: string;
|
||||
stack?: string | undefined;
|
||||
code?: string | undefined;
|
||||
plugin?: string | undefined;
|
||||
pluginCode?: unknown | undefined;
|
||||
loc?: {
|
||||
column: number;
|
||||
file?: string | undefined;
|
||||
line: number;
|
||||
} | undefined;
|
||||
meta?: any;
|
||||
}
|
||||
interface UnpluginContext {
|
||||
error: (message: string | UnpluginMessage) => void;
|
||||
warn: (message: string | UnpluginMessage) => void;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/define.d.ts
|
||||
declare function createUnplugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions, Nested>;
|
||||
declare function createEsbuildPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["esbuild"];
|
||||
declare function createRollupPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["rollup"];
|
||||
declare function createVitePlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["vite"];
|
||||
declare function createRolldownPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["rolldown"];
|
||||
declare function createWebpackPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["webpack"];
|
||||
declare function createRspackPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["rspack"];
|
||||
declare function createFarmPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["farm"];
|
||||
declare function createUnloaderPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["unloader"];
|
||||
//#endregion
|
||||
export { Arrayable, type EsbuildPlugin, ExternalIdResult, FilterPattern, Hook, HookFilter, HookFnMap, NativeBuildContext, Nullable, ObjectHook, ResolvedUnpluginOptions, type RolldownPlugin, type RollupPlugin, type RspackCompiler, type RspackPluginInstance, SourceMapCompact, StringFilter, StringOrRegExp, Thenable, TransformResult, type UnloaderPlugin, UnpluginBuildContext, UnpluginContext, UnpluginContextMeta, UnpluginFactory, UnpluginFactoryOutput, UnpluginInstance, UnpluginMessage, UnpluginOptions, type VitePlugin, type WebpackCompiler, type WebpackPluginInstance, createEsbuildPlugin, createFarmPlugin, createRolldownPlugin, createRollupPlugin, createRspackPlugin, createUnloaderPlugin, createUnplugin, createVitePlugin, createWebpackPlugin };
|
||||
198
node_modules/unctx/node_modules/unplugin/dist/index.d.ts
generated
vendored
Normal file
198
node_modules/unctx/node_modules/unplugin/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
import VirtualModulesPlugin from "webpack-virtual-modules";
|
||||
import { CompilationContext, JsPlugin } from "@farmfe/core";
|
||||
import { Compilation, Compiler as RspackCompiler, LoaderContext, RspackPluginInstance } from "@rspack/core";
|
||||
import { BuildOptions, Loader, Plugin as EsbuildPlugin, PluginBuild } from "esbuild";
|
||||
import { Plugin as RolldownPlugin } from "rolldown";
|
||||
import { AstNode, EmittedAsset, Plugin as RollupPlugin, PluginContextMeta, SourceMapInput } from "rollup";
|
||||
import { Plugin as UnloaderPlugin } from "unloader";
|
||||
import { Plugin as VitePlugin } from "vite";
|
||||
import { Compilation as Compilation$1, Compiler as WebpackCompiler, LoaderContext as LoaderContext$1, WebpackPluginInstance } from "webpack";
|
||||
|
||||
//#region src/types.d.ts
|
||||
type Thenable<T> = T | Promise<T>;
|
||||
/**
|
||||
* Null or whatever
|
||||
*/
|
||||
type Nullable<T> = T | null | undefined;
|
||||
/**
|
||||
* Array, or not yet
|
||||
*/
|
||||
type Arrayable<T> = T | Array<T>;
|
||||
interface SourceMapCompact {
|
||||
file?: string | undefined;
|
||||
mappings: string;
|
||||
names: string[];
|
||||
sourceRoot?: string | undefined;
|
||||
sources: string[];
|
||||
sourcesContent?: (string | null)[] | undefined;
|
||||
version: number;
|
||||
}
|
||||
type TransformResult = string | {
|
||||
code: string;
|
||||
map?: SourceMapInput | SourceMapCompact | null | undefined;
|
||||
} | null | undefined | void;
|
||||
interface ExternalIdResult {
|
||||
id: string;
|
||||
external?: boolean | undefined;
|
||||
}
|
||||
type NativeBuildContext = {
|
||||
framework: "webpack";
|
||||
compiler: WebpackCompiler;
|
||||
compilation?: Compilation$1 | undefined;
|
||||
loaderContext?: LoaderContext$1<{
|
||||
unpluginName: string;
|
||||
}> | undefined;
|
||||
inputSourceMap?: any;
|
||||
} | {
|
||||
framework: "esbuild";
|
||||
build: PluginBuild;
|
||||
} | {
|
||||
framework: "rspack";
|
||||
compiler: RspackCompiler;
|
||||
compilation: Compilation;
|
||||
loaderContext?: LoaderContext | undefined;
|
||||
inputSourceMap?: any;
|
||||
} | {
|
||||
framework: "farm";
|
||||
context: CompilationContext;
|
||||
};
|
||||
interface UnpluginBuildContext {
|
||||
addWatchFile: (id: string) => void;
|
||||
emitFile: (emittedFile: EmittedAsset) => void;
|
||||
getWatchFiles: () => string[];
|
||||
parse: (input: string, options?: any) => AstNode;
|
||||
getNativeBuildContext?: (() => NativeBuildContext) | undefined;
|
||||
}
|
||||
type StringOrRegExp = string | RegExp;
|
||||
type FilterPattern = Arrayable<StringOrRegExp>;
|
||||
type StringFilter = FilterPattern | {
|
||||
include?: FilterPattern | undefined;
|
||||
exclude?: FilterPattern | undefined;
|
||||
};
|
||||
interface HookFilter {
|
||||
id?: StringFilter | undefined;
|
||||
code?: StringFilter | undefined;
|
||||
}
|
||||
interface ObjectHook<T extends HookFnMap[keyof HookFnMap], F extends keyof HookFilter> {
|
||||
filter?: Pick<HookFilter, F> | undefined;
|
||||
handler: T;
|
||||
}
|
||||
type Hook<T extends HookFnMap[keyof HookFnMap], F extends keyof HookFilter> = T | ObjectHook<T, F>;
|
||||
interface HookFnMap {
|
||||
buildStart: (this: UnpluginBuildContext) => Thenable<void>;
|
||||
buildEnd: (this: UnpluginBuildContext) => Thenable<void>;
|
||||
transform: (this: UnpluginBuildContext & UnpluginContext, code: string, id: string) => Thenable<TransformResult>;
|
||||
load: (this: UnpluginBuildContext & UnpluginContext, id: string) => Thenable<TransformResult>;
|
||||
resolveId: (this: UnpluginBuildContext & UnpluginContext, id: string, importer: string | undefined, options: {
|
||||
isEntry: boolean;
|
||||
}) => Thenable<string | ExternalIdResult | null | undefined>;
|
||||
writeBundle: (this: void) => Thenable<void>;
|
||||
}
|
||||
interface UnpluginOptions {
|
||||
name: string;
|
||||
enforce?: "post" | "pre" | undefined;
|
||||
buildStart?: HookFnMap["buildStart"] | undefined;
|
||||
buildEnd?: HookFnMap["buildEnd"] | undefined;
|
||||
transform?: Hook<HookFnMap["transform"], "code" | "id"> | undefined;
|
||||
load?: Hook<HookFnMap["load"], "id"> | undefined;
|
||||
resolveId?: Hook<HookFnMap["resolveId"], "id"> | undefined;
|
||||
writeBundle?: HookFnMap["writeBundle"] | undefined;
|
||||
watchChange?: ((this: UnpluginBuildContext, id: string, change: {
|
||||
event: "create" | "update" | "delete";
|
||||
}) => void) | undefined;
|
||||
/**
|
||||
* Custom predicate function to filter modules to be loaded.
|
||||
* When omitted, all modules will be included (might have potential perf impact on Webpack).
|
||||
*
|
||||
* @deprecated Use `load.filter` instead.
|
||||
*/
|
||||
loadInclude?: ((id: string) => boolean | null | undefined) | undefined;
|
||||
/**
|
||||
* Custom predicate function to filter modules to be transformed.
|
||||
* When omitted, all modules will be included (might have potential perf impact on Webpack).
|
||||
*
|
||||
* @deprecated Use `transform.filter` instead.
|
||||
*/
|
||||
transformInclude?: ((id: string) => boolean | null | undefined) | undefined;
|
||||
rollup?: Partial<RollupPlugin> | undefined;
|
||||
webpack?: ((compiler: WebpackCompiler) => void) | undefined;
|
||||
rspack?: ((compiler: RspackCompiler) => void) | undefined;
|
||||
vite?: Partial<VitePlugin> | undefined;
|
||||
unloader?: Partial<UnloaderPlugin> | undefined;
|
||||
rolldown?: Partial<RolldownPlugin> | undefined;
|
||||
esbuild?: {
|
||||
onResolveFilter?: RegExp | undefined;
|
||||
onLoadFilter?: RegExp | undefined;
|
||||
loader?: Loader | ((code: string, id: string) => Loader) | undefined;
|
||||
setup?: ((build: PluginBuild) => void | Promise<void>) | undefined;
|
||||
config?: ((options: BuildOptions) => void) | undefined;
|
||||
} | undefined;
|
||||
farm?: Partial<JsPlugin> | undefined;
|
||||
}
|
||||
interface ResolvedUnpluginOptions extends UnpluginOptions {
|
||||
__vfs?: VirtualModulesPlugin | undefined;
|
||||
__vfsModules?: Map<string, Promise<unknown>> | Set<string> | undefined;
|
||||
__virtualModulePrefix: string;
|
||||
}
|
||||
type UnpluginFactory<UserOptions, Nested extends boolean = boolean> = (options: UserOptions, meta: UnpluginContextMeta) => Nested extends true ? Array<UnpluginOptions> : UnpluginOptions;
|
||||
type UnpluginFactoryOutput<UserOptions, Return> = undefined extends UserOptions ? (options?: UserOptions | undefined) => Return : (options: UserOptions) => Return;
|
||||
interface UnpluginInstance<UserOptions, Nested extends boolean = boolean> {
|
||||
rollup: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<RollupPlugin> : RollupPlugin>;
|
||||
vite: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<VitePlugin> : VitePlugin>;
|
||||
rolldown: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<RolldownPlugin> : RolldownPlugin>;
|
||||
webpack: UnpluginFactoryOutput<UserOptions, WebpackPluginInstance>;
|
||||
rspack: UnpluginFactoryOutput<UserOptions, RspackPluginInstance>;
|
||||
esbuild: UnpluginFactoryOutput<UserOptions, EsbuildPlugin>;
|
||||
unloader: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<UnloaderPlugin> : UnloaderPlugin>;
|
||||
farm: UnpluginFactoryOutput<UserOptions, JsPlugin>;
|
||||
raw: UnpluginFactory<UserOptions, Nested>;
|
||||
}
|
||||
type UnpluginContextMeta = Partial<PluginContextMeta> & ({
|
||||
framework: "rollup" | "vite" | "rolldown" | "farm" | "unloader";
|
||||
} | {
|
||||
framework: "webpack";
|
||||
webpack: {
|
||||
compiler: WebpackCompiler;
|
||||
};
|
||||
} | {
|
||||
framework: "esbuild";
|
||||
/** Set the host plugin name of esbuild when returning multiple plugins */
|
||||
esbuildHostName?: string | undefined;
|
||||
} | {
|
||||
framework: "rspack";
|
||||
rspack: {
|
||||
compiler: RspackCompiler;
|
||||
};
|
||||
});
|
||||
interface UnpluginMessage {
|
||||
name?: string | undefined;
|
||||
id?: string | undefined;
|
||||
message: string;
|
||||
stack?: string | undefined;
|
||||
code?: string | undefined;
|
||||
plugin?: string | undefined;
|
||||
pluginCode?: unknown | undefined;
|
||||
loc?: {
|
||||
column: number;
|
||||
file?: string | undefined;
|
||||
line: number;
|
||||
} | undefined;
|
||||
meta?: any;
|
||||
}
|
||||
interface UnpluginContext {
|
||||
error: (message: string | UnpluginMessage) => void;
|
||||
warn: (message: string | UnpluginMessage) => void;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/define.d.ts
|
||||
declare function createUnplugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions, Nested>;
|
||||
declare function createEsbuildPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["esbuild"];
|
||||
declare function createRollupPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["rollup"];
|
||||
declare function createVitePlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["vite"];
|
||||
declare function createRolldownPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["rolldown"];
|
||||
declare function createWebpackPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["webpack"];
|
||||
declare function createRspackPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["rspack"];
|
||||
declare function createFarmPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["farm"];
|
||||
declare function createUnloaderPlugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions>["unloader"];
|
||||
//#endregion
|
||||
export { Arrayable, type EsbuildPlugin, ExternalIdResult, FilterPattern, Hook, HookFilter, HookFnMap, NativeBuildContext, Nullable, ObjectHook, ResolvedUnpluginOptions, type RolldownPlugin, type RollupPlugin, type RspackCompiler, type RspackPluginInstance, SourceMapCompact, StringFilter, StringOrRegExp, Thenable, TransformResult, type UnloaderPlugin, UnpluginBuildContext, UnpluginContext, UnpluginContextMeta, UnpluginFactory, UnpluginFactoryOutput, UnpluginInstance, UnpluginMessage, UnpluginOptions, type VitePlugin, type WebpackCompiler, type WebpackPluginInstance, createEsbuildPlugin, createFarmPlugin, createRolldownPlugin, createRollupPlugin, createRspackPlugin, createUnloaderPlugin, createUnplugin, createVitePlugin, createWebpackPlugin };
|
||||
1005
node_modules/unctx/node_modules/unplugin/dist/index.js
generated
vendored
Normal file
1005
node_modules/unctx/node_modules/unplugin/dist/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
27
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/load.cjs
generated
vendored
Normal file
27
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/load.cjs
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
const require_context = require('../../context-CQfDPcdE.cjs');
|
||||
const require_webpack_like = require('../../webpack-like-DDVwPJ4e.cjs');
|
||||
const require_context$1 = require('../../context-CrbHoDid.cjs');
|
||||
const require_utils = require('../../utils-CJMEEaD7.cjs');
|
||||
|
||||
//#region src/rspack/loaders/load.ts
|
||||
async function load(source, map) {
|
||||
const callback = this.async();
|
||||
const { plugin } = this.query;
|
||||
let id = this.resource;
|
||||
if (!plugin?.load || !id) return callback(null, source, map);
|
||||
if (require_utils.isVirtualModuleId(id, plugin)) id = require_utils.decodeVirtualModuleId(id, plugin);
|
||||
const context = require_context$1.createContext(this);
|
||||
const { handler } = require_context.normalizeObjectHook("load", plugin.load);
|
||||
try {
|
||||
const res = await handler.call(Object.assign({}, this._compilation && require_context$1.createBuildContext(this._compiler, this._compilation, this), context), require_webpack_like.normalizeAbsolutePath(id));
|
||||
if (res == null) callback(null, source, map);
|
||||
else if (typeof res !== "string") callback(null, res.code, res.map ?? map);
|
||||
else callback(null, res, map);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) callback(error);
|
||||
else callback(new Error(String(error)));
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
module.exports = load;
|
||||
5
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/load.d.cts
generated
vendored
Normal file
5
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/load.d.cts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { LoaderContext } from "@rspack/core";
|
||||
|
||||
//#region src/rspack/loaders/load.d.ts
|
||||
declare function load(this: LoaderContext, source: string, map: any): Promise<void>;
|
||||
export = load;
|
||||
6
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/load.d.ts
generated
vendored
Normal file
6
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/load.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { LoaderContext } from "@rspack/core";
|
||||
|
||||
//#region src/rspack/loaders/load.d.ts
|
||||
declare function load(this: LoaderContext, source: string, map: any): Promise<void>;
|
||||
//#endregion
|
||||
export { load as default };
|
||||
27
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/load.js
generated
vendored
Normal file
27
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/load.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { n as normalizeObjectHook } from "../../context-Csj9j3eN.js";
|
||||
import { t as normalizeAbsolutePath } from "../../webpack-like-DFGTNSuV.js";
|
||||
import { n as createContext, t as createBuildContext } from "../../context-DkYlx1xL.js";
|
||||
import { i as isVirtualModuleId, n as decodeVirtualModuleId } from "../../utils-BosfZ0pB.js";
|
||||
|
||||
//#region src/rspack/loaders/load.ts
|
||||
async function load(source, map) {
|
||||
const callback = this.async();
|
||||
const { plugin } = this.query;
|
||||
let id = this.resource;
|
||||
if (!plugin?.load || !id) return callback(null, source, map);
|
||||
if (isVirtualModuleId(id, plugin)) id = decodeVirtualModuleId(id, plugin);
|
||||
const context = createContext(this);
|
||||
const { handler } = normalizeObjectHook("load", plugin.load);
|
||||
try {
|
||||
const res = await handler.call(Object.assign({}, this._compilation && createBuildContext(this._compiler, this._compilation, this), context), normalizeAbsolutePath(id));
|
||||
if (res == null) callback(null, source, map);
|
||||
else if (typeof res !== "string") callback(null, res.code, res.map ?? map);
|
||||
else callback(null, res, map);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) callback(error);
|
||||
else callback(new Error(String(error)));
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { load as default };
|
||||
25
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/transform.cjs
generated
vendored
Normal file
25
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/transform.cjs
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
const require_context = require('../../context-CQfDPcdE.cjs');
|
||||
const require_context$1 = require('../../context-CrbHoDid.cjs');
|
||||
|
||||
//#region src/rspack/loaders/transform.ts
|
||||
async function transform(source, map) {
|
||||
const callback = this.async();
|
||||
const { plugin } = this.query;
|
||||
if (!plugin?.transform) return callback(null, source, map);
|
||||
const id = this.resource;
|
||||
const context = require_context$1.createContext(this);
|
||||
const { handler, filter } = require_context.normalizeObjectHook("transform", plugin.transform);
|
||||
if (!filter(this.resource, source)) return callback(null, source, map);
|
||||
try {
|
||||
const res = await handler.call(Object.assign({}, this._compilation && require_context$1.createBuildContext(this._compiler, this._compilation, this, map), context), source, id);
|
||||
if (res == null) callback(null, source, map);
|
||||
else if (typeof res !== "string") callback(null, res.code, map == null ? map : res.map || map);
|
||||
else callback(null, res, map);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) callback(error);
|
||||
else callback(new Error(String(error)));
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
module.exports = transform;
|
||||
5
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/transform.d.cts
generated
vendored
Normal file
5
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/transform.d.cts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { LoaderContext } from "@rspack/core";
|
||||
|
||||
//#region src/rspack/loaders/transform.d.ts
|
||||
declare function transform(this: LoaderContext, source: string, map: any): Promise<void>;
|
||||
export = transform;
|
||||
6
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/transform.d.ts
generated
vendored
Normal file
6
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/transform.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { LoaderContext } from "@rspack/core";
|
||||
|
||||
//#region src/rspack/loaders/transform.d.ts
|
||||
declare function transform(this: LoaderContext, source: string, map: any): Promise<void>;
|
||||
//#endregion
|
||||
export { transform as default };
|
||||
25
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/transform.js
generated
vendored
Normal file
25
node_modules/unctx/node_modules/unplugin/dist/rspack/loaders/transform.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { n as normalizeObjectHook } from "../../context-Csj9j3eN.js";
|
||||
import { n as createContext, t as createBuildContext } from "../../context-DkYlx1xL.js";
|
||||
|
||||
//#region src/rspack/loaders/transform.ts
|
||||
async function transform(source, map) {
|
||||
const callback = this.async();
|
||||
const { plugin } = this.query;
|
||||
if (!plugin?.transform) return callback(null, source, map);
|
||||
const id = this.resource;
|
||||
const context = createContext(this);
|
||||
const { handler, filter } = normalizeObjectHook("transform", plugin.transform);
|
||||
if (!filter(this.resource, source)) return callback(null, source, map);
|
||||
try {
|
||||
const res = await handler.call(Object.assign({}, this._compilation && createBuildContext(this._compiler, this._compilation, this, map), context), source, id);
|
||||
if (res == null) callback(null, source, map);
|
||||
else if (typeof res !== "string") callback(null, res.code, map == null ? map : res.map || map);
|
||||
else callback(null, res, map);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) callback(error);
|
||||
else callback(new Error(String(error)));
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { transform as default };
|
||||
54
node_modules/unctx/node_modules/unplugin/dist/utils-BosfZ0pB.js
generated
vendored
Normal file
54
node_modules/unctx/node_modules/unplugin/dist/utils-BosfZ0pB.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import fs from "node:fs";
|
||||
import { basename, dirname, resolve } from "node:path";
|
||||
|
||||
//#region src/rspack/utils.ts
|
||||
function encodeVirtualModuleId(id, plugin) {
|
||||
return resolve(plugin.__virtualModulePrefix, encodeURIComponent(id));
|
||||
}
|
||||
function decodeVirtualModuleId(encoded, _plugin) {
|
||||
return decodeURIComponent(basename(encoded));
|
||||
}
|
||||
function isVirtualModuleId(encoded, plugin) {
|
||||
return dirname(encoded) === plugin.__virtualModulePrefix;
|
||||
}
|
||||
var FakeVirtualModulesPlugin = class FakeVirtualModulesPlugin {
|
||||
name = "FakeVirtualModulesPlugin";
|
||||
static counters = /* @__PURE__ */ new Map();
|
||||
static initCleanup = false;
|
||||
constructor(plugin) {
|
||||
this.plugin = plugin;
|
||||
if (!FakeVirtualModulesPlugin.initCleanup) {
|
||||
FakeVirtualModulesPlugin.initCleanup = true;
|
||||
process.once("exit", () => {
|
||||
FakeVirtualModulesPlugin.counters.forEach((_, dir) => {
|
||||
fs.rmSync(dir, {
|
||||
recursive: true,
|
||||
force: true
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
apply(compiler) {
|
||||
const dir = this.plugin.__virtualModulePrefix;
|
||||
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
||||
const counter = FakeVirtualModulesPlugin.counters.get(dir) ?? 0;
|
||||
FakeVirtualModulesPlugin.counters.set(dir, counter + 1);
|
||||
compiler.hooks.shutdown.tap(this.name, () => {
|
||||
const counter$1 = (FakeVirtualModulesPlugin.counters.get(dir) ?? 1) - 1;
|
||||
if (counter$1 === 0) {
|
||||
FakeVirtualModulesPlugin.counters.delete(dir);
|
||||
fs.rmSync(dir, {
|
||||
recursive: true,
|
||||
force: true
|
||||
});
|
||||
} else FakeVirtualModulesPlugin.counters.set(dir, counter$1);
|
||||
});
|
||||
}
|
||||
async writeModule(file) {
|
||||
return fs.promises.writeFile(file, "");
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
export { isVirtualModuleId as i, decodeVirtualModuleId as n, encodeVirtualModuleId as r, FakeVirtualModulesPlugin as t };
|
||||
80
node_modules/unctx/node_modules/unplugin/dist/utils-CJMEEaD7.cjs
generated
vendored
Normal file
80
node_modules/unctx/node_modules/unplugin/dist/utils-CJMEEaD7.cjs
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
const require_context = require('./context-CQfDPcdE.cjs');
|
||||
let node_fs = require("node:fs");
|
||||
node_fs = require_context.__toESM(node_fs);
|
||||
let node_path = require("node:path");
|
||||
node_path = require_context.__toESM(node_path);
|
||||
|
||||
//#region src/rspack/utils.ts
|
||||
function encodeVirtualModuleId(id, plugin) {
|
||||
return (0, node_path.resolve)(plugin.__virtualModulePrefix, encodeURIComponent(id));
|
||||
}
|
||||
function decodeVirtualModuleId(encoded, _plugin) {
|
||||
return decodeURIComponent((0, node_path.basename)(encoded));
|
||||
}
|
||||
function isVirtualModuleId(encoded, plugin) {
|
||||
return (0, node_path.dirname)(encoded) === plugin.__virtualModulePrefix;
|
||||
}
|
||||
var FakeVirtualModulesPlugin = class FakeVirtualModulesPlugin {
|
||||
name = "FakeVirtualModulesPlugin";
|
||||
static counters = /* @__PURE__ */ new Map();
|
||||
static initCleanup = false;
|
||||
constructor(plugin) {
|
||||
this.plugin = plugin;
|
||||
if (!FakeVirtualModulesPlugin.initCleanup) {
|
||||
FakeVirtualModulesPlugin.initCleanup = true;
|
||||
process.once("exit", () => {
|
||||
FakeVirtualModulesPlugin.counters.forEach((_, dir) => {
|
||||
node_fs.default.rmSync(dir, {
|
||||
recursive: true,
|
||||
force: true
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
apply(compiler) {
|
||||
const dir = this.plugin.__virtualModulePrefix;
|
||||
if (!node_fs.default.existsSync(dir)) node_fs.default.mkdirSync(dir, { recursive: true });
|
||||
const counter = FakeVirtualModulesPlugin.counters.get(dir) ?? 0;
|
||||
FakeVirtualModulesPlugin.counters.set(dir, counter + 1);
|
||||
compiler.hooks.shutdown.tap(this.name, () => {
|
||||
const counter$1 = (FakeVirtualModulesPlugin.counters.get(dir) ?? 1) - 1;
|
||||
if (counter$1 === 0) {
|
||||
FakeVirtualModulesPlugin.counters.delete(dir);
|
||||
node_fs.default.rmSync(dir, {
|
||||
recursive: true,
|
||||
force: true
|
||||
});
|
||||
} else FakeVirtualModulesPlugin.counters.set(dir, counter$1);
|
||||
});
|
||||
}
|
||||
async writeModule(file) {
|
||||
return node_fs.default.promises.writeFile(file, "");
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'FakeVirtualModulesPlugin', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return FakeVirtualModulesPlugin;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'decodeVirtualModuleId', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return decodeVirtualModuleId;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'encodeVirtualModuleId', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return encodeVirtualModuleId;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'isVirtualModuleId', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return isVirtualModuleId;
|
||||
}
|
||||
});
|
||||
45
node_modules/unctx/node_modules/unplugin/dist/webpack-like-DDVwPJ4e.cjs
generated
vendored
Normal file
45
node_modules/unctx/node_modules/unplugin/dist/webpack-like-DDVwPJ4e.cjs
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
const require_context = require('./context-CQfDPcdE.cjs');
|
||||
let node_path = require("node:path");
|
||||
node_path = require_context.__toESM(node_path);
|
||||
|
||||
//#region src/utils/webpack-like.ts
|
||||
function transformUse(data, plugin, transformLoader) {
|
||||
if (data.resource == null) return [];
|
||||
const id = normalizeAbsolutePath(data.resource + (data.resourceQuery || ""));
|
||||
if (plugin.transformInclude && !plugin.transformInclude(id)) return [];
|
||||
const { filter } = require_context.normalizeObjectHook("load", plugin.transform);
|
||||
if (!filter(id)) return [];
|
||||
return [{
|
||||
loader: transformLoader,
|
||||
options: { plugin },
|
||||
ident: plugin.name
|
||||
}];
|
||||
}
|
||||
/**
|
||||
* Normalizes a given path when it's absolute. Normalizing means returning a new path by converting
|
||||
* the input path to the native os format. This is useful in cases where we want to normalize
|
||||
* the `id` argument of a hook. Any absolute ids should be in the default format
|
||||
* of the operating system. Any relative imports or node_module imports should remain
|
||||
* untouched.
|
||||
*
|
||||
* @param path - Path to normalize.
|
||||
* @returns a new normalized path.
|
||||
*/
|
||||
function normalizeAbsolutePath(path) {
|
||||
if ((0, node_path.isAbsolute)(path)) return (0, node_path.normalize)(path);
|
||||
else return path;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'normalizeAbsolutePath', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return normalizeAbsolutePath;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'transformUse', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return transformUse;
|
||||
}
|
||||
});
|
||||
33
node_modules/unctx/node_modules/unplugin/dist/webpack-like-DFGTNSuV.js
generated
vendored
Normal file
33
node_modules/unctx/node_modules/unplugin/dist/webpack-like-DFGTNSuV.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import { n as normalizeObjectHook } from "./context-Csj9j3eN.js";
|
||||
import { isAbsolute, normalize } from "node:path";
|
||||
|
||||
//#region src/utils/webpack-like.ts
|
||||
function transformUse(data, plugin, transformLoader) {
|
||||
if (data.resource == null) return [];
|
||||
const id = normalizeAbsolutePath(data.resource + (data.resourceQuery || ""));
|
||||
if (plugin.transformInclude && !plugin.transformInclude(id)) return [];
|
||||
const { filter } = normalizeObjectHook("load", plugin.transform);
|
||||
if (!filter(id)) return [];
|
||||
return [{
|
||||
loader: transformLoader,
|
||||
options: { plugin },
|
||||
ident: plugin.name
|
||||
}];
|
||||
}
|
||||
/**
|
||||
* Normalizes a given path when it's absolute. Normalizing means returning a new path by converting
|
||||
* the input path to the native os format. This is useful in cases where we want to normalize
|
||||
* the `id` argument of a hook. Any absolute ids should be in the default format
|
||||
* of the operating system. Any relative imports or node_module imports should remain
|
||||
* untouched.
|
||||
*
|
||||
* @param path - Path to normalize.
|
||||
* @returns a new normalized path.
|
||||
*/
|
||||
function normalizeAbsolutePath(path$1) {
|
||||
if (isAbsolute(path$1)) return normalize(path$1);
|
||||
else return path$1;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { transformUse as n, normalizeAbsolutePath as t };
|
||||
28
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/load.cjs
generated
vendored
Normal file
28
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/load.cjs
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
const require_context = require('../../context-CQfDPcdE.cjs');
|
||||
const require_webpack_like = require('../../webpack-like-DDVwPJ4e.cjs');
|
||||
const require_context$1 = require('../../context-D7WFmOmt.cjs');
|
||||
|
||||
//#region src/webpack/loaders/load.ts
|
||||
async function load(source, map) {
|
||||
const callback = this.async();
|
||||
const { plugin } = this.query;
|
||||
let id = this.resource;
|
||||
if (!plugin?.load || !id) return callback(null, source, map);
|
||||
if (id.startsWith(plugin.__virtualModulePrefix)) id = decodeURIComponent(id.slice(plugin.__virtualModulePrefix.length));
|
||||
const context = require_context$1.createContext(this);
|
||||
const { handler } = require_context.normalizeObjectHook("load", plugin.load);
|
||||
const res = await handler.call(Object.assign({}, require_context$1.createBuildContext({
|
||||
addWatchFile: (file) => {
|
||||
this.addDependency(file);
|
||||
},
|
||||
getWatchFiles: () => {
|
||||
return this.getDependencies();
|
||||
}
|
||||
}, this._compiler, this._compilation, this), context), require_webpack_like.normalizeAbsolutePath(id));
|
||||
if (res == null) callback(null, source, map);
|
||||
else if (typeof res !== "string") callback(null, res.code, res.map ?? map);
|
||||
else callback(null, res, map);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
module.exports = load;
|
||||
5
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/load.d.cts
generated
vendored
Normal file
5
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/load.d.cts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { LoaderContext } from "webpack";
|
||||
|
||||
//#region src/webpack/loaders/load.d.ts
|
||||
declare function load(this: LoaderContext<any>, source: string, map: any): Promise<void>;
|
||||
export = load;
|
||||
6
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/load.d.ts
generated
vendored
Normal file
6
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/load.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { LoaderContext } from "webpack";
|
||||
|
||||
//#region src/webpack/loaders/load.d.ts
|
||||
declare function load(this: LoaderContext<any>, source: string, map: any): Promise<void>;
|
||||
//#endregion
|
||||
export { load as default };
|
||||
28
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/load.js
generated
vendored
Normal file
28
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/load.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { n as normalizeObjectHook } from "../../context-Csj9j3eN.js";
|
||||
import { t as normalizeAbsolutePath } from "../../webpack-like-DFGTNSuV.js";
|
||||
import { n as createBuildContext, r as createContext } from "../../context-OCFO8EW1.js";
|
||||
|
||||
//#region src/webpack/loaders/load.ts
|
||||
async function load(source, map) {
|
||||
const callback = this.async();
|
||||
const { plugin } = this.query;
|
||||
let id = this.resource;
|
||||
if (!plugin?.load || !id) return callback(null, source, map);
|
||||
if (id.startsWith(plugin.__virtualModulePrefix)) id = decodeURIComponent(id.slice(plugin.__virtualModulePrefix.length));
|
||||
const context = createContext(this);
|
||||
const { handler } = normalizeObjectHook("load", plugin.load);
|
||||
const res = await handler.call(Object.assign({}, createBuildContext({
|
||||
addWatchFile: (file) => {
|
||||
this.addDependency(file);
|
||||
},
|
||||
getWatchFiles: () => {
|
||||
return this.getDependencies();
|
||||
}
|
||||
}, this._compiler, this._compilation, this), context), normalizeAbsolutePath(id));
|
||||
if (res == null) callback(null, source, map);
|
||||
else if (typeof res !== "string") callback(null, res.code, res.map ?? map);
|
||||
else callback(null, res, map);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { load as default };
|
||||
31
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/transform.cjs
generated
vendored
Normal file
31
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/transform.cjs
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
const require_context = require('../../context-CQfDPcdE.cjs');
|
||||
const require_context$1 = require('../../context-D7WFmOmt.cjs');
|
||||
|
||||
//#region src/webpack/loaders/transform.ts
|
||||
async function transform(source, map) {
|
||||
const callback = this.async();
|
||||
const { plugin } = this.query;
|
||||
if (!plugin?.transform) return callback(null, source, map);
|
||||
const context = require_context$1.createContext(this);
|
||||
const { handler, filter } = require_context.normalizeObjectHook("transform", plugin.transform);
|
||||
if (!filter(this.resource, source)) return callback(null, source, map);
|
||||
try {
|
||||
const res = await handler.call(Object.assign({}, require_context$1.createBuildContext({
|
||||
addWatchFile: (file) => {
|
||||
this.addDependency(file);
|
||||
},
|
||||
getWatchFiles: () => {
|
||||
return this.getDependencies();
|
||||
}
|
||||
}, this._compiler, this._compilation, this, map), context), source, this.resource);
|
||||
if (res == null) callback(null, source, map);
|
||||
else if (typeof res !== "string") callback(null, res.code, map == null ? map : res.map || map);
|
||||
else callback(null, res, map);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) callback(error);
|
||||
else callback(new Error(String(error)));
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
module.exports = transform;
|
||||
5
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/transform.d.cts
generated
vendored
Normal file
5
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/transform.d.cts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { LoaderContext } from "webpack";
|
||||
|
||||
//#region src/webpack/loaders/transform.d.ts
|
||||
declare function transform(this: LoaderContext<any>, source: string, map: any): Promise<void>;
|
||||
export = transform;
|
||||
6
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/transform.d.ts
generated
vendored
Normal file
6
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/transform.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { LoaderContext } from "webpack";
|
||||
|
||||
//#region src/webpack/loaders/transform.d.ts
|
||||
declare function transform(this: LoaderContext<any>, source: string, map: any): Promise<void>;
|
||||
//#endregion
|
||||
export { transform as default };
|
||||
31
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/transform.js
generated
vendored
Normal file
31
node_modules/unctx/node_modules/unplugin/dist/webpack/loaders/transform.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { n as normalizeObjectHook } from "../../context-Csj9j3eN.js";
|
||||
import { n as createBuildContext, r as createContext } from "../../context-OCFO8EW1.js";
|
||||
|
||||
//#region src/webpack/loaders/transform.ts
|
||||
async function transform(source, map) {
|
||||
const callback = this.async();
|
||||
const { plugin } = this.query;
|
||||
if (!plugin?.transform) return callback(null, source, map);
|
||||
const context = createContext(this);
|
||||
const { handler, filter } = normalizeObjectHook("transform", plugin.transform);
|
||||
if (!filter(this.resource, source)) return callback(null, source, map);
|
||||
try {
|
||||
const res = await handler.call(Object.assign({}, createBuildContext({
|
||||
addWatchFile: (file) => {
|
||||
this.addDependency(file);
|
||||
},
|
||||
getWatchFiles: () => {
|
||||
return this.getDependencies();
|
||||
}
|
||||
}, this._compiler, this._compilation, this, map), context), source, this.resource);
|
||||
if (res == null) callback(null, source, map);
|
||||
else if (typeof res !== "string") callback(null, res.code, map == null ? map : res.map || map);
|
||||
else callback(null, res, map);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) callback(error);
|
||||
else callback(new Error(String(error)));
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { transform as default };
|
||||
92
node_modules/unctx/node_modules/unplugin/package.json
generated
vendored
Normal file
92
node_modules/unctx/node_modules/unplugin/package.json
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
{
|
||||
"name": "unplugin",
|
||||
"type": "module",
|
||||
"version": "2.3.11",
|
||||
"description": "Unified plugin system for build tools",
|
||||
"license": "MIT",
|
||||
"homepage": "https://unplugin.unjs.io",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/unjs/unplugin.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"./dist/webpack/loaders/*": "./dist/webpack/loaders/*.cjs",
|
||||
"./dist/rspack/loaders/*": "./dist/rspack/loaders/*.cjs"
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18.12.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@jridgewell/remapping": "^2.3.5",
|
||||
"acorn": "^8.15.0",
|
||||
"picomatch": "^4.0.3",
|
||||
"webpack-virtual-modules": "^0.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^6.2.0",
|
||||
"@antfu/ni": "^27.0.1",
|
||||
"@farmfe/cli": "^1.0.5",
|
||||
"@farmfe/core": "^1.7.11",
|
||||
"@rspack/cli": "^1.6.0",
|
||||
"@rspack/core": "^1.6.0",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/node": "^24.10.0",
|
||||
"@types/picomatch": "^4.0.2",
|
||||
"ansis": "^4.2.0",
|
||||
"bumpp": "^10.3.1",
|
||||
"esbuild": "^0.25.12",
|
||||
"esbuild-plugin-copy": "^2.1.1",
|
||||
"eslint": "^9.39.0",
|
||||
"eslint-plugin-format": "^1.0.2",
|
||||
"fast-glob": "^3.3.3",
|
||||
"fs-extra": "^11.3.2",
|
||||
"jiti": "^2.6.1",
|
||||
"lint-staged": "^16.2.6",
|
||||
"magic-string": "^0.30.21",
|
||||
"rolldown": "^1.0.0-beta.46",
|
||||
"rollup": "^4.52.5",
|
||||
"simple-git-hooks": "^2.13.1",
|
||||
"tsdown": "^0.15.12",
|
||||
"typescript": "~5.9.3",
|
||||
"unloader": "^0.5.0",
|
||||
"unplugin-unused": "^0.5.5",
|
||||
"vite": "^7.1.12",
|
||||
"vitest": "^4.0.6",
|
||||
"webpack": "^5.102.1",
|
||||
"webpack-cli": "^6.0.1",
|
||||
"unplugin": "2.3.11"
|
||||
},
|
||||
"resolutions": {
|
||||
"esbuild": "catalog:"
|
||||
},
|
||||
"simple-git-hooks": {
|
||||
"pre-commit": "pnpm i --frozen-lockfile --ignore-scripts --offline && npx lint-staged"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*": "eslint --fix"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsdown",
|
||||
"dev": "tsdown --watch src",
|
||||
"lint": "eslint --cache .",
|
||||
"lint:fix": "nr lint --fix",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"docs:dev": "pnpm -C docs run dev",
|
||||
"docs:build": "pnpm -C docs run build",
|
||||
"docs:gen-files": "pnpm -C docs run gen-files",
|
||||
"release": "bumpp",
|
||||
"test": "nr test:build && vitest run --pool=forks",
|
||||
"test:build": "jiti scripts/buildFixtures.ts"
|
||||
}
|
||||
}
|
||||
67
node_modules/unctx/package.json
generated
vendored
Normal file
67
node_modules/unctx/package.json
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"name": "unctx",
|
||||
"version": "2.5.0",
|
||||
"description": "Composition-api in Vanilla js",
|
||||
"repository": "unjs/unctx",
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"./transform": {
|
||||
"types": "./dist/transform.d.ts",
|
||||
"import": "./dist/transform.mjs"
|
||||
},
|
||||
"./plugin": {
|
||||
"types": "./dist/plugin.d.ts",
|
||||
"import": "./dist/plugin.mjs"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"*": [
|
||||
"./dist/*",
|
||||
"./dist/index.d.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "vitest",
|
||||
"lint": "eslint . && prettier -c src test",
|
||||
"lint:fix": "eslint --fix . && prettier -w src test",
|
||||
"prepack": "unbuild",
|
||||
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
|
||||
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
|
||||
"test:types": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn": "^8.15.0",
|
||||
"estree-walker": "^3.0.3",
|
||||
"magic-string": "^0.30.21",
|
||||
"unplugin": "^2.3.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/estree": "^1.0.8",
|
||||
"@types/node": "^25.0.2",
|
||||
"@vitest/coverage-v8": "^4.0.16",
|
||||
"changelogen": "^0.6.2",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-config-unjs": "^0.5.0",
|
||||
"jiti": "^2.6.1",
|
||||
"prettier": "^3.7.4",
|
||||
"typescript": "^5.9.3",
|
||||
"unbuild": "^3.6.1",
|
||||
"vitest": "^4.0.16"
|
||||
},
|
||||
"packageManager": "pnpm@10.26.0"
|
||||
}
|
||||
Reference in New Issue
Block a user