Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esbuild-jest

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-jest - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0-beta.1

10

esbuild-jest.d.ts

@@ -13,7 +13,9 @@ import { Loader } from 'esbuild';

}
declare function process(content: string, filename: string, config: any): {
code: string;
map: any;
declare const createTransformer: (options?: Options) => {
process(content: string, filename: string): {
code: string;
map: string;
};
};
export { Options, process };
export { Options, createTransformer };

91

esbuild-jest.es.js
import { transformSync } from 'esbuild';
import path2, { extname } from 'path';
import path, { extname } from 'path';
const getExt = (str) => {
const basename = path2.basename(str);
const firstDot = basename.indexOf(".");
const lastDot = basename.lastIndexOf(".");
const extname2 = path2.extname(basename).replace(/(\.[a-z0-9]+).*/i, "$1");
if (firstDot === lastDot)
return extname2;
return basename.slice(firstDot, lastDot) + extname2;
const getExt = (str)=>{
const basename = path.basename(str);
const firstDot = basename.indexOf('.');
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 getOptions = (config) => {
let options = {};
for (let i = 0; i < config.transform.length; i++) {
options = config.transform[i][2];
}
return options;
};
function process(content, filename, config) {
const options = getOptions(config);
const ext = getExt(filename);
const loader = (options == null ? void 0 : options.loaders) && (options == null ? void 0 : options.loaders[ext]) ? options.loaders[ext] : extname(filename).slice(1);
const sourcemaps = (options == null ? void 0 : options.sourcemap) ? {sourcemap: true, sourcefile: filename} : {};
const result = transformSync(content, {
loader,
format: (options == null ? void 0 : options.format) || "cjs",
target: (options == null ? void 0 : options.target) || "es2018",
...(options == null ? void 0 : options.jsxFactory) ? {jsxFactory: options.jsxFactory} : {},
...(options == null ? void 0 : options.jsxFragment) ? {jsxFragment: options.jsxFragment} : {},
...sourcemaps
});
return {
code: result.code,
map: (result == null ? void 0 : result.map) ? {
...JSON.parse(result.map),
sourcesContent: null
} : ""
};
}
const createTransformer = (options)=>({
process (content, filename) {
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 sourcemaps = enableSourcemaps ? {
sourcemap: true,
sourcesContent: false,
sourcefile: filename
} : {
};
const result = transformSync(content, {
loader,
format: (options === null || options === void 0 ? void 0 : options.format) || 'cjs',
target: (options === null || options === void 0 ? void 0 : options.target) || 'es2018',
...(options === null || options === void 0 ? void 0 : options.jsxFactory) ? {
jsxFactory: options.jsxFactory
} : {
},
...(options === null || options === void 0 ? void 0 : options.jsxFragment) ? {
jsxFragment: options.jsxFragment
} : {
},
...sourcemaps
});
let { map , code } = result;
if (enableSourcemaps) {
map = {
...JSON.parse(result.map),
sourcesContent: null
};
// Append the inline sourcemap manually to ensure the "sourcesContent"
// is null. Otherwise, breakpoints won't pause within the actual source.
code = code + '\n//# sourceMappingURL=data:application/json;base64,' + Buffer.from(JSON.stringify(map)).toString('base64');
} else {
map = null;
}
return {
code,
map
};
}
})
;
export { process };
export { createTransformer };

@@ -6,46 +6,61 @@ 'use strict';

var esbuild = require('esbuild');
var path2 = require('path');
var path = require('path');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var path2__default = /*#__PURE__*/_interopDefaultLegacy(path2);
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
const getExt = (str) => {
const basename = path2__default['default'].basename(str);
const firstDot = basename.indexOf(".");
const lastDot = basename.lastIndexOf(".");
const extname2 = path2__default['default'].extname(basename).replace(/(\.[a-z0-9]+).*/i, "$1");
if (firstDot === lastDot)
return extname2;
return basename.slice(firstDot, lastDot) + extname2;
const getExt = (str)=>{
const basename = path__default['default'].basename(str);
const firstDot = basename.indexOf('.');
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 getOptions = (config) => {
let options = {};
for (let i = 0; i < config.transform.length; i++) {
options = config.transform[i][2];
}
return options;
};
function process(content, filename, config) {
const options = getOptions(config);
const ext = getExt(filename);
const loader = (options == null ? void 0 : options.loaders) && (options == null ? void 0 : options.loaders[ext]) ? options.loaders[ext] : path2.extname(filename).slice(1);
const sourcemaps = (options == null ? void 0 : options.sourcemap) ? {sourcemap: true, sourcefile: filename} : {};
const result = esbuild.transformSync(content, {
loader,
format: (options == null ? void 0 : options.format) || "cjs",
target: (options == null ? void 0 : options.target) || "es2018",
...(options == null ? void 0 : options.jsxFactory) ? {jsxFactory: options.jsxFactory} : {},
...(options == null ? void 0 : options.jsxFragment) ? {jsxFragment: options.jsxFragment} : {},
...sourcemaps
});
return {
code: result.code,
map: (result == null ? void 0 : result.map) ? {
...JSON.parse(result.map),
sourcesContent: null
} : ""
};
}
const createTransformer = (options)=>({
process (content, filename) {
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 sourcemaps = enableSourcemaps ? {
sourcemap: true,
sourcesContent: false,
sourcefile: filename
} : {
};
const result = esbuild.transformSync(content, {
loader,
format: (options === null || options === void 0 ? void 0 : options.format) || 'cjs',
target: (options === null || options === void 0 ? void 0 : options.target) || 'es2018',
...(options === null || options === void 0 ? void 0 : options.jsxFactory) ? {
jsxFactory: options.jsxFactory
} : {
},
...(options === null || options === void 0 ? void 0 : options.jsxFragment) ? {
jsxFragment: options.jsxFragment
} : {
},
...sourcemaps
});
let { map , code } = result;
if (enableSourcemaps) {
map = {
...JSON.parse(result.map),
sourcesContent: null
};
// Append the inline sourcemap manually to ensure the "sourcesContent"
// is null. Otherwise, breakpoints won't pause within the actual source.
code = code + '\n//# sourceMappingURL=data:application/json;base64,' + Buffer.from(JSON.stringify(map)).toString('base64');
} else {
map = null;
}
return {
code,
map
};
}
})
;
exports.process = process;
exports.createTransformer = createTransformer;
{
"name": "esbuild-jest",
"version": "0.3.0",
"version": "0.4.0-beta.1",
"description": "Jest plugin to use esbuild for transformation",

@@ -24,4 +24,4 @@ "main": "esbuild-jest.js",

"peerDependencies": {
"esbuild": ">=0.8.16"
"esbuild": ">=0.8.36"
}
}

@@ -46,3 +46,3 @@ # esbuild-jest

{
sourcemap: false,
sourcemap: true,
loaders: {

@@ -59,1 +59,2 @@ '.spec.ts': 'tsx'

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc