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

Uploading a new extension publishes a previous version and not a new one #80

Closed
juan-hf opened this issue Jan 8, 2024 · 9 comments
Closed

Comments

@juan-hf
Copy link

juan-hf commented Jan 8, 2024

I have the following code

import chromeWebstoreUpload from 'chrome-webstore-upload';
import chalk from 'chalk';
import fs from 'fs'; // Import the fs module
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import dotenv from 'dotenv';

// Initialize dotenv to load the .env variables
dotenv.config();

const argv = yargs(hideBin(process.argv)).argv;
const zipname = "./extension.zip";
const myZipFile = fs.createReadStream(zipname);

const webStore = chromeWebstoreUpload({
    clientId: process.env.CLIENT_ID,
    clientSecret: process.env.CLIENT_SECRET,
    refreshToken: process.env.REFRESH_TOKEN,
    extensionId: argv.extensionid
})

webStore.fetchToken()
    .then(token => {
        console.log(chalk.green("Token fetched"));
        webStore.uploadExisting(myZipFile, token).then(res => {
            webStore.publish().then(res => {
                console.log(chalk.green('Successfully published the newer version'));
                fs.unlink(zipname, (err) => {
                    if (err) throw err;
                    console.log(chalk.magenta('The ZIP file has been deleted'));
                });
            }).catch((error) => {
                console.log(`Error while publishing uploaded extension: ${error}`);
                process.exit(1);
            });
        });
    })
    .catch(error => {
        console.log(chalk.red('An error occurred:', error));
    }); 
  • I'm using Node 20
  • I'm using pnpm as packet manager

Issue:

  • The extension publishes again the previous version of the Chrome extension
  • It doesn't take into consideration the version that is in the manifest of the ZIPed extension files

Tests:

  • I uploaded manually the exact same file and the process worked as expected, updating the code and version number of the new deployment that is inside the manifest
@fregante
Copy link
Owner

fregante commented Jan 8, 2024

Note that there's a dedicated method to upload and publish, you can use that one.

@fregante
Copy link
Owner

fregante commented Jan 8, 2024

I got confused with the cli version.

Is there a specific reason to use this module instead of chrome-webstore-upload-cli? It takes care of everything in one line

@juan-hf
Copy link
Author

juan-hf commented Jan 8, 2024

Because I have some actions that happen before and after (for example I check if I forgot to change the manifest number) and I'd rather have 1 code to do everything, than having multiple node apps and a bash script that puts everything together.

@fregante
Copy link
Owner

fregante commented Jan 8, 2024

I used this script just last week without issue: https://github.com/fregante/chrome-webstore-upload/blob/main/test/live-test.js

It doesn't take into consideration the version that is in the manifest of the ZIPed extension files

chrome-webstore-upload doesn't read the zip file, it just sends it to the API and then it's the store that deals with it.

Try using the .upload() method alone, after that one it should appear in the dashboard as a new draft version (wait a minute for it to update first)

.publish() just instructs the store to publish whatever version is in draft, so if the first step fails then this one won't do anything.

@juan-hf
Copy link
Author

juan-hf commented Jan 8, 2024

There's no upload method in your library

Zight 2024-01-08 at 3 01 41 PM

@fregante
Copy link
Owner

fregante commented Jan 8, 2024

That's the one I meant

@juan-hf
Copy link
Author

juan-hf commented Jan 8, 2024

Ok I found the problem.
It came from the fact that the Zip file didn't follow the guidelines
So the script was republishing the version that was already published (by automatically recreating a draft) instead of taking into account the new one, that was never uploaded in the first place.

Thank you for your prompt help.

Best

@fregante
Copy link
Owner

fregante commented Jan 8, 2024

Thanks for the update! The cli script actually tries to validate the input folder and can provide better errors.

At some point I might move that functionality to this repository instead.

@fregante fregante closed this as not planned Won't fix, can't repro, duplicate, stale Jan 8, 2024
@fregante
Copy link
Owner

I think the issue here was that this module does not handle errors by the API, because it responds with HTTP 200.

I opened an issue to improve that handling:

I think the cli has some of this this built-in

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

No branches or pull requests

2 participants