1.0.0 • Published 5 years ago

@artdeco/pirates v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

@artdeco/pirates

npm version

@artdeco/pirates is a fork of Properly Hijack Require In ES6 For Google Closure Compiler.

yarn add @artdeco/pirates

Table Of Contents

API

The package is available by importing its default function:

import addHook from '@artdeco/pirates'

addHook(  hook: function,  conf?: Config,): function

Add a require hook. Returns a function that allows to revert the hook.

_pirates.Config: Options for the program.

NameTypeDescriptionDefault
exts(string | !Array<string>)The extension or extensions to hook. Should start with ...js
matcher(path: string) => booleanA matcher function, will be called with path to a file. Should return truthy if the file should be hooked, falsy otherwise.-
ignoreNodeModulesbooleanAuto-ignore node_modules. Independent of any matcher.false
import addHook from '@artdeco/pirates'
import { relative } from 'path'

addHook((code, filename) => {
  const rel = relative('', filename)
  return `console.log('hooked source code from %s:', '${rel}')
  ${code}`
})

require('./source')
hooked source code from example/source.js:
hello world

Copyright

Original Author: Ari Porad