Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor uses of __dirname now that API is using esnext #3507

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api.planx.uk/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ const config: JestConfigWithTsJest = {
useESM: true,
// we need a separate module/moduleResolution config for tests (jest v30 may fix this)
tsconfig: "tsconfig.test.json",
diagnostics: {
ignoreCodes: [1343],
},
astTransformers: {
before: [
{
path: "node_modules/ts-jest-mock-import-meta",
},
],
},
},
],
},
Expand Down
31 changes: 18 additions & 13 deletions api.planx.uk/modules/send/utils/exportZip.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import os from "os";
import path from "path";
import { $api } from "../../../client/index.js";
import { stringify } from "csv-stringify";
import fs from "fs";
import str from "string-to-stream";
import AdmZip from "adm-zip";
import { getFileFromS3 } from "../../file/service/getFile.js";
import {
hasRequiredDataForTemplate,
generateMapHTML,
generateApplicationHTML,
generateDocxTemplateStream,
generateMapHTML,
hasRequiredDataForTemplate,
Passport,
} from "@opensystemslab/planx-core";
import { Passport } from "@opensystemslab/planx-core";
import type { Passport as IPassport } from "../../../types.js";
import type { Stream } from "node:stream";
import type { PlanXExportData } from "@opensystemslab/planx-core/types";
import AdmZip from "adm-zip";
import { stringify } from "csv-stringify";
import fs from "fs";
import type { Stream } from "node:stream";
import os from "os";
import path from "path";
import str from "string-to-stream";
import { fileURLToPath } from "url";
import { $api } from "../../../client/index.js";
import type { Passport as IPassport } from "../../../types.js";
import { getFileFromS3 } from "../../file/service/getFile.js";
import { isApplicationTypeSupported } from "./helpers.js";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is mostly noise from running "organise imports" in this file, only one new import here which is fileURLToPath


export async function buildSubmissionExportZip({
Expand Down Expand Up @@ -206,6 +207,10 @@ export class ExportZip {
this.zip = new AdmZip();
// make a tmp directory to avoid file name collisions if simultaneous applications
this.tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), sessionId));

// we can't directly access `__dirname` in ESM, so get equivalent using fileURLToPath
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory
this.filename = path.join(__dirname, `${flowSlug}-${sessionId}.zip`);
}

Expand Down
1 change: 1 addition & 0 deletions api.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"rimraf": "^5.0.5",
"supertest": "^7.0.0",
"ts-jest": "^29.2.4",
"ts-jest-mock-import-meta": "^1.2.0",
"tsx": "^4.16.2",
"typescript": "^5.5.2",
"uuid": "^10.0.0"
Expand Down
11 changes: 11 additions & 0 deletions api.planx.uk/pnpm-lock.yaml

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

6 changes: 5 additions & 1 deletion api.planx.uk/tests/loadOrRecordNockRequests.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createHash } from "crypto";
import { writeFileSync } from "fs";
import stringify from "json-stringify-pretty-compact";
import nock from "nock";
import path from "path";
import stringify from "json-stringify-pretty-compact";
import { fileURLToPath } from "url";

/**
* Attempts to load HTTP requests that have been made in previous tests.
Expand All @@ -20,6 +21,9 @@ function loadOrRecordNockRequests(filename, hashKey) {
.digest("hex")
.slice(0, 8);

// we can't directly access `__dirname` in ESM, so get equivalent using fileURLToPath
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory
const filePath = path.join(__dirname, "nocks", `${filename}.${hash}.json`);

const records = [];
Expand Down
Loading