New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

postcss-import-ext-glob

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-import-ext-glob - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

4

CHANGELOG.md

@@ -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

@@ -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],
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc