@after-work.js/transform
Advanced tools
Comparing version 6.0.13 to 7.0.0-alpha.0
{ | ||
"name": "@after-work.js/transform", | ||
"version": "6.0.13", | ||
"version": "7.0.0-alpha.0", | ||
"publishConfig": { | ||
@@ -23,4 +23,4 @@ "access": "public" | ||
"dependencies": { | ||
"@after-work.js/utils": "6.0.13", | ||
"find-cache-dir": "3.3.0", | ||
"@after-work.js/utils": "7.0.0-alpha.0", | ||
"find-cache-dir": "3.3.1", | ||
"import-cwd": "3.0.0" | ||
@@ -31,3 +31,3 @@ }, | ||
], | ||
"gitHead": "1ae4d0bd13053bc2b420d410de9c512ee5c6cb2a" | ||
"gitHead": "689884010c7bd56512bb31a79bb3bfdc599df554" | ||
} |
/* eslint class-methods-use-this: 0, no-restricted-syntax: 0, guard-for-in: 0, no-await-in-loop: 0, max-len: 0 */ | ||
const path = require('path'); | ||
const findCacheDir = require('find-cache-dir'); | ||
const fs = require('fs'); | ||
const zlib = require('zlib'); | ||
const crypto = require('crypto'); | ||
const path = require("path"); | ||
const findCacheDir = require("find-cache-dir"); | ||
const fs = require("fs"); | ||
const zlib = require("zlib"); | ||
const crypto = require("crypto"); | ||
@@ -12,3 +12,3 @@ class FileCache { | ||
this.cacheDir = findCacheDir({ | ||
name: '@after-work.js/transform', | ||
name: "@after-work.js/transform", | ||
create: true, | ||
@@ -20,6 +20,3 @@ }); | ||
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`); | ||
@@ -33,6 +30,3 @@ } | ||
}); | ||
return crypto | ||
.createHash('md5') | ||
.update(data) | ||
.digest('hex'); | ||
return crypto.createHash("md5").update(data).digest("hex"); | ||
} | ||
@@ -47,5 +41,3 @@ | ||
setSync(filename, transformItem, options) { | ||
const { | ||
virtualMock, babelOptions, instrument, transform, | ||
} = options; | ||
const { virtualMock, babelOptions, instrument, transform } = options; | ||
transformItem.hash = this.getCacheHash(filename, { | ||
@@ -113,3 +105,3 @@ ...babelOptions, | ||
const gz = zlib.gzipSync(str); | ||
fs.writeFileSync(this.getCacheFilename(filename), gz, 'utf8'); | ||
fs.writeFileSync(this.getCacheFilename(filename), gz, "utf8"); | ||
} catch (err) { | ||
@@ -116,0 +108,0 @@ console.error(err); |
/* 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 fs = require("fs"); | ||
const { | ||
@@ -9,7 +9,7 @@ isSourceMap, | ||
isTestFile, | ||
} = require('@after-work.js/utils'); | ||
const FileCache = require('./file-cache'); | ||
} = require("@after-work.js/utils"); | ||
const FileCache = require("./file-cache"); | ||
const fileCache = new FileCache(); | ||
const debug = createDebug('transform'); | ||
const debug = createDebug("transform"); | ||
@@ -22,7 +22,8 @@ function getBabelOpts(filename, argv) { | ||
const virtualMock = !!argv.virtualMock; | ||
const addCoverage = virtualMock === false && isTestFile(filename, argv) === false; | ||
const addCoverage = | ||
virtualMock === false && isTestFile(filename, argv) === false; | ||
const usePlugins = addCoverage | ||
? [...plugins, [babelPluginIstanbul, argv.nyc]] | ||
: plugins; | ||
const sourceMaps = 'both'; | ||
const sourceMaps = "both"; | ||
const retainLines = true; | ||
@@ -39,3 +40,3 @@ const opts = { | ||
}; | ||
debug('getBabelOpts', opts); | ||
debug("getBabelOpts", opts); | ||
return opts; | ||
@@ -61,3 +62,3 @@ } | ||
if (!compilerOptions.module) { | ||
compilerOptions.module = __isNodeRunner ? 'commonjs' : 'esnext'; | ||
compilerOptions.module = __isNodeRunner ? "commonjs" : "esnext"; | ||
} | ||
@@ -68,3 +69,3 @@ const transpileOpts = { fileName, compilerOptions }; | ||
let tsBabelOpts = { | ||
sourceMaps: 'both', | ||
sourceMaps: "both", | ||
}; | ||
@@ -77,13 +78,13 @@ | ||
tsBabelOpts = Object.assign(babelOptions, tsBabelOpts); | ||
debug(':transformTypescript', tsContent, tsBabelOpts); | ||
debug(":transformTypescript", tsContent, tsBabelOpts); | ||
return { tsContent, tsBabelOpts }; | ||
} | ||
function transformFile(filename, argv, content = null) { | ||
debug(':transformFile'); | ||
debug(":transformFile"); | ||
if (!content && isSourceMap(filename)) { | ||
const cachedTransform = fileCache.getSync( | ||
filename.split('.map').join(''), | ||
argv, | ||
filename.split(".map").join(""), | ||
argv | ||
); | ||
debug(':transformFile cached source map', cachedTransform); | ||
debug(":transformFile cached source map", cachedTransform); | ||
return cachedTransform.map; | ||
@@ -98,11 +99,11 @@ } | ||
if (cachedTransform) { | ||
debug(':transformFile cached transform', cachedTransform); | ||
debug(":transformFile cached transform", cachedTransform); | ||
return cachedTransform.code; | ||
} | ||
content = fs.readFileSync(filename, 'utf8'); | ||
content = fs.readFileSync(filename, "utf8"); | ||
} | ||
const cachedTransform = fileCache.getSync(filename, argv); | ||
if (cachedTransform) { | ||
debug(':transformFile cached transform', cachedTransform); | ||
debug(":transformFile cached transform", cachedTransform); | ||
return cachedTransform.code; | ||
@@ -116,3 +117,3 @@ } | ||
content, | ||
argv, | ||
argv | ||
); | ||
@@ -125,5 +126,5 @@ content = tsContent; | ||
const transform = babel.transform(content, babelOpts); | ||
debug(':transformFile transform', transform); | ||
debug(":transformFile transform", transform); | ||
if (!transform) { | ||
debug(':transformFile transform null'); | ||
debug(":transformFile transform null"); | ||
return content; | ||
@@ -135,4 +136,5 @@ } | ||
const getTransform = filename => fileCache.getSync(filename, { ignoreCacheInvalidation: true }); | ||
const deleteTransform = filename => fileCache.transform.delete(filename); | ||
const getTransform = (filename) => | ||
fileCache.getSync(filename, { ignoreCacheInvalidation: true }); | ||
const deleteTransform = (filename) => fileCache.transform.delete(filename); | ||
const safeSaveCache = () => fileCache.saveSync(); | ||
@@ -139,0 +141,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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
8535
228
1
1
+ Added@after-work.js/utils@7.0.0-alpha.0(transitive)
+ Addedfind-cache-dir@3.3.1(transitive)
+ Addedglobby@11.0.1(transitive)
- Removed@after-work.js/utils@6.0.13(transitive)
- Removed@types/glob@7.2.0(transitive)
- Removed@types/minimatch@5.1.2(transitive)
- Removed@types/node@22.10.1(transitive)
- Removedfind-cache-dir@3.3.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedglobby@10.0.2(transitive)
- Removedinflight@1.0.6(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedundici-types@6.20.0(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedfind-cache-dir@3.3.1