Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PostCSS 6 #283

Merged
merged 4 commits into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- 'stable'
- '0.12'
- stable
- 4.5
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

environment:
matrix:
- nodejs_version: 5
- nodejs_version: 0.12
- nodejs_version: 7
- nodejs_version: 4.5

version: "{build}"
build: off
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// builtin tooling
var path = require("path")

// external tooling
var assign = require("object-assign")
var postcss = require("postcss")

// internal tooling
var joinMedia = require("./lib/join-media")
var resolveId = require("./lib/resolve-id")
var loadContent = require("./lib/load-content")
Expand Down
3 changes: 3 additions & 0 deletions lib/parse-statements.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// external tooling
var valueParser = require("postcss-value-parser")

// extended tooling
var stringify = valueParser.stringify

function split(params, start) {
Expand Down
5 changes: 5 additions & 0 deletions lib/process-content.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// builtin tooling
var path = require("path")

// external tooling
var postcss = require("postcss")

// placeholder tooling
var sugarss

module.exports = function processContent(
Expand Down
15 changes: 1 addition & 14 deletions lib/resolve-id.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
// external tooling
var resolve = require("resolve")
var jspmResolve
// Works around https://github.com/jspm/jspm-cli/pull/1779 is released
try {
jspmResolve = require("pkg-resolve")
}
catch (ex) {
// pass
}

var moduleDirectories = [
"web_modules",
Expand Down Expand Up @@ -47,12 +40,6 @@ module.exports = function(id, base, options) {
.catch(function() {
return resolveModule(id, resolveOpts)
})
.catch(function() {
return jspmResolve.default(id, {
basedir: resolveOpts.basedir,
extensions : resolveOpts.extensions,
})
})
.catch(function() {
if (paths.indexOf(base) === -1) {
paths.unshift(base)
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
],
"dependencies": {
"object-assign": "^4.0.1",
"postcss": "^5.0.14",
"postcss": "^6.0.1",
"postcss-value-parser": "^3.2.3",
"read-cache": "^1.0.0",
"resolve": "^1.1.7"
},
"devDependencies": {
"ava": "^0.16.0",
"eslint": "^1.10.3",
"eslint-config-i-am-meticulous": "^2.0.0",
"ava": "^0.19.1",
"eslint": "^3.19.0",
"eslint-config-i-am-meticulous": "^6.0.1",
"eslint-plugin-import": "^2.2.0",
"npmpub": "^3.0.1",
"postcss-scss": "^0.1.3",
"sugarss": "^0.2.0"
"postcss-scss": "^1.0.0",
"sugarss": "^1.0.0"
},
"jspm": {
"name": "postcss-import",
Expand Down
3 changes: 3 additions & 0 deletions test/custom-load.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// external tooling
import test from "ava"

// internal tooling
import compareFixtures from "./helpers/compare-fixtures"

test.serial("should accept content", t => {
Expand Down
31 changes: 19 additions & 12 deletions test/custom-resolve.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// builtin tooling
import path from "path"

// external tooling
import test from "ava"
import compareFixtures from "./helpers/compare-fixtures"
import postcss from "postcss"

// internal tooling
import compareFixtures from "./helpers/compare-fixtures"

// plugin
import atImport from ".."
import path from "path"

test.serial("should accept file", t => {
return compareFixtures(t, "custom-resolve-file", {
resolve: () => {
return path.resolve("fixtures/imports/custom-resolve-1.css")
return path.resolve("test/fixtures/imports/custom-resolve-1.css")
},
})
})
Expand All @@ -16,7 +23,7 @@ test.serial("should accept promised file", t => {
return compareFixtures(t, "custom-resolve-file", {
resolve: () => {
return Promise.resolve(
path.resolve("fixtures/imports/custom-resolve-1.css")
path.resolve("test/fixtures/imports/custom-resolve-1.css")
)
},
})
Expand All @@ -26,9 +33,9 @@ test.serial("should accept array of files", t => {
return compareFixtures(t, "custom-resolve-array", {
resolve: () => {
return [
path.resolve("fixtures/imports/custom-resolve-1.css"),
path.resolve("fixtures/imports/custom-resolve-2.css"),
path.resolve("fixtures/imports/custom-resolve-1.css"),
path.resolve("test/fixtures/imports/custom-resolve-1.css"),
path.resolve("test/fixtures/imports/custom-resolve-2.css"),
path.resolve("test/fixtures/imports/custom-resolve-1.css"),
]
},
})
Expand All @@ -38,9 +45,9 @@ test.serial("should accept promised array of files", t => {
return compareFixtures(t, "custom-resolve-array", {
resolve: () => {
return Promise.resolve([
path.resolve("fixtures/imports/custom-resolve-1.css"),
path.resolve("fixtures/imports/custom-resolve-2.css"),
path.resolve("fixtures/imports/custom-resolve-1.css"),
path.resolve("test/fixtures/imports/custom-resolve-1.css"),
path.resolve("test/fixtures/imports/custom-resolve-2.css"),
path.resolve("test/fixtures/imports/custom-resolve-1.css"),
])
},
})
Expand All @@ -55,11 +62,11 @@ test(
return path.replace("foo", "imports/bar")
},
load: p => {
t.is(p, path.resolve("fixtures/imports", "bar.css"))
t.is(p, path.resolve("test/fixtures/imports", "bar.css"))
return "/* comment */"
},
}))
.process(`@import "foo.css";`, { from: "fixtures/custom-resolve-file" })
.process(`@import "foo.css";`, { from: "test/fixtures/custom-resolve-file" })
.then(result => {
t.is(result.css, "/* comment */")
})
Expand Down
3 changes: 3 additions & 0 deletions test/custom-syntax-parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// external tooling
import test from "ava"
import scss from "postcss-scss"
import sugarss from "sugarss"

// internal tooling
import compareFixtures from "./helpers/compare-fixtures"
import compareFixturesExt from "./helpers/compare-fixtures-ext"

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/resolve-cwd.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@import "fixtures/imports/foo.css";
@import "fixtures/imports/foo-recursive.css";
@import "test/fixtures/imports/foo.css";
@import "test/fixtures/imports/foo-recursive.css";
12 changes: 6 additions & 6 deletions test/fixtures/resolve-local-modules.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import "fixtures/imports/modules/simple";
@import "fixtures/imports/modules/empty";
@import "fixtures/imports/modules/style";
@import "fixtures/imports/modules/main";
@import "fixtures/imports/modules/main-js";
@import "fixtures/imports/modules/main-style";
@import "test/fixtures/imports/modules/simple";
@import "test/fixtures/imports/modules/empty";
@import "test/fixtures/imports/modules/style";
@import "test/fixtures/imports/modules/main";
@import "test/fixtures/imports/modules/main-js";
@import "test/fixtures/imports/modules/main-style";
13 changes: 9 additions & 4 deletions test/helpers/compare-fixtures-ext.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
// builtin tooling
var fs = require("fs")
var postcss = require("postcss")

// external tooling
var assign = require("object-assign")
var postcss = require("postcss")

// plugin
var atImport = require("../..")

function read(name, ext) {
if (!ext) ext = ".css"
return fs.readFileSync("fixtures/" + name + ext, "utf8")
return fs.readFileSync("test/fixtures/" + name + ext, "utf8")
}

module.exports = function(t, name, ext, opts, postcssOpts, warnings) {
opts = assign({ path: "fixtures/imports" }, opts)
opts = assign({ path: "test/fixtures/imports" }, opts)
return postcss(atImport(opts))
.process(read(name, ext), postcssOpts || {})
.then(function(result) {
var actual = result.css
var expected = read(name + ".expected")
// handy thing: checkout actual in the *.actual.css file
fs.writeFile("fixtures/" + name + ".actual.css", actual)
fs.writeFile("test/fixtures/" + name + ".actual.css", actual)
t.is(actual, expected)
if (!warnings) {
warnings = []
Expand Down
13 changes: 9 additions & 4 deletions test/helpers/compare-fixtures.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
// builtin tooling
var fs = require("fs")
var postcss = require("postcss")

// external tooling
var assign = require("object-assign")
var postcss = require("postcss")

// plugin
var atImport = require("../..")

function read(name) {
return fs.readFileSync("fixtures/" + name + ".css", "utf8")
return fs.readFileSync("test/fixtures/" + name + ".css", "utf8")
}

module.exports = function(t, name, opts, postcssOpts, warnings) {
opts = assign({ path: "fixtures/imports" }, opts)
opts = assign({ path: "test/fixtures/imports" }, opts)
return postcss(atImport(opts))
.process(read(name), postcssOpts || {})
.then(function(result) {
var actual = result.css
var expected = read(name + ".expected")
// handy thing: checkout actual in the *.actual.css file
fs.writeFile("fixtures/" + name + ".actual.css", actual)
fs.writeFile("test/fixtures/" + name + ".actual.css", actual)
t.is(actual, expected)
if (!warnings) {
warnings = []
Expand Down
35 changes: 20 additions & 15 deletions test/import-events.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
// builtin tooling
import { readFileSync } from "fs"
import { resolve } from "path"

// external tooling
import test from "ava"
import postcss from "postcss"

// plugin
import atImport from ".."
import { resolve } from "path"
import { readFileSync } from "fs"

test("should have a callback that returns an object" +
" containing imported files", t => {
return postcss()
.use(atImport({
path: "fixtures/imports",
path: "test/fixtures/imports",
onImport: files => {
t.deepEqual(
files,
[
resolve("fixtures/media-import.css"),
resolve("fixtures/imports/media-import-level-2.css"),
resolve("fixtures/imports/media-import-level-3.css"),
resolve("test/fixtures/media-import.css"),
resolve("test/fixtures/imports/media-import-level-2.css"),
resolve("test/fixtures/imports/media-import-level-3.css"),
]
)
},
}))
.process(readFileSync("fixtures/media-import.css"), {
from: "fixtures/media-import.css",
.process(readFileSync("test/fixtures/media-import.css"), {
from: "test/fixtures/media-import.css",
})
})

test("should add dependency message for each import", t => {
return postcss()
.use(atImport({
path: "fixtures/imports",
path: "test/fixtures/imports",
}))
.process(readFileSync("fixtures/media-import.css"), {
from: "fixtures/media-import.css",
.process(readFileSync("test/fixtures/media-import.css"), {
from: "test/fixtures/media-import.css",
})
.then((result) => {
var deps = result.messages.filter(
Expand All @@ -40,13 +45,13 @@ test("should add dependency message for each import", t => {
var expected = [
{
type: "dependency",
file: resolve("fixtures/imports/media-import-level-2.css"),
parent: resolve("fixtures/media-import.css"),
file: resolve("test/fixtures/imports/media-import-level-2.css"),
parent: resolve("test/fixtures/media-import.css"),
},
{
type: "dependency",
file: resolve("fixtures/imports/media-import-level-3.css"),
parent: resolve("fixtures/imports/media-import-level-2.css"),
file: resolve("test/fixtures/imports/media-import-level-3.css"),
parent: resolve("test/fixtures/imports/media-import-level-2.css"),
},
]
t.deepEqual(deps, expected)
Expand Down
Loading