From e68f6f7f36d7b3898af3f2022f55e80ce50193bc Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sat, 16 Sep 2023 22:28:37 +0200 Subject: [PATCH 1/3] add benchmarks for creating sourcemaps --- gulpfile.js | 4 +-- sourcemaps.js | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 sourcemaps.js diff --git a/gulpfile.js b/gulpfile.js index 64298ea..d46b4a2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -31,7 +31,7 @@ gulp.task('bootstrap', async () => { }) }) -for (let name of ['preprocessors', 'parsers', 'prefixers', 'tokenizers', 'linters']) { +for (let name of ['preprocessors', 'parsers', 'prefixers', 'tokenizers', 'linters', 'sourcemaps']) { gulp.task( name, gulp.series('bootstrap', () => { @@ -47,5 +47,5 @@ for (let name of ['preprocessors', 'parsers', 'prefixers', 'tokenizers', 'linter gulp.task( 'default', - gulp.series('preprocessors', 'parsers', 'prefixers', 'tokenizers', 'linters') + gulp.series('preprocessors', 'parsers', 'prefixers', 'tokenizers', 'linters', 'sourcemaps') ) diff --git a/sourcemaps.js b/sourcemaps.js new file mode 100644 index 0000000..b2a1f45 --- /dev/null +++ b/sourcemaps.js @@ -0,0 +1,67 @@ +/* Results on Node 20.3.1, Github Actions: + +TODO +*/ + +let { existsSync, readFileSync } = require('fs') +let { join } = require('path') +const postcss = require('postcss') + +let example = join(__dirname, 'cache', 'bootstrap.css') +let css = readFileSync(example).toString() + +module.exports = { + maxTime: 15, + name: 'Sourcemaps', + tests: [ + { + defer: true, + fn: done => { + { + let root = postcss.parse(css, { from: example }) + root.toResult({ map: { inline: false }, to: 'dist/bootstrap.css' }).map.toJSON() + } + + { + let root = postcss.parse(css, { from: example }) + root.toResult({ map: { absolute: true, inline: false }, to: 'dist/bootstrap.css' }).map.toJSON() + } + + { + let root = postcss.parse(css, { from: example }) + root.toResult({ map: { inline: true }, to: 'dist/bootstrap.css' }) + } + + done.resolve() + }, + name: 'PostCSS' + } + ] +} + +let devPath = join(__dirname, '../postcss/lib/postcss.js') +if (existsSync(devPath)) { + let devPostcss = require(devPath) + module.exports.tests.splice(1, 0, { + defer: true, + fn: done => { + { + let root = devPostcss.parse(css, { from: example }) + root.toResult({ map: { inline: false }, to: 'dist/bootstrap.css' }).map.toJSON() + } + + { + let root = devPostcss.parse(css, { from: example }) + root.toResult({ map: { absolute: true, inline: false }, to: 'dist/bootstrap.css' }).map.toJSON() + } + + { + let root = devPostcss.parse(css, { from: example }) + root.toResult({ map: { inline: true }, to: 'dist/bootstrap.css' }) + } + + done.resolve() + }, + name: 'Next PostCSS' + }) +} From b7eaa6bc82dbc01e24c5abd227059aa25fc28d0d Mon Sep 17 00:00:00 2001 From: Romain Menke <11521496+romainmenke@users.noreply.github.com> Date: Sat, 16 Sep 2023 22:35:10 +0200 Subject: [PATCH 2/3] Update sourcemaps.js --- sourcemaps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sourcemaps.js b/sourcemaps.js index b2a1f45..5a8b0e0 100644 --- a/sourcemaps.js +++ b/sourcemaps.js @@ -1,6 +1,6 @@ /* Results on Node 20.3.1, Github Actions: -TODO +PostCSS: 389 ms */ let { existsSync, readFileSync } = require('fs') From a44e7e5d1c97b19ba5001ac840aea2d40f3d8717 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sat, 16 Sep 2023 22:52:17 +0200 Subject: [PATCH 3/3] apply suggestions from code review --- sourcemaps.js | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/sourcemaps.js b/sourcemaps.js index 5a8b0e0..0583d02 100644 --- a/sourcemaps.js +++ b/sourcemaps.js @@ -17,20 +17,14 @@ module.exports = { { defer: true, fn: done => { - { - let root = postcss.parse(css, { from: example }) - root.toResult({ map: { inline: false }, to: 'dist/bootstrap.css' }).map.toJSON() - } + let root = postcss.parse(css, { from: example }) + root.toResult({ map: { inline: false }, to: 'dist/bootstrap.css' }).map.toJSON() - { - let root = postcss.parse(css, { from: example }) - root.toResult({ map: { absolute: true, inline: false }, to: 'dist/bootstrap.css' }).map.toJSON() - } + root = postcss.parse(css, { from: example }) + root.toResult({ map: { absolute: true, inline: false }, to: 'dist/bootstrap.css' }).map.toJSON() - { - let root = postcss.parse(css, { from: example }) - root.toResult({ map: { inline: true }, to: 'dist/bootstrap.css' }) - } + root = postcss.parse(css, { from: example }) + root.toResult({ map: { inline: true }, to: 'dist/bootstrap.css' }) done.resolve() }, @@ -45,20 +39,14 @@ if (existsSync(devPath)) { module.exports.tests.splice(1, 0, { defer: true, fn: done => { - { - let root = devPostcss.parse(css, { from: example }) - root.toResult({ map: { inline: false }, to: 'dist/bootstrap.css' }).map.toJSON() - } + let root = devPostcss.parse(css, { from: example }) + root.toResult({ map: { inline: false }, to: 'dist/bootstrap.css' }).map.toJSON() - { - let root = devPostcss.parse(css, { from: example }) - root.toResult({ map: { absolute: true, inline: false }, to: 'dist/bootstrap.css' }).map.toJSON() - } + root = devPostcss.parse(css, { from: example }) + root.toResult({ map: { absolute: true, inline: false }, to: 'dist/bootstrap.css' }).map.toJSON() - { - let root = devPostcss.parse(css, { from: example }) - root.toResult({ map: { inline: true }, to: 'dist/bootstrap.css' }) - } + root = devPostcss.parse(css, { from: example }) + root.toResult({ map: { inline: true }, to: 'dist/bootstrap.css' }) done.resolve() },