Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Ability to pass custom options #6

Open
pbadenski opened this issue Mar 29, 2021 · 5 comments
Open

Ability to pass custom options #6

pbadenski opened this issue Mar 29, 2021 · 5 comments

Comments

@pbadenski
Copy link

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

@vjpr
Copy link

vjpr commented Aug 23, 2021

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.

@psugihara
Copy link

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?

@elado
Copy link

elado commented Oct 4, 2022

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)

@ilovepixelart
Copy link

ilovepixelart commented Dec 13, 2022

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
}

@Tarrowren
Copy link

Hello everyone, does the "swc-node" support custom options?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

6 participants