Skip to content

Commit

Permalink
fix: convert CJS modules to ES modules
Browse files Browse the repository at this point in the history
  • Loading branch information
dzehnder committed Oct 11, 2023
1 parent b8a5733 commit 1acf7ff
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 19 deletions.
7 changes: 4 additions & 3 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
const AWS = require('aws-sdk');
const { log } = require('./util.js');
import AWS from 'aws-sdk';
import { log } from './util.js';

const TABLE_SITES = 'sites';
const TABLE_AUDITS = 'audits';
Expand Down Expand Up @@ -117,4 +117,5 @@ function DB(config) {
saveAuditError,
};
}
module.exports = DB;

export default DB;
9 changes: 7 additions & 2 deletions src/edge-delivery-service-admin-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
* governing permissions and limitations under the License.
*/
const BASE_URL = 'https://www.hlx.live/';

/**
* Retrieve the status of the admin endpoint.
* @returns {Promise<string>} - The lastModification property.
* @throws {Error} - Throws an error if there's a network issue
* or some other error while fetching data.
*/
function EdgeDeliveryServiceAdminClient() {

const getLastModification = async () => {
try {
const response = await fetch(`${BASE_URL}docs/status.json`);
Expand All @@ -34,6 +34,11 @@ function EdgeDeliveryServiceAdminClient() {
throw error;
}
};

// Return the function from within the EdgeDeliveryServiceAdminClient
return {
getLastModification,
};
}

module.exports = EdgeDeliveryServiceAdminClient;
export default EdgeDeliveryServiceAdminClient;
6 changes: 3 additions & 3 deletions src/github-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
const axios = require('axios');
const { log } = require('./util.js');
import axios from 'axios';
import { log } from './util.js';

const SECONDS_IN_A_DAY = 86400; // Number of seconds in a day

Expand Down Expand Up @@ -120,4 +120,4 @@ function GithubClient(config) {
};
}

module.exports = GithubClient;
export default GithubClient;
13 changes: 9 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import secrets from '@adobe/helix-shared-secrets';
import wrap from '@adobe/helix-shared-wrap';
import { logger } from '@adobe/helix-universal-logger';
import { helixStatus } from '@adobe/helix-status';

const DB = require('./db');
const PSIClient = require('./psi-client');
import DB from './db.js'; // Assuming the exported content of './db' is default exported
import PSIClient from './psi-client.js'; // Assuming the exported content of './psi-client' is default exported

/**
* This is the main function
Expand All @@ -24,11 +23,17 @@ const PSIClient = require('./psi-client');
* @returns {Response} a response
*/
async function run(request, context) {
const db = DB({ region: process.env.REGION, accessKeyId: process.env.ACCESS_KEY_ID, secretAccessKey: process.env.SECRET_ACCESS_KEY });
const db = DB({
region: process.env.REGION,
accessKeyId: process.env.ACCESS_KEY_ID,
secretAccessKey: process.env.SECRET_ACCESS_KEY,
});

const psiClient = PSIClient({
apiKey: process.env.PAGESPEED_API_KEY,
baseUrl: process.env.PAGESPEED_API_BASE_URL,
});

const auditResult = await psiClient.runAudit('https://www.bamboohr.com/');
await db.saveAuditIndex(auditResult);
}
Expand Down
6 changes: 3 additions & 3 deletions src/psi-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
const axios = require('axios');
const { log } = require('./util.js');
import axios from 'axios';
import { log } from './util.js';

function PSIClient(config) {
const AUDIT_TYPE = 'PSI';
Expand Down Expand Up @@ -182,4 +182,4 @@ function PSIClient(config) {
};
}

module.exports = PSIClient;
export default PSIClient;
6 changes: 3 additions & 3 deletions src/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
const AWS = require('aws-sdk');
const { log } = require('util');
import AWS from 'aws-sdk';
import { log } from 'util';

const s3 = new AWS.S3();

Expand All @@ -35,4 +35,4 @@ function S3(config) {
}
}

module.exports = { S3 };
export { S3 };
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ const log = (level, message, ...args) => {
}
};

module.exports = {
export {
log,
};

0 comments on commit 1acf7ff

Please sign in to comment.