extension-develop 3.9.0-next.3 → 3.9.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/{946.cjs → 270.cjs} +6050 -5966
- package/dist/323.cjs +35 -16
- package/dist/324.cjs +146 -12
- package/dist/552.cjs +1 -1
- package/dist/module.cjs +108 -22
- package/dist/warn-no-default-export.cjs +74 -30
- package/package.json +1 -1
|
@@ -1,4 +1,7 @@
|
|
|
1
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
|
+
}();
|
|
2
5
|
var __webpack_require__ = {};
|
|
3
6
|
(()=>{
|
|
4
7
|
__webpack_require__.n = (module)=>{
|
|
@@ -64,6 +67,38 @@ function findNearestPackageJsonSync(manifestPath) {
|
|
|
64
67
|
return null;
|
|
65
68
|
}
|
|
66
69
|
}
|
|
70
|
+
require("os");
|
|
71
|
+
require("pintor");
|
|
72
|
+
const external_module_namespaceObject = require("module");
|
|
73
|
+
(0, external_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
74
|
+
require("crypto");
|
|
75
|
+
require("child_process");
|
|
76
|
+
(0, external_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
77
|
+
function parseJsonSafe(text) {
|
|
78
|
+
const s = text && 0xfeff === text.charCodeAt(0) ? text.slice(1) : text;
|
|
79
|
+
return JSON.parse(s || '{}');
|
|
80
|
+
}
|
|
81
|
+
function hasDependency(projectPath, dependency) {
|
|
82
|
+
const findNearestPackageJsonDirectory = (startPath)=>{
|
|
83
|
+
let currentDirectory = startPath;
|
|
84
|
+
const maxDepth = 4;
|
|
85
|
+
for(let i = 0; i < maxDepth; i++){
|
|
86
|
+
const candidate = external_path_namespaceObject.join(currentDirectory, 'package.json');
|
|
87
|
+
if (external_fs_namespaceObject.existsSync(candidate)) return currentDirectory;
|
|
88
|
+
const parentDirectory = external_path_namespaceObject.dirname(currentDirectory);
|
|
89
|
+
if (parentDirectory === currentDirectory) break;
|
|
90
|
+
currentDirectory = parentDirectory;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const packageJsonDirectory = findNearestPackageJsonDirectory(projectPath);
|
|
94
|
+
if (!packageJsonDirectory) return false;
|
|
95
|
+
const packageJsonPath = external_path_namespaceObject.join(packageJsonDirectory, 'package.json');
|
|
96
|
+
if (!external_fs_namespaceObject.existsSync(packageJsonPath)) return false;
|
|
97
|
+
const packageJson = parseJsonSafe(external_fs_namespaceObject.readFileSync(packageJsonPath, 'utf8'));
|
|
98
|
+
const dependencies = packageJson.dependencies || {};
|
|
99
|
+
const devDependencies = packageJson.devDependencies || {};
|
|
100
|
+
return !!dependencies[dependency] || !!devDependencies[dependency];
|
|
101
|
+
}
|
|
67
102
|
const core_namespaceObject = require("@swc/core");
|
|
68
103
|
const external_schema_utils_namespaceObject = require("schema-utils");
|
|
69
104
|
const schema = {
|
|
@@ -80,6 +115,34 @@ const schema = {
|
|
|
80
115
|
}
|
|
81
116
|
}
|
|
82
117
|
};
|
|
118
|
+
const EXAMPLES_BASE = 'https://github.com/extension-js/examples/blob/main';
|
|
119
|
+
function getContentScriptSampleInfo(packageJsonDir, resourcePath) {
|
|
120
|
+
if (hasDependency(packageJsonDir, 'react')) return {
|
|
121
|
+
phrase: 'See React sample',
|
|
122
|
+
url: `${EXAMPLES_BASE}/react/src/content/scripts.tsx`
|
|
123
|
+
};
|
|
124
|
+
if (hasDependency(packageJsonDir, 'preact')) return {
|
|
125
|
+
phrase: 'See Preact sample',
|
|
126
|
+
url: `${EXAMPLES_BASE}/preact/src/content/scripts.tsx`
|
|
127
|
+
};
|
|
128
|
+
if (hasDependency(packageJsonDir, 'vue')) return {
|
|
129
|
+
phrase: 'See Vue sample',
|
|
130
|
+
url: `${EXAMPLES_BASE}/vue/src/content/scripts.ts`
|
|
131
|
+
};
|
|
132
|
+
if (hasDependency(packageJsonDir, 'svelte')) return {
|
|
133
|
+
phrase: 'See Svelte sample',
|
|
134
|
+
url: `${EXAMPLES_BASE}/svelte/src/content/scripts.ts`
|
|
135
|
+
};
|
|
136
|
+
const ext = external_path_default().extname(resourcePath).toLowerCase();
|
|
137
|
+
if ('.ts' === ext || '.tsx' === ext || '.mts' === ext || '.mtsx' === ext) return {
|
|
138
|
+
phrase: 'See TypeScript sample',
|
|
139
|
+
url: `${EXAMPLES_BASE}/typescript/src/content/scripts.ts`
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
phrase: 'See vanilla JS sample',
|
|
143
|
+
url: `${EXAMPLES_BASE}/content/src/content/scripts.js`
|
|
144
|
+
};
|
|
145
|
+
}
|
|
83
146
|
function getSourceSignature(source) {
|
|
84
147
|
const head = source.slice(0, 64);
|
|
85
148
|
const tail = source.slice(-64);
|
|
@@ -253,47 +316,28 @@ function warn_no_default_export(source) {
|
|
|
253
316
|
}
|
|
254
317
|
const relativeFile = external_path_default().relative(packageJsonDir, resourceAbsPath);
|
|
255
318
|
const found = 'class' === analysis.kind ? 'class' : 'non-callable value';
|
|
319
|
+
const sample = getContentScriptSampleInfo(packageJsonDir, this.resourcePath);
|
|
256
320
|
const message = [
|
|
257
321
|
"Content script default export must be a function.",
|
|
258
|
-
`File: ${relativeFile}`,
|
|
259
|
-
"",
|
|
260
|
-
`Found: ${found}
|
|
261
|
-
"",
|
|
262
|
-
|
|
263
|
-
" - Export a default function that sets up your script and returns optional cleanup.",
|
|
264
|
-
" - If you want to use a class, instantiate it inside the default function and call its methods.",
|
|
265
|
-
"",
|
|
266
|
-
"Example:",
|
|
267
|
-
" class App { start(){} stop(){} }",
|
|
268
|
-
" export default function main(){",
|
|
269
|
-
" const app = new App(); app.start();",
|
|
270
|
-
" return () => app.stop();",
|
|
271
|
-
" }"
|
|
322
|
+
` │ File: ${relativeFile}`,
|
|
323
|
+
" │",
|
|
324
|
+
` │ Found: ${found}. Export a default function that sets up your script and returns optional cleanup.`,
|
|
325
|
+
" │ Without it: duplicate UI mounts, memory leaks, and inconsistent state during HMR.",
|
|
326
|
+
` │ ${sample.phrase} ${sample.url}`
|
|
272
327
|
].join('\n');
|
|
273
328
|
compilation?.warnings.push(message);
|
|
274
329
|
compilation?.__extjsWarnedDefaultExportKinds?.add(dedupeKindKey);
|
|
275
330
|
}
|
|
276
331
|
} else {
|
|
277
332
|
const relativeFile = external_path_default().relative(packageJsonDir, resourceAbsPath);
|
|
333
|
+
const sample = getContentScriptSampleInfo(packageJsonDir, this.resourcePath);
|
|
278
334
|
const message = [
|
|
279
335
|
"Content script requires a default export.",
|
|
280
|
-
`File: ${relativeFile}`,
|
|
281
|
-
"",
|
|
282
|
-
"Why:",
|
|
283
|
-
" - During development, Extension.js uses your default export to start and stop your content script safely.",
|
|
284
|
-
" - Without it, automatic reloads and cleanup might not work reliably.",
|
|
285
|
-
"",
|
|
286
|
-
"Required:",
|
|
287
|
-
" - Export a default function (it can optionally return a cleanup callback).",
|
|
288
|
-
"",
|
|
289
|
-
"Example:",
|
|
290
|
-
" export default function main() {",
|
|
291
|
-
" // setup...",
|
|
292
|
-
" return () => { /* cleanup */ }",
|
|
293
|
-
" }",
|
|
336
|
+
` File: ${relativeFile}`,
|
|
294
337
|
"",
|
|
295
|
-
"
|
|
296
|
-
"
|
|
338
|
+
" Export a default function so Extension.js can mount and cleanup safely.",
|
|
339
|
+
" Without it: duplicate UI mounts and inconsistent state during HMR.",
|
|
340
|
+
` ${sample.phrase}: ${sample.url}`
|
|
297
341
|
].join('\n');
|
|
298
342
|
compilation?.warnings.push(message);
|
|
299
343
|
compilation?.__extjsWarnedDefaultExport?.add(dedupeKey);
|
package/package.json
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"webpack/webpack-lib/optional-dependencies.json"
|
|
26
26
|
],
|
|
27
27
|
"name": "extension-develop",
|
|
28
|
-
"version": "3.9.0
|
|
28
|
+
"version": "3.9.0",
|
|
29
29
|
"description": "Develop, build, preview, and package Extension.js projects.",
|
|
30
30
|
"author": {
|
|
31
31
|
"name": "Cezar Augusto",
|