first commit
This commit is contained in:
17
build/node_modules/postcss-import/lib/join-media.js
generated
vendored
Normal file
17
build/node_modules/postcss-import/lib/join-media.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict"
|
||||
|
||||
module.exports = function(parentMedia, childMedia) {
|
||||
if (!parentMedia.length && childMedia.length) return childMedia
|
||||
if (parentMedia.length && !childMedia.length) return parentMedia
|
||||
if (!parentMedia.length && !childMedia.length) return []
|
||||
|
||||
const media = []
|
||||
|
||||
parentMedia.forEach(parentItem => {
|
||||
childMedia.forEach(childItem => {
|
||||
if (parentItem !== childItem) media.push(`${parentItem} and ${childItem}`)
|
||||
})
|
||||
})
|
||||
|
||||
return media
|
||||
}
|
||||
5
build/node_modules/postcss-import/lib/load-content.js
generated
vendored
Normal file
5
build/node_modules/postcss-import/lib/load-content.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
const readCache = require("read-cache")
|
||||
|
||||
module.exports = filename => readCache(filename, "utf-8")
|
||||
137
build/node_modules/postcss-import/lib/parse-statements.js
generated
vendored
Normal file
137
build/node_modules/postcss-import/lib/parse-statements.js
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
"use strict"
|
||||
|
||||
// external tooling
|
||||
const valueParser = require("postcss-value-parser")
|
||||
|
||||
// extended tooling
|
||||
const stringify = valueParser.stringify
|
||||
|
||||
function split(params, start) {
|
||||
const list = []
|
||||
const last = params.reduce((item, node, index) => {
|
||||
if (index < start) return ""
|
||||
if (node.type === "div" && node.value === ",") {
|
||||
list.push(item)
|
||||
return ""
|
||||
}
|
||||
return item + stringify(node)
|
||||
}, "")
|
||||
list.push(last)
|
||||
return list
|
||||
}
|
||||
|
||||
module.exports = function(result, styles) {
|
||||
const statements = []
|
||||
let nodes = []
|
||||
|
||||
styles.each(node => {
|
||||
let stmt
|
||||
if (node.type === "atrule") {
|
||||
if (node.name === "import") stmt = parseImport(result, node)
|
||||
else if (node.name === "media") stmt = parseMedia(result, node)
|
||||
}
|
||||
|
||||
if (stmt) {
|
||||
if (nodes.length) {
|
||||
statements.push({
|
||||
type: "nodes",
|
||||
nodes: nodes,
|
||||
media: [],
|
||||
})
|
||||
nodes = []
|
||||
}
|
||||
statements.push(stmt)
|
||||
} else nodes.push(node)
|
||||
})
|
||||
|
||||
if (nodes.length) {
|
||||
statements.push({
|
||||
type: "nodes",
|
||||
nodes: nodes,
|
||||
media: [],
|
||||
})
|
||||
}
|
||||
|
||||
return statements
|
||||
}
|
||||
|
||||
function parseMedia(result, atRule) {
|
||||
const params = valueParser(atRule.params).nodes
|
||||
return {
|
||||
type: "media",
|
||||
node: atRule,
|
||||
media: split(params, 0),
|
||||
}
|
||||
}
|
||||
|
||||
function parseImport(result, atRule) {
|
||||
let prev = getPrev(atRule)
|
||||
if (prev) {
|
||||
do {
|
||||
if (
|
||||
prev.type !== "atrule" ||
|
||||
(prev.name !== "import" && prev.name !== "charset")
|
||||
) {
|
||||
return result.warn(
|
||||
"@import must precede all other statements (besides @charset)",
|
||||
{ node: atRule }
|
||||
)
|
||||
} else prev = getPrev(prev)
|
||||
} while (prev)
|
||||
}
|
||||
|
||||
if (atRule.nodes) {
|
||||
return result.warn(
|
||||
"It looks like you didn't end your @import statement correctly. " +
|
||||
"Child nodes are attached to it.",
|
||||
{ node: atRule }
|
||||
)
|
||||
}
|
||||
|
||||
const params = valueParser(atRule.params).nodes
|
||||
const stmt = {
|
||||
type: "import",
|
||||
node: atRule,
|
||||
media: [],
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
if (
|
||||
!params.length ||
|
||||
(
|
||||
params[0].type !== "string" ||
|
||||
!params[0].value
|
||||
) &&
|
||||
(
|
||||
params[0].type !== "function" ||
|
||||
params[0].value !== "url" ||
|
||||
!params[0].nodes.length ||
|
||||
!params[0].nodes[0].value
|
||||
)
|
||||
) {
|
||||
return result.warn(`Unable to find uri in '${ atRule.toString() }'`, {
|
||||
node: atRule,
|
||||
})
|
||||
}
|
||||
|
||||
if (params[0].type === "string") stmt.uri = params[0].value
|
||||
else stmt.uri = params[0].nodes[0].value
|
||||
stmt.fullUri = stringify(params[0])
|
||||
|
||||
if (params.length > 2) {
|
||||
if (params[1].type !== "space") {
|
||||
return result.warn("Invalid import media statement", { node: atRule })
|
||||
}
|
||||
stmt.media = split(params, 2)
|
||||
}
|
||||
|
||||
return stmt
|
||||
}
|
||||
|
||||
function getPrev(item) {
|
||||
let prev = item.prev()
|
||||
while (prev && prev.type === "comment") {
|
||||
prev = prev.prev()
|
||||
}
|
||||
return prev
|
||||
}
|
||||
57
build/node_modules/postcss-import/lib/process-content.js
generated
vendored
Normal file
57
build/node_modules/postcss-import/lib/process-content.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
"use strict"
|
||||
|
||||
// builtin tooling
|
||||
const path = require("path")
|
||||
|
||||
// external tooling
|
||||
const postcss = require("postcss")
|
||||
|
||||
// placeholder tooling
|
||||
let sugarss
|
||||
|
||||
module.exports = function processContent(result, content, filename, options) {
|
||||
const plugins = options.plugins
|
||||
const ext = path.extname(filename)
|
||||
|
||||
const parserList = []
|
||||
|
||||
// SugarSS support:
|
||||
if (ext === ".sss") {
|
||||
if (!sugarss) {
|
||||
try {
|
||||
sugarss = require("sugarss")
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
if (sugarss) return runPostcss(content, filename, plugins, [sugarss])
|
||||
}
|
||||
|
||||
// Syntax support:
|
||||
if (result.opts.syntax && result.opts.syntax.parse) {
|
||||
parserList.push(result.opts.syntax.parse)
|
||||
}
|
||||
|
||||
// Parser support:
|
||||
if (result.opts.parser) parserList.push(result.opts.parser)
|
||||
// Try the default as a last resort:
|
||||
parserList.push(null)
|
||||
|
||||
return runPostcss(content, filename, plugins, parserList)
|
||||
}
|
||||
|
||||
function runPostcss(content, filename, plugins, parsers, index) {
|
||||
if (!index) index = 0
|
||||
return postcss(plugins)
|
||||
.process(content, {
|
||||
from: filename,
|
||||
parser: parsers[index],
|
||||
})
|
||||
.catch(err => {
|
||||
// If there's an error, try the next parser
|
||||
index++
|
||||
// If there are no parsers left, throw it
|
||||
if (index === parsers.length) throw err
|
||||
return runPostcss(content, filename, plugins, parsers, index)
|
||||
})
|
||||
}
|
||||
42
build/node_modules/postcss-import/lib/resolve-id.js
generated
vendored
Normal file
42
build/node_modules/postcss-import/lib/resolve-id.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
"use strict"
|
||||
|
||||
// external tooling
|
||||
const resolve = require("resolve")
|
||||
|
||||
const moduleDirectories = ["web_modules", "node_modules"]
|
||||
|
||||
function resolveModule(id, opts) {
|
||||
return new Promise((res, rej) => {
|
||||
resolve(id, opts, (err, path) => (err ? rej(err) : res(path)))
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = function(id, base, options) {
|
||||
const paths = options.path
|
||||
|
||||
const resolveOpts = {
|
||||
basedir: base,
|
||||
moduleDirectory: moduleDirectories.concat(options.addModulesDirectories),
|
||||
paths: paths,
|
||||
extensions: [".css"],
|
||||
packageFilter: function processPackage(pkg) {
|
||||
if (pkg.style) pkg.main = pkg.style
|
||||
else if (!pkg.main || !/\.css$/.test(pkg.main)) pkg.main = "index.css"
|
||||
return pkg
|
||||
},
|
||||
preserveSymlinks: false,
|
||||
}
|
||||
|
||||
return resolveModule(`./${id}`, resolveOpts)
|
||||
.catch(() => resolveModule(id, resolveOpts))
|
||||
.catch(() => {
|
||||
if (paths.indexOf(base) === -1) paths.unshift(base)
|
||||
|
||||
throw new Error(
|
||||
`Failed to find '${id}'
|
||||
in [
|
||||
${paths.join(",\n ")}
|
||||
]`
|
||||
)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user