Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumped postcss to v8 #764

Merged
merged 9 commits into from
Mar 22, 2022
Merged
6 changes: 4 additions & 2 deletions packages/ckeditor5-dev-env/lib/translations/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ function saveNewTranslations( { packageName, packagePath, translations, simplify

poFileContent = cleanPoFileContent( poFileContent, { simplifyLicenseHeader } );

const pathToSave = path.join( packagePath, lang + '.po' );
const pathToSave = path.join( packagePath, lang + '.po' )
.split( path.sep ).join( path.posix.sep );

fs.outputFileSync( pathToSave, poFileContent );
savedFiles++;
Expand All @@ -132,7 +133,8 @@ function saveNewTranslations( { packageName, packagePath, translations, simplify
* @return {String}
*/
function getPathToTranslations( cwd, packagePath ) {
return path.join( cwd, packagePath, 'lang', 'translations' );
return path.join( cwd, packagePath, 'lang', 'translations' )
.split( path.sep ).join( path.posix.sep );
}

function isPoFileContainingTranslations( poFileContent ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe( 'dev-env/release-tools/utils/transform-commit', () => {
} );

afterEach( () => {
fs.rmdirSync( path.join( tmpCwd, '.git' ), { recursive: true } );
fs.rmSync( path.join( tmpCwd, '.git' ), { recursive: true } );
fs.readdirSync( tmpCwd ).forEach( file => fs.unlinkSync( file ) );
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe( 'dev-env/release-tools/utils', () => {

afterEach( () => {
process.chdir( cwd );
fs.rmdirSync( path.join( tmpCwd, '.git' ), { recursive: true } );
fs.rmSync( path.join( tmpCwd, '.git' ), { recursive: true } );

sandbox.restore();
mockery.disable();
Expand Down
117 changes: 59 additions & 58 deletions packages/ckeditor5-dev-utils/lib/styles/themeimporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@ const getPackageName = require( './utils/getpackagename' );
* to reflect the structure of the CSS files in editor packages,
*
* E.g., if the path to the theme is:
*
* "/foo/bar/ckeditor5-theme-foo/theme/theme.css"
* `/foo/bar/ckeditor5-theme-foo/theme/theme.css`
*
* and the CSS to be themed is:
* `/baz/qux/ckeditor5-qux/theme/components/button.css`
*
* "/baz/qux/ckeditor5-qux/theme/components/button.css"
*
* the theme file for "button.css" should be located under
*
* "/foo/bar/ckeditor5-theme-foo/ckeditor5-qux/theme/components/button.css"
* the theme file for `button.css` should be located under:
* `/foo/bar/ckeditor5-theme-foo/ckeditor5-qux/theme/components/button.css`
*
* See the `ThemeImporterOptions` to learn about importer options.
*
Expand All @@ -41,30 +38,37 @@ const getPackageName = require( './utils/getpackagename' );
* @param {ThemeImporterOptions} pluginOptions
* @returns {Function} A PostCSS plugin.
*/
module.exports = postcss.plugin( 'postcss-ckeditor5-theme-importer', ( pluginOptions = {} ) => {
return ( root, result ) => {
// Clone the options, don't alter the original options object.
const options = Object.assign( {}, pluginOptions, {
debug: pluginOptions.debug || false,
postCssOptions: {
plugins: [
require( 'postcss-import' )(),
require( './themelogger' )()
]
},
root, result
} );
module.exports = ( pluginOptions = {} ) => {
return {
postcssPlugin: 'postcss-ckeditor5-theme-importer',
Once( root, { result } ) {
// Clone the options, don't alter the original options object.
const options = Object.assign( {}, pluginOptions, {
debug: pluginOptions.debug || false,
postCssOptions: {
plugins: [
require( 'postcss-import' )(),
require( './themelogger' )()
]
},
root, result
} );

return importThemeFile( options );
return importThemeFile( options );
}
};
} );

// Imports a complementary theme file corresponding with a CSS file being processed by
// PostCSS, if such theme file exists.
//
// @private
// @param {Options} Plugin options.
// @returns {Promise}
};

pomek marked this conversation as resolved.
Show resolved Hide resolved
module.exports.postcss = true;

/**
* Imports a complementary theme file corresponding with a CSS file being processed by
* PostCSS, if such theme file exists.
*
* @private
* @param {Options} Plugin options.
* @returns {Promise}
*/
function importThemeFile( options ) {
const inputFilePath = options.root.source.input.file;

Expand All @@ -83,12 +87,14 @@ function importThemeFile( options ) {
}
}

// Imports a CSS file specified in the options using the postcss-import
// plugin and appends its content to the css tree (root).
//
// @private
// @param {Options} Plugin options.
// @returns {Promise}
/**
* Imports a CSS file specified in the options using the postcss-import
* plugin and appends its content to the css tree (root).
*
* @private
* @param {Options} Plugin options.
* @returns {Promise}
*/
function importFile( options ) {
const { root, result, sourceMap } = options;
const file = options.fileToImport;
Expand Down Expand Up @@ -134,29 +140,24 @@ function importFile( options ) {
} );
}

// For given:
//
// * path to the theme,
// * and path to the CSS file processed by PostCSS,
//
// it returns a path to the complementary file in the theme.
//
// E.g., if the path to the theme is:
//
// "/foo/bar/ckeditor5-theme-foo/theme/theme.css"
//
// and the CSS to be themed is:
//
// "/baz/qux/ckeditor5-qux/theme/components/button.css"
//
// this helper will return:
//
// "/foo/bar/ckeditor5-theme-foo/ckeditor5-qux/theme/components/button.css"
//
// @private
// @param {String} themePath Path to the theme.
// @param {String} inputFilePath Path to the CSS file which is to be themed.
// @returns {String}
/**
* For given path to the theme, and a path to the CSS file processed by
* PostCSS, it returns a path to the complementary file in the theme.
*
* E.g., if the path to the theme is:
* `/foo/bar/ckeditor5-theme-foo/theme/theme.css`
*
* and the CSS to be themed is:
* `/baz/qux/ckeditor5-qux/theme/components/button.css`
*
* this helper will return:
* `/foo/bar/ckeditor5-theme-foo/ckeditor5-qux/theme/components/button.css`
*
* @private
* @param {String} themePath Path to the theme.
* @param {String} inputFilePath Path to the CSS file which is to be themed.
* @returns {String}
*/
function getThemeFilePath( themePath, inputFilePath ) {
// ckeditor5-theme-foo/theme/theme.css -> ckeditor5-theme-foo/theme
themePath = path.dirname( themePath );
Expand Down
17 changes: 10 additions & 7 deletions packages/ckeditor5-dev-utils/lib/styles/themelogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@

'use strict';

/* eslint-env node */

const postcss = require( 'postcss' );

/**
* A plugin that prepends a path to the file in the comment for each file
* processed by PostCSS.
*
* @returns {Function} A PostCSS plugin.
*/
module.exports = postcss.plugin( 'postcss-ckeditor5-theme-logger', () => {
return root => root.prepend( `/* ${ root.source.input.file } */ \n` );
} );
module.exports = () => {
return {
postcssPlugin: 'postcss-ckeditor5-theme-logger',
Once( root ) {
root.prepend( `/* ${ root.source.input.file } */ \n` );
}
};
};

module.exports.postcss = true;
11 changes: 6 additions & 5 deletions packages/ckeditor5-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
"is-interactive": "^1.0.0",
"javascript-stringify": "^1.6.0",
"pofile": "^1.0.9",
"postcss": "^7.0.39",
"postcss-import": "^12.0.0",
"postcss-loader": "^3.0.0",
"postcss-mixins": "^6.2.0",
"postcss-nesting": "^7.0.0",
"postcss": "^8.4.12",
pomek marked this conversation as resolved.
Show resolved Hide resolved
"postcss-import": "^14.0.2",
"postcss-loader": "^4.3.0",
"postcss-mixins": "^6.2.3",
"postcss-nesting": "^7.0.1",
"raw-loader": "^4.0.1",
"shelljs": "^0.8.1",
"style-loader": "^2.0.0",
Expand All @@ -38,6 +38,7 @@
"vinyl": "^2.1.0"
},
"peerDependencies": {
"postcss": "^8.4.12",
"webpack": "^4.43.0 || ^5.24.0"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-dev-utils/tests/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe( 'stream', () => {
const file = new Vinyl( {
cwd: './',
path,
contents: new Buffer( '' )
contents: new Buffer.from( '' ) // eslint-disable-line new-cap
pomek marked this conversation as resolved.
Show resolved Hide resolved
} );

expect( utils.isTestFile( file ) ).to.equal( expected );
Expand Down