Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Oct 9, 2024
1 parent c7e6c5d commit 1ac2daf
Show file tree
Hide file tree
Showing 22 changed files with 716 additions and 630 deletions.
183 changes: 98 additions & 85 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,102 +1,115 @@
import {
transform as swcTransform,
transformSync as swcTransformSync,
Options as SwcOptions,
ReactConfig,
Config,
JscTarget,
} from '@swc/core'
Config,
JscTarget,
ReactConfig,
Options as SwcOptions,
transform as swcTransform,
transformSync as swcTransformSync,
} from "@swc/core";

// Oldest LTS Node.js supported target
const DEFAULT_ES_TARGET: JscTarget = 'es2018'
const DEFAULT_ES_TARGET: JscTarget = "es2018";

export interface Options {
target?: JscTarget
module?: 'commonjs' | 'umd' | 'amd' | 'es6'
sourcemap?: Config['sourceMaps']
jsx?: boolean
experimentalDecorators?: boolean
emitDecoratorMetadata?: boolean
useDefineForClassFields?: boolean
dynamicImport?: boolean
esModuleInterop?: boolean
keepClassNames?: boolean
externalHelpers?: boolean
react?: Partial<ReactConfig>
baseUrl?: string
paths?: {
[from: string]: [string]
}
swc?: SwcOptions
ignoreDynamic?: boolean
target?: JscTarget;
module?: "commonjs" | "umd" | "amd" | "es6";
sourcemap?: Config["sourceMaps"];
jsx?: boolean;
experimentalDecorators?: boolean;
emitDecoratorMetadata?: boolean;
useDefineForClassFields?: boolean;
dynamicImport?: boolean;
esModuleInterop?: boolean;
keepClassNames?: boolean;
externalHelpers?: boolean;
react?: Partial<ReactConfig>;
baseUrl?: string;
paths?: {
[from: string]: [string];
};
swc?: SwcOptions;
ignoreDynamic?: boolean;
}

