anypack-plugin-serve 0.1.0-alpha.2 → 0.1.0-beta.1
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/client.js +3 -3
- package/lib/client/client.js +5 -5
- package/lib/client/log.js +1 -1
- package/lib/client/overlays/status.js +1 -1
- package/lib/errors.js +5 -5
- package/lib/helpers.js +12 -13
- package/lib/index.js +13 -39
- package/lib/plugins/hmr.js +3 -10
- package/lib/plugins/ramdisk.js +2 -3
- package/lib/plugins/ramdisk_lib.js +0 -12
- package/lib/ws.js +1 -1
- package/package.json +9 -7
package/client.js
CHANGED
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
let options;
|
|
20
20
|
try {
|
|
21
21
|
options = ʎɐɹɔosǝʌɹǝs;
|
|
22
|
-
} catch (
|
|
22
|
+
} catch (_e) {
|
|
23
23
|
const { log } = require('./lib/client/log.js');
|
|
24
24
|
log.error(
|
|
25
|
-
'The entry for anypack-plugin-serve was included in your build, but it does not appear that the plugin was. Please check your configuration.'
|
|
25
|
+
'The entry for anypack-plugin-serve was included in your build, but it does not appear that the plugin was. Please check your configuration.',
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
try {
|
|
30
30
|
hash = __webpack_hash__;
|
|
31
|
-
} catch (
|
|
31
|
+
} catch (_e) {}
|
|
32
32
|
|
|
33
33
|
run(hash, options);
|
|
34
34
|
})();
|
package/lib/client/client.js
CHANGED
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
const run = (buildHash, options) => {
|
|
12
12
|
const { address, client = {}, hmr, progress, secure, status } = options;
|
|
13
13
|
|
|
14
|
-
options.firstInstance = !window.
|
|
14
|
+
options.firstInstance = !window.anypackPluginServe;
|
|
15
15
|
|
|
16
|
-
window.
|
|
16
|
+
window.anypackPluginServe = window.anypackPluginServe || {
|
|
17
17
|
compilers: {},
|
|
18
18
|
};
|
|
19
|
-
window.
|
|
19
|
+
window.anypackPluginServe.silent = !!client.silent;
|
|
20
20
|
|
|
21
21
|
const { ClientSocket } = require('./ClientSocket.js');
|
|
22
22
|
const { replace } = require('./hmr.js');
|
|
@@ -30,7 +30,7 @@ const run = (buildHash, options) => {
|
|
|
30
30
|
|
|
31
31
|
const { compilerName } = options;
|
|
32
32
|
|
|
33
|
-
window.
|
|
33
|
+
window.anypackPluginServe.compilers[compilerName] = {};
|
|
34
34
|
|
|
35
35
|
// prevents ECONNRESET errors on the server
|
|
36
36
|
window.addEventListener('beforeunload', () => socket.close());
|
|
@@ -42,7 +42,7 @@ const run = (buildHash, options) => {
|
|
|
42
42
|
const identifier = options.compilerName
|
|
43
43
|
? `(Compiler: ${options.compilerName}) `
|
|
44
44
|
: '';
|
|
45
|
-
const compiler = window.
|
|
45
|
+
const compiler = window.anypackPluginServe.compilers[compilerName];
|
|
46
46
|
const { wpsId } = data;
|
|
47
47
|
|
|
48
48
|
switch (action) {
|
package/lib/client/log.js
CHANGED
package/lib/errors.js
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
The above copyright notice and this permission notice shall be
|
|
9
9
|
included in all copies or substantial portions of this Source Code Form.
|
|
10
10
|
*/
|
|
11
|
-
class
|
|
11
|
+
class AnypackPluginServeError extends Error {
|
|
12
12
|
constructor(...args) {
|
|
13
13
|
super(...args);
|
|
14
|
-
this.name = '
|
|
14
|
+
this.name = 'AnypackPluginServeError';
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
class PluginExistsError extends
|
|
18
|
+
class PluginExistsError extends AnypackPluginServeError {
|
|
19
19
|
constructor(...args) {
|
|
20
20
|
super(...args);
|
|
21
21
|
this.name = 'PluginExistsError';
|
|
@@ -23,7 +23,7 @@ class PluginExistsError extends WebpackPluginServeError {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
class RamdiskPathError extends
|
|
26
|
+
class RamdiskPathError extends AnypackPluginServeError {
|
|
27
27
|
constructor(...args) {
|
|
28
28
|
super(...args);
|
|
29
29
|
this.name = 'RamdiskPathError';
|
|
@@ -34,5 +34,5 @@ class RamdiskPathError extends WebpackPluginServeError {
|
|
|
34
34
|
module.exports = {
|
|
35
35
|
PluginExistsError,
|
|
36
36
|
RamdiskPathError,
|
|
37
|
-
|
|
37
|
+
AnypackPluginServeError,
|
|
38
38
|
};
|
package/lib/helpers.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
function defer() {
|
|
2
|
+
/** @type {{ promise: Promise, resolve: () => {}, reject: () => {} }} */
|
|
3
|
+
const deferred = {};
|
|
4
|
+
|
|
5
|
+
deferred.promise = new Promise((resolve, reject) => {
|
|
6
|
+
deferred.resolve = resolve;
|
|
7
|
+
deferred.reject = reject;
|
|
8
|
+
});
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
deferred.reject = reject;
|
|
12
|
-
});
|
|
10
|
+
return deferred;
|
|
11
|
+
}
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
module.exports = {
|
|
14
|
+
defer,
|
|
16
15
|
};
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,6 @@ const colors = require('ansi-colors');
|
|
|
15
15
|
|
|
16
16
|
const globby = require('tinyglobby');
|
|
17
17
|
const { customAlphabet } = require('nanoid');
|
|
18
|
-
const { DefinePlugin, ProgressPlugin } = require('webpack');
|
|
19
18
|
|
|
20
19
|
const { init: initHmrPlugin } = require('./plugins/hmr');
|
|
21
20
|
const { init: initRamdiskPlugin } = require('./plugins/ramdisk');
|
|
@@ -45,13 +44,11 @@ const defaults = {
|
|
|
45
44
|
};
|
|
46
45
|
|
|
47
46
|
const key = 'anypack-plugin-serve';
|
|
48
|
-
const newline = () => console.log();
|
|
49
47
|
const nanoid = customAlphabet('1234567890abcdef', 7);
|
|
50
48
|
|
|
51
49
|
let instance = null;
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
class WebpackPluginServe extends EventEmitter {
|
|
51
|
+
class AnypackPluginServe extends EventEmitter {
|
|
55
52
|
constructor(opts = {}) {
|
|
56
53
|
super();
|
|
57
54
|
|
|
@@ -59,7 +56,7 @@ class WebpackPluginServe extends EventEmitter {
|
|
|
59
56
|
|
|
60
57
|
if (valid.error) {
|
|
61
58
|
forceError(
|
|
62
|
-
'An option was passed to
|
|
59
|
+
'An option was passed to AnypackPluginServe that is not valid',
|
|
63
60
|
);
|
|
64
61
|
throw valid.error;
|
|
65
62
|
}
|
|
@@ -92,22 +89,12 @@ class WebpackPluginServe extends EventEmitter {
|
|
|
92
89
|
// returns a promise
|
|
93
90
|
if (typeof options.host === 'string') {
|
|
94
91
|
const { host } = options;
|
|
95
|
-
options.host =
|
|
96
|
-
// biome-ignore lint/suspicious/noThenProperty: legacy
|
|
97
|
-
then(r) {
|
|
98
|
-
r(host);
|
|
99
|
-
},
|
|
100
|
-
};
|
|
92
|
+
options.host = Promise.resolve(host);
|
|
101
93
|
}
|
|
102
94
|
|
|
103
95
|
if (Number.isInteger(options.port)) {
|
|
104
96
|
const { port } = options;
|
|
105
|
-
options.port =
|
|
106
|
-
// biome-ignore lint/suspicious/noThenProperty: legacy
|
|
107
|
-
then(r) {
|
|
108
|
-
r(port);
|
|
109
|
-
},
|
|
110
|
-
};
|
|
97
|
+
options.port = Promise.resolve(port);
|
|
111
98
|
}
|
|
112
99
|
|
|
113
100
|
if (!options.static) {
|
|
@@ -231,25 +218,10 @@ class WebpackPluginServe extends EventEmitter {
|
|
|
231
218
|
});
|
|
232
219
|
}
|
|
233
220
|
|
|
234
|
-
compiler.hooks.compilation.tap(key, (compilation) => {
|
|
235
|
-
compilation.hooks.afterHash.tap(key, () => {
|
|
236
|
-
// webpack still has a 4 year old bug whereby in watch mode, file timestamps aren't properly
|
|
237
|
-
// accounted for, which will trigger multiple builds of the same hash.
|
|
238
|
-
// see: https://github.com/egoist/time-fix-plugin
|
|
239
|
-
/* istanbul ignore if */
|
|
240
|
-
if (this.lastHash === compilation.hash) {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
this.lastHash = compilation.hash;
|
|
244
|
-
this.emit('build', compiler.name, compiler);
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
221
|
watchRun.tapPromise(key, async () => {
|
|
249
222
|
if (!this.state.starting) {
|
|
250
223
|
// ensure we're only trying to start the server once
|
|
251
224
|
this.state.starting = start.bind(this)();
|
|
252
|
-
this.state.starting.then(() => newline());
|
|
253
225
|
}
|
|
254
226
|
|
|
255
227
|
// wait for the server to startup so we can get our client connection info from it
|
|
@@ -264,16 +236,18 @@ class WebpackPluginServe extends EventEmitter {
|
|
|
264
236
|
|
|
265
237
|
const defineObject = Object.assign({}, this.options, compilerData);
|
|
266
238
|
const defineData = { ʎɐɹɔosǝʌɹǝs: JSON.stringify(defineObject) };
|
|
267
|
-
const definePlugin = new DefinePlugin(defineData);
|
|
239
|
+
const definePlugin = new compiler.webpack.DefinePlugin(defineData);
|
|
268
240
|
|
|
269
241
|
definePlugin.apply(compiler);
|
|
270
242
|
|
|
271
243
|
if (this.options.progress) {
|
|
272
|
-
const progressPlugin = new ProgressPlugin(
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
244
|
+
const progressPlugin = new compiler.webpack.ProgressPlugin(
|
|
245
|
+
(percent, message, misc) => {
|
|
246
|
+
// pass the data onto the client raw. connected sockets may want to interpret the data
|
|
247
|
+
// differently
|
|
248
|
+
this.emit('progress', { percent, message, misc }, compiler);
|
|
249
|
+
},
|
|
250
|
+
);
|
|
277
251
|
|
|
278
252
|
progressPlugin.apply(compiler);
|
|
279
253
|
}
|
|
@@ -281,4 +255,4 @@ class WebpackPluginServe extends EventEmitter {
|
|
|
281
255
|
}
|
|
282
256
|
}
|
|
283
257
|
|
|
284
|
-
module.exports = { defaults,
|
|
258
|
+
module.exports = { defaults, AnypackPluginServe };
|
package/lib/plugins/hmr.js
CHANGED
|
@@ -8,29 +8,22 @@
|
|
|
8
8
|
The above copyright notice and this permission notice shall be
|
|
9
9
|
included in all copies or substantial portions of this Source Code Form.
|
|
10
10
|
*/
|
|
11
|
-
const { HotModuleReplacementPlugin, version } = require('webpack');
|
|
12
|
-
|
|
13
|
-
const { getMajorVersion } = require('../helpers');
|
|
14
11
|
|
|
15
12
|
const { PluginExistsError } = require('../errors');
|
|
16
13
|
|
|
17
14
|
const addPlugin = (compiler) => {
|
|
18
|
-
const hmrPlugin = new HotModuleReplacementPlugin();
|
|
15
|
+
const hmrPlugin = new compiler.webpack.HotModuleReplacementPlugin();
|
|
19
16
|
hmrPlugin.apply(compiler);
|
|
20
17
|
};
|
|
21
18
|
|
|
22
19
|
const init = function init(compiler, log) {
|
|
23
|
-
const webpackMajorVersion = getMajorVersion(version);
|
|
24
20
|
compiler.options.output = Object.assign(compiler.options.output, {
|
|
25
21
|
hotUpdateChunkFilename: `${compiler.wpsId}-[id]-wps-hmr.js`,
|
|
26
|
-
hotUpdateMainFilename:
|
|
27
|
-
webpackMajorVersion >= 5
|
|
28
|
-
? `[runtime]-${compiler.wpsId}-wps-hmr.json`
|
|
29
|
-
: `${compiler.wpsId}-wps-hmr.json`,
|
|
22
|
+
hotUpdateMainFilename: `[runtime]-${compiler.wpsId}-wps-hmr.json`,
|
|
30
23
|
});
|
|
31
24
|
|
|
32
25
|
const hasHMRPlugin = compiler.options.plugins.some(
|
|
33
|
-
(plugin) => plugin instanceof HotModuleReplacementPlugin,
|
|
26
|
+
(plugin) => plugin instanceof compiler.webpack.HotModuleReplacementPlugin,
|
|
34
27
|
);
|
|
35
28
|
|
|
36
29
|
/* istanbul ignore else */
|
package/lib/plugins/ramdisk.js
CHANGED
|
@@ -85,14 +85,13 @@ module.exports = {
|
|
|
85
85
|
: defaultOptions,
|
|
86
86
|
);
|
|
87
87
|
|
|
88
|
+
compiler.hooks.shutdown.tap('clean-ramdisk', () => plugin.cleanup());
|
|
89
|
+
|
|
88
90
|
if (
|
|
89
91
|
fs.lstatSync(path, { throwIfNoEntry: false }) ||
|
|
90
92
|
fs.statSync(path, { throwIfNoEntry: false })
|
|
91
93
|
) {
|
|
92
|
-
console.log('Removing', path);
|
|
93
94
|
fs.rmSync(path, { recursive: true });
|
|
94
|
-
} else {
|
|
95
|
-
console.log('Path does not exist', path);
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
const ramdiskPath = join(plugin.diskPath, newPath);
|
|
@@ -125,18 +125,6 @@ class Ramdisk {
|
|
|
125
125
|
);
|
|
126
126
|
this.commands?.mount(this.options);
|
|
127
127
|
}
|
|
128
|
-
|
|
129
|
-
process.on('SIGINT', () => {
|
|
130
|
-
this.cleanup();
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
process.on('SIGTERM', () => {
|
|
134
|
-
this.cleanup();
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
process.on('exit', () => {
|
|
138
|
-
this.cleanup();
|
|
139
|
-
});
|
|
140
128
|
}
|
|
141
129
|
|
|
142
130
|
get diskPath() {
|
package/lib/ws.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
The above copyright notice and this permission notice shall be
|
|
9
9
|
included in all copies or substantial portions of this Source Code Form.
|
|
10
10
|
*/
|
|
11
|
-
const defer = require('./helpers.js')
|
|
11
|
+
const { defer } = require('./helpers.js');
|
|
12
12
|
const WebSocket = require('ws');
|
|
13
13
|
|
|
14
14
|
const socketServer = new WebSocket.Server({ noServer: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anypack-plugin-serve",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
4
|
"description": "A Development Server in a Webpack Plugin",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"repository": "onigoetz/anypack-plugin-serve",
|
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
"dev": "npm run dev:clean && node ../node_modules/webpack-nano/bin/wp --config test/fixtures/simple/webpack.config.js",
|
|
17
17
|
"dev:clean": "del test/fixtures/multi/output/* test/fixtures/simple/output/*",
|
|
18
18
|
"dev:multi": "npm run dev:clean && ../node node_modules/webpack-nano/bin/wp --config test/fixtures/multi/webpack.config.js",
|
|
19
|
-
"test": "rstest"
|
|
19
|
+
"test": "rstest",
|
|
20
|
+
"format": "biome format",
|
|
21
|
+
"lint": "biome check --write",
|
|
22
|
+
"ci:lint": "biome check"
|
|
20
23
|
},
|
|
21
24
|
"files": [
|
|
22
25
|
"client.js",
|
|
@@ -32,7 +35,7 @@
|
|
|
32
35
|
"ansi-colors": "^4.1.3",
|
|
33
36
|
"connect-history-api-fallback": "^2.0.0",
|
|
34
37
|
"empathic": "^2.0.0",
|
|
35
|
-
"http-proxy-middleware": "^
|
|
38
|
+
"http-proxy-middleware": "^3.0.5",
|
|
36
39
|
"json-stringify-safe": "^5.0.1",
|
|
37
40
|
"nanoid": "^5.1.6",
|
|
38
41
|
"onetime": "^7.0.0",
|
|
@@ -44,12 +47,11 @@
|
|
|
44
47
|
"ws": "^8.18.3"
|
|
45
48
|
},
|
|
46
49
|
"devDependencies": {
|
|
47
|
-
"@
|
|
48
|
-
"@rstest/
|
|
50
|
+
"@biomejs/biome": "2.3.11",
|
|
51
|
+
"@rstest/core": "^0.7.7",
|
|
52
|
+
"@rstest/coverage-istanbul": "^0.1.4",
|
|
49
53
|
"del-cli": "7.0.0",
|
|
50
|
-
"execa": "^9.0.0",
|
|
51
54
|
"get-port": "^7.1.0",
|
|
52
|
-
"line-by-line": "^0.1.6",
|
|
53
55
|
"node-fetch": "^3.3.2",
|
|
54
56
|
"puppeteer": "^24.34.0",
|
|
55
57
|
"random-js": "^2.1.0",
|