Skip to content

Commit

Permalink
Upgrade the "serve" deployment also to the latest
Browse files Browse the repository at this point in the history
Related issue: e-mission/e-mission-docs#838
Related PR for cordovabuild: #952
Related PR for devapp: e-mission/e-mission-devapp#18

Main changes:
- need to add "Ventura" to the list of releases to fix:

    ```
    /Users/kshankar/e-mission/phone-rciti-branch/node_modules/macos-release/index.js:27
        const [name, version] = nameMap.get(release);
                                ^

    TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
        at macosRelease (/Users/kshankar/e-mission/phone-rciti-branch/node_modules/macos-release/index.js:27:26)
        at osName (/Users/kshankar/e-mission/phone-rciti-branch/node_modules/os-name/index.js:21:18)
        at new Insight (/Users/kshankar/e-mission/phone-rciti-branch/node_modules/insight/lib/index.js:37:13)
        at Object.<anonymous> (/Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/node_modules/cordova/src/telemetry.js:26:15)
        at Module._compile (node:internal/modules/cjs/loader:1246:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1300:10)
        at Module.load (node:internal/modules/cjs/loader:1103:32)
        at Module._load (node:internal/modules/cjs/loader:942:12)
        at Module.require (node:internal/modules/cjs/loader:1127:19)
        at require (node:internal/modules/helpers:112:18)
    ```
    - we do this by copying over a file that includes Ventura
        per https://stackoverflow.com/questions/68318289/ionic-fails-building-in-macos-12-monterey
    - I tried to do this in a more principled fashion by upgrading to the most recent version of cordova
        - but we are already at the most recent version of cordova, and it still doesn't work
    - I then tried to compare it to the same file in the cordovabuild version and it was the same

        ```
           $ grep Ventura ~/e-mission/native_code_upgrade/node_modules/macos-release/index.js | wc -l
           0
        ```
    - on further invesigation, it turns out that the issue is not that the more
      recent version of cordova has a newer version of the macos-release
      library, but that it doesn't use `Insight` (at least by default), which
      is the module that calls it
    - phonegap, which we need for `phonegap serve`, does
        ```
        $ grep -r "new Insight" node_modules/
        node_modules//cordova/node_modules/insight/readme.md:const insight = new Insight({
        node_modules//cordova/node_modules/insight/readme.md:const insight = new Insight({
        node_modules//cordova/node_modules/insight/lib/push.js: const insight = new Insight(message);
        node_modules//insight/readme.md:const insight = new Insight({
        node_modules//insight/readme.md:const insight = new Insight({
        node_modules//insight/lib/push.js:  const insight = new Insight(msg);
        node_modules//phonegap/node_modules/cordova/src/telemetry.js:var insight = new Insight({
        node_modules//phonegap/lib/cli/analytics.js:var insight = new Insight({
        ```
    - so there is really no alternative to hot-patching the file

- add the cordova `browser` platform to fix:

    ```
    CordovaError: No platforms added to this project. Please use `phonegap platform add <platform>`.
        at Object.preProcessOptions (/Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/node_modules/cordova-lib/src/cordova/util.js:313:15)
        at /Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/node_modules/cordova-lib/src/cordova/prepare.js:49:40
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    ```
    - incidentally, if we don't add the platform, cordova tries to add it itself, and that completely messes up the `node_modules`

    There are 720 packages

    ```
    $ ls -al node_modules/ | wc -l
         720
    ```

    we try to add the browser, which fails

    ```
    Using cordova-fetch for cordova-browser@^6.0.0

    (node:24473) Warning: Accessing non-existent property 'browser' of module exports inside circular dependency
    (Use `node --trace-warnings ...` to show where the warning was created)

    Failed to fetch platform cordova-browser@^6.0.0
    Probably this is either a connection problem, or platform spec is incorrect.
    Check your connection and platform name/version/URL.
    Could not determine package name from output:
    added 24 packages, changed 1 package, and audited 131 packages in 10s
    ```

    we end up with 111 packages, and `phonegap` is uninstalled as well

    ```
    $ ls -al node_modules | wc -l
         111
    ```

    - and the `phonegap` command is not found either

