postcss-smart-asset
Advanced tools
Comparing version 1.0.6 to 2.0.0
@@ -1,36 +0,33 @@ | ||
/*! postcss-smart-asset v1.0.6 by Sebastian Software <s.werner@sebastian-software.de> */ | ||
/*! postcss-smart-asset v2.0.0 by Sebastian Software <s.werner@sebastian-software.de> */ | ||
'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
require('core-js/modules/es.array.iterator'); | ||
require('core-js/modules/es.object.to-string'); | ||
require('core-js/modules/es.promise'); | ||
require('core-js/modules/es.string.iterator'); | ||
require('core-js/modules/web.dom-collections.iterator'); | ||
var path = _interopDefault(require('path')); | ||
var postcss = _interopDefault(require('postcss')); | ||
var path = require('path'); | ||
require('core-js/modules/es.array.for-each'); | ||
require('core-js/modules/es.array.is-array'); | ||
require('core-js/modules/es.array.iterator'); | ||
require('core-js/modules/es.array.map'); | ||
require('core-js/modules/es.array.slice'); | ||
require('core-js/modules/es.object.to-string'); | ||
require('core-js/modules/es.promise'); | ||
require('core-js/modules/es.regexp.exec'); | ||
require('core-js/modules/es.set'); | ||
require('core-js/modules/es.string.iterator'); | ||
require('core-js/modules/es.string.match'); | ||
require('core-js/modules/es.string.replace'); | ||
require('core-js/modules/web.dom-collections.for-each'); | ||
require('core-js/modules/web.dom-collections.iterator'); | ||
require('core-js/modules/es.array.join'); | ||
require('core-js/modules/es.function.name'); | ||
require('core-js/modules/es.string.search'); | ||
var cpFile = _interopDefault(require('cp-file')); | ||
var promises = require('fs/promises'); | ||
var assetHash = require('asset-hash'); | ||
require('core-js/modules/es.array.find'); | ||
var fs = require('fs'); | ||
var fs__default = _interopDefault(fs); | ||
var mime = _interopDefault(require('mime/lite')); | ||
var mime = require('mime/lite'); | ||
require('core-js/modules/es.array.index-of'); | ||
var url = _interopDefault(require('url')); | ||
var url = require('url'); | ||
require('core-js/modules/es.date.to-string'); | ||
require('core-js/modules/es.regexp.to-string'); | ||
var pify = _interopDefault(require('pify')); | ||
require('core-js/modules/es.array.concat'); | ||
@@ -40,8 +37,16 @@ require('core-js/modules/es.array.filter'); | ||
require('core-js/modules/es.regexp.constructor'); | ||
var minimatch = _interopDefault(require('minimatch')); | ||
var minimatch = require('minimatch'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; } | ||
var path__default = /*#__PURE__*/_interopDefaultLegacy(path); | ||
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs); | ||
var mime__default = /*#__PURE__*/_interopDefaultLegacy(mime); | ||
var url__default = /*#__PURE__*/_interopDefaultLegacy(url); | ||
var minimatch__default = /*#__PURE__*/_interopDefaultLegacy(minimatch); | ||
var normalize = function normalize(assetUrl) { | ||
assetUrl = path.normalize(assetUrl); | ||
assetUrl = path__default.normalize(assetUrl); | ||
if (path.sep === "\\") { | ||
if (path__default.sep === "\\") { | ||
assetUrl = assetUrl.replace(/\\/g, "/"); | ||
@@ -63,3 +68,3 @@ } | ||
var getAssetsPath = function getAssetsPath(baseDir, assetsPath, relative) { | ||
return path.resolve(baseDir, assetsPath || "", relative || ""); | ||
return path__default.resolve(baseDir, assetsPath || "", relative || ""); | ||
}; | ||
@@ -74,3 +79,3 @@ var getTargetDir = function getTargetDir(dir) { | ||
var filename = getPathDeclFile(decl); | ||
return filename ? path.dirname(filename) : process.cwd(); | ||
return filename ? path__default.dirname(filename) : process.cwd(); | ||
}; | ||
@@ -88,5 +93,5 @@ var getPathByBasePath = function getPathByBasePath(basePath, dirFrom, relPath) { | ||
var prepareAsset = function prepareAsset(assetUrl, dir, decl) { | ||
var parsedUrl = url.parse(assetUrl), | ||
var parsedUrl = url__default.parse(assetUrl), | ||
pathname = !isUrlWithoutPathname(assetUrl) ? parsedUrl.pathname : null, | ||
absolutePath = pathname ? path.resolve(path.join(dir.file, pathname)) : getPathDeclFile(decl); | ||
absolutePath = pathname ? path__default.resolve(path__default.join(dir.file, pathname)) : getPathDeclFile(decl); | ||
return { | ||
@@ -97,3 +102,3 @@ url: assetUrl, | ||
absolutePath: absolutePath || dir.from, | ||
relativePath: absolutePath ? path.relative(dir.from, absolutePath) : ".", | ||
relativePath: absolutePath ? path__default.relative(dir.from, absolutePath) : ".", | ||
search: parsedUrl.search || "", | ||
@@ -115,3 +120,3 @@ hash: parsedUrl.hash || "" | ||
path: filePath, | ||
mimeType: mime.getType(filePath) | ||
mimeType: mime__default.getType(filePath) | ||
}; | ||
@@ -151,7 +156,7 @@ }; | ||
if (options.useHash && options.keepName) { | ||
pathObj = path.parse(assetRelativePath); | ||
fileName = path.parse(asset.relativePath).name; | ||
pathObj = path__default.parse(assetRelativePath); | ||
fileName = path__default.parse(asset.relativePath).name; | ||
pathObj.name = fileName + "~" + pathObj.name; | ||
delete pathObj.base; | ||
assetRelativePath = path.format(pathObj); | ||
assetRelativePath = path__default.format(pathObj); | ||
} | ||
@@ -161,9 +166,15 @@ | ||
newAssetBaseDir = getAssetsPath(targetDir, options.assetsPath); | ||
newAssetPath = path.join(newAssetBaseDir, assetRelativePath); | ||
newRelativeAssetPath = normalize(path.relative(targetDir, newAssetPath)); | ||
return Promise.resolve(cpFile(file.path, newAssetPath, { | ||
overwrite: true | ||
newAssetPath = path__default.join(newAssetBaseDir, assetRelativePath); | ||
newRelativeAssetPath = normalize(path__default.relative(targetDir, newAssetPath)); | ||
return Promise.resolve(promises.mkdir(path__default.dirname(newAssetPath), { | ||
recursive: true | ||
})).then(function () { | ||
try { | ||
return $return("" + newRelativeAssetPath + asset.search + asset.hash); | ||
return Promise.resolve(promises.copyFile(file.path, newAssetPath)).then(function () { | ||
try { | ||
return $return("" + newRelativeAssetPath + asset.search + asset.hash); | ||
} catch ($boundEx) { | ||
return $error($boundEx); | ||
} | ||
}, $error); | ||
} catch ($boundEx) { | ||
@@ -184,4 +195,3 @@ return $error($boundEx); | ||
var readFileAsync = pify(fs.readFile), | ||
optimizedSvgEncode = function optimizedSvgEncode(svgContent) { | ||
var optimizedSvgEncode = function optimizedSvgEncode(svgContent) { | ||
var result = encodeURIComponent(svgContent).replace(/%3D/g, "=").replace(/%3A/g, ":").replace(/%2F/g, "/").replace(/%22/g, "'").replace(/%2C/g, ",").replace(/%3B/g, ";"); | ||
@@ -197,3 +207,3 @@ return result.replace(/(%[\dA-Z]{2})/g, function (matched, AZ) { | ||
dataMime = "data:" + file.mimeType; | ||
return Promise.resolve(readFileAsync(file.path)).then(function ($await_1) { | ||
return Promise.resolve(promises.readFile(file.path)).then(function ($await_1) { | ||
try { | ||
@@ -219,3 +229,3 @@ contents = $await_1; | ||
function rebaseAsset(asset, dir) { | ||
var rebasedUrl = normalize(path.relative(dir.to, asset.absolutePath)); | ||
var rebasedUrl = normalize(path__default.relative(dir.to, asset.absolutePath)); | ||
return "" + rebasedUrl + asset.search + asset.hash; | ||
@@ -286,6 +296,6 @@ } | ||
var matchesFilter = function matchesFilter(asset, pattern) { | ||
var relativeToRoot = path.relative(process.cwd(), asset.absolutePath); | ||
var relativeToRoot = path__default.relative(process.cwd(), asset.absolutePath); | ||
if (typeof pattern == "string") { | ||
pattern = minimatch.filter(pattern); | ||
pattern = minimatch__default.filter(pattern); | ||
return pattern(relativeToRoot); | ||
@@ -422,3 +432,8 @@ } | ||
var processTracker = new Set(); | ||
var declProcessor = function declProcessor(from, to, options, result, decl) { | ||
if (processTracker.has(decl)) { | ||
return; | ||
} | ||
var dir = { | ||
@@ -461,2 +476,3 @@ from: from, | ||
})).then(function (values) { | ||
processTracker.add(decl); | ||
decl.value = decl.value.replace(pattern, function (match) { | ||
@@ -469,3 +485,3 @@ var replacement = values.shift(); | ||
var index = postcss.plugin("postcss-smart-asset", function (options) { | ||
var index = (function (options) { | ||
if (options === void 0) { | ||
@@ -475,19 +491,17 @@ options = {}; | ||
return function (root, result) { | ||
var opts = result.opts, | ||
from = opts.from ? path.dirname(opts.from) : ".", | ||
to = opts.to ? path.dirname(opts.to) : from, | ||
promises = []; | ||
root.walkDecls(function (decl) { | ||
var waiter = declProcessor(from, to, options, result, decl); | ||
if (waiter && waiter.then) { | ||
promises.push(waiter); | ||
} | ||
}); | ||
return Promise.all(promises); | ||
return { | ||
postcssPlugin: "postcss-smart-asset", | ||
Declaration: function Declaration(decl, _ref) { | ||
var result = _ref.result, | ||
opts = result.opts, | ||
from = opts.from ? path__default.dirname(opts.from) : ".", | ||
to = opts.to ? path__default.dirname(opts.to) : from; | ||
return declProcessor(from, to, options, result, decl); | ||
} | ||
}; | ||
}); | ||
var postcss = true; | ||
module.exports = index; | ||
exports.default = index; | ||
exports.postcss = postcss; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,25 +0,24 @@ | ||
/*! postcss-smart-asset v1.0.6 by Sebastian Software <s.werner@sebastian-software.de> */ | ||
import 'core-js/modules/es.array.iterator'; | ||
import 'core-js/modules/es.object.to-string'; | ||
import 'core-js/modules/es.promise'; | ||
import 'core-js/modules/es.string.iterator'; | ||
import 'core-js/modules/web.dom-collections.iterator'; | ||
/*! postcss-smart-asset v2.0.0 by Sebastian Software <s.werner@sebastian-software.de> */ | ||
import path from 'path'; | ||
import postcss from 'postcss'; | ||
import 'core-js/modules/es.array.for-each'; | ||
import 'core-js/modules/es.array.is-array'; | ||
import 'core-js/modules/es.array.iterator'; | ||
import 'core-js/modules/es.array.map'; | ||
import 'core-js/modules/es.array.slice'; | ||
import 'core-js/modules/es.object.to-string'; | ||
import 'core-js/modules/es.promise'; | ||
import 'core-js/modules/es.regexp.exec'; | ||
import 'core-js/modules/es.set'; | ||
import 'core-js/modules/es.string.iterator'; | ||
import 'core-js/modules/es.string.match'; | ||
import 'core-js/modules/es.string.replace'; | ||
import 'core-js/modules/web.dom-collections.for-each'; | ||
import 'core-js/modules/web.dom-collections.iterator'; | ||
import 'core-js/modules/es.array.join'; | ||
import 'core-js/modules/es.function.name'; | ||
import 'core-js/modules/es.string.search'; | ||
import cpFile from 'cp-file'; | ||
import { mkdir, copyFile, readFile } from 'fs/promises'; | ||
import { getHashedName } from 'asset-hash'; | ||
import 'core-js/modules/es.array.find'; | ||
import fs, { readFile } from 'fs'; | ||
import fs from 'fs'; | ||
import mime from 'mime/lite'; | ||
@@ -30,3 +29,2 @@ import 'core-js/modules/es.array.index-of'; | ||
import 'core-js/modules/es.regexp.to-string'; | ||
import pify from 'pify'; | ||
import 'core-js/modules/es.array.concat'; | ||
@@ -152,7 +150,13 @@ import 'core-js/modules/es.array.filter'; | ||
newRelativeAssetPath = normalize(path.relative(targetDir, newAssetPath)); | ||
return Promise.resolve(cpFile(file.path, newAssetPath, { | ||
overwrite: true | ||
return Promise.resolve(mkdir(path.dirname(newAssetPath), { | ||
recursive: true | ||
})).then(function () { | ||
try { | ||
return $return("" + newRelativeAssetPath + asset.search + asset.hash); | ||
return Promise.resolve(copyFile(file.path, newAssetPath)).then(function () { | ||
try { | ||
return $return("" + newRelativeAssetPath + asset.search + asset.hash); | ||
} catch ($boundEx) { | ||
return $error($boundEx); | ||
} | ||
}, $error); | ||
} catch ($boundEx) { | ||
@@ -173,4 +177,3 @@ return $error($boundEx); | ||
var readFileAsync = pify(readFile), | ||
optimizedSvgEncode = function optimizedSvgEncode(svgContent) { | ||
var optimizedSvgEncode = function optimizedSvgEncode(svgContent) { | ||
var result = encodeURIComponent(svgContent).replace(/%3D/g, "=").replace(/%3A/g, ":").replace(/%2F/g, "/").replace(/%22/g, "'").replace(/%2C/g, ",").replace(/%3B/g, ";"); | ||
@@ -186,3 +189,3 @@ return result.replace(/(%[\dA-Z]{2})/g, function (matched, AZ) { | ||
dataMime = "data:" + file.mimeType; | ||
return Promise.resolve(readFileAsync(file.path)).then(function ($await_1) { | ||
return Promise.resolve(readFile(file.path)).then(function ($await_1) { | ||
try { | ||
@@ -409,3 +412,8 @@ contents = $await_1; | ||
var processTracker = new Set(); | ||
var declProcessor = function declProcessor(from, to, options, result, decl) { | ||
if (processTracker.has(decl)) { | ||
return; | ||
} | ||
var dir = { | ||
@@ -448,2 +456,3 @@ from: from, | ||
})).then(function (values) { | ||
processTracker.add(decl); | ||
decl.value = decl.value.replace(pattern, function (match) { | ||
@@ -456,3 +465,3 @@ var replacement = values.shift(); | ||
var index = postcss.plugin("postcss-smart-asset", function (options) { | ||
var index = (function (options) { | ||
if (options === void 0) { | ||
@@ -462,19 +471,17 @@ options = {}; | ||
return function (root, result) { | ||
var opts = result.opts, | ||
from = opts.from ? path.dirname(opts.from) : ".", | ||
to = opts.to ? path.dirname(opts.to) : from, | ||
promises = []; | ||
root.walkDecls(function (decl) { | ||
var waiter = declProcessor(from, to, options, result, decl); | ||
if (waiter && waiter.then) { | ||
promises.push(waiter); | ||
} | ||
}); | ||
return Promise.all(promises); | ||
return { | ||
postcssPlugin: "postcss-smart-asset", | ||
Declaration: function Declaration(decl, _ref) { | ||
var result = _ref.result, | ||
opts = result.opts, | ||
from = opts.from ? path.dirname(opts.from) : ".", | ||
to = opts.to ? path.dirname(opts.to) : from; | ||
return declProcessor(from, to, options, result, decl); | ||
} | ||
}; | ||
}); | ||
var postcss = true; | ||
export default index; | ||
export { postcss }; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "postcss-smart-asset", | ||
"version": "1.0.6", | ||
"version": "2.0.0", | ||
"description": "PostCSS plugin to rebase or inline on url().", | ||
@@ -16,5 +16,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=10.0.0", | ||
"yarn": ">=1.0.0", | ||
"npm": ">=4.0.0" | ||
"node": ">=10.0.0" | ||
}, | ||
@@ -38,27 +36,27 @@ "license": "MIT", | ||
"dependencies": { | ||
"asset-hash": "^3.0.7", | ||
"core-js": "^3.6.5", | ||
"cp-file": "^9.0.0", | ||
"asset-hash": "^3.0.8", | ||
"core-js": "^3.7.0", | ||
"mime": "^2.4.6", | ||
"minimatch": "^3.0.4", | ||
"pify": "^5.0.0", | ||
"postcss": "^7.0.32" | ||
"minimatch": "^3.0.4" | ||
}, | ||
"peerDependencies": { | ||
"postcss": "^8.1.7" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.10.2", | ||
"@effective/eslint-config": "^3.7.1", | ||
"@effective/prettier": "^4.0.3", | ||
"@babel/core": "^7.12.3", | ||
"@effective/eslint-config": "^3.8.0", | ||
"@effective/prettier": "^4.2.0", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-jest": "^26.0.1", | ||
"babel-jest": "^26.6.3", | ||
"babel-preset-edge": "^5.5.1", | ||
"eslint": "^7.2.0", | ||
"husky": "^4.2.5", | ||
"jest-cli": "^26.0.1", | ||
"lint-staged": "^10.2.10", | ||
"postcss-import": "^12.0.1", | ||
"preppy": "^10.5.0", | ||
"prettier": "^2.0.5", | ||
"release-it": "^13.6.3", | ||
"eslint": "^7.13.0", | ||
"husky": "^4.3.0", | ||
"jest-cli": "^26.6.3", | ||
"lint-staged": "^10.5.1", | ||
"postcss-import": "^13.0.0", | ||
"preppy": "^10.8.0", | ||
"prettier": "^2.1.2", | ||
"release-it": "^14.2.1", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^3.9.5" | ||
"typescript": "^4.0.5" | ||
}, | ||
@@ -65,0 +63,0 @@ "scripts": { |
@@ -20,3 +20,3 @@ # PostCSS Smart Asset<br/>[![Sponsored by][sponsor-img]][sponsor] [![Version][npm-version-img]][npm] [![Downloads][npm-downloads-img]][npm] [![Build Status Unix][travis-img]][travis] [![Build Status Windows][appveyor-img]][appveyor] [![Dependencies][deps-img]][deps] | ||
```console | ||
$ npm install postcss-smart-asset | ||
$ npm install postcss postcss-smart-asset | ||
``` | ||
@@ -23,0 +23,0 @@ |
{ | ||
"include": ["src"], | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
@@ -3,0 +4,0 @@ "allowJs": true, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
107763
5
846
5
+ Addednanoid@3.3.8(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpostcss@8.5.3(transitive)
+ Addedsource-map-js@1.2.1(transitive)
- Removedcp-file@^9.0.0
- Removedpify@^5.0.0
- Removedpostcss@^7.0.32
- Removedcp-file@9.1.0(transitive)
- Removedmake-dir@3.1.0(transitive)
- Removednested-error-stacks@2.1.1(transitive)
- Removedp-event@4.2.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-timeout@3.2.0(transitive)
- Removedpicocolors@0.2.1(transitive)
- Removedpify@5.0.0(transitive)
- Removedpostcss@7.0.39(transitive)
- Removedsemver@6.3.1(transitive)
- Removedsource-map@0.6.1(transitive)
Updatedasset-hash@^3.0.8
Updatedcore-js@^3.7.0