Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit 9aad8a9

Browse files
committed
Fixed: CLI watcher now works watchs correctl multiples @import (1.8.2)
Close #123
1 parent 9107b32 commit 9aad8a9

File tree

8 files changed

+50
-30
lines changed

8 files changed

+50
-30
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.8.2 - 2015-07-23
2+
3+
- Fixed: CLI watcher now works watchs correctl multiples `@import`
4+
([#123](https://github.com/cssnext/cssnext/issues/123))
5+
16
# 1.8.1 - 2015-07-15
27

38
- Added: cssnext now throw an error if used as a webpack loader to prevent

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cssnext",
3-
"version": "1.8.1",
3+
"version": "1.8.2",
44
"description": "Use tomorrow's CSS syntax, today",
55
"keywords": [
66
"css",

src/__tests__/cli.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/**
22
* Test dependencies
33
*/
4-
const exec = require("child_process").exec
4+
import {exec} from "child_process"
55

6-
const test = require("tape")
6+
import test from "tape"
77

8-
const utils = require("./utils")
9-
const cssnext = require("..")
8+
import utils from "./utils"
9+
import cssnext from ".."
10+
11+
import isBabel from "./utils/isBabel"
1012

1113
/**
1214
* CLI tests
@@ -15,7 +17,7 @@ const input = utils.readFixture("cli")
1517
const output = utils.readFixture("cli.expected")
1618

1719
// node bin is used to help for windows
18-
const cssnextBin = "node dist/bin"
20+
const cssnextBin = isBabel ? "babel-node src/bin" : "node dist/bin"
1921

2022
test("cli", function(t) {
2123
let planned = 0

src/__tests__/cli.watcher.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
/**
22
* Test dependencies
33
*/
4-
const exec = require("child_process").exec
5-
const spawn = require("child_process").spawn
6-
const fs = require("fs")
4+
import {exec, spawn} from "child_process"
5+
import fs from "fs"
76

8-
const test = require("tape")
7+
import test from "tape"
98

10-
const utils = require("./utils")
9+
import utils from "./utils"
10+
11+
import isBabel from "./utils/isBabel"
1112

1213
// I don't success to call the kill() process from node and both Travis CI and
1314
// Appveyor so we avoid this test on this environnements
1415
if (!(process.env.TRAVIS || process.env.APPVEYOR)) {
1516
// node bin is used to help for windows
16-
const cssnextBin = "node dist/bin"
17+
const nodeBin = isBabel ? "babel-node" : "node"
18+
const cssnextBin = isBabel ? "src/bin" : "dist/bin"
1719

1820
test("cli/watcher", function(t) {
1921
let planned = 0
2022

2123
const watchProcess = exec(
22-
cssnextBin +
24+
`${ nodeBin } ${ cssnextBin }` +
2325
" --watch src/__tests__/fixtures/cli.error.css" +
2426
" src/__tests__/fixtures/cli.output--watch.css",
2527
function(err) {
@@ -51,9 +53,10 @@ if (!(process.env.TRAVIS || process.env.APPVEYOR)) {
5153
const watchOut = "src/__tests__/fixtures/cli.output--watch-import.css"
5254

5355
const watchImportProcess = spawn(
54-
"node",
56+
nodeBin,
5557
[
56-
"dist/bin",
58+
cssnextBin,
59+
// "--verbose",
5760
"--watch",
5861
"src/__tests__/fixtures/cli.watch-import.css",
5962
watchOut,
@@ -69,7 +72,9 @@ if (!(process.env.TRAVIS || process.env.APPVEYOR)) {
6972
// cli.import2.css
7073
fs.writeFileSync(
7174
"src/__tests__/fixtures/cli.watch-import.css",
72-
"/**/ @import 'cli.watch-import-import.css';"
75+
"/**/ " +
76+
"@import 'cli.watch-import-import.css';" +
77+
"@import 'cli.watch-import-import2.css';"
7378
)
7479

7580
// we are using setTimeout for the watcher to do his job
@@ -80,7 +85,7 @@ if (!(process.env.TRAVIS || process.env.APPVEYOR)) {
8085
watchOut,
8186
{encoding: "utf8"}
8287
),
83-
"/**/ watch{}",
88+
"/**/ watch{}er{}",
8489
"should update the file"
8590
)
8691

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
watch{}
1+
watch{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
er{}

src/__tests__/utils/isBabel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default typeof _babelPolyfill !== "undefined" && _babelPolyfill === true

src/bin.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ if (config.watch) {
116116

117117
watcher = require("chokidar").watch(input, {ignoreInitial: true})
118118

119+
if (verbose) {
120+
log(color.cyan("Watching"), input)
121+
}
122+
123+
// https://github.com/paulmillr/chokidar/issues/288
124+
// ready event might not be triggered at all
125+
// watcher.on("ready", function() {
126+
// if (verbose) {
127+
// log(color.cyan("Watcher ready"), input)
128+
// }
129+
// })
130+
131+
watcher.on("change", transform)
132+
119133
// watch `@import`ed files
120134
if (config.import) {
121135
// keep a up to date list of imported files
@@ -131,10 +145,12 @@ if (config.watch) {
131145
}
132146

133147
const watcherOnImport = function(imported) {
134-
arrayDiff(importedFiles, imported).forEach(function(file) {
148+
const toUnwatch = arrayDiff(importedFiles, imported)
149+
const toWatch = arrayDiff(imported, importedFiles)
150+
toUnwatch.forEach(function(file) {
135151
watcher.unwatch(rebaseFile(file))
136152
})
137-
arrayDiff(imported, importedFiles).forEach(function(file) {
153+
toWatch.forEach(function(file) {
138154
watcher.add(rebaseFile(file))
139155
})
140156
importedFiles = imported
@@ -195,16 +211,6 @@ function transform() {
195211

196212
transform()
197213

198-
if (watcher) {
199-
watcher.on("ready", function() {
200-
if (verbose) {
201-
log(color.cyan("Watching"), input)
202-
}
203-
204-
watcher.on("change", transform)
205-
})
206-
}
207-
208214
/**
209215
* log content prefixed by time
210216
*

0 commit comments

Comments
 (0)