MCPcopy
hub / github.com/TypeStrong/ts-node / registerExtension

Function registerExtension

src/index.ts:1600–1623  ·  view source on GitHub ↗

* Register the extension for node.

(
  ext: string,
  service: Service,
  originalHandler: (m: NodeModule, filename: string) => any
)

Source from the content-addressed store, hash-verified

1598 * Register the extension for node.
1599 */
1600function registerExtension(
1601 ext: string,
1602 service: Service,
1603 originalHandler: (m: NodeModule, filename: string) => any
1604) {
1605 const old = require.extensions[ext] || originalHandler;
1606
1607 require.extensions[ext] = function (m: any, filename) {
1608 if (service.ignored(filename)) return old(m, filename);
1609
1610 assertScriptCanLoadAsCJS(service, m, filename);
1611
1612 const _compile = m._compile;
1613
1614 m._compile = function (code: string, fileName: string) {
1615 debug('module._compile', fileName);
1616
1617 const result = service.compile(code, fileName);
1618 return _compile.call(this, result, fileName);
1619 };
1620
1621 return old(m, filename);
1622 };
1623}
1624
1625/**
1626 * Internal source output.

Callers 1

registerExtensionsFunction · 0.85

Calls 2

ignoredMethod · 0.80
compileMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…