Skip to content

Commit 4a15678

Browse files
author
Serhii Pashchenko
committed
Make dependencies of config watchable
1 parent db1bd56 commit 4a15678

File tree

5 files changed

+82
-6
lines changed

5 files changed

+82
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"autoprefixer": "^9.4.5",
4343
"bytes": "^3.0.0",
4444
"chalk": "^2.4.1",
45+
"detective": "^5.2.0",
4546
"fs-extra": "^8.0.0",
4647
"lodash": "^4.17.11",
4748
"node-emoji": "^1.8.1",

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs from 'fs'
44
import _ from 'lodash'
55
import postcss from 'postcss'
66

7+
import getModuleDependencies from './lib/getModuleDependencies'
78
import registerConfigAsDependency from './lib/registerConfigAsDependency'
89
import processTailwindFeatures from './processTailwindFeatures'
910
import formatCSS from './lib/formatCSS'
@@ -49,7 +50,9 @@ const getConfigFunction = config => () => {
4950
}
5051

5152
if (!_.isObject(config)) {
52-
delete require.cache[require.resolve(config)]
53+
getModuleDependencies(config).forEach(mdl => {
54+
delete require.cache[require.resolve(mdl.file)]
55+
})
5356
}
5457

5558
return resolveConfig([

src/lib/getModuleDependencies.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import fs from 'fs'
2+
import path from 'path'
3+
import resolve from 'resolve'
4+
import detective from 'detective'
5+
6+
function createModule(file) {
7+
const source = fs.readFileSync(file, 'utf-8')
8+
const requires = detective(source)
9+
10+
return { file, requires }
11+
}
12+
13+
export default function getModuleDependencies(entryFile) {
14+
const rootModule = createModule(entryFile)
15+
const modules = [rootModule]
16+
17+
// Iterate over the modules, even when new
18+
// ones are being added
19+
for (const mdl of modules) {
20+
mdl.requires.forEach(dep => {
21+
const basedir = path.dirname(mdl.file)
22+
const depPath = resolve.sync(dep, { basedir })
23+
const depModule = createModule(depPath)
24+
25+
modules.push(depModule)
26+
})
27+
}
28+
29+
return modules
30+
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import fs from 'fs'
2+
import getModuleDependencies from './getModuleDependencies'
23

34
export default function(configFile) {
45
if (!fs.existsSync(configFile)) {
56
throw new Error(`Specified Tailwind config file "${configFile}" doesn't exist.`)
67
}
78

89
return function(css, opts) {
9-
opts.messages.push({
10-
type: 'dependency',
11-
file: configFile,
12-
parent: css.source.input.file,
10+
getModuleDependencies(configFile).forEach(mdl => {
11+
opts.messages.push({
12+
type: 'dependency',
13+
parent: css.source.input.file,
14+
file: mdl.file,
15+
})
1316
})
1417
}
1518
}

yarn.lock

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,11 @@ abbrev@1:
914914
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
915915
integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==
916916

917+
acorn-dynamic-import@^4.0.0:
918+
version "4.0.0"
919+
resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-4.0.0.tgz#482210140582a36b83c3e342e1cfebcaa9240948"
920+
integrity sha512-d3OEjQV4ROpoflsnUA8HozoIR504TFxNivYEUi6uwz0IYhBkTDXGuWlNdMtybRt3nqVx/L6XqMt0FxkXuWKZhw==
921+
917922
acorn-globals@^4.1.0:
918923
version "4.3.2"
919924
resolved "https://registry.yarnpkg.com/acorn-globals/-/acorn-globals-4.3.2.tgz#4e2c2313a597fd589720395f6354b41cd5ec8006"
@@ -927,7 +932,17 @@ acorn-jsx@^5.0.0:
927932
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.0.1.tgz#32a064fd925429216a09b141102bfdd185fae40e"
928933
integrity sha512-HJ7CfNHrfJLlNTzIEUTj43LNWGkqpRLxm3YjAlcD0ACydk9XynzYsCBHxut+iqt+1aBXkx9UP/w/ZqMr13XIzg==
929934

930-
acorn-walk@^6.0.1:
935+
acorn-node@^1.6.1:
936+
version "1.7.0"
937+
resolved "https://registry.yarnpkg.com/acorn-node/-/acorn-node-1.7.0.tgz#aac6a559d27af6176b076ab6fb13c5974c213e3b"
938+
integrity sha512-XhahLSsCB6X6CJbe+uNu3Mn9sJBNFxtBN9NLgAOQovfS6Kh0lDUtmlclhjn9CvEK7A7YyRU13PXlNcpSiLI9Yw==
939+
dependencies:
940+
acorn "^6.1.1"
941+
acorn-dynamic-import "^4.0.0"
942+
acorn-walk "^6.1.1"
943+
xtend "^4.0.1"
944+
945+
acorn-walk@^6.0.1, acorn-walk@^6.1.1:
931946
version "6.2.0"
932947
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-6.2.0.tgz#123cb8f3b84c2171f1f7fb252615b1c78a6b1a8c"
933948
integrity sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA==
@@ -942,6 +957,11 @@ acorn@^6.0.1, acorn@^6.0.7:
942957
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.2.0.tgz#67f0da2fc339d6cfb5d6fb244fd449f33cd8bbe3"
943958
integrity sha512-8oe72N3WPMjA+2zVG71Ia0nXZ8DpQH+QyyHO+p06jT8eg8FGG3FbcUIi8KziHlAfheJQZeoqbvq1mQSQHXKYLw==
944959

960+
acorn@^6.1.1:
961+
version "6.2.1"
962+
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.2.1.tgz#3ed8422d6dec09e6121cc7a843ca86a330a86b51"
963+
integrity sha512-JD0xT5FCRDNyjDda3Lrg/IxFscp9q4tiYtxE1/nOzlKCk7hIRuYjhq1kCNkbPjMRMZuFq20HNQn1I9k8Oj0E+Q==
964+
945965
ajv@^6.10.0, ajv@^6.5.5, ajv@^6.9.1:
946966
version "6.10.0"
947967
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.10.0.tgz#90d0d54439da587cd7e843bfb7045f50bd22bdf1"
@@ -1588,6 +1608,11 @@ define-property@^2.0.2:
15881608
is-descriptor "^1.0.2"
15891609
isobject "^3.0.1"
15901610

1611+
defined@^1.0.0:
1612+
version "1.0.0"
1613+
resolved "https://registry.yarnpkg.com/defined/-/defined-1.0.0.tgz#c98d9bcef75674188e110969151199e39b1fa693"
1614+
integrity sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=
1615+
15911616
delayed-stream@~1.0.0:
15921617
version "1.0.0"
15931618
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
@@ -1608,6 +1633,15 @@ detect-newline@^2.1.0:
16081633
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-2.1.0.tgz#f41f1c10be4b00e87b5f13da680759f2c5bfd3e2"
16091634
integrity sha1-9B8cEL5LAOh7XxPaaAdZ8sW/0+I=
16101635

1636+
detective@^5.2.0:
1637+
version "5.2.0"
1638+
resolved "https://registry.yarnpkg.com/detective/-/detective-5.2.0.tgz#feb2a77e85b904ecdea459ad897cc90a99bd2a7b"
1639+
integrity sha512-6SsIx+nUUbuK0EthKjv0zrdnajCCXVYGmbYYiYjFVpzcjwEs/JMDZ8tPRG29J/HhN56t3GJp2cGSWDRjjot8Pg==
1640+
dependencies:
1641+
acorn-node "^1.6.1"
1642+
defined "^1.0.0"
1643+
minimist "^1.1.1"
1644+
16111645
diff-sequences@^24.3.0:
16121646
version "24.3.0"
16131647
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-24.3.0.tgz#0f20e8a1df1abddaf4d9c226680952e64118b975"
@@ -4963,6 +4997,11 @@ xml-name-validator@^3.0.0:
49634997
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"
49644998
integrity sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==
49654999

5000+
xtend@^4.0.1:
5001+
version "4.0.2"
5002+
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
5003+
integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==
5004+
49665005
"y18n@^3.2.1 || ^4.0.0":
49675006
version "4.0.0"
49685007
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b"

0 commit comments

Comments
 (0)