From 1e05e4b8587f65e36e012e805a6c7b9a234ffeff Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 28 May 2024 19:01:11 +0200 Subject: [PATCH 1/2] test: skip static-import on > v21 (#81) Better fix for #80 Closes #73 --- ...import-assert.mjs => v18-v21-static-import-assert.mjs} | 0 test/version-check.js | 8 +++++++- 2 files changed, 7 insertions(+), 1 deletion(-) rename test/hook/{v18-static-import-assert.mjs => v18-v21-static-import-assert.mjs} (100%) diff --git a/test/hook/v18-static-import-assert.mjs b/test/hook/v18-v21-static-import-assert.mjs similarity index 100% rename from test/hook/v18-static-import-assert.mjs rename to test/hook/v18-v21-static-import-assert.mjs diff --git a/test/version-check.js b/test/version-check.js index fc3341a..fdc2f5c 100644 --- a/test/version-check.js +++ b/test/version-check.js @@ -12,10 +12,11 @@ process.env.IITM_TEST_FILE = filename const [processMajor, processMinor] = process.versions.node.split('.').map(Number) -const match = filename.match(/v([0-9]+)(?:\.([0-9]+))?/) +const match = filename.match(/v([0-9]+)(?:\.([0-9]+))?(?:-v([0-9]+))?/) const majorRequirement = match ? match[1] : 0 const minorRequirement = match && match[2] +const majorMax = match ? match[3] : Infinity if (processMajor < majorRequirement) { console.log(`skipping ${filename} as this is Node.js v${processMajor} and test wants v${majorRequirement}`) @@ -25,3 +26,8 @@ if (processMajor <= majorRequirement && processMinor < minorRequirement) { console.log(`skipping ${filename} as this is Node.js v${processMajor}.${processMinor} and test wants >=v${majorRequirement}.${minorRequirement}`) process.exit(0) } + +if (processMajor > majorMax) { + console.log(`skipping ${filename} as this is Node.js v${processMajor} and test wants <=v${majorMax}`) + process.exit(0) +} From 0d9f351c8912cdcf7b0cf4813d140d6dec78fa7a Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 28 May 2024 19:01:25 +0200 Subject: [PATCH 2/2] fix: Handle cyclical reference to current file (#83) Closes #82 --- hook.js | 9 +++++++++ test/fixtures/cyclical-self.mjs | 8 ++++++++ test/hook/cyclical-self.mjs | 4 ++++ 3 files changed, 21 insertions(+) create mode 100644 test/fixtures/cyclical-self.mjs create mode 100644 test/hook/cyclical-self.mjs diff --git a/hook.js b/hook.js index 79a2e5b..5bea2b9 100644 --- a/hook.js +++ b/hook.js @@ -253,6 +253,15 @@ function createHook (meta) { return url } + // If the file is referencing itself, we need to skip adding the iitm search params + if (url.url === parentURL) { + return { + url: url.url, + shortCircuit: true, + format: url.format + } + } + specifiers.set(url.url, specifier) return { diff --git a/test/fixtures/cyclical-self.mjs b/test/fixtures/cyclical-self.mjs new file mode 100644 index 0000000..cabcb57 --- /dev/null +++ b/test/fixtures/cyclical-self.mjs @@ -0,0 +1,8 @@ +// File generated from our OpenAPI spec by Stainless. +import * as BatchesAPI from './cyclical-self.mjs' +export class Batches {} +export class BatchesPage {} +(function (Batches) { + Batches.BatchesPage = BatchesAPI.BatchesPage +// eslint-disable-next-line no-class-assign +})(Batches || (Batches = {})) diff --git a/test/hook/cyclical-self.mjs b/test/hook/cyclical-self.mjs new file mode 100644 index 0000000..4e40613 --- /dev/null +++ b/test/hook/cyclical-self.mjs @@ -0,0 +1,4 @@ +import { Batches, BatchesPage } from '../fixtures/cyclical-self.mjs' +import { strictEqual } from 'assert' + +strictEqual(Batches.BatchesPage, BatchesPage)