From 643aa432bc63712c2ef412bcf7fa9451576961ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Tue, 20 Oct 2020 15:52:08 +0200 Subject: [PATCH 01/20] Add support for PostCSS 8 --- .travis.yml | 3 +-- package.json | 7 ++++-- src/index.js | 60 ++++++++++++++++++++++++++++------------------------ 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index ea1830f..da1499d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,7 @@ sudo: false language: node_js node_js: - stable - - "4" - - "0.12" + - "12" branches: only: - master diff --git a/package.json b/package.json index d05c091..23931c5 100644 --- a/package.json +++ b/package.json @@ -29,16 +29,19 @@ "ava": "^0.15.2", "babel-cli": "^6.4.0", "babel-plugin-add-module-exports": "^0.2.1", - "babel-preset-es2015": "^6.3.13" + "babel-preset-es2015": "^6.3.13", + "postcss": "^8.1.2" }, "dependencies": { "bluebird": "^3.1.1", "debug": "^2.6.0", "fs-extra": "^0.26.4", "lodash": "^4.0.0", - "postcss": "^5.0.14", "spritesmith": "^3.0.1", "svg-sprite": "^1.3.5" }, + "peerDependencies": { + "postcss": "^8.1.2" + }, "typings": "./typings.d.ts" } diff --git a/src/index.js b/src/index.js index 49e424b..f519d90 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,3 @@ -import postcss from 'postcss'; import _ from 'lodash'; import { defaults, @@ -18,34 +17,39 @@ import { /** * Plugin registration. */ -export default postcss.plugin('postcss-sprites', (options = {}) => { - return (css, result) => { - // Extend defaults - const opts = _.merge({}, defaults, options); +const plugin = (options = {}) => { + return { + postcssPlugin: 'postcss-sprites', + Once: (css, { result }) => { + // Extend defaults + const opts = _.merge({}, defaults, options); - // Setup the logger - opts.logger = createLogger(opts.verbose); + // Setup the logger + opts.logger = createLogger(opts.verbose); - // Prepare filter & group functions - prepareFilterBy(opts, result); - prepareGroupBy(opts); + // Prepare filter & group functions + prepareFilterBy(opts, result); + prepareGroupBy(opts); - // Process it - return extractImages(css, opts, result) - .spread((opts, images) => applyFilterBy(opts, images)) - .spread((opts, images) => applyGroupBy(opts, images)) - .spread((opts, images) => setTokens(css, opts, images)) - .spread((root, opts, images) => runSpritesmith(opts, images)) - .spread((opts, images, spritesheets) => saveSpritesheets(opts, images, spritesheets)) - .spread((opts, images, spritesheets) => mapSpritesheetProps(opts, images, spritesheets)) - .spread((opts, images, spritesheets) => updateReferences(css, opts, images, spritesheets)) - .spread((root, opts, images, spritesheets) => { - opts.logger(`${spritesheets.length} ${spritesheets.length > 1 ? 'spritesheets' : 'spritesheet'} generated.`); - }) - .catch((err) => { - console.error(`postcss-sprites: An error occurred while processing files - ${err.message}`); - console.error(err.stack); - throw err; - }); + // Process it + return extractImages(css, opts, result) + .spread((opts, images) => applyFilterBy(opts, images)) + .spread((opts, images) => applyGroupBy(opts, images)) + .spread((opts, images) => setTokens(css, opts, images)) + .spread((root, opts, images) => runSpritesmith(opts, images)) + .spread((opts, images, spritesheets) => saveSpritesheets(opts, images, spritesheets)) + .spread((opts, images, spritesheets) => mapSpritesheetProps(opts, images, spritesheets)) + .spread((opts, images, spritesheets) => updateReferences(css, opts, images, spritesheets)) + .spread((root, opts, images, spritesheets) => { + opts.logger(`${spritesheets.length} ${spritesheets.length > 1 ? 'spritesheets' : 'spritesheet'} generated.`); + }) + .catch((err) => { + console.error(`postcss-sprites: An error occurred while processing files - ${err.message}`); + console.error(err.stack); + throw err; + }); + } } -}); +}; +export default plugin; +plugin.postcss = true; From 19677ad0f59119bd13a0de3d40f1cc693728085c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Sat, 24 Oct 2020 09:39:21 +0200 Subject: [PATCH 02/20] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index da1499d..27c27b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ sudo: false language: node_js node_js: - stable - - "12" + - "10" branches: only: - master From 107c6b4e9f538696272b03927727ca272e0c8963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Mon, 8 Nov 2021 10:25:54 +0100 Subject: [PATCH 03/20] Upgrade dependencies --- .babelrc | 4 +- .gitignore | 1 + package.json | 27 ++++++---- test/07-run-spritesmith.js | 12 ++--- test/08-save-spritesheets.js | 62 ++++++++++----------- test/09-map-spritesheet-props.js | 16 +++--- test/10-update-references.js | 28 +++++----- test/11-e2e.js | 92 ++++++++++++++++---------------- test/12-examples.js | 46 ++++++++-------- 9 files changed, 148 insertions(+), 140 deletions(-) diff --git a/.babelrc b/.babelrc index 073bc2d..954afbf 100644 --- a/.babelrc +++ b/.babelrc @@ -1,8 +1,8 @@ { "presets": [ - ["es2015", { "loose": true }] + ["@babel/preset-env", { "loose": true }] ], "plugins": [ - "add-module-exports" + "@babel/plugin-transform-runtime" ] } diff --git a/.gitignore b/.gitignore index 2c2b14b..bdcfdb8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ test/build/ lib/ +package-lock.json diff --git a/package.json b/package.json index 23931c5..0e8e5fb 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,9 @@ "svg" ], "scripts": { - "test": "./node_modules/.bin/ava test/*.js --verbose --serial", - "build": "./node_modules/.bin/babel src/ --out-dir lib/", - "watch": "./node_modules/.bin/babel --watch src/ --out-dir lib/", + "test": "ava test/*.js --verbose --serial", + "build": "babel src/ --out-dir lib/", + "watch": "babel --watch src/ --out-dir lib/", "prepublish": "npm test", "pretest": "npm run build" }, @@ -26,16 +26,17 @@ "bugs": "https://github.com/2createStudio/postcss-sprites/issues", "homepage": "https://github.com/2createStudio/postcss-sprites#readme", "devDependencies": { - "ava": "^0.15.2", - "babel-cli": "^6.4.0", - "babel-plugin-add-module-exports": "^0.2.1", - "babel-preset-es2015": "^6.3.13", + "@ava/babel": "^2.0.0", + "@babel/cli": "^7.16.0", + "@babel/plugin-transform-runtime": "^7.16.0", + "@babel/preset-env": "^7.16.0", + "ava": "^3.15.0", "postcss": "^8.1.2" }, "dependencies": { "bluebird": "^3.1.1", - "debug": "^2.6.0", - "fs-extra": "^0.26.4", + "debug": "^4.3.2", + "fs-extra": "^10.0.0", "lodash": "^4.0.0", "spritesmith": "^3.0.1", "svg-sprite": "^1.3.5" @@ -43,5 +44,11 @@ "peerDependencies": { "postcss": "^8.1.2" }, - "typings": "./typings.d.ts" + "typings": "./typings.d.ts", + "engines": { + "node": ">=12" + }, + "ava": { + "babel": true + } } diff --git a/test/07-run-spritesmith.js b/test/07-run-spritesmith.js index c42b983..9693cd7 100644 --- a/test/07-run-spritesmith.js +++ b/test/07-run-spritesmith.js @@ -12,8 +12,8 @@ test.beforeEach((t) => { }); test('should generate spritesheets', async (t) => { - const cssContents = await readFileAsync('./fixtures/basic/style.css'); - const ast = postcss.parse(cssContents, { from: './fixtures/basic/style.css' }); + const cssContents = await readFileAsync('./test/fixtures/basic/style.css'); + const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts; [ opts, images ] = await extractImages(ast, t.context.opts); @@ -24,8 +24,8 @@ test('should generate spritesheets', async (t) => { }); test('should generate SVG spritesheets', async (t) => { - const cssContents = await readFileAsync('./fixtures/svg-basic/style.css'); - const ast = postcss.parse(cssContents, { from: './fixtures/svg-basic/style.css' }); + const cssContents = await readFileAsync('./test/fixtures/svg-basic/style.css'); + const ast = postcss.parse(cssContents, { from: './test/fixtures/svg-basic/style.css' }); let images, spritesheets, opts; prepareGroupBy(t.context.opts); @@ -38,8 +38,8 @@ test('should generate SVG spritesheets', async (t) => { }); test('should generate spritesheets by groups', async (t) => { - const cssContents = await readFileAsync('./fixtures/retina/style.css'); - const ast = postcss.parse(cssContents, { from: './fixtures/retina/style.css' }); + const cssContents = await readFileAsync('./test/fixtures/retina/style.css'); + const ast = postcss.parse(cssContents, { from: './test/fixtures/retina/style.css' }); let images, spritesheets, opts; t.context.opts.retina = true; diff --git a/test/08-save-spritesheets.js b/test/08-save-spritesheets.js index b792999..8af6c7b 100644 --- a/test/08-save-spritesheets.js +++ b/test/08-save-spritesheets.js @@ -20,26 +20,26 @@ test.beforeEach((t) => { }); test('should save spritesheets', async (t) => { - const cssContents = await readFileAsync('./fixtures/basic/style.css'); - const ast = postcss.parse(cssContents, { from: './fixtures/basic/style.css' }); + const cssContents = await readFileAsync('./test/fixtures/basic/style.css'); + const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts; - t.context.opts.spritePath = './build/basic'; + t.context.opts.spritePath = './test/build/basic'; [ opts, images ] = await extractImages(ast, t.context.opts); [ opts, images, spritesheets ] = await runSpritesmith(t.context.opts, images); [ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets); - t.deepEqual(spritesheets[0].path, 'build/basic/sprite.png'); - t.truthy(fs.statAsync('./build/basic/sprite.png')); + t.deepEqual(spritesheets[0].path, 'test/build/basic/sprite.png'); + t.truthy(fs.statAsync('./test/build/basic/sprite.png')); }); test('should save SVG spritesheets', async (t) => { - const cssContents = await readFileAsync('./fixtures/svg-basic/style.css'); - const ast = postcss.parse(cssContents, { from: './fixtures/svg-basic/style.css' }); + const cssContents = await readFileAsync('./test/fixtures/svg-basic/style.css'); + const ast = postcss.parse(cssContents, { from: './test/fixtures/svg-basic/style.css' }); let images, spritesheets, opts; - t.context.opts.spritePath = './build/svg-basic'; + t.context.opts.spritePath = './test/build/svg-basic'; prepareGroupBy(t.context.opts); [ opts, images ] = await extractImages(ast, t.context.opts); @@ -47,16 +47,16 @@ test('should save SVG spritesheets', async (t) => { [ opts, images, spritesheets ] = await runSpritesmith(t.context.opts, images); [ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets); - t.deepEqual(spritesheets[0].path, 'build/svg-basic/sprite.svg'); - t.truthy(fs.statAsync('./build/svg-basic/sprite.svg')); + t.deepEqual(spritesheets[0].path, 'test/build/svg-basic/sprite.svg'); + t.truthy(fs.statAsync('./test/build/svg-basic/sprite.svg')); }); test('should save spritesheets by groups', async (t) => { - const cssContents = await readFileAsync('./fixtures/retina/style.css'); - const ast = postcss.parse(cssContents, { from: './fixtures/retina/style.css' }); + const cssContents = await readFileAsync('./test/fixtures/retina/style.css'); + const ast = postcss.parse(cssContents, { from: './test/fixtures/retina/style.css' }); let images, spritesheets, opts; - t.context.opts.spritePath = './build/retina'; + t.context.opts.spritePath = './test/build/retina'; t.context.opts.retina = true; prepareGroupBy(t.context.opts); @@ -66,18 +66,18 @@ test('should save spritesheets by groups', async (t) => { [ opts, images, spritesheets ] = await runSpritesmith(t.context.opts, images); [ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets); - t.deepEqual(spritesheets[0].path, 'build/retina/sprite.png'); - t.deepEqual(spritesheets[1].path, 'build/retina/sprite.@2x.png'); - t.truthy(fs.statAsync('./build/retina/sprite.png')); - t.truthy(fs.statAsync('./build/retina/sprite.@2x.png')); + t.deepEqual(spritesheets[0].path, 'test/build/retina/sprite.png'); + t.deepEqual(spritesheets[1].path, 'test/build/retina/sprite.@2x.png'); + t.truthy(fs.statAsync('./test/build/retina/sprite.png')); + t.truthy(fs.statAsync('./test/build/retina/sprite.@2x.png')); }); test('should use path provided by book', async (t) => { - const cssContents = await readFileAsync('./fixtures/basic/style.css'); - const ast = postcss.parse(cssContents, { from: './fixtures/basic/style.css' }); + const cssContents = await readFileAsync('./test/fixtures/basic/style.css'); + const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts; - t.context.opts.spritePath = './build/on-save-hook/'; + t.context.opts.spritePath = './test/build/on-save-hook/'; t.context.opts.hooks.onSaveSpritesheet = (pluginOpts, spritesheetGroups) => { return path.join(pluginOpts.spritePath, 'custom-name.png'); } @@ -86,16 +86,16 @@ test('should use path provided by book', async (t) => { [ opts, images, spritesheets ] = await runSpritesmith(t.context.opts, images); [ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets); - t.deepEqual(spritesheets[0].path, 'build/on-save-hook/custom-name.png'); - t.truthy(fs.statAsync('./build/on-save-hook/custom-name.png')); + t.deepEqual(spritesheets[0].path, 'test/build/on-save-hook/custom-name.png'); + t.truthy(fs.statAsync('./test/build/on-save-hook/custom-name.png')); }); test('should throw error if path is empty', async (t) => { - const cssContents = await readFileAsync('./fixtures/basic/style.css'); - const ast = postcss.parse(cssContents, { from: './fixtures/basic/style.css' }); + const cssContents = await readFileAsync('./test/fixtures/basic/style.css'); + const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts; - t.context.opts.spritePath = './build/on-save-hook/'; + t.context.opts.spritePath = './test/build/on-save-hook/'; t.context.opts.hooks.onSaveSpritesheet = (pluginOpts, spritesheetGroups) => { return ''; } @@ -103,15 +103,15 @@ test('should throw error if path is empty', async (t) => { [ opts, images ] = await extractImages(ast, t.context.opts); [ opts, images, spritesheets ] = await runSpritesmith(t.context.opts, images); - t.throws(saveSpritesheets(t.context.opts, images, spritesheets)); + return t.throwsAsync(() => saveSpritesheets(t.context.opts, images, spritesheets)); }); test('should use Promise result provided by book', async (t) => { - const cssContents = await readFileAsync('./fixtures/basic/style.css'); - const ast = postcss.parse(cssContents, { from: './fixtures/basic/style.css' }); + const cssContents = await readFileAsync('./test/fixtures/basic/style.css'); + const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts; - t.context.opts.spritePath = './build/on-save-hook/'; + t.context.opts.spritePath = './test/build/on-save-hook/'; t.context.opts.hooks.onSaveSpritesheet = (pluginOpts, spritesheetGroups) => { return new Promise(( resolve ) => setTimeout(() => resolve(Promise.resolve(path.join(pluginOpts.spritePath, 'custom-name.png'))), 0)); } @@ -120,6 +120,6 @@ test('should use Promise result provided by book', async (t) => { [ opts, images, spritesheets ] = await runSpritesmith(t.context.opts, images); [ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets); - t.deepEqual(spritesheets[0].path, 'build/on-save-hook/custom-name.png'); - t.truthy(fs.statAsync('./build/on-save-hook/custom-name.png')); + t.deepEqual(spritesheets[0].path, 'test/build/on-save-hook/custom-name.png'); + t.truthy(fs.statAsync('./test/build/on-save-hook/custom-name.png')); }); diff --git a/test/09-map-spritesheet-props.js b/test/09-map-spritesheet-props.js index 3261559..0d84869 100644 --- a/test/09-map-spritesheet-props.js +++ b/test/09-map-spritesheet-props.js @@ -20,27 +20,27 @@ test.beforeEach((t) => { }); test('should add coords & spritePath to every image', async (t) => { - const cssContents = await readFileAsync('./fixtures/basic/style.css'); - const ast = postcss.parse(cssContents, { from: './fixtures/basic/style.css' }); + const cssContents = await readFileAsync('./test/fixtures/basic/style.css'); + const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts; - t.context.opts.spritePath = './build/basic'; + t.context.opts.spritePath = './test/build/basic'; [ opts, images ] = await extractImages(ast, t.context.opts); [ opts, images, spritesheets ] = await runSpritesmith(t.context.opts, images); [ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets); [ opts, images, spritesheets ] = await mapSpritesheetProps(t.context.opts, images, spritesheets); - t.deepEqual(images[0].spritePath, 'build/basic/sprite.png'); + t.deepEqual(images[0].spritePath, 'test/build/basic/sprite.png'); t.deepEqual(images[0].coords, { x: 0, y: 0, height: 25, width: 25 }); }); test('should add coords & spritePath to every SVG image', async (t) => { - const cssContents = await readFileAsync('./fixtures/svg-basic/style.css'); - const ast = postcss.parse(cssContents, { from: './fixtures/svg-basic/style.css' }); + const cssContents = await readFileAsync('./test/fixtures/svg-basic/style.css'); + const ast = postcss.parse(cssContents, { from: './test/fixtures/svg-basic/style.css' }); let images, spritesheets, opts; - t.context.opts.spritePath = './build/svg-basic'; + t.context.opts.spritePath = './test/build/svg-basic'; prepareGroupBy(t.context.opts); [ opts, images ] = await extractImages(ast, t.context.opts); @@ -49,6 +49,6 @@ test('should add coords & spritePath to every SVG image', async (t) => { [ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets); [ opts, images, spritesheets ] = await mapSpritesheetProps(t.context.opts, images, spritesheets); - t.deepEqual(images[0].spritePath, 'build/svg-basic/sprite.svg'); + t.deepEqual(images[0].spritePath, 'test/build/svg-basic/sprite.svg'); t.deepEqual(images[0].coords, { x: 0, y: 0, height: 600, width: 600 }); }); diff --git a/test/10-update-references.js b/test/10-update-references.js index 46b040f..1ed1fda 100644 --- a/test/10-update-references.js +++ b/test/10-update-references.js @@ -21,13 +21,13 @@ test.beforeEach((t) => { }); test('should update CSS declarations', async (t) => { - const input = await readFileAsync('./fixtures/basic/style.css'); - const expected = await readFileAsync('./expectations/basic/style.css', 'utf8'); - const ast = postcss.parse(input, { from: './fixtures/basic/style.css' }); + const input = await readFileAsync('./test/fixtures/basic/style.css'); + const expected = await readFileAsync('./test/expectations/basic/style.css', 'utf8'); + const ast = postcss.parse(input, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts, root; - t.context.opts.spritePath = './build/basic'; - t.context.opts.stylesheetPath = './build/basic'; + t.context.opts.spritePath = './test/build/basic'; + t.context.opts.stylesheetPath = './test/build/basic'; [ opts, images ] = await extractImages(ast, t.context.opts); [ root, opts, images ] = await setTokens(ast, t.context.opts, images); @@ -40,12 +40,12 @@ test('should update CSS declarations', async (t) => { }); test('should update CSS declarations with relative paths', async (t) => { - const input = await readFileAsync('./fixtures/relative/style.css'); - const expected = await readFileAsync('./expectations/relative/style.css', 'utf8'); - const ast = postcss.parse(input, { from: './fixtures/relative/style.css' }); + const input = await readFileAsync('./test/fixtures/relative/style.css'); + const expected = await readFileAsync('./test/expectations/relative/style.css', 'utf8'); + const ast = postcss.parse(input, { from: './test/fixtures/relative/style.css' }); let images, spritesheets, opts, root; - t.context.opts.spritePath = './build/relative'; + t.context.opts.spritePath = './test/build/relative'; [ opts, images ] = await extractImages(ast, t.context.opts); [ root, opts, images ] = await setTokens(ast, t.context.opts, images); @@ -58,13 +58,13 @@ test('should update CSS declarations with relative paths', async (t) => { }); test('should use function provided by onUpdateRule hook', async (t) => { - const input = await readFileAsync('./fixtures/basic/style.css'); - const expected = await readFileAsync('./expectations/basic-on-update-rule-hook/style.css', 'utf8'); - const ast = postcss.parse(input, { from: './fixtures/basic/style.css' }); + const input = await readFileAsync('./test/fixtures/basic/style.css'); + const expected = await readFileAsync('./test/expectations/basic-on-update-rule-hook/style.css', 'utf8'); + const ast = postcss.parse(input, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts, root; - t.context.opts.spritePath = './build/basic-on-update-rule-hook'; - t.context.opts.stylesheetPath = './build/basic-on-update-rule-hook'; + t.context.opts.spritePath = './test/build/basic-on-update-rule-hook'; + t.context.opts.stylesheetPath = './test/build/basic-on-update-rule-hook'; t.context.opts.hooks.onUpdateRule = (rule, commentNode, image) => { const backgroundColorDecl = postcss.decl({ prop: 'background-color', diff --git a/test/11-e2e.js b/test/11-e2e.js index 0f40ac2..902f124 100644 --- a/test/11-e2e.js +++ b/test/11-e2e.js @@ -5,11 +5,11 @@ import Promise from 'bluebird'; import path from 'path'; import plugin from '../lib'; -Promise.promisifyAll(fs); +const readFileAsync = Promise.promisify(fs.readFile); async function run(inputPath, expectedPath, opts, t) { - const input = await fs.readFileAsync(inputPath, 'utf8'); - const expected = await fs.readFileAsync(expectedPath, 'utf8'); + const input = await readFileAsync(inputPath, 'utf8'); + const expected = await readFileAsync(expectedPath, 'utf8'); const processor = postcss([plugin(opts)]); const result = await processor.process(input, { from: inputPath }); @@ -17,46 +17,46 @@ async function run(inputPath, expectedPath, opts, t) { } test('throws error', async (t) => { - const inputPath = './fixtures/error/style.css'; + const inputPath = './test/fixtures/error/style.css'; const opts = { - stylesheetPath: './build/example-error/', - spritePath: './build/example-error/', + stylesheetPath: './test/build/example-error/', + spritePath: './test/build/example-error/', }; - const input = await fs.readFileAsync(inputPath, 'utf8'); + const input = await readFileAsync(inputPath, 'utf8'); const processor = postcss([plugin(opts)]); - t.throws(processor.process(input, { from: inputPath })); + return t.throwsAsync(() => processor.process(input, { from: inputPath })); }); test('basic', async (t) => { - const inputPath = './fixtures/basic/style.css'; - const expectedPath = './expectations/basic/style.css'; + const inputPath = './test/fixtures/basic/style.css'; + const expectedPath = './test/expectations/basic/style.css'; const opts = { - stylesheetPath: './build/basic/', - spritePath: './build/basic/' + stylesheetPath: './test/build/basic/', + spritePath: './test/build/basic/' }; return run(inputPath, expectedPath, opts, t); }); test('basic SVG', async (t) => { - const inputPath = './fixtures/svg-basic/style.css'; - const expectedPath = './expectations/svg-basic/style.css'; + const inputPath = './test/fixtures/svg-basic/style.css'; + const expectedPath = './test/expectations/svg-basic/style.css'; const opts = { - stylesheetPath: './build/svg-basic/', - spritePath: './build/svg-basic/' + stylesheetPath: './test/build/svg-basic/', + spritePath: './test/build/svg-basic/' }; return run(inputPath, expectedPath, opts, t); }); test('retina', async (t) => { - const inputPath = './fixtures/retina/style.css'; - const expectedPath = './expectations/retina/style.css'; + const inputPath = './test/fixtures/retina/style.css'; + const expectedPath = './test/expectations/retina/style.css'; const opts = { - stylesheetPath: './build/retina/', - spritePath: './build/retina/', + stylesheetPath: './test/build/retina/', + spritePath: './test/build/retina/', retina: true }; @@ -64,44 +64,44 @@ test('retina', async (t) => { }); test('color', async (t) => { - const inputPath = './fixtures/color/style.css'; - const expectedPath = './expectations/color/style.css'; + const inputPath = './test/fixtures/color/style.css'; + const expectedPath = './test/expectations/color/style.css'; const opts = { - stylesheetPath: './build/color/', - spritePath: './build/color/' + stylesheetPath: './test/build/color/', + spritePath: './test/build/color/' }; return run(inputPath, expectedPath, opts, t); }); test('absolute path', async (t) => { - const inputPath = './fixtures/absolute/css/style.css'; - const expectedPath = './expectations/absolute/style.css'; + const inputPath = './test/fixtures/absolute/css/style.css'; + const expectedPath = './test/expectations/absolute/style.css'; const opts = { - basePath: './fixtures/absolute/', - stylesheetPath: './build/absolute/', - spritePath: './build/absolute/' + basePath: './test/fixtures/absolute/', + stylesheetPath: './test/build/absolute/', + spritePath: './test/build/absolute/' }; return run(inputPath, expectedPath, opts, t); }); test('relative path', async (t) => { - const inputPath = './fixtures/relative/style.css'; - const expectedPath = './expectations/relative/style.css'; + const inputPath = './test/fixtures/relative/style.css'; + const expectedPath = './test/expectations/relative/style.css'; const opts = { - spritePath: './build/relative/' + spritePath: './test/build/relative/' }; return run(inputPath, expectedPath, opts, t); }); test('filter by', async (t) => { - const inputPath = './fixtures/filter-by/style.css'; - const expectedPath = './expectations/filter-by/style.css'; + const inputPath = './test/fixtures/filter-by/style.css'; + const expectedPath = './test/expectations/filter-by/style.css'; const opts = { - stylesheetPath: './build/filter-by/', - spritePath: './build/filter-by/', + stylesheetPath: './test/build/filter-by/', + spritePath: './test/build/filter-by/', filterBy: (image) => { if (image.url.indexOf('square') === -1) { return Promise.reject(); @@ -115,11 +115,11 @@ test('filter by', async (t) => { }); test('group by', async (t) => { - const inputPath = './fixtures/group-by/style.css'; - const expectedPath = './expectations/group-by/style.css'; + const inputPath = './test/fixtures/group-by/style.css'; + const expectedPath = './test/expectations/group-by/style.css'; const opts = { - stylesheetPath: './build/group-by/', - spritePath: './build/group-by/', + stylesheetPath: './test/build/group-by/', + spritePath: './test/build/group-by/', groupBy: (image) => { if (image.url.indexOf('square') === -1 && image.url.indexOf('circle') === -1) { return Promise.reject(); @@ -133,14 +133,14 @@ test('group by', async (t) => { }); test('hooks', async (t) => { - const inputPath = './fixtures/hooks/style.css'; - const expectedPath = './expectations/hooks/style.css'; + const inputPath = './test/fixtures/hooks/style.css'; + const expectedPath = './test/expectations/hooks/style.css'; const opts = { - stylesheetPath: './build/hooks/', - spritePath: './build/hooks/', + stylesheetPath: './test/build/hooks/', + spritePath: './test/build/hooks/', hooks: { - onSaveSpritesheet: (opts, groups) => { - return path.join(opts.spritePath, ['shapes', ...groups, 'png'].join('.')); + onSaveSpritesheet: (opts, spritesheet) => { + return path.join(opts.spritePath, ['shapes', ...spritesheet.groups, 'png'].join('.')); }, onUpdateRule: (rule, token, image) => { rule.insertAfter(token, postcss.decl({ diff --git a/test/12-examples.js b/test/12-examples.js index 21da3e0..67c093e 100644 --- a/test/12-examples.js +++ b/test/12-examples.js @@ -6,11 +6,11 @@ import path from 'path'; import plugin from '../lib'; import { updateRule } from '../lib/core'; -Promise.promisifyAll(fs); +const readFileAsync = Promise.promisify(fs.readFile); async function run(inputPath, expectedPath, opts, t) { - const input = await fs.readFileAsync(inputPath, 'utf8'); - const expected = await fs.readFileAsync(expectedPath, 'utf8'); + const input = await readFileAsync(inputPath, 'utf8'); + const expected = await readFileAsync(expectedPath, 'utf8'); const processor = postcss([plugin(opts)]); const result = await processor.process(input, { from: inputPath }); @@ -18,11 +18,11 @@ async function run(inputPath, expectedPath, opts, t) { } test('filter by', async (t) => { - const inputPath = './fixtures/example-filter-by/style.css'; - const expectedPath = './expectations/example-filter-by/style.css'; + const inputPath = './test/fixtures/example-filter-by/style.css'; + const expectedPath = './test/expectations/example-filter-by/style.css'; const opts = { - stylesheetPath: './build/example-filter-by/', - spritePath: './build/example-filter-by/', + stylesheetPath: './test/build/example-filter-by/', + spritePath: './test/build/example-filter-by/', filterBy: (image) => { if (!/\.png$/.test(image.url)) { return Promise.reject(); @@ -36,11 +36,11 @@ test('filter by', async (t) => { }); test('group by', async (t) => { - const inputPath = './fixtures/example-group-by/style.css'; - const expectedPath = './expectations/example-group-by/style.css'; + const inputPath = './test/fixtures/example-group-by/style.css'; + const expectedPath = './test/expectations/example-group-by/style.css'; const opts = { - stylesheetPath: './build/example-group-by/', - spritePath: './build/example-group-by/', + stylesheetPath: './test/build/example-group-by/', + spritePath: './test/build/example-group-by/', groupBy: (image) => { if (image.url.indexOf('shapes') === -1) { return Promise.reject(); @@ -54,11 +54,11 @@ test('group by', async (t) => { }); test('output dimensions', async (t) => { - const inputPath = './fixtures/example-output-dimensions/style.css'; - const expectedPath = './expectations/example-output-dimensions/style.css'; + const inputPath = './test/fixtures/example-output-dimensions/style.css'; + const expectedPath = './test/expectations/example-output-dimensions/style.css'; const opts = { - stylesheetPath: './build/example-output-dimensions/', - spritePath: './build/example-output-dimensions/', + stylesheetPath: './test/build/example-output-dimensions/', + spritePath: './test/build/example-output-dimensions/', hooks: { onUpdateRule: (rule, token, image) => { updateRule(rule, token, image); @@ -77,11 +77,11 @@ test('output dimensions', async (t) => { }); test('responsive spritesheets', async (t) => { - const inputPath = './fixtures/example-responsive-spritesheets/style.css'; - const expectedPath = './expectations/example-responsive-spritesheets/style.css'; + const inputPath = './test/fixtures/example-responsive-spritesheets/style.css'; + const expectedPath = './test/expectations/example-responsive-spritesheets/style.css'; const opts = { - stylesheetPath: './build/example-responsive-spritesheets/', - spritePath: './build/example-responsive-spritesheets/', + stylesheetPath: './test/build/example-responsive-spritesheets/', + spritePath: './test/build/example-responsive-spritesheets/', hooks: { onUpdateRule: (rule, token, image) => { let backgroundSizeX = (image.spriteWidth / image.coords.width) * 100; @@ -120,11 +120,11 @@ test('responsive spritesheets', async (t) => { }); test('skip prefix', async (t) => { - const inputPath = './fixtures/example-skip-prefix/style.css'; - const expectedPath = './expectations/example-skip-prefix/style.css'; + const inputPath = './test/fixtures/example-skip-prefix/style.css'; + const expectedPath = './test/expectations/example-skip-prefix/style.css'; const opts = { - stylesheetPath: './build/example-skip-prefix/', - spritePath: './build/example-skip-prefix/', + stylesheetPath: './test/build/example-skip-prefix/', + spritePath: './test/build/example-skip-prefix/', hooks: { onSaveSpritesheet: (opts, groups) => { return path.join(opts.spritePath, 'shapes.png'); From 3026dd7717380b5c09a5429c95178a24a258244d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Mon, 8 Nov 2021 11:05:02 +0100 Subject: [PATCH 04/20] Use `Buffer.from` --- src/core.js | 2 +- src/factories/vector.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index 08579a6..59d28b2 100644 --- a/src/core.js +++ b/src/core.js @@ -61,7 +61,7 @@ export const defaults = { shape: { id: { generator(name, file) { - return new Buffer(file.path).toString('base64'); + return Buffer.from(file.path).toString('base64'); } } }, diff --git a/src/factories/vector.js b/src/factories/vector.js index 72a432a..c5414c2 100644 --- a/src/factories/vector.js +++ b/src/factories/vector.js @@ -33,7 +33,7 @@ export default function run(opts, images) { data.css.shapes.forEach((shape) => { - spritesheet.coordinates[new Buffer(shape.name, 'base64').toString()] = { + spritesheet.coordinates[Buffer.from(shape.name, 'base64').toString()] = { width: shape.width.outer, height: shape.height.outer, x: shape.position.absolute.x, From 6a2ae5b72a325a400ee239abc986cb15cc5295fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Mon, 8 Nov 2021 11:06:16 +0100 Subject: [PATCH 05/20] Update test values --- test/09-map-spritesheet-props.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/09-map-spritesheet-props.js b/test/09-map-spritesheet-props.js index 0d84869..2aa1265 100644 --- a/test/09-map-spritesheet-props.js +++ b/test/09-map-spritesheet-props.js @@ -50,5 +50,5 @@ test('should add coords & spritePath to every SVG image', async (t) => { [ opts, images, spritesheets ] = await mapSpritesheetProps(t.context.opts, images, spritesheets); t.deepEqual(images[0].spritePath, 'test/build/svg-basic/sprite.svg'); - t.deepEqual(images[0].coords, { x: 0, y: 0, height: 600, width: 600 }); + t.deepEqual(images[0].coords, { x: -0, y: -0, height: 600, width: 600 }); }); From 043d123ae8cf3c4357b474363e16e914ce47c1d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Mon, 8 Nov 2021 11:45:27 +0100 Subject: [PATCH 06/20] Simplify Bluebird usage --- src/core.js | 9 ++------- test/04-apply-filter-by.js | 1 - test/05-apply-group-by.js | 1 - test/07-run-spritesmith.js | 11 ++++------- test/08-save-spritesheets.js | 27 ++++++++++++--------------- test/09-map-spritesheet-props.js | 7 ++----- test/10-update-references.js | 15 ++++++--------- test/11-e2e.js | 9 +++------ test/12-examples.js | 7 ++----- 9 files changed, 31 insertions(+), 56 deletions(-) diff --git a/src/core.js b/src/core.js index 59d28b2..70e2e28 100644 --- a/src/core.js +++ b/src/core.js @@ -6,11 +6,6 @@ import debug from 'debug'; import RasterFactory from './factories/raster'; import VectorFactory from './factories/vector'; -/** - * Wrap with promises. - */ -Promise.promisifyAll(fs); - /** * Plugin constants. */ @@ -86,7 +81,7 @@ export function prepareFilterBy(opts, result) { // Filter non existing images opts.filterBy.unshift(image => { - return fs.statAsync(image.path) + return fs.stat(image.path) .catch(() => { const message = `Skip ${image.url} because doesn't exist.`; @@ -363,7 +358,7 @@ export function saveSpritesheets(opts, images, spritesheets) { spritesheet.path = spritesheet.path.replace(/\\/g, '/'); - return fs.outputFileAsync(spritesheet.path, spritesheet.image); + return fs.outputFile(spritesheet.path, spritesheet.image); }); }).then(spritesheets => { return [opts, images, spritesheets]; diff --git a/test/04-apply-filter-by.js b/test/04-apply-filter-by.js index a614ef1..9089198 100644 --- a/test/04-apply-filter-by.js +++ b/test/04-apply-filter-by.js @@ -1,6 +1,5 @@ import test from 'ava'; import postcss from 'postcss'; -import Promise from 'bluebird'; import _ from 'lodash'; import { defaults, prepareFilterBy, extractImages, applyFilterBy } from '../lib/core'; diff --git a/test/05-apply-group-by.js b/test/05-apply-group-by.js index 2ccb955..80e41c5 100644 --- a/test/05-apply-group-by.js +++ b/test/05-apply-group-by.js @@ -1,6 +1,5 @@ import test from 'ava'; import postcss from 'postcss'; -import Promise from 'bluebird'; import _ from 'lodash'; import { defaults, prepareGroupBy, extractImages, applyGroupBy } from '../lib/core'; diff --git a/test/07-run-spritesmith.js b/test/07-run-spritesmith.js index 9693cd7..00f64fe 100644 --- a/test/07-run-spritesmith.js +++ b/test/07-run-spritesmith.js @@ -1,18 +1,15 @@ import test from 'ava'; import postcss from 'postcss'; import _ from 'lodash'; -import Promise from 'bluebird'; -import fs from 'fs'; +import fs from 'fs-extra'; import { defaults, extractImages, prepareGroupBy, applyGroupBy, runSpritesmith } from '../lib/core'; -const readFileAsync = Promise.promisify(fs.readFile); - test.beforeEach((t) => { t.context.opts = _.merge({ logger() {} }, defaults); }); test('should generate spritesheets', async (t) => { - const cssContents = await readFileAsync('./test/fixtures/basic/style.css'); + const cssContents = await fs.readFile('./test/fixtures/basic/style.css'); const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts; @@ -24,7 +21,7 @@ test('should generate spritesheets', async (t) => { }); test('should generate SVG spritesheets', async (t) => { - const cssContents = await readFileAsync('./test/fixtures/svg-basic/style.css'); + const cssContents = await fs.readFile('./test/fixtures/svg-basic/style.css'); const ast = postcss.parse(cssContents, { from: './test/fixtures/svg-basic/style.css' }); let images, spritesheets, opts; @@ -38,7 +35,7 @@ test('should generate SVG spritesheets', async (t) => { }); test('should generate spritesheets by groups', async (t) => { - const cssContents = await readFileAsync('./test/fixtures/retina/style.css'); + const cssContents = await fs.readFile('./test/fixtures/retina/style.css'); const ast = postcss.parse(cssContents, { from: './test/fixtures/retina/style.css' }); let images, spritesheets, opts; diff --git a/test/08-save-spritesheets.js b/test/08-save-spritesheets.js index 8af6c7b..5cf5e2c 100644 --- a/test/08-save-spritesheets.js +++ b/test/08-save-spritesheets.js @@ -1,7 +1,6 @@ import test from 'ava'; import postcss from 'postcss'; import _ from 'lodash'; -import Promise from 'bluebird'; import fs from 'fs-extra'; import path from 'path'; import { @@ -13,14 +12,12 @@ import { saveSpritesheets } from '../lib/core'; -const readFileAsync = Promise.promisify(fs.readFile); - test.beforeEach((t) => { t.context.opts = _.merge({ logger() {} }, defaults); }); test('should save spritesheets', async (t) => { - const cssContents = await readFileAsync('./test/fixtures/basic/style.css'); + const cssContents = await fs.readFile('./test/fixtures/basic/style.css'); const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts; @@ -31,11 +28,11 @@ test('should save spritesheets', async (t) => { [ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets); t.deepEqual(spritesheets[0].path, 'test/build/basic/sprite.png'); - t.truthy(fs.statAsync('./test/build/basic/sprite.png')); + t.truthy(fs.stat('./test/build/basic/sprite.png')); }); test('should save SVG spritesheets', async (t) => { - const cssContents = await readFileAsync('./test/fixtures/svg-basic/style.css'); + const cssContents = await fs.readFile('./test/fixtures/svg-basic/style.css'); const ast = postcss.parse(cssContents, { from: './test/fixtures/svg-basic/style.css' }); let images, spritesheets, opts; @@ -48,11 +45,11 @@ test('should save SVG spritesheets', async (t) => { [ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets); t.deepEqual(spritesheets[0].path, 'test/build/svg-basic/sprite.svg'); - t.truthy(fs.statAsync('./test/build/svg-basic/sprite.svg')); + t.truthy(fs.stat('./test/build/svg-basic/sprite.svg')); }); test('should save spritesheets by groups', async (t) => { - const cssContents = await readFileAsync('./test/fixtures/retina/style.css'); + const cssContents = await fs.readFile('./test/fixtures/retina/style.css'); const ast = postcss.parse(cssContents, { from: './test/fixtures/retina/style.css' }); let images, spritesheets, opts; @@ -68,12 +65,12 @@ test('should save spritesheets by groups', async (t) => { t.deepEqual(spritesheets[0].path, 'test/build/retina/sprite.png'); t.deepEqual(spritesheets[1].path, 'test/build/retina/sprite.@2x.png'); - t.truthy(fs.statAsync('./test/build/retina/sprite.png')); - t.truthy(fs.statAsync('./test/build/retina/sprite.@2x.png')); + t.truthy(fs.stat('./test/build/retina/sprite.png')); + t.truthy(fs.stat('./test/build/retina/sprite.@2x.png')); }); test('should use path provided by book', async (t) => { - const cssContents = await readFileAsync('./test/fixtures/basic/style.css'); + const cssContents = await fs.readFile('./test/fixtures/basic/style.css'); const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts; @@ -87,11 +84,11 @@ test('should use path provided by book', async (t) => { [ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets); t.deepEqual(spritesheets[0].path, 'test/build/on-save-hook/custom-name.png'); - t.truthy(fs.statAsync('./test/build/on-save-hook/custom-name.png')); + t.truthy(fs.stat('./test/build/on-save-hook/custom-name.png')); }); test('should throw error if path is empty', async (t) => { - const cssContents = await readFileAsync('./test/fixtures/basic/style.css'); + const cssContents = await fs.readFile('./test/fixtures/basic/style.css'); const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts; @@ -107,7 +104,7 @@ test('should throw error if path is empty', async (t) => { }); test('should use Promise result provided by book', async (t) => { - const cssContents = await readFileAsync('./test/fixtures/basic/style.css'); + const cssContents = await fs.readFile('./test/fixtures/basic/style.css'); const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts; @@ -121,5 +118,5 @@ test('should use Promise result provided by book', async (t) => { [ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets); t.deepEqual(spritesheets[0].path, 'test/build/on-save-hook/custom-name.png'); - t.truthy(fs.statAsync('./test/build/on-save-hook/custom-name.png')); + t.truthy(fs.stat('./test/build/on-save-hook/custom-name.png')); }); diff --git a/test/09-map-spritesheet-props.js b/test/09-map-spritesheet-props.js index 2aa1265..560b634 100644 --- a/test/09-map-spritesheet-props.js +++ b/test/09-map-spritesheet-props.js @@ -1,7 +1,6 @@ import test from 'ava'; import postcss from 'postcss'; import _ from 'lodash'; -import Promise from 'bluebird'; import fs from 'fs-extra'; import { defaults, @@ -13,14 +12,12 @@ import { applyGroupBy } from '../lib/core'; -const readFileAsync = Promise.promisify(fs.readFile); - test.beforeEach((t) => { t.context.opts = _.merge({ logger() {} }, defaults); }); test('should add coords & spritePath to every image', async (t) => { - const cssContents = await readFileAsync('./test/fixtures/basic/style.css'); + const cssContents = await fs.readFile('./test/fixtures/basic/style.css'); const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts; @@ -36,7 +33,7 @@ test('should add coords & spritePath to every image', async (t) => { }); test('should add coords & spritePath to every SVG image', async (t) => { - const cssContents = await readFileAsync('./test/fixtures/svg-basic/style.css'); + const cssContents = await fs.readFile('./test/fixtures/svg-basic/style.css'); const ast = postcss.parse(cssContents, { from: './test/fixtures/svg-basic/style.css' }); let images, spritesheets, opts; diff --git a/test/10-update-references.js b/test/10-update-references.js index 1ed1fda..cfef5fc 100644 --- a/test/10-update-references.js +++ b/test/10-update-references.js @@ -1,7 +1,6 @@ import test from 'ava'; import postcss from 'postcss'; import _ from 'lodash'; -import Promise from 'bluebird'; import fs from 'fs-extra'; import { defaults, @@ -14,15 +13,13 @@ import { updateRule } from '../lib/core'; -const readFileAsync = Promise.promisify(fs.readFile); - test.beforeEach((t) => { t.context.opts = _.merge({ logger() {} }, defaults); }); test('should update CSS declarations', async (t) => { - const input = await readFileAsync('./test/fixtures/basic/style.css'); - const expected = await readFileAsync('./test/expectations/basic/style.css', 'utf8'); + const input = await fs.readFile('./test/fixtures/basic/style.css'); + const expected = await fs.readFile('./test/expectations/basic/style.css', 'utf8'); const ast = postcss.parse(input, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts, root; @@ -40,8 +37,8 @@ test('should update CSS declarations', async (t) => { }); test('should update CSS declarations with relative paths', async (t) => { - const input = await readFileAsync('./test/fixtures/relative/style.css'); - const expected = await readFileAsync('./test/expectations/relative/style.css', 'utf8'); + const input = await fs.readFile('./test/fixtures/relative/style.css'); + const expected = await fs.readFile('./test/expectations/relative/style.css', 'utf8'); const ast = postcss.parse(input, { from: './test/fixtures/relative/style.css' }); let images, spritesheets, opts, root; @@ -58,8 +55,8 @@ test('should update CSS declarations with relative paths', async (t) => { }); test('should use function provided by onUpdateRule hook', async (t) => { - const input = await readFileAsync('./test/fixtures/basic/style.css'); - const expected = await readFileAsync('./test/expectations/basic-on-update-rule-hook/style.css', 'utf8'); + const input = await fs.readFile('./test/fixtures/basic/style.css'); + const expected = await fs.readFile('./test/expectations/basic-on-update-rule-hook/style.css', 'utf8'); const ast = postcss.parse(input, { from: './test/fixtures/basic/style.css' }); let images, spritesheets, opts, root; diff --git a/test/11-e2e.js b/test/11-e2e.js index 902f124..128ddd4 100644 --- a/test/11-e2e.js +++ b/test/11-e2e.js @@ -1,15 +1,12 @@ import test from 'ava'; import postcss from 'postcss'; import fs from 'fs-extra'; -import Promise from 'bluebird'; import path from 'path'; import plugin from '../lib'; -const readFileAsync = Promise.promisify(fs.readFile); - async function run(inputPath, expectedPath, opts, t) { - const input = await readFileAsync(inputPath, 'utf8'); - const expected = await readFileAsync(expectedPath, 'utf8'); + const input = await fs.readFile(inputPath, 'utf8'); + const expected = await fs.readFile(expectedPath, 'utf8'); const processor = postcss([plugin(opts)]); const result = await processor.process(input, { from: inputPath }); @@ -23,7 +20,7 @@ test('throws error', async (t) => { spritePath: './test/build/example-error/', }; - const input = await readFileAsync(inputPath, 'utf8'); + const input = await fs.readFile(inputPath, 'utf8'); const processor = postcss([plugin(opts)]); return t.throwsAsync(() => processor.process(input, { from: inputPath })); diff --git a/test/12-examples.js b/test/12-examples.js index 67c093e..1220381 100644 --- a/test/12-examples.js +++ b/test/12-examples.js @@ -1,16 +1,13 @@ import test from 'ava'; import postcss from 'postcss'; import fs from 'fs-extra'; -import Promise from 'bluebird'; import path from 'path'; import plugin from '../lib'; import { updateRule } from '../lib/core'; -const readFileAsync = Promise.promisify(fs.readFile); - async function run(inputPath, expectedPath, opts, t) { - const input = await readFileAsync(inputPath, 'utf8'); - const expected = await readFileAsync(expectedPath, 'utf8'); + const input = await fs.readFile(inputPath, 'utf8'); + const expected = await fs.readFile(expectedPath, 'utf8'); const processor = postcss([plugin(opts)]); const result = await processor.process(input, { from: inputPath }); From ccd548130e9f2a5479119e2a377c26a4a4b7328c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Mon, 8 Nov 2021 12:48:10 +0100 Subject: [PATCH 07/20] Remove Bluebird --- package.json | 5 ++++- src/core.js | 15 +++++++++------ src/factories/raster.js | 4 ++-- src/factories/vector.js | 15 ++++++++++----- src/index.js | 16 ++++++++-------- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 0e8e5fb..a477aae 100644 --- a/package.json +++ b/package.json @@ -34,10 +34,13 @@ "postcss": "^8.1.2" }, "dependencies": { - "bluebird": "^3.1.1", "debug": "^4.3.2", "fs-extra": "^10.0.0", "lodash": "^4.0.0", + "p-each-series": "^2.2.0", + "p-filter": "^2.1.0", + "p-map": "^4.0.0", + "p-reduce": "^2.1.0", "spritesmith": "^3.0.1", "svg-sprite": "^1.3.5" }, diff --git a/src/core.js b/src/core.js index 70e2e28..bf1722e 100644 --- a/src/core.js +++ b/src/core.js @@ -1,8 +1,11 @@ import path from 'path'; import fs from 'fs-extra'; -import Promise from 'bluebird'; import _ from 'lodash'; import debug from 'debug'; +import pFilter from 'p-filter'; +import pReduce from 'p-reduce'; +import pMap from 'p-map'; +import pEach from 'p-each-series'; import RasterFactory from './factories/raster'; import VectorFactory from './factories/vector'; @@ -196,8 +199,8 @@ export function extractImages(root, opts, result) { export function applyFilterBy(opts, images) { opts.logger('Applying the filters...'); - return Promise.reduce(opts.filterBy, (images, filterFn) => { - return Promise.filter(images, (image) => { + return pReduce(opts.filterBy, (images, filterFn) => { + return pFilter(images, (image) => { return filterFn(image) .then(() => true) .catch(() => false); @@ -214,8 +217,8 @@ export function applyFilterBy(opts, images) { export function applyGroupBy(opts, images) { opts.logger('Applying the groups...'); - return Promise.reduce(opts.groupBy, (images, groupFn) => { - return Promise.map(images, (image) => { + return pReduce(opts.groupBy, (images, groupFn) => { + return pMap(images, (image) => { return groupFn(image) .then(group => { image.groups.push(group); @@ -339,7 +342,7 @@ export function runSpritesmith(opts, images) { export function saveSpritesheets(opts, images, spritesheets) { opts.logger('Saving the spritesheets...'); - return Promise.each(spritesheets, (spritesheet) => { + return pEach(spritesheets, (spritesheet) => { return ( _.isFunction(opts.hooks.onSaveSpritesheet) ? Promise.resolve(opts.hooks.onSaveSpritesheet(opts, spritesheet)) : diff --git a/src/factories/raster.js b/src/factories/raster.js index 2e14d0e..b201772 100644 --- a/src/factories/raster.js +++ b/src/factories/raster.js @@ -1,5 +1,5 @@ import Spritesmith from 'spritesmith'; -import Promise from 'bluebird'; +import { promisify } from 'util'; import _ from 'lodash'; /** @@ -27,7 +27,7 @@ export default function run(opts, images) { } } - return Promise.promisify(Spritesmith.run, { context: Spritesmith })(config) + return promisify(Spritesmith.run.bind(Spritesmith))(config) .then((spritesheet) => { spritesheet.extension = 'png'; diff --git a/src/factories/vector.js b/src/factories/vector.js index c5414c2..59a0241 100644 --- a/src/factories/vector.js +++ b/src/factories/vector.js @@ -1,6 +1,6 @@ import fs from 'fs'; import SVGSpriter from 'svg-sprite'; -import Promise from 'bluebird'; +import { promisify } from 'util'; import _ from 'lodash'; /** @@ -17,10 +17,15 @@ export default function run(opts, images) { spriter.add(path, null, fs.readFileSync(path, { encoding: 'utf-8' })); }); - return Promise.promisify(spriter.compile, { - context: spriter, - multiArgs: true - })().spread((result, data) => { + return new Promise((resolve, reject) => { + spriter.compile((error, ...result) => { + if (error) { + reject(error); + return + } + resolve(result); + }) + }).then(([result, data]) => { const spritesheet = {}; spritesheet.extension = 'svg'; diff --git a/src/index.js b/src/index.js index f519d90..e731559 100644 --- a/src/index.js +++ b/src/index.js @@ -33,14 +33,14 @@ const plugin = (options = {}) => { // Process it return extractImages(css, opts, result) - .spread((opts, images) => applyFilterBy(opts, images)) - .spread((opts, images) => applyGroupBy(opts, images)) - .spread((opts, images) => setTokens(css, opts, images)) - .spread((root, opts, images) => runSpritesmith(opts, images)) - .spread((opts, images, spritesheets) => saveSpritesheets(opts, images, spritesheets)) - .spread((opts, images, spritesheets) => mapSpritesheetProps(opts, images, spritesheets)) - .spread((opts, images, spritesheets) => updateReferences(css, opts, images, spritesheets)) - .spread((root, opts, images, spritesheets) => { + .then(([opts, images]) => applyFilterBy(opts, images)) + .then(([opts, images]) => applyGroupBy(opts, images)) + .then(([opts, images]) => setTokens(css, opts, images)) + .then(([root, opts, images]) => runSpritesmith(opts, images)) + .then(([opts, images, spritesheets]) => saveSpritesheets(opts, images, spritesheets)) + .then(([opts, images, spritesheets]) => mapSpritesheetProps(opts, images, spritesheets)) + .then(([opts, images, spritesheets]) => updateReferences(css, opts, images, spritesheets)) + .then(([root, opts, images, spritesheets]) => { opts.logger(`${spritesheets.length} ${spritesheets.length > 1 ? 'spritesheets' : 'spritesheet'} generated.`); }) .catch((err) => { From 1148a04f9f3009b08d5367d2f4ae3d29e66cf9fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Mon, 8 Nov 2021 12:58:09 +0100 Subject: [PATCH 08/20] Use GitHub Actions --- .github/workflows/ci.yml | 26 ++++++++++++++++++++++++++ .travis.yml | 8 -------- package.json | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..fc2c3b2 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,26 @@ +name: CI +on: + - push + - pull_request +jobs: + Test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: + - 12 + - 16 + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Use Node ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: npm install + + - name: Test + run: npm test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 27c27b0..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -sudo: false -language: node_js -node_js: - - stable - - "10" -branches: - only: - - master diff --git a/package.json b/package.json index a477aae..3f107ee 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "test": "ava test/*.js --verbose --serial", "build": "babel src/ --out-dir lib/", "watch": "babel --watch src/ --out-dir lib/", - "prepublish": "npm test", + "prepublishOnly": "npm run build && npm test", "pretest": "npm run build" }, "repository": "2createStudio/postcss-sprites", From 1f02c3d04a0e913549153c3fb112aa36ef525936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Mon, 8 Nov 2021 12:59:46 +0100 Subject: [PATCH 09/20] Update badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 96585f0..9f6d865 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# postcss-sprites [![Build Status](https://travis-ci.org/2createStudio/postcss-sprites.svg?branch=master)](https://travis-ci.org/2createStudio/postcss-sprites) [![npm version](https://badge.fury.io/js/postcss-sprites.svg)](http://badge.fury.io/js/postcss-sprites) +# postcss-sprites [![Build Status](https://github.com/niksy/postcss-sprites/workflows/CI/badge.svg?branch=postcss-8-support)](https://github.com/niksy/postcss-sprites/actions?query=workflow%3ACI) [![npm version](https://badge.fury.io/js/postcss-sprites.svg)](https://badge.fury.io/js/postcss-sprites) > [PostCSS](https://github.com/postcss/postcss) plugin that generates spritesheets from your stylesheets. From de8fb343c6e50a83be7694f0cb8338c37bdd8319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Mon, 8 Nov 2021 15:45:35 +0100 Subject: [PATCH 10/20] Update Babel configuration --- .babelrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.babelrc b/.babelrc index 954afbf..56c22d1 100644 --- a/.babelrc +++ b/.babelrc @@ -3,6 +3,6 @@ ["@babel/preset-env", { "loose": true }] ], "plugins": [ - "@babel/plugin-transform-runtime" + ["@babel/plugin-transform-runtime", { "helpers": false }] ] } From ae6664d418c04c53d91002e932f9ae51f040cce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Mon, 8 Nov 2021 16:27:14 +0100 Subject: [PATCH 11/20] Adjust Node target for Babel compile --- .babelrc | 5 +---- package.json | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.babelrc b/.babelrc index 56c22d1..af12ba4 100644 --- a/.babelrc +++ b/.babelrc @@ -1,8 +1,5 @@ { "presets": [ - ["@babel/preset-env", { "loose": true }] - ], - "plugins": [ - ["@babel/plugin-transform-runtime", { "helpers": false }] + ["@babel/preset-env", { "loose": true, "targets": { "node": "12" } }] ] } diff --git a/package.json b/package.json index 3f107ee..482cc8d 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "devDependencies": { "@ava/babel": "^2.0.0", "@babel/cli": "^7.16.0", - "@babel/plugin-transform-runtime": "^7.16.0", "@babel/preset-env": "^7.16.0", "ava": "^3.15.0", "postcss": "^8.1.2" From 1b8755f5d2fa6de84129e30ca62e1dbdce87593f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Mon, 8 Nov 2021 16:28:40 +0100 Subject: [PATCH 12/20] Adjust plugin exports --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index e731559..1eae758 100644 --- a/src/index.js +++ b/src/index.js @@ -51,5 +51,6 @@ const plugin = (options = {}) => { } } }; -export default plugin; plugin.postcss = true; + +export default plugin; From d9f63a9544aea58a511f401b557497a2bf48d0d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Mon, 8 Nov 2021 16:31:21 +0100 Subject: [PATCH 13/20] Update documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f6d865..832fea0 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ ```javascript var fs = require('fs'); var postcss = require('postcss'); -var sprites = require('postcss-sprites'); +var { default: sprites } = require('postcss-sprites'); var css = fs.readFileSync('./css/style.css', 'utf8'); var opts = { From 71de80897f64a933c3c0e4685720750491940beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Mon, 8 Nov 2021 16:33:57 +0100 Subject: [PATCH 14/20] Update changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b0d557..47dc73a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## [5.0.0] - 2021-11-08 +### Changed +- Support PostCSS >= 8 +- Support Node >= 12 +- Dependencies upgrade +- Default export is now inside `default` (follows default Babel implementation) + ## [4.2.1] - 2017-02-07 ### Fixed - Preserve source of original declarations - See #90 From f2d81ad62cb90e9004a1ead445387950bcd674fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Wed, 17 Nov 2021 08:22:27 +0100 Subject: [PATCH 15/20] Adjust attributions --- README.md | 2 +- package.json | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 832fea0..a5773e6 100644 --- a/README.md +++ b/README.md @@ -265,7 +265,7 @@ Every filter or group function will be called with an ``Image`` object. Pull requests are welcome. ``` -$ git clone git@github.com:2createStudio/postcss-sprites.git +$ git clone git@github.com:niksy/postcss-sprites.git $ npm install $ npm run watch ``` diff --git a/package.json b/package.json index 482cc8d..fd879fc 100644 --- a/package.json +++ b/package.json @@ -20,11 +20,11 @@ "prepublishOnly": "npm run build && npm test", "pretest": "npm run build" }, - "repository": "2createStudio/postcss-sprites", - "author": "2createStudio", + "repository": "niksy/postcss-sprites", + "author": "niksy", "license": "MIT", - "bugs": "https://github.com/2createStudio/postcss-sprites/issues", - "homepage": "https://github.com/2createStudio/postcss-sprites#readme", + "bugs": "https://github.com/niksy/postcss-sprites/issues", + "homepage": "https://github.com/niksy/postcss-sprites#readme", "devDependencies": { "@ava/babel": "^2.0.0", "@babel/cli": "^7.16.0", From 4411f03490e9a728912388239acb3791faceacf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Wed, 17 Nov 2021 08:22:40 +0100 Subject: [PATCH 16/20] Improve typings --- typings.d.ts | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 179 insertions(+), 1 deletion(-) diff --git a/typings.d.ts b/typings.d.ts index c6235f8..e73c197 100644 --- a/typings.d.ts +++ b/typings.d.ts @@ -1 +1,179 @@ -export declare function sprites(): any; +import { Plugin, AnyNode, Comment } from 'postcss'; + +interface Spritesheet { + path: string, + image: string, + groups: string[], + extension: string, + coordinates: { width: number, height: number, x: number, y: number }, + properties: { width: number, height: number } +} + +interface Image { + /** + * An absolute path to the stylesheet. + */ + styleFilePath: string, + + /** + * An absolute path to the image. + */ + path: string, + + /** + * The url found in your stylesheet including the query params. + */ + originalUrl: string, + + /** + * A normalized version of the original url. + */ + url: string, + + /** + * The retina ratio of your image. + */ + ratio: number, + + /** + * Indicates whenever your image is retina. + */ + retina: boolean, + + /** + * The groups associated with the image. + */ + groups: string[], + + /** + * The string used as reference in your stylesheet. + */ + token: string, + + /** + * The position & dimensions of image in generated spritesheet. + */ + coords: { width: number, height: number, x: number, y: number }, + + /** + * A relative path to the generated spritesheet. + */ + spritePath: string, + + /** + * A CSS url to the generated spritesheet. + */ + spriteUrl: string, + + /** + * The total width of the spritesheet. + */ + spriteWidth: number, + + /** + * The total height of the spritesheet. + */ + spriteHeight: number +} + +interface Hooks { + /** + * Hook that allows to rewrite the data of produced spritesheet. + */ + onSaveSpritesheet?: (options: Options, spritesheet: Spritesheet) => string|object|Promise, + + /** + * Hook that allows to rewrite the CSS output for an image. + */ + onUpdateRule?: (rule: AnyNode, token: Comment, image: Image) => void +} + +interface Spritesmith { + + /** + * The [engine](https://github.com/Ensighten/spritesmith#engines). + */ + engine?: string, + + /** + * The [algorithm](https://github.com/Ensighten/spritesmith#algorithms). + */ + algorithm?: 'top-down' | 'left-right' | 'diagonal' | 'alt-diagonal' | 'binary-tree', + + /** + * The space between images in spritesheet. + */ + padding?: number, + + /** + * The configuration of the [engine](https://github.com/Ensighten/spritesmith#engines). + */ + engineOpts?: object, + + /** + * The export options of the [engine](https://github.com/Ensighten/spritesmith#engines). + */ + exportOpts?: object, +} + +interface Options { + /** + * Relative path to the folder that will keep your output stylesheet(s). If it's null the path of CSS file will be used. + */ + stylesheetPath?: string, + + /** + * Relative path to the folder that will keep your output spritesheet(s). + */ + spritePath: string, + + /** + * Your base path that will be used for images with absolute CSS urls. + */ + basePath?: string, + + /** + * Indicates whether the url should be relative against current CSS context or original CSS stylesheet file. + */ + relativeTo?: string, + + /** + * Defines filter functions that will manipulate the list of images founded in your stylesheet(s). + */ + filterBy?: (image: Image) => Promise, + + /** + * Defines group functions that will manipulate the list of images founded in your stylesheet(s). + */ + groupBy?: (image: Image) => Promise, + + /** + * Defines whether or not to search for retina mark in the filename. + */ + retina?: boolean, + + /** + * Process hooks. + */ + hooks?: Hooks, + + /** + * A [spritesmith](https://github.com/Ensighten/spritesmith) configuration. + */ + spritesmith?: Spritesmith, + + /** + * A [svg-sprite](https://github.com/jkphl/svg-sprite#configuration-basics) configuration. + */ + svgsprite?: object, + + /** + * Prints the plugin output to the console. + */ + verbose?: boolean + +} + +declare function sprites(options: Options): Plugin; + +export = sprites; From 64e610313d86ea9c9e4ac357812d6c2fb70f8568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Wed, 17 Nov 2021 08:25:05 +0100 Subject: [PATCH 17/20] Add release script --- package.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index fd879fc..38c7932 100644 --- a/package.json +++ b/package.json @@ -17,11 +17,12 @@ "test": "ava test/*.js --verbose --serial", "build": "babel src/ --out-dir lib/", "watch": "babel --watch src/ --out-dir lib/", - "prepublishOnly": "npm run build && npm test", - "pretest": "npm run build" + "prepublishOnly": "npm run build", + "pretest": "npm run build", + "release": "np" }, "repository": "niksy/postcss-sprites", - "author": "niksy", + "author": "2createStudio", "license": "MIT", "bugs": "https://github.com/niksy/postcss-sprites/issues", "homepage": "https://github.com/niksy/postcss-sprites#readme", @@ -30,6 +31,7 @@ "@babel/cli": "^7.16.0", "@babel/preset-env": "^7.16.0", "ava": "^3.15.0", + "np": "^6.5.0", "postcss": "^8.1.2" }, "dependencies": { From 9313925269bdc0d30ecee0125dd56fc3f7ced4a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Wed, 17 Nov 2021 08:26:08 +0100 Subject: [PATCH 18/20] Scope package --- README.md | 2 +- examples/filter-by.md | 2 +- examples/group-by.md | 2 +- examples/output-dimensions.md | 2 +- examples/relative-to-rule.md | 2 +- examples/responsive-spritesheets.md | 2 +- examples/skip-prefix.md | 2 +- examples/webpack-hot-load.md | 2 +- package.json | 5 ++++- 9 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a5773e6..ac23acf 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ ```javascript var fs = require('fs'); var postcss = require('postcss'); -var { default: sprites } = require('postcss-sprites'); +var { default: sprites } = require('@niksy/postcss-sprites'); var css = fs.readFileSync('./css/style.css', 'utf8'); var opts = { diff --git a/examples/filter-by.md b/examples/filter-by.md index 5f58e7a..7b6328c 100644 --- a/examples/filter-by.md +++ b/examples/filter-by.md @@ -10,7 +10,7 @@ ```javascript var postcss = require('postcss'); -var sprites = require('postcss-sprites'); +var sprites = require('@niksy/postcss-sprites'); var opts = { stylesheetPath: './css', spritePath: './css/images/', diff --git a/examples/group-by.md b/examples/group-by.md index 64563e6..0cf6e6b 100644 --- a/examples/group-by.md +++ b/examples/group-by.md @@ -12,7 +12,7 @@ ```javascript var postcss = require('postcss'); -var sprites = require('postcss-sprites'); +var sprites = require('@niksy/postcss-sprites'); var opts = { stylesheetPath: './css', spritePath: './css/images/', diff --git a/examples/output-dimensions.md b/examples/output-dimensions.md index 2935eda..3c9eb2d 100644 --- a/examples/output-dimensions.md +++ b/examples/output-dimensions.md @@ -10,7 +10,7 @@ ```javascript var postcss = require('postcss'); -var sprites = require('postcss-sprites'); +var sprites = require('@niksy/postcss-sprites'); var updateRule = require('postcss-sprites/lib/core').updateRule; var opts = { stylesheetPath: './css', diff --git a/examples/relative-to-rule.md b/examples/relative-to-rule.md index 114ccdb..df73e4b 100644 --- a/examples/relative-to-rule.md +++ b/examples/relative-to-rule.md @@ -16,7 +16,7 @@ ```javascript var postcss = require('postcss'); -var sprites = require('postcss-sprites'); +var sprites = require('@niksy/postcss-sprites'); var opts = { stylesheetPath: './css', spritePath: './css/images/', diff --git a/examples/responsive-spritesheets.md b/examples/responsive-spritesheets.md index ca5617f..06531ef 100644 --- a/examples/responsive-spritesheets.md +++ b/examples/responsive-spritesheets.md @@ -10,7 +10,7 @@ ```javascript var postcss = require('postcss'); -var sprites = require('postcss-sprites'); +var sprites = require('@niksy/postcss-sprites'); var opts = { stylesheetPath: './css', spritePath: './css/images/', diff --git a/examples/skip-prefix.md b/examples/skip-prefix.md index 3428ec2..fb6ff3f 100644 --- a/examples/skip-prefix.md +++ b/examples/skip-prefix.md @@ -13,7 +13,7 @@ There [used to be a `skipPrefix` plugin option](https://github.com/2createStudio ```js var path = require('path'); var postcss = require('postcss'); -var sprites = require('postcss-sprites'); +var sprites = require('@niksy/postcss-sprites'); var opts = { stylesheetPath: './css', spritePath: './css/images/', diff --git a/examples/webpack-hot-load.md b/examples/webpack-hot-load.md index 5dc72e6..e540788 100644 --- a/examples/webpack-hot-load.md +++ b/examples/webpack-hot-load.md @@ -10,7 +10,7 @@ If you want to hot load image assets as they are introduced or edited, you can c ```js var path = require('path'); var postcss = require('postcss'); -var sprites = require('postcss-sprites'); +var sprites = require('@niksy/postcss-sprites'); var revHash = require('rev-hash'); module.exports = function loadPostcssPlugins() { diff --git a/package.json b/package.json index 38c7932..93b5b84 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "postcss-sprites", + "name": "@niksy/postcss-sprites", "version": "4.2.1", "description": "Generate spritesheets from stylesheets", "main": "lib/index.js", @@ -54,5 +54,8 @@ }, "ava": { "babel": true + }, + "publishConfig": { + "access": "public" } } From 5bce337037b83b438ecf28fd6e1377bdecf4e380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Wed, 17 Nov 2021 08:31:33 +0100 Subject: [PATCH 19/20] 5.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 93b5b84..e72c01d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@niksy/postcss-sprites", - "version": "4.2.1", + "version": "5.0.0", "description": "Generate spritesheets from stylesheets", "main": "lib/index.js", "keywords": [ From 567eeb2e17f323d54e1a0f1d3b9230933e3a4984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Wed, 17 Nov 2021 08:34:59 +0100 Subject: [PATCH 20/20] Update badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ac23acf..9f44233 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# postcss-sprites [![Build Status](https://github.com/niksy/postcss-sprites/workflows/CI/badge.svg?branch=postcss-8-support)](https://github.com/niksy/postcss-sprites/actions?query=workflow%3ACI) [![npm version](https://badge.fury.io/js/postcss-sprites.svg)](https://badge.fury.io/js/postcss-sprites) +# postcss-sprites [![Build Status](https://github.com/niksy/postcss-sprites/workflows/CI/badge.svg?branch=postcss-8-support)](https://github.com/niksy/postcss-sprites/actions?query=workflow%3ACI) [![npm version](https://badge.fury.io/js/@niksy%2Fpostcss-sprites.svg)](https://badge.fury.io/js/@niksy%2Fpostcss-sprites) > [PostCSS](https://github.com/postcss/postcss) plugin that generates spritesheets from your stylesheets.