require-extension-hooks
Advanced tools
Comparing version 0.2.0 to 0.3.0
{ | ||
"name": "require-extension-hooks", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Add hooks for js extension types", | ||
"main": "index.js", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "ava" | ||
}, | ||
"ava": { | ||
"files": "spec/**/*.spec.js" | ||
}, | ||
"repository": { | ||
@@ -22,4 +25,8 @@ "type": "git", | ||
"merge-source-map": "^1.0.3", | ||
"minimatch": "^3.0.4", | ||
"source-map": "^0.5.6" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.20.0" | ||
} | ||
} |
@@ -39,4 +39,22 @@ # require-extension-hooks | ||
Loads a plugin. The plugin can either be a partial name (i.e. for *require-extension-hooks-vue* you can just type `hook.plugin('vue')`), the full name of a plugin (i.e. `hook.plugin('require-extension-hooks-vue')`) or a direct function (i.e. `hook.plugin(function(config){}`). | ||
The plugin function does not automatically append the plugin to the hook queue, you also need to tell it what to do. i.e. `hook.plugin('vue').push()`. | ||
The plugin is automatically added to the hook queue. You can move it to the start of the queue by calling `hook.plugin('xxx').unshift()`. | ||
### include(pattern | fn) | ||
Restricts the hook to only run based on the provided pattern. The argument can either a function (that takes the same configuration options as the hook itself), or a **glob** pattern that is matched against the filename. | ||
```js | ||
// these 2 examples will both only run for files in the node_modules folder | ||
hooks('js').include('**/node_modules/**/*.js').push(...); | ||
hooks('js').include(({filename}) => filename.includes('node_modules')); | ||
``` | ||
### exclude(pattern | fn) | ||
Restricts the hook to skip files that do not match the provided pattern. The argument can either a function (that takes the same configuration options as the hook itself), or a **glob** pattern that is matched against the filename. | ||
```js | ||
// these 2 examples will both EXCLUDE any files from the node_modules folder | ||
hooks('js').exclude('**/node_modules/**/*.js').push(...); | ||
hooks('js').exclude(({filename}) => filename.includes('node_modules')); | ||
``` | ||
It is possible to chain multiple include and exclude patterns, the file must match all of the patterns to continue. | ||
### config | ||
@@ -56,3 +74,19 @@ A hook function takes a config object as its only argument. This object contains the following options: | ||
The source map object from any previous transpilations. You don't need to manually merge the input source map into your current source map as this is automatically calculated. | ||
#### hook | ||
The `hook` method allows you to parse a file's content through another extension and return the transpiled content. This is useful if you have a file that contains multiple languages. | ||
```js | ||
hooks('.custom').push(function ({content, hook}) { | ||
let {javascriptPart, typescriptPart} = extractStuffFromContent(content); | ||
let transpiledTypescriptPart = hook('.ts', typescriptPart); | ||
return `${javascriptPart}\n${typescriptPart}`; | ||
}) | ||
``` | ||
The hook method takes a file extension as its first parameter. The second parameter can be one of the following: | ||
- `String` - assumed to be the content you want to parse. | ||
- `{content : String}` - same as passing content directly | ||
- `{content : String, filename : String}` - passes the content to the hook but with a custom filename | ||
- `{filename : String}` - pass in a custom filename and it will read in and transpile that file's content. | ||
If you do not pass any parameters into the `hook` method, it will pass in the current content and filename. | ||
#### return | ||
@@ -59,0 +93,0 @@ The hook function *must* return a value. If no value is returned, the next hook is automatically called instead. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
15870
8
278
1
123
4
1
5
1
+ Addedminimatch@^3.0.4
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedminimatch@3.1.2(transitive)