elm-webpack-loader 8.0.3 → 9.0.0
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/.travis.yml +5 -5
- package/CHANGELOG.md +12 -0
- package/README.md +94 -4
- package/example/package-lock.json +3686 -3724
- package/example/package.json +6 -7
- package/example/webpack.config.js +5 -2
- package/index.js +43 -7
- package/package.json +7 -4
- package/test/loader.js +79 -0
package/example/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "elm-
|
|
2
|
+
"name": "elm-webpack-loader-example",
|
|
3
3
|
"version": "0.0.1",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"private": true,
|
|
@@ -7,14 +7,13 @@
|
|
|
7
7
|
"build": "webpack --mode production",
|
|
8
8
|
"watch": "webpack --mode development --watch",
|
|
9
9
|
"dev": "webpack serve --mode development --port 3000",
|
|
10
|
-
"errors": "webpack --mode development --
|
|
10
|
+
"errors": "webpack --mode development --stats verbose"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"file-loader": "
|
|
15
|
-
"
|
|
16
|
-
"webpack": "^
|
|
17
|
-
"webpack-
|
|
18
|
-
"webpack-dev-server": "^3.11.0"
|
|
14
|
+
"file-loader": "6.2.0",
|
|
15
|
+
"webpack": "^5.112.2",
|
|
16
|
+
"webpack-cli": "^7.3.1",
|
|
17
|
+
"webpack-dev-server": "^6.1.0"
|
|
19
18
|
}
|
|
20
19
|
}
|
package/index.js
CHANGED
|
@@ -6,7 +6,8 @@ var temp = require("temp").track();
|
|
|
6
6
|
var loaderUtils = require("loader-utils");
|
|
7
7
|
var elmCompiler = require("node-elm-compiler");
|
|
8
8
|
|
|
9
|
-
var compilerQueue =
|
|
9
|
+
var compilerQueue = [];
|
|
10
|
+
var runningInstances = 0;
|
|
10
11
|
|
|
11
12
|
var getFiles = function(options) {
|
|
12
13
|
var files = options && options.files;
|
|
@@ -81,6 +82,14 @@ module.exports = function() {
|
|
|
81
82
|
var files = getFiles.call(this, options);
|
|
82
83
|
var resourcePath = this.resourcePath;
|
|
83
84
|
|
|
85
|
+
var maxInstances = options.maxInstances;
|
|
86
|
+
if (typeof maxInstances === "undefined") {
|
|
87
|
+
maxInstances = 1;
|
|
88
|
+
} else if (!Number.isInteger(maxInstances) || maxInstances < 1) {
|
|
89
|
+
throw new Error("maxInstances option must be a positive integer");
|
|
90
|
+
}
|
|
91
|
+
delete options.maxInstances;
|
|
92
|
+
|
|
84
93
|
var promises = [];
|
|
85
94
|
var cache = compiler.options.cache;
|
|
86
95
|
var trackDependencies = compiler.watching ||
|
|
@@ -102,7 +111,7 @@ module.exports = function() {
|
|
|
102
111
|
promises.push(dependencies);
|
|
103
112
|
}
|
|
104
113
|
|
|
105
|
-
var compilation = compileInQueue(files, options)
|
|
114
|
+
var compilation = compileInQueue(files, options, maxInstances)
|
|
106
115
|
.then(function(v) { return { kind: "success", result: v }; })
|
|
107
116
|
.catch(function(v) { return { kind: "error", error: v }; });
|
|
108
117
|
|
|
@@ -129,13 +138,40 @@ module.exports = function() {
|
|
|
129
138
|
}
|
|
130
139
|
|
|
131
140
|
|
|
132
|
-
function compileInQueue(sources, options) {
|
|
133
|
-
|
|
134
|
-
|
|
141
|
+
function compileInQueue(sources, options, maxInstances) {
|
|
142
|
+
return new Promise(function(resolve, reject) {
|
|
143
|
+
compilerQueue.push({
|
|
144
|
+
sources: sources,
|
|
145
|
+
options: options,
|
|
146
|
+
maxInstances: maxInstances,
|
|
147
|
+
resolve: resolve,
|
|
148
|
+
reject: reject
|
|
149
|
+
});
|
|
150
|
+
runCompilerQueue();
|
|
135
151
|
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function runCompilerQueue() {
|
|
155
|
+
while (compilerQueue.length > 0) {
|
|
156
|
+
var next = compilerQueue[0];
|
|
157
|
+
if (runningInstances >= next.maxInstances) return;
|
|
136
158
|
|
|
137
|
-
|
|
138
|
-
|
|
159
|
+
compilerQueue.shift();
|
|
160
|
+
startCompilation(next);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function startCompilation(job) {
|
|
165
|
+
runningInstances += 1;
|
|
166
|
+
compile(job.sources, job.options).then(function(result) {
|
|
167
|
+
runningInstances -= 1;
|
|
168
|
+
job.resolve(result);
|
|
169
|
+
runCompilerQueue();
|
|
170
|
+
}, function(error) {
|
|
171
|
+
runningInstances -= 1;
|
|
172
|
+
job.reject(error);
|
|
173
|
+
runCompilerQueue();
|
|
174
|
+
});
|
|
139
175
|
}
|
|
140
176
|
|
|
141
177
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elm-webpack-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "Webpack loader for the Elm programming language.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "mocha test/*.js"
|
|
8
8
|
},
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": ">=
|
|
10
|
+
"node": ">=22.15.0"
|
|
11
|
+
},
|
|
12
|
+
"overrides": {
|
|
13
|
+
"cross-spawn": "6.0.6"
|
|
11
14
|
},
|
|
12
15
|
"repository": {
|
|
13
16
|
"type": "git",
|
|
@@ -30,8 +33,8 @@
|
|
|
30
33
|
"temp": "^0.9.4"
|
|
31
34
|
},
|
|
32
35
|
"devDependencies": {
|
|
33
|
-
"chai": "^3.
|
|
34
|
-
"mocha": "^
|
|
36
|
+
"chai": "^6.3.0",
|
|
37
|
+
"mocha": "^12.0.3"
|
|
35
38
|
},
|
|
36
39
|
"optionalDependencies": {
|
|
37
40
|
"elm": "^0.19.3-0 || ^0.19.2-0 || ^0.19.1-3 <0.19.1 || 0.19.0-no-deps"
|
package/test/loader.js
CHANGED
|
@@ -336,6 +336,15 @@ describe('async mode', function () {
|
|
|
336
336
|
loader.call(context, badSource);
|
|
337
337
|
});
|
|
338
338
|
|
|
339
|
+
it('requires maxInstances to be a positive integer', function () {
|
|
340
|
+
[0, -1, 1.5, '1'].forEach(function (maxInstances) {
|
|
341
|
+
context = mock(goodSource, null, { cwd: fixturesDir, maxInstances: maxInstances }, function () {});
|
|
342
|
+
assert.throw(function () {
|
|
343
|
+
loader.call(context, goodSource);
|
|
344
|
+
}, /maxInstances option must be a positive integer/);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
339
348
|
it('serializes compiler processes and continues after errors', function (done) {
|
|
340
349
|
this.timeout(2000);
|
|
341
350
|
|
|
@@ -421,4 +430,74 @@ describe('async mode', function () {
|
|
|
421
430
|
}));
|
|
422
431
|
});
|
|
423
432
|
|
|
433
|
+
it('allows concurrent compiler processes up to maxInstances', function (done) {
|
|
434
|
+
this.timeout(2000);
|
|
435
|
+
|
|
436
|
+
var originalCompile = compiler.compile;
|
|
437
|
+
var processes = [];
|
|
438
|
+
var active = 0;
|
|
439
|
+
var maxActive = 0;
|
|
440
|
+
var callbacks = [];
|
|
441
|
+
var finished = false;
|
|
442
|
+
|
|
443
|
+
var finish = function (err) {
|
|
444
|
+
if (finished) return;
|
|
445
|
+
finished = true;
|
|
446
|
+
compiler.compile = originalCompile;
|
|
447
|
+
done(err);
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
var complete = function (label, err, result) {
|
|
451
|
+
try {
|
|
452
|
+
assert.isNull(err);
|
|
453
|
+
assert.equal(result, label);
|
|
454
|
+
callbacks.push(label);
|
|
455
|
+
if (callbacks.length === 3) {
|
|
456
|
+
assert.deepEqual(callbacks.sort(), ['first', 'second', 'third']);
|
|
457
|
+
assert.lengthOf(processes, 3);
|
|
458
|
+
assert.equal(maxActive, 2);
|
|
459
|
+
finish();
|
|
460
|
+
}
|
|
461
|
+
} catch (assertionError) {
|
|
462
|
+
finish(assertionError);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
compiler.compile = function (sources, options) {
|
|
467
|
+
var child = new EventEmitter();
|
|
468
|
+
child.stderr = new EventEmitter();
|
|
469
|
+
child.options = options;
|
|
470
|
+
var index = processes.length;
|
|
471
|
+
processes.push(child);
|
|
472
|
+
active += 1;
|
|
473
|
+
maxActive = Math.max(maxActive, active);
|
|
474
|
+
child.on('close', function () { active -= 1; });
|
|
475
|
+
|
|
476
|
+
try {
|
|
477
|
+
assert.isUndefined(options.maxInstances);
|
|
478
|
+
if (index === 1) {
|
|
479
|
+
fs.writeFileSync(processes[0].options.output, 'first');
|
|
480
|
+
process.nextTick(function () { processes[0].emit('close', 0); });
|
|
481
|
+
} else if (index === 2) {
|
|
482
|
+
fs.writeFileSync(processes[1].options.output, 'second');
|
|
483
|
+
fs.writeFileSync(processes[2].options.output, 'third');
|
|
484
|
+
process.nextTick(function () {
|
|
485
|
+
processes[1].emit('close', 0);
|
|
486
|
+
processes[2].emit('close', 0);
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
} catch (assertionError) {
|
|
490
|
+
finish(assertionError);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return child;
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
['first', 'second', 'third'].forEach(function (label) {
|
|
497
|
+
loader.call(mock(goodSource, null, { cwd: fixturesDir, maxInstances: 2 }, function (err, result) {
|
|
498
|
+
complete(label, err, result);
|
|
499
|
+
}));
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
|
|
424
503
|
});
|