forked from swc-project/swc-node
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7e6c5d
commit 1ac2daf
Showing
22 changed files
with
716 additions
and
630 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.