Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to @swc-node/register the new version of @swc/register #99

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
315 changes: 233 additions & 82 deletions index.js
Expand Up @@ -263,100 +263,204 @@ var extensions = {
hook.registerTSX(config);
},
},
'.swc.js': {
module: '@swc/register',
register: function (hook, config) {
config = config || {
only: [endsInSwcJs],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'ecmascript',
'.swc.js': [
{
module: '@swc-node/register',
register: function (mod, config) {
config = config || {
only: [endsInSwcJs],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'ecmascript',
},
},
},
module: {
type: 'commonjs',
},
};
module: {
type: 'commonjs',
},
};

hook(
Object.assign({}, config, {
extensions: '.js',
})
);
mod.register(
Object.assign({}, config, {
extensions: '.js',
})
);
},
},
},
'.swc.jsx': {
module: '@swc/register',
register: function (hook, config) {
config = config || {
only: [endsInSwcJsx],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'ecmascript',
jsx: true,
{
module: '@swc/register',
register: function (hook, config) {
config = config || {
only: [endsInSwcJs],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'ecmascript',
},
},
},
module: {
type: 'commonjs',
},
};
module: {
type: 'commonjs',
},
};

console.log(hook)
codermarcos marked this conversation as resolved.
Show resolved Hide resolved

hook(
Object.assign({}, config, {
extensions: '.js',
})
);
},
}
],
'.swc.jsx': [
{
module: '@swc-node/register',
register: function (mod, config) {
config = config || {
only: [endsInSwcJsx],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'ecmascript',
jsx: true,
},
},
module: {
type: 'commonjs',
},
};

hook(
Object.assign({}, config, {
extensions: '.jsx',
})
);
mod.register(
Object.assign({}, config, {
extensions: '.jsx',
})
);
},
},
},
'.swc.ts': {
module: '@swc/register',
register: function (hook, config) {
config = config || {
only: [endsInSwcTs],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'typescript',
{
module: '@swc/register',
register: function (hook, config) {
config = config || {
only: [endsInSwcJsx],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'ecmascript',
jsx: true,
},
},
},
module: {
type: 'commonjs',
},
};
module: {
type: 'commonjs',
},
};

hook(
Object.assign({}, config, {
extensions: '.jsx',
})
);
},
}
],
'.swc.ts': [
{
module: '@swc-node/register',
register: function (mod, config) {
config = config || {
only: [endsInSwcTs],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'typescript',
},
},
module: {
type: 'commonjs',
},
};

hook(
Object.assign({}, config, {
extensions: '.ts',
})
);
mod.register(
Object.assign({}, config, {
extensions: '.ts',
})
);
},
},
},
'.swc.tsx': {
module: '@swc/register',
register: function (hook, config) {
config = config || {
only: [endsInSwcTsx],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
{
module: '@swc/register',
register: function (hook, config) {
config = config || {
only: [endsInSwcTs],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'typescript',
},
},
},
module: {
type: 'commonjs',
},
};
module: {
type: 'commonjs',
},
};

hook(
Object.assign({}, config, {
extensions: '.ts',
})
);
},
}
],
'.swc.tsx': [
{
module: '@swc-node/register',
register: function (mod, config) {
config = config || {
only: [endsInSwcTsx],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
},
},
module: {
type: 'commonjs',
},
};

hook(
Object.assign({}, config, {
extensions: '.tsx',
})
);
mod.register(
Object.assign({}, config, {
extensions: '.tsx',
})
);
},
},
},
{
module: '@swc/register',
register: function (hook, config) {
config = config || {
only: [endsInSwcTsx],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
},
},
module: {
type: 'commonjs',
},
};

hook(
Object.assign({}, config, {
extensions: '.tsx',
})
);
},
}
],
'.toml': {
module: 'toml-require',
register: function (hook, config) {
Expand Down Expand Up @@ -401,6 +505,29 @@ var extensions = {
);
},
},
{
module: '@swc-node/register',
register: function (mod, config) {
config = config || {
only: [endsInTs],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'typescript',
},
},
module: {
type: 'commonjs',
},
};

mod.register(
Object.assign({}, config, {
extensions: '.ts',
})
);
},
},
{
module: '@swc/register',
register: function (hook, config) {
Expand Down Expand Up @@ -474,6 +601,30 @@ var extensions = {
);
},
},
{
module: '@swc-node/register',
register: function (mod, config) {
config = config || {
only: [endsInTsx],
ignore: [isNodeModules],
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
},
},
module: {
type: 'commonjs',
},
};

mod.register(
Object.assign({}, config, {
extensions: '.tsx',
})
);
},
},
{
module: '@swc/register',
register: function (hook, config) {
Expand Down
1 change: 0 additions & 1 deletion scripts/plugin.mjs
@@ -1,5 +1,4 @@
import fs from 'fs';
import path from 'path';
import yaml from 'js-yaml';
import { codeImport } from 'remark-code-import';

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/swc.js/0/package.json
@@ -1,6 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
"@swc/register": "^0.1.7"
"@swc-node/register": "^1.9.0"
}
}
6 changes: 6 additions & 0 deletions test/fixtures/swc.js/1/package.json
@@ -0,0 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
"@swc/register": "^0.1.7"
}
}
14 changes: 14 additions & 0 deletions test/fixtures/swc.js/1/test.swc.js
@@ -0,0 +1,14 @@
class Foo {
#x = 1;
#y = 2;
}

export default {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1,
},
},
};
2 changes: 1 addition & 1 deletion test/fixtures/swc.jsx/0/package.json
@@ -1,6 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
"@swc/register": "^0.1.7"
"@swc-node/register": "^1.9.0"
}
}
6 changes: 6 additions & 0 deletions test/fixtures/swc.jsx/1/package.json
@@ -0,0 +1,6 @@
{
"dependencies": {
"@swc/core": "^1.2.110",
"@swc/register": "^0.1.7"
}
}