Skip to content

Commit 5ff0da1

Browse files
committed
Fix clean function
1 parent aee98a3 commit 5ff0da1

File tree

10 files changed

+66
-34
lines changed

10 files changed

+66
-34
lines changed

.github/CODE_OF_CONDUCT.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Code of Conduct
32

43
## Our Pledge
@@ -18,23 +17,23 @@ diverse, inclusive, and healthy community.
1817
Examples of behavior that contributes to a positive environment for our
1918
community include:
2019

21-
* Demonstrating empathy and kindness toward other people
22-
* Being respectful of differing opinions, viewpoints, and experiences
23-
* Giving and gracefully accepting constructive feedback
24-
* Accepting responsibility and apologizing to those affected by our mistakes,
20+
- Demonstrating empathy and kindness toward other people
21+
- Being respectful of differing opinions, viewpoints, and experiences
22+
- Giving and gracefully accepting constructive feedback
23+
- Accepting responsibility and apologizing to those affected by our mistakes,
2524
and learning from the experience
26-
* Focusing on what is best not just for us as individuals, but for the overall
25+
- Focusing on what is best not just for us as individuals, but for the overall
2726
community
2827

2928
Examples of unacceptable behavior include:
3029

31-
* The use of sexualized language or imagery, and sexual attention or advances of
30+
- The use of sexualized language or imagery, and sexual attention or advances of
3231
any kind
33-
* Trolling, insulting or derogatory comments, and personal or political attacks
34-
* Public or private harassment
35-
* Publishing others' private information, such as a physical or email address,
32+
- Trolling, insulting or derogatory comments, and personal or political attacks
33+
- Public or private harassment
34+
- Publishing others' private information, such as a physical or email address,
3635
without their explicit permission
37-
* Other conduct which could reasonably be considered inappropriate in a
36+
- Other conduct which could reasonably be considered inappropriate in a
3837
professional setting
3938

4039
## Enforcement Responsibilities

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[npm-version-image]: https://img.shields.io/npm/v/extension.svg?color=0971fe
22
[npm-version-url]: https://www.npmjs.com/package/extension
3-
[downloads-image]: https://img.shields.io/npm/dm/extension.svg
3+
[downloads-image]: https://img.shields.io/npm/dm/extension.svg?color=2ecc40
44
[downloads-url]: https://npmjs.org/package/extension
5-
[action-image]: https://github.com/extension-js/extension.js/actions/workflows/ci.yml/badge.svg?branch=main
5+
[action-image]: https://github.com/extension-js/extension.js/actions/workflows/ci.yml/badge.svg?branch=main&color=2ecc40
66
[action-url]: https://github.com/extension-js/extension.js/actions
7-
[coverage-image]: https://img.shields.io/codecov/c/github/extension-js/extension.js
7+
[coverage-image]: https://img.shields.io/codecov/c/github/extension-js/extension.js?color=2ecc40
88
[coverage-url]: https://codecov.io/github/extension-js/extension.js
9-
[discord-image]: https://img.shields.io/discord/1253608412890271755?label=Discord&logo=discord&style=flat
9+
[discord-image]: https://img.shields.io/discord/1253608412890271755?label=Discord&logo=discord&style=flat&color=2ecc40
1010
[discord-url]: https://discord.gg/v9h2RgeTSN
11-
[snyk-image]: https://snyk.io/test/github/extension-js/extension/badge.svg
11+
[snyk-image]: https://snyk.io/test/github/extension-js/extension/badge.svg?color=2ecc40
1212
[snyk-url]: https://snyk.io/test/github/extension-js/extension
1313

1414
> The cross-browser extension framework

