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

@discordx/importer

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@discordx/importer

A solution to import files on the module and commonjs at the same time

  • 1.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
291
decreased by-37.28%
Maintainers
1
Weekly downloads
 
Created
Source

Create a discord bot with TypeScript and Decorators!

📖 Introduction

You can use this library without discordx

Support esm and cjs at the same time

💻 Installation

Version 16.6.0 or newer of Node.js is required

npm install @discordx/importer
yarn add @discordx/importer

Usage

If you use this code with esm or ejs, it will tell you about your environment.

import { isESM } from "@discordx/importer";

console.log(`isESM: ${isESM()}`);

Resolve glob paths

const resolvedPaths = await resolve(`${__dirname}/commands/**.js`);

console.log(resolvedPaths);

Import glob paths

Here is an example that could be used with the commonjs or esm modules

Module - CommonJS

importx(`${__dirname}/commands/**.js`).then(() =>
  console.log("All files imported"),
);

Module - ESNext

Remember: In esm, __dirname is not defined, so here is a workaround

import { dirname, importx } from "@discordx/importer";
const __dirname = dirname(import.meta.url);

importx(`${__dirname}/commands/**.js`).then(() =>
  console.log("All files imported"),
);

Combine - CommonJS and ESNext

If you are creating a module or extension of your own library, you can set it to auto-import paths based on the user module

import { dirname, importx, isESM } from "@discordx/importer";
const folder = isESM() ? dirname(import.meta.url) : __dirname;

importx(`${folder}/commands/**.js`).then(() =>
  console.log("All files imported"),
);

Use relative path

You can use relative path, which will be more convenient to write code by eliminating DIRNAME

import { importx } from "@discordx/importer";

// relative path start from root folder
importx("./tests/commands/**.js").then(() => console.log("All files imported"));

📜 Documentation

☎️ Need help?

💖 Thank you

You can support discordx by giving it a GitHub star.

Keywords

FAQs

Package last updated on 18 Jun 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