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

@after-work.js/transform

Package Overview
Dependencies
Maintainers
2
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@after-work.js/transform - npm Package Compare versions

Comparing version 5.1.1 to 5.1.2

6

package.json
{
"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 @@ }

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