Skip to content

Commit

Permalink
significantly reduce package size & bump version
Browse files Browse the repository at this point in the history
I've removed fs-extra (almost everything can be done with built-in fs) and replaced chalk with kleur
  • Loading branch information
SassNinja committed Dec 19, 2019
1 parent 851c1eb commit 15c8009
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 98 deletions.
22 changes: 13 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

const _ = require('lodash');
const fs = require('fs-extra');
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const { green, yellow } = require('kleur');
const postcss = require('postcss');
const rootPath = require('app-root-path').path

Expand Down Expand Up @@ -54,18 +54,16 @@ module.exports = postcss.plugin('postcss-extract-media-query', opts => {
// Deprecation warnings
// TODO: remove in future
if (typeof opts.whitelist === 'boolean') {
console.log(chalk.yellow('[WARNING] whitelist option is deprecated – please use extractAll'));
console.log(yellow('[WARNING] whitelist option is deprecated – please use extractAll'));
if (opts.whitelist === true) {
opts.extractAll = false;
}
}
if (opts.combine) {
console.log(chalk.yellow('[WARNING] combine option is deprecated – please use another plugin for this'));
console.log(chalk.yellow('\trecommended: https://github.com/SassNinja/postcss-combine-media-query'));
console.log(yellow('[WARNING] combine option is deprecated – please use another plugin for this'));
}
if (opts.minimize) {
console.log(chalk.yellow('[WARNING] minimize option is deprecated – please use another plugin for this'));
console.log(chalk.yellow('\trecommended: https://github.com/cssnano/cssnano'));
console.log(yellow('[WARNING] minimize option is deprecated – please use another plugin for this'));
}

const media = {};
Expand Down Expand Up @@ -130,15 +128,21 @@ module.exports = postcss.plugin('postcss-extract-media-query', opts => {
.replace(/\[ext\]/g, ext)

const newFilePath = path.join(opts.output.path, newFile);
const newFileDir = path.dirname(newFilePath);

if (opts.output.path) {

applySubsequentPlugins(css, newFilePath).then(css => {

fs.outputFileSync(newFilePath, css);
if (!fs.existsSync(path.dirname(newFilePath))) {
// make sure we can write
fs.mkdirSync(newFileDir, { recursive: true });
}

fs.writeFileSync(newFilePath, css);

if (opts.stats === true) {
console.log(chalk.green('[extracted media query]'), newFile);
console.log(green('[extracted media query]'), newFile);
}
resolve();
});
Expand Down
144 changes: 63 additions & 81 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-extract-media-query",
"version": "1.3.0",
"version": "2.0.0",
"description": "PostCSS plugin to extract all media query from CSS and emit as separate files.",
"author": "Kai Falkowski",
"license": "MIT",
Expand All @@ -21,15 +21,14 @@
],
"dependencies": {
"app-root-path": "^3.0.0",
"chalk": "^2.4.1",
"csswring": "^6.0.3",
"fs-extra": "^6.0.1",
"kleur": "^3.0.3",
"lodash": "^4.17.10",
"postcss": "^6.0.22"
},
"devDependencies": {
"chai": "^4.1.2",
"mocha": "^5.2.0"
"mocha": "^5.2.0",
"rimraf": "^3.0.0"
},
"repository": {
"type": "git",
Expand Down
7 changes: 4 additions & 3 deletions test/options.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

const assert = require('chai').assert;
const fs = require('fs-extra');
const fs = require('fs');
const path = require('path');
const rimraf = require('rimraf');
const postcss = require('postcss');
const plugin = require('../index.js');

Expand All @@ -10,8 +11,8 @@ const entryExampleFile = fs.readFileSync('test/data/entry-example.css', 'utf-8')

describe('Options', function() {

before(function() {
fs.removeSync('test/output');
before((done) => {
rimraf('test/output', done);
});

describe('extractAll', function() {
Expand Down

0 comments on commit 15c8009

Please sign in to comment.