@swc-node/register
Advanced tools
Comparing version 0.2.6 to 0.3.1
@@ -6,2 +6,12 @@ # Change Log | ||
## [0.3.1](https://github.com/Brooooooklyn/swc-node/compare/@swc-node/register@0.3.0...@swc-node/register@0.3.1) (2020-08-20) | ||
**Note:** Version bump only for package @swc-node/register | ||
## [0.3.0](https://github.com/Brooooooklyn/swc-node/compare/@swc-node/register@0.2.6...@swc-node/register@0.3.0) (2020-08-20) | ||
### BREAKING CHANGE | ||
- **register:** respect tsconfig.json in SWC_NODE_PROJECT | ||
## [0.2.6](https://github.com/Brooooooklyn/swc-node/compare/@swc-node/register@0.2.5...@swc-node/register@0.2.6) (2020-08-18) | ||
@@ -8,0 +18,0 @@ |
@@ -1,1 +0,3 @@ | ||
export function register(options: import('@swc-node/core').Options & { fallbackToTs: (path: string) => boolean }): void | ||
export function register( | ||
options: import('typescript').CompilerOptions & { fallbackToTs: (path: string) => boolean }, | ||
): void |
75
index.js
@@ -1,74 +0,3 @@ | ||
const { transformSync } = require('@swc-node/core') | ||
const { SourcemapMap, installSourceMapSupport } = require('@swc-node/sourcemap-support') | ||
const { addHook } = require('pirates') | ||
const ts = require('typescript') | ||
const { register } = require('./register') | ||
const DEFAULT_EXTENSIONS = Object.freeze(['.js', '.jsx', '.es6', '.es', '.mjs', '.ts', '.tsx', '.d.ts']) | ||
function toTsTarget(target) { | ||
switch (target) { | ||
case 'es3': | ||
return ts.ScriptTarget.ES3 | ||
case 'es5': | ||
return ts.ScriptTarget.ES5 | ||
case 'es2015': | ||
return ts.ScriptTarget.ES2015 | ||
case 'es2016': | ||
return ts.ScriptTarget.ES2016 | ||
case 'es2017': | ||
return ts.ScriptTarget.ES2017 | ||
case 'es2018': | ||
return ts.ScriptTarget.ES2018 | ||
case 'es2019': | ||
return ts.ScriptTarget.ES2019 | ||
case 'es2020': | ||
return ts.ScriptTarget.ES2020 | ||
} | ||
} | ||
function toModule(moduleKind) { | ||
switch (moduleKind) { | ||
case 'commonjs': | ||
return ts.ModuleKind.CommonJS | ||
case 'umd': | ||
return ts.ModuleKind.UMD | ||
case 'amd': | ||
return ts.ModuleKind.AMD | ||
case 'es6': | ||
return ts.ModuleKind.ES2015 | ||
} | ||
} | ||
function compile(sourcecode, filename, options) { | ||
if (options && typeof options.fallbackToTs === 'function' && options.fallbackToTs(filename)) { | ||
const ts = require('typescript') | ||
const { outputText, sourceMapText } = ts.transpileModule(sourcecode, { | ||
fileName: filename, | ||
compilerOptions: { | ||
jsx: filename.endsWith('.tsx') || filename.endsWith('.jsx') ? ts.JsxEmit.React : ts.JsxEmit.None, | ||
experimentalDecorators: Boolean(options.experimentalDecorators), | ||
emitDecoratorMetadata: Boolean(options.emitDecoratorMetadata), | ||
module: toModule(options.module || 'commonjs'), | ||
moduleResolution: ts.ModuleResolutionKind.NodeJs, | ||
sourceMap: options.sourcemap === false, | ||
target: toTsTarget(options.target || 'es2018'), | ||
esModuleInterop: true, | ||
}, | ||
}) | ||
if (sourceMapText) { | ||
SourcemapMap.set(filename, sourceMapText) | ||
} | ||
return outputText | ||
} else { | ||
const { code, map } = transformSync(sourcecode, filename, options) | ||
SourcemapMap.set(filename, map) | ||
return code | ||
} | ||
} | ||
module.exports.register = function register(options = {}) { | ||
installSourceMapSupport() | ||
addHook((code, filename) => compile(code, filename, options), { | ||
exts: DEFAULT_EXTENSIONS, | ||
}) | ||
} | ||
register() |
{ | ||
"name": "@swc-node/register", | ||
"version": "0.2.6", | ||
"version": "0.3.1", | ||
"description": "SWC node register", | ||
@@ -41,7 +41,8 @@ "keywords": [ | ||
"dependencies": { | ||
"@swc-node/core": "^0.2.6", | ||
"@swc-node/core": "^0.2.8", | ||
"@swc-node/sourcemap-support": "^0.1.7", | ||
"debug": "^4.1.1", | ||
"pirates": "^4.0.1" | ||
}, | ||
"gitHead": "50a591f13c939fd5084cb7fa337de73db240e0c0" | ||
"gitHead": "9406e55e868ed1f8dd9a9a516e875e1150444c71" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4625
4
5
1
+ Addeddebug@^4.1.1
+ Addeddebug@4.3.7(transitive)
+ Addedms@2.1.3(transitive)
Updated@swc-node/core@^0.2.8