esbuild-jest
Advanced tools
Comparing version 0.4.0 to 0.5.0-beta.1
@@ -0,1 +1,2 @@ | ||
import { Transformer } from '@jest/transform'; | ||
import { Loader } from 'esbuild'; | ||
@@ -13,9 +14,6 @@ | ||
} | ||
declare const createTransformer: (options?: Options) => { | ||
process(content: string, filename: string): { | ||
code: string; | ||
map: string; | ||
}; | ||
}; | ||
export { Options, createTransformer }; | ||
declare const transformer: Pick<Transformer, 'canInstrument' | 'createTransformer'>; | ||
export default transformer; | ||
export { Options }; |
@@ -0,4 +1,29 @@ | ||
import path, { extname } from 'path'; | ||
import { transformSync } from 'esbuild'; | ||
import path, { extname } from 'path'; | ||
import babelJest from 'babel-jest'; | ||
const { process } = babelJest.createTransformer({ | ||
plugins: [ | ||
"@babel/plugin-transform-modules-commonjs" | ||
], | ||
parserOpts: { | ||
plugins: [ | ||
"jsx", | ||
"typescript" | ||
] | ||
} | ||
}); | ||
function babelTransform(opts) { | ||
const { sourceText , sourcePath , config , options } = opts; | ||
const babelResult = process(sourceText, sourcePath, config, options); | ||
return babelResult.code; | ||
} | ||
const loaders = [ | ||
"js", | ||
"jsx", | ||
"ts", | ||
"tsx", | ||
"json" | ||
]; | ||
const getExt = (str)=>{ | ||
@@ -8,11 +33,15 @@ const basename = path.basename(str); | ||
const lastDot = basename.lastIndexOf('.'); | ||
const extname1 = path.extname(basename).replace(/(\.[a-z0-9]+).*/i, '$1'); | ||
if (firstDot === lastDot) return extname1; | ||
return basename.slice(firstDot, lastDot) + extname1; | ||
const extname = path.extname(basename).replace(/(\.[a-z0-9]+).*/i, '$1'); | ||
if (firstDot === lastDot) return extname; | ||
return basename.slice(firstDot, lastDot) + extname; | ||
}; | ||
const createTransformer = (options)=>({ | ||
process (content, filename) { | ||
process (content, filename, config, opts) { | ||
const sources = { | ||
code: content | ||
}; | ||
const ext = getExt(filename), extName = extname(filename).slice(1); | ||
const enableSourcemaps = (options === null || options === void 0 ? void 0 : options.sourcemap) || false; | ||
const ext = getExt(filename); | ||
const loader = (options === null || options === void 0 ? void 0 : options.loaders) && (options === null || options === void 0 ? void 0 : options.loaders[ext]) ? options.loaders[ext] : extname(filename).slice(1); | ||
const loader = (options === null || options === void 0 ? void 0 : options.loaders) && (options === null || options === void 0 ? void 0 : options.loaders[ext]) ? options.loaders[ext] : loaders.includes(extName) ? extName : 'text'; | ||
const sourcemaps = enableSourcemaps ? { | ||
@@ -24,3 +53,16 @@ sourcemap: true, | ||
}; | ||
const result = transformSync(content, { | ||
/// this logic or code from | ||
/// https://github.com/threepointone/esjest-transform/blob/main/src/index.js | ||
/// this will supoort the jest.mock | ||
/// https://github.com/aelbore/esbuild-jest/issues/12 | ||
if (sources.code.indexOf("ock(") >= 0 || (opts === null || opts === void 0 ? void 0 : opts.instrument)) { | ||
const source = babelTransform({ | ||
sourceText: content, | ||
sourcePath: filename, | ||
config, | ||
options: opts | ||
}); | ||
sources.code = source; | ||
} | ||
const result = transformSync(sources.code, { | ||
loader, | ||
@@ -58,3 +100,7 @@ format: (options === null || options === void 0 ? void 0 : options.format) || 'cjs', | ||
; | ||
const transformer = { | ||
canInstrument: true, | ||
createTransformer | ||
}; | ||
export { createTransformer }; | ||
export default transformer; |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var path = require('path'); | ||
var esbuild = require('esbuild'); | ||
var path = require('path'); | ||
var babelJest = require('babel-jest'); | ||
@@ -11,3 +10,28 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var path__default = /*#__PURE__*/_interopDefaultLegacy(path); | ||
var babelJest__default = /*#__PURE__*/_interopDefaultLegacy(babelJest); | ||
const { process } = babelJest__default['default'].createTransformer({ | ||
plugins: [ | ||
"@babel/plugin-transform-modules-commonjs" | ||
], | ||
parserOpts: { | ||
plugins: [ | ||
"jsx", | ||
"typescript" | ||
] | ||
} | ||
}); | ||
function babelTransform(opts) { | ||
const { sourceText , sourcePath , config , options } = opts; | ||
const babelResult = process(sourceText, sourcePath, config, options); | ||
return babelResult.code; | ||
} | ||
const loaders = [ | ||
"js", | ||
"jsx", | ||
"ts", | ||
"tsx", | ||
"json" | ||
]; | ||
const getExt = (str)=>{ | ||
@@ -17,11 +41,15 @@ const basename = path__default['default'].basename(str); | ||
const lastDot = basename.lastIndexOf('.'); | ||
const extname1 = path__default['default'].extname(basename).replace(/(\.[a-z0-9]+).*/i, '$1'); | ||
if (firstDot === lastDot) return extname1; | ||
return basename.slice(firstDot, lastDot) + extname1; | ||
const extname = path__default['default'].extname(basename).replace(/(\.[a-z0-9]+).*/i, '$1'); | ||
if (firstDot === lastDot) return extname; | ||
return basename.slice(firstDot, lastDot) + extname; | ||
}; | ||
const createTransformer = (options)=>({ | ||
process (content, filename) { | ||
process (content, filename, config, opts) { | ||
const sources = { | ||
code: content | ||
}; | ||
const ext = getExt(filename), extName = path.extname(filename).slice(1); | ||
const enableSourcemaps = (options === null || options === void 0 ? void 0 : options.sourcemap) || false; | ||
const ext = getExt(filename); | ||
const loader = (options === null || options === void 0 ? void 0 : options.loaders) && (options === null || options === void 0 ? void 0 : options.loaders[ext]) ? options.loaders[ext] : path.extname(filename).slice(1); | ||
const loader = (options === null || options === void 0 ? void 0 : options.loaders) && (options === null || options === void 0 ? void 0 : options.loaders[ext]) ? options.loaders[ext] : loaders.includes(extName) ? extName : 'text'; | ||
const sourcemaps = enableSourcemaps ? { | ||
@@ -33,3 +61,16 @@ sourcemap: true, | ||
}; | ||
const result = esbuild.transformSync(content, { | ||
/// this logic or code from | ||
/// https://github.com/threepointone/esjest-transform/blob/main/src/index.js | ||
/// this will supoort the jest.mock | ||
/// https://github.com/aelbore/esbuild-jest/issues/12 | ||
if (sources.code.indexOf("ock(") >= 0 || (opts === null || opts === void 0 ? void 0 : opts.instrument)) { | ||
const source = babelTransform({ | ||
sourceText: content, | ||
sourcePath: filename, | ||
config, | ||
options: opts | ||
}); | ||
sources.code = source; | ||
} | ||
const result = esbuild.transformSync(sources.code, { | ||
loader, | ||
@@ -67,3 +108,7 @@ format: (options === null || options === void 0 ? void 0 : options.format) || 'cjs', | ||
; | ||
const transformer = { | ||
canInstrument: true, | ||
createTransformer | ||
}; | ||
exports.createTransformer = createTransformer; | ||
module.exports = transformer; |
{ | ||
"name": "esbuild-jest", | ||
"version": "0.4.0", | ||
"version": "0.5.0-beta.1", | ||
"description": "Jest plugin to use esbuild for transformation", | ||
@@ -24,4 +24,9 @@ "main": "esbuild-jest.js", | ||
"peerDependencies": { | ||
"esbuild": ">=0.8.36" | ||
"esbuild": ">=0.8.49" | ||
}, | ||
"dependencies": { | ||
"@babel/core": "^7.12.17", | ||
"@babel/plugin-transform-modules-commonjs": "^7.12.13", | ||
"babel-jest": "^26.6.3" | ||
} | ||
} |
@@ -8,2 +8,4 @@ # esbuild-jest | ||
| Note: Jest mocks are not currently supported, for more information see https://github.com/aelbore/esbuild-jest/issues/12 and https://github.com/evanw/esbuild/issues/412 | ||
## Install | ||
@@ -10,0 +12,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
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
10433
217
61
4
+ Added@babel/core@^7.12.17
+ Addedbabel-jest@^26.6.3
+ Added@ampproject/remapping@2.3.0(transitive)
+ Added@babel/code-frame@7.24.7(transitive)
+ Added@babel/compat-data@7.25.4(transitive)
+ Added@babel/core@7.25.2(transitive)
+ Added@babel/generator@7.25.6(transitive)
+ Added@babel/helper-compilation-targets@7.25.2(transitive)
+ Added@babel/helper-module-imports@7.24.7(transitive)
+ Added@babel/helper-module-transforms@7.25.2(transitive)
+ Added@babel/helper-plugin-utils@7.24.8(transitive)
+ Added@babel/helper-simple-access@7.24.7(transitive)
+ Added@babel/helper-string-parser@7.24.8(transitive)
+ Added@babel/helper-validator-identifier@7.24.7(transitive)
+ Added@babel/helper-validator-option@7.24.8(transitive)
+ Added@babel/helpers@7.25.6(transitive)
+ Added@babel/highlight@7.24.7(transitive)
+ Added@babel/parser@7.25.6(transitive)
+ Added@babel/plugin-syntax-async-generators@7.8.4(transitive)
+ Added@babel/plugin-syntax-bigint@7.8.3(transitive)
+ Added@babel/plugin-syntax-class-properties@7.12.13(transitive)
+ Added@babel/plugin-syntax-class-static-block@7.14.5(transitive)
+ Added@babel/plugin-syntax-import-attributes@7.25.6(transitive)
+ Added@babel/plugin-syntax-import-meta@7.10.4(transitive)
+ Added@babel/plugin-syntax-json-strings@7.8.3(transitive)
+ Added@babel/plugin-syntax-logical-assignment-operators@7.10.4(transitive)
+ Added@babel/plugin-syntax-nullish-coalescing-operator@7.8.3(transitive)
+ Added@babel/plugin-syntax-numeric-separator@7.10.4(transitive)
+ Added@babel/plugin-syntax-object-rest-spread@7.8.3(transitive)
+ Added@babel/plugin-syntax-optional-catch-binding@7.8.3(transitive)
+ Added@babel/plugin-syntax-optional-chaining@7.8.3(transitive)
+ Added@babel/plugin-syntax-private-property-in-object@7.14.5(transitive)
+ Added@babel/plugin-syntax-top-level-await@7.14.5(transitive)
+ Added@babel/plugin-transform-modules-commonjs@7.24.8(transitive)
+ Added@babel/template@7.25.0(transitive)
+ Added@babel/traverse@7.25.6(transitive)
+ Added@babel/types@7.25.6(transitive)
+ Added@cnakazawa/watch@1.0.4(transitive)
+ Added@istanbuljs/load-nyc-config@1.1.0(transitive)
+ Added@istanbuljs/schema@0.1.3(transitive)
+ Added@jest/transform@26.6.2(transitive)
+ Added@jest/types@26.6.2(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Added@types/babel__core@7.20.5(transitive)
+ Added@types/babel__generator@7.6.8(transitive)
+ Added@types/babel__template@7.4.4(transitive)
+ Added@types/babel__traverse@7.20.6(transitive)
+ Added@types/graceful-fs@4.1.9(transitive)
+ Added@types/istanbul-lib-coverage@2.0.6(transitive)
+ Added@types/istanbul-lib-report@3.0.3(transitive)
+ Added@types/istanbul-reports@3.0.4(transitive)
+ Added@types/node@22.5.5(transitive)
+ Added@types/yargs@15.0.19(transitive)
+ Added@types/yargs-parser@21.0.3(transitive)
+ Addedansi-styles@3.2.14.3.0(transitive)
+ Addedanymatch@2.0.03.1.3(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedarr-diff@4.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedarray-unique@0.3.2(transitive)
+ Addedassign-symbols@1.0.0(transitive)
+ Addedatob@2.1.2(transitive)
+ Addedbabel-jest@26.6.3(transitive)
+ Addedbabel-plugin-istanbul@6.1.1(transitive)
+ Addedbabel-plugin-jest-hoist@26.6.2(transitive)
+ Addedbabel-preset-current-node-syntax@1.1.0(transitive)
+ Addedbabel-preset-jest@26.6.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase@0.11.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbraces@2.3.23.0.3(transitive)
+ Addedbrowserslist@4.23.3(transitive)
+ Addedbser@2.1.1(transitive)
+ Addedcache-base@1.0.1(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedcaniuse-lite@1.0.30001660(transitive)
+ Addedcapture-exit@2.0.0(transitive)
+ Addedchalk@2.4.24.1.2(transitive)
+ Addedci-info@2.0.0(transitive)
+ Addedclass-utils@0.3.6(transitive)
+ Addedcollection-visit@1.0.0(transitive)
+ Addedcolor-convert@1.9.32.0.1(transitive)
+ Addedcolor-name@1.1.31.1.4(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconvert-source-map@1.9.02.0.0(transitive)
+ Addedcopy-descriptor@0.1.1(transitive)
+ Addedcross-spawn@6.0.5(transitive)
+ Addeddebug@2.6.94.3.7(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddefine-property@0.2.51.0.02.0.2(transitive)
+ Addedelectron-to-chromium@1.5.24(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedexec-sh@0.3.6(transitive)
+ Addedexeca@1.0.0(transitive)
+ Addedexpand-brackets@2.1.4(transitive)
+ Addedextend-shallow@2.0.13.0.2(transitive)
+ Addedextglob@2.0.4(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfb-watchman@2.0.2(transitive)
+ Addedfill-range@4.0.07.1.1(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfragment-cache@0.2.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedgensync@1.0.0-beta.2(transitive)
+ Addedget-package-type@0.1.0(transitive)
+ Addedget-stream@4.1.0(transitive)
+ Addedget-value@2.0.6(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglobals@11.12.0(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-flag@3.0.04.0.0(transitive)
+ Addedhas-value@0.3.11.0.0(transitive)
+ Addedhas-values@0.1.41.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedimurmurhash@0.1.4(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-accessor-descriptor@1.0.1(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-ci@2.0.0(transitive)
+ Addedis-data-descriptor@1.0.1(transitive)
+ Addedis-descriptor@0.1.71.0.3(transitive)
+ Addedis-extendable@0.1.11.0.1(transitive)
+ Addedis-number@3.0.07.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedisobject@2.1.03.0.1(transitive)
+ Addedistanbul-lib-coverage@3.2.2(transitive)
+ Addedistanbul-lib-instrument@5.2.1(transitive)
+ Addedjest-haste-map@26.6.2(transitive)
+ Addedjest-regex-util@26.0.0(transitive)
+ Addedjest-serializer@26.6.2(transitive)
+ Addedjest-util@26.6.2(transitive)
+ Addedjest-worker@26.6.2(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedjsesc@2.5.2(transitive)
+ Addedjson5@2.2.3(transitive)
+ Addedkind-of@3.2.24.0.06.0.3(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedlru-cache@5.1.1(transitive)
+ Addedmakeerror@1.0.12(transitive)
+ Addedmap-cache@0.2.2(transitive)
+ Addedmap-visit@1.0.0(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addedmicromatch@3.1.104.0.8(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmixin-deep@1.3.2(transitive)
+ Addedms@2.0.02.1.3(transitive)
+ Addednanomatch@1.2.13(transitive)
+ Addednice-try@1.0.5(transitive)
+ Addednode-int64@0.4.0(transitive)
+ Addednode-releases@2.0.18(transitive)
+ Addednormalize-path@2.1.13.0.0(transitive)
+ Addednpm-run-path@2.0.2(transitive)
+ Addedobject-copy@0.1.0(transitive)
+ Addedobject-visit@1.0.1(transitive)
+ Addedobject.pick@1.3.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpascalcase@0.1.1(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedpicocolors@1.1.0(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedpirates@4.0.6(transitive)
+ Addedposix-character-classes@0.1.1(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedregex-not@1.0.2(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedresolve-from@5.0.0(transitive)
+ Addedresolve-url@0.2.1(transitive)
+ Addedret@0.1.15(transitive)
+ Addedrsvp@4.8.5(transitive)
+ Addedsafe-regex@1.1.0(transitive)
+ Addedsane@4.1.0(transitive)
+ Addedsemver@5.7.26.3.1(transitive)
+ Addedset-value@2.0.1(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedslash@3.0.0(transitive)
+ Addedsnapdragon@0.8.2(transitive)
+ Addedsnapdragon-node@2.1.1(transitive)
+ Addedsnapdragon-util@3.0.1(transitive)
+ Addedsource-map@0.5.70.6.1(transitive)
+ Addedsource-map-resolve@0.5.3(transitive)
+ Addedsource-map-url@0.4.1(transitive)
+ Addedsplit-string@3.1.0(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedstatic-extend@0.1.2(transitive)
+ Addedstrip-eof@1.0.0(transitive)
+ Addedsupports-color@5.5.07.2.0(transitive)
+ Addedtest-exclude@6.0.0(transitive)
+ Addedtmpl@1.0.5(transitive)
+ Addedto-fast-properties@2.0.0(transitive)
+ Addedto-object-path@0.3.0(transitive)
+ Addedto-regex@3.0.2(transitive)
+ Addedto-regex-range@2.1.15.0.1(transitive)
+ Addedtypedarray-to-buffer@3.1.5(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedunion-value@1.0.1(transitive)
+ Addedunset-value@1.0.0(transitive)
+ Addedupdate-browserslist-db@1.1.0(transitive)
+ Addedurix@0.1.0(transitive)
+ Addeduse@3.1.1(transitive)
+ Addedwalker@1.0.8(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedwrite-file-atomic@3.0.3(transitive)
+ Addedyallist@3.1.1(transitive)