-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
821 additions
and
438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
plugins: ['mock-plugin'] | ||
} | ||
plugins: ["mock-plugin"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
const postcss = require('postcss') | ||
const postcss = require("postcss"); | ||
|
||
module.exports = postcss.plugin('postcss-fixture', () => (root) => { | ||
console.warn('warn') | ||
console.error('error') | ||
return root | ||
}) | ||
module.exports = (options = {}) => ({ | ||
postcssPlugin: "postcss-csso", | ||
Once(root, { result, postcss }) { | ||
console.warn("warn"); | ||
console.error("error"); | ||
return root; | ||
}, | ||
}); | ||
|
||
module.exports.postcss = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,39 @@ | ||
const { spawnSync } = require('child_process') | ||
const path = require('path') | ||
const { spawnSync } = require("child_process"); | ||
const path = require("path"); | ||
|
||
module.exports = (css, settings) => { | ||
const cssWithPlaceholders = css | ||
.replace(/%%styled-jsx-placeholder-(\d+)%%/g, (_, id) => | ||
`/*%%styled-jsx-placeholder-${id}%%*/` | ||
) | ||
const cssWithPlaceholders = css.replace( | ||
/%%styled-jsx-placeholder-(\d+)%%/g, | ||
(_, id) => `/*%%styled-jsx-placeholder-${id}%%*/` | ||
); | ||
|
||
const result = spawnSync('node', [path.resolve(__dirname, 'processor.js')], { | ||
const result = spawnSync("node", [path.resolve(__dirname, "processor.js")], { | ||
input: JSON.stringify({ | ||
css: cssWithPlaceholders, | ||
settings | ||
settings, | ||
}), | ||
encoding: 'utf8' | ||
}) | ||
encoding: "utf8", | ||
}); | ||
|
||
if (result.status !== 0) { | ||
if (result.stderr.includes('Invalid PostCSS Plugin')) { | ||
console.error('Next.js 9 default postcss support uses a non standard postcss config schema https://err.sh/next.js/postcss-shape, you must use the interoperable object-based format instead https://nextjs.org/docs/advanced-features/customizing-postcss-config') | ||
if (result.stderr.includes("Invalid PostCSS Plugin")) { | ||
let isNext = false; | ||
try { | ||
require.resolve("next"); | ||
isNext = true; | ||
} catch (err) {} | ||
if (isNext) { | ||
console.error( | ||
"Next.js 9 default postcss support uses a non standard postcss config schema https://err.sh/next.js/postcss-shape, you must use the interoperable object-based format instead https://nextjs.org/docs/advanced-features/customizing-postcss-config" | ||
); | ||
} | ||
} | ||
|
||
throw new Error(`postcss failed with ${result.stderr}`) | ||
throw new Error(`postcss failed with ${result.stderr}`); | ||
} | ||
|
||
return result.stdout | ||
.replace(/\/\*%%styled-jsx-placeholder-(\d+)%%\*\//g, (_, id) => | ||
`%%styled-jsx-placeholder-${id}%%` | ||
) | ||
} | ||
return result.stdout.replace( | ||
/\/\*%%styled-jsx-placeholder-(\d+)%%\*\//g, | ||
(_, id) => `%%styled-jsx-placeholder-${id}%%` | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
const path = require('path') | ||
const path = require("path"); | ||
|
||
module.exports = { | ||
plugins: { | ||
'postcss-easy-import': {}, | ||
'postcss-preset-env': { | ||
browsers: ['last 2 versions', 'ie >= 10'], | ||
"postcss-import": {}, | ||
"postcss-preset-env": { | ||
browsers: ["last 2 versions", "ie >= 10"], | ||
features: { | ||
'nesting-rules': true, | ||
'color-mod-function': { | ||
unresolved: 'warn', | ||
"nesting-rules": true, | ||
"color-mod-function": { | ||
unresolved: "warn", | ||
}, | ||
}, | ||
}, | ||
'postcss-spiffing': {}, | ||
[path.resolve(__dirname, './fixture-postcss-plugin.js')]: {} | ||
"postcss-calc": {}, | ||
[path.resolve(__dirname, "./fixture-postcss-plugin.js")]: {}, | ||
}, | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,47 @@ | ||
const postcss = require('postcss') | ||
const loader = require('postcss-load-plugins') | ||
const postcss = require("postcss"); | ||
const loader = require("postcss-load-config"); | ||
|
||
let plugins | ||
let _processor | ||
let plugins; | ||
let _processor; | ||
|
||
function processor(src, options) { | ||
options = options || {} | ||
let loaderPromise | ||
options = options || {}; | ||
let loaderPromise; | ||
if (!plugins) { | ||
loaderPromise = loader(options.env || process.env, options.path, { argv: false }) | ||
.then(pluginsInfo => { | ||
plugins = pluginsInfo.plugins || [] | ||
}) | ||
loaderPromise = loader(options.env || process.env, options.path, { | ||
argv: false, | ||
}).then((pluginsInfo) => { | ||
plugins = pluginsInfo.plugins || []; | ||
}); | ||
} else { | ||
loaderPromise = Promise.resolve() | ||
loaderPromise = Promise.resolve(); | ||
} | ||
|
||
return loaderPromise | ||
.then(() => { | ||
if (!_processor) { | ||
_processor = postcss(plugins) | ||
_processor = postcss(plugins); | ||
} | ||
return _processor.process(src, { from: false }) | ||
return _processor.process(src, { from: false }); | ||
}) | ||
.then(result => result.css) | ||
.then((result) => result.css); | ||
} | ||
|
||
let input = '' | ||
process.stdin.on('data', data => { | ||
input += data.toString() | ||
}) | ||
let input = ""; | ||
process.stdin.on("data", (data) => { | ||
input += data.toString(); | ||
}); | ||
|
||
process.stdin.on('end', () => { | ||
const inputData = JSON.parse(input) | ||
process.stdin.on("end", () => { | ||
const inputData = JSON.parse(input); | ||
processor(inputData.css, inputData.settings) | ||
.then(result => { | ||
process.stdout.write(result) | ||
.then((result) => { | ||
process.stdout.write(result); | ||
}) | ||
.catch(err => { | ||
.catch((err) => { | ||
// NOTE: we console.erorr(err) and then process.exit(1) instead of throwing the error | ||
// to avoid the UnhandledPromiseRejectionWarning message. | ||
console.error(err) | ||
process.exit(1) | ||
}) | ||
}) | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
}); |
Oops, something went wrong.