Skip to content

Commit

Permalink
[api] ESM-ify require statements to finish migration from commonsJS
Browse files Browse the repository at this point in the history
  • Loading branch information
freemvmt committed Aug 1, 2024
1 parent 3f221a6 commit 6aa01c8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 39 deletions.
9 changes: 4 additions & 5 deletions api.planx.uk/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import type { JestConfigWithTsJest } from "ts-jest";

const config: JestConfigWithTsJest = {
// we don't use a preset, preferring to give an explicit manual config
// ts-jest presets are deprecated, so we prefer to give an explicit manual config
testEnvironment: "node",
transform: {
// esbuild-jest is unmaintained and can't handle TypeScript with ESM, so we stick to ts-jest
// TODO: if tests are slow, consider swapping out for @swc/jest
// esbuild-jest transformer is unmaintained and can't handle ts-with-esm, so we stick to ts-jest
// TODO: if tests are too slow, consider swapping out for @swc/jest
"^.+\\.[jt]s$": [
"ts-jest",
{
useESM: true,
target: "esnext",
// we need a separate moduleResolutuion for tests (jest v30 may fix this)
// we need a separate module/moduleResolution config for tests (jest v30 may fix this)
tsconfig: "tsconfig.test.json",
},
],
Expand Down
60 changes: 35 additions & 25 deletions api.planx.uk/modules/gis/service/digitalLand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ import { addDesignatedVariable, omitGeometry } from "./helpers.js";
import { baseSchema } from "./local_authorities/metadata/base.js";
import { $api } from "../../../client/index.js";

import * as barkingAndDagenham from "./local_authorities/metadata/barkingAndDagenham.js";
import * as barnet from "./local_authorities/metadata/barnet.js";
import * as birmingham from "./local_authorities/metadata/birmingham.js";
import * as buckinghamshire from "./local_authorities/metadata/buckinghamshire.js";
import * as camden from "./local_authorities/metadata/camden.js";
import * as canterbury from "./local_authorities/metadata/canterbury.js";
import * as doncaster from "./local_authorities/metadata/doncaster.js";
import * as epsomAndEwell from "./local_authorities/metadata/epsomAndEwell.js";
import * as gateshead from "./local_authorities/metadata/gateshead.js";
import * as gloucester from "./local_authorities/metadata/gloucester.js";
import * as lambeth from "./local_authorities/metadata/lambeth.js";
import * as medway from "./local_authorities/metadata/medway.js";
import * as newcastle from "./local_authorities/metadata/newcastle.js";
import * as southwark from "./local_authorities/metadata/southwark.js";
import * as stAlbans from "./local_authorities/metadata/stAlbans.js";
import * as tewkesbury from "./local_authorities/metadata/tewkesbury.js";
import * as westBerkshire from "./local_authorities/metadata/westBerkshire.js";

export interface LocalAuthorityMetadata {
planningConstraints: {
article4: {
Expand All @@ -19,31 +37,23 @@ export interface LocalAuthorityMetadata {

/** When a team publishes their granular Article 4 data, add them to this list. Key must match team slug */
export const localAuthorityMetadata: Record<string, LocalAuthorityMetadata> = {
"barking-and-dagenham": await import(
"./local_authorities/metadata/barkingAndDagenham.js"
),
barnet: await import("./local_authorities/metadata/barnet.js"),
birmingham: await import("./local_authorities/metadata/birmingham.js"),
buckinghamshire: await import(
"./local_authorities/metadata/buckinghamshire.js"
),
camden: await import("./local_authorities/metadata/camden.js"),
canterbury: await import("./local_authorities/metadata/canterbury.js"),
doncaster: await import("./local_authorities/metadata/doncaster.js"),
"epsom-and-ewell": await import(
"./local_authorities/metadata/epsomAndEwell.js"
),
gateshead: await import("./local_authorities/metadata/gateshead.js"),
gloucester: await import("./local_authorities/metadata/gloucester.js"),
lambeth: await import("./local_authorities/metadata/lambeth.js"),
medway: await import("./local_authorities/metadata/medway.js"),
newcastle: await import("./local_authorities/metadata/newcastle.js"),
southwark: await import("./local_authorities/metadata/southwark.js"),
"st-albans": await import("./local_authorities/metadata/stAlbans.js"),
tewkesbury: await import("./local_authorities/metadata/tewkesbury.js"),
"west-berkshire": await import(
"./local_authorities/metadata/westBerkshire.js"
),
"barking-and-dagenham": barkingAndDagenham,
barnet,
birmingham,
buckinghamshire,
camden,
canterbury,
doncaster,
"epsom-and-ewell": epsomAndEwell,
gateshead,
gloucester,
lambeth,
medway,
newcastle,
southwark,
"st-albans": stAlbans,
tewkesbury,
"west-berkshire": westBerkshire,
};

/**
Expand Down
13 changes: 10 additions & 3 deletions api.planx.uk/modules/gis/service/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import * as digitalLand from "./digitalLand.js";
import * as scotland from "./local_authorities/scotland.js";
import * as braintree from "./local_authorities/braintree.js";

const localAuthorities = {
braintree: await import("./local_authorities/braintree.js"),
scotland: await import("./local_authorities/scotland.js"),
digitalLand: await import("./digitalLand.js"),
// braintree: await import("./local_authorities/braintree.js"),
// scotland: await import("./local_authorities/scotland.js"),
// digitalLand: await import("./digitalLand.js"),
digitalLand,
braintree,
scotland,
};

/**
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"lint": "eslint '**/*.{js,ts}' && prettier -c .",
"lint:fix": "eslint --fix '**/*.{js,ts}' && prettier -w .",
"check": "tsc --noEmit && pnpm lint",
"test": "TZ=Europe/London NODE_OPTIONS='$NODE_OPTIONS --experimental-vm-modules' jest --silent",
"test": "TZ=Europe/London NODE_OPTIONS='$NODE_OPTIONS --experimental-vm-modules' jest --no-cache",
"test:coverage": "TZ=Europe/London NODE_OPTIONS='$NODE_OPTIONS --experimental-vm-modules' jest; open ./coverage/lcov-report/index.html",
"test:watch": "TZ=Europe/London NODE_OPTIONS='$NODE_OPTIONS --experimental-vm-modules' jest --coverage=false --watch",
"build": "rimraf ./dist && npx tsc && pnpm copy-swagger-files",
Expand Down Expand Up @@ -111,7 +111,7 @@
"prettier": "^3.2.4",
"rimraf": "^5.0.5",
"supertest": "^7.0.0",
"ts-jest": "^29.2.3",
"ts-jest": "^29.2.4",
"tsx": "^4.16.2",
"typescript": "^5.5.2",
"uuid": "^10.0.0"
Expand Down
8 changes: 4 additions & 4 deletions api.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6aa01c8

Please sign in to comment.