Skip to content

Commit

Permalink
Linters gonna lint
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Oct 25, 2024
1 parent 96a41cc commit ba9fac5
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 36 deletions.
1 change: 0 additions & 1 deletion examples/content-css-modules/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ test.skip('takes a screenshot of the page', async ({page}) => {
await page.waitForSelector('body > div.content_script')
await takeScreenshot(page, path.join(__dirname, 'screenshot.png'))
})

1 change: 0 additions & 1 deletion examples/content-extension-config/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,3 @@ test.skip('takes a screenshot of the page', async ({page}) => {
await page.waitForSelector('body > div.content_script')
await takeScreenshot(page, path.join(__dirname, 'screenshot.png'))
})

1 change: 0 additions & 1 deletion examples/content-less-modules/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ test.skip('takes a screenshot of the page', async ({page}) => {
await page.waitForSelector('body > div.content_script')
await takeScreenshot(page, path.join(__dirname, 'screenshot.png'))
})

1 change: 0 additions & 1 deletion examples/content-less/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ test.skip('takes a screenshot of the page', async ({page}) => {
await page.waitForSelector('body > div.content_script')
await takeScreenshot(page, path.join(__dirname, 'screenshot.png'))
})

1 change: 0 additions & 1 deletion examples/content-sass-modules/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ test.skip('takes a screenshot of the page', async ({page}) => {
await page.waitForSelector('body > div.content_script')
await takeScreenshot(page, path.join(__dirname, 'screenshot.png'))
})

1 change: 0 additions & 1 deletion examples/content-sass/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ test.skip('takes a screenshot of the page', async ({page}) => {
await page.waitForSelector('body > div.content_script')
await takeScreenshot(page, path.join(__dirname, 'screenshot.png'))
})

1 change: 0 additions & 1 deletion examples/content-typescript/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ test.skip('takes a screenshot of the page', async ({page}) => {
await page.waitForSelector('body > div.content_script')
await takeScreenshot(page, path.join(__dirname, 'screenshot.png'))
})

1 change: 0 additions & 1 deletion examples/content/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ test.skip('takes a screenshot of the page', async ({page}) => {
await page.waitForSelector('body > div.content_script')
await takeScreenshot(page, path.join(__dirname, 'screenshot.png'))
})

52 changes: 48 additions & 4 deletions programs/develop/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DEFAULT_TEMPLATE,
SUPPORTED_BROWSERS
} from '../../examples/data'
import {extensionBuild} from './dist/module'
import {extensionBuild, Manifest} from './dist/module'

async function removeDir(dirPath: string) {
if (fs.existsSync(dirPath)) {
Expand Down Expand Up @@ -86,11 +86,55 @@ describe('extension build', () => {
browser: SUPPORTED_BROWSERS[0] as 'chrome'
})

expect.assertions(1)

expect(
path.join(templatePath, SUPPORTED_BROWSERS[0], 'manifest.json')
path.join(
templatePath,
'dist',
SUPPORTED_BROWSERS[0],
'manifest.json'
)
).toBeTruthy()

const manifestText = fs.readFileSync(
path.join(
templatePath,
'dist',
SUPPORTED_BROWSERS[0],
'manifest.json'
),
'utf-8'
)

const manifest: Manifest = JSON.parse(manifestText)
expect(manifest.name).toBeTruthy
expect(manifest.version).toBeTruthy
expect(manifest.manifest_version).toBeTruthy

if (template.name.includes('content')) {
expect(manifest.content_scripts![0].js![0]).toEqual(
'content_scripts/content-0.js'
)
expect(manifest.content_scripts![0].css![0]).toEqual(
'content_scripts/content-0.css'
)

expect(
distFileExists(
template.name,
'dist',
SUPPORTED_BROWSERS[0],
'content_scripts/content-0.css'
)
).toBeTruthy()
expect(
distFileExists(
template.name,
'dist',
SUPPORTED_BROWSERS[0],
'content_scripts/content-0.js'
)
).toBeTruthy()
}
},
80000
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import path from 'path'
import {type Compiler, Compilation, sources} from 'webpack'
import {Compiler, Compilation, sources} from 'webpack'
import {getManifestOverrides} from '../manifest-overrides'
import {getFilename, getManifestContent} from '../../../lib/utils'
import {
type FilepathList,
type PluginInterface,
type Manifest
} from '../../../webpack-types'
import {FilepathList, PluginInterface, Manifest} from '../../../webpack-types'
import fs from 'fs'

export class UpdateManifest {
public readonly manifestPath: string
Expand Down Expand Up @@ -46,14 +43,20 @@ export class UpdateManifest {

// Make a .css file for every .js file in content_scripts
// so we can later reference it in the manifest.
contentObj.css = contentObj.js.map((js: string) => {
const contentCss = path.join(outputPath, js.replace('.js', '.css'))
return getFilename(
`content_scripts/content-${index}.css`,
contentCss,
{}
)
})
contentObj.css = contentObj.js
.map((js: string) => {
const cssFilename = js.replace('.js', '.css')
const cssFilePath = path.join(outputPath, cssFilename)

return fs.existsSync(cssFilePath)
? getFilename(
`content_scripts/content-${index}.css`,
cssFilePath,
{}
)
: null
})
.filter((css) => css !== null) as string[]
}

return contentObj
Expand Down Expand Up @@ -97,16 +100,6 @@ export class UpdateManifest {
}
}

// During production, webpack styles are bundled in a CSS file,
// and not injected in the page via <style> tag. We need to
// reference these files in the manifest.
if (compiler.options.mode === 'development') {
if (patchedManifest.content_scripts) {
patchedManifest.content_scripts =
this.applyDevOverrides(patchedManifest)
}
}

const source = JSON.stringify(patchedManifest, null, 2)
const rawSource = new sources.RawSource(source)

Expand Down

0 comments on commit ba9fac5

Please sign in to comment.