browser-extension-manager 1.0.10 → 1.0.12
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.
|
@@ -3,8 +3,17 @@ const { template } = require('node-powertools');
|
|
|
3
3
|
|
|
4
4
|
// Plugin
|
|
5
5
|
class ReplacePlugin {
|
|
6
|
-
constructor(replacements) {
|
|
6
|
+
constructor(replacements = {}, options = {}) {
|
|
7
7
|
this.replacements = replacements
|
|
8
|
+
this.options = Object.assign(
|
|
9
|
+
{
|
|
10
|
+
type: 'template', // 'template' | 'raw'
|
|
11
|
+
brackets: ['%%%', '%%%'], // Template brackets
|
|
12
|
+
fileTest: /\.js$/, // Default: only replace in JS files
|
|
13
|
+
regex: false, // Use regex for replacements
|
|
14
|
+
},
|
|
15
|
+
options
|
|
16
|
+
)
|
|
8
17
|
}
|
|
9
18
|
|
|
10
19
|
apply(compiler) {
|
|
@@ -16,25 +25,54 @@ class ReplacePlugin {
|
|
|
16
25
|
},
|
|
17
26
|
(assets) => {
|
|
18
27
|
for (const filename in assets) {
|
|
19
|
-
//
|
|
20
|
-
if (!
|
|
28
|
+
// Check if the file matches the test
|
|
29
|
+
if (!this.options.fileTest.test(filename)) {
|
|
21
30
|
continue
|
|
22
31
|
}
|
|
23
32
|
|
|
24
33
|
// Get the asset
|
|
25
|
-
let asset = assets[filename]
|
|
34
|
+
let asset = assets[filename];
|
|
26
35
|
let content = asset.source();
|
|
27
36
|
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
// Log
|
|
38
|
+
// console.log('Processing', filename);
|
|
39
|
+
|
|
40
|
+
// Replace content
|
|
41
|
+
if (this.options.type === 'template') {
|
|
42
|
+
content = template(content, this.replacements, {
|
|
43
|
+
brackets: this.options.brackets,
|
|
44
|
+
})
|
|
45
|
+
} else if (this.options.type === 'raw') {
|
|
46
|
+
for (const key in this.replacements) {
|
|
47
|
+
const value = this.replacements[key]
|
|
48
|
+
|
|
49
|
+
if (this.options.regex && key.startsWith('/') && key.lastIndexOf('/') > 0) {
|
|
50
|
+
try {
|
|
51
|
+
const lastSlash = key.lastIndexOf('/');
|
|
52
|
+
const pattern = key.slice(1, lastSlash);
|
|
53
|
+
const flags = key.slice(lastSlash + 1);
|
|
54
|
+
const regex = new RegExp(pattern, flags);
|
|
55
|
+
|
|
56
|
+
// Update the content
|
|
57
|
+
content = content.replace(regex, value);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.warn('Regex error in key:', key, err);
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
// Replace all instances of the key with the value
|
|
63
|
+
const regex = new RegExp(key, 'g');
|
|
64
|
+
|
|
65
|
+
// Update the content
|
|
66
|
+
content = content.replace(regex, value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
32
70
|
|
|
33
71
|
// Update the asset
|
|
34
72
|
compilation.updateAsset(
|
|
35
73
|
filename,
|
|
36
74
|
new compiler.webpack.sources.RawSource(content)
|
|
37
|
-
)
|
|
75
|
+
);
|
|
38
76
|
}
|
|
39
77
|
}
|
|
40
78
|
)
|
|
@@ -13,6 +13,20 @@ const project = Manager.getPackage('project');
|
|
|
13
13
|
const rootPathPackage = Manager.getRootPath('main');
|
|
14
14
|
const rootPathProject = Manager.getRootPath('project');
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
function getRedactions() {
|
|
18
|
+
const REDACTED = './REDACTED_REMOTE_CODE';
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
'https://app.chatsy.ai/resources/script.js': REDACTED + 1,
|
|
22
|
+
// '/https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js\\?[^"\'\\s]*/g': REDACTED + 2,
|
|
23
|
+
'https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js': REDACTED + 2,
|
|
24
|
+
'https://www.google.com/recaptcha/enterprise.js': REDACTED + 3,
|
|
25
|
+
'https://apis.google.com/js/api.js': REDACTED + 4,
|
|
26
|
+
'https://www.google.com/recaptcha/api.js': REDACTED + 5,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
16
30
|
// Glob
|
|
17
31
|
const input = [
|
|
18
32
|
// Files to include
|
|
@@ -111,6 +125,25 @@ async function packageRaw() {
|
|
|
111
125
|
// Copy files to raw package directory
|
|
112
126
|
await execute(`cp -r dist/* ${outputDir}`);
|
|
113
127
|
|
|
128
|
+
// Loop thru outputDir/dist/assets/js all JS files
|
|
129
|
+
const jsFiles = jetpack.find(path.join(outputDir, 'assets', 'js'), { matching: '*.js' });
|
|
130
|
+
const redactions = getRedactions();
|
|
131
|
+
|
|
132
|
+
jsFiles.forEach(filePath => {
|
|
133
|
+
// Load the content
|
|
134
|
+
let content = jetpack.read(filePath);
|
|
135
|
+
|
|
136
|
+
// Replace keys with their corresponding values
|
|
137
|
+
Object.keys(redactions).forEach(key => {
|
|
138
|
+
const value = redactions[key];
|
|
139
|
+
const regex = new RegExp(key, 'g'); // Create a global regex for the key
|
|
140
|
+
content = content.replace(regex, value);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Write the new content to the file
|
|
144
|
+
jetpack.write(filePath, content);
|
|
145
|
+
});
|
|
146
|
+
|
|
114
147
|
// Compile manifest and locales
|
|
115
148
|
await compileManifest(outputDir);
|
|
116
149
|
await compileLocales(outputDir);
|
|
@@ -38,7 +38,8 @@ const settings = {
|
|
|
38
38
|
mode: 'production',
|
|
39
39
|
target: ['web', 'es5'],
|
|
40
40
|
plugins: [
|
|
41
|
-
new ReplacePlugin(
|
|
41
|
+
new ReplacePlugin(getTemplateReplaceOptions(), { type: 'template' }),
|
|
42
|
+
// new ReplacePlugin(getRawReplaceOptions(), { type: 'raw', regex: true }),
|
|
42
43
|
],
|
|
43
44
|
entry: {
|
|
44
45
|
// Entry is dynamically generated
|
|
@@ -170,7 +171,7 @@ function updateEntryPoints() {
|
|
|
170
171
|
logger.log('Updated entry points:', settings.entry);
|
|
171
172
|
}
|
|
172
173
|
|
|
173
|
-
function
|
|
174
|
+
function getTemplateReplaceOptions() {
|
|
174
175
|
// Setup options
|
|
175
176
|
const options = {
|
|
176
177
|
// App & Project
|
|
@@ -236,5 +237,18 @@ function getReplaceOptions() {
|
|
|
236
237
|
return options;
|
|
237
238
|
}
|
|
238
239
|
|
|
240
|
+
// function getRawReplaceOptions() {
|
|
241
|
+
// const REDACTED = './REDACTED_REMOTE_CODE';
|
|
242
|
+
|
|
243
|
+
// return {
|
|
244
|
+
// 'https://app.chatsy.ai/resources/script.js': REDACTED + 1,
|
|
245
|
+
// // '/https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js\\?[^"\'\\s]*/g': REDACTED + 2,
|
|
246
|
+
// 'https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js': REDACTED + 2,
|
|
247
|
+
// 'https://www.google.com/recaptcha/enterprise.js': REDACTED + 3,
|
|
248
|
+
// 'https://apis.google.com/js/api.js': REDACTED + 4,
|
|
249
|
+
// 'https://www.google.com/recaptcha/api.js': REDACTED + 5,
|
|
250
|
+
// }
|
|
251
|
+
// }
|
|
252
|
+
|
|
239
253
|
// Default Task
|
|
240
254
|
module.exports = series(webpack, webpackWatcher);
|
package/dist/index.js
CHANGED
|
@@ -34,5 +34,13 @@ Manager.prototype.initialize = function (callback) {
|
|
|
34
34
|
return self.webManager;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
Manager.prototype.library = function (name) {
|
|
38
|
+
const self = this;
|
|
39
|
+
|
|
40
|
+
// Return
|
|
41
|
+
return require(`./lib/${name}`);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
|
|
37
45
|
// Export
|
|
38
46
|
module.exports = Manager;
|