Search code examples
google-apps-scriptlibraries

How to make Google Apps Script library always serve the latest version


I have a Google Apps Script library. Several other users are subscribed to the library. When I update the library, I want to push the latest changes to the subscribers without the users needing to take any additionals steps beyond, perhaps, some initial approval.

Is this possible? If so, how?


Solution

  • From your replying comment, I could confirm your goal as follows.

    • You want to always make users use the latest version of the library without using the developer mode.

    For this, how about this answer?

    In this answer, I would like to propose a workaround using 2 libraries.

    Usage:

    1. Create 2 standalone scripts.

    Please create 2 standalone scripts. In this case, those are the script "A" and "B".

    • The script "A" is used as the library the users use.
    • The script "B" is used as the library for using at the script "A".

    In this case, the users use the script "A" as the library. You develop the library by modifying the script "B".

    2. Setup library you develop.

    Please copy and paste the following script to the script "B". And, please give the version at "File" -> "Manage versions" on the script editor.

    function myFunction(e) {
      return "ok: " + e;
    }
    

    3. Setup library users use.

    1. Copy and paste the following script to the script "A".

      function myFunction(e) {
        return lib.myFunction(e);
      }
      
    2. Install a library of the script "B". Please turn on "Development mode". In this case, it supposes that "Identifier" is lib.

      • By this, when you modified the script "B", this script "A" can use the latest script you modified.
      • This is uses as the wrapper library for achieving your goal.
    3. Give the version to the script "A" at "File" -> "Manage versions" on the script editor.

    4. Install library at user side.

    Install the script "A" as the library at the user side. At that time, please turn off "Development mode". In this case, it supposes that "Identifier" is Lib. And you can use the following script.

    function myFunction() {
      const res = Lib.myFunction("sample");
      console.log(res)  // "ok: sample" is returned.
    }
    

    By this, when you modify the script "B", at the script "A", the latest script can be used. On the other hand, users can use the latest library using the constant version without using the developer mode.