Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 5e82138

Browse files
authored
fix: ensure correct babel options (#276)
* feat: bypass reading file cache with `--no-file-cache` * fix: ensure correct babel options
1 parent f909651 commit 5e82138

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

commands-common/register/src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ function compileHook(argv, code, filename, virtualMock = false) {
2828
}
2929
const newArgv = {
3030
...argv,
31-
babelOptions: {
32-
...opts,
31+
babel: {
32+
...argv.babel,
33+
options: {
34+
...opts,
35+
},
3336
},
3437
virtualMock,
3538
};

commands-common/transform/src/file-cache.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ class FileCache {
4444
getSync(filename, options = {}) {
4545
const {
4646
ignoreCacheInvalidation = false,
47+
fileCache = true,
4748
virtualMock = false,
4849
babelOptions,
4950
instrument,
5051
transform,
5152
} = options;
5253
const value = this.safeLoadCacheSync(this.getCacheFilename(filename));
5354
this.transform.set(filename, value);
55+
if (!fileCache) {
56+
return null;
57+
}
5458
if (ignoreCacheInvalidation) {
5559
return value;
5660
}

commands-common/transform/src/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
/* eslint global-require: 0, import/no-dynamic-require: 0, object-curly-newline: 0, class-methods-use-this: 0, max-len: 0 */
2-
const path = require('path');
32
const fs = require('fs');
43
const { isSourceMap, isTypescript, ensureFilePath } = require('@after-work.js/utils');
54
const FileCache = require('./file-cache');
65

76
const fileCache = new FileCache();
87

98
function getBabelOpts(filename, argv) {
10-
const { options, babelPluginIstanbul } = argv.babel;
11-
const sourceRoot = (options && options.sourceRoot) || argv.coverage ? path.dirname(filename) : undefined;// eslint-disable-line
9+
const { options: { sourceRoot, only, ignore }, babelPluginIstanbul } = argv.babel;
1210
const addCoverage = argv.instrument.testExclude.shouldInstrument(filename);
1311
const plugins = addCoverage ?
1412
[[babelPluginIstanbul, {}]] :
1513
[];
1614
const sourceMaps = 'both';
1715
const retainLines = true;
18-
const { only, ignore } = argv.babelOptions || {};
1916
return { filename, sourceRoot, plugins, only, ignore, sourceMaps, retainLines };
2017
}
2118

2219
function transformTypescript(filePath, sourceRoot, tsContent, argv) {
2320
const { babel: { typescript } } = argv;
2421
const { transform: { typescript: { compilerOptions, babelOptions } } } = argv;
25-
const fileName = argv.coverage ? path.basename(filePath) : filePath;
26-
compilerOptions.sourceRoot = argv.coverage ? path.resolve(path.dirname(filePath)) : sourceRoot;
22+
const fileName = filePath;
23+
compilerOptions.sourceRoot = sourceRoot;
2724
compilerOptions.inlineSources = true;
2825
if (!compilerOptions.sourceMap && !compilerOptions.inlineSourceMap) {
2926
compilerOptions.inlineSourceMap = true;

0 commit comments

Comments
 (0)