Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
babel-plugin-extend-docs
Advanced tools
Babel plugin which rewrites imports and templates according to a configuration
A plugin which rewrites imports and templates according to a configuration. This enables the reuse of existing documentation from source packages while still using your extensions code.
npm i -D babel-plugin-extend-docs
We want to only execute babel-plugin-extend-docs
on the actual files we want to modify/extend.
You may also consider using babel overrides.
👉 web-dev-server.config.js
import path from 'path';
import { fromRollup } from '@web/dev-server-rollup';
import rollupBabel from '@rollup/plugin-babel';
const extendDocsConfig = {
changes: [
// possible changes as described below
],
};
// note that you need to use `.default` for babel
const babel = fromRollup(rollupBabel.default);
export default {
nodeResolve: true,
plugins: [
babel({
include: ['./glob/to/files/**/*.js'],
plugins: [[path.resolve('./'), extendDocsConfig]],
}),
],
};
A change is what gets placed between in the extendDocsConfig within the changes
array.
automating the generation of changes is optional but encouraged
It has the following possibilities:
changes: [
{
description: 'MyCounter', // not needed but can be added for easier reading of the config
variable: {
// see below
},
tag: {
// see below
},
},
];
Both variable
and tag
are required to have a paths
array which defines how to remap import paths. Generally it should be a single entry.
paths: [
{ from: 'source-pkg/counter', to: 'extension-pkg/counter' },
],
We have an existing demo code which we want to reuse.
import { LitElement, html } from '@lion/core';
import 'source-pkg/counter/define';
class MyApp extends LitElement {
render() {
return html`
<h1>Example App</h1>
<source-counter></source-counter>
`;
}
}
customElements.define('my-app', MyApp);
We created a "better" version of <source-counter>
so we would like to use that in the demo.
Our extension is called <extension-counter>
and is available via extension-pkg/counter/define
.
Within babel-plugin-extend-docs
we can define to replace the tag + it's import.
tag: {
from: 'source-counter',
to: 'extension-counter',
paths: [{ from: 'source-pkg/counter/define', to: 'extension-pkg/counter/define' }],
}
import { LitElement, html } from '@lion/core';
import 'extension-pkg/counter/define';
class MyApp extends LitElement {
render() {
return html`
<h1>Example App</h1>
<extension-counter></extension-counter>
`;
}
}
customElements.define('my-app', MyApp);
We have an existing demo code which we want to reuse.
import { LitElement, html } from '@lion/core';
import { SourceCounter } from 'source-pkg/counter';
class TenCounter extends SourceCounter {
inc() {
this.count += 10;
}
}
customElements.define('ten-counter', TenCounter);
class MyApp extends LitElement {
render() {
return html`
<h1>Example App</h1>
<ten-counter></ten-counter>
`;
}
}
customElements.define('my-app', MyApp);
We created a "better" version of SourceCounter
so we would like that TenCounter
now extends it instead.
Within babel-plugin-extend-docs
we can define to replace the class + it's import.
variable: {
from: 'SourceCounter',
to: 'ExtensionCounter',
paths: [
{ from: 'source-pkg/counter', to: 'extension-pkg/counter' },
],
},
import { LitElement, html } from '@lion/core';
import { SourceCounter } from 'extension-pkg/counter';
class TenCounter extends SourceCounter {
inc() {
this.count += 10;
}
}
customElements.define('ten-counter', TenCounter);
class MyApp extends LitElement {
render() {
return html`
<h1>Example App</h1>
<ten-counter></ten-counter>
`;
}
}
customElements.define('my-app', MyApp);
You can run the example locally via npm run start
or look at its source code.
Note we are configuring babel via the server.config.mjs
👉 server.config.mjs
import path from 'path';
import { fromRollup } from '@web/dev-server-rollup';
import rollupBabel from '@rollup/plugin-babel';
const extendDocsConfig = {
changes: [
{
name: 'SourceCounter',
variable: {
from: 'SourceCounter',
to: 'ExtensionCounter',
paths: [{ from: '#source/counter', to: '#extension/counter' }],
},
tag: {
from: 'source-counter',
to: 'extension-counter',
paths: [{ from: '#source/counter/define', to: '#extension/counter/define' }],
},
},
],
};
// note that you need to use `.default` for babel
const babel = fromRollup(rollupBabel.default);
export default {
nodeResolve: true,
watch: true,
open: 'demo/',
plugins: [
babel({
include: ['./demo/**/*.demo.js'],
plugins: [[path.resolve('./'), extendDocsConfig]],
}),
],
};
FAQs
Babel plugin which rewrites imports and templates according to a configuration
The npm package babel-plugin-extend-docs receives a total of 6 weekly downloads. As such, babel-plugin-extend-docs popularity was classified as not popular.
We found that babel-plugin-extend-docs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.