Skip to content

Commit 8d29696

Browse files
committed
build: speed up legacy tests bundle
I've noticed a speed up from 4min to like 30seconds that way. Sass also recommends the sync variant.
1 parent 6c9595c commit 8d29696

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

scripts/create-legacy-tests-bundle.mjs

+17-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import fs from 'fs';
77
import glob from 'glob';
88
import module from 'module';
99
import {dirname, join, relative} from 'path';
10-
import sass from 'sass';
10+
import * as sass from 'sass';
1111
import url from 'url';
1212
import tsNode from 'ts-node';
1313

@@ -86,22 +86,26 @@ async function main() {
8686
*/
8787
async function compileSassFiles() {
8888
const sassFiles = glob.sync('src/**/!(_*|theme).scss', {cwd: projectDir, absolute: true});
89-
const sassTasks = [];
89+
const writeTasks = [];
9090

91+
let count = 0;
9192
for (const file of sassFiles) {
9293
const outRelativePath = relative(projectDir, file).replace(/\.scss$/, '.css');
9394
const outPath = join(projectDir, outRelativePath);
94-
const task = renderSassFileAsync(file).then(async content => {
95+
const content = renderSassFile(file).css;
96+
97+
count++;
98+
console.error(`Compiled ${count}/${sassFiles.length} files`);
99+
100+
writeTasks.push(async () => {
95101
console.info('Compiled, now writing:', outRelativePath);
96102
await fs.promises.mkdir(dirname(outPath), {recursive: true});
97103
await fs.promises.writeFile(outPath, content);
98104
});
99-
100-
sassTasks.push(task);
101105
}
102106

103-
// Wait for all Sass compilations to finish.
104-
await Promise.all(sassTasks);
107+
// Start all writes and wait for them to finish.
108+
await Promise.all(writeTasks.map(task => task()));
105109
}
106110

107111
/**
@@ -156,14 +160,12 @@ async function createEntryPointSpecFile() {
156160
return specEntryPointFile;
157161
}
158162

159-
/** Helper function to render a Sass file asynchronously using promises. */
160-
async function renderSassFileAsync(inputFile) {
161-
return sass
162-
.compileAsync(inputFile, {
163-
loadPaths: [nodeModulesDir, projectDir],
164-
importers: [localPackageSassImporter],
165-
})
166-
.then(result => result.css);
163+
/** Helper function to render a Sass file. */
164+
function renderSassFile(inputFile) {
165+
return sass.compile(inputFile, {
166+
loadPaths: [nodeModulesDir, projectDir],
167+
importers: [localPackageSassImporter],
168+
});
167169
}
168170

169171
/**

0 commit comments

Comments
 (0)