Skip to content

Commit e901c0d

Browse files
committed
Add icss-utils
1 parent bb501ee commit e901c0d

File tree

4 files changed

+22
-90
lines changed

4 files changed

+22
-90
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"strip-indent": "^2.0.0"
5757
},
5858
"dependencies": {
59-
"icss-replace-symbols": "^1.1.0",
59+
"icss-utils": "^2.0.0",
6060
"postcss": "^6.0.1"
6161
}
6262
}

src/icss.js

-74
This file was deleted.

src/index.js

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
const postcss = require('postcss')
2-
const { default: replaceSymbols, replaceAll } = require('icss-replace-symbols')
3-
const { extractICSS, createICSSRules } = require('./icss.js')
1+
import postcss from 'postcss'
2+
import {
3+
replaceSymbols,
4+
replaceValueSymbols,
5+
extractICSS,
6+
createICSSRules
7+
} from 'icss-utils'
48

59
const matchImports = /^(.+?|\([\s\S]+?\))\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/
610
const matchValueDefinition = /(?:\s+|^)([\w-]+):?\s+(.+?)\s*$/g
@@ -14,11 +18,11 @@ module.exports = postcss.plugin('postcss-modules-values', () => (
1418
css,
1519
result
1620
) => {
17-
const { imports, exports } = extractICSS(css)
21+
const { icssImports, icssExports } = extractICSS(css)
1822
let importIndex = 0
1923
const createImportedName = (path, name) => {
2024
const importedName = getAliasName(name, importIndex)
21-
if (imports[path] && imports[path][importedName]) {
25+
if (icssImports[path] && icssImports[path][importedName]) {
2226
importIndex += 1
2327
return createImportedName(path, name)
2428
}
@@ -31,7 +35,7 @@ module.exports = postcss.plugin('postcss-modules-values', () => (
3135
while ((matches = matchValueDefinition.exec(atRule.params))) {
3236
let [, key, value] = matches
3337
// Add to the definitions, knowing that values can refer to each other
34-
exports[key] = replaceAll(exports, value)
38+
icssExports[key] = replaceValueSymbols(value, icssExports)
3539
atRule.remove()
3640
}
3741
}
@@ -41,7 +45,7 @@ module.exports = postcss.plugin('postcss-modules-values', () => (
4145
if (matches) {
4246
let [, aliasesString, path] = matches
4347
// We can use constants for path names
44-
if (exports[path]) path = exports[path]
48+
if (icssExports[path]) path = icssExports[path]
4549
let aliases = aliasesString
4650
.replace(/^\(\s*([\s\S]+)\s*\)$/, '$1')
4751
.split(/\s*,\s*/)
@@ -50,7 +54,7 @@ module.exports = postcss.plugin('postcss-modules-values', () => (
5054
if (tokens) {
5155
let [, theirName, myName = theirName] = tokens
5256
let importedName = createImportedName(path, myName)
53-
exports[myName] = importedName
57+
icssExports[myName] = importedName
5458
return { theirName, importedName }
5559
} else {
5660
throw new Error(`@import statement "${alias}" is invalid!`)
@@ -60,7 +64,7 @@ module.exports = postcss.plugin('postcss-modules-values', () => (
6064
acc[importedName] = theirName
6165
return acc
6266
}, {})
63-
imports[path] = Object.assign({}, imports[path], aliases)
67+
icssImports[path] = Object.assign({}, icssImports[path], aliases)
6468
atRule.remove()
6569
}
6670
}
@@ -79,10 +83,10 @@ module.exports = postcss.plugin('postcss-modules-values', () => (
7983
})
8084

8185
/* If we have no definitions, don't continue */
82-
if (Object.keys(exports).length === 0) return
86+
if (Object.keys(icssExports).length === 0) return
8387

8488
/* Perform replacements */
85-
replaceSymbols(css, exports)
89+
replaceSymbols(css, icssExports)
8690

87-
css.prepend(createICSSRules(imports, exports))
91+
css.prepend(createICSSRules(icssImports, icssExports))
8892
})

yarn.lock

+5-3
Original file line numberDiff line numberDiff line change
@@ -1370,9 +1370,11 @@ iconv-lite@0.4.13:
13701370
version "0.4.13"
13711371
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.13.tgz#1f88aba4ab0b1508e8312acc39345f36e992e2f2"
13721372

1373-
icss-replace-symbols@^1.1.0:
1374-
version "1.1.0"
1375-
resolved "https://registry.yarnpkg.com/icss-replace-symbols/-/icss-replace-symbols-1.1.0.tgz#06ea6f83679a7749e386cfe1fe812ae5db223ded"
1373+
icss-utils@^2.0.0:
1374+
version "2.0.0"
1375+
resolved "https://registry.yarnpkg.com/icss-utils/-/icss-utils-2.0.0.tgz#9eb8432af871adc003e4ac7a574d24169398317d"
1376+
dependencies:
1377+
postcss "^6.0.1"
13761378

13771379
indent-string@^2.1.0:
13781380
version "2.1.0"

0 commit comments

Comments
 (0)