Skip to content

Commit f352744

Browse files
Fix up Firefox build
1 parent 6e6466e commit f352744

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

scripts/inject.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { rollupScript } from './utils/build.js'
22
import { parseArgs, write } from './script-utils.js'
3+
import { camelcase } from '../src/utils.js'
34

45
const contentScopePath = 'src/content-scope-features.js'
56
const contentScopeName = 'contentScopeFeatures'
@@ -41,7 +42,8 @@ const builds = {
4142

4243
async function initOther (injectScriptPath, platformName) {
4344
const supportsMozProxies = platformName === 'firefox'
44-
const injectScript = await rollupScript(injectScriptPath, `inject${platformName}`, supportsMozProxies)
45+
const identName = `inject${camelcase(platformName)}`
46+
const injectScript = await rollupScript(injectScriptPath, identName, supportsMozProxies)
4547
const outputScript = injectScript
4648
return outputScript
4749
}

scripts/utils/build.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ function runtimeInjections () {
4444
}
4545

4646
export async function rollupScript (scriptPath, name, supportsMozProxies = false) {
47-
let mozProxies = false
4847
// The code is using a global, that we define here which means once tree shaken we get a browser specific output.
49-
if (supportsMozProxies) {
50-
mozProxies = true
51-
}
48+
const mozProxies = supportsMozProxies
49+
5250
const inputOptions = {
5351
input: scriptPath,
5452
plugins: [

unit-test/verify-artifacts.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { join, relative } from 'node:path'
2-
import { statSync } from 'node:fs'
2+
import { readFileSync, statSync } from 'node:fs'
33
import { cwd } from '../scripts/script-utils.js'
44

55
// path helpers
66
const ROOT = join(cwd(import.meta.url), '..')
77
const BUILD = join(ROOT, 'build')
88
const APPLE_BUILD = join(ROOT, 'Sources/ContentScopeScripts/dist')
9-
const CSS_OUTPUT_SIZE = 512000
9+
const CSS_OUTPUT_SIZE = 530000
1010
const CSS_OUTPUT_SIZE_CHROME = CSS_OUTPUT_SIZE * 1.45 // 45% larger for Chrome MV2 due to base64 encoding
1111

1212
const checks = {
@@ -17,10 +17,12 @@ const checks = {
1717
{ kind: 'maxFileSize', value: CSS_OUTPUT_SIZE_CHROME, path: join(BUILD, 'chrome/inject.js') }
1818
],
1919
'chrome-mv3': [
20-
{ kind: 'maxFileSize', value: CSS_OUTPUT_SIZE, path: join(BUILD, 'chrome-mv3/inject.js') }
20+
{ kind: 'maxFileSize', value: CSS_OUTPUT_SIZE, path: join(BUILD, 'chrome-mv3/inject.js') },
21+
{ kind: 'containsString', text: 'cloneInto(', path: join(BUILD, 'chrome-mv3/inject.js'), includes: false }
2122
],
2223
firefox: [
23-
{ kind: 'maxFileSize', value: CSS_OUTPUT_SIZE, path: join(BUILD, 'firefox/inject.js') }
24+
{ kind: 'maxFileSize', value: CSS_OUTPUT_SIZE, path: join(BUILD, 'firefox/inject.js') },
25+
{ kind: 'containsString', text: 'cloneInto(', path: join(BUILD, 'firefox/inject.js'), includes: true }
2426
],
2527
integration: [
2628
{ kind: 'maxFileSize', value: CSS_OUTPUT_SIZE, path: join(BUILD, 'integration/contentScope.js') }
@@ -36,13 +38,24 @@ const checks = {
3638
describe('checks', () => {
3739
for (const [platformName, platformChecks] of Object.entries(checks)) {
3840
for (const check of platformChecks) {
41+
const localPath = relative(ROOT, check.path)
3942
if (check.kind === 'maxFileSize') {
40-
const localPath = relative(ROOT, check.path)
4143
it(`${platformName}: '${localPath}' is smaller than ${check.value}`, () => {
4244
const stats = statSync(check.path)
4345
expect(stats.size).toBeLessThan(check.value)
4446
})
4547
}
48+
if (check.kind === 'containsString') {
49+
it(`${platformName}: '${localPath}' contains ${check.text}`, () => {
50+
const fileContents = readFileSync(localPath).toString()
51+
const includes = fileContents.includes(check.text)
52+
if (check.includes) {
53+
expect(includes).toBeTrue()
54+
} else {
55+
expect(includes).toBeFalse()
56+
}
57+
})
58+
}
4659
}
4760
}
4861
})

0 commit comments

Comments
 (0)