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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know if it's okay to remove

    apply_sed 's/\"@types\/bluebird\": \".*\"/"@types\/bluebird": "3.5.21"/g' $WORK_DIR/typescript-models/package.json

?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have deleted it by accident.
I will double check it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recalled why did I remove it at all, there was no dependency on bluebird in package.json.

To check, go to https://www.npmjs.com/package/@devfile/api?activeTab=code and open existing 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