@epublishing/grunt-epublishing 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/sass-compiler.js +31 -3
- package/package.json +1 -1
package/lib/sass-compiler.js
CHANGED
|
@@ -141,7 +141,21 @@ async function ensureDir(filePath) {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
/**
|
|
144
|
-
* Compile a single Sass file
|
|
144
|
+
* Compile a single Sass file in an isolated dart-sass compiler instance.
|
|
145
|
+
*
|
|
146
|
+
* Uses `sass.initAsyncCompiler()` instead of the module-level
|
|
147
|
+
* `sass.compileAsync()` to guarantee no shared state between concurrent
|
|
148
|
+
* compilations. The module-level singleton queues all calls through a
|
|
149
|
+
* single long-running dart-sass worker; in that model any subtle stateful
|
|
150
|
+
* behavior (import caching, in-flight deps, etc.) can bleed from one
|
|
151
|
+
* compilation's output into another's when we run a chunk in parallel.
|
|
152
|
+
*
|
|
153
|
+
* The symptom was stylesheets ending up with rules that their source
|
|
154
|
+
* file never imported (e.g. achrnews `application-v2.css` getting print
|
|
155
|
+
* rules from `jade-bnp-print.scss`). With a per-file isolated compiler,
|
|
156
|
+
* each file is compiled in its own worker, disposed when done — no
|
|
157
|
+
* possible cross-contamination vector.
|
|
158
|
+
*
|
|
145
159
|
* @param {string} src - Source file path
|
|
146
160
|
* @param {string} dest - Destination file path
|
|
147
161
|
* @param {Object} options - Compilation options
|
|
@@ -163,8 +177,10 @@ async function compileFile(src, dest, options = {}) {
|
|
|
163
177
|
importers.push(adaptLegacyImporter(legacyImporter));
|
|
164
178
|
}
|
|
165
179
|
|
|
180
|
+
let compiler = null;
|
|
166
181
|
try {
|
|
167
|
-
|
|
182
|
+
compiler = await sass.initAsyncCompiler();
|
|
183
|
+
const result = await compiler.compileAsync(src, {
|
|
168
184
|
style,
|
|
169
185
|
sourceMap,
|
|
170
186
|
loadPaths,
|
|
@@ -187,6 +203,14 @@ async function compileFile(src, dest, options = {}) {
|
|
|
187
203
|
return { src, dest, success: true };
|
|
188
204
|
} catch (error) {
|
|
189
205
|
return { src, dest, success: false, error };
|
|
206
|
+
} finally {
|
|
207
|
+
if (compiler) {
|
|
208
|
+
try {
|
|
209
|
+
await compiler.dispose();
|
|
210
|
+
} catch {
|
|
211
|
+
// Disposal errors are not actionable; compiler is going away.
|
|
212
|
+
}
|
|
213
|
+
}
|
|
190
214
|
}
|
|
191
215
|
}
|
|
192
216
|
|
|
@@ -198,7 +222,11 @@ async function compileFile(src, dest, options = {}) {
|
|
|
198
222
|
*/
|
|
199
223
|
async function compileSass(config, options = {}) {
|
|
200
224
|
const {
|
|
201
|
-
|
|
225
|
+
// Serial by default. compileFile() now spawns an isolated dart-sass
|
|
226
|
+
// compiler per file so concurrency wouldn't actually share state, but
|
|
227
|
+
// running serial gives us deterministic output ordering and bounded
|
|
228
|
+
// memory use. --parallel in cli.js still bumps this to 4 if needed.
|
|
229
|
+
maxConcurrency = 1,
|
|
202
230
|
verbose = false,
|
|
203
231
|
} = options;
|
|
204
232
|
|
package/package.json
CHANGED