Comparing version 0.1.2 to 0.1.3
67
index.js
@@ -13,20 +13,55 @@ "use strict"; | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var fs = __importStar(require("fs")); | ||
var path = __importStar(require("path")); | ||
var core_1 = require("@swc/core"); | ||
var transformOpts; | ||
function set(obj, path, value) { | ||
var o = obj; | ||
var parents = path.split('.'); | ||
var key = parents.pop(); | ||
for (var _i = 0, parents_1 = parents; _i < parents_1.length; _i++) { | ||
var prop = parents_1[_i]; | ||
if (o[prop] == null) | ||
o[prop] = {}; | ||
o = o[prop]; | ||
} | ||
o[key] = value; | ||
} | ||
module.exports = { | ||
process: function (src, path, jestConfig) { | ||
var _a = (jestConfig.transform || []).find(function (_a) { | ||
var transformerPath = _a[1]; | ||
return transformerPath === __filename; | ||
}) || [], _b = _a[2], transformOptions = _b === void 0 ? {} : _b; | ||
if (/\.(t|j)sx?$/.test(path)) { | ||
return core_1.transformSync(src, __assign(__assign({}, transformOptions), { filename: path, jsc: { | ||
transform: { | ||
//@ts-ignore | ||
hidden: { | ||
jest: true | ||
} | ||
}, | ||
}, module: { | ||
type: "commonjs" | ||
} })); | ||
process: function (src, filename, jestConfig) { | ||
if (/\.(t|j)sx?$/.test(filename)) { | ||
if (!transformOpts) { | ||
var isSwcJestTransformer = function (_a) { | ||
var transformerPath = _a[1]; | ||
return transformerPath === __filename; | ||
}; | ||
var _a = (jestConfig.transform || []).find(isSwcJestTransformer) || [], swcOptions = _a[2]; | ||
if (!swcOptions) { | ||
var swcrc = path.join(process.cwd(), '.swcrc'); | ||
swcOptions = fs.existsSync(swcrc) ? JSON.parse(fs.readFileSync(swcrc, 'utf-8')) : {}; | ||
} | ||
set(swcOptions, 'module.type', 'commonjs'); | ||
set(swcOptions, 'jsc.transform.hidden.jest', true); | ||
transformOpts = swcOptions; | ||
} | ||
return core_1.transformSync(src, __assign(__assign({}, transformOpts), { filename: filename })); | ||
} | ||
@@ -33,0 +68,0 @@ return src; |
{ | ||
"name": "@swc/jest", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "swc integration for jest", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,6 +17,7 @@ # @swc/jest | ||
`jest.config.js`: | ||
``` | ||
module.exports = { | ||
transform: { | ||
'^.+\\.(t|j)sx?$': ['@swc/jest'], | ||
'^.+\\.(t|j)sx?$': '@swc/jest', | ||
}, | ||
@@ -26,2 +27,12 @@ } | ||
It will load swc configuration from `.swcrc` in default. You also can custom it: | ||
``` | ||
module.exports = { | ||
transform: { | ||
'^.+\\.(t|j)sx?$': ['@swc/jest', {/* you swc configuration */}], | ||
}, | ||
} | ||
``` | ||
## License | ||
@@ -28,0 +39,0 @@ |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
3897
69
41
2