Skip to content

Commit

Permalink
3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathantneal committed Dec 20, 2016
1 parent 5775e91 commit f21afdb
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 23 deletions.
22 changes: 20 additions & 2 deletions .tape.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
message: /^Failed to find 'import1.css'/
}
},
'02-touch/test:enabled': {
'02-touch/test:true': {
message: 'supports { touch: true } with missing import usage',
options: {
touch: true
Expand All @@ -23,7 +23,19 @@ module.exports = {
)
},
'03-glob/test': {
message: 'supports { glob: true } usage'
message: 'supports { glob: true } usage',
options: {
glob: true
}
},
'03-glob/test:false': {
message: 'supports { glob: false } usage',
options: {
glob: false
},
error: {
message: /^Failed to find 'dir1\/\*\.css'/
}
},
'04-resolve/test': {
message: 'supports { resolve: customFn } usage',
Expand All @@ -34,6 +46,12 @@ module.exports = {
// Otherwise, use the regular resolve
resolve(id, base, options)
}
},
'05-pcss/test': {
message: 'supports { extension: ".pcss" } usage',
options: {
extension: '.pcss'
}
}
}
};
Expand Down
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
### 3.1.0 (December 20, 2016)

- Added: Tests for glob, extension
- Changed: Default `prefix` is now empty (`""`)
- Removed: JSCS validation

### 3.0.1 (December 14, 2016)

- Added: lib directory to package
- Added: `lib` directory to the package

### 3.0.0 (December 14, 2016)

- Added: Plugin refactoring as an alternative version of postcss-import
- Updated: boilerplate conventions (Node v6.9.1 LTS)
- Updated: Boilerplate conventions (Node v6.9.1 LTS)

### 2.1.0 (October 18, 2016)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ Whether similar files (based on the same content) will be skipped.
#### `prefix`

Type: `String`
Default: `"_"`
Default: `""`

Leading characters conditionally prepended to imports which are not found without them.
Leading characters conditionally prepended to imports which are not found without them. For [Sass]-like, use `"_"`.

#### `glob`

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = postcss.plugin(
{
glob: true,
extension: '.css',
prefix: '_',
prefix: '',
touch: false
},
opts,
Expand Down
29 changes: 20 additions & 9 deletions lib/resolve-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,33 @@ module.exports = (id, base, options) => resolveId(id, base, options).catch(
}
).catch(
(error) => {
let altId = id;

// when the prefix option is truthy
if (options.prefix) {
// prefixed file path matcher
const prefixMatch = RegExp(`(${ escapeRegExp(path.sep) })?(${ escapeRegExp(options.prefix) })?([^${ escapeRegExp(path.sep) }]+)$`);

// prefixed file path
const prefixedId = id.replace(prefixMatch, `$1${ options.prefix }$3`);
altId = altId.replace(prefixMatch, `$1${ options.prefix }$3`);
}

// when the prefix option is truthy
if (options.extension) {
// prefixed file path matcher
const extensionMatch = RegExp(`(${ escapeRegExp(options.extension) })?$`);

if (prefixedId !== id) {
// resolve prefixed file path
return resolveId(prefixedId, base, options).catch(
() => {
throw error;
}
);
}
// prefixed file path
altId = altId.replace(extensionMatch, options.extension);
}

if (altId !== id) {
// resolve prefixed file path
return resolveId(altId, base, options).catch(
() => {
throw error;
}
);
}

throw error;
Expand Down
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-partial-import",
"version": "3.0.1",
"version": "3.1.0",
"description": "Inline sugary @import statements in CSS",
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
"license": "CC0-1.0",
Expand All @@ -13,7 +13,7 @@
"lib"
],
"scripts": {
"lint": "echint && eslint *.js && jscs *.js",
"lint": "echint && eslint *.js lib/*.js",
"prepublish": "npm test",
"tape": "postcss-tape",
"test": "npm run lint && postcss-tape"
Expand All @@ -30,8 +30,6 @@
"echint-config-dev": "1.0.0",
"eslint": "^3.12.1",
"eslint-config-dev": "1.0.0",
"jscs": "^3.0.7",
"jscs-config-dev": "1.0.1",
"normalize-css": "^2.3.1",
"postcss-tape": "1.3.0"
},
Expand All @@ -42,11 +40,11 @@
"extends": "dev",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-nested-ternary": [0]
}
},
"jscsConfig": {
"preset": "dev"
},
"keywords": [
"postcss",
"css",
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions test/03-glob/test.false.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "dir1/*.css"
1 change: 1 addition & 0 deletions test/03-glob/test.false.expect.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "dir1/*.css"
3 changes: 3 additions & 0 deletions test/05-pcss/dir1/dir2/import3.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a {
color: red;
}
1 change: 1 addition & 0 deletions test/05-pcss/dir1/import1.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "import2";
1 change: 1 addition & 0 deletions test/05-pcss/dir1/import2.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "dir2/import3";
1 change: 1 addition & 0 deletions test/05-pcss/test.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "dir1/import1";
3 changes: 3 additions & 0 deletions test/05-pcss/test.expect.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a {
color: red;
}

0 comments on commit f21afdb

Please sign in to comment.