- add shelljs to the dependencies to fix

    ```
     [warning] Unable to load PlatformApi from platform. Error: Cannot find module 'shelljs'
     [warning] Require stack:
     [warning] - /Users/kshankar/e-mission/phone-rciti-branch/platforms/browser/cordova/Api.js
     [warning] - /Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/node_modules/cordova-lib/src/cordova/util.js
     [warning] - /Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/node_modules/cordova-lib/src/platforms/platforms.js
     [warning] - /Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/node_modules/cordova-lib/src/plugman/install.js
     [warning] - /Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/node_modules/cordova-lib/src/plugman/plugman.js
     [warning] - /Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/node_modules/cordova-lib/cordova-lib.js
     [warning] - /Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/node_modules/cordova/cordova.js
     [warning] - /Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/lib/cordova/index.js
     [warning] - /Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/lib/phonegap/cordova.js
     [warning] - /Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/lib/phonegap.js
     [warning] - /Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/lib/main.js
     [warning] - /Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/lib/cli.js
     [warning] - /Users/kshankar/e-mission/phone-rciti-branch/node_modules/phonegap/bin/phonegap.js
    ```

Testing done:

```
$ rm -rf node_modules
$ bash setup/setup_serve.sh
$ npm run serve
```

the serve process starts up and the devapp is able to connect to it
  • Loading branch information
shankari committed Apr 23, 2023
1 parent 17bc991 commit 460f6ee
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions bin/setup_autodeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ cp $SRC_DIR/middleware.js $INSTALL_DIR/lib/middleware.js
cp $SRC_DIR/nocache.js $INSTALL_DIR/lib/middleware/nocache.js
cp $SRC_DIR/lib_autoreload.js $INSTALL_DIR/lib/middleware/autoreload.js
cp $SRC_DIR/res_autoreload.js $INSTALL_DIR/res/middleware/autoreload.js
cp $SRC_DIR/macos-index.js $INSTALL_DIR/../macos-release/index.js
echo "Finished copying files from $SRC_DIR to $INSTALL_DIR"
14 changes: 10 additions & 4 deletions package.serve.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@
},
"devDependencies": {
"phonegap": "9.0.0+cordova.9.0.0",
"cordova": "9.0.0",
"@ionic/cli": "6.10.1",
"bower": "1.8.8"
"cordova": "^11.1.0",
"@ionic/cli": "6.20.8",
"bower": "1.8.14"
},
"dependencies": {
"fs-extra": "^9.0.1",
"klaw-sync": "^6.0.0"
"klaw-sync": "^6.0.0",
"shelljs": "^0.8.5"
},
"cordova": {
"platforms": [
"browser"
]
}
}
38 changes: 38 additions & 0 deletions setup/autoreload/macos-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';
const os = require('os');

const nameMap = new Map([
[22, ['Ventura', '13']],
[21, ['Monterey', '12']],
[20, ['Big Sur', '11']],
[19, ['Catalina', '10.15']],
[18, ['Mojave', '10.14']],
[17, ['High Sierra', '10.13']],
[16, ['Sierra', '10.12']],
[15, ['El Capitan', '10.11']],
[14, ['Yosemite', '10.10']],
[13, ['Mavericks', '10.9']],
[12, ['Mountain Lion', '10.8']],
[11, ['Lion', '10.7']],
[10, ['Snow Leopard', '10.6']],
[9, ['Leopard', '10.5']],
[8, ['Tiger', '10.4']],
[7, ['Panther', '10.3']],
[6, ['Jaguar', '10.2']],
[5, ['Puma', '10.1']]
]);

const macosRelease = release => {
release = Number((release || os.release()).split('.')[0]);

const [name, version] = nameMap.get(release);

return {
name,
version
};
};

module.exports = macosRelease;
// TODO: remove this in the next major version
module.exports.default = macosRelease;

0 comments on commit 460f6ee

Please sign in to comment.