-
Notifications
You must be signed in to change notification settings - Fork 36
/
recompile-@devfile-api.sh
executable file
·81 lines (65 loc) · 2.7 KB
/
recompile-@devfile-api.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#
# Copyright (c) 2021 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
#!/bin/bash
# All the extensions in Visual Studio Code have `commonjs` type.
# Some extensions depend on `@devfile/api` package, which is build as a `module`.
#
# There is a restriction, that it is not possible to use 'import'
# when referencing `module` libraries from `commonjs` code.
#
# This script will recompile `node_modules/@devfile/api` dependency for specified extensions
# to have the dependency with type `commonjs` instead of `module`.
set -e
set -u
recompile_devfile_api() {
local devfile_api_path="code/extensions/${1}/node_modules/@devfile/api"
echo "Recompile ${devfile_api_path}"
# remember current directory
local cur_dir=$(pwd)
# go to dependency directory
cd $devfile_api_path
# delete target dist directory, a new one will be created
rm -rf dist
#
# patch package.json
#
# remove `main`, `type`, `module`, `exports`, `typings` properties
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
# add new `main` and `types` properties with new values
echo "$(jq '. += {"main": "dist/index.js"}' package.json)" > package.json
echo "$(jq '. += {"types": "dist/index.d.ts"}' package.json)" > package.json
#
# patch 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
# recompile the library
npm run build
# return back to the root directory
cd $cur_dir
}
extensions=("che-api" "che-commands" "che-github-authentication" "che-port" "che-remote")
for extension in ${extensions[@]}; do
recompile_devfile_api "${extension}"
done