New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@roots/wordpress-transforms

Package Overview
Dependencies
Maintainers
0
Versions
573
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@roots/wordpress-transforms

Transform requests for WordPress provided externals

  • 6.24.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.8K
decreased by-0.54%
Maintainers
0
Weekly downloads
 
Created
Source

bud.js

MIT License npm Follow Roots

@roots/wordpress-transforms

Transform requests for WordPress provided externals


Installation

Install @roots/wordpress-transforms to your project.

Yarn:

yarn add @roots/wordpress-transforms --dev

npm:

npm install @roots/wordpress-transforms --save-dev

Usage

@roots/wordpress-transforms/handle

Transform a request for a WordPress provided package to its enqueue handle.

  • @wordpress/dom-ready => 'dom-ready'
  • react => 'react'
  • not-provided-package => undefined
import { transform } from "@roots/wordpress-transforms/handle";

transform(`@wordpress/edit-post`);
// ==> `wp-edit-post`

transform(`lodash`);
// ==> `lodash`

transform(`non-match`);
// ==> undefined

@roots/wordpress-transforms/window

Transform a request for a WordPress provided package to its window variable (expressesd as an array).

  • @wordpress/dom-ready => ['wp', 'domReady']
  • react => ['React']
  • not-provided-package => undefined
import { transform } from "@roots/wordpress-transforms/window";

transform(`@wordpress/edit-post`);
// ==> [`wp`, `editPost`]

transform(`lodash`);
// ==> [`lodash`]

transform(`non-match`);
// ==> undefined

@roots/wordpress-transforms/wordpress

Utilities used by @roots/wordpress-transforms/handle and @roots/wordpress-transforms/window.

Examples:

import * as wp from "@roots/wordpress-transforms/wordpress";

wp.isLibrary(`jquery`); // true
wp.isLibrary(`@wordpress/dom-ready`); // false
wp.isLibrary(`non-match`); // false

wp.isProvided(`@wordpress/icons`); // false
wp.isProvided(`lodash`); // true

wp.isWordPressRequest(`@wordpress/element`); // true
wp.isWordPressRequest(`lodash`); // false

wp.normalize(`../node_modules/react-refresh/runtime/foo/bar`); // `react-refresh/runtime`

@roots/wordpress-transforms

The three submodules are exported from root.

import { handle, window, wordpress } from "@roots/wordpress-transforms";

handle.transform(/**  */);

window.transform(/** */);

wordpress.isLibrary(/** */);

Example

This is the plugin exported by @roots/wordpress-externals-webpack-plugin, which uses this library:

import { window } from "@roots/wordpress-transforms";
import Webpack, { type WebpackPluginInstance } from "webpack";

/**
 * {@link WebpackPluginInstance}
 */
export class WordPressExternalsWebpackPlugin implements WebpackPluginInstance {
  /**
   * {@link WebpackPluginInstance.apply}
   */
  public apply(compiler: Webpack.Compiler) {
    new Webpack.ExternalsPlugin(`window`, ({ request }, callback) => {
      const lookup = window.transform(request);
      return lookup ? callback(null, lookup) : callback();
    }).apply(compiler);
  }
}

Contributing

Contributions are welcome from everyone.

We have contribution guidelines to help you get started.

License

@roots/wordpress-transforms is licensed under MIT.

Community

Keep track of development and community news.

Sponsors

bud.js is an open source project and completely free to use.

However, the amount of effort needed to maintain and develop new features and projects within the Roots ecosystem is not sustainable without proper financial backing. If you have the capability, please consider sponsoring Roots.

Carrot WordPress.com Worksite Safety Itineris

Keywords

FAQs

Package last updated on 09 Dec 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc