Skip to content

Commit

Permalink
Merge pull request #18 from AbstractSDK/fix/esbuild-2
Browse files Browse the repository at this point in the history
feat: bundle-require package
  • Loading branch information
dalechyn authored Jan 4, 2024
2 parents 7f76ca9 + 31348c5 commit 5303097
Show file tree
Hide file tree
Showing 30 changed files with 1,200 additions and 47 deletions.
8 changes: 8 additions & 0 deletions .changeset/tasty-onions-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@abstract-money/bundle-require": patch
"@abstract-money/cli": patch
"@abstract-money/cosmwasm-utils": patch
"@abstract-money/react": patch
---

Forked `bundle-require` package with the fixed peer dependency.
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,5 @@
"simple-git-hooks": {
"pre-commit": "pnpm format && pnpm lint:fix && git add -u"
},
"packageManager": "[email protected]",
"pnpm": {
"overrides": {
"esbuild": "0.15.13"
}
}
"packageManager": "[email protected]"
}
4 changes: 4 additions & 0 deletions packages/bundle-require/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules
.DS_Store
dist
*.log
21 changes: 21 additions & 0 deletions packages/bundle-require/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright © 2021 EGOIST (https://github.com/sponsors/egoist)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
55 changes: 55 additions & 0 deletions packages/bundle-require/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# @abstract-money/bundle-require

[![npm version](https://badgen.net/npm/v/@abstract-money/bundle-require)](https://npm.im/@abstract-money/bundle-require) [![npm downloads](https://badgen.net/npm/dm/@abstract-money/bundle-require)](https://npm.im/@abstract-money/bundle-require) [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/bundle-require)

## Disclaimer

This package is a fork of [egoist/bundle-require](https://github.com/egoist/bundle-require) version 3.1.2 with the corrected `esbuild` peer dependency as one breaks when used as peer in the projects that depend on the `esbuild<0.17.0`.

## Use Case

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.

## How it works

- Bundle your file with esbuild, `node_modules` are excluded because it's problematic to try to bundle it
- `__filename`, `__dirname` and `import.meta.url` are replaced with source file's value instead of the one from the temporary output file
- Output file in `esm` format if possible (for `.ts`, `.js` input files)
- Load output file with `import()` if possible
- Return the loaded module and its dependencies (imported files)

## Install

```bash
npm i @abstract-money/bundle-require esbuild
```

`esbuild` is a peer dependency.

## Usage

```ts
import { bundleRequire } from '@abstract-money/bundle-require'

const { mod } = await bundleRequire({
filepath: './project/vite.config.ts',
})
```

## API

https://www.jsdocs.io/package/@abstract-money/bundle-require

## Projects Using @abstract-money/bundle-require

Projects that use **@abstract-money/bundle-require**:

- [VuePress](https://github.com/vuejs/vuepress): :memo: Minimalistic Vue-powered static site generator.

## Sponsors

[![sponsors](https://sponsors-images.egoist.sh/sponsors.svg)](https://github.com/sponsors/egoist)

## License

MIT &copy; [EGOIST](https://github.com/sponsors/egoist)
54 changes: 54 additions & 0 deletions packages/bundle-require/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@abstract-money/bundle-require",
"version": "0.0.0",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/AbstractSDK/abstract.js.git",
"directory": "packages/bundle-require"
},
"bugs": {
"url": "https://github.com/AbstractSDK/abstract.js/issues"
},
"description": "bundle and require a file",
"publishConfig": {
"access": "public"
},
"files": [
"/dist"
],
"type": "module",
"main": "./dist/index.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsup",
"clean": "rimraf dist",
"test": "npm run build && vitest run",
"prepublishOnly": "npm run build"
},
"devDependencies": {
"@egoist/prettier-config": "1.0.0",
"@types/node": "16.11.21",
"esbuild": "0.13.15",
"prettier": "2.5.1",
"rimraf": "^3.0.0",
"typescript": "4.5.5",
"vitest": "0.2.5"
},
"dependencies": {
"load-tsconfig": "^0.2.0"
},
"peerDependencies": {
"esbuild": ">=0.13.x <= 0.16.x"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}
}
Loading

0 comments on commit 5303097

Please sign in to comment.