extension-develop 3.12.0 → 3.13.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/README.md +1 -1
- package/dist/{890.cjs → 264.cjs} +179 -4770
- package/dist/324.cjs +21 -3
- package/dist/extension-js-devtools/chrome/background/service_worker.js +1 -1
- package/dist/extension-js-devtools/chromium/background/service_worker.js +1 -1
- package/dist/extension-js-devtools/edge/background/service_worker.js +1 -1
- package/dist/extension-js-devtools/firefox/background/scripts.js +1 -1
- package/dist/module.cjs +349 -5644
- package/dist/preview.cjs +1461 -0
- package/package.json +10 -12
- package/dist/215.cjs +0 -849
- package/dist/323.cjs +0 -1100
- package/webpack/webpack-lib/build-dependencies.json +0 -24
package/dist/preview.cjs
ADDED
|
@@ -0,0 +1,1461 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
3
|
+
return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
4
|
+
}();
|
|
5
|
+
var __webpack_modules__ = {
|
|
6
|
+
"./webpack/webpack-lib/messages.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
7
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
8
|
+
BX: ()=>isUsingExperimentalConfig,
|
|
9
|
+
F$: ()=>downloadingProjectPath,
|
|
10
|
+
GW: ()=>failedToDownloadOrExtractZIPFileError,
|
|
11
|
+
H3: ()=>managedDependencyConflict,
|
|
12
|
+
SG: ()=>debugDirs,
|
|
13
|
+
Ud: ()=>downloadingText,
|
|
14
|
+
V_: ()=>previewing,
|
|
15
|
+
W4: ()=>creatingProjectPath,
|
|
16
|
+
_A: ()=>debugBrowser,
|
|
17
|
+
ax: ()=>downloadedProjectFolderNotFound,
|
|
18
|
+
dx: ()=>manifestNotFoundError,
|
|
19
|
+
f7: ()=>configLoadingError,
|
|
20
|
+
gC: ()=>unpackagingExtension,
|
|
21
|
+
jV: ()=>debugPreviewOutput,
|
|
22
|
+
k4: ()=>previewSkippedNoBrowser,
|
|
23
|
+
tQ: ()=>fetchingProjectPath,
|
|
24
|
+
tc: ()=>invalidRemoteZip,
|
|
25
|
+
zM: ()=>unpackagedSuccessfully
|
|
26
|
+
});
|
|
27
|
+
__webpack_require__("fs");
|
|
28
|
+
var path__rspack_import_1 = __webpack_require__("path");
|
|
29
|
+
var pintor__rspack_import_2 = __webpack_require__("pintor");
|
|
30
|
+
var pintor__rspack_import_2_default = /*#__PURE__*/ __webpack_require__.n(pintor__rspack_import_2);
|
|
31
|
+
__webpack_require__("./package.json");
|
|
32
|
+
const fmt = {
|
|
33
|
+
heading: (title)=>pintor__rspack_import_2_default().underline(pintor__rspack_import_2_default().blue(title)),
|
|
34
|
+
label: (key)=>pintor__rspack_import_2_default().gray(key.toUpperCase()),
|
|
35
|
+
val: (value)=>pintor__rspack_import_2_default().underline(value),
|
|
36
|
+
code: (value)=>pintor__rspack_import_2_default().blue(value),
|
|
37
|
+
bullet: (value)=>`- ${value}`,
|
|
38
|
+
block (title, rows) {
|
|
39
|
+
const head = fmt.heading(title);
|
|
40
|
+
const body = rows.map(([key, value])=>`${fmt.label(key)} ${value}`).join('\n');
|
|
41
|
+
return `${head}\n${body}`;
|
|
42
|
+
},
|
|
43
|
+
truncate (input, max = 800) {
|
|
44
|
+
const s = (()=>{
|
|
45
|
+
try {
|
|
46
|
+
return 'string' == typeof input ? input : JSON.stringify(input);
|
|
47
|
+
} catch {
|
|
48
|
+
return String(input);
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
51
|
+
return s.length > max ? s.slice(0, max) + '…' : s;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
function getLoggingPrefix(type) {
|
|
55
|
+
const isAuthor = 'true' === process.env.EXTENSION_AUTHOR_MODE;
|
|
56
|
+
if (isAuthor) {
|
|
57
|
+
const base = 'error' === type ? 'ERROR Author says' : '⏵⏵⏵ Author says';
|
|
58
|
+
return pintor__rspack_import_2_default().brightMagenta(base);
|
|
59
|
+
}
|
|
60
|
+
if ('error' === type) return pintor__rspack_import_2_default().red('ERROR');
|
|
61
|
+
if ('warn' === type) return pintor__rspack_import_2_default().brightYellow('⏵⏵⏵');
|
|
62
|
+
if ('info' === type) return pintor__rspack_import_2_default().gray('⏵⏵⏵');
|
|
63
|
+
return pintor__rspack_import_2_default().green('⏵⏵⏵');
|
|
64
|
+
}
|
|
65
|
+
function isPathLike(input) {
|
|
66
|
+
return input.includes('/') || input.includes('\\') || path__rspack_import_1.isAbsolute(input);
|
|
67
|
+
}
|
|
68
|
+
function manifestNotFoundError(manifestPath) {
|
|
69
|
+
return `${getLoggingPrefix('error')} Manifest file not found.\n${pintor__rspack_import_2_default().red('Ensure the path to your extension exists and try again.')}\n${pintor__rspack_import_2_default().red('NOT FOUND')}\n${pintor__rspack_import_2_default().gray('PATH')} ${pintor__rspack_import_2_default().underline(manifestPath)}`;
|
|
70
|
+
}
|
|
71
|
+
function previewing(browser) {
|
|
72
|
+
return `${getLoggingPrefix('info')} Previewing the extension on ${capitalizedBrowserName(browser)}...`;
|
|
73
|
+
}
|
|
74
|
+
function previewSkippedNoBrowser(browser) {
|
|
75
|
+
return `${getLoggingPrefix('info')} Skipping browser launch for ${capitalizedBrowserName(browser)} (no-browser).`;
|
|
76
|
+
}
|
|
77
|
+
function fetchingProjectPath(owner, project) {
|
|
78
|
+
return fmt.block('Fetching project', [
|
|
79
|
+
[
|
|
80
|
+
'URL',
|
|
81
|
+
fmt.val(`https://github.com/${owner}/${project}`)
|
|
82
|
+
]
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
function downloadingProjectPath(projectName) {
|
|
86
|
+
const formatted = isPathLike(projectName) ? pintor__rspack_import_2_default().underline(projectName) : pintor__rspack_import_2_default().yellow(projectName);
|
|
87
|
+
return `${getLoggingPrefix('info')} Downloading ${formatted}...`;
|
|
88
|
+
}
|
|
89
|
+
function creatingProjectPath(projectPath) {
|
|
90
|
+
return `${getLoggingPrefix('info')} Creating a new browser extension...\n${pintor__rspack_import_2_default().gray('PATH')} ${pintor__rspack_import_2_default().underline(projectPath)}`;
|
|
91
|
+
}
|
|
92
|
+
function downloadedProjectFolderNotFound(cwd, candidates) {
|
|
93
|
+
return `${getLoggingPrefix('error')} Downloaded project folder not found.\n${pintor__rspack_import_2_default().gray('PATH')} ${pintor__rspack_import_2_default().underline(cwd)}\n${pintor__rspack_import_2_default().gray('Tried')} ${pintor__rspack_import_2_default().underline(candidates.join(', '))}`;
|
|
94
|
+
}
|
|
95
|
+
function downloadingText(url) {
|
|
96
|
+
return fmt.block('Downloading extension', [
|
|
97
|
+
[
|
|
98
|
+
'URL',
|
|
99
|
+
fmt.val(url)
|
|
100
|
+
]
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
function unpackagingExtension(zipFilePath) {
|
|
104
|
+
return `${getLoggingPrefix('info')} Unpackaging browser extension...\n${pintor__rspack_import_2_default().gray('PATH')} ${pintor__rspack_import_2_default().underline(zipFilePath)}`;
|
|
105
|
+
}
|
|
106
|
+
function unpackagedSuccessfully() {
|
|
107
|
+
return `${getLoggingPrefix('info')} Browser extension unpackaged ${pintor__rspack_import_2_default().green('successfully')}.`;
|
|
108
|
+
}
|
|
109
|
+
function failedToDownloadOrExtractZIPFileError(error) {
|
|
110
|
+
return `${getLoggingPrefix('error')} Failed to download or extract ZIP file.\n${pintor__rspack_import_2_default().red(error)}`;
|
|
111
|
+
}
|
|
112
|
+
function invalidRemoteZip(url, contentType) {
|
|
113
|
+
return `${getLoggingPrefix('error')} Remote URL does not appear to be a ZIP archive.\n${pintor__rspack_import_2_default().gray('URL')} ${pintor__rspack_import_2_default().underline(url)}\n${pintor__rspack_import_2_default().gray('Content-Type')} ${pintor__rspack_import_2_default().underline(contentType || 'unknown')}`;
|
|
114
|
+
}
|
|
115
|
+
function capitalizedBrowserName(browser) {
|
|
116
|
+
const b = String(browser || '');
|
|
117
|
+
const cap = b.charAt(0).toUpperCase() + b.slice(1);
|
|
118
|
+
return pintor__rspack_import_2_default().yellow(`${cap}`);
|
|
119
|
+
}
|
|
120
|
+
function isUsingExperimentalConfig(integration) {
|
|
121
|
+
return `${getLoggingPrefix('info')} Using ${pintor__rspack_import_2_default().yellow(integration)}.`;
|
|
122
|
+
}
|
|
123
|
+
function debugDirs(manifestDir, packageJsonDir) {
|
|
124
|
+
return `${getLoggingPrefix('info')} Directories\n${pintor__rspack_import_2_default().gray('MANIFEST_DIR')} ${pintor__rspack_import_2_default().underline(manifestDir)}\n${pintor__rspack_import_2_default().gray('PACKAGE_JSON_DIR')} ${pintor__rspack_import_2_default().underline(packageJsonDir)}`;
|
|
125
|
+
}
|
|
126
|
+
function debugBrowser(browser, chromiumBinary, geckoBinary) {
|
|
127
|
+
return `${getLoggingPrefix('info')} Browser Target\n${pintor__rspack_import_2_default().gray('BROWSER')} ${pintor__rspack_import_2_default().yellow(String(browser))}\n${pintor__rspack_import_2_default().gray('CHROMIUM_BINARY')} ${pintor__rspack_import_2_default().underline(String(chromiumBinary || 'auto'))}\n${pintor__rspack_import_2_default().gray('GECKO_BINARY')} ${pintor__rspack_import_2_default().underline(String(geckoBinary || 'auto'))}`;
|
|
128
|
+
}
|
|
129
|
+
function debugPreviewOutput(outputPath, distPath) {
|
|
130
|
+
return `${getLoggingPrefix('info')} Preview Output\n${pintor__rspack_import_2_default().gray('OUTPUT')} ${pintor__rspack_import_2_default().underline(outputPath)}\n${pintor__rspack_import_2_default().gray('DIST')} ${pintor__rspack_import_2_default().underline(distPath)}`;
|
|
131
|
+
}
|
|
132
|
+
function configLoadingError(configPath, error) {
|
|
133
|
+
return `${pintor__rspack_import_2_default().red('ERROR')} ${pintor__rspack_import_2_default().brightBlue('config load failed')}\n${fmt.label('PATH')} ${fmt.val(configPath)}\n` + pintor__rspack_import_2_default().red(fmt.truncate(error, 1200));
|
|
134
|
+
}
|
|
135
|
+
function managedDependencyConflict(duplicates, userPackageJsonPath) {
|
|
136
|
+
const list = duplicates.map((d)=>`- ${pintor__rspack_import_2_default().yellow(d)}`).join('\n');
|
|
137
|
+
return `${getLoggingPrefix('error')} Your project declares dependencies that are managed by ${pintor__rspack_import_2_default().blue('Extension.js')} and referenced in ${pintor__rspack_import_2_default().underline('extension.config.js')}\n${pintor__rspack_import_2_default().red('This can cause version conflicts and break the development/build process.')}\n\n${pintor__rspack_import_2_default().gray('Managed dependencies (remove these from your package.json):')}\n${list}\n\n${pintor__rspack_import_2_default().gray('PATH')} ${pintor__rspack_import_2_default().underline(userPackageJsonPath)}\nIf you need a different version, open an issue so we can consider bundling it safely.\nOperation aborted.`;
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"adm-zip" (module) {
|
|
141
|
+
module.exports = require("adm-zip");
|
|
142
|
+
},
|
|
143
|
+
fs (module) {
|
|
144
|
+
module.exports = require("fs");
|
|
145
|
+
},
|
|
146
|
+
path (module) {
|
|
147
|
+
module.exports = require("path");
|
|
148
|
+
},
|
|
149
|
+
pintor (module) {
|
|
150
|
+
module.exports = require("pintor");
|
|
151
|
+
},
|
|
152
|
+
"./package.json" (module) {
|
|
153
|
+
module.exports = JSON.parse('{"rE":"3.13.0","El":{"@prefresh/core":"1.5.9","@prefresh/utils":"1.2.1","@rspack/core":"^1.7.5","@rspack/dev-server":"^1.2.1","@rspack/plugin-preact-refresh":"1.1.4","@rspack/plugin-react-refresh":"1.6.0","@swc/core":"^1.15.8","@swc/helpers":"^0.5.18","@vue/compiler-sfc":"3.5.26","adm-zip":"^0.5.16","browser-extension-manifest-fields":"^2.2.1","case-sensitive-paths-webpack-plugin":"^2.4.0","content-security-policy-parser":"^0.6.0","cross-spawn":"^7.0.6","dotenv":"^17.2.3","extension-from-store":"^0.1.1","go-git-it":"^5.1.5","ignore":"^7.0.5","less":"4.5.1","less-loader":"12.3.0","loader-utils":"^3.3.1","magic-string":"^0.30.21","parse5":"^8.0.0","parse5-utilities":"^1.0.0","pintor":"0.3.0","postcss":"8.5.6","postcss-loader":"8.2.0","postcss-preset-env":"11.1.1","postcss-scss":"4.0.9","preact":"10.27.3","react-refresh":"0.18.0","sass-loader":"16.0.6","schema-utils":"^4.3.3","svelte-loader":"3.2.4","tiny-glob":"^0.2.9","typescript":"5.9.3","unique-names-generator":"^4.7.1","vue":"3.5.26","vue-loader":"17.4.2","webextension-polyfill":"^0.12.0","webpack-merge":"^6.0.1","webpack-target-webextension":"^2.1.3"}}');
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
var __webpack_module_cache__ = {};
|
|
157
|
+
function __webpack_require__(moduleId) {
|
|
158
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
159
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
160
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
161
|
+
exports: {}
|
|
162
|
+
};
|
|
163
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
164
|
+
return module.exports;
|
|
165
|
+
}
|
|
166
|
+
__webpack_require__.m = __webpack_modules__;
|
|
167
|
+
(()=>{
|
|
168
|
+
__webpack_require__.n = (module)=>{
|
|
169
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
170
|
+
__webpack_require__.d(getter, {
|
|
171
|
+
a: getter
|
|
172
|
+
});
|
|
173
|
+
return getter;
|
|
174
|
+
};
|
|
175
|
+
})();
|
|
176
|
+
(()=>{
|
|
177
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
178
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
get: definition[key]
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
})();
|
|
184
|
+
(()=>{
|
|
185
|
+
__webpack_require__.f = {};
|
|
186
|
+
__webpack_require__.e = (chunkId)=>Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key)=>{
|
|
187
|
+
__webpack_require__.f[key](chunkId, promises);
|
|
188
|
+
return promises;
|
|
189
|
+
}, []));
|
|
190
|
+
})();
|
|
191
|
+
(()=>{
|
|
192
|
+
__webpack_require__.u = (chunkId)=>"" + chunkId + ".cjs";
|
|
193
|
+
})();
|
|
194
|
+
(()=>{
|
|
195
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
196
|
+
})();
|
|
197
|
+
(()=>{
|
|
198
|
+
__webpack_require__.r = (exports1)=>{
|
|
199
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
200
|
+
value: 'Module'
|
|
201
|
+
});
|
|
202
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
203
|
+
value: true
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
})();
|
|
207
|
+
(()=>{
|
|
208
|
+
var installedChunks = {
|
|
209
|
+
534: 1
|
|
210
|
+
};
|
|
211
|
+
var installChunk = (chunk)=>{
|
|
212
|
+
var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;
|
|
213
|
+
for(var moduleId in moreModules)if (__webpack_require__.o(moreModules, moduleId)) __webpack_require__.m[moduleId] = moreModules[moduleId];
|
|
214
|
+
if (runtime) runtime(__webpack_require__);
|
|
215
|
+
for(var i = 0; i < chunkIds.length; i++)installedChunks[chunkIds[i]] = 1;
|
|
216
|
+
};
|
|
217
|
+
__webpack_require__.f.require = (chunkId, promises)=>{
|
|
218
|
+
if (!installedChunks[chunkId]) installChunk(require("./" + __webpack_require__.u(chunkId)));
|
|
219
|
+
};
|
|
220
|
+
})();
|
|
221
|
+
var __webpack_exports__ = {};
|
|
222
|
+
(()=>{
|
|
223
|
+
__webpack_require__.r(__webpack_exports__);
|
|
224
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
225
|
+
extensionPreview: ()=>extensionPreview
|
|
226
|
+
});
|
|
227
|
+
var external_path_ = __webpack_require__("path");
|
|
228
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_);
|
|
229
|
+
var external_fs_ = __webpack_require__("fs");
|
|
230
|
+
var webpack_lib_messages = __webpack_require__("./webpack/webpack-lib/messages.ts");
|
|
231
|
+
async function findUpLocal(filename, options) {
|
|
232
|
+
const root = external_path_.parse(options.cwd).root;
|
|
233
|
+
let currentDir = options.cwd;
|
|
234
|
+
while(true){
|
|
235
|
+
const candidate = external_path_.join(currentDir, filename);
|
|
236
|
+
try {
|
|
237
|
+
const stat = await external_fs_.promises.stat(candidate);
|
|
238
|
+
if (stat.isFile()) return candidate;
|
|
239
|
+
} catch {}
|
|
240
|
+
if (currentDir === root) return;
|
|
241
|
+
currentDir = external_path_.dirname(currentDir);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
async function findNearestPackageJson(manifestPath) {
|
|
245
|
+
try {
|
|
246
|
+
const manifestDir = external_path_.dirname(manifestPath);
|
|
247
|
+
const packageJsonPath = await findUpLocal('package.json', {
|
|
248
|
+
cwd: manifestDir
|
|
249
|
+
});
|
|
250
|
+
return packageJsonPath || null;
|
|
251
|
+
} catch (error) {
|
|
252
|
+
console.warn('Failed to find package.json:', error);
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function validatePackageJson(packageJsonPath) {
|
|
257
|
+
try {
|
|
258
|
+
if (!external_fs_.existsSync(packageJsonPath)) return false;
|
|
259
|
+
const content = external_fs_.readFileSync(packageJsonPath, 'utf-8');
|
|
260
|
+
JSON.parse(content);
|
|
261
|
+
return true;
|
|
262
|
+
} catch (error) {
|
|
263
|
+
console.warn('Invalid package.json at:', packageJsonPath, error);
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
const isUrl = (url)=>{
|
|
268
|
+
try {
|
|
269
|
+
new URL(url);
|
|
270
|
+
return true;
|
|
271
|
+
} catch (e) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
async function importUrlSourceFromGithub(pathOrRemoteUrl, text) {
|
|
276
|
+
const cwd = process.cwd();
|
|
277
|
+
const url = new URL(pathOrRemoteUrl);
|
|
278
|
+
const segments = url.pathname.split('/').filter(Boolean);
|
|
279
|
+
const repoName = segments.length >= 2 ? segments[1] : segments[segments.length - 1];
|
|
280
|
+
const treeIndex = segments.indexOf('tree');
|
|
281
|
+
const expectedName = -1 !== treeIndex && segments.length > treeIndex + 2 ? segments[segments.length - 1] : repoName;
|
|
282
|
+
const expectedPath = external_path_.resolve(cwd, expectedName);
|
|
283
|
+
if (external_fs_.existsSync(expectedPath)) try {
|
|
284
|
+
const entries = external_fs_.readdirSync(expectedPath);
|
|
285
|
+
if (0 === entries.length) external_fs_.rmSync(expectedPath, {
|
|
286
|
+
recursive: true,
|
|
287
|
+
force: true
|
|
288
|
+
});
|
|
289
|
+
else {
|
|
290
|
+
const hasManifest = (dir)=>{
|
|
291
|
+
const stack = [
|
|
292
|
+
dir
|
|
293
|
+
];
|
|
294
|
+
while(stack.length){
|
|
295
|
+
const current = stack.pop();
|
|
296
|
+
const items = external_fs_.readdirSync(current, {
|
|
297
|
+
withFileTypes: true
|
|
298
|
+
});
|
|
299
|
+
for (const it of items){
|
|
300
|
+
if (it.isFile() && 'manifest.json' === it.name) return true;
|
|
301
|
+
if (it.isDirectory() && 'node_modules' !== it.name && 'dist' !== it.name && !it.name.startsWith('.')) stack.push(external_path_.join(current, it.name));
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return false;
|
|
305
|
+
};
|
|
306
|
+
if (hasManifest(expectedPath)) return expectedPath;
|
|
307
|
+
external_fs_.rmSync(expectedPath, {
|
|
308
|
+
recursive: true,
|
|
309
|
+
force: true
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
} catch {}
|
|
313
|
+
async function tryGitClone() {
|
|
314
|
+
const { default: goGitIt } = await import("go-git-it");
|
|
315
|
+
await goGitIt(pathOrRemoteUrl, cwd, text);
|
|
316
|
+
}
|
|
317
|
+
async function tryZipFallback() {
|
|
318
|
+
const branch = -1 !== treeIndex && segments.length > treeIndex + 1 ? segments[treeIndex + 1] : 'main';
|
|
319
|
+
const owner = segments[0];
|
|
320
|
+
const repo = segments[1];
|
|
321
|
+
const subdir = -1 !== treeIndex && segments.length > treeIndex + 2 ? segments.slice(treeIndex + 2).join('/') : '';
|
|
322
|
+
const zipUrl = `https://codeload.github.com/${owner}/${repo}/zip/refs/heads/${branch}`;
|
|
323
|
+
const extractedPath = await importUrlSourceFromZip(zipUrl);
|
|
324
|
+
const extractedDirs = external_fs_.readdirSync(extractedPath, {
|
|
325
|
+
withFileTypes: true
|
|
326
|
+
}).filter((d)=>d.isDirectory()).map((d)=>d.name);
|
|
327
|
+
const repoRootDir = extractedDirs.find((d)=>d.startsWith(`${repo}-${branch}`));
|
|
328
|
+
const repoRoot = repoRootDir ? external_path_.join(extractedPath, repoRootDir) : extractedPath;
|
|
329
|
+
return subdir ? external_path_.join(repoRoot, subdir) : repoRoot;
|
|
330
|
+
}
|
|
331
|
+
try {
|
|
332
|
+
await tryGitClone();
|
|
333
|
+
} catch {
|
|
334
|
+
return await tryZipFallback();
|
|
335
|
+
}
|
|
336
|
+
const candidates = [];
|
|
337
|
+
if (-1 !== treeIndex && segments.length > treeIndex + 2) candidates.push(segments[segments.length - 1]);
|
|
338
|
+
candidates.push(repoName);
|
|
339
|
+
for (const name of candidates){
|
|
340
|
+
const p = external_path_.resolve(cwd, name);
|
|
341
|
+
if (external_fs_.existsSync(p)) return p;
|
|
342
|
+
}
|
|
343
|
+
const dirs = external_fs_.readdirSync(cwd, {
|
|
344
|
+
withFileTypes: true
|
|
345
|
+
}).filter((d)=>d.isDirectory()).map((d)=>d.name);
|
|
346
|
+
for (const dir of dirs){
|
|
347
|
+
const manifestPath = external_path_.join(cwd, dir, 'manifest.json');
|
|
348
|
+
if (external_fs_.existsSync(manifestPath)) return external_path_.join(cwd, dir);
|
|
349
|
+
}
|
|
350
|
+
try {
|
|
351
|
+
const dirs = external_fs_.readdirSync(cwd, {
|
|
352
|
+
withFileTypes: true
|
|
353
|
+
}).filter((d)=>d.isDirectory()).map((d)=>d.name);
|
|
354
|
+
const ghRoot = dirs.find((d)=>/-main$|-master$/.test(d));
|
|
355
|
+
if (ghRoot) return external_path_.join(cwd, ghRoot);
|
|
356
|
+
} catch {}
|
|
357
|
+
throw new Error(webpack_lib_messages.ax(cwd, candidates));
|
|
358
|
+
}
|
|
359
|
+
async function importUrlSourceFromZip(pathOrRemoteUrl) {
|
|
360
|
+
const cwd = process.cwd();
|
|
361
|
+
const { downloadAndExtractZip } = await __webpack_require__.e("419").then(__webpack_require__.bind(__webpack_require__, "./webpack/webpack-lib/zip.ts"));
|
|
362
|
+
const extractedPath = await downloadAndExtractZip(pathOrRemoteUrl, cwd);
|
|
363
|
+
return extractedPath;
|
|
364
|
+
}
|
|
365
|
+
async function getProjectPath(pathOrRemoteUrl) {
|
|
366
|
+
if (!pathOrRemoteUrl) return process.cwd();
|
|
367
|
+
if (isUrl(pathOrRemoteUrl)) {
|
|
368
|
+
const url = new URL(pathOrRemoteUrl);
|
|
369
|
+
if (url.protocol.startsWith('http')) {
|
|
370
|
+
const pathname = url.pathname.toLowerCase();
|
|
371
|
+
if (pathname.endsWith('.zip')) return await importUrlSourceFromZip(pathOrRemoteUrl);
|
|
372
|
+
if ('https://github.com' !== url.origin) {
|
|
373
|
+
const urlSource = await importUrlSourceFromZip(pathOrRemoteUrl);
|
|
374
|
+
return urlSource;
|
|
375
|
+
}
|
|
376
|
+
const urlData = url.pathname.split('/');
|
|
377
|
+
const owner = urlData.slice(1, 3)[0];
|
|
378
|
+
const project = urlData.slice(1, 3)[1];
|
|
379
|
+
console.log(webpack_lib_messages.tQ(owner, project));
|
|
380
|
+
const projectName = external_path_.basename(url.pathname);
|
|
381
|
+
const urlSource = await importUrlSourceFromGithub(pathOrRemoteUrl, webpack_lib_messages.F$(projectName));
|
|
382
|
+
console.log(webpack_lib_messages.W4(url.pathname));
|
|
383
|
+
return urlSource;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return external_path_.resolve(process.cwd(), pathOrRemoteUrl);
|
|
387
|
+
}
|
|
388
|
+
async function getProjectStructure(pathOrRemoteUrl) {
|
|
389
|
+
const projectPath = await getProjectPath(pathOrRemoteUrl);
|
|
390
|
+
const isUnderDir = (baseDir, candidatePath)=>{
|
|
391
|
+
const rel = external_path_.relative(baseDir, candidatePath);
|
|
392
|
+
return Boolean(rel && !rel.startsWith('..') && !external_path_.isAbsolute(rel));
|
|
393
|
+
};
|
|
394
|
+
const packageJsonPathFromProject = await findNearestPackageJson(external_path_.join(projectPath, 'manifest.json'));
|
|
395
|
+
const packageJsonDirFromProject = packageJsonPathFromProject ? external_path_.dirname(packageJsonPathFromProject) : void 0;
|
|
396
|
+
const rootManifestPath = external_path_.join(projectPath, 'manifest.json');
|
|
397
|
+
const srcManifestPath = external_path_.join(projectPath, 'src', 'manifest.json');
|
|
398
|
+
let manifestPath = external_fs_.existsSync(srcManifestPath) ? srcManifestPath : rootManifestPath;
|
|
399
|
+
if (!external_fs_.existsSync(manifestPath)) {
|
|
400
|
+
if (packageJsonDirFromProject) throw new Error(webpack_lib_messages.dx(manifestPath));
|
|
401
|
+
const findManifest = (dir)=>{
|
|
402
|
+
const files = external_fs_.readdirSync(dir, {
|
|
403
|
+
withFileTypes: true
|
|
404
|
+
});
|
|
405
|
+
for (const file of files){
|
|
406
|
+
if (file.isFile() && 'manifest.json' === file.name) return external_path_.join(dir, file.name);
|
|
407
|
+
if (file.isDirectory() && !file.name.startsWith('.') && 'node_modules' !== file.name && 'dist' !== file.name && 'public' !== file.name) {
|
|
408
|
+
const found = findManifest(external_path_.join(dir, file.name));
|
|
409
|
+
if (found) return found;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return null;
|
|
413
|
+
};
|
|
414
|
+
const foundManifest = findManifest(projectPath);
|
|
415
|
+
if (foundManifest) manifestPath = foundManifest;
|
|
416
|
+
else throw new Error(webpack_lib_messages.dx(manifestPath));
|
|
417
|
+
}
|
|
418
|
+
const packageJsonPath = await findNearestPackageJson(manifestPath);
|
|
419
|
+
const packageJsonDir = packageJsonPath ? external_path_.dirname(packageJsonPath) : void 0;
|
|
420
|
+
if (packageJsonDir) {
|
|
421
|
+
const publicRoot = external_path_.join(packageJsonDir, 'public');
|
|
422
|
+
if (isUnderDir(publicRoot, manifestPath)) {
|
|
423
|
+
const fallbackSrc = external_path_.join(packageJsonDir, 'src', 'manifest.json');
|
|
424
|
+
const fallbackRoot = external_path_.join(packageJsonDir, 'manifest.json');
|
|
425
|
+
if (external_fs_.existsSync(fallbackSrc)) manifestPath = fallbackSrc;
|
|
426
|
+
else if (external_fs_.existsSync(fallbackRoot)) manifestPath = fallbackRoot;
|
|
427
|
+
else throw new Error(webpack_lib_messages.dx(fallbackRoot));
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (!packageJsonPath || !validatePackageJson(packageJsonPath)) return {
|
|
431
|
+
manifestPath
|
|
432
|
+
};
|
|
433
|
+
return {
|
|
434
|
+
manifestPath,
|
|
435
|
+
packageJsonPath
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
const external_os_namespaceObject = require("os");
|
|
439
|
+
const external_vm_namespaceObject = require("vm");
|
|
440
|
+
const external_url_namespaceObject = require("url");
|
|
441
|
+
const external_module_namespaceObject = require("module");
|
|
442
|
+
const external_dotenv_namespaceObject = require("dotenv");
|
|
443
|
+
var external_dotenv_default = /*#__PURE__*/ __webpack_require__.n(external_dotenv_namespaceObject);
|
|
444
|
+
function loadCommonJsConfigWithStableDirname(absolutePath) {
|
|
445
|
+
const code = external_fs_.readFileSync(absolutePath, 'utf-8');
|
|
446
|
+
const dirname = external_path_.dirname(absolutePath);
|
|
447
|
+
const requireFn = (0, external_module_namespaceObject.createRequire)(absolutePath);
|
|
448
|
+
const module = {
|
|
449
|
+
exports: {}
|
|
450
|
+
};
|
|
451
|
+
const exports1 = module.exports;
|
|
452
|
+
const wrapped = `(function (exports, require, module, __filename, __dirname) {\n${code}\n})`;
|
|
453
|
+
const fn = new external_vm_namespaceObject.Script(wrapped, {
|
|
454
|
+
filename: absolutePath
|
|
455
|
+
}).runInThisContext();
|
|
456
|
+
fn(exports1, requireFn, module, absolutePath, dirname);
|
|
457
|
+
return module.exports?.default || module.exports;
|
|
458
|
+
}
|
|
459
|
+
function findNearestWorkspaceRoot(startDir) {
|
|
460
|
+
let current = external_path_.resolve(startDir);
|
|
461
|
+
while(true){
|
|
462
|
+
if (external_fs_.existsSync(external_path_.join(current, 'pnpm-workspace.yaml'))) return current;
|
|
463
|
+
const parent = external_path_.dirname(current);
|
|
464
|
+
if (parent === current) return;
|
|
465
|
+
current = parent;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
function preloadEnvFilesFromDir(envDir, options) {
|
|
469
|
+
let loadedAny = false;
|
|
470
|
+
try {
|
|
471
|
+
const defaultsPath = external_path_.join(envDir, '.env.defaults');
|
|
472
|
+
if (external_fs_.existsSync(defaultsPath)) {
|
|
473
|
+
external_dotenv_default().config({
|
|
474
|
+
path: defaultsPath,
|
|
475
|
+
override: Boolean(options?.override),
|
|
476
|
+
quiet: true
|
|
477
|
+
});
|
|
478
|
+
loadedAny = true;
|
|
479
|
+
}
|
|
480
|
+
const envCandidates = [
|
|
481
|
+
'.env.development',
|
|
482
|
+
'.env.local',
|
|
483
|
+
'.env'
|
|
484
|
+
];
|
|
485
|
+
for (const filename of envCandidates){
|
|
486
|
+
const filePath = external_path_.join(envDir, filename);
|
|
487
|
+
if (external_fs_.existsSync(filePath)) {
|
|
488
|
+
external_dotenv_default().config({
|
|
489
|
+
path: filePath,
|
|
490
|
+
override: Boolean(options?.override),
|
|
491
|
+
quiet: true
|
|
492
|
+
});
|
|
493
|
+
loadedAny = true;
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
} catch {}
|
|
498
|
+
return {
|
|
499
|
+
loadedAny,
|
|
500
|
+
envDir
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
function preloadEnvFiles(projectDir) {
|
|
504
|
+
const local = preloadEnvFilesFromDir(projectDir);
|
|
505
|
+
if (local.loadedAny) return local;
|
|
506
|
+
const workspaceRoot = findNearestWorkspaceRoot(projectDir);
|
|
507
|
+
if (workspaceRoot && workspaceRoot !== projectDir) return preloadEnvFilesFromDir(workspaceRoot);
|
|
508
|
+
return local;
|
|
509
|
+
}
|
|
510
|
+
async function loadConfigFile(configPath) {
|
|
511
|
+
const absolutePath = external_path_.resolve(configPath);
|
|
512
|
+
const projectDir = external_path_.dirname(absolutePath);
|
|
513
|
+
preloadEnvFiles(projectDir);
|
|
514
|
+
try {
|
|
515
|
+
if (absolutePath.endsWith('.cjs')) {
|
|
516
|
+
const requireFn = (0, external_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
517
|
+
const required = requireFn(absolutePath);
|
|
518
|
+
return required?.default || required;
|
|
519
|
+
}
|
|
520
|
+
let esmImportPath = absolutePath;
|
|
521
|
+
try {
|
|
522
|
+
const originalContent = external_fs_.readFileSync(absolutePath, 'utf-8');
|
|
523
|
+
if (originalContent.includes('import.meta.env')) {
|
|
524
|
+
const tmpDir = external_fs_.mkdtempSync(external_path_.join(external_os_namespaceObject.tmpdir(), 'extension-config-esm-'));
|
|
525
|
+
const tmpPath = external_path_.join(tmpDir, external_path_.basename(absolutePath));
|
|
526
|
+
const envObjectLiteral = JSON.stringify(Object.fromEntries(Object.entries(process.env).map(([k, v])=>[
|
|
527
|
+
k,
|
|
528
|
+
v
|
|
529
|
+
])), null, 0);
|
|
530
|
+
const shimHeader = `const __IMPORT_META_ENV__ = Object.freeze(${envObjectLiteral});\n`;
|
|
531
|
+
const replaced = originalContent.replace(/import\.meta\.env/g, '__IMPORT_META_ENV__');
|
|
532
|
+
external_fs_.writeFileSync(tmpPath, `${shimHeader}${replaced}`, 'utf-8');
|
|
533
|
+
esmImportPath = tmpPath;
|
|
534
|
+
}
|
|
535
|
+
} catch {}
|
|
536
|
+
const module = await import((0, external_url_namespaceObject.pathToFileURL)(esmImportPath).href);
|
|
537
|
+
return module.default || module;
|
|
538
|
+
} catch (err) {
|
|
539
|
+
const error = err;
|
|
540
|
+
try {
|
|
541
|
+
if (!absolutePath.endsWith('.mjs')) {
|
|
542
|
+
const requireFn = (0, external_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
543
|
+
let required;
|
|
544
|
+
try {
|
|
545
|
+
required = requireFn(absolutePath);
|
|
546
|
+
} catch (requireErr) {
|
|
547
|
+
const message = String(error?.message || '') + ' ' + String(requireErr?.message || '');
|
|
548
|
+
const looksLikeCommonJsInEsm = message.includes('require is not defined in ES module scope') || message.includes('Cannot use import statement outside a module') || message.includes('ERR_REQUIRE_ESM');
|
|
549
|
+
if (looksLikeCommonJsInEsm) try {
|
|
550
|
+
required = loadCommonJsConfigWithStableDirname(absolutePath);
|
|
551
|
+
} catch {
|
|
552
|
+
const tmpDir = external_fs_.mkdtempSync(external_path_.join(external_os_namespaceObject.tmpdir(), 'extension-config-'));
|
|
553
|
+
const tmpCjsPath = external_path_.join(tmpDir, external_path_.basename(absolutePath, external_path_.extname(absolutePath)) + '.cjs');
|
|
554
|
+
external_fs_.copyFileSync(absolutePath, tmpCjsPath);
|
|
555
|
+
required = requireFn(tmpCjsPath);
|
|
556
|
+
}
|
|
557
|
+
else throw requireErr;
|
|
558
|
+
}
|
|
559
|
+
return required?.default || required;
|
|
560
|
+
}
|
|
561
|
+
} catch {}
|
|
562
|
+
try {
|
|
563
|
+
const content = external_fs_.readFileSync(absolutePath, 'utf-8');
|
|
564
|
+
return JSON.parse(content);
|
|
565
|
+
} catch (jsonErr) {
|
|
566
|
+
throw new Error(`Failed to load config file: ${configPath}\nError: ${error.message || error}`);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
async function loadCommandConfig(projectPath, command) {
|
|
571
|
+
const userConfigPath = external_path_.join(projectPath, 'extension.config.js');
|
|
572
|
+
const moduleUserConfigPath = external_path_.join(projectPath, 'extension.config.mjs');
|
|
573
|
+
const commonJsUserConfigPath = external_path_.join(projectPath, 'extension.config.cjs');
|
|
574
|
+
const candidates = [
|
|
575
|
+
userConfigPath,
|
|
576
|
+
moduleUserConfigPath,
|
|
577
|
+
commonJsUserConfigPath
|
|
578
|
+
];
|
|
579
|
+
const configPath = candidates.find((p)=>external_fs_.existsSync(p));
|
|
580
|
+
if (configPath) {
|
|
581
|
+
if (await isUsingExperimentalConfig(projectPath)) try {
|
|
582
|
+
const userConfig = await loadConfigFile(configPath);
|
|
583
|
+
const baseExtensions = userConfig && userConfig.extensions ? {
|
|
584
|
+
extensions: userConfig.extensions
|
|
585
|
+
} : {};
|
|
586
|
+
const baseTranspilePackages = userConfig && Array.isArray(userConfig.transpilePackages) ? {
|
|
587
|
+
transpilePackages: userConfig.transpilePackages
|
|
588
|
+
} : {};
|
|
589
|
+
const perCommand = userConfig && userConfig.commands && userConfig.commands[command] ? userConfig.commands[command] : {};
|
|
590
|
+
return {
|
|
591
|
+
...baseExtensions,
|
|
592
|
+
...baseTranspilePackages,
|
|
593
|
+
...perCommand
|
|
594
|
+
};
|
|
595
|
+
} catch (err) {
|
|
596
|
+
const error = err;
|
|
597
|
+
console.error(webpack_lib_messages.f7(configPath, error));
|
|
598
|
+
throw err;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return {};
|
|
602
|
+
}
|
|
603
|
+
async function loadBrowserConfig(projectPath, browser = 'chrome') {
|
|
604
|
+
const userConfigPath = external_path_.join(projectPath, 'extension.config.js');
|
|
605
|
+
const moduleUserConfigPath = external_path_.join(projectPath, 'extension.config.mjs');
|
|
606
|
+
const commonJsUserConfigPath = external_path_.join(projectPath, 'extension.config.cjs');
|
|
607
|
+
const candidates = [
|
|
608
|
+
userConfigPath,
|
|
609
|
+
moduleUserConfigPath,
|
|
610
|
+
commonJsUserConfigPath
|
|
611
|
+
];
|
|
612
|
+
const configPath = candidates.find((p)=>external_fs_.existsSync(p));
|
|
613
|
+
if (configPath) {
|
|
614
|
+
if (await isUsingExperimentalConfig(projectPath)) try {
|
|
615
|
+
const userConfig = await loadConfigFile(configPath);
|
|
616
|
+
if (userConfig && userConfig.browser) {
|
|
617
|
+
const browsers = userConfig.browser;
|
|
618
|
+
if ('chromium-based' === browser) {
|
|
619
|
+
if (browsers['chromium-based']) return browsers['chromium-based'];
|
|
620
|
+
if (browsers.chromium) return browsers.chromium;
|
|
621
|
+
} else if ('gecko-based' === browser) {
|
|
622
|
+
if (browsers['gecko-based']) return browsers['gecko-based'];
|
|
623
|
+
if (browsers.firefox) return browsers.firefox;
|
|
624
|
+
} else {
|
|
625
|
+
const direct = browsers[browser];
|
|
626
|
+
if (direct) return direct;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
} catch (err) {
|
|
630
|
+
const error = err;
|
|
631
|
+
console.error(webpack_lib_messages.f7(configPath, error));
|
|
632
|
+
throw err;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return {
|
|
636
|
+
browser: browser || 'chrome'
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
let userMessageDelivered = false;
|
|
640
|
+
async function isUsingExperimentalConfig(projectPath) {
|
|
641
|
+
const userConfigPath = external_path_.join(projectPath, 'extension.config.js');
|
|
642
|
+
const moduleUserConfigPath = external_path_.join(projectPath, 'extension.config.mjs');
|
|
643
|
+
const commonJsUserConfigPath = external_path_.join(projectPath, 'extension.config.cjs');
|
|
644
|
+
const candidates = [
|
|
645
|
+
userConfigPath,
|
|
646
|
+
moduleUserConfigPath,
|
|
647
|
+
commonJsUserConfigPath
|
|
648
|
+
];
|
|
649
|
+
const configPath = candidates.find((p)=>external_fs_.existsSync(p));
|
|
650
|
+
if (configPath) {
|
|
651
|
+
if (!userMessageDelivered) {
|
|
652
|
+
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(webpack_lib_messages.BX('extension.config.js'));
|
|
653
|
+
userMessageDelivered = true;
|
|
654
|
+
}
|
|
655
|
+
return true;
|
|
656
|
+
}
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
var package_0 = __webpack_require__("./package.json");
|
|
660
|
+
function assertNoManagedDependencyConflicts(userPackageJsonPath, projectPath) {
|
|
661
|
+
try {
|
|
662
|
+
const raw = external_fs_.readFileSync(userPackageJsonPath, 'utf-8');
|
|
663
|
+
const userPackageJson = JSON.parse(raw);
|
|
664
|
+
const userDeps = Array.from(new Set([
|
|
665
|
+
...Object.keys(userPackageJson.dependencies || {}),
|
|
666
|
+
...Object.keys(userPackageJson.devDependencies || {}),
|
|
667
|
+
...Object.keys(userPackageJson.optionalDependencies || {}),
|
|
668
|
+
...Object.keys(userPackageJson.peerDependencies || {})
|
|
669
|
+
]));
|
|
670
|
+
const managedDeps = new Set([
|
|
671
|
+
...Object.keys(package_0.El || {}),
|
|
672
|
+
...Object.keys(package_0.optionalDependencies || {})
|
|
673
|
+
]);
|
|
674
|
+
managedDeps.delete('webpack');
|
|
675
|
+
const userConfigJs = external_path_.join(projectPath, 'extension.config.js');
|
|
676
|
+
const userConfigMjs = external_path_.join(projectPath, 'extension.config.mjs');
|
|
677
|
+
const hasConfig = external_fs_.existsSync(userConfigJs) || external_fs_.existsSync(userConfigMjs);
|
|
678
|
+
if (!hasConfig) return;
|
|
679
|
+
const configPath = external_fs_.existsSync(userConfigJs) ? userConfigJs : userConfigMjs;
|
|
680
|
+
const configSource = external_fs_.readFileSync(configPath, 'utf-8');
|
|
681
|
+
const duplicates = userDeps.filter((d)=>managedDeps.has(d)).filter((d)=>configSource.includes(d)).sort();
|
|
682
|
+
if (duplicates.length > 0) {
|
|
683
|
+
console.error(webpack_lib_messages.H3(duplicates, userPackageJsonPath));
|
|
684
|
+
process.exit(1);
|
|
685
|
+
}
|
|
686
|
+
} catch (error) {
|
|
687
|
+
if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.warn(error);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
require("crypto");
|
|
691
|
+
(0, external_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
692
|
+
if (!process.env.EXTENSION_JS_OPTIONAL_DEPS_VERSION) process.env.EXTENSION_JS_OPTIONAL_DEPS_VERSION = package_0.rE;
|
|
693
|
+
function asAbsolute(p) {
|
|
694
|
+
return external_path_.isAbsolute(p) ? p : external_path_.resolve(p);
|
|
695
|
+
}
|
|
696
|
+
function getDirs(struct) {
|
|
697
|
+
const manifestDir = asAbsolute(external_path_.dirname(struct.manifestPath));
|
|
698
|
+
const packageJsonDir = asAbsolute(struct.packageJsonPath ? external_path_.dirname(struct.packageJsonPath) : manifestDir);
|
|
699
|
+
return {
|
|
700
|
+
manifestDir,
|
|
701
|
+
packageJsonDir
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
function normalizeBrowser(browser, chromiumBinary, geckoBinary) {
|
|
705
|
+
const requested = String(browser || '');
|
|
706
|
+
if (chromiumBinary) {
|
|
707
|
+
if (!requested || 'chromium-based' === requested) return 'chromium-based';
|
|
708
|
+
if ('chromium' === requested) return 'chromium';
|
|
709
|
+
if ('edge' === requested) return 'edge';
|
|
710
|
+
if ('chrome' === requested) return 'chrome';
|
|
711
|
+
}
|
|
712
|
+
if (geckoBinary) {
|
|
713
|
+
if (!requested || 'gecko-based' === requested || 'firefox-based' === requested) return 'gecko-based';
|
|
714
|
+
if ('firefox' === requested) return 'firefox';
|
|
715
|
+
}
|
|
716
|
+
switch(requested){
|
|
717
|
+
case 'chrome':
|
|
718
|
+
return 'chrome';
|
|
719
|
+
case 'edge':
|
|
720
|
+
return 'edge';
|
|
721
|
+
case 'chromium':
|
|
722
|
+
return 'chromium';
|
|
723
|
+
case 'chromium-based':
|
|
724
|
+
return 'chromium-based';
|
|
725
|
+
case 'firefox':
|
|
726
|
+
return 'firefox';
|
|
727
|
+
case 'gecko-based':
|
|
728
|
+
case 'firefox-based':
|
|
729
|
+
return 'gecko-based';
|
|
730
|
+
default:
|
|
731
|
+
return browser || 'chrome';
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
function getDistPath(packageJsonDir, browser) {
|
|
735
|
+
return asAbsolute(external_path_.join(packageJsonDir, 'dist', browser));
|
|
736
|
+
}
|
|
737
|
+
function computePreviewOutputPath(struct, browser, explicitOutputPath) {
|
|
738
|
+
const { manifestDir, packageJsonDir } = getDirs(struct);
|
|
739
|
+
if (explicitOutputPath) return asAbsolute(explicitOutputPath);
|
|
740
|
+
if (struct.packageJsonPath) {
|
|
741
|
+
const distDir = getDistPath(packageJsonDir, browser);
|
|
742
|
+
try {
|
|
743
|
+
if (external_fs_.existsSync(external_path_.join(distDir, 'manifest.json'))) return distDir;
|
|
744
|
+
} catch {}
|
|
745
|
+
}
|
|
746
|
+
return manifestDir;
|
|
747
|
+
}
|
|
748
|
+
function devtoolsEngineFor(browser) {
|
|
749
|
+
switch(browser){
|
|
750
|
+
case 'chrome':
|
|
751
|
+
return 'chrome';
|
|
752
|
+
case 'edge':
|
|
753
|
+
return 'edge';
|
|
754
|
+
case 'chromium':
|
|
755
|
+
case 'chromium-based':
|
|
756
|
+
return 'chromium';
|
|
757
|
+
case 'firefox':
|
|
758
|
+
case 'gecko-based':
|
|
759
|
+
return 'firefox';
|
|
760
|
+
default:
|
|
761
|
+
return 'chrome';
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
function _define_property(obj, key, value) {
|
|
765
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
766
|
+
value: value,
|
|
767
|
+
enumerable: true,
|
|
768
|
+
configurable: true,
|
|
769
|
+
writable: true
|
|
770
|
+
});
|
|
771
|
+
else obj[key] = value;
|
|
772
|
+
return obj;
|
|
773
|
+
}
|
|
774
|
+
function nowISO() {
|
|
775
|
+
return new Date().toISOString();
|
|
776
|
+
}
|
|
777
|
+
function createRunId() {
|
|
778
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
779
|
+
}
|
|
780
|
+
function plugin_playwright_ensureDirSync(dirPath) {
|
|
781
|
+
try {
|
|
782
|
+
external_fs_.mkdirSync(dirPath, {
|
|
783
|
+
recursive: true
|
|
784
|
+
});
|
|
785
|
+
} catch {}
|
|
786
|
+
}
|
|
787
|
+
function writeJsonAtomic(filePath, value) {
|
|
788
|
+
try {
|
|
789
|
+
const tmpPath = `${filePath}.tmp-${process.pid}`;
|
|
790
|
+
external_fs_.writeFileSync(tmpPath, JSON.stringify(value, null, 2) + '\n', 'utf-8');
|
|
791
|
+
external_fs_.renameSync(tmpPath, filePath);
|
|
792
|
+
} catch {}
|
|
793
|
+
}
|
|
794
|
+
function getPlaywrightMetadataDir(packageJsonDir, browser) {
|
|
795
|
+
return asAbsolute(external_path_.join(packageJsonDir, 'dist', 'extension-js', browser));
|
|
796
|
+
}
|
|
797
|
+
function createPlaywrightMetadataWriter(options) {
|
|
798
|
+
const metadataDir = getPlaywrightMetadataDir(options.packageJsonDir, options.browser);
|
|
799
|
+
const readyPath = asAbsolute(external_path_.join(metadataDir, 'ready.json'));
|
|
800
|
+
const eventsPath = asAbsolute(external_path_.join(metadataDir, 'events.ndjson'));
|
|
801
|
+
const base = {
|
|
802
|
+
command: options.command,
|
|
803
|
+
browser: options.browser,
|
|
804
|
+
runId: createRunId(),
|
|
805
|
+
startedAt: nowISO(),
|
|
806
|
+
distPath: options.distPath,
|
|
807
|
+
manifestPath: options.manifestPath,
|
|
808
|
+
port: (()=>{
|
|
809
|
+
if ('number' == typeof options.port && Number.isFinite(options.port)) return options.port;
|
|
810
|
+
if ('string' == typeof options.port) {
|
|
811
|
+
const parsed = parseInt(options.port, 10);
|
|
812
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
813
|
+
}
|
|
814
|
+
return null;
|
|
815
|
+
})()
|
|
816
|
+
};
|
|
817
|
+
function writeReady(status, extra) {
|
|
818
|
+
plugin_playwright_ensureDirSync(metadataDir);
|
|
819
|
+
const payload = {
|
|
820
|
+
...base,
|
|
821
|
+
status,
|
|
822
|
+
pid: process.pid,
|
|
823
|
+
ts: nowISO(),
|
|
824
|
+
compiledAt: extra?.compiledAt ?? null,
|
|
825
|
+
errors: Array.isArray(extra?.errors) ? extra.errors : []
|
|
826
|
+
};
|
|
827
|
+
if (extra?.code) payload.code = extra.code;
|
|
828
|
+
if (extra?.message) payload.message = extra.message;
|
|
829
|
+
writeJsonAtomic(readyPath, payload);
|
|
830
|
+
}
|
|
831
|
+
function appendEvent(event) {
|
|
832
|
+
plugin_playwright_ensureDirSync(metadataDir);
|
|
833
|
+
try {
|
|
834
|
+
external_fs_.appendFileSync(eventsPath, `${JSON.stringify(event)}\n`, 'utf-8');
|
|
835
|
+
} catch {}
|
|
836
|
+
}
|
|
837
|
+
return {
|
|
838
|
+
metadataDir,
|
|
839
|
+
readyPath,
|
|
840
|
+
eventsPath,
|
|
841
|
+
writeStarting () {
|
|
842
|
+
writeReady('starting');
|
|
843
|
+
},
|
|
844
|
+
writeReady (compiledAt) {
|
|
845
|
+
writeReady('ready', {
|
|
846
|
+
compiledAt: compiledAt || nowISO()
|
|
847
|
+
});
|
|
848
|
+
},
|
|
849
|
+
writeError (code, message, errors) {
|
|
850
|
+
writeReady('error', {
|
|
851
|
+
code,
|
|
852
|
+
message,
|
|
853
|
+
errors: Array.isArray(errors) ? errors : [],
|
|
854
|
+
compiledAt: null
|
|
855
|
+
});
|
|
856
|
+
},
|
|
857
|
+
appendEvent
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
class PlaywrightPlugin {
|
|
861
|
+
apply(compiler) {
|
|
862
|
+
this.writer.writeStarting();
|
|
863
|
+
compiler.hooks.compile.tap(PlaywrightPlugin.name, ()=>{
|
|
864
|
+
this.writer.appendEvent({
|
|
865
|
+
type: 'compile_start',
|
|
866
|
+
ts: nowISO(),
|
|
867
|
+
command: this.command,
|
|
868
|
+
browser: this.browser
|
|
869
|
+
});
|
|
870
|
+
});
|
|
871
|
+
compiler.hooks.done.tap(PlaywrightPlugin.name, (stats)=>{
|
|
872
|
+
const durationMs = Number((stats?.compilation?.endTime || 0) - (stats?.compilation?.startTime || 0));
|
|
873
|
+
const hasErrors = Boolean(stats?.hasErrors?.());
|
|
874
|
+
const errorsCount = Number(Array.isArray(stats?.toJson?.({
|
|
875
|
+
all: false,
|
|
876
|
+
errors: true
|
|
877
|
+
})?.errors) ? stats.toJson({
|
|
878
|
+
all: false,
|
|
879
|
+
errors: true
|
|
880
|
+
}).errors.length : 0);
|
|
881
|
+
if (hasErrors) {
|
|
882
|
+
this.writer.appendEvent({
|
|
883
|
+
type: 'compile_error',
|
|
884
|
+
ts: nowISO(),
|
|
885
|
+
command: this.command,
|
|
886
|
+
browser: this.browser,
|
|
887
|
+
durationMs: Number.isFinite(durationMs) ? durationMs : void 0,
|
|
888
|
+
errorCount: Number.isFinite(errorsCount) ? errorsCount : 1
|
|
889
|
+
});
|
|
890
|
+
this.writer.writeError('compile_error', 'Compilation failed', [
|
|
891
|
+
`errors: ${String(errorsCount || 1)}`
|
|
892
|
+
]);
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
this.writer.appendEvent({
|
|
896
|
+
type: 'compile_success',
|
|
897
|
+
ts: nowISO(),
|
|
898
|
+
command: this.command,
|
|
899
|
+
browser: this.browser,
|
|
900
|
+
durationMs: Number.isFinite(durationMs) ? durationMs : void 0,
|
|
901
|
+
errorCount: 0
|
|
902
|
+
});
|
|
903
|
+
this.writer.writeReady(nowISO());
|
|
904
|
+
});
|
|
905
|
+
compiler.hooks.failed.tap(PlaywrightPlugin.name, (error)=>{
|
|
906
|
+
this.writer.appendEvent({
|
|
907
|
+
type: 'compile_error',
|
|
908
|
+
ts: nowISO(),
|
|
909
|
+
command: this.command,
|
|
910
|
+
browser: this.browser,
|
|
911
|
+
errorCount: 1
|
|
912
|
+
});
|
|
913
|
+
this.writer.writeError('compile_failed', error instanceof Error ? error.message : String(error));
|
|
914
|
+
});
|
|
915
|
+
compiler.hooks.watchClose.tap(PlaywrightPlugin.name, ()=>{
|
|
916
|
+
this.writer.appendEvent({
|
|
917
|
+
type: 'shutdown',
|
|
918
|
+
ts: nowISO(),
|
|
919
|
+
command: this.command,
|
|
920
|
+
browser: this.browser
|
|
921
|
+
});
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
constructor(options){
|
|
925
|
+
_define_property(this, "writer", void 0);
|
|
926
|
+
_define_property(this, "command", void 0);
|
|
927
|
+
_define_property(this, "browser", void 0);
|
|
928
|
+
this.browser = String(options.browser || 'chromium');
|
|
929
|
+
this.command = options.command || ('development' === options.mode ? 'dev' : 'start');
|
|
930
|
+
this.writer = createPlaywrightMetadataWriter({
|
|
931
|
+
packageJsonDir: options.packageJsonDir,
|
|
932
|
+
browser: this.browser,
|
|
933
|
+
command: this.command,
|
|
934
|
+
distPath: options.outputPath,
|
|
935
|
+
manifestPath: options.manifestPath,
|
|
936
|
+
port: options.port
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
_define_property(PlaywrightPlugin, "name", 'plugin-playwright');
|
|
941
|
+
function sanitize(obj) {
|
|
942
|
+
return Object.fromEntries(Object.entries(obj || {}).filter(([, value])=>void 0 !== value));
|
|
943
|
+
}
|
|
944
|
+
const external_extension_from_store_namespaceObject = require("extension-from-store");
|
|
945
|
+
function isDir(p) {
|
|
946
|
+
try {
|
|
947
|
+
return external_fs_.existsSync(p) && external_fs_.statSync(p).isDirectory();
|
|
948
|
+
} catch {
|
|
949
|
+
return false;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
function isFile(p) {
|
|
953
|
+
try {
|
|
954
|
+
return external_fs_.existsSync(p) && external_fs_.statSync(p).isFile();
|
|
955
|
+
} catch {
|
|
956
|
+
return false;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
function toAbs(projectRoot, p) {
|
|
960
|
+
return external_path_.isAbsolute(p) ? p : external_path_.resolve(projectRoot, p);
|
|
961
|
+
}
|
|
962
|
+
function isValidExtensionRoot(dir) {
|
|
963
|
+
if (!isDir(dir)) return false;
|
|
964
|
+
return isFile(external_path_.join(dir, 'manifest.json'));
|
|
965
|
+
}
|
|
966
|
+
function normalizeCompanionConfig(config) {
|
|
967
|
+
const explicitPaths = [];
|
|
968
|
+
let scanDir;
|
|
969
|
+
if (Array.isArray(config)) explicitPaths.push(...config.filter((p)=>'string' == typeof p));
|
|
970
|
+
else if (config && 'object' == typeof config) {
|
|
971
|
+
if (Array.isArray(config.paths)) explicitPaths.push(...config.paths.filter((p)=>'string' == typeof p));
|
|
972
|
+
if ('string' == typeof config.dir && config.dir.trim().length > 0) scanDir = config.dir.trim();
|
|
973
|
+
}
|
|
974
|
+
return {
|
|
975
|
+
dir: scanDir,
|
|
976
|
+
paths: explicitPaths
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
function isPathLike(value) {
|
|
980
|
+
if (external_path_.isAbsolute(value)) return true;
|
|
981
|
+
if (value.startsWith('./') || value.startsWith('../')) return true;
|
|
982
|
+
return value.includes('/') || value.includes('\\');
|
|
983
|
+
}
|
|
984
|
+
function isSubpathOf(parent, child) {
|
|
985
|
+
const rel = external_path_.relative(parent, child);
|
|
986
|
+
return '' !== rel && !rel.startsWith('..') && !external_path_.isAbsolute(rel);
|
|
987
|
+
}
|
|
988
|
+
function getBrowserFolder(browser) {
|
|
989
|
+
if ('firefox' === browser || 'gecko-based' === browser || 'firefox-based' === browser) return 'firefox';
|
|
990
|
+
if ('edge' === browser) return 'edge';
|
|
991
|
+
return 'chrome';
|
|
992
|
+
}
|
|
993
|
+
function parseChromeWebStoreId(url) {
|
|
994
|
+
if ('chromewebstore.google.com' !== url.hostname) return null;
|
|
995
|
+
const match = url.pathname.match(/\/([a-z]{32})(?:\/|$)/i);
|
|
996
|
+
return match ? match[1] : null;
|
|
997
|
+
}
|
|
998
|
+
function parseEdgeAddonsId(url) {
|
|
999
|
+
if ('microsoftedge.microsoft.com' !== url.hostname) return null;
|
|
1000
|
+
const match = url.pathname.match(/\/([a-z]{32})(?:\/|$)/i);
|
|
1001
|
+
return match ? match[1] : null;
|
|
1002
|
+
}
|
|
1003
|
+
function parseAmoSlug(url) {
|
|
1004
|
+
if ('addons.mozilla.org' !== url.hostname) return null;
|
|
1005
|
+
const match = url.pathname.match(/\/addon\/([^/]+)(?:\/|$)/i);
|
|
1006
|
+
return match ? match[1] : null;
|
|
1007
|
+
}
|
|
1008
|
+
function parseStoreUrl(raw) {
|
|
1009
|
+
let url;
|
|
1010
|
+
try {
|
|
1011
|
+
url = new URL(raw);
|
|
1012
|
+
} catch {
|
|
1013
|
+
return null;
|
|
1014
|
+
}
|
|
1015
|
+
const chromeId = parseChromeWebStoreId(url);
|
|
1016
|
+
if (chromeId) return {
|
|
1017
|
+
browser: 'chrome',
|
|
1018
|
+
id: chromeId
|
|
1019
|
+
};
|
|
1020
|
+
const edgeId = parseEdgeAddonsId(url);
|
|
1021
|
+
if (edgeId) return {
|
|
1022
|
+
browser: 'edge',
|
|
1023
|
+
id: edgeId
|
|
1024
|
+
};
|
|
1025
|
+
const amoSlug = parseAmoSlug(url);
|
|
1026
|
+
if (amoSlug) return {
|
|
1027
|
+
browser: 'firefox',
|
|
1028
|
+
id: amoSlug
|
|
1029
|
+
};
|
|
1030
|
+
return null;
|
|
1031
|
+
}
|
|
1032
|
+
function ensurePathsUnderExtensions(projectRoot, paths) {
|
|
1033
|
+
const extensionsRoot = external_path_.resolve(projectRoot, 'extensions');
|
|
1034
|
+
return paths.map((p)=>{
|
|
1035
|
+
const abs = toAbs(projectRoot, p);
|
|
1036
|
+
if (abs !== extensionsRoot && !isSubpathOf(extensionsRoot, abs) && external_path_.resolve(abs) !== extensionsRoot) throw new Error(`Companion extensions must be inside ${extensionsRoot}.\nInvalid path: ${abs}`);
|
|
1037
|
+
return abs;
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
function findExtensionRoots(dir, maxDepth = 3) {
|
|
1041
|
+
const found = [];
|
|
1042
|
+
function walk(current, depth) {
|
|
1043
|
+
if (depth > maxDepth) return;
|
|
1044
|
+
if (!isDir(current)) return;
|
|
1045
|
+
if (isValidExtensionRoot(current)) return void found.push(current);
|
|
1046
|
+
let entries = [];
|
|
1047
|
+
try {
|
|
1048
|
+
entries = external_fs_.readdirSync(current, {
|
|
1049
|
+
withFileTypes: true
|
|
1050
|
+
});
|
|
1051
|
+
} catch {
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
for (const ent of entries)if (ent.isDirectory()) {
|
|
1055
|
+
if (!ent.name.startsWith('.')) walk(external_path_.join(current, ent.name), depth + 1);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
walk(dir, 0);
|
|
1059
|
+
return found;
|
|
1060
|
+
}
|
|
1061
|
+
async function runExtensionFromStore(url, outDir) {
|
|
1062
|
+
const isAuthor = 'true' === process.env.EXTENSION_AUTHOR_MODE;
|
|
1063
|
+
await (0, external_extension_from_store_namespaceObject.fetchExtensionFromStore)(url, {
|
|
1064
|
+
outDir,
|
|
1065
|
+
extract: true,
|
|
1066
|
+
logger: isAuthor ? {
|
|
1067
|
+
onInfo: (message)=>console.log(message),
|
|
1068
|
+
onWarn: (message)=>console.warn(message),
|
|
1069
|
+
onError: (message, error)=>console.error(message, error)
|
|
1070
|
+
} : void 0
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
async function resolveStoreExtensionToPath(opts) {
|
|
1074
|
+
const { projectRoot, storeUrl, browser, id } = opts;
|
|
1075
|
+
const extensionsRoot = external_path_.resolve(projectRoot, 'extensions');
|
|
1076
|
+
const targetRoot = external_path_.join(extensionsRoot, browser, id);
|
|
1077
|
+
const manifestPath = external_path_.join(targetRoot, 'manifest.json');
|
|
1078
|
+
if (isFile(manifestPath)) return targetRoot;
|
|
1079
|
+
await runExtensionFromStore(storeUrl, external_path_.join(extensionsRoot, browser));
|
|
1080
|
+
const candidates = findExtensionRoots(external_path_.join(extensionsRoot, browser));
|
|
1081
|
+
let selected;
|
|
1082
|
+
if (1 === candidates.length) selected = candidates[0];
|
|
1083
|
+
else if (candidates.length > 1) {
|
|
1084
|
+
const directMatch = candidates.find((c)=>external_path_.basename(c) === id);
|
|
1085
|
+
const versionedMatch = candidates.find((c)=>external_path_.basename(c).startsWith(`${id}@`));
|
|
1086
|
+
if (directMatch) selected = directMatch;
|
|
1087
|
+
else if (versionedMatch) selected = versionedMatch;
|
|
1088
|
+
}
|
|
1089
|
+
if (!selected) throw new Error(`Could not locate an unpacked extension from ${storeUrl}.`);
|
|
1090
|
+
external_fs_.mkdirSync(external_path_.dirname(targetRoot), {
|
|
1091
|
+
recursive: true
|
|
1092
|
+
});
|
|
1093
|
+
if (external_path_.basename(selected).startsWith(`${id}@`)) external_fs_.renameSync(selected, targetRoot);
|
|
1094
|
+
return targetRoot;
|
|
1095
|
+
}
|
|
1096
|
+
async function resolveCompanionExtensionsConfig(opts) {
|
|
1097
|
+
const { projectRoot, browser, config } = opts;
|
|
1098
|
+
if (!config) return;
|
|
1099
|
+
const normalized = normalizeCompanionConfig(config);
|
|
1100
|
+
const runtimeBrowser = getBrowserFolder(browser);
|
|
1101
|
+
const resolvedPaths = [];
|
|
1102
|
+
const localPaths = [];
|
|
1103
|
+
for (const entry of normalized.paths){
|
|
1104
|
+
const parsedStore = parseStoreUrl(entry);
|
|
1105
|
+
if (parsedStore) {
|
|
1106
|
+
if (parsedStore.browser !== runtimeBrowser) continue;
|
|
1107
|
+
const resolvedPath = await resolveStoreExtensionToPath({
|
|
1108
|
+
projectRoot,
|
|
1109
|
+
storeUrl: entry,
|
|
1110
|
+
browser: parsedStore.browser,
|
|
1111
|
+
id: parsedStore.id
|
|
1112
|
+
});
|
|
1113
|
+
resolvedPaths.push(resolvedPath);
|
|
1114
|
+
continue;
|
|
1115
|
+
}
|
|
1116
|
+
if (isPathLike(entry)) localPaths.push(entry);
|
|
1117
|
+
}
|
|
1118
|
+
if (localPaths.length > 0) {
|
|
1119
|
+
const absLocalPaths = ensurePathsUnderExtensions(projectRoot, localPaths);
|
|
1120
|
+
resolvedPaths.push(...absLocalPaths);
|
|
1121
|
+
}
|
|
1122
|
+
const output = {};
|
|
1123
|
+
if ('string' == typeof normalized.dir) {
|
|
1124
|
+
const absDir = toAbs(projectRoot, normalized.dir);
|
|
1125
|
+
const extensionsRoot = external_path_.resolve(projectRoot, 'extensions');
|
|
1126
|
+
if (absDir !== extensionsRoot && !isSubpathOf(extensionsRoot, absDir)) throw new Error(`extensions.dir must be inside ${extensionsRoot}.\nInvalid dir: ${absDir}`);
|
|
1127
|
+
output.dir = normalized.dir;
|
|
1128
|
+
}
|
|
1129
|
+
if (resolvedPaths.length > 0) output.paths = resolvedPaths;
|
|
1130
|
+
return output;
|
|
1131
|
+
}
|
|
1132
|
+
function resolveCompanionExtensionDirs(opts) {
|
|
1133
|
+
const { projectRoot, config } = opts;
|
|
1134
|
+
const normalized = normalizeCompanionConfig(config);
|
|
1135
|
+
const explicitPaths = normalized.paths;
|
|
1136
|
+
const scanDir = normalized.dir;
|
|
1137
|
+
const found = [];
|
|
1138
|
+
for (const p of explicitPaths){
|
|
1139
|
+
const abs = toAbs(projectRoot, p);
|
|
1140
|
+
if (isValidExtensionRoot(abs)) found.push(abs);
|
|
1141
|
+
}
|
|
1142
|
+
if (scanDir) {
|
|
1143
|
+
const absScan = toAbs(projectRoot, scanDir);
|
|
1144
|
+
if (isDir(absScan)) {
|
|
1145
|
+
let entries = [];
|
|
1146
|
+
try {
|
|
1147
|
+
entries = external_fs_.readdirSync(absScan, {
|
|
1148
|
+
withFileTypes: true
|
|
1149
|
+
});
|
|
1150
|
+
} catch {
|
|
1151
|
+
entries = [];
|
|
1152
|
+
}
|
|
1153
|
+
const scanOneLevel = (rootDir)=>{
|
|
1154
|
+
let dirEntries = [];
|
|
1155
|
+
try {
|
|
1156
|
+
dirEntries = external_fs_.readdirSync(rootDir, {
|
|
1157
|
+
withFileTypes: true
|
|
1158
|
+
});
|
|
1159
|
+
} catch {
|
|
1160
|
+
dirEntries = [];
|
|
1161
|
+
}
|
|
1162
|
+
for (const ent of dirEntries){
|
|
1163
|
+
if (!ent.isDirectory()) continue;
|
|
1164
|
+
if (ent.name.startsWith('.')) continue;
|
|
1165
|
+
const candidate = external_path_.join(rootDir, ent.name);
|
|
1166
|
+
if (isValidExtensionRoot(candidate)) found.push(candidate);
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
scanOneLevel(absScan);
|
|
1170
|
+
if ('extensions' === external_path_.basename(absScan)) for (const ent of entries){
|
|
1171
|
+
if (!ent.isDirectory()) continue;
|
|
1172
|
+
if (ent.name.startsWith('.')) continue;
|
|
1173
|
+
const browserDir = external_path_.join(absScan, ent.name);
|
|
1174
|
+
scanOneLevel(browserDir);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
const unique = [];
|
|
1179
|
+
const seen = new Set();
|
|
1180
|
+
for (const p of found)if (!seen.has(p)) {
|
|
1181
|
+
seen.add(p);
|
|
1182
|
+
unique.push(p);
|
|
1183
|
+
}
|
|
1184
|
+
return unique;
|
|
1185
|
+
}
|
|
1186
|
+
const external_browser_extension_manifest_fields_namespaceObject = require("browser-extension-manifest-fields");
|
|
1187
|
+
function isUnderPublicDir(entry, projectRoot, publicDir) {
|
|
1188
|
+
if (!entry) return false;
|
|
1189
|
+
const normalizedEntry = String(entry);
|
|
1190
|
+
const candidate = external_path_default().isAbsolute(normalizedEntry) ? normalizedEntry : external_path_default().join(projectRoot, normalizedEntry);
|
|
1191
|
+
const rel = external_path_default().relative(publicDir, candidate);
|
|
1192
|
+
return Boolean(rel && !rel.startsWith('..') && !external_path_default().isAbsolute(rel));
|
|
1193
|
+
}
|
|
1194
|
+
function filterPublicEntrypoints(list, projectRoot, publicDir) {
|
|
1195
|
+
const next = {};
|
|
1196
|
+
for (const [key, value] of Object.entries(list || {})){
|
|
1197
|
+
if (Array.isArray(value)) {
|
|
1198
|
+
const filtered = value.filter((entry)=>!isUnderPublicDir(String(entry), projectRoot, publicDir));
|
|
1199
|
+
if (filtered.length > 0) next[key] = filtered;
|
|
1200
|
+
continue;
|
|
1201
|
+
}
|
|
1202
|
+
if ('string' == typeof value) {
|
|
1203
|
+
if (!isUnderPublicDir(value, projectRoot, publicDir)) next[key] = value;
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
return next;
|
|
1208
|
+
}
|
|
1209
|
+
function getSpecialFoldersDataForProjectRoot(projectRoot) {
|
|
1210
|
+
const publicDir = external_path_default().join(projectRoot, 'public');
|
|
1211
|
+
const data = (0, external_browser_extension_manifest_fields_namespaceObject.getSpecialFoldersData)({
|
|
1212
|
+
manifestPath: external_path_default().join(projectRoot, 'package.json')
|
|
1213
|
+
});
|
|
1214
|
+
return finalizeSpecialFoldersData(data, projectRoot, publicDir);
|
|
1215
|
+
}
|
|
1216
|
+
function finalizeSpecialFoldersData(data, projectRoot, publicDir) {
|
|
1217
|
+
return {
|
|
1218
|
+
...data,
|
|
1219
|
+
pages: filterPublicEntrypoints(data.pages, projectRoot, publicDir),
|
|
1220
|
+
scripts: filterPublicEntrypoints(data.scripts, projectRoot, publicDir),
|
|
1221
|
+
extensions: {
|
|
1222
|
+
dir: './extensions'
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
function hasNewTabOverride(extensionDir) {
|
|
1227
|
+
const manifestPath = external_path_.join(extensionDir, 'manifest.json');
|
|
1228
|
+
if (!external_fs_.existsSync(manifestPath)) return false;
|
|
1229
|
+
try {
|
|
1230
|
+
const raw = external_fs_.readFileSync(manifestPath, 'utf-8');
|
|
1231
|
+
const manifest = JSON.parse(raw);
|
|
1232
|
+
const newtab = manifest?.chrome_url_overrides?.newtab;
|
|
1233
|
+
return 'string' == typeof newtab && newtab.trim().length > 0;
|
|
1234
|
+
} catch {
|
|
1235
|
+
return false;
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
function resolveBuiltInExtensionForBrowser(input) {
|
|
1239
|
+
const engine = devtoolsEngineFor(input.browser);
|
|
1240
|
+
const packageRelativeCandidates = [
|
|
1241
|
+
external_path_.join('dist', input.packageName, engine)
|
|
1242
|
+
];
|
|
1243
|
+
const normalizedBaseDir = external_path_.normalize(input.baseDir);
|
|
1244
|
+
const parentName = external_path_.basename(external_path_.dirname(normalizedBaseDir));
|
|
1245
|
+
const baseName = external_path_.basename(normalizedBaseDir);
|
|
1246
|
+
if ('programs' === parentName && 'develop' === baseName) packageRelativeCandidates.push(external_path_.join('..', '..', 'extensions', input.packageName, 'dist', engine));
|
|
1247
|
+
for (const rel of packageRelativeCandidates){
|
|
1248
|
+
const candidate = external_path_.resolve(input.baseDir, rel);
|
|
1249
|
+
if (external_fs_.existsSync(candidate)) return candidate;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
function computeExtensionsToLoad(baseDir, mode, browser, userExtensionOutputPath, extraExtensionDirs = [], userManifestPath) {
|
|
1253
|
+
const list = [];
|
|
1254
|
+
try {
|
|
1255
|
+
const devtoolsForBrowser = resolveBuiltInExtensionForBrowser({
|
|
1256
|
+
baseDir,
|
|
1257
|
+
packageName: 'extension-js-devtools',
|
|
1258
|
+
browser
|
|
1259
|
+
});
|
|
1260
|
+
const themeForBrowser = resolveBuiltInExtensionForBrowser({
|
|
1261
|
+
baseDir,
|
|
1262
|
+
packageName: 'extension-js-theme',
|
|
1263
|
+
browser
|
|
1264
|
+
});
|
|
1265
|
+
const userHasNewTabOverride = hasNewTabOverride(userExtensionOutputPath) || ('string' == typeof userManifestPath ? hasNewTabOverride(external_path_.dirname(userManifestPath)) : false);
|
|
1266
|
+
const devtoolsHasNewTabOverride = devtoolsForBrowser ? hasNewTabOverride(devtoolsForBrowser) : false;
|
|
1267
|
+
const shouldSkipDevtoolsForNtpConflict = userHasNewTabOverride && devtoolsHasNewTabOverride;
|
|
1268
|
+
if (devtoolsForBrowser && !shouldSkipDevtoolsForNtpConflict) list.push(devtoolsForBrowser);
|
|
1269
|
+
if (themeForBrowser) list.push(themeForBrowser);
|
|
1270
|
+
} catch {}
|
|
1271
|
+
for (const p of extraExtensionDirs)list.push(p);
|
|
1272
|
+
list.push(userExtensionOutputPath);
|
|
1273
|
+
return list;
|
|
1274
|
+
}
|
|
1275
|
+
function getDarkModeDefaults(browser) {
|
|
1276
|
+
if ('chrome' === browser || 'edge' === browser || 'chromium' === browser || 'chromium-based' === browser) return {
|
|
1277
|
+
browserFlags: [
|
|
1278
|
+
'--force-dark-mode',
|
|
1279
|
+
'--enable-features=WebUIDarkMode'
|
|
1280
|
+
],
|
|
1281
|
+
preferences: {}
|
|
1282
|
+
};
|
|
1283
|
+
if ('firefox' === browser || 'gecko-based' === browser || 'firefox-based' === browser) return {
|
|
1284
|
+
browserFlags: [],
|
|
1285
|
+
preferences: {
|
|
1286
|
+
'ui.systemUsesDarkTheme': 1,
|
|
1287
|
+
'layout.css.prefers-color-scheme.content-override': 2,
|
|
1288
|
+
'devtools.theme': 'dark'
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
return {
|
|
1292
|
+
browserFlags: [],
|
|
1293
|
+
preferences: {}
|
|
1294
|
+
};
|
|
1295
|
+
}
|
|
1296
|
+
function withDarkMode(config) {
|
|
1297
|
+
const defaults = getDarkModeDefaults(config.browser);
|
|
1298
|
+
const existingFlags = Array.isArray(config.browserFlags) ? [
|
|
1299
|
+
...config.browserFlags
|
|
1300
|
+
] : [];
|
|
1301
|
+
const nextFlags = [
|
|
1302
|
+
...existingFlags
|
|
1303
|
+
];
|
|
1304
|
+
for (const flag of defaults.browserFlags || [])if (!nextFlags.some((f)=>String(f).trim() === flag)) nextFlags.push(flag);
|
|
1305
|
+
const nextPreferences = {
|
|
1306
|
+
...config.preferences || {},
|
|
1307
|
+
...Object.fromEntries(Object.entries(defaults.preferences || {}).filter(([k])=>!(k in (config.preferences || {}))))
|
|
1308
|
+
};
|
|
1309
|
+
return {
|
|
1310
|
+
...config,
|
|
1311
|
+
browserFlags: nextFlags,
|
|
1312
|
+
preferences: nextPreferences
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
var external_pintor_ = __webpack_require__("pintor");
|
|
1316
|
+
var external_pintor_default = /*#__PURE__*/ __webpack_require__.n(external_pintor_);
|
|
1317
|
+
function readJsonRecord(filePath) {
|
|
1318
|
+
try {
|
|
1319
|
+
return JSON.parse(external_fs_.readFileSync(filePath, 'utf8'));
|
|
1320
|
+
} catch {
|
|
1321
|
+
return null;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
function capitalizeToken(value) {
|
|
1325
|
+
return value.split('-').filter(Boolean).map((token)=>token.charAt(0).toUpperCase() + token.slice(1)).join('-');
|
|
1326
|
+
}
|
|
1327
|
+
function getExtensionVersion() {
|
|
1328
|
+
return process.env.EXTENSION_DEVELOP_VERSION || process.env.EXTENSION_CLI_VERSION || (()=>{
|
|
1329
|
+
try {
|
|
1330
|
+
return __webpack_require__("./package.json").rE;
|
|
1331
|
+
} catch {
|
|
1332
|
+
return 'unknown';
|
|
1333
|
+
}
|
|
1334
|
+
})();
|
|
1335
|
+
}
|
|
1336
|
+
function browserRunnerDisabled(args) {
|
|
1337
|
+
const manifest = readJsonRecord(args.manifestPath);
|
|
1338
|
+
const ready = readJsonRecord(args.readyPath);
|
|
1339
|
+
const browserLabel = capitalizeToken(String(args.browser || 'unknown'));
|
|
1340
|
+
const runId = String(ready?.runId || '').trim();
|
|
1341
|
+
const pid = Number.isInteger(ready?.pid) ? String(ready?.pid) : '';
|
|
1342
|
+
const runLabel = runId ? `${external_pintor_default().gray(runId)}${pid ? ` · ${external_pintor_default().gray(`PID ${pid}`)}` : ''}` : pid ? external_pintor_default().gray(`PID ${pid}`) : external_pintor_default().gray('n/a');
|
|
1343
|
+
const extensionName = String(manifest?.name || 'Extension');
|
|
1344
|
+
const extensionVersion = String(manifest?.version || '').trim();
|
|
1345
|
+
const extensionLabel = extensionVersion ? `${extensionName} ${extensionVersion}` : extensionName;
|
|
1346
|
+
const extensionJsVersion = getExtensionVersion();
|
|
1347
|
+
return [
|
|
1348
|
+
` 🧩 ${external_pintor_default().brightBlue('Extension.js')} ${external_pintor_default().gray(extensionJsVersion)}`,
|
|
1349
|
+
` Browser ${external_pintor_default().gray(args.browserModeLabel || `${browserLabel} (build-only mode)`)}`,
|
|
1350
|
+
` Extension ${external_pintor_default().gray(extensionLabel)}`,
|
|
1351
|
+
` Run ID ${runLabel}`
|
|
1352
|
+
].join('\n');
|
|
1353
|
+
}
|
|
1354
|
+
function spacerLine() {
|
|
1355
|
+
return ' ';
|
|
1356
|
+
}
|
|
1357
|
+
async function extensionPreview(pathOrRemoteUrl, previewOptions, browserLauncher) {
|
|
1358
|
+
const projectStructure = await getProjectStructure(pathOrRemoteUrl);
|
|
1359
|
+
const debug = 'true' === process.env.EXTENSION_AUTHOR_MODE;
|
|
1360
|
+
const { manifestDir, packageJsonDir } = getDirs(projectStructure);
|
|
1361
|
+
if (projectStructure.packageJsonPath) assertNoManagedDependencyConflicts(projectStructure.packageJsonPath, packageJsonDir);
|
|
1362
|
+
const browser = normalizeBrowser(previewOptions.browser || 'chrome', previewOptions.chromiumBinary, previewOptions.geckoBinary || previewOptions.firefoxBinary);
|
|
1363
|
+
const outputPath = computePreviewOutputPath(projectStructure, browser, previewOptions.outputPath);
|
|
1364
|
+
const distPath = getDistPath(packageJsonDir, browser);
|
|
1365
|
+
const metadataCommand = 'start' === previewOptions.metadataCommand ? 'start' : 'preview';
|
|
1366
|
+
const metadata = createPlaywrightMetadataWriter({
|
|
1367
|
+
packageJsonDir,
|
|
1368
|
+
browser: String(browser),
|
|
1369
|
+
command: metadataCommand,
|
|
1370
|
+
distPath,
|
|
1371
|
+
manifestPath: projectStructure.manifestPath,
|
|
1372
|
+
port: 'number' == typeof previewOptions.port ? previewOptions.port : 'string' == typeof previewOptions.port ? parseInt(previewOptions.port, 10) : null
|
|
1373
|
+
});
|
|
1374
|
+
metadata.writeStarting();
|
|
1375
|
+
if (debug) {
|
|
1376
|
+
console.log(webpack_lib_messages.SG(manifestDir, packageJsonDir));
|
|
1377
|
+
console.log(webpack_lib_messages._A(browser, previewOptions.chromiumBinary, previewOptions.geckoBinary || previewOptions.firefoxBinary));
|
|
1378
|
+
console.log(webpack_lib_messages.jV(outputPath, distPath));
|
|
1379
|
+
}
|
|
1380
|
+
const manifestAtOutput = external_path_.join(outputPath, 'manifest.json');
|
|
1381
|
+
if (!external_fs_.existsSync(manifestAtOutput)) {
|
|
1382
|
+
metadata.writeError('preview_manifest_missing', `Expected manifest at ${manifestAtOutput}`);
|
|
1383
|
+
throw new Error(`Preview is run-only and does not compile.\nExpected an unpacked extension at:\n ${manifestAtOutput}\n\nRun \`extension build\` or \`extension dev\` first, or pass --output-path to an existing unpacked extension directory.`);
|
|
1384
|
+
}
|
|
1385
|
+
const commandConfig = await loadCommandConfig(packageJsonDir, 'preview');
|
|
1386
|
+
const browserConfig = await loadBrowserConfig(packageJsonDir, browser);
|
|
1387
|
+
console.log(webpack_lib_messages.V_(browser));
|
|
1388
|
+
if (previewOptions.noBrowser) {
|
|
1389
|
+
console.log(webpack_lib_messages.k4(browser));
|
|
1390
|
+
metadata.writeReady();
|
|
1391
|
+
console.log(spacerLine());
|
|
1392
|
+
const browserLabel = String(browser || 'unknown');
|
|
1393
|
+
console.log(browserRunnerDisabled({
|
|
1394
|
+
browser: browserLabel,
|
|
1395
|
+
manifestPath: projectStructure.manifestPath,
|
|
1396
|
+
readyPath: metadata.readyPath,
|
|
1397
|
+
browserModeLabel: `${browserLabel.charAt(0).toUpperCase() + browserLabel.slice(1)} (no-browser mode)`
|
|
1398
|
+
}));
|
|
1399
|
+
return;
|
|
1400
|
+
}
|
|
1401
|
+
const safeBrowserConfig = sanitize(browserConfig);
|
|
1402
|
+
const safeCommandConfig = sanitize(commandConfig);
|
|
1403
|
+
const safePreviewOptions = sanitize(previewOptions);
|
|
1404
|
+
const specialFoldersData = getSpecialFoldersDataForProjectRoot(packageJsonDir);
|
|
1405
|
+
const mergedExtensionsConfig = safePreviewOptions.extensions ?? safeCommandConfig.extensions ?? safeBrowserConfig.extensions ?? specialFoldersData.extensions;
|
|
1406
|
+
const resolvedExtensionsConfig = await resolveCompanionExtensionsConfig({
|
|
1407
|
+
projectRoot: packageJsonDir,
|
|
1408
|
+
browser,
|
|
1409
|
+
config: mergedExtensionsConfig
|
|
1410
|
+
});
|
|
1411
|
+
const mergedGeckoBinary = safePreviewOptions.geckoBinary || safePreviewOptions.firefoxBinary || safeCommandConfig.geckoBinary || safeCommandConfig.firefoxBinary || safeBrowserConfig.geckoBinary || safeBrowserConfig.firefoxBinary;
|
|
1412
|
+
const mergedChromiumBinary = safePreviewOptions.chromiumBinary || safeCommandConfig.chromiumBinary || safeBrowserConfig.chromiumBinary;
|
|
1413
|
+
const merged = {
|
|
1414
|
+
...safeBrowserConfig,
|
|
1415
|
+
...safeCommandConfig,
|
|
1416
|
+
...safePreviewOptions,
|
|
1417
|
+
extensions: resolvedExtensionsConfig,
|
|
1418
|
+
chromiumBinary: mergedChromiumBinary,
|
|
1419
|
+
geckoBinary: mergedGeckoBinary
|
|
1420
|
+
};
|
|
1421
|
+
const darkDefaults = withDarkMode({
|
|
1422
|
+
browser,
|
|
1423
|
+
browserFlags: merged.browserFlags,
|
|
1424
|
+
preferences: merged.preferences
|
|
1425
|
+
});
|
|
1426
|
+
const companionUnpackedExtensionDirs = resolveCompanionExtensionDirs({
|
|
1427
|
+
projectRoot: packageJsonDir,
|
|
1428
|
+
config: merged.extensions
|
|
1429
|
+
});
|
|
1430
|
+
const unpackedExtensionDirsToLoad = computeExtensionsToLoad(external_path_.resolve(__dirname, '..'), 'production', browser, outputPath, companionUnpackedExtensionDirs, projectStructure.manifestPath);
|
|
1431
|
+
const resolvedOpts = {
|
|
1432
|
+
browser,
|
|
1433
|
+
outPath: outputPath,
|
|
1434
|
+
contextDir: packageJsonDir,
|
|
1435
|
+
readyPath: metadata.readyPath,
|
|
1436
|
+
extensionsToLoad: unpackedExtensionDirsToLoad,
|
|
1437
|
+
noOpen: merged.noOpen,
|
|
1438
|
+
profile: merged.profile,
|
|
1439
|
+
persistProfile: merged.persistProfile,
|
|
1440
|
+
preferences: darkDefaults.preferences,
|
|
1441
|
+
browserFlags: darkDefaults.browserFlags,
|
|
1442
|
+
excludeBrowserFlags: merged.excludeBrowserFlags,
|
|
1443
|
+
startingUrl: merged.startingUrl,
|
|
1444
|
+
chromiumBinary: merged.chromiumBinary,
|
|
1445
|
+
geckoBinary: merged.geckoBinary,
|
|
1446
|
+
instanceId: merged.instanceId,
|
|
1447
|
+
port: merged.port,
|
|
1448
|
+
dryRun: merged.dryRun
|
|
1449
|
+
};
|
|
1450
|
+
if (!browserLauncher) throw new Error("extensionPreview requires a browserLauncher callback. The browser launch code has moved to programs/browser/.");
|
|
1451
|
+
await browserLauncher(resolvedOpts);
|
|
1452
|
+
metadata.writeReady();
|
|
1453
|
+
}
|
|
1454
|
+
})();
|
|
1455
|
+
exports.extensionPreview = __webpack_exports__.extensionPreview;
|
|
1456
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
1457
|
+
"extensionPreview"
|
|
1458
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
1459
|
+
Object.defineProperty(exports, '__esModule', {
|
|
1460
|
+
value: true
|
|
1461
|
+
});
|