Skip to content

Fix firefox build #393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions scripts/inject.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { rollupScript } from './utils/build.js'
import { parseArgs, write } from './script-utils.js'
import { camelcase } from '../src/utils.js'

const contentScopePath = 'src/content-scope-features.js'
const contentScopeName = 'contentScopeFeatures'
Expand Down Expand Up @@ -40,7 +41,9 @@ const builds = {
}

async function initOther (injectScriptPath, platformName) {
const injectScript = await rollupScript(injectScriptPath, `inject${platformName}`)
const supportsMozProxies = platformName === 'firefox'
const identName = `inject${camelcase(platformName)}`
const injectScript = await rollupScript(injectScriptPath, identName, supportsMozProxies)
const outputScript = injectScript
return outputScript
}
Expand Down Expand Up @@ -73,7 +76,7 @@ async function init () {
if (args.platform === 'chrome') {
output = await initChrome(build.input)
} else {
output = await initOther(build.input)
output = await initOther(build.input, args.platform)
}

// bundle and write the output
Expand Down
8 changes: 3 additions & 5 deletions scripts/utils/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ function runtimeInjections () {
}
}

export async function rollupScript (scriptPath, name, supportsMozProxies = true) {
let mozProxies = false
export async function rollupScript (scriptPath, name, supportsMozProxies = false) {
// The code is using a global, that we define here which means once tree shaken we get a browser specific output.
if (process.argv[2] === 'firefox' && supportsMozProxies) {
mozProxies = true
}
const mozProxies = supportsMozProxies

const inputOptions = {
input: scriptPath,
plugins: [
Expand Down
23 changes: 18 additions & 5 deletions unit-test/verify-artifacts.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { join, relative } from 'node:path'
import { statSync } from 'node:fs'
import { readFileSync, statSync } from 'node:fs'
import { cwd } from '../scripts/script-utils.js'

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

const checks = {
Expand All @@ -17,10 +17,12 @@ const checks = {
{ kind: 'maxFileSize', value: CSS_OUTPUT_SIZE_CHROME, path: join(BUILD, 'chrome/inject.js') }
],
'chrome-mv3': [
{ kind: 'maxFileSize', value: CSS_OUTPUT_SIZE, path: join(BUILD, 'chrome-mv3/inject.js') }
{ kind: 'maxFileSize', value: CSS_OUTPUT_SIZE, path: join(BUILD, 'chrome-mv3/inject.js') },
{ kind: 'containsString', text: 'cloneInto(', path: join(BUILD, 'chrome-mv3/inject.js'), includes: false }
],
firefox: [
{ kind: 'maxFileSize', value: CSS_OUTPUT_SIZE, path: join(BUILD, 'firefox/inject.js') }
{ kind: 'maxFileSize', value: CSS_OUTPUT_SIZE, path: join(BUILD, 'firefox/inject.js') },
{ kind: 'containsString', text: 'cloneInto(', path: join(BUILD, 'firefox/inject.js'), includes: true }
],
integration: [
{ kind: 'maxFileSize', value: CSS_OUTPUT_SIZE, path: join(BUILD, 'integration/contentScope.js') }
Expand All @@ -36,13 +38,24 @@ const checks = {
describe('checks', () => {
for (const [platformName, platformChecks] of Object.entries(checks)) {
for (const check of platformChecks) {
const localPath = relative(ROOT, check.path)
if (check.kind === 'maxFileSize') {
const localPath = relative(ROOT, check.path)
it(`${platformName}: '${localPath}' is smaller than ${check.value}`, () => {
const stats = statSync(check.path)
expect(stats.size).toBeLessThan(check.value)
})
}
if (check.kind === 'containsString') {
it(`${platformName}: '${localPath}' contains ${check.text}`, () => {
const fileContents = readFileSync(localPath).toString()
const includes = fileContents.includes(check.text)
if (check.includes) {
expect(includes).toBeTrue()
} else {
expect(includes).toBeFalse()
}
})
}
}
}
})