Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compile nmp library as 'commonjs' module #1666

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
with:
name: SARIF file
path: results.sarif
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ The following are required to build the CRDs and TypeScript models containing yo

- Docker or Podman
- Git
- Command-line JSON processor (jq)
- Node 18 or later

Testing requires Go 1.21+ to be installed.

Expand Down
57 changes: 43 additions & 14 deletions build/typescript-model/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,49 @@ EOF
export OPENAPI_GENERATOR_COMMIT="v6.3.0"
bash $WORK_DIR/gen/openapi/typescript.sh $WORK_DIR/typescript-models $WORK_DIR/config.sh

apply_sed 's/\"name\": \".*\"/"name": "@devfile\/api"/g' $WORK_DIR/typescript-models/package.json
apply_sed 's/\"description\": \".*\"/"description": "Typescript types for devfile api"/g' $WORK_DIR/typescript-models/package.json
apply_sed 's/\"repository\": \".*\"/"repository": "devfile\/api"/g' $WORK_DIR/typescript-models/package.json
apply_sed 's/\"license\": \".*\"/"license": "Apache-2.0"/g' $WORK_DIR/typescript-models/package.json
apply_sed 's/\"@types\/bluebird\": \".*\"/"@types\/bluebird": "3.5.21"/g' $WORK_DIR/typescript-models/package.json

local workdir=$(pwd)
cd "$WORK_DIR/typescript-models"

######################################################################################################
echo "[INFO] preparing package.json"
######################################################################################################

echo "$(jq '. += {"name": "@devfile/api"}' package.json)" > package.json
echo "$(jq '. += {"description": "Typescript types for devfile api"}' package.json)" > package.json
echo "$(jq '.repository += {"url": "https://github.com/devfile/api"}' package.json)" > package.json
echo "$(jq '. += {"homepage": "https://github.com/devfile/api/blob/main/README.md"}' package.json)" > package.json
echo "$(jq '. += {"license": "Apache-2.0"}' package.json)" > package.json

echo "$(jq 'del(.main)' package.json)" > package.json
echo "$(jq 'del(.type)' package.json)" > package.json
echo "$(jq 'del(.module)' package.json)" > package.json
echo "$(jq 'del(.exports)' package.json)" > package.json
echo "$(jq 'del(.typings)' package.json)" > package.json

echo "$(jq '. += {"main": "dist/index.js"}' package.json)" > package.json
echo "$(jq '. += {"types": "dist/index.d.ts"}' package.json)" > package.json

######################################################################################################
echo "[INFO] preparing tsconfig.json"
######################################################################################################

# remove comments
cp -f tsconfig.json tsconfig.json.copy
node -p 'JSON.stringify(eval(`(${require("fs").readFileSync("tsconfig.json.copy", "utf-8").toString()})`))' | jq > tsconfig.json

# remove unwanted properties
echo "$(jq 'del(.compilerOptions.noUnusedLocals)' tsconfig.json)" > tsconfig.json
echo "$(jq 'del(.compilerOptions.noUnusedParameters)' tsconfig.json)" > tsconfig.json
echo "$(jq 'del(.compilerOptions.noImplicitReturns)' tsconfig.json)" > tsconfig.json
echo "$(jq 'del(.compilerOptions.noFallthroughCasesInSwitch)' tsconfig.json)" > tsconfig.json

# add module type
echo "$(jq '.compilerOptions += {"module": "commonjs"}' tsconfig.json)" > tsconfig.json
# add skipLibCheck
echo "$(jq '.compilerOptions += {"skipLibCheck": true}' tsconfig.json)" > tsconfig.json

cd $workdir

echo "" > $WORK_DIR/typescript-models/.npmignore
echo "[INFO] Generated typescript model which now is available in $WORK_DIR/typescript-models"
}
Expand Down Expand Up @@ -86,14 +123,6 @@ build_typescript_model() {
echo "[INFO] Done."
}

apply_sed(){
if [ "$(uname)" == "Darwin" ]; then
sed -i '' "$@"
else
sed -i "$@"
fi
}

generate_swagger_json
k8s_client_gen
generate_typescript_metadata
Expand Down
Loading