extension-develop 3.15.1 → 3.16.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/dist/0~branding.mjs +26 -0
- package/dist/0~dev-server.mjs +488 -0
- package/dist/0~rslib-runtime.mjs +40 -0
- package/dist/0~rspack-config.mjs +8648 -0
- package/dist/0~stats-handler.mjs +25 -0
- package/dist/0~zip.mjs +34 -0
- package/dist/314.mjs +35 -0
- package/dist/526.mjs +23 -0
- package/dist/946.mjs +1670 -0
- package/dist/962.mjs +1389 -0
- package/dist/ensure-hmr-for-scripts.js +12 -56
- package/dist/{ensure-hmr-for-scripts.cjs → ensure-hmr-for-scripts.mjs} +12 -56
- package/dist/feature-scripts-content-script-wrapper.js +23 -98
- package/dist/{feature-scripts-content-script-wrapper.cjs → feature-scripts-content-script-wrapper.mjs} +23 -98
- package/dist/main-world-bridge.js +0 -18
- package/dist/{main-world-bridge.cjs → main-world-bridge.mjs} +0 -18
- package/dist/minimum-chromium-file.js +0 -5
- package/dist/minimum-chromium-file.mjs +5 -0
- package/dist/minimum-firefox-file.js +0 -5
- package/dist/minimum-firefox-file.mjs +5 -0
- package/dist/minimum-script-file.js +0 -18
- package/dist/{minimum-script-file.cjs → minimum-script-file.mjs} +0 -18
- package/dist/module.mjs +3 -0
- package/dist/package.json +1 -1
- package/dist/preact-refresh-shim.mjs +7 -0
- package/dist/preview.mjs +2 -0
- package/dist/resolve-paths-loader.js +1043 -1093
- package/dist/resolve-paths-loader.mjs +1300 -0
- package/package.json +8 -8
- package/dist/221.cjs +0 -513
- package/dist/442.cjs +0 -9226
- package/dist/504.cjs +0 -65
- package/dist/787.cjs +0 -44
- package/dist/minimum-chromium-file.cjs +0 -10
- package/dist/minimum-firefox-file.cjs +0 -10
- package/dist/module.cjs +0 -3479
- package/dist/preact-refresh-shim.cjs +0 -25
- package/dist/preview.cjs +0 -1464
- package/dist/resolve-paths-loader.cjs +0 -1350
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
|
|
2
|
+
function scrubBrand(txt, brand = 'Extension.js') {
|
|
3
|
+
if (!txt) return txt;
|
|
4
|
+
const safeBrand = brand.replace(/\$/g, '$$$$');
|
|
5
|
+
const preserved = [];
|
|
6
|
+
const preserve = (value)=>{
|
|
7
|
+
const token = `__EXT_BRAND_PRESERVE_${preserved.length}__`;
|
|
8
|
+
preserved.push(value);
|
|
9
|
+
return token;
|
|
10
|
+
};
|
|
11
|
+
let output = txt.replace(/\bRspack\b(?=\s+performance recommendations:)/gi, preserve).replace(/https?:\/\/rspack\.(?:rs|dev)\/[^\s)]+/gi, preserve).replace(/(?<!@)\bRspack\b/gi, safeBrand).replace(/(?<!@)\bWebpack\b/gi, safeBrand).replace(/(?<!@)\bwebpack-dev-server\b/gi, `${safeBrand} dev server`).replace(/(?<!@)\bRspackDevServer\b/gi, `${safeBrand} dev server`).replace(/ModuleBuildError:\s*/g, '').replace(/ModuleParseError:\s*/g, '').replace(/Error:\s*Module\s+build\s+failed.*?\n/gi, '').replace(/\n{3,}/g, '\n\n').replace(/\n{2}(?=WARNING in )/g, '\n');
|
|
12
|
+
preserved.forEach((value, index)=>{
|
|
13
|
+
output = output.replace(`__EXT_BRAND_PRESERVE_${index}__`, value);
|
|
14
|
+
});
|
|
15
|
+
return output;
|
|
16
|
+
}
|
|
17
|
+
function makeSanitizedConsole(brand = 'Extension.js') {
|
|
18
|
+
const sanitize = (a)=>'string' == typeof a ? scrubBrand(a, brand) : a;
|
|
19
|
+
return {
|
|
20
|
+
log: (...args)=>console.log(...args.map(sanitize)),
|
|
21
|
+
info: (...args)=>console.info(...args.map(sanitize)),
|
|
22
|
+
warn: (...args)=>console.warn(...args.map(sanitize)),
|
|
23
|
+
error: (...args)=>console.error(...args.map(sanitize))
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export { makeSanitizedConsole, scrubBrand };
|
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import { Writable } from "stream";
|
|
4
|
+
import { rspack } from "@rspack/core";
|
|
5
|
+
import { RspackDevServer } from "@rspack/dev-server";
|
|
6
|
+
import { merge } from "webpack-merge";
|
|
7
|
+
import { createPlaywrightMetadataWriter, autoExitModeEnabled, autoExitForceKill, loadCommandConfig, extensionJsRunnerError, portInUse, devServerStartTimeout, autoExitTriggered, loadCustomConfig, loadBrowserConfig, sanitize, resolveCompanionExtensionsConfig, getSpecialFoldersDataForProjectRoot } from "./946.mjs";
|
|
8
|
+
import { setupNoBrowserBannerOnFirstDone, webpackConfig, setupCompilerLifecycleHooks } from "./0~rspack-config.mjs";
|
|
9
|
+
import * as __rspack_external_path from "path";
|
|
10
|
+
import * as __rspack_external_crypto from "crypto";
|
|
11
|
+
import * as __rspack_external_net from "net";
|
|
12
|
+
import * as __rspack_external_fs from "fs";
|
|
13
|
+
async function findAvailablePortNear(startPort, maxAttempts = 20, host = '127.0.0.1') {
|
|
14
|
+
if (0 === startPort) return new Promise((resolve, reject)=>{
|
|
15
|
+
const server = __rspack_external_net.createServer();
|
|
16
|
+
server.once('error', (err)=>reject(err));
|
|
17
|
+
server.once('listening', ()=>{
|
|
18
|
+
const addr = server.address();
|
|
19
|
+
server.close(()=>resolve(addr.port));
|
|
20
|
+
});
|
|
21
|
+
server.listen(0, host);
|
|
22
|
+
});
|
|
23
|
+
function tryPort(port) {
|
|
24
|
+
return new Promise((resolve)=>{
|
|
25
|
+
const server = __rspack_external_net.createServer();
|
|
26
|
+
server.once('error', ()=>resolve(false));
|
|
27
|
+
server.once('listening', ()=>{
|
|
28
|
+
server.close(()=>resolve(true));
|
|
29
|
+
});
|
|
30
|
+
server.listen(port, host);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
let candidate = startPort;
|
|
34
|
+
for(let i = 0; i < maxAttempts; i++){
|
|
35
|
+
const ok = await tryPort(candidate);
|
|
36
|
+
if (ok) return candidate;
|
|
37
|
+
candidate += 1;
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Could not find an available port near ${startPort} after ${maxAttempts} attempts`);
|
|
40
|
+
}
|
|
41
|
+
function resolveInstanceIdOverride() {
|
|
42
|
+
const raw = process.env.EXTENSION_INSTANCE_ID || process.env.EXTENSION_DEV_INSTANCE_ID || process.env.EXTJS_INSTANCE_ID || '';
|
|
43
|
+
const value = String(raw).trim();
|
|
44
|
+
if (!value) return;
|
|
45
|
+
return value.replace(/[^a-zA-Z0-9_-]/g, '-').slice(0, 64) || void 0;
|
|
46
|
+
}
|
|
47
|
+
class PortManager {
|
|
48
|
+
basePort;
|
|
49
|
+
currentInstance = null;
|
|
50
|
+
constructor(_browser, _projectPath, basePort = 8080){
|
|
51
|
+
this.basePort = basePort;
|
|
52
|
+
}
|
|
53
|
+
async allocatePorts(_browser, _projectPath, requestedPort) {
|
|
54
|
+
try {
|
|
55
|
+
const isValidRequested = 'number' == typeof requestedPort && requestedPort >= 0 && requestedPort < 65536;
|
|
56
|
+
const base = isValidRequested ? requestedPort : this.basePort;
|
|
57
|
+
const port = await findAvailablePortNear(base);
|
|
58
|
+
const webSocketPort = await findAvailablePortNear(port + 1);
|
|
59
|
+
const instanceId = resolveInstanceIdOverride() || __rspack_external_crypto.randomBytes(8).toString('hex');
|
|
60
|
+
this.currentInstance = {
|
|
61
|
+
instanceId,
|
|
62
|
+
port,
|
|
63
|
+
webSocketPort
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
port,
|
|
67
|
+
webSocketPort,
|
|
68
|
+
instanceId
|
|
69
|
+
};
|
|
70
|
+
} catch (error) {
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
getCurrentInstance() {
|
|
75
|
+
return this.currentInstance;
|
|
76
|
+
}
|
|
77
|
+
async updateExtensionId(extensionId) {
|
|
78
|
+
if (this.currentInstance) this.currentInstance.extensionId = extensionId;
|
|
79
|
+
}
|
|
80
|
+
async terminateCurrentInstance() {
|
|
81
|
+
this.currentInstance = null;
|
|
82
|
+
}
|
|
83
|
+
getPortInfo(allocation) {
|
|
84
|
+
return `Port: ${allocation.port}, WebSocket: ${allocation.webSocketPort}, Instance: ${allocation.instanceId.slice(0, 8)}`;
|
|
85
|
+
}
|
|
86
|
+
async isPortInUse(port) {
|
|
87
|
+
return new Promise((resolve)=>{
|
|
88
|
+
const server = __rspack_external_net.createServer();
|
|
89
|
+
server.once('error', ()=>resolve(true));
|
|
90
|
+
server.once('listening', ()=>{
|
|
91
|
+
server.close(()=>resolve(false));
|
|
92
|
+
});
|
|
93
|
+
server.listen(port, '127.0.0.1');
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async getRunningInstances() {
|
|
97
|
+
return this.currentInstance ? [
|
|
98
|
+
this.currentInstance
|
|
99
|
+
] : [];
|
|
100
|
+
}
|
|
101
|
+
async getStats() {
|
|
102
|
+
return {
|
|
103
|
+
total: this.currentInstance ? 1 : 0,
|
|
104
|
+
running: this.currentInstance ? 1 : 0,
|
|
105
|
+
terminated: 0,
|
|
106
|
+
error: 0
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function hasDependency(projectPath, dependency) {
|
|
111
|
+
const findNearestPackageJsonDirectory = (startPath)=>{
|
|
112
|
+
let currentDirectory = startPath;
|
|
113
|
+
const maxDepth = 4;
|
|
114
|
+
for(let i = 0; i < maxDepth; i++){
|
|
115
|
+
const candidate = __rspack_external_path.join(currentDirectory, 'package.json');
|
|
116
|
+
if (__rspack_external_fs.existsSync(candidate)) return currentDirectory;
|
|
117
|
+
const parentDirectory = __rspack_external_path.dirname(currentDirectory);
|
|
118
|
+
if (parentDirectory === currentDirectory) break;
|
|
119
|
+
currentDirectory = parentDirectory;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const packageJsonDirectory = findNearestPackageJsonDirectory(projectPath);
|
|
123
|
+
if (!packageJsonDirectory) return false;
|
|
124
|
+
const packageJsonPath = __rspack_external_path.join(packageJsonDirectory, 'package.json');
|
|
125
|
+
if (!__rspack_external_fs.existsSync(packageJsonPath)) return false;
|
|
126
|
+
const packageJson = JSON.parse(__rspack_external_fs.readFileSync(packageJsonPath, 'utf8'));
|
|
127
|
+
const dependencies = packageJson.dependencies || {};
|
|
128
|
+
const devDependencies = packageJson.devDependencies || {};
|
|
129
|
+
return !!dependencies[dependency] || !!devDependencies[dependency];
|
|
130
|
+
}
|
|
131
|
+
function isUsingJSFramework(projectPath) {
|
|
132
|
+
const frameworks = [
|
|
133
|
+
'react',
|
|
134
|
+
'vue',
|
|
135
|
+
'@angular/core',
|
|
136
|
+
'svelte',
|
|
137
|
+
'solid-js',
|
|
138
|
+
'preact'
|
|
139
|
+
];
|
|
140
|
+
return frameworks.some((fw)=>hasDependency(projectPath, fw));
|
|
141
|
+
}
|
|
142
|
+
function parseMilliseconds(value) {
|
|
143
|
+
if ('number' == typeof value) return Number.isFinite(value) && value > 0 ? value : null;
|
|
144
|
+
if ('string' == typeof value) {
|
|
145
|
+
const parsed = parseInt(value, 10);
|
|
146
|
+
return !Number.isNaN(parsed) && parsed > 0 ? parsed : null;
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
function setupAutoExit(autoExitMsRaw, forceKillMsRaw, onCleanup) {
|
|
151
|
+
let autoExitTimer = null;
|
|
152
|
+
let forceKillTimer = null;
|
|
153
|
+
const autoExitMs = parseMilliseconds(autoExitMsRaw);
|
|
154
|
+
if (null === autoExitMs) return ()=>{};
|
|
155
|
+
try {
|
|
156
|
+
console.log(autoExitModeEnabled(autoExitMs));
|
|
157
|
+
} catch {}
|
|
158
|
+
autoExitTimer = setTimeout(async ()=>{
|
|
159
|
+
try {
|
|
160
|
+
console.log(autoExitTriggered(autoExitMs));
|
|
161
|
+
} catch {}
|
|
162
|
+
await onCleanup();
|
|
163
|
+
}, autoExitMs);
|
|
164
|
+
const parsedForceKillMs = parseMilliseconds(forceKillMsRaw);
|
|
165
|
+
const forceKillMs = null !== parsedForceKillMs && parsedForceKillMs > 0 ? parsedForceKillMs : autoExitMs + 4000;
|
|
166
|
+
forceKillTimer = setTimeout(()=>{
|
|
167
|
+
try {
|
|
168
|
+
console.log(autoExitForceKill(forceKillMs));
|
|
169
|
+
} catch {}
|
|
170
|
+
process.exit(0);
|
|
171
|
+
}, forceKillMs);
|
|
172
|
+
function cancelAutoExitTimers() {
|
|
173
|
+
if (null !== autoExitTimer) {
|
|
174
|
+
clearTimeout(autoExitTimer);
|
|
175
|
+
autoExitTimer = null;
|
|
176
|
+
}
|
|
177
|
+
if (null !== forceKillTimer) {
|
|
178
|
+
clearTimeout(forceKillTimer);
|
|
179
|
+
forceKillTimer = null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return cancelAutoExitTimers;
|
|
183
|
+
}
|
|
184
|
+
function closeAll(devServer, portManager) {
|
|
185
|
+
return devServer.stop().then(async ()=>{
|
|
186
|
+
await portManager.terminateCurrentInstance();
|
|
187
|
+
setTimeout(()=>process.exit(), 500);
|
|
188
|
+
}).catch(async (error)=>{
|
|
189
|
+
console.log(extensionJsRunnerError(error));
|
|
190
|
+
await portManager.terminateCurrentInstance();
|
|
191
|
+
setTimeout(()=>process.exit(1), 500);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function setupCleanupHandlers(devServer, portManager) {
|
|
195
|
+
let isShuttingDown = false;
|
|
196
|
+
const cleanup = async ()=>{
|
|
197
|
+
if (isShuttingDown) return;
|
|
198
|
+
isShuttingDown = true;
|
|
199
|
+
try {
|
|
200
|
+
await closeAll(devServer, portManager);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
console.error('[Extension.js Runner] Error during cleanup.', error);
|
|
203
|
+
process.exit(1);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
process.on('uncaughtException', async (error)=>{
|
|
207
|
+
console.error('[Extension.js Runner] Uncaught exception.', error);
|
|
208
|
+
await cleanup();
|
|
209
|
+
});
|
|
210
|
+
process.on('unhandledRejection', async (reason, promise)=>{
|
|
211
|
+
console.error('[Extension.js Runner] Unhandled rejection.', promise, reason);
|
|
212
|
+
await cleanup();
|
|
213
|
+
});
|
|
214
|
+
const cancelAutoExit = setupAutoExit(process.env.EXTENSION_AUTO_EXIT_MS, process.env.EXTENSION_FORCE_KILL_MS, cleanup);
|
|
215
|
+
const cancelAndCleanup = async ()=>{
|
|
216
|
+
try {
|
|
217
|
+
cancelAutoExit();
|
|
218
|
+
} catch {}
|
|
219
|
+
await cleanup();
|
|
220
|
+
};
|
|
221
|
+
process.on('ERROR', cancelAndCleanup);
|
|
222
|
+
process.on('SIGINT', cancelAndCleanup);
|
|
223
|
+
process.on('SIGTERM', cancelAndCleanup);
|
|
224
|
+
process.on('SIGHUP', cancelAndCleanup);
|
|
225
|
+
return cancelAutoExit;
|
|
226
|
+
}
|
|
227
|
+
function shouldWriteAssetToDisk(filePath) {
|
|
228
|
+
return !/(?:^|[/\\])manifest\.json$/i.test(filePath);
|
|
229
|
+
}
|
|
230
|
+
function isSamePath(left, right) {
|
|
231
|
+
return __rspack_external_path.resolve(left) === __rspack_external_path.resolve(right);
|
|
232
|
+
}
|
|
233
|
+
function isManifestTempPath(filePath) {
|
|
234
|
+
const base = __rspack_external_path.basename(filePath);
|
|
235
|
+
return base.startsWith('.manifest.') && base.endsWith('.tmp');
|
|
236
|
+
}
|
|
237
|
+
function createDiscardWriteStream() {
|
|
238
|
+
const stream = new Writable({
|
|
239
|
+
write (_chunk, _encoding, callback) {
|
|
240
|
+
callback();
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
stream.on('finish', ()=>{
|
|
244
|
+
stream.emit('close');
|
|
245
|
+
});
|
|
246
|
+
process.nextTick(()=>{
|
|
247
|
+
stream.emit('open', 0);
|
|
248
|
+
});
|
|
249
|
+
return stream;
|
|
250
|
+
}
|
|
251
|
+
const guardedManifestDiskWritePaths = new Set();
|
|
252
|
+
let isManifestDiskWriteGuardInstalled = false;
|
|
253
|
+
function hasGuardedManifestDiskPath(filePath) {
|
|
254
|
+
if ('string' != typeof filePath) return false;
|
|
255
|
+
const resolvedPath = __rspack_external_path.resolve(filePath);
|
|
256
|
+
for (const guardedPath of guardedManifestDiskWritePaths)if (isSamePath(guardedPath, resolvedPath)) return true;
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
function suppressManifestOutputWrites(compiler, manifestOutputPath) {
|
|
260
|
+
const outputFileSystem = compiler?.outputFileSystem;
|
|
261
|
+
if (!outputFileSystem || outputFileSystem.__extensionjsManifestWriteGuard) return;
|
|
262
|
+
const isManifestPath = (filePath)=>'string' == typeof filePath && isSamePath(filePath, manifestOutputPath);
|
|
263
|
+
if ('function' == typeof outputFileSystem.writeFile) {
|
|
264
|
+
const originalWriteFile = outputFileSystem.writeFile.bind(outputFileSystem);
|
|
265
|
+
outputFileSystem.writeFile = (filePath, ...args)=>{
|
|
266
|
+
if (isManifestPath(filePath)) {
|
|
267
|
+
const callback = args[args.length - 1];
|
|
268
|
+
if ('function' == typeof callback) callback(null);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
return originalWriteFile(filePath, ...args);
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
if ('function' == typeof outputFileSystem.writeFileSync) {
|
|
275
|
+
const originalWriteFileSync = outputFileSystem.writeFileSync.bind(outputFileSystem);
|
|
276
|
+
outputFileSystem.writeFileSync = (filePath, ...args)=>{
|
|
277
|
+
if (isManifestPath(filePath)) return;
|
|
278
|
+
return originalWriteFileSync(filePath, ...args);
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
if ('function' == typeof outputFileSystem.createWriteStream) {
|
|
282
|
+
const originalCreateWriteStream = outputFileSystem.createWriteStream.bind(outputFileSystem);
|
|
283
|
+
outputFileSystem.createWriteStream = (filePath, ...args)=>{
|
|
284
|
+
if (isManifestPath(filePath)) {
|
|
285
|
+
const stream = createDiscardWriteStream();
|
|
286
|
+
stream.path = filePath;
|
|
287
|
+
return stream;
|
|
288
|
+
}
|
|
289
|
+
return originalCreateWriteStream(filePath, ...args);
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
if ('function' == typeof outputFileSystem?.promises?.writeFile) {
|
|
293
|
+
const originalPromiseWriteFile = outputFileSystem.promises.writeFile.bind(outputFileSystem.promises);
|
|
294
|
+
outputFileSystem.promises.writeFile = async (filePath, ...args)=>{
|
|
295
|
+
if (isManifestPath(filePath)) return;
|
|
296
|
+
return originalPromiseWriteFile(filePath, ...args);
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
outputFileSystem.__extensionjsManifestWriteGuard = true;
|
|
300
|
+
}
|
|
301
|
+
function installManifestDiskWriteGuard(manifestOutputPath) {
|
|
302
|
+
const guardKey = __rspack_external_path.resolve(manifestOutputPath);
|
|
303
|
+
guardedManifestDiskWritePaths.add(guardKey);
|
|
304
|
+
if (isManifestDiskWriteGuardInstalled) return;
|
|
305
|
+
const guardedFs = fs;
|
|
306
|
+
const isManifestPath = (filePath)=>hasGuardedManifestDiskPath(filePath);
|
|
307
|
+
const allowManifestRename = (fromPath, toPath)=>'string' == typeof fromPath && 'string' == typeof toPath && isManifestPath(toPath) && isManifestTempPath(fromPath);
|
|
308
|
+
const originalWriteFile = guardedFs.writeFile.bind(guardedFs);
|
|
309
|
+
guardedFs.writeFile = (filePath, ...args)=>{
|
|
310
|
+
if (isManifestPath(filePath)) {
|
|
311
|
+
const callback = args[args.length - 1];
|
|
312
|
+
if ('function' == typeof callback) callback(null);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
return originalWriteFile(filePath, ...args);
|
|
316
|
+
};
|
|
317
|
+
const originalWriteFileSync = guardedFs.writeFileSync.bind(guardedFs);
|
|
318
|
+
guardedFs.writeFileSync = (filePath, ...args)=>{
|
|
319
|
+
if (isManifestPath(filePath)) return;
|
|
320
|
+
return originalWriteFileSync(filePath, ...args);
|
|
321
|
+
};
|
|
322
|
+
const originalCreateWriteStream = guardedFs.createWriteStream.bind(guardedFs);
|
|
323
|
+
guardedFs.createWriteStream = (filePath, ...args)=>{
|
|
324
|
+
if (isManifestPath(filePath)) {
|
|
325
|
+
const stream = createDiscardWriteStream();
|
|
326
|
+
stream.path = String(filePath);
|
|
327
|
+
return stream;
|
|
328
|
+
}
|
|
329
|
+
return originalCreateWriteStream(filePath, ...args);
|
|
330
|
+
};
|
|
331
|
+
const originalOpen = guardedFs.open.bind(guardedFs);
|
|
332
|
+
guardedFs.open = (pathLike, flags, ...args)=>{
|
|
333
|
+
const nextPath = isManifestPath(pathLike) ? '/dev/null' : pathLike;
|
|
334
|
+
return originalOpen(nextPath, flags, ...args);
|
|
335
|
+
};
|
|
336
|
+
const originalOpenSync = guardedFs.openSync.bind(guardedFs);
|
|
337
|
+
guardedFs.openSync = (pathLike, flags, ...args)=>{
|
|
338
|
+
const nextPath = isManifestPath(pathLike) ? '/dev/null' : pathLike;
|
|
339
|
+
return originalOpenSync(nextPath, flags, ...args);
|
|
340
|
+
};
|
|
341
|
+
const originalRename = guardedFs.rename.bind(guardedFs);
|
|
342
|
+
guardedFs.rename = (oldPath, newPath, callback)=>{
|
|
343
|
+
if (isManifestPath(newPath) && !allowManifestRename(oldPath, newPath)) {
|
|
344
|
+
if ('function' == typeof callback) callback(null);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
return originalRename(oldPath, newPath, callback);
|
|
348
|
+
};
|
|
349
|
+
const originalRenameSync = guardedFs.renameSync.bind(guardedFs);
|
|
350
|
+
guardedFs.renameSync = (oldPath, newPath)=>{
|
|
351
|
+
if (isManifestPath(newPath) && !allowManifestRename(oldPath, newPath)) return;
|
|
352
|
+
return originalRenameSync(oldPath, newPath);
|
|
353
|
+
};
|
|
354
|
+
if (guardedFs.promises?.writeFile) {
|
|
355
|
+
const originalPromiseWriteFile = guardedFs.promises.writeFile.bind(guardedFs.promises);
|
|
356
|
+
guardedFs.promises.writeFile = async (filePath, ...args)=>{
|
|
357
|
+
if (isManifestPath(filePath)) return;
|
|
358
|
+
return originalPromiseWriteFile(filePath, ...args);
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
isManifestDiskWriteGuardInstalled = true;
|
|
362
|
+
}
|
|
363
|
+
async function dev_server_devServer(projectStructure, devOptions) {
|
|
364
|
+
process.env.EXTENSION_BROWSER_LAUNCH_ENABLED = devOptions.noBrowser ? '0' : '1';
|
|
365
|
+
const { manifestPath, packageJsonPath } = projectStructure;
|
|
366
|
+
__rspack_external_path.dirname(manifestPath);
|
|
367
|
+
const packageJsonDir = __rspack_external_path.dirname(packageJsonPath);
|
|
368
|
+
const commandConfig = await loadCommandConfig(packageJsonDir, 'dev');
|
|
369
|
+
const browserConfig = await loadBrowserConfig(packageJsonDir, devOptions.browser);
|
|
370
|
+
const portManager = new PortManager(devOptions.browser, packageJsonDir, 8080);
|
|
371
|
+
const desiredPort = 'string' == typeof devOptions.port ? parseInt(devOptions.port, 10) : devOptions.port;
|
|
372
|
+
const portAllocation = await portManager.allocatePorts(devOptions.browser, packageJsonDir, desiredPort);
|
|
373
|
+
const currentInstance = portManager.getCurrentInstance();
|
|
374
|
+
if (!currentInstance) throw new Error('Failed to create instance');
|
|
375
|
+
const port = portAllocation.port;
|
|
376
|
+
const devServerHost = devOptions.host || '127.0.0.1';
|
|
377
|
+
const devServerWebSocketURL = {
|
|
378
|
+
protocol: 'ws',
|
|
379
|
+
hostname: devServerHost,
|
|
380
|
+
port
|
|
381
|
+
};
|
|
382
|
+
process.env.EXTENSION_DEV_SERVER_PROTOCOL = devServerWebSocketURL.protocol;
|
|
383
|
+
process.env.EXTENSION_DEV_SERVER_HOST = devServerHost;
|
|
384
|
+
process.env.EXTENSION_DEV_SERVER_PORT = String(port);
|
|
385
|
+
process.env.EXTENSION_DEV_SERVER_PATH = '/ws';
|
|
386
|
+
const safeBrowserConfig = sanitize(browserConfig);
|
|
387
|
+
const safeCommandConfig = sanitize(commandConfig);
|
|
388
|
+
const safeDevOptions = sanitize(devOptions);
|
|
389
|
+
const specialFoldersData = getSpecialFoldersDataForProjectRoot(packageJsonDir);
|
|
390
|
+
const mergedExtensionsConfig = safeDevOptions.extensions ?? safeCommandConfig.extensions ?? safeBrowserConfig.extensions ?? specialFoldersData.extensions;
|
|
391
|
+
const resolvedExtensionsConfig = await resolveCompanionExtensionsConfig({
|
|
392
|
+
projectRoot: packageJsonDir,
|
|
393
|
+
browser: devOptions.browser,
|
|
394
|
+
config: mergedExtensionsConfig
|
|
395
|
+
});
|
|
396
|
+
const baseConfig = webpackConfig(projectStructure, {
|
|
397
|
+
...safeBrowserConfig,
|
|
398
|
+
...safeCommandConfig,
|
|
399
|
+
...safeDevOptions,
|
|
400
|
+
extensions: resolvedExtensionsConfig,
|
|
401
|
+
browser: devOptions.browser,
|
|
402
|
+
mode: 'development',
|
|
403
|
+
instanceId: currentInstance.instanceId,
|
|
404
|
+
port: portAllocation.port,
|
|
405
|
+
output: {
|
|
406
|
+
clean: false,
|
|
407
|
+
path: __rspack_external_path.join(packageJsonDir, 'dist', devOptions.browser)
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
const customWebpackConfig = await loadCustomConfig(packageJsonDir);
|
|
411
|
+
const finalConfig = customWebpackConfig(baseConfig);
|
|
412
|
+
const compilerConfig = merge(finalConfig, {});
|
|
413
|
+
const compiler = rspack(compilerConfig);
|
|
414
|
+
const manifestOutputPath = __rspack_external_path.join(packageJsonDir, 'dist', devOptions.browser, 'manifest.json');
|
|
415
|
+
installManifestDiskWriteGuard(manifestOutputPath);
|
|
416
|
+
suppressManifestOutputWrites(compiler, manifestOutputPath);
|
|
417
|
+
const metadata = createPlaywrightMetadataWriter({
|
|
418
|
+
packageJsonDir,
|
|
419
|
+
browser: String(devOptions.browser || 'chromium'),
|
|
420
|
+
command: 'dev',
|
|
421
|
+
distPath: __rspack_external_path.join(packageJsonDir, 'dist', String(devOptions.browser || 'chromium')),
|
|
422
|
+
manifestPath,
|
|
423
|
+
port
|
|
424
|
+
});
|
|
425
|
+
setupCompilerLifecycleHooks(compiler);
|
|
426
|
+
if (devOptions.noBrowser) setupNoBrowserBannerOnFirstDone({
|
|
427
|
+
compiler,
|
|
428
|
+
browser: String(devOptions.browser || 'chromium'),
|
|
429
|
+
manifestPath,
|
|
430
|
+
readyPath: metadata.readyPath
|
|
431
|
+
});
|
|
432
|
+
if (void 0 !== devOptions.port && devOptions.port !== port) console.log(portInUse(devOptions.port, port));
|
|
433
|
+
const serverConfig = {
|
|
434
|
+
host: devServerHost,
|
|
435
|
+
allowedHosts: 'all',
|
|
436
|
+
static: {
|
|
437
|
+
directory: __rspack_external_path.join(packageJsonDir, 'public'),
|
|
438
|
+
watch: false
|
|
439
|
+
},
|
|
440
|
+
compress: false,
|
|
441
|
+
devMiddleware: {
|
|
442
|
+
writeToDisk: shouldWriteAssetToDisk,
|
|
443
|
+
stats: {
|
|
444
|
+
all: false
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
watchFiles: {
|
|
448
|
+
paths: [
|
|
449
|
+
__rspack_external_path.join(packageJsonDir, 'public', '**/*'),
|
|
450
|
+
...isUsingJSFramework(packageJsonDir) ? [] : [
|
|
451
|
+
__rspack_external_path.join(packageJsonDir, '**/*.html')
|
|
452
|
+
]
|
|
453
|
+
],
|
|
454
|
+
options: {
|
|
455
|
+
ignored: [
|
|
456
|
+
__rspack_external_path.join(packageJsonDir, 'dist', '**/*')
|
|
457
|
+
],
|
|
458
|
+
ignoreInitial: true,
|
|
459
|
+
usePolling: true,
|
|
460
|
+
interval: 1000
|
|
461
|
+
}
|
|
462
|
+
},
|
|
463
|
+
client: false,
|
|
464
|
+
headers: {
|
|
465
|
+
'Access-Control-Allow-Origin': '*'
|
|
466
|
+
},
|
|
467
|
+
port,
|
|
468
|
+
hot: true,
|
|
469
|
+
liveReload: true
|
|
470
|
+
};
|
|
471
|
+
const devServer = new RspackDevServer(serverConfig, compiler);
|
|
472
|
+
const START_TIMEOUT_MS = parseInt(String(process.env.EXTENSION_START_TIMEOUT_MS || '30000'), 10);
|
|
473
|
+
let startTimeout;
|
|
474
|
+
try {
|
|
475
|
+
startTimeout = setTimeout(()=>{
|
|
476
|
+
console.error(devServerStartTimeout(START_TIMEOUT_MS));
|
|
477
|
+
}, START_TIMEOUT_MS);
|
|
478
|
+
await devServer.start();
|
|
479
|
+
if (startTimeout) clearTimeout(startTimeout);
|
|
480
|
+
} catch (error) {
|
|
481
|
+
if (startTimeout) clearTimeout(startTimeout);
|
|
482
|
+
metadata.writeError('dev_server_start_failed', error instanceof Error ? error.message : String(error));
|
|
483
|
+
console.log(extensionJsRunnerError(error));
|
|
484
|
+
process.exit(1);
|
|
485
|
+
}
|
|
486
|
+
setupCleanupHandlers(devServer, portManager);
|
|
487
|
+
}
|
|
488
|
+
export { dev_server_devServer as devServer };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
|
|
2
|
+
var __webpack_modules__ = {};
|
|
3
|
+
var __webpack_module_cache__ = {};
|
|
4
|
+
function __webpack_require__(moduleId) {
|
|
5
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
6
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
7
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
8
|
+
exports: {}
|
|
9
|
+
};
|
|
10
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
11
|
+
return module.exports;
|
|
12
|
+
}
|
|
13
|
+
__webpack_require__.m = __webpack_modules__;
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.d = (exports, definition)=>{
|
|
16
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: definition[key]
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
})();
|
|
22
|
+
(()=>{
|
|
23
|
+
__webpack_require__.add = function(modules) {
|
|
24
|
+
Object.assign(__webpack_require__.m, modules);
|
|
25
|
+
};
|
|
26
|
+
})();
|
|
27
|
+
(()=>{
|
|
28
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
29
|
+
})();
|
|
30
|
+
(()=>{
|
|
31
|
+
__webpack_require__.r = (exports)=>{
|
|
32
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
|
|
33
|
+
value: 'Module'
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, '__esModule', {
|
|
36
|
+
value: true
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
export { __webpack_require__ };
|