Skip to content

Commit 4d527f9

Browse files
fix: compile nmp library as 'commonjs' module (#1666)
* fix: compile nmp library as 'commonjs' module Signed-off-by: vitaliy-guliy <[email protected]> * fix: compile nmp library as 'commonjs' module Signed-off-by: vitaliy-guliy <[email protected]> * fix: update version of upload-artifact action Signed-off-by: vitaliy-guliy <[email protected]> --------- Signed-off-by: vitaliy-guliy <[email protected]>
1 parent d009cca commit 4d527f9

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

.github/workflows/scorecard.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
4646
# format to the repository Actions tab.
4747
- name: "Upload artifact"
48-
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
48+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
4949
with:
5050
name: SARIF file
5151
path: results.sarif

CONTRIBUTING.md

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ The following are required to build the CRDs and TypeScript models containing yo
4646

4747
- Docker or Podman
4848
- Git
49+
- Command-line JSON processor (jq)
50+
- Node 18 or later
4951

5052
Testing requires Go 1.21+ to be installed.
5153

build/typescript-model/generate.sh

+43-14
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,49 @@ EOF
5353
export OPENAPI_GENERATOR_COMMIT="v6.3.0"
5454
bash $WORK_DIR/gen/openapi/typescript.sh $WORK_DIR/typescript-models $WORK_DIR/config.sh
5555

56-
apply_sed 's/\"name\": \".*\"/"name": "@devfile\/api"/g' $WORK_DIR/typescript-models/package.json
57-
apply_sed 's/\"description\": \".*\"/"description": "Typescript types for devfile api"/g' $WORK_DIR/typescript-models/package.json
58-
apply_sed 's/\"repository\": \".*\"/"repository": "devfile\/api"/g' $WORK_DIR/typescript-models/package.json
59-
apply_sed 's/\"license\": \".*\"/"license": "Apache-2.0"/g' $WORK_DIR/typescript-models/package.json
60-
apply_sed 's/\"@types\/bluebird\": \".*\"/"@types\/bluebird": "3.5.21"/g' $WORK_DIR/typescript-models/package.json
61-
56+
local workdir=$(pwd)
57+
cd "$WORK_DIR/typescript-models"
58+
59+
######################################################################################################
60+
echo "[INFO] preparing package.json"
61+
######################################################################################################
62+
63+
echo "$(jq '. += {"name": "@devfile/api"}' package.json)" > package.json
64+
echo "$(jq '. += {"description": "Typescript types for devfile api"}' package.json)" > package.json
65+
echo "$(jq '.repository += {"url": "https://github.com/devfile/api"}' package.json)" > package.json
66+
echo "$(jq '. += {"homepage": "https://github.com/devfile/api/blob/main/README.md"}' package.json)" > package.json
67+
echo "$(jq '. += {"license": "Apache-2.0"}' package.json)" > package.json
68+
69+
echo "$(jq 'del(.main)' package.json)" > package.json
70+
echo "$(jq 'del(.type)' package.json)" > package.json
71+
echo "$(jq 'del(.module)' package.json)" > package.json
72+
echo "$(jq 'del(.exports)' package.json)" > package.json
73+
echo "$(jq 'del(.typings)' package.json)" > package.json
74+
75+
echo "$(jq '. += {"main": "dist/index.js"}' package.json)" > package.json
76+
echo "$(jq '. += {"types": "dist/index.d.ts"}' package.json)" > package.json
77+
78+
######################################################################################################
79+
echo "[INFO] preparing tsconfig.json"
80+
######################################################################################################
81+
82+
# remove comments
83+
cp -f tsconfig.json tsconfig.json.copy
84+
node -p 'JSON.stringify(eval(`(${require("fs").readFileSync("tsconfig.json.copy", "utf-8").toString()})`))' | jq > tsconfig.json
85+
86+
# remove unwanted properties
87+
echo "$(jq 'del(.compilerOptions.noUnusedLocals)' tsconfig.json)" > tsconfig.json
88+
echo "$(jq 'del(.compilerOptions.noUnusedParameters)' tsconfig.json)" > tsconfig.json
89+
echo "$(jq 'del(.compilerOptions.noImplicitReturns)' tsconfig.json)" > tsconfig.json
90+
echo "$(jq 'del(.compilerOptions.noFallthroughCasesInSwitch)' tsconfig.json)" > tsconfig.json
91+
92+
# add module type
93+
echo "$(jq '.compilerOptions += {"module": "commonjs"}' tsconfig.json)" > tsconfig.json
94+
# add skipLibCheck
95+
echo "$(jq '.compilerOptions += {"skipLibCheck": true}' tsconfig.json)" > tsconfig.json
96+
97+
cd $workdir
98+
6299
echo "" > $WORK_DIR/typescript-models/.npmignore
63100
echo "[INFO] Generated typescript model which now is available in $WORK_DIR/typescript-models"
64101
}
@@ -86,14 +123,6 @@ build_typescript_model() {
86123
echo "[INFO] Done."
87124
}
88125

89-
apply_sed(){
90-
if [ "$(uname)" == "Darwin" ]; then
91-
sed -i '' "$@"
92-
else
93-
sed -i "$@"
94-
fi
95-
}
96-
97126
generate_swagger_json
98127
k8s_client_gen
99128
generate_typescript_metadata

0 commit comments

Comments
 (0)