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