Skip to content

Commit

Permalink
Convert from CJS to ESM
Browse files Browse the repository at this point in the history
The server builds are still CJS for now. This is made possible by
remix-run/remix#7180, which was included in
the recent release of Remix 2.0.1.
  • Loading branch information
lpsinger committed Sep 22, 2023
1 parent baff933 commit 2ac4da9
Show file tree
Hide file tree
Showing 20 changed files with 15 additions and 27 deletions.
2 changes: 1 addition & 1 deletion __mocks__/openid-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ const openid_client = jest.createMockFromModule('openid-client')

openid_client.TokenSet = {}

module.exports = openid_client
export default openid_client
4 changes: 1 addition & 3 deletions app/email-incoming/circulars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ interface EmailProps {

const fromName = 'GCN Circulars'

// FIXME: must use module.exports here for OpenTelemetry shim to work correctly.
// See https://dev.to/heymarkkop/how-to-solve-cannot-redefine-property-handler-on-aws-lambda-3j67
module.exports.handler = createEmailIncomingMessageHandler(
export const handler = createEmailIncomingMessageHandler(
async ({ content }) => {
const parsed = await parseEmailContentFromSource(content)
const { address: userEmail, submittedHow } = getFromAddress(parsed.from)
Expand Down
5 changes: 1 addition & 4 deletions app/email-incoming/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ const origData = {

/**
* Forward incoming emails to Zendesk.
*
* FIXME: must use module.exports here for OpenTelemetry shim to work correctly.
* See https://dev.to/heymarkkop/how-to-solve-cannot-redefine-property-handler-on-aws-lambda-3j67
*/
module.exports.handler = createEmailIncomingMessageHandler(
export const handler = createEmailIncomingMessageHandler(
async ({ content, receipt: { recipients } }) => {
let data = { recipients, emailData: content.toString(), ...origData }
data = await transformRecipients(data)
Expand Down
4 changes: 1 addition & 3 deletions app/scheduled/ads/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ async function* getAdsEntries() {
} while (length)
}

// FIXME: must use module.exports here for OpenTelemetry shim to work correctly.
// See https://dev.to/heymarkkop/how-to-solve-cannot-redefine-property-handler-on-aws-lambda-3j67
module.exports.handler = async () => {
export async function handler() {
const db = await tables()
for await (const entries of getAdsEntries()) {
await Promise.all(
Expand Down
4 changes: 1 addition & 3 deletions app/scheduled/circulars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { forAllCirculars } from './actions'
import { statsAction } from './actions/stats'
import { jsonUploadAction, txtUploadAction } from './actions/tar'

// FIXME: must use module.exports here for OpenTelemetry shim to work correctly.
// See https://dev.to/heymarkkop/how-to-solve-cannot-redefine-property-handler-on-aws-lambda-3j67
module.exports.handler = async () => {
export async function handler() {
await forAllCirculars(jsonUploadAction, txtUploadAction, statsAction)
}
4 changes: 1 addition & 3 deletions app/table-streams/circulars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ async function send(circular: Circular) {
})
}

// FIXME: must use module.exports here for OpenTelemetry shim to work correctly.
// See https://dev.to/heymarkkop/how-to-solve-cannot-redefine-property-handler-on-aws-lambda-3j67
module.exports.handler = createTriggerHandler(
export const handler = createTriggerHandler(
async ({ eventName, dynamodb }: DynamoDBRecord) => {
const id = unmarshallTrigger(dynamodb!.Keys).circularId as number
const promises = []
Expand Down
1 change: 1 addition & 0 deletions esbuild.mjs → esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const options = {
logLevel: 'info',
outdir: 'build',
outbase: 'app',
outExtension: { '.js': '.cjs' },
external: ['@aws-sdk/*', 'aws-sdk'],
platform: 'node',
target: ['node18'],
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"private": true,
"type": "module",
"name": "@nasa-gcn/gcn.nasa.gov",
"description": "General Coordinates Network web site",
"repository": {
Expand All @@ -10,12 +11,12 @@
"scripts": {
"build:remix": "remix build",
"build:sass": "sass -Inode_modules/nasawds/src/theme -Inode_modules/@uswds -Inode_modules/@uswds/uswds/packages app:app",
"build:esbuild": "node esbuild.mjs",
"build:esbuild": "node esbuild.js",
"build:website": "run-s build:sass build:remix",
"build": "run-p build:website build:esbuild",
"dev:remix": "remix dev --manual -c \"arc sandbox -e testing --host localhost\"",
"dev:sass": "sass --watch -Inode_modules/nasawds/src/theme -Inode_modules/@uswds -Inode_modules/@uswds/uswds/packages app:app",
"dev:esbuild": "node esbuild.mjs --dev",
"dev:esbuild": "node esbuild.js --dev",
"dev": "run-p \"dev:*\"",
"prepare": "husky install",
"deploy": "arc deploy --no-hydrate --prune --production",
Expand Down
2 changes: 1 addition & 1 deletion remix.config.mjs → remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default {
assetsBuildDirectory: 'build/static',
publicPath: '/_static/app/',
server: './server.ts',
serverBuildPath: 'build/server/index.js',
serverBuildPath: 'build/server/index.cjs',
serverMinify: isProduction,
serverModuleFormat: 'cjs',
serverDependenciesToBundle: [
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions sandbox-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
import { readFile } from 'fs/promises'

const { readFile } = require('fs/promises')

module.exports = async function () {
export default async function () {
const text = await readFile('sandbox-seed.json', { encoding: 'utf-8' })
const { circulars } = JSON.parse(text)
return circulars.flatMap((item) => [
Expand Down
4 changes: 1 addition & 3 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import sourceMapSupport from 'source-map-support'
sourceMapSupport.install()
installGlobals()

// FIXME: must use module.exports here for OpenTelemetry shim to work correctly.
// See https://dev.to/heymarkkop/how-to-solve-cannot-redefine-property-handler-on-aws-lambda-3j67
module.exports.handler = createRequestHandler({
export const handler = createRequestHandler({
build,
mode: process.env.NODE_ENV,
})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { logDevReady } from '@remix-run/node'
import * as fs from 'node:fs'
import * as path from 'node:path'

const buildPath = 'build/server/index.js'
const buildPath = 'build/server/index.cjs'

let lastTimeout

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 2ac4da9

Please sign in to comment.