@after-work.js/transform
Advanced tools
Comparing version 5.1.1 to 5.1.2
{ | ||
"name": "@after-work.js/transform", | ||
"version": "5.1.1", | ||
"version": "5.1.2", | ||
"publishConfig": { | ||
@@ -23,3 +23,3 @@ "access": "public" | ||
"dependencies": { | ||
"@after-work.js/utils": "5.1.1", | ||
"@after-work.js/utils": "^5.1.2", | ||
"find-cache-dir": "2.0.0", | ||
@@ -31,3 +31,3 @@ "import-cwd": "2.1.0" | ||
], | ||
"gitHead": "437b47d84de1baec6ce8e7810c9b8d519c41a70a" | ||
"gitHead": "d52747827a31b49d77f6d7de8afd7114bb033b1a" | ||
} |
@@ -11,3 +11,6 @@ /* eslint class-methods-use-this: 0, no-restricted-syntax: 0, guard-for-in: 0, no-await-in-loop: 0, max-len: 0 */ | ||
constructor() { | ||
this.cacheDir = findCacheDir({ name: '@after-work.js/transform', create: true }); | ||
this.cacheDir = findCacheDir({ | ||
name: '@after-work.js/transform', | ||
create: true, | ||
}); | ||
this.transform = new Map(); | ||
@@ -17,3 +20,6 @@ } | ||
getCacheFilename(filename) { | ||
const hash = crypto.createHash('md5').update(filename).digest('hex'); | ||
const hash = crypto | ||
.createHash('md5') | ||
.update(filename) | ||
.digest('hex'); | ||
return path.join(this.cacheDir, `${hash}.json.gz`); | ||
@@ -27,3 +33,6 @@ } | ||
}); | ||
return crypto.createHash('md5').update(data).digest('hex'); | ||
return crypto | ||
.createHash('md5') | ||
.update(data) | ||
.digest('hex'); | ||
} | ||
@@ -39,8 +48,9 @@ | ||
const { | ||
virtualMock, | ||
babelOptions, | ||
instrument, | ||
transform, | ||
virtualMock, babelOptions, instrument, transform, | ||
} = options; | ||
transformItem.hash = this.getCacheHash(filename, { ...babelOptions, ...instrument, ...transform }); | ||
transformItem.hash = this.getCacheHash(filename, { | ||
...babelOptions, | ||
...instrument, | ||
...transform, | ||
}); | ||
if (virtualMock) { | ||
@@ -71,3 +81,4 @@ return; | ||
} | ||
if (virtualMock) { // virtual mock always refresh | ||
if (virtualMock) { | ||
// virtual mock always refresh | ||
return null; | ||
@@ -78,3 +89,7 @@ } | ||
} | ||
const hash = this.getCacheHash(filename, { ...babelOptions, ...instrument, ...transform }); | ||
const hash = this.getCacheHash(filename, { | ||
...babelOptions, | ||
...instrument, | ||
...transform, | ||
}); | ||
if (value && value.hash && value.hash !== hash) { | ||
@@ -102,3 +117,3 @@ return null; | ||
} catch (err) { | ||
console.log(err); | ||
console.error(err); | ||
} | ||
@@ -105,0 +120,0 @@ } |
/* eslint global-require: 0, import/no-dynamic-require: 0, object-curly-newline: 0, class-methods-use-this: 0, max-len: 0 */ | ||
const fs = require('fs'); | ||
const { isSourceMap, isTypescript, ensureFilePath } = require('@after-work.js/utils'); | ||
const { | ||
isSourceMap, | ||
isTypescript, | ||
ensureFilePath, | ||
createDebug, | ||
} = require('@after-work.js/utils'); | ||
const FileCache = require('./file-cache'); | ||
const fileCache = new FileCache(); | ||
const debug = createDebug('transform'); | ||
function getBabelOpts(filename, argv) { | ||
const { options: { sourceRoot, only, ignore } = {}, babelPluginIstanbul } = argv.babel; | ||
const { | ||
options: { sourceRoot, only, ignore, plugins = [], presets = [] } = {}, | ||
babelPluginIstanbul, | ||
} = argv.babel; | ||
const virtualMock = !!argv.virtualMock; | ||
const addCoverage = argv.instrument.testExclude.shouldInstrument(filename) && virtualMock === false; | ||
const plugins = addCoverage | ||
? [[babelPluginIstanbul, {}]] | ||
: []; | ||
const addCoverage = virtualMock === false; | ||
const usePlugins = addCoverage | ||
? [...plugins, [babelPluginIstanbul, argv.nyc]] | ||
: plugins; | ||
const sourceMaps = 'both'; | ||
const retainLines = true; | ||
return { filename, sourceRoot, plugins, only, ignore, sourceMaps, retainLines }; | ||
const opts = { | ||
filename, | ||
sourceRoot, | ||
presets, | ||
plugins: usePlugins, | ||
only, | ||
ignore, | ||
sourceMaps, | ||
retainLines, | ||
}; | ||
debug('getBabelOpts', opts); | ||
return opts; | ||
} | ||
function transformTypescript(filePath, sourceRoot, tsContent, argv) { | ||
const { babel: { typescript } } = argv; | ||
const { transform: { typescript: { compilerOptions = {}, babelOptions = {} } = {} } = {} } = argv; | ||
const { | ||
babel: { typescript }, | ||
__isNodeRunner = false, | ||
} = argv; | ||
const { | ||
transform: { | ||
typescript: { compilerOptions = {}, babelOptions = {} } = {}, | ||
} = {}, | ||
} = argv; | ||
const fileName = filePath; | ||
@@ -31,3 +57,3 @@ compilerOptions.sourceRoot = sourceRoot; | ||
if (!compilerOptions.module) { | ||
compilerOptions.module = 'esnext'; | ||
compilerOptions.module = __isNodeRunner ? 'commonjs' : 'esnext'; | ||
} | ||
@@ -46,7 +72,13 @@ const transpileOpts = { fileName, compilerOptions }; | ||
tsBabelOpts = Object.assign(babelOptions, tsBabelOpts); | ||
debug(':transformTypescript', tsContent, tsBabelOpts); | ||
return { tsContent, tsBabelOpts }; | ||
} | ||
function transformFile(filename, argv, content = null) { | ||
debug(':transformFile'); | ||
if (!content && isSourceMap(filename)) { | ||
const cachedTransform = fileCache.getSync(filename.split('.map').join(''), argv); | ||
const cachedTransform = fileCache.getSync( | ||
filename.split('.map').join(''), | ||
argv, | ||
); | ||
debug(':transformFile cached source map', cachedTransform); | ||
return cachedTransform.map; | ||
@@ -56,6 +88,11 @@ } | ||
filename = ensureFilePath(filename); | ||
if (!filename) { | ||
return null; | ||
} | ||
const cachedTransform = fileCache.getSync(filename, argv); | ||
if (cachedTransform) { | ||
debug(':transformFile cached transform', cachedTransform); | ||
return cachedTransform.code; | ||
} | ||
content = fs.readFileSync(filename, 'utf8'); | ||
@@ -65,2 +102,3 @@ } | ||
if (cachedTransform) { | ||
debug(':transformFile cached transform', cachedTransform); | ||
return cachedTransform.code; | ||
@@ -70,3 +108,8 @@ } | ||
if (isTypescript(filename)) { | ||
const { tsContent, tsBabelOpts } = transformTypescript(filename, babelOpts.sourceRoot, content, argv); | ||
const { tsContent, tsBabelOpts } = transformTypescript( | ||
filename, | ||
babelOpts.sourceRoot, | ||
content, | ||
argv, | ||
); | ||
content = tsContent; | ||
@@ -78,3 +121,5 @@ babelOpts = Object.assign({}, babelOpts, tsBabelOpts); | ||
const transform = babel.transform(content, babelOpts); | ||
debug(':transformFile transform', transform); | ||
if (!transform) { | ||
debug(':transformFile transform null'); | ||
return content; | ||
@@ -81,0 +126,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
8511
233
+ Added@after-work.js/utils@5.1.2(transitive)
+ Added@mrmlnc/readdir-enhanced@2.2.1(transitive)
+ Added@nodelib/fs.stat@1.1.3(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedaproba@1.2.0(transitive)
+ Addedare-we-there-yet@1.1.7(transitive)
+ Addedarr-diff@4.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedarray-union@1.0.2(transitive)
+ Addedarray-uniq@1.0.3(transitive)
+ Addedarray-unique@0.3.2(transitive)
+ Addedassign-symbols@1.0.0(transitive)
+ Addedatob@2.1.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase@0.11.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbraces@2.3.2(transitive)
+ Addedcache-base@1.0.1(transitive)
+ Addedcall-me-maybe@1.0.2(transitive)
+ Addedclass-utils@0.3.6(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcollection-visit@1.0.0(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconsole-control-strings@1.1.0(transitive)
+ Addedcopy-descriptor@0.1.1(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddebug@2.6.94.0.1(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddefine-property@0.2.51.0.02.0.2(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddir-glob@2.2.2(transitive)
+ Addedexpand-brackets@2.1.4(transitive)
+ Addedextend-shallow@2.0.13.0.2(transitive)
+ Addedextglob@2.0.4(transitive)
+ Addedfast-glob@2.2.7(transitive)
+ Addedfill-range@4.0.0(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfragment-cache@0.2.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedgauge@2.7.4(transitive)
+ Addedget-value@2.0.6(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglob-parent@3.1.0(transitive)
+ Addedglob-to-regexp@0.3.0(transitive)
+ Addedglobby@8.0.1(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedhas-value@0.3.11.0.0(transitive)
+ Addedhas-values@0.1.41.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedignore@3.3.10(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-data-descriptor@1.0.1(transitive)
+ Addedis-descriptor@0.1.71.0.3(transitive)
+ Addedis-extendable@0.1.11.0.1(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedis-glob@3.1.04.0.3(transitive)
+ Addedis-number@3.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.03.0.1(transitive)
+ Addedkind-of@3.2.24.0.06.0.3(transitive)
+ Addedmap-cache@0.2.2(transitive)
+ Addedmap-visit@1.0.0(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@3.1.10(transitive)
+ Addedminimatch@3.0.43.1.2(transitive)
+ Addedmixin-deep@1.3.2(transitive)
+ Addedms@2.0.02.1.3(transitive)
+ Addednanomatch@1.2.13(transitive)
+ Addednpmlog@4.1.2(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedobject-copy@0.1.0(transitive)
+ Addedobject-visit@1.0.1(transitive)
+ Addedobject.pick@1.3.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpascalcase@0.1.1(transitive)
+ Addedpath-dirname@1.0.2(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-type@3.0.0(transitive)
+ Addedposix-character-classes@0.1.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedregex-not@1.0.2(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedresolve-url@0.2.1(transitive)
+ Addedret@0.1.15(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsafe-regex@1.1.0(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedset-value@2.0.1(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedslash@1.0.0(transitive)
+ Addedsnapdragon@0.8.2(transitive)
+ Addedsnapdragon-node@2.1.1(transitive)
+ Addedsnapdragon-util@3.0.1(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedsource-map-resolve@0.5.3(transitive)
+ Addedsource-map-url@0.4.1(transitive)
+ Addedsplit-string@3.1.0(transitive)
+ Addedstatic-extend@0.1.2(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedto-object-path@0.3.0(transitive)
+ Addedto-regex@3.0.2(transitive)
+ Addedto-regex-range@2.1.1(transitive)
+ Addedunion-value@1.0.1(transitive)
+ Addedunset-value@1.0.0(transitive)
+ Addedurix@0.1.0(transitive)
+ Addeduse@3.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwide-align@1.1.5(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removed@after-work.js/utils@5.1.1(transitive)
Updated@after-work.js/utils@^5.1.2