File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,29 @@ import { PackageURL } from './package-url.js'
2727
2828import type { QualifiersObject } from './purl-component.js'
2929
30+ /**
31+ * Known Limitation: instanceof checks with ESM/CommonJS interop
32+ * ==============================================================
33+ *
34+ * When using PackageURLBuilder in environments that mix ESM and CommonJS modules
35+ * (such as Vitest tests importing CommonJS-compiled code as ESM), the instanceof
36+ * operator may not work reliably for checking if the built objects are instances
37+ * of PackageURL.
38+ *
39+ * This occurs because:
40+ * - PackageURLBuilder internally imports PackageURL using CommonJS require()
41+ * - External code may import PackageURL using ESM import
42+ * - Node.js creates different wrapper objects for the same class
43+ * - The instanceof check fails due to different object identities
44+ *
45+ * Workaround:
46+ * Instead of: `purl instanceof PackageURL`
47+ * Use: `purl.constructor.name === 'PackageURL'` or check for expected properties/methods
48+ *
49+ * This limitation only affects instanceof checks, not the actual functionality
50+ * of the created PackageURL objects.
51+ */
52+
3053/**
3154 * Builder class for constructing PackageURL instances using a fluent API.
3255 *
Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ SOFTWARE.
2222
2323/**
2424 * @fileoverview Package URL parsing and construction utilities.
25+ *
26+ * Note on instanceof checks:
27+ * When this module is compiled to CommonJS and imported from ESM contexts,
28+ * instanceof checks may fail due to module system interoperability issues.
29+ * See package-url-builder.ts for detailed explanation and workarounds.
2530 */
2631import { decodePurlComponent } from './decode.js'
2732import { PurlError } from './error.js'
You can’t perform that action at this time.
0 commit comments