web: add ESM to generated Client

https://github.com/OpenAPITools/openapi-generator/issues/8881
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-08-23 11:11:18 +02:00
parent ac47fc9295
commit 08f3294a1d
5 changed files with 43 additions and 19 deletions

View File

@ -45,6 +45,7 @@ gen-web:
-o /local/web-api \
--additional-properties=typescriptThreePlus=true,supportsES6=true,npmName=@goauthentik/api,npmVersion=${NPM_VERSION}
mkdir -p web/node_modules/@goauthentik/api
python -m scripts.web_api_esm
cd web-api && npm i
\cp -rfv web-api/* web/node_modules/@goauthentik/api

29
scripts/web_api_esm.py Normal file
View File

@ -0,0 +1,29 @@
"""Enable ESM Modules for generated Web API"""
from json import loads, dumps
TSCONFIG_ESM = {
"compilerOptions": {
"declaration": True,
"target": "es6",
"module": "esnext",
"moduleResolution": "node",
"outDir": "./dist/esm",
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"dist",
"node_modules"
]
}
with open("web-api/package.json", encoding="utf-8") as _package:
package = loads(_package.read())
package["module"] = "./dist/esm/index.js"
package["sideEffects"] = False
package["scripts"]["build"] = "tsc && tsc --project tsconfig.esm.json"
open("web-api/package.json", "w+", encoding="utf-8").write(dumps(package))
open("web-api/tsconfig.esm.json", "w+", encoding="utf-8").write(dumps(TSCONFIG_ESM))

14
web/package-lock.json generated
View File

@ -15,7 +15,7 @@
"@babel/preset-env": "^7.15.0",
"@babel/preset-typescript": "^7.15.0",
"@fortawesome/fontawesome-free": "^5.15.4",
"@goauthentik/api": "^1629704636.0.0",
"@goauthentik/api": "^2021.8.1-rc1-1629709535",
"@lingui/cli": "^3.10.2",
"@lingui/core": "^3.10.4",
"@lingui/macro": "^3.10.2",
@ -1690,9 +1690,9 @@
}
},
"node_modules/@goauthentik/api": {
"version": "1629704636.0.0",
"resolved": "https://registry.npmjs.org/@goauthentik/api/-/api-1629704636.0.0.tgz",
"integrity": "sha512-rjUjp7Gbf/Tzw0hGPx2ig5InXa4bPqj4FkFnIEgR6T1w6jbHV+q2BghztVFDc2hK2ib2NnQUQp6LWIAcYLAdSw=="
"version": "2021.8.1-rc1-1629709535",
"resolved": "https://registry.npmjs.org/@goauthentik/api/-/api-2021.8.1-rc1-1629709535.tgz",
"integrity": "sha512-rlOt63gF3ALGuRIn8RiWRT5cZ4JhKu9koCtdFA7FDOYYU9jWBJ3e/YlFLLOLQrL8Cyl2g553We98t0n8AyDOBQ=="
},
"node_modules/@humanwhocodes/config-array": {
"version": "0.5.0",
@ -9567,9 +9567,9 @@
"integrity": "sha512-eYm8vijH/hpzr/6/1CJ/V/Eb1xQFW2nnUKArb3z+yUWv7HTwj6M7SP957oMjfZjAHU6qpoNc2wQvIxBLWYa/Jg=="
},
"@goauthentik/api": {
"version": "1629704636.0.0",
"resolved": "https://registry.npmjs.org/@goauthentik/api/-/api-1629704636.0.0.tgz",
"integrity": "sha512-rjUjp7Gbf/Tzw0hGPx2ig5InXa4bPqj4FkFnIEgR6T1w6jbHV+q2BghztVFDc2hK2ib2NnQUQp6LWIAcYLAdSw=="
"version": "2021.8.1-rc1-1629709535",
"resolved": "https://registry.npmjs.org/@goauthentik/api/-/api-2021.8.1-rc1-1629709535.tgz",
"integrity": "sha512-rlOt63gF3ALGuRIn8RiWRT5cZ4JhKu9koCtdFA7FDOYYU9jWBJ3e/YlFLLOLQrL8Cyl2g553We98t0n8AyDOBQ=="
},
"@humanwhocodes/config-array": {
"version": "0.5.0",

View File

@ -46,7 +46,7 @@
"@babel/preset-env": "^7.15.0",
"@babel/preset-typescript": "^7.15.0",
"@fortawesome/fontawesome-free": "^5.15.4",
"@goauthentik/api": "^2021.8.1-rc1+1629705955",
"@goauthentik/api": "^2021.8.1-rc1-1629709535",
"@lingui/cli": "^3.10.2",
"@lingui/core": "^3.10.4",
"@lingui/macro": "^3.10.2",

View File

@ -6,7 +6,6 @@ import cssimport from "rollup-plugin-cssimport";
import copy from "rollup-plugin-copy";
import babel from "@rollup/plugin-babel";
import replace from "@rollup/plugin-replace";
import * as authentik from "@goauthentik/api";
const extensions = [".js", ".jsx", ".ts", ".tsx"];
@ -47,6 +46,9 @@ const resources = [
const isProdBuild = process.env.NODE_ENV === "production";
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
function manualChunks(id) {
if (id.includes("@goauthentik/api")) {
return "api";
}
if (id.includes("locales")) {
const parts = id.split("/");
const file = parts[parts.length - 1];
@ -100,11 +102,7 @@ export default [
plugins: [
cssimport(),
resolve({ extensions, browser: true }),
// Because the API Client uses star exports from typescript, we have to explicitly tell rollup
// Which classes can be imported
commonjs({
namedExports: { "@goauthentik/api": Object.keys(authentik) },
}),
commonjs(),
babel({
extensions,
babelHelpers: "runtime",
@ -136,11 +134,7 @@ export default [
plugins: [
cssimport(),
resolve({ extensions, browser: true }),
// Because the API Client uses star exports from typescript, we have to explicitly tell rollup
// Which classes can be imported
commonjs({
namedExports: { "@goauthentik/api": Object.keys(authentik) },
}),
commonjs(),
babel({
extensions,
babelHelpers: "runtime",