MCPcopy
hub / github.com/vitejs/vite / wrapEnvironmentTransform

Function wrapEnvironmentTransform

packages/vite/src/node/build.ts:1415–1437  ·  view source on GitHub ↗
(
  environment: Environment,
  hook: Plugin['transform'] | undefined,
  pluginName: string,
)

Source from the content-addressed store, hash-verified

1413}
1414
1415function wrapEnvironmentTransform(
1416 environment: Environment,
1417 hook: Plugin['transform'] | undefined,
1418 pluginName: string,
1419): Plugin['transform'] {
1420 if (!hook) return
1421
1422 const fn = getHookHandler(hook)
1423 const handler: Plugin['transform'] = function (code, importer, ...args) {
1424 return fn.call(
1425 injectEnvironmentInContext(this, environment),
1426 code,
1427 importer,
1428 injectSsrFlag(args[0], environment, pluginName),
1429 )
1430 }
1431
1432 if ('handler' in hook) {
1433 return wrapHookObject(hook, handler)
1434 } else {
1435 return handler
1436 }
1437}
1438
1439function wrapEnvironmentHook<HookName extends keyof Plugin>(
1440 environment: Environment,

Callers 1

injectEnvironmentToHooksFunction · 0.85

Calls 2

getHookHandlerFunction · 0.90
wrapHookObjectFunction · 0.85

Tested by

no test coverage detected