diff --git a/.gitignore b/.gitignore index 5c49d4c..f6d83d4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ coverage/ tmp/ npm-debug.log* .DS_Store +.nyc_output/ diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml index eb5b6c6..d3e8bac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,18 @@ -node_js: - - stable - - 9 - - 6 - - 4 -sudo: false +os: linux +dist: bionic language: node_js +node_js: + - 12 + - 10 + - 8 script: "npm run test:cov" -after_script: "npm i -g codecov.io && cat ./coverage/lcov.info | codecov" + +jobs: + include: + - node_js: stable + after_script: | + npm i -g codecov + npx nyc report --reporter=text-lcov | codecov --pipe + # Node.js 6 is not supported by nyc, so run tests without code coverage + - node_js: 6 + script: npm run test diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..50f9803 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,21 @@ +# css-extract change log + +All notable changes to this project will be documented in this file. + +This project adheres to [Semantic Versioning](http://semver.org/). + +## 2.0.0 +* Update dependencies. ([@goto-bus-stop][] in [#16][]) +* Add test for `insertCss(someDynamicValue)`. ([@ahdinosaur][] in [#12][]) + +[@goto-bus-stop]: https://github.com/goto-bus-stop +[@ahdinosaur]: https://github.com/ahdinosaur +[#12]: https://github.com/stackcss/css-extract/pull/12 +[#16]: https://github.com/stackcss/css-extract/pull/16 + +## 1.3.1 +* Update static-module. ([@s3ththompson][] in [#15][]) +* Update stability badge to stable. + +[@s3ththompson]: https://github.com/s3ththompson +[#15]: https://github.com/stackcss/css-extract/pull/15 diff --git a/README.md b/README.md index cc5119d..4e3f3ae 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ $ npm install css-extract ## License [MIT](https://tldrlegal.com/license/mit-license) -[0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square +[0]: https://img.shields.io/badge/stability-stable-green.svg?style=flat-square [1]: https://nodejs.org/api/documentation.html#documentation_stability_index [2]: https://img.shields.io/npm/v/css-extract.svg?style=flat-square [3]: https://npmjs.org/package/css-extract diff --git a/index.js b/index.js index 289f646..473099b 100644 --- a/index.js +++ b/index.js @@ -16,8 +16,8 @@ function cssExtract (bundle, opts) { var outFile = opts.out || opts.o || 'bundle.css' var sourceMap = d(opts.sourceMap, bundle && bundle._options && bundle._options.debug, false) - assert.equal(typeof bundle, 'object', 'bundle should be an object') - assert.equal(typeof opts, 'object', 'opts should be an object') + assert.strictEqual(typeof bundle, 'object', 'bundle should be an object') + assert.strictEqual(typeof opts, 'object', 'opts should be an object') // every time .bundle is called, attach hook bundle.on('reset', addHooks) diff --git a/package.json b/package.json index 71dd1ac..9eddcde 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "css-extract", - "version": "1.3.0", + "version": "2.0.0", "description": "Extract CSS from a browserify bundle", "main": "index.js", "scripts": { "deps": "dependency-check . && dependency-check . --extra --no-dev", "test": "standard && npm run deps && NODE_ENV=test node test", - "test:cov": "standard && npm run deps && NODE_ENV=test istanbul cover ./test/index.js" + "test:cov": "standard && npm run deps && NODE_ENV=test nyc node test" }, "repository": "stackcss/css-extract", "keywords": [ @@ -20,21 +20,21 @@ ], "license": "MIT", "dependencies": { - "bl": "^1.1.2", + "bl": "^4.0.2", "defined": "^1.0.0", "from2-string": "^1.1.0", - "static-module": "^2.2.0", - "through2": "^2.0.1" + "static-module": "^3.0.0", + "through2": "^4.0.2" }, "devDependencies": { - "browserify": "^13.0.0", - "dependency-check": "^2.5.1", + "browserify": "^16.5.2", + "dependency-check": "^2.10.1", "insert-css": "^2.0.0", - "istanbul": "^0.4.2", - "sheetify": "^6.0.0", - "standard": "^6.0.7", - "tape": "^4.5.0", - "tmp": "0.0.28" + "nyc": "^15.1.0", + "sheetify": "^8.0.0", + "standard": "^14.3.4", + "tape": "^5.0.1", + "tmp": "^0.2.1" }, "files": [ "index.js", diff --git a/test/index.js b/test/index.js index 1afa789..2a93fb4 100644 --- a/test/index.js +++ b/test/index.js @@ -33,7 +33,7 @@ test('css-extract', function (t) { t.test('should extract sheetify css to file', function (t) { t.plan(3) - tmpDir({unsafeCleanup: true}, onDir) + tmpDir({ unsafeCleanup: true }, onDir) function onDir (err, dir, cleanup) { t.ifError(err, 'no error') @@ -108,4 +108,26 @@ test('css-extract', function (t) { t.ok(String(data).indexOf(String(source)) !== -1, 'source is still in built bundle') } }) + + t.test('should not extract dynamic insert-css statements, again', function (t) { + t.plan(4) + const sourcePath = path.join(__dirname, 'source-dynamic-2.js') + + browserify(sourcePath) + .plugin(cssExtract, { out: readCss }) + .bundle(readJs) + + function readCss () { + return bl(function (err, data) { + t.ifError(err, 'no error') + t.equal(String(data), '', 'no css extracted') + }) + } + + function readJs (err, data) { + t.ifError(err, 'no error') + const source = fs.readFileSync(sourcePath, 'utf8') + t.ok(String(data).indexOf(String(source)) !== -1, 'source is still in built bundle') + } + }) }) diff --git a/test/source-dynamic-2.js b/test/source-dynamic-2.js new file mode 100644 index 0000000..fd696d4 --- /dev/null +++ b/test/source-dynamic-2.js @@ -0,0 +1,7 @@ +var insertCss = require('insert-css') + +insert('.foo {}') + +function insert (foo) { + insertCss(foo) +}