@syncify/acquire
v0.0.2
Published
File require and import helper with TS Transform support
Maintainers
Readme
@syncify/acquire
Resolves ESM and CJS config files. Based on Bundle Require by egoist, performs identical resolution with minor differences for appropriation and usage in the Syncify CLI. Supports the following extensions and file types:
.ts
.js
.cjs
.mjs
How this differs from bundle-require?
Bundle require performs some additional analysis that I did not need along with applied logic that Syncify obtains that can be used more effeciently. This variation does not perform package.json
analysis, it does not provide .tsx
or .jsx
support and module resolution is applied on the thenable
.
The return object are getters and provide access to esbuild warnings. Lastly Resolve issues throw custom errors
Installation
Peer depedency on ESBuild.
pnpm add @syncify/acquire -D
Usage
The module itself can be used in isolation in any node.js project, despite being design for usage within Syncify CLI. Similar configuration and setup bundle-require, though the following methods and options are provided.
import { acquire, $import, $tsconfig, $require } from '@syncify/acquire';
const $module = await acquire({
file: '/path/to/syncify.config.ts', // Required
cwd: process.cwd(), // Optional
type: 'module' | undefined, // Optional
named: undefined, // Optional
preserve: false, // Optional
tsconfig: '/path/to/tsconfig.json', // Optional
identifier: 'Random Name', // Optional
external: [], // Optional
extenalNodeModules: [], // Optional
noExternal: [], // Optional
onError: (errors) => [], // Optional - Bundle errors (if any)
onWarning: (errors) => [], // Optional - Bundle warnings (if any)
onRebuild: ($module) => $module // Optional - Bundle Module
})
$module // Bundle Module
// ADDITIONAL EXPORTS
$import('id') // Importy CJS/ESM
$require('id') // Import CJS
$tsconfig('path') // Resolve tsconfig.json
The module is throughly typed and annotated with JSDocs comment descriptions, which will describe each option and method in good detail.
Practical Usage
The most basic usage is as follows:
import { acquire } from '@syncify/acquire';
const config = await acquire({
file: '/path/to/syncify.config.ts',
onError: errors => console.error(...errors)
});
config; // Returns null is errors or module itself