Skip to content

Commit

Permalink
Merge pull request #497 from mountaindude/puppeteer20
Browse files Browse the repository at this point in the history
3.3.0 RC1
  • Loading branch information
mountaindude authored Feb 16, 2024
2 parents baea904 + ed32a01 commit 07b668d
Show file tree
Hide file tree
Showing 19 changed files with 395 additions and 220 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
build: |
cd src
./node_modules/.bin/esbuild "${env:DIST_FILE_NAME}.js" --bundle --external:vm2 --external:axios --outfile=build.cjs --format=cjs --platform=node --target=node18.5.0
pkg --output "../${env:DIST_FILE_NAME}.exe" -t node18-win-x64 ./build.cjs --config package.json --compress GZip
pkg --output "../${env:DIST_FILE_NAME}.exe" -t node18-win-x64 ./build.cjs --config package.json --options no-deprecation --compress GZip
dir
cd ..
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
build: |
cd src
./node_modules/.bin/esbuild ${DIST_FILE_NAME}.js --bundle --external:vm2 --external:axios --outfile=build.cjs --format=cjs --platform=node --target=node18.5.0
pkg --output "../${DIST_FILE_NAME}" -t node18-macos-x64 ./build.cjs --config package.json --compress GZip
pkg --output "../${DIST_FILE_NAME}" -t node18-macos-x64 ./build.cjs --config package.json --options no-deprecation --compress GZip
cd ..
chmod +x "${DIST_FILE_NAME}"
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
build: |
cd src
./node_modules/.bin/esbuild ${DIST_FILE_NAME}.js --bundle --external:vm2 --external:axios --outfile=build.cjs --format=cjs --platform=node --target=node18.5.0
pkg --output "../${DIST_FILE_NAME}" -t node18-linux-x64 ./build.cjs --config package.json --compress GZip
pkg --output "../${DIST_FILE_NAME}" -t node18-linux-x64 ./build.cjs --config package.json --options no-deprecation --compress GZip
cd ..
chmod +x ${DIST_FILE_NAME}
Expand Down Expand Up @@ -586,7 +586,7 @@ jobs:
pwd
cd src
./node_modules/.bin/esbuild ${DIST_FILE_NAME}.js --bundle --external:vm2 --external:axios --outfile=build.cjs --format=cjs --platform=node --target=node18.5.0
pkg --output "../${DIST_FILE_NAME}" -t node18-macos-x64 ./build.cjs --config package.json --compress GZip
pkg --output "../${DIST_FILE_NAME}" -t node18-macos-x64 ./build.cjs --config package.json --options no-deprecation --compress GZip
cd ..
chmod +x "${DIST_FILE_NAME}"
Expand Down Expand Up @@ -713,7 +713,7 @@ jobs:
run: |
cd src
./node_modules/.bin/esbuild "${env:DIST_FILE_NAME}.js" --bundle --external:vm2 --external:axios --outfile=build.cjs --format=cjs --platform=node --target=node18.5.0
pkg --output "../${env:DIST_FILE_NAME}.exe" -t node18-win-x64 ./build.cjs --config package.json --compress GZip
pkg --output "../${env:DIST_FILE_NAME}.exe" -t node18-win-x64 ./build.cjs --config package.json --options no-deprecation --compress GZip
cd ..
Expand Down Expand Up @@ -819,7 +819,7 @@ jobs:
run: |
cd src
./node_modules/.bin/esbuild ${DIST_FILE_NAME}.js --bundle --external:vm2 --external:axios --outfile=build.cjs --format=cjs --platform=node --target=node18.5.0
pkg --output "../${DIST_FILE_NAME}" -t node18-linux-x64 ./build.cjs --config package.json --compress GZip
pkg --output "../${DIST_FILE_NAME}" -t node18-linux-x64 ./build.cjs --config package.json --options no-deprecation --compress GZip
cd ..
chmod +x ${DIST_FILE_NAME}
Expand Down
105 changes: 60 additions & 45 deletions README.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"last-release-sha": "4b6b9008737ff66321d5baf0a473fb698391a42b",
"release-as": "3.2.3",
"release-type": "node",
"prerelease": false,
"draft": true,
"release-search-depth": 10,
"commit-search-depth": 200,
"changelog-sections": [
{
"type": "feat",
Expand Down
43 changes: 38 additions & 5 deletions src/butler-sheet-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const program = new Command();
'Create thumbnail images based on the layout of each sheet in Qlik Sense Enterprise on Windows (QSEoW) applications.\nMultiple apps can be updated with a single command, using a Qlik Sense tag to identify which apps will be updated.'
)
.action(async (options, command) => {
// Show app version
logger.info(`App version: ${appVersion}`);

logger.verbose(`appid=${options.appid}`);
logger.verbose(`itemid=${options.itemid}`);
try {
Expand Down Expand Up @@ -187,6 +190,9 @@ const program = new Command();
.command('remove-sheet-icons')
.description('Remove all sheet icons from a Qlik Sense Enterprise on Windows (QSEoW) app.')
.action(async (options, command) => {
// Show app version
logger.info(`App version: ${appVersion}`);

try {
const res = await qseowRemoveSheetIcons(options, command);
logger.debug(`Call to qseowRemoveSheetIcons succeeded: ${res}`);
Expand Down Expand Up @@ -264,6 +270,9 @@ const program = new Command();
'Create thumbnail images based on the layout of each sheet in Qlik Sense Cloud applications.\nMultiple apps can be updated with a single command, using a Qlik Sense collection to identify which apps will be updated.'
)
.action(async (options, command) => {
// Show app version
logger.info(`App version: ${appVersion}`);

logger.verbose(`appid=${options.appid}`);
try {
// Set default browser version per browser
Expand Down Expand Up @@ -355,11 +364,15 @@ const program = new Command();
'--browser-version <version>',
'Version (=build id) of the browser to install. Use "butler-sheet-icons browser list-installed" to see which browsers are currently installed.'
);

// ---------
cloud
.command('list-collections')
.description('List available collections.')
.action(async (options, command) => {
// Show app version
logger.info(`App version: ${appVersion}`);

logger.verbose(`collection=${options.collection}`);
try {
const res = await qscloudListCollections(options, command);
Expand Down Expand Up @@ -395,6 +408,9 @@ const program = new Command();
.command('remove-sheet-icons')
.description('Remove all sheet icons from a Qlik Sense Cloud app.')
.action(async (options, command) => {
// Show app version
logger.info(`App version: ${appVersion}`);

try {
const res = await qscloudRemoveSheetIcons(options, command);
logger.debug(`Call to qscloudRemoveSheetIcons succeeded: ${res}`);
Expand Down Expand Up @@ -445,6 +461,9 @@ const program = new Command();
'Show which browsers are currently installed and available for use by Butler Sheet Icons.'
)
.action(async (options, command) => {
// Show app version
logger.info(`App version: ${appVersion}`);

logger.verbose(`appid=${options.appid}`);
try {
const res = await browserInstalled(options, command);
Expand Down Expand Up @@ -472,6 +491,9 @@ const program = new Command();
'Uninstall a browser from the Butler Sheet Icons cache.\nThis will remove the browser from the cache, but will not affect other browsers on this computer.\nUse the "butler-sheet-icons browser list-installed" command to see which browsers are currently installed.'
)
.action(async (options, command) => {
// Show app version
logger.info(`App version: ${appVersion}`);

try {
const res = await browserUninstall(options, command);
logger.debug(`Call to browserUninstall succeeded: ${res}`);
Expand Down Expand Up @@ -507,6 +529,9 @@ const program = new Command();
'Uninstall all browsers from the Butler Sheet Icons cache.\nThis will remove all browsers from the cache, but will not affect other browsers on this computer.\nUse the "butler-sheet-icons browser list-installed" command to see which browsers are currently installed.'
)
.action(async (options, command) => {
// Show app version
logger.info(`App version: ${appVersion}`);

try {
const res = await browserUninstallAll(options, command);
logger.debug(`Call to browserUninstallAll succeeded: ${res}`);
Expand All @@ -533,6 +558,9 @@ const program = new Command();
'Install a browser into the Butler Sheet Icons cache.\nThis will download the browser and install it into the cache, where it can be used by Butler Sheet Icons.\nUse the "butler-sheet-icons browser list-installed" command to see which browsers are currently installed.'
)
.action(async (options, command) => {
// Show app version
logger.info(`App version: ${appVersion}`);

try {
// Set default browser version per browser
if (!options.browserVersion || options.browserVersion === '') {
Expand Down Expand Up @@ -560,12 +588,12 @@ const program = new Command();
const res = await browserInstall(options, command);
logger.debug(`Call to browserInstall succeeded: ${res}`);
} catch (err) {
logger.error(`BROWSER MAIN 9: ${err}`);
if (err.message) {
logger.error(`BROWSER MAIN 9 (message): ${err.message}`);
}
if (err.stack) {
logger.error(`BROWSER MAIN 9 (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`BROWSER MAIN 9 (message): ${err.message}`);
} else {
logger.error(`BROWSER MAIN 9: ${err}`);
}
}
})
Expand Down Expand Up @@ -594,9 +622,14 @@ const program = new Command();
'Show which browsers are available for download and installation by Butler Sheet Icons.'
)
.action(async (options, command) => {
// Show app version
logger.info(`App version: ${appVersion}`);

try {
const res = await browserListAvailable(options, command);
logger.debug(`Call to browserAvailable succeeded: ${res}`);
logger.debug(
`Call to browserAvailable succeeded: ${JSON.stringify(res, null, 2)}`
);
} catch (err) {
logger.error(`BROWSER MAIN 10: ${err}`);
if (err.message) {
Expand Down
22 changes: 21 additions & 1 deletion src/lib/browser/browser-install.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const { install, resolveBuildId, detectBrowserPlatform } = require('@puppeteer/browsers');
const {
install,
resolveBuildId,
detectBrowserPlatform,
canDownload,
} = require('@puppeteer/browsers');
const path = require('path');
const { homedir } = require('os');

Expand Down Expand Up @@ -42,6 +47,21 @@ const browserInstall = async (options, _command) => {
logger.info(
`Resolved browser build id: "${buildId}" for browser "${options.browser}" version "${options.browserVersion}"`
);

// Ensure browser can be downloaded
const canDownloadBrowser = await canDownload({
browser: options.browser,
buildId,
cacheDir: browserPath,
unpack: true,
});

if (!canDownloadBrowser) {
throw new Error(
`Browser "${options.browser}" version "${options.browserVersion}" cannot be downloaded. Please use the "list-available" command to check available versions`
);
}

logger.info('Installing browser...');

const browser = await install({
Expand Down
32 changes: 28 additions & 4 deletions src/lib/browser/browser-list-available.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { detectBrowserPlatform } = require('@puppeteer/browsers');
const { detectBrowserPlatform, canDownload } = require('@puppeteer/browsers');
const path = require('path');
const { homedir } = require('os');
const axios = require('axios');
Expand Down Expand Up @@ -45,6 +45,8 @@ async function browserListAvailable(options) {
// Get versions for the selected browser
let browsersAvailable = [];
if (options.browser === 'chrome') {
// https://developer.chrome.com/docs/web-platform/versionhistory/guide
//
// Chome version history API:
// https://developer.chrome.com/docs/versionhistory/guide/
//
Expand All @@ -69,6 +71,10 @@ async function browserListAvailable(options) {
// "nextPageToken": ""
// }

logger.debug(
`Get Chrome versions from: https://versionhistory.googleapis.com/v1/chrome/platforms/${platform}/channels/${options.channel}/versions`
);

const axiosConfig = {
method: 'get',
responseType: 'json',
Expand All @@ -82,9 +88,27 @@ async function browserListAvailable(options) {
// Output Chrome versions and names to info log
if (browsersAvailable.length > 0) {
logger.info(`Chrome versions from "${options.channel}" channel:`);
browsersAvailable.forEach((version) => {
logger.info(` ${version.version}, "${version.name}"`);
});
logger.verbose(
'Note that not all versions may be available for use with Butler Sheet Icons.'
);

// eslint-disable-next-line no-restricted-syntax
for (const version of browsersAvailable) {
// Can this version be downloaded?
// eslint-disable-next-line no-await-in-loop
const canDownloadBrowser = await canDownload({
browser: options.browser,
buildId: version.version,
cacheDir: browserPath,
unpack: true,
});

if (canDownloadBrowser) {
logger.info(` ${version.version}, "${version.name}"`);
} else {
logger.verbose(` ${version.version}, "${version.name}" (not available)`);
}
}
} else {
logger.info('No Chrome versions available');
}
Expand Down
58 changes: 40 additions & 18 deletions src/lib/cloud/cloud-collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const { table } = require('table');
const { logger, setLoggingLevel, bsiExecutablePath, isPkg } = require('../../globals.js');
const QlikSaas = require('./cloud-repo');
const { qscloudTestConnection } = require('./cloud-test-connection');

/**
*
Expand All @@ -30,13 +31,33 @@ const qscloudListCollections = async (options) => {
try {
saasInstance = new QlikSaas(cloudConfig);
} catch (err) {
logger.error(`LIST COLLECTIONS 1: ${err}`);
if (err.message) {
if (err.stack) {
logger.error(`LIST COLLECTIONS 1 (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`LIST COLLECTIONS 1 (message): ${err.message}`);
} else {
logger.error(`LIST COLLECTIONS 1: ${err}`);
}

return false;
}

// Test connection to QS Cloud by getting info about the user associated with the API key
try {
const res = await qscloudTestConnection(options, saasInstance);
logger.verbose(
`Connection to tenant ${options.tenanturl} successful: ${JSON.stringify(res)}`
);
} catch (err) {
if (err.stack) {
logger.error(`LIST COLLECTIONS 1 (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`LIST COLLECTIONS 1 (message): ${err.message}`);
logger.error(`LIST COLLECTIONS 1 (error code): ${err.status}="${err.statusText}"`);
} else {
logger.error(`LIST COLLECTIONS 1: ${err}`);
}

return false;
}

Expand All @@ -45,12 +66,12 @@ const qscloudListCollections = async (options) => {
try {
allCollections = await saasInstance.Get('collections');
} catch (err) {
logger.error(`LIST COLLECTIONS 2: ${err}`);
if (err.message) {
logger.error(`LIST COLLECTIONS 2 (message): ${err.message}`);
}
if (err.stack) {
logger.error(`LIST COLLECTIONS 2 (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`LIST COLLECTIONS 2 (message): ${err.message}`);
} else {
logger.error(`LIST COLLECTIONS 2: ${err}`);
}
return false;
}
Expand Down Expand Up @@ -98,13 +119,14 @@ const qscloudListCollections = async (options) => {

return true;
} catch (err) {
logger.error(`LIST COLLECTIONS 3: ${err}`);
if (err.message) {
logger.error(`LIST COLLECTIONS 3 (message): ${err.message}`);
}
if (err.stack) {
logger.error(`LIST COLLECTIONS 3 (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`LIST COLLECTIONS 3 (message): ${err.message}`);
} else {
logger.error(`LIST COLLECTIONS 3: ${err}`);
}

return false;
}
};
Expand Down Expand Up @@ -147,23 +169,23 @@ const qscloudVerifyCollectionExists = (options) =>
})
.catch((err) => {
// Return error msg
logger.error(`CLOUD COLLECTION EXISTS 1: ${err}`);
if (err.message) {
logger.error(`CLOUD COLLECTION EXISTS 1 (message): ${err.message}`);
}
if (err.stack) {
logger.error(`CLOUD COLLECTION EXISTS 1 (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`CLOUD COLLECTION EXISTS 1 (message): ${err.message}`);
} else {
logger.error(`CLOUD COLLECTION EXISTS 1: ${err}`);
}

reject(new Error(`COLLECTION EXISTS 1: ${err}`));
});
} catch (err) {
logger.error(`CLOUD COLLECTION EXISTS 2: ${JSON.stringify(err, null, 2)}`);
if (err.message) {
logger.error(`CLOUD COLLECTION EXISTS 2 (stack): ${err.message}`);
}
if (err.stack) {
logger.error(`CLOUD COLLECTION EXISTS 2 (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`CLOUD COLLECTION EXISTS 2 (stack): ${err.message}`);
} else {
logger.error(`CLOUD COLLECTION EXISTS 2: ${JSON.stringify(err, null, 2)}`);
}

reject(new Error(`COLLECTION EXISTS: ${err}`));
Expand Down
Loading

0 comments on commit 07b668d

Please sign in to comment.