-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
fix: Support Yarn Berry when creating sources zip #945
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
This is a great PR, thanks for working on it! |
2862602
to
1ff0b2f
Compare
I'm a bit stuck on this one. Firstly, I systematically download workspace-prefixed dependencies, because I only want to publish the source code linked to my extension, and not the one linked to my other applications. So I have to extract the folder containing my extension source code from the monorepo hosting all my projets and update its package.json to make it work outside of a workspace before publishing it. Secondly, I introduce into the zip.ts file exceptions related to yarn-specific protocols. There may be a cleaner way to do it. Thirdly, I didn’t add zipping & unzipping tests for the workspace architecture mentioned in the first post of this pull request. It seems that it would need a bit of reflexion. How to test this behavior on NPM, pnpm, Bun and Yarn while keeping the tests small and compatible with the CI process? Finally, I now feel that the hooks you recently introduced to the zip command may be a better way to handle some of the modifications I made in this pull request. @aklinker1 I will mark this pull request as ready, but feel free to leave your thoughts on it here if you feel that it shouldn’t be merged as is.
|
1ff0b2f
to
e48baea
Compare
wxt isn't compatible with yarn berry. See wxt-dev/wxt#945 wxt + yarn was causing problems generating the sources zip for Firefox. wxt also has problems with pnpm in a workspace environment. Downloading "private" packages doesn't work if because wxt uses npm pack to pull in those packages. npm pack doesn't work with the version name that is given to linked workspace packages: link:{relative-path}. I'll file an issue with wxt about this later, but for now I've written a hook in bandcamp-tempo-adjust/wxt.config.ts that regenerates the Firefox sources zip. Firefox sources zip generation for discogs-tempo-adjust isn't fixed in this commit. I'll get to that later. Also, a lot of references to yarn still exis in README.md. I'll also get to that later.
I also had problems using wxt to generate a sources zip when using a pnpm monorepo with a similar structure to you, @mezannic. I ended up following your idea to use the hooks in the zip command to make a sources zip that worked. Hoping maybe this will help others: export default defineWxtModule({
name: 'wxt-monorepo-hooks',
hooks: {
'zip:sources:done': async (wxt, sourcesZipPath) => {
console.log('\x1b[36mℹ\x1b[0m', 'Re-zipping sources...');
const projectDirName = path.basename(wxt.config.root);
/*
* assumes that the workspace is structured like this:
*
* packages/
* - package-a/
* apps/
* - app-a/ <- wxt.config.root
*/
const workspaceRoot = path.resolve(wxt.config.root, '../..');
const zip = new JSZip();
// zip the workspace root's pnpm-workspace.yaml
zip.file(
'pnpm-workspace.yaml',
fs.readFileSync(path.resolve(workspaceRoot, 'pnpm-workspace.yaml'))
);
// zip the workspace root's package.json
zip.file(
'package.json',
fs.readFileSync(path.resolve(workspaceRoot, 'package.json'))
);
// get all files in all packages
const packageFiles = glob.sync('packages/**/*', {
cwd: workspaceRoot,
ignore: ['**/node_modules/**/*'],
});
// get all files in the current app
const appFiles = glob.sync(`apps/${projectDirName}/**/*`, {
cwd: workspaceRoot,
ignore: ['**/node_modules/**/*'],
});
const files = [...packageFiles, ...appFiles];
// add SOURCE_CODE_REVIEW.md of the current app to the zip root
zip.file(
'SOURCE_CODE_REVIEW.md',
fs.readFileSync(path.resolve(wxt.config.root, 'SOURCE_CODE_REVIEW.md'))
);
for (const file of files) {
const absolutePath = path.resolve(workspaceRoot, file);
const content = fs.readFileSync(absolutePath);
zip.file(file, content);
}
await new Promise((resolve, reject) => {
zip
.generateNodeStream({
type: 'nodebuffer',
...(wxt.config.zip.compressionLevel === 0
? { compression: 'STORE' }
: {
compression: 'DEFLATE',
compressionOptions: {
level: wxt.config.zip.compressionLevel,
},
}),
})
.pipe(fs.createWriteStream(sourcesZipPath))
.on('error', reject)
.on('close', resolve);
});
},
},
}); |
@azarbayejani for workspaces where you need to include source code outside the project's root, you can use zip.sourcesRoot. Then you just need to adjust the |
Fixes
yarn zip -b firefox
command on a monorepo with the following file structureand browser extension dependencies such as "@xxx/foo-package-a@workspace:*".
TODO: add source code export test (dependencies install & build) for every supported package manager.
For now, I tested the build on my project with the following shell script.