register
register copied to clipboard
Ability to pass custom options
If I understand correctly swc-register will at the moment use .swcrc for options. Could we have ability to pass custom options in code API similar to @babel/register: https://babeljs.io/docs/en/babel-register/#specifying-options
register(); <---------
function register(opts) {
if (opts === void 0) { opts = {}; }
// Clone to avoid mutating the arguments object with the 'delete's below.
opts = __assign({}, opts);
hookExtensions(opts.extensions || swc.DEFAULT_EXTENSIONS);
delete opts.extensions;
transformOpts = __assign(__assign({}, opts), { caller: __assign({ name: "@swc/register" }, (opts.caller || {})) });
var _a = transformOpts.cwd, cwd = _a === void 0 ? "." : _a;
// Ensure that the working directory is resolved up front so that
// things don't break if it changes later.
cwd = transformOpts.cwd = path_1.default.resolve(cwd);
if (transformOpts.ignore === undefined && transformOpts.only === undefined) {
transformOpts.only = [
// Only compile things inside the current working directory.
new RegExp("^" + lodash_escaperegexp_1.default(cwd), "i")
];
transformOpts.ignore = [
// Ignore any node_modules inside the current working directory.
new RegExp("^" +
lodash_escaperegexp_1.default(cwd) +
"(?:" +
path_1.default.sep +
".*)?" +
lodash_escaperegexp_1.default(path_1.default.sep + "node_modules" + path_1.default.sep), "i")
];
}
}
exports.default = register;
There currently appears to be a way by using the default export, but the register function is always called on import which might be problematic.
Just looked and realized you can already do this. Here's the PR that docs it: https://github.com/swc-project/register/pull/15/files
Close this?
It's possible but the types in d.ts are incorrect
https://unpkg.com/browse/@swc/[email protected]/lib/index.d.ts
index.d.ts shows export {} but it should be something like export function register(options?: InputOptions)
Hey folks! Its been a while, are you still supporting this package?
In case you need example of register.d.ts
import type { Swcrc } from '@swc/core'
declare module '@swc/register' {
export default function register(options?: Swcrc): void
}
Hello everyone, does the "swc-node" support custom options?