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

bundle-require

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bundle-require - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

61

dist/index.js

@@ -1,13 +0,37 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined")
return require.apply(this, arguments);
throw new Error('Dynamic require of "' + x + '" is not supported');
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module2, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module2) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
// src/index.ts
__export(exports, {
bundleRequire: () => bundleRequire
});
// node_modules/tsup/assets/cjs_shims.js
var importMetaUrlShim = typeof document === "undefined" ? new (require("url")).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
// src/index.ts
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
var _esbuild = require('esbuild');
var import_fs = __toModule(require("fs"));
var import_path = __toModule(require("path"));
var import_esbuild = __toModule(require("esbuild"));
var JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/;

@@ -19,3 +43,3 @@ async function bundleRequire(options) {

const outfile = options.filepath.replace(JS_EXT_RE, ".bundled.cjs");
await _esbuild.build.call(void 0, {
await (0, import_esbuild.build)({
entryPoints: [options.filepath],

@@ -36,3 +60,3 @@ outfile,

}
if (_path2.default.isAbsolute(args.path) || args.path.startsWith(".")) {
if (import_path.default.isAbsolute(args.path) || args.path.startsWith(".")) {
return {

@@ -48,5 +72,5 @@ path: args.path

ctx.onLoad({ filter: JS_EXT_RE }, async (args) => {
const contents = await _fs2.default.promises.readFile(args.path, "utf-8");
const contents = await import_fs.default.promises.readFile(args.path, "utf-8");
return {
contents: contents.replace(/\b__filename\b/g, args.path).replace(/\b__dirname\b/g, _path2.default.dirname(args.path)).replace(/\bimport\.meta\.url\b/g, `file://${args.path}`)
contents: contents.replace(/\b__filename\b/g, args.path).replace(/\b__dirname\b/g, import_path.default.dirname(args.path)).replace(/\bimport\.meta\.url\b/g, `file://${args.path}`)
};

@@ -58,8 +82,9 @@ });

});
const mod = __require(outfile);
await _fs2.default.promises.unlink(outfile);
const mod = require(outfile);
await import_fs.default.promises.unlink(outfile);
return mod;
}
exports.bundleRequire = bundleRequire;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
bundleRequire
});
{
"name": "bundle-require",
"version": "1.0.0",
"version": "1.0.1",
"description": "bundle and require a file",

@@ -12,10 +12,5 @@ "publishConfig": {

"main": "./dist/index.js",
"module": "./dist/index.mjs",
"exports": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts-resolve",
"build": "tsup src/index.ts --format cjs --dts-resolve",
"test": "jest",

@@ -32,3 +27,3 @@ "prepublishOnly": "npm run build"

"prettier": "^2.2.1",
"tsup": "^4.8.4",
"tsup": "^5.4.0",
"typescript": "^4.2.3"

@@ -35,0 +30,0 @@ },

@@ -11,3 +11,3 @@ **💛 You can help the author become a full-time open-source maintainer by [sponsoring him on GitHub](https://github.com/sponsors/egoist).**

Projects like [Vite](https://vitejs.dev) need to load config files provided by the user, but you can't do it with just `require()` because it's not necessary a CommonJS module, it could also be a `.mjs` or event written in TypeScript, and that's where the `bundle-require` package comes in, it loads the config file regardless what module format it is.
Projects like [Vite](https://vitejs.dev) need to load config files provided by the user, but you can't do it with just `require()` because it's not necessarily a CommonJS module, it could also be a `.mjs` or even be written in TypeScript, and that's where the `bundle-require` package comes in, it loads the config file regardless what module format it is.

@@ -14,0 +14,0 @@ This is implemented by pre-bundling the file with [esbuild](https://esbuild.github.io/) and then loading it with `require()`.

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