programs/cli/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[npm-version-image]: https://img.shields.io/npm/v/extension.svg?color=0971fe
22
[npm-version-url]: https://www.npmjs.com/package/extension
3-
[downloads-image]: https://img.shields.io/npm/dm/extension.svg
3+
[downloads-image]: https://img.shields.io/npm/dm/extension.svg?color=2ecc40
44
[downloads-url]: https://npmjs.org/package/extension
5-
[action-image]: https://github.com/extension-js/extension.js/actions/workflows/ci.yml/badge.svg?branch=main
5+
[action-image]: https://github.com/extension-js/extension.js/actions/workflows/ci.yml/badge.svg?branch=main&color=2ecc40
66
[action-url]: https://github.com/extension-js/extension.js/actions
7-
[coverage-image]: https://img.shields.io/codecov/c/github/extension-js/extension.js
7+
[coverage-image]: https://img.shields.io/codecov/c/github/extension-js/extension.js?color=2ecc40
88
[coverage-url]: https://codecov.io/github/extension-js/extension.js
9-
[discord-image]: https://img.shields.io/discord/1253608412890271755?label=Discord&logo=discord&style=flat
9+
[discord-image]: https://img.shields.io/discord/1253608412890271755?label=Discord&logo=discord&style=flat&color=2ecc40
1010
[discord-url]: https://discord.gg/v9h2RgeTSN
11-
[snyk-image]: https://snyk.io/test/github/extension-js/extension/badge.svg
11+
[snyk-image]: https://snyk.io/test/github/extension-js/extension/badge.svg?color=2ecc40
1212
[snyk-url]: https://snyk.io/test/github/extension-js/extension
1313

1414
> The cross-browser extension framework

programs/develop/commands/commands-lib/get-project-path.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as path from 'path'
2+
import * as fs from 'fs'
23
import goGitIt from 'go-git-it'
34
import * as messages from './messages'
45
import {downloadAndExtractZip} from './extract-from-zip'
@@ -68,3 +69,10 @@ export async function getProjectPath(pathOrRemoteUrl: string | undefined) {
6869

6970
return path.resolve(process.cwd(), pathOrRemoteUrl)
7071
}
72+
73+
export function getProjectOutputPath(projectPath: string, browser: string) {
74+
const distPath = path.join(projectPath, 'dist', browser)
75+
const outputPath = fs.existsSync(distPath) ? distPath : projectPath
76+
77+
return outputPath
78+
}

programs/develop/commands/commands-lib/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export function writingTypeDefinitionsError(error: any) {
236236

237237
export function downloadingText(url: string) {
238238
return (
239-
`${getLoggingPrefix('info')} Downloading extension...\n` +
239+
`${getLoggingPrefix('info')} Downloading browser extension...\n` +
240240
`${chalk.gray('URL')} ${chalk.underline(url)}`
241241
)
242242
}

programs/develop/commands/preview.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import * as path from 'path'
1010
import {rspack, type Configuration} from '@rspack/core'
1111
import {merge} from 'webpack-merge'
1212
import webpackConfig from '../webpack/webpack-config'
13-
import {getProjectPath} from './commands-lib/get-project-path'
13+
import {
14+
getProjectPath,
15+
getProjectOutputPath
16+
} from './commands-lib/get-project-path'
1417
import * as messages from './commands-lib/messages'
1518
import {loadCustomWebpackConfig} from './commands-lib/get-extension-config'
1619
import {PreviewOptions} from './commands-lib/config-types'
@@ -47,11 +50,12 @@ export async function extensionPreview(
4750
}
4851
})
4952

53+
const contextPath = getProjectOutputPath(projectPath, browser)
5054
const onlyBrowserRunners = baseConfig.plugins?.filter((plugin) => {
5155
return plugin?.constructor.name === 'plugin-browsers'
5256
})
5357

