Skip to content

Commit

Permalink
Allow external package mappings in imports field in package.json (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Jan 9, 2025
1 parent 03eb60d commit 1beaa9f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
69 changes: 68 additions & 1 deletion src/schemas/json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,73 @@
}
]
},
"packageImportsEntryPath": {
"type": [
"string",
"null"
],
"description": "The module path that is resolved when this specifier is imported. Set to `null` to disallow importing this module."
},
"packageImportsEntryObject": {
"type": "object",
"description": "Used to specify conditional exports, note that Conditional exports are unsupported in older environments, so it's recommended to use the fallback array option if support for those environments is a concern.",
"properties": {
"require": {
"$ref": "#/definitions/packageImportsEntryOrFallback",
"description": "The module path that is resolved when this specifier is imported as a CommonJS module using the `require(...)` function."
},
"import": {
"$ref": "#/definitions/packageImportsEntryOrFallback",
"description": "The module path that is resolved when this specifier is imported as an ECMAScript module using an `import` declaration or the dynamic `import(...)` function."
},
"node": {
"$ref": "#/definitions/packageImportsEntryOrFallback",
"description": "The module path that is resolved when this environment is Node.js."
},
"default": {
"$ref": "#/definitions/packageImportsEntryOrFallback",
"description": "The module path that is resolved when no other export type matches."
},
"types": {
"$ref": "#/definitions/packageImportsEntryOrFallback",
"description": "The module path that is resolved for TypeScript types when this specifier is imported. Should be listed before other conditions."
}
},
"patternProperties": {
"^[^.0-9]+$": {
"$ref": "#/definitions/packageImportsEntryOrFallback",
"description": "The module path that is resolved when this environment matches the property name."
}
},
"additionalProperties": false
},
"packageImportsEntry": {
"oneOf": [
{
"$ref": "#/definitions/packageImportsEntryPath"
},
{
"$ref": "#/definitions/packageImportsEntryObject"
}
]
},
"packageImportsFallback": {
"type": "array",
"description": "Used to allow fallbacks in case this environment doesn't support the preceding entries.",
"items": {
"$ref": "#/definitions/packageImportsEntry"
}
},
"packageImportsEntryOrFallback": {
"oneOf": [
{
"$ref": "#/definitions/packageImportsEntry"
},
{
"$ref": "#/definitions/packageImportsFallback"
}
]
},
"fundingUrl": {
"type": "string",
"format": "uri",
Expand Down Expand Up @@ -349,7 +416,7 @@
"type": "object",
"patternProperties": {
"^#.+$": {
"$ref": "#/definitions/packageExportsEntryOrFallback",
"$ref": "#/definitions/packageImportsEntryOrFallback",
"description": "The module path that is resolved when this environment matches the property name."
}
},
Expand Down
7 changes: 7 additions & 0 deletions src/test/package/imports-test4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"description": "different package",
"imports": {
"#foo": "different-package"
},
"name": "my-mod"
}

0 comments on commit 1beaa9f

Please sign in to comment.