function transformOption(path: string, options?: Options, jest = false): SwcOptions {
const opts = options ?? {}
opts.esModuleInterop = opts.esModuleInterop ?? true
const moduleType = options?.module ?? 'commonjs'
return {
filename: path,
jsc: options?.swc?.swcrc
? undefined
: {
target: opts.target ?? DEFAULT_ES_TARGET,
externalHelpers: jest ? true : Boolean(opts.externalHelpers),
parser: {
syntax: 'typescript' as const,
tsx: typeof opts.jsx !== 'undefined' ? opts.jsx : path.endsWith('.tsx'),
decorators: Boolean(opts.experimentalDecorators),
dynamicImport: Boolean(opts.dynamicImport),
},
transform: {
legacyDecorator: Boolean(opts.experimentalDecorators),
decoratorMetadata: Boolean(opts.emitDecoratorMetadata),
useDefineForClassFields: Boolean(opts.useDefineForClassFields),
react: options?.react,
// @ts-expect-error
hidden: {
jest,
},
},
keepClassNames: opts.keepClassNames,
paths: opts.paths,
baseUrl: opts.baseUrl,
experimental: {
keepImportAttributes: true,
},
},
minify: false,
isModule: true,
module: options?.swc?.swcrc
? undefined
: {
type: moduleType,
...(moduleType === 'commonjs' || moduleType === 'umd' || moduleType === 'amd'
? {
noInterop: !opts.esModuleInterop,
ignoreDynamic: opts.ignoreDynamic,
}
: undefined),
},
sourceMaps: options?.swc?.swcrc
? undefined
: jest || typeof opts.sourcemap === 'undefined'
? 'inline'
: opts.sourcemap,
inlineSourcesContent: true,
swcrc: false,
...options?.swc,
}
function transformOption(
path: string,
options?: Options,
jest = false,
): SwcOptions {
const opts = options ?? {};
opts.esModuleInterop = opts.esModuleInterop ?? true;
const moduleType = options?.module ?? "commonjs";
return {
filename: path,
jsc: options?.swc?.swcrc
? undefined
: {
target: opts.target ?? DEFAULT_ES_TARGET,
externalHelpers: jest
? true
: Boolean(opts.externalHelpers),
parser: {
syntax: "typescript" as const,
tsx:
typeof opts.jsx !== "undefined"
? opts.jsx
: path.endsWith(".tsx"),
decorators: Boolean(opts.experimentalDecorators),
dynamicImport: Boolean(opts.dynamicImport),
},
transform: {
legacyDecorator: Boolean(opts.experimentalDecorators),
decoratorMetadata: Boolean(opts.emitDecoratorMetadata),
useDefineForClassFields: Boolean(
opts.useDefineForClassFields,
),
react: options?.react,
// @ts-expect-error
hidden: {
jest,
},
},
keepClassNames: opts.keepClassNames,
paths: opts.paths,
baseUrl: opts.baseUrl,
experimental: {
keepImportAttributes: true,
},
},
minify: false,
isModule: true,
module: options?.swc?.swcrc
? undefined
: {
type: moduleType,
...(moduleType === "commonjs" ||
moduleType === "umd" ||
moduleType === "amd"
? {
noInterop: !opts.esModuleInterop,
ignoreDynamic: opts.ignoreDynamic,
}
: undefined),
},
sourceMaps: options?.swc?.swcrc
? undefined
: jest || typeof opts.sourcemap === "undefined"
? "inline"
: opts.sourcemap,
inlineSourcesContent: true,
swcrc: false,
...options?.swc,
};
}

export function transformSync(source: string, path: string, options?: Options) {
return swcTransformSync(source, transformOption(path, options))
return swcTransformSync(source, transformOption(path, options));
}

export function transformJest(source: string, path: string, options?: Options) {
return swcTransformSync(source, transformOption(path, options, true))
return swcTransformSync(source, transformOption(path, options, true));
}

export function transform(source: string, path: string, options?: Options) {
return swcTransform(source, transformOption(path, options))
return swcTransform(source, transformOption(path, options));
}
18 changes: 9 additions & 9 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "@swc-node/core",
"description": "Faster swc nodejs binding",
"devDependencies": {
"@swc/core": "1.7.26",
"@swc/types": "0.1.12"
},
"files": [
"lib"
],
"funding": {
"type": "github",
"url": "https://github.com/sponsors/Brooooooklyn"
},
"main": "lib/index.js",
"name": "@swc-node/core",
"typings": "lib/index.d.ts"
"typings": "lib/index.d.ts",
"files": [
"lib"
],
"devDependencies": {
"@swc/core": "1.7.26",
"@swc/types": "0.1.12"
}
}
16 changes: 8 additions & 8 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"rootDir": ".",
"outDir": "./lib",
},
"include": ["."],
"exclude": ["./lib"],
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"rootDir": ".",
"outDir": "./lib"
},
"include": ["."],
"exclude": ["./lib"]
}
4 changes: 2 additions & 2 deletions packages/integrate-module/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "integrate-module",
"dependencies": {
"file-type": "19.5.0",
"p-timeout": "6.1.2"
Expand All @@ -11,6 +12,5 @@
"ipaddr.js": "2.2.0",
"postgres": "3.4.4",
"simple-git": "3.27.0"
},
"name": "integrate-module"
}
}
26 changes: 13 additions & 13 deletions packages/integrate-module/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"composite": true,
"jsx": "react-jsx",
"outDir": "dist",
"baseUrl": "./",
"paths": {
"@subdirectory/*": ["./src/subdirectory/*"]
}
},
"include": ["src", "package.json"]
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"composite": true,
"jsx": "react-jsx",
"outDir": "dist",
"baseUrl": "./",
"paths": {
"@subdirectory/*": ["./src/subdirectory/*"]
}
},
"include": ["src", "package.json"]
}
4 changes: 2 additions & 2 deletions packages/integrate/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@swc-node/integrate",
"description": "Integrate testing",
"devDependencies": {
"@swc-node/core": "1.13.3",
"@swc-node/register": "workspace:*",
"@swc/helpers": "0.5.13",
"sinon": "19.0.2"
},
"name": "@swc-node/integrate"
}
}
40 changes: 20 additions & 20 deletions packages/integrate/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"rootDir": ".",
"outDir": "./lib",
"jsx": "react-jsx",
"types": ["node", "jest"],
"allowImportingTsExtensions": true
},
"references": [
{
"path": "../core"
},
{
"path": "../register"
}
],
"include": ["."],
"files": ["./package.json"],
"exclude": ["lib"]
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"rootDir": ".",
"outDir": "./lib",
"jsx": "react-jsx",
"types": ["node", "jest"],
"allowImportingTsExtensions": true
},
"references": [
{
"path": "../core"
},
{
"path": "../register"
}
],
"include": ["."],
"files": ["./package.json"],
"exclude": ["lib"]
}
4 changes: 3 additions & 1 deletion packages/jest/jest-preset.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports = { transform: { '^.+\\.((m|c)?t|(m|c)?j)sx?$': '@swc-node/jest' } }
module.exports = {
transform: { "^.+\\.((m|c)?t|(m|c)?j)sx?$": "@swc-node/jest" },
};
26 changes: 13 additions & 13 deletions packages/jest/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"dependencies": {
"@node-rs/xxhash": "1.7.4",
"@swc-node/core": "1.13.3",
"@swc-node/register": "1.10.9"
},
"name": "@swc-node/jest",
"description": "swc preprocessor for jest with source map support",
"devDependencies": {
"@swc/core": "1.7.26",
"@swc/types": "0.1.12"
"funding": {
"type": "github",
"url": "https://github.com/sponsors/Brooooooklyn"
},
"main": "./lib/index.js",
"files": [
"lib",
"jest-preset.js",
"LICENSE"
],
"funding": {
"type": "github",
"url": "https://github.com/sponsors/Brooooooklyn"
"dependencies": {
"@node-rs/xxhash": "1.7.4",
"@swc-node/core": "1.13.3",
"@swc-node/register": "1.10.9"
},
"main": "./lib/index.js",
"name": "@swc-node/jest"
"devDependencies": {
"@swc/core": "1.7.26",
"@swc/types": "0.1.12"
}
}
Loading

0 comments on commit 1ac2daf

Please sign in to comment.