-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(build): fix bundling of overridden ApiDOM deps (#2853)
Without this fix `npm ci` script in newer npm versions has problem consolidating the dependency tree.
- Loading branch information
Showing
3 changed files
with
126 additions
and
73 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,8 @@ | |
"Buu Nguyen <[email protected]>", | ||
"Josh Ponelat <[email protected]>", | ||
"Kyle Shockey <[email protected]>", | ||
"Sahar Jafari <[email protected]>" | ||
"Sahar Jafari <[email protected]>", | ||
"Vladimír Gorej <[email protected]>" | ||
], | ||
"files": [ | ||
"LICENSE", | ||
|
@@ -138,15 +139,21 @@ | |
], | ||
"overrides": { | ||
"@swagger-api/apidom-ast": { | ||
"short-unique-id": "npm:[email protected]", | ||
"@types/ramda": "npm:[email protected]" | ||
"unraw": "npm:[email protected]", | ||
"@types/ramda": { | ||
".": "npm:[email protected]" | ||
} | ||
}, | ||
"@swagger-api/apidom-core": { | ||
"short-unique-id": "npm:[email protected]", | ||
"@types/ramda": "npm:[email protected]" | ||
"@types/ramda": { | ||
".": "npm:[email protected]" | ||
} | ||
}, | ||
"@swagger-api/apidom-ns-json-schema-draft-4": { | ||
"@types/ramda": "npm:[email protected]" | ||
"@types/ramda": { | ||
".": "npm:[email protected]" | ||
} | ||
}, | ||
"@swagger-api/apidom-ns-openapi-3-0": { | ||
"@types/ramda": "npm:[email protected]" | ||
|
@@ -155,20 +162,51 @@ | |
"@types/ramda": "npm:[email protected]" | ||
}, | ||
"@swagger-api/apidom-reference": { | ||
"@swagger-api/apidom-ns-asyncapi-2": "npm:[email protected]", | ||
"@swagger-api/apidom-ns-api-design-systems": "npm:[email protected]", | ||
"@swagger-api/apidom-parser-adapter-api-design-systems-json": "npm:[email protected]", | ||
"@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "npm:[email protected]", | ||
"@swagger-api/apidom-parser-adapter-asyncapi-json-2": "npm:[email protected]", | ||
"@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "npm:[email protected]", | ||
"@swagger-api/apidom-parser-adapter-json": "npm:[email protected]", | ||
"@swagger-api/apidom-parser-adapter-openapi-json-3-0": "npm:[email protected]", | ||
"@swagger-api/apidom-parser-adapter-openapi-json-3-1": "npm:[email protected]", | ||
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "npm:[email protected]", | ||
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "npm:[email protected]", | ||
"@swagger-api/apidom-parser-adapter-yaml-1-2": "npm:[email protected]", | ||
"axios": "npm:[email protected]", | ||
"@types/ramda": "npm:[email protected]" | ||
"@swagger-api/apidom-ns-asyncapi-2": { | ||
".": "npm:[email protected]" | ||
}, | ||
"@swagger-api/apidom-ns-api-design-systems": { | ||
".": "npm:[email protected]" | ||
}, | ||
"@swagger-api/apidom-parser-adapter-api-design-systems-json": { | ||
".": "npm:[email protected]" | ||
}, | ||
"@swagger-api/apidom-parser-adapter-api-design-systems-yaml": { | ||
".": "npm:[email protected]" | ||
}, | ||
"@swagger-api/apidom-parser-adapter-asyncapi-json-2": { | ||
".": "npm:[email protected]" | ||
}, | ||
"@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": { | ||
".": "npm:[email protected]" | ||
}, | ||
"@swagger-api/apidom-parser-adapter-json": { | ||
".": "npm:[email protected]" | ||
}, | ||
"@swagger-api/apidom-parser-adapter-openapi-json-3-0": { | ||
".": "npm:[email protected]" | ||
}, | ||
"@swagger-api/apidom-parser-adapter-openapi-json-3-1": { | ||
".": "npm:[email protected]" | ||
}, | ||
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": { | ||
".": "npm:[email protected]" | ||
}, | ||
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": { | ||
".": "npm:[email protected]" | ||
}, | ||
"@swagger-api/apidom-parser-adapter-yaml-1-2": { | ||
".": "npm:[email protected]" | ||
}, | ||
"axios": { | ||
".": "npm:[email protected]" | ||
}, | ||
"@types/ramda": { | ||
".": "npm:[email protected]" | ||
}, | ||
"minimatch": { | ||
".": "*" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,49 @@ | ||
/** | ||
* This script simulates `overrides` package.json field | ||
* in older npm versions that doesn't support it. | ||
* This script uses package.json `overrides` field and remove all | ||
* unnecessary dependencies of ApiDOM from npm bundling. | ||
* The mechanism is fully idempotent. | ||
* | ||
* Older versions of npm match the package overrides by name and version, | ||
* instead of just name (this is how new `override` package.json field works). | ||
* Dependencies are only removed when using following override notation: | ||
* | ||
* ``` | ||
* "dep": { | ||
* ".": "dep-override" | ||
* } | ||
* ``` | ||
*/ | ||
/* eslint-disable import/no-dynamic-require */ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const rootPckg = require(path.join(__dirname, '..', 'package.json')); | ||
const apidomReferencePckgPath = path.join( | ||
__dirname, | ||
'..', | ||
'node_modules', | ||
'@swagger-api', | ||
'apidom-reference', | ||
'package.json' | ||
const fs = require('node:fs'); | ||
const path = require('node:path'); | ||
|
||
const rootPckgJSON = require(path.join(__dirname, '..', 'package.json')); // eslint-disable-line import/no-dynamic-require | ||
const { overrides: rootOverrides } = rootPckgJSON; | ||
const swaggerApiOverrides = Object.fromEntries( | ||
Object.entries(rootOverrides).filter(([pckgName]) => pckgName.startsWith('@swagger-api')) | ||
); | ||
const apidomReferencePckg = require(apidomReferencePckgPath); | ||
|
||
const { | ||
overrides: { '@swagger-api/apidom-reference': overrides }, | ||
} = rootPckg; | ||
const overridesList = Object.keys(overrides).filter((key) => key.startsWith('@swagger-api/')); | ||
const readPckg = (pckgName) => { | ||
const pckgPath = path.join(__dirname, '..', 'node_modules', pckgName, 'package.json'); | ||
|
||
overridesList.forEach((override) => { | ||
if (Object.hasOwn(apidomReferencePckg.dependencies, override)) { | ||
apidomReferencePckg.dependencies[override] = '=0.0.1'; | ||
} | ||
}); | ||
return JSON.parse(fs.readFileSync(pckgPath, { encoding: 'utf-8' })); | ||
}; | ||
|
||
const writePckg = (pckgName, pckgJSON) => { | ||
const pckgPath = path.join(__dirname, '..', 'node_modules', pckgName, 'package.json'); | ||
|
||
return fs.writeFileSync(pckgPath, JSON.stringify(pckgJSON, null, 2)); | ||
}; | ||
|
||
fs.writeFileSync(apidomReferencePckgPath, JSON.stringify(apidomReferencePckg, null, 2)); | ||
const removeDeps = (pckgName, overrides) => { | ||
const pckgJSON = readPckg(pckgName); | ||
|
||
Object.entries(overrides).forEach(([dep, override]) => { | ||
if (typeof override === 'object') { | ||
delete pckgJSON?.dependencies[dep]; | ||
} | ||
}); | ||
|
||
return writePckg(pckgName, pckgJSON); | ||
}; | ||
|
||
Object.entries(swaggerApiOverrides).forEach(([pckgName]) => { | ||
removeDeps(pckgName, swaggerApiOverrides[pckgName]); | ||
}); |