postcss-import-ext-glob
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -6,2 +6,6 @@ # Change Log | ||
## 2.0.0 - 2021-01-02 | ||
### Breaking | ||
- Upgrade to PostCSS v8. | ||
## 1.1.0 - 2018-08-15 | ||
@@ -8,0 +12,0 @@ ### Added |
104
index.js
@@ -1,2 +0,1 @@ | ||
const postcss = require('postcss'); | ||
const valueParser = require('postcss-value-parser'); | ||
@@ -11,58 +10,69 @@ | ||
module.exports = postcss.plugin('postcss-import-ext-glob', (opts = {}) => { | ||
const sorter = SORTERS.indexOf(opts.sort) > -1 | ||
? opts.sort | ||
: DEFAULT_SORTER; | ||
module.exports = (opts = {}) => { | ||
const sorter = SORTERS.indexOf(opts.sort) !== -1 ? opts.sort : DEFAULT_SORTER; | ||
return (root, result) => { | ||
const promisesList = []; | ||
return { | ||
postcssPlugin: 'postcss-import-ext-glob', | ||
Once(root, { AtRule, result }) { | ||
const promisesList = []; | ||
root.walkAtRules('import-glob', rule => { | ||
promisesList.push(new Promise(resolve => { | ||
const globList = []; | ||
const params = valueParser(rule.params).nodes; | ||
root.walkAtRules('import-glob', (rule) => { | ||
promisesList.push( | ||
new Promise((resolve) => { | ||
const globList = []; | ||
const dirname = typeof rule.source.input.file === 'string' | ||
? path.dirname(rule.source.input.file) | ||
: __dirname; | ||
const params = valueParser(rule.params).nodes; | ||
for (const param of params) { | ||
if (param.type === 'string') { | ||
globList.push(path.join(dirname, param.value)); | ||
} | ||
} | ||
const dirName = | ||
typeof rule.source.input.file === 'string' | ||
? path.dirname(rule.source.input.file) | ||
: __dirname; | ||
if (globList.length) { | ||
fg(globList) | ||
.then(entries => { | ||
if (!entries.length) { | ||
result.warn( | ||
`No file found for @import-glob ${rule.params}`, | ||
{ node: rule } | ||
); | ||
for (const param of params) { | ||
if (param.type === 'string') { | ||
globList.push(path.join(dirName, param.value)); | ||
} | ||
} | ||
const sortedEntries = sort(entries)[sorter](); | ||
if (globList.length) { | ||
fg(globList).then((entries) => { | ||
if (!entries.length) { | ||
result.warn(`No file found for @import-glob ${rule.params}`, { | ||
node: rule, | ||
}); | ||
} | ||
for (const entry of sortedEntries) { | ||
root.insertBefore(rule, { | ||
name: 'import', | ||
params: `"${entry}"`, | ||
source: rule.source | ||
const sortedEntries = sort(entries)[sorter](); | ||
sortedEntries.forEach((entry) => { | ||
rule.before( | ||
new AtRule({ | ||
name: 'import', | ||
params: `"${entry}"`, | ||
source: rule.source, | ||
}) | ||
); | ||
}); | ||
} | ||
rule.remove(); | ||
resolve(); | ||
}); | ||
} else { | ||
throw rule.error( | ||
`No string found with rule @import-glob ${rule.params}`, | ||
{ plugin: 'postcss-import-ext-glob' } | ||
); | ||
} | ||
})); | ||
}); | ||
return Promise.all(promisesList); | ||
rule.remove(); | ||
resolve(); | ||
}); | ||
} else { | ||
throw rule.error( | ||
`No string found with rule @import-glob ${rule.params}`, | ||
{ | ||
word: rule.params, | ||
} | ||
); | ||
} | ||
}) | ||
); | ||
}); | ||
return Promise.all(promisesList); | ||
}, | ||
}; | ||
}); | ||
}; | ||
module.exports.postcss = true; |
{ | ||
"name": "postcss-import-ext-glob", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "A PostCSS plugin to extend postcss-import path resolver to allow glob usage as path", | ||
@@ -11,6 +11,3 @@ "license": "MIT", | ||
}, | ||
"author": { | ||
"name": "Dimitri NICOLAS", | ||
"email": "dimitri@fivecorp.fr" | ||
}, | ||
"author": "Dimitri NICOLAS <dimitri@ooeo.fr>", | ||
"keywords": [ | ||
@@ -32,7 +29,9 @@ "front-end", | ||
"dependencies": { | ||
"fast-glob": "^2.2.2", | ||
"fast-sort": "^1.5.3", | ||
"postcss": "^7.0.2", | ||
"postcss-value-parser": "^3.3.0" | ||
"fast-glob": "^3.2.4", | ||
"fast-sort": "^2.2.0", | ||
"postcss-value-parser": "^4.1.0" | ||
}, | ||
"peerDependencies": { | ||
"postcss": "^8.2.0" | ||
} | ||
} |
# postcss-import-ext-glob [![Build Status][travis badge]][travis link] [![Coverage Status][coveralls badge]][coveralls link] | ||
A [PostCSS][postcss] plugin to extend [postcss-import][postcss-import] path | ||
A [PostCSS][postcss] v8 plugin to extend [postcss-import][postcss-import] path | ||
resolver to allow [glob][glob ref] usage as a path. | ||
You must use this plugin along with [postcss-import][postcss-import], place | ||
You must use this plugin along with [postcss-import][postcss-import], place | ||
this plugin **before** `postcss-import`. | ||
@@ -16,3 +16,3 @@ | ||
```console | ||
$ npm install postcss-import-ext-glob | ||
$ npm install --save-dev postcss postcss-import postcss-import-ext-glob | ||
``` | ||
@@ -23,3 +23,3 @@ | ||
```js | ||
// Postcss plugins | ||
// PostCSS plugins | ||
postcss([ | ||
@@ -31,3 +31,3 @@ require('postcss-import-ext-glob'), | ||
Check out [PostCSS](https://github.com/postcss/postcss) docs for the complete | ||
Check out [PostCSS](https://github.com/postcss/postcss) docs for the complete | ||
installation. | ||
@@ -77,3 +77,3 @@ | ||
- [postcss-import][postcss-import] - PostCSS plugin to inline @import rules | ||
- [postcss-import][postcss-import] - PostCSS plugin to inline @import rules | ||
content | ||
@@ -80,0 +80,0 @@ - [fast-glob][fast-glob] - Module used for getting glob entries |
135
test.js
@@ -1,30 +0,78 @@ | ||
import test from 'ava'; | ||
import PostcssTester from 'ava-postcss-tester'; | ||
const test = require('ava'); | ||
const PostcssTester = require('ava-postcss-tester'); | ||
import postcss from 'postcss'; | ||
import postcssImport from 'postcss-import'; | ||
const postcss = require('postcss'); | ||
const postcssImport = require('postcss-import'); | ||
import postcssImportExtGlob from '.'; | ||
const postcssImportExtGlob = require('.'); | ||
const tester = new PostcssTester({ | ||
postcss, | ||
plugin: postcssImportExtGlob | ||
plugin: postcssImportExtGlob, | ||
}); | ||
test('simple test', async t => { | ||
const input = /* scss */` | ||
test('no @import-blog', async (t) => { | ||
const input = ` | ||
@import "fixtures/css/foo/**/*.css"; | ||
`; | ||
const output = ` | ||
@import "fixtures/css/foo/**/*.css"; | ||
`; | ||
await tester.test(input, output, t); | ||
}); | ||
test('postcss-import test', async (t) => { | ||
const input = ` | ||
@import "/Users/dimitrinicolas/Developer/postcss-import-ext-glob/fixtures/css/style.css"; | ||
`; | ||
const output = ` | ||
div { | ||
margin: auto; | ||
} | ||
`; | ||
await tester.test(input, output, t, { | ||
pluginsAfter: [postcssImport], | ||
}); | ||
}); | ||
test('simple test', async (t) => { | ||
const input = ` | ||
@import-glob "fixtures/css/foo/**/*.css"; | ||
`; | ||
const output = /* scss */` | ||
const output = ` | ||
@import "${__dirname}/fixtures/css/foo/bar.css"; | ||
@import "${__dirname}/fixtures/css/foo/foo.css"; | ||
`; | ||
await tester.test(input, output, t); | ||
}); | ||
test('simple test postcss-import', async t => { | ||
const input = /* scss */` | ||
test('only changing @import-glob at rules', async (t) => { | ||
const input = ` | ||
@import "fixtures/css/foo/**/*.css"; | ||
@import-glob "fixtures/css/foo/**/*.css"; | ||
@media (max-width: 600px) { .foo { color: red; } } | ||
`; | ||
const output = /* scss */` | ||
const output = ` | ||
@import "fixtures/css/foo/**/*.css"; | ||
@import "${__dirname}/fixtures/css/foo/bar.css"; | ||
@import "${__dirname}/fixtures/css/foo/foo.css"; | ||
@media (max-width: 600px) { .foo { color: red; } } | ||
`; | ||
await tester.test(input, output, t); | ||
}); | ||
test('simple test postcss-import', async (t) => { | ||
const input = ` | ||
@import-glob "fixtures/css/foo/**/*.css"; | ||
`; | ||
const output = ` | ||
.bar { | ||
@@ -37,12 +85,14 @@ display: inline-block; | ||
`; | ||
await tester.test(input, output, t, { | ||
pluginsAfter: [postcssImport] | ||
pluginsAfter: [postcssImport], | ||
}); | ||
}); | ||
test('sort option', async t => { | ||
const input = /* scss */` | ||
test('sort option', async (t) => { | ||
const input = ` | ||
@import-glob "fixtures/css/foo/**/*.css"; | ||
`; | ||
const output = /* scss */` | ||
const output = ` | ||
.foo { | ||
@@ -55,16 +105,18 @@ display: block; | ||
`; | ||
await tester.test(input, output, t, { | ||
pluginOptions: { | ||
sort: 'desc' | ||
sort: 'desc', | ||
}, | ||
pluginsAfter: [postcssImport] | ||
pluginsAfter: [postcssImport], | ||
}); | ||
}); | ||
test('multiple globs', async t => { | ||
const input = /* scss */` | ||
test('multiple globs', async (t) => { | ||
const input = ` | ||
@import-glob "fixtures/css/foo/**/*.css"; | ||
@import-glob "fixtures/css/*.css"; | ||
`; | ||
const output = /* scss */` | ||
const output = ` | ||
.bar { | ||
@@ -80,12 +132,14 @@ display: inline-block; | ||
`; | ||
await tester.test(input, output, t, { | ||
pluginsAfter: [postcssImport] | ||
pluginsAfter: [postcssImport], | ||
}); | ||
}); | ||
test('multiple globs inline', async t => { | ||
const input = /* scss */` | ||
test('multiple globs inline', async (t) => { | ||
const input = ` | ||
@import-glob "fixtures/css/foo/**/*.css", "fixtures/css/*.css"; | ||
`; | ||
const output = /* scss */` | ||
const output = ` | ||
.bar { | ||
@@ -101,30 +155,37 @@ display: inline-block; | ||
`; | ||
await tester.test(input, output, t, { | ||
pluginsAfter: [postcssImport] | ||
pluginsAfter: [postcssImport], | ||
}); | ||
}); | ||
test('error empty param test', async t => { | ||
const input = /* scss */` | ||
test('error empty param test', async (t) => { | ||
const input = ` | ||
@import-glob; | ||
`; | ||
await tester.test(input, err => { | ||
t.true(/No string found with rule @import-glob/.test(err)); | ||
}, t, { | ||
pluginsAfter: [postcssImport] | ||
}); | ||
await tester.test( | ||
input, | ||
(err) => { | ||
t.true(/No string found with rule @import-glob/.test(err)); | ||
}, | ||
t, | ||
{ | ||
pluginsAfter: [postcssImport], | ||
} | ||
); | ||
}); | ||
test('no entries warning', async t => { | ||
test('no entries warning', async (t) => { | ||
const warningsTester = new PostcssTester({ | ||
postcss, | ||
plugin: postcssImportExtGlob, | ||
tolerateWarnings: true | ||
tolerateWarnings: true, | ||
}); | ||
const input = /* scss */` | ||
const input = ` | ||
@import-glob "fixtures/css/_unknow/**/*.css"; | ||
`; | ||
await warningsTester.test(input, '', t, { | ||
pluginsAfter: [postcssImport] | ||
pluginsAfter: [postcssImport], | ||
}); | ||
}); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10541
219
0
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedfast-glob@3.3.3(transitive)
+ Addedfast-sort@2.2.0(transitive)
+ Addedfastq@1.19.1(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addednanoid@3.3.8(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedpostcss@8.5.3(transitive)
+ Addedpostcss-value-parser@4.2.0(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedreusify@1.1.0(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedsource-map-js@1.2.1(transitive)
+ Addedto-regex-range@5.0.1(transitive)
- Removedpostcss@^7.0.2
- Removed@mrmlnc/readdir-enhanced@2.2.1(transitive)
- Removed@nodelib/fs.stat@1.1.3(transitive)
- Removedarr-diff@4.0.0(transitive)
- Removedarr-flatten@1.1.0(transitive)
- Removedarr-union@3.1.0(transitive)
- Removedarray-unique@0.3.2(transitive)
- Removedassign-symbols@1.0.0(transitive)
- Removedatob@2.1.2(transitive)
- Removedbase@0.11.2(transitive)
- Removedbraces@2.3.2(transitive)
- Removedcache-base@1.0.1(transitive)
- Removedcall-me-maybe@1.0.2(transitive)
- Removedclass-utils@0.3.6(transitive)
- Removedcollection-visit@1.0.0(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedcopy-descriptor@0.1.1(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removeddefine-property@0.2.51.0.02.0.2(transitive)
- Removedexpand-brackets@2.1.4(transitive)
- Removedextend-shallow@2.0.13.0.2(transitive)
- Removedextglob@2.0.4(transitive)
- Removedfast-glob@2.2.7(transitive)
- Removedfast-sort@1.6.0(transitive)
- Removedfill-range@4.0.0(transitive)
- Removedfor-in@1.0.2(transitive)
- Removedfragment-cache@0.2.1(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-value@2.0.6(transitive)
- Removedglob-parent@3.1.0(transitive)
- Removedglob-to-regexp@0.3.0(transitive)
- Removedhas-value@0.3.11.0.0(transitive)
- Removedhas-values@0.1.41.0.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedis-accessor-descriptor@1.0.1(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-data-descriptor@1.0.1(transitive)
- Removedis-descriptor@0.1.71.0.3(transitive)
- Removedis-extendable@0.1.11.0.1(transitive)
- Removedis-glob@3.1.0(transitive)
- Removedis-number@3.0.0(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedisarray@1.0.0(transitive)
- Removedisobject@2.1.03.0.1(transitive)
- Removedkind-of@3.2.24.0.06.0.3(transitive)
- Removedmap-cache@0.2.2(transitive)
- Removedmap-visit@1.0.0(transitive)
- Removedmicromatch@3.1.10(transitive)
- Removedmixin-deep@1.3.2(transitive)
- Removedms@2.0.0(transitive)
- Removednanomatch@1.2.13(transitive)
- Removedobject-copy@0.1.0(transitive)
- Removedobject-visit@1.0.1(transitive)
- Removedobject.pick@1.3.0(transitive)
- Removedpascalcase@0.1.1(transitive)
- Removedpath-dirname@1.0.2(transitive)
- Removedpicocolors@0.2.1(transitive)
- Removedposix-character-classes@0.1.1(transitive)
- Removedpostcss@7.0.39(transitive)
- Removedpostcss-value-parser@3.3.1(transitive)
- Removedregex-not@1.0.2(transitive)
- Removedrepeat-element@1.1.4(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedresolve-url@0.2.1(transitive)
- Removedret@0.1.15(transitive)
- Removedsafe-regex@1.1.0(transitive)
- Removedset-value@2.0.1(transitive)
- Removedsnapdragon@0.8.2(transitive)
- Removedsnapdragon-node@2.1.1(transitive)
- Removedsnapdragon-util@3.0.1(transitive)
- Removedsource-map@0.5.70.6.1(transitive)
- Removedsource-map-resolve@0.5.3(transitive)
- Removedsource-map-url@0.4.1(transitive)
- Removedsplit-string@3.1.0(transitive)
- Removedstatic-extend@0.1.2(transitive)
- Removedto-object-path@0.3.0(transitive)
- Removedto-regex@3.0.2(transitive)
- Removedto-regex-range@2.1.1(transitive)
- Removedunion-value@1.0.1(transitive)
- Removedunset-value@1.0.0(transitive)
- Removedurix@0.1.0(transitive)
- Removeduse@3.1.1(transitive)
Updatedfast-glob@^3.2.4
Updatedfast-sort@^2.2.0
Updatedpostcss-value-parser@^4.1.0