@atlaspack/transformer-webextension 2.14.5-canary.35 → 2.14.5-canary.351
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/CHANGELOG.md +325 -0
- package/dist/WebExtensionTransformer.js +412 -0
- package/dist/schema.js +560 -0
- package/lib/types/WebExtensionTransformer.d.ts +3 -0
- package/lib/types/schema.d.ts +4 -0
- package/package.json +12 -8
- package/src/{WebExtensionTransformer.js → WebExtensionTransformer.ts} +21 -17
- package/src/{schema.js → schema.ts} +21 -22
- package/tsconfig.json +18 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {MutableAsset, HMROptions} from '@atlaspack/types';
|
|
3
2
|
|
|
4
3
|
import {Transformer} from '@atlaspack/plugin';
|
|
@@ -39,8 +38,10 @@ const DEP_LOCS = [
|
|
|
39
38
|
async function collectDependencies(
|
|
40
39
|
asset: MutableAsset,
|
|
41
40
|
program: any,
|
|
42
|
-
ptrs: {
|
|
43
|
-
|
|
41
|
+
ptrs: {
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
},
|
|
44
|
+
hmrOptions?: HMROptions | null,
|
|
44
45
|
) {
|
|
45
46
|
const hot = Boolean(hmrOptions);
|
|
46
47
|
const fs = asset.fs;
|
|
@@ -50,13 +51,13 @@ async function collectDependencies(
|
|
|
50
51
|
delete program.$schema;
|
|
51
52
|
if (program.default_locale) {
|
|
52
53
|
const locales = path.join(assetDir, '_locales');
|
|
53
|
-
let err = !(await fs.exists(locales))
|
|
54
|
+
let err: 'key' | 'value' | null = !(await fs.exists(locales))
|
|
54
55
|
? 'key'
|
|
55
56
|
: !(await fs.exists(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
path.join(locales, program.default_locale, 'messages.json'),
|
|
58
|
+
))
|
|
59
|
+
? 'value'
|
|
60
|
+
: null;
|
|
60
61
|
if (err) {
|
|
61
62
|
throw new ThrowableDiagnostic({
|
|
62
63
|
diagnostic: [
|
|
@@ -151,7 +152,7 @@ async function collectDependencies(
|
|
|
151
152
|
const loc = {
|
|
152
153
|
filePath,
|
|
153
154
|
...getJSONSourceLocation(ptrs[`/dictionaries/${dict}`], 'value'),
|
|
154
|
-
};
|
|
155
|
+
} as const;
|
|
155
156
|
program.dictionaries[dict] = asset.addURLDependency(dictFile, {
|
|
156
157
|
needsStableName: true,
|
|
157
158
|
loc,
|
|
@@ -181,12 +182,12 @@ async function collectDependencies(
|
|
|
181
182
|
}
|
|
182
183
|
}
|
|
183
184
|
if (program.web_accessible_resources) {
|
|
184
|
-
let war = [];
|
|
185
|
+
let war: Array<any> | Array<any | string> = [];
|
|
185
186
|
for (let i = 0; i < program.web_accessible_resources.length; ++i) {
|
|
186
187
|
// TODO: this doesn't support Atlaspack resolution
|
|
187
188
|
const currentEntry = program.web_accessible_resources[i];
|
|
188
189
|
const files = isMV2 ? [currentEntry] : currentEntry.resources;
|
|
189
|
-
let currentFiles = [];
|
|
190
|
+
let currentFiles: Array<any> | Array<any | string> = [];
|
|
190
191
|
for (let j = 0; j < files.length; ++j) {
|
|
191
192
|
const globFiles = (
|
|
192
193
|
await glob(path.join(assetDir, files[j]), fs, {})
|
|
@@ -218,8 +219,11 @@ async function collectDependencies(
|
|
|
218
219
|
program.web_accessible_resources = war;
|
|
219
220
|
}
|
|
220
221
|
if (program.declarative_net_request) {
|
|
221
|
-
const rrs: {
|
|
222
|
-
|
|
222
|
+
const rrs: {
|
|
223
|
+
path: string;
|
|
224
|
+
id: string;
|
|
225
|
+
enabled: boolean;
|
|
226
|
+
}[] = program.declarative_net_request?.rule_resources ?? [];
|
|
223
227
|
rrs.forEach((resources, i) => {
|
|
224
228
|
resources.path = asset.addURLDependency(resources.path, {
|
|
225
229
|
pipeline: 'raw',
|
|
@@ -344,7 +348,7 @@ async function collectDependencies(
|
|
|
344
348
|
program.permissions.push('scripting');
|
|
345
349
|
}
|
|
346
350
|
const hostPerms = [
|
|
347
|
-
...new Set(program.content_scripts?.flatMap((sc) => sc.matches)),
|
|
351
|
+
...new Set(program.content_scripts?.flatMap((sc: any) => sc.matches)),
|
|
348
352
|
];
|
|
349
353
|
if (isMV2) program.permissions = program.permissions.concat(hostPerms);
|
|
350
354
|
else {
|
|
@@ -354,7 +358,7 @@ async function collectDependencies(
|
|
|
354
358
|
}
|
|
355
359
|
}
|
|
356
360
|
|
|
357
|
-
function cspPatchHMR(policy
|
|
361
|
+
function cspPatchHMR(policy?: string | null, insert?: string) {
|
|
358
362
|
let defaultSrc = "'self'";
|
|
359
363
|
if (insert == null) {
|
|
360
364
|
insert = "'unsafe-eval'";
|
|
@@ -381,7 +385,7 @@ function cspPatchHMR(policy: ?string, insert?: string) {
|
|
|
381
385
|
}
|
|
382
386
|
}
|
|
383
387
|
|
|
384
|
-
export default
|
|
388
|
+
export default new Transformer({
|
|
385
389
|
async transform({asset, options}) {
|
|
386
390
|
// Set environment to browser, since web extensions are always used in
|
|
387
391
|
// browsers, and because it avoids delegating extra config to the user
|
|
@@ -433,4 +437,4 @@ export default (new Transformer({
|
|
|
433
437
|
asset.meta.webextEntry = true;
|
|
434
438
|
return [asset];
|
|
435
439
|
},
|
|
436
|
-
})
|
|
440
|
+
}) as Transformer<unknown>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
import type {SchemaEntity} from '@atlaspack/utils';
|
|
3
2
|
|
|
4
|
-
const validateVersion = (ver: string):
|
|
3
|
+
const validateVersion = (ver: string): string | null | undefined => {
|
|
5
4
|
const parts = ver.split('.', 5);
|
|
6
5
|
if (parts.length == 5) return 'Extension versions to have at most three dots';
|
|
7
6
|
if (
|
|
@@ -33,12 +32,12 @@ const actionProps = {
|
|
|
33
32
|
},
|
|
34
33
|
default_popup: string,
|
|
35
34
|
default_title: string,
|
|
36
|
-
};
|
|
35
|
+
} as const;
|
|
37
36
|
|
|
38
37
|
const arrStr = {
|
|
39
38
|
type: 'array',
|
|
40
39
|
items: string,
|
|
41
|
-
};
|
|
40
|
+
} as const;
|
|
42
41
|
|
|
43
42
|
const browserAction = {
|
|
44
43
|
type: 'object',
|
|
@@ -64,7 +63,7 @@ const browserAction = {
|
|
|
64
63
|
},
|
|
65
64
|
},
|
|
66
65
|
additionalProperties: false,
|
|
67
|
-
};
|
|
66
|
+
} as const;
|
|
68
67
|
|
|
69
68
|
const warBase = {
|
|
70
69
|
type: 'object',
|
|
@@ -75,7 +74,7 @@ const warBase = {
|
|
|
75
74
|
use_dynamic_url: boolean,
|
|
76
75
|
},
|
|
77
76
|
additionalProperties: false,
|
|
78
|
-
};
|
|
77
|
+
} as const;
|
|
79
78
|
|
|
80
79
|
const mv2Background = {
|
|
81
80
|
type: 'object',
|
|
@@ -85,7 +84,7 @@ const mv2Background = {
|
|
|
85
84
|
persistent: boolean,
|
|
86
85
|
},
|
|
87
86
|
additionalProperties: false,
|
|
88
|
-
};
|
|
87
|
+
} as const;
|
|
89
88
|
|
|
90
89
|
const commonProps = {
|
|
91
90
|
$schema: string,
|
|
@@ -145,7 +144,7 @@ const commonProps = {
|
|
|
145
144
|
},
|
|
146
145
|
additionalProperties: false,
|
|
147
146
|
},
|
|
148
|
-
commands:
|
|
147
|
+
commands: {
|
|
149
148
|
type: 'object',
|
|
150
149
|
properties: {},
|
|
151
150
|
additionalProperties: {
|
|
@@ -168,7 +167,7 @@ const commonProps = {
|
|
|
168
167
|
},
|
|
169
168
|
additionalProperties: false,
|
|
170
169
|
},
|
|
171
|
-
}
|
|
170
|
+
} as SchemaEntity,
|
|
172
171
|
content_scripts: {
|
|
173
172
|
type: 'array',
|
|
174
173
|
items: {
|
|
@@ -195,7 +194,7 @@ const commonProps = {
|
|
|
195
194
|
required: ['matches'],
|
|
196
195
|
},
|
|
197
196
|
},
|
|
198
|
-
declarative_net_request:
|
|
197
|
+
declarative_net_request: {
|
|
199
198
|
type: 'object',
|
|
200
199
|
properties: {
|
|
201
200
|
rule_resources: {
|
|
@@ -214,14 +213,14 @@ const commonProps = {
|
|
|
214
213
|
},
|
|
215
214
|
additionalProperties: false,
|
|
216
215
|
required: ['rule_resources'],
|
|
217
|
-
}
|
|
216
|
+
} as SchemaEntity,
|
|
218
217
|
devtools_page: string,
|
|
219
218
|
// looks to be FF only
|
|
220
|
-
dictionaries:
|
|
219
|
+
dictionaries: {
|
|
221
220
|
type: 'object',
|
|
222
221
|
properties: {},
|
|
223
222
|
additionalProperties: string,
|
|
224
|
-
}
|
|
223
|
+
} as SchemaEntity,
|
|
225
224
|
externally_connectable: {
|
|
226
225
|
type: 'object',
|
|
227
226
|
properties: {
|
|
@@ -280,11 +279,11 @@ const commonProps = {
|
|
|
280
279
|
additionalProperties: false,
|
|
281
280
|
},
|
|
282
281
|
offline_enabled: boolean,
|
|
283
|
-
omnibox:
|
|
282
|
+
omnibox: {
|
|
284
283
|
type: 'object',
|
|
285
284
|
properties: {},
|
|
286
285
|
additionalProperties: string,
|
|
287
|
-
}
|
|
286
|
+
} as SchemaEntity,
|
|
288
287
|
optional_host_permissions: arrStr,
|
|
289
288
|
optional_permissions: arrStr,
|
|
290
289
|
// options_page is deprecated
|
|
@@ -453,9 +452,9 @@ const commonProps = {
|
|
|
453
452
|
additionalProperties: false,
|
|
454
453
|
},
|
|
455
454
|
version_name: string,
|
|
456
|
-
};
|
|
455
|
+
} as const;
|
|
457
456
|
|
|
458
|
-
export const MV3Schema =
|
|
457
|
+
export const MV3Schema = {
|
|
459
458
|
type: 'object',
|
|
460
459
|
properties: {
|
|
461
460
|
...commonProps,
|
|
@@ -525,9 +524,9 @@ export const MV3Schema = ({
|
|
|
525
524
|
},
|
|
526
525
|
},
|
|
527
526
|
required: ['manifest_version', 'name', 'version'],
|
|
528
|
-
}
|
|
527
|
+
} as SchemaEntity;
|
|
529
528
|
|
|
530
|
-
export const MV2Schema =
|
|
529
|
+
export const MV2Schema = {
|
|
531
530
|
type: 'object',
|
|
532
531
|
properties: {
|
|
533
532
|
...commonProps,
|
|
@@ -560,9 +559,9 @@ export const MV2Schema = ({
|
|
|
560
559
|
web_accessible_resources: arrStr,
|
|
561
560
|
},
|
|
562
561
|
required: ['manifest_version', 'name', 'version'],
|
|
563
|
-
}
|
|
562
|
+
} as SchemaEntity;
|
|
564
563
|
|
|
565
|
-
export const VersionSchema =
|
|
564
|
+
export const VersionSchema = {
|
|
566
565
|
type: 'object',
|
|
567
566
|
properties: {
|
|
568
567
|
$schema: string,
|
|
@@ -572,4 +571,4 @@ export const VersionSchema = ({
|
|
|
572
571
|
},
|
|
573
572
|
},
|
|
574
573
|
required: ['manifest_version'],
|
|
575
|
-
}
|
|
574
|
+
} as SchemaEntity;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.base.json",
|
|
3
|
+
"include": ["src"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"composite": true
|
|
6
|
+
},
|
|
7
|
+
"references": [
|
|
8
|
+
{
|
|
9
|
+
"path": "../../core/diagnostic/tsconfig.json"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "../../core/plugin/tsconfig.json"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "../../core/utils/tsconfig.json"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|