54-
const userExtensionConfig = await loadCustomWebpackConfig(projectPath)
58+
const userExtensionConfig = await loadCustomWebpackConfig(contextPath)
5559
const userConfig = userExtensionConfig({
5660
...baseConfig,
5761
plugins: onlyBrowserRunners
@@ -66,9 +70,7 @@ export async function extensionPreview(
6670
}
6771

6872
if (!stats?.hasErrors()) {
69-
console.log(
70-
messages.runningInProduction(path.join(projectPath, 'dist', browser))
71-
)
73+
console.log(messages.runningInProduction(contextPath))
7274
} else {
7375
console.log(stats.toString({colors: true}))
7476
process.exit(1)

programs/develop/webpack/plugin-compilation/clean-dist.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import * as fs from 'fs'
22
import * as path from 'path'
33
import {type Compiler} from '@rspack/core'
4+
import {getProjectOutputPath} from '../../commands/commands-lib/get-project-path'
45

56
export class CleanDistFolderPlugin {
7+
constructor(private options: {browser: string}) {}
68
apply(compiler: Compiler): void {
7-
const outputPath = path.join(compiler.options.output.path || '')
9+
const outputPath = getProjectOutputPath(
10+
compiler.options.context!,
11+
this.options.browser
12+
)
813

914
if (fs.existsSync(outputPath)) {
1015
try {

programs/develop/webpack/plugin-compilation/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ export class CompilationPlugin {
1111

1212
public readonly manifestPath: string
1313
public readonly browser: PluginInterface['browser']
14+
public readonly clean: boolean
1415

15-
constructor(options: PluginInterface) {
16+
constructor(options: PluginInterface & {clean: boolean}) {
1617
this.manifestPath = options.manifestPath
1718
this.browser = options.browser || 'chrome'
19+
this.clean = options.clean || true
1820
}
1921

2022
public apply(compiler: Compiler): void {
@@ -26,7 +28,15 @@ export class CompilationPlugin {
2628
browser: this.browser
2729
}).apply(compiler)
2830

29-
new CleanDistFolderPlugin().apply(compiler)
31+
// The CleanDistFolderPlugin will remove the dist folder
32+
// before the compilation starts. This is a problem
33+
// for preview mode, where we don't want to clean the
34+
// folder that is being used by the preview server.
35+
if (this.clean) {
36+
new CleanDistFolderPlugin({
37+
browser: this.browser || 'chrome'
38+
}).apply(compiler)
39+
}
3040

3141
compiler.hooks.done.tapAsync('develop:brand', (stats, done) => {
3242
stats.compilation.name = undefined
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 61556a4917863645031ac3e26b308df327389f0a

programs/develop/webpack/webpack-config.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as path from 'path'
99
import * as fs from 'fs'
1010
import {type Configuration} from '@rspack/core'
1111
import {DevOptions} from '../commands/commands-lib/config-types'
12+
import {getProjectOutputPath} from '../commands/commands-lib/get-project-path'
1213

1314
// Plugins
1415
import {CompilationPlugin} from './plugin-compilation'
@@ -37,9 +38,14 @@ export default function webpackConfig(
3738
JSON.parse(fs.readFileSync(manifestPath, 'utf-8')),
3839
devOptions.browser
3940
)
40-
const userExtensionOutputPath = path.join(
41+
const userExtensionOutputPath = getProjectOutputPath(
4142
projectPath,
42-
`dist/${devOptions.browser}`
43+
devOptions.browser
44+
)
45+
const managerExtensionPath = path.join(
46+
__dirname,
47+
'extensions',
48+
`${devOptions.browser}-manager-extension`
4349
)
4450

4551
const browser = devOptions.chromiumBinary
@@ -101,7 +107,8 @@ export default function webpackConfig(
101107
plugins: [
102108
new CompilationPlugin({
103109
manifestPath,
104-
browser
110+
browser,
111+
clean: devOptions.output?.clean
105112
}),
106113
new StaticAssetsPlugin({
107114
mode: devOptions.mode,
@@ -132,7 +139,7 @@ export default function webpackConfig(
132139
new BrowsersPlugin({
133140
extension: [
134141
userExtensionOutputPath,
135-
path.join(__dirname, 'extensions', `${browser}-manager-extension`)
142+
devOptions.mode !== 'production' ? managerExtensionPath : ''
136143
],
137144
browser,
138145
open: devOptions.open,

0 commit comments

Comments
 (0)