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

icon-maker-loader

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

icon-maker-loader - npm Package Compare versions

Comparing version 0.1.8 to 0.1.9

76

index.js

@@ -5,2 +5,3 @@ const loaderUtils = require('loader-utils');

const fs = require('fs');
const crypto = require('crypto');
const createTmpDir = require('./create-tmp-dir.js');

@@ -12,3 +13,6 @@

const fonts = {};
const filesForFont = {};
const getSha1ForContent = content => crypto.createHash('sha1').update(content).digest('hex');
const writeFontFiles = (fontFamily, iconMaker, cb) => {

@@ -77,3 +81,2 @@ const pathToFontJs = path.join(tmpFolder, `${fontFamily}.js`);

const pathToSvg = this.resourcePath;
console.log('load', pathToSvg);
const params = loaderUtils.parseQuery(this.query);

@@ -87,2 +90,3 @@ const fileName = path.basename(pathToSvg, '.svg');

doOnFinish: [],
paths: [],
iconMaker: new IconMaker({ fontFamily, files, isLocalCss })

@@ -95,22 +99,68 @@ };

const cb = this.async();
const moduleContent = `
var style = require(${JSON.stringify(`${tmpFolderForNode}/${fontFamily}.js`)});
if (style) {
module.exports = style[${JSON.stringify(fontFamily)}] + " " + style[${JSON.stringify(`${fontFamily}-${fileName}`)}];
} else {
module.exports = ${JSON.stringify(`${fontFamily} ${fontFamily}-${fileName}`)};
}
`;
font.paths.push(pathToSvg);
font.doOnFinish.push(err => {
const moduleContent = `
var style = require(${JSON.stringify(`${tmpFolderForNode}/${fontFamily}.js`)});
if (style) {
module.exports = style[${JSON.stringify(fontFamily)}] + " " + style[${JSON.stringify(`${fontFamily}-${fileName}`)}];
} else {
module.exports = ${JSON.stringify(`${fontFamily} ${fontFamily}-${fileName}`)};
}
`;
cb(err, moduleContent);
});
font.timeoutIdentifier = setTimeout(() => {
writeFontFiles(fontFamily, font.iconMaker, err => {
console.log(err);
setTimeout(() => {
const isFirstTime = filesForFont[fontFamily] === undefined;
Promise.all(
[
isFirstTime ? Promise.resolve : new Promise((res, rej) => {
const isThereAChangeInLength = Object.keys(filesForFont[fontFamily]).length !== font.paths.length;
if (isThereAChangeInLength) {
res();
} else {
rej();
}
})
].concat(isFirstTime ? [] : font.paths.map(currPathToSvg => new Promise((res, rej) => {
fs.readFile(currPathToSvg, (err, data) => {
const isThereAChangeInHashForSvg = filesForFont[fontFamily][currPathToSvg] === getSha1ForContent(data);
if (isThereAChangeInHashForSvg) {
res();
} else {
rej();
}
});
})))
).then(() => {
filesForFont[fontFamily] = {};
Promise.all(
[
new Promise((res, rej) => {
writeFontFiles(fontFamily, font.iconMaker, err => {
if (err) {
rej(err);
} else {
res();
}
});
})
].concat(font.paths.map(currPathToSvg => new Promise((res, rej) => {
fs.readFile(currPathToSvg, (err, data) => {
if (err) {
rej(err);
} else {
filesForFont[fontFamily][currPathToSvg] = getSha1ForContent(data);
res();
}
});
})))
).then(() => {
font.doOnFinish.forEach(fn => fn());
delete fonts[fontFamily];
}, err => {
font.doOnFinish.forEach(fn => fn(err));
delete fonts[fontFamily];
}, 1000);
});
});
}, 1000);
};

3

package.json
{
"name": "icon-maker-loader",
"version": "0.1.8",
"version": "0.1.9",
"description": "",

@@ -32,2 +32,3 @@ "main": "index.js",

"dependencies": {
"crypto": "0.0.3",
"icon-maker": "^0.2.4",

@@ -34,0 +35,0 @@ "loader-utils": "^0.2.16",

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