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

swc-import-glob-array-plugin

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swc-import-glob-array-plugin

SWC plugin that expands glob patterns and imports them as an array

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

SWC Import Glob Array Plugin

This plugin is a port of babel-plugin-import-glob-array from JavaScript to Rust for Speedy Web Compiler (SWC).

Before continuing, please understand that SWC plugins are distributed as WebAssembly binaries and are currently not backwards compatible, meaning that plugins may break frequently between versions. To ensure that you're using a version of this plugin that is compatible with your current @swc/core or next package(s), check out the compatibility table below.

Installation

Installation can be done via npm:

# npm
$ npm install --save-dev swc-import-glob-array-plugin

# yarn
$ yarn add -D swc-import-glob-array-plugin

# pnpm
$ pnpm add -D swc-import-glob-array-plugin

Then you'll add the plugin under jsc.experimental.plugins:

{
  "jsc": {
    "experimental": {
      "plugins": [
        [
          "swc-import-glob-array-plugin",
          {}
        ]
      ]
    }
  }
}

For more information on adding and configuration an SWC plugin, check out their documentation.

Usage

This plugin check the imports of each SWC file to determine if it contains a glob pattern. If it does, it will expand the single import to individual imports. As an example, let's say you have the following directory structure:

|- my-app
  |- docs
    |- hello.md
    |- world.md
  |- index.js

And index.js, which will get compiled by SWC, has the following import:

import docs from "./docs/*.md";

The single import will get parsed and expanded into:

import _iga1 from "./docs/hello.md";
import _iga2 from "./docs/world.md";

const docs = [ _iga1, _iga2 ];

Adding Import Metadata

In addition to expanding a single import, you can also import metadata information about where the file came from and what was imported via the special _importMeta property.

Using the example above, we can slightly modify our import statement:

import docs, { _importMeta as metadata } from "./docs/*.md";

Which will get parsed and expanded into:

import _iga1 from "./docs/hello.md";
import _iga2 from "./docs/world.md";

const docs = [ _iga1, _iga2 ];

const metadata = [
    {
        absolutePath: "/path/to/project/docs/hello.md",
        importedPath: "./docs/hello.md"
    },
    {
        absolutePath: "/path/to/project/docs/world.md",
        importedPath: "./docs/world.md"
    }
];

Compatibility

swc-import-glob-array-plugin@swc/core
1.0.11.3.44 ~ 1.3.47
1.0.21.3.49 ~ 1.3.56

Keywords

FAQs

Package last updated on 10 May 2023

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