@istanbuljs/esm-loader-hook
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.1.2](https://github.com/istanbuljs/esm-loader-hook/compare/v0.1.1...v0.1.2) (2020-05-31) | ||
### Bug Fixes | ||
* Prepare for ESM loader hooks moving to worker threads. ([#3](https://github.com/istanbuljs/esm-loader-hook/issues/3)) ([8105a8f](https://github.com/istanbuljs/esm-loader-hook/commit/8105a8f110321e5d2c76e01e59c36a13b7f14162)) | ||
### 0.1.1 (2020-05-20) | ||
@@ -7,0 +14,0 @@ |
20
index.js
@@ -18,5 +18,5 @@ import {fileURLToPath} from 'url'; | ||
export async function transformSource(source, context) { | ||
if (loader.isLoading()) { | ||
return {source}; | ||
export async function transformSource(source, context, defaultTransformSource) { | ||
if (context.format !== 'module' || loader.isLoading()) { | ||
return defaultTransformSource(source, context, defaultTransformSource); | ||
} | ||
@@ -45,14 +45,12 @@ | ||
if (Buffer.isBuffer(source)) { | ||
source = source.toString(); | ||
} else if (typeof source !== 'string') { | ||
return {source}; | ||
} | ||
const filename = fileURLToPath(context.url); | ||
/* babel-plugin-istanbul does this but the early check optimizes */ | ||
if (!testExclude.shouldInstrument(filename)) { | ||
return {source}; | ||
return defaultTransformSource(source, context, defaultTransformSource); | ||
} | ||
if (typeof source !== 'string') { | ||
source = new TextDecoder().decode(source); | ||
} | ||
/* Can/should this handle inputSourceMap? */ | ||
@@ -76,3 +74,3 @@ const {code} = await babel.transformAsync(source, { | ||
return {source: code}; | ||
return defaultTransformSource(code, context, defaultTransformSource); | ||
} |
{ | ||
"name": "@istanbuljs/esm-loader-hook", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Loader hook for ESM instrumentation (experimental!!)", | ||
@@ -5,0 +5,0 @@ "type": "module", |
6852
64