Skip to content
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

feat: prevent building public files #117

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

maltoze
Copy link
Contributor

@maltoze maltoze commented Jun 8, 2023

I have a pre-compiled js file under public folder, which is included in the content_scripts of the manifest file. However, writeBuild will overwrite it.

@samrum
Copy link
Owner

samrum commented Jun 9, 2023

Is this only an issue in dev mode? What happens on build?

@maltoze
Copy link
Contributor Author

maltoze commented Jun 9, 2023

updated

using this in my manifest.😂

process.env.NODE_ENV === 'development' ? 'foo.js' : 'public/foo.js'

maybe we should also ignore public files from here.

protected async writeManifestScriptFile(fileName: string): Promise<string> {

then there is no need to check NODE_ENV and use public/foo.js directly.

@samrum
Copy link
Owner

samrum commented Jul 4, 2023

Yeah, I think that'll be the more correct solution. All of the write functions shouldn't be writing anything that exists in the public directory. Similarly for the build functions.

@maltoze
Copy link
Contributor Author

maltoze commented Jul 4, 2023

This function will return null when building. It seems that we only need to focus on dev mode.

export function getScriptLoaderForOutputChunk(
contentScriptFileName: string,
chunk: OutputChunk
): { fileName: string; source: string } | null {
if (!chunk.imports.length && !chunk.dynamicImports.length) {
return null;
}
return getScriptLoaderFile(contentScriptFileName, [chunk.fileName]);
}

@@ -177,6 +178,12 @@ export default abstract class DevBuilder<
}

protected async writeManifestScriptFile(fileName: string): Promise<string> {
const publicDirName = path.basename(this.publicDir);
if (fileName.split(path.sep)[0] === publicDirName) {
await copy(fileName, `${this.outDir}/${fileName}`);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this copy need to happen? Wouldn't all public files have already been copied by line 67?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is necessary because their behaviors are different.
line 67: public/foo.js -> dist/foo.js
this line: public/foo.js -> dist/public/foo.js

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. Line 67 is correct. The contents of public are supposed to be copied to the root of the dist directory not a subdirectory [1] so we wouldn't want this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we include public/foo.js in the content scripts section of the manifest, it will not be found.

@maltoze maltoze changed the title feat: do not build public files feat: prevent building public files Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants