mirror of
https://github.com/coder/code-server.git
synced 2026-11-29 07:16:53 +08:00
* Stop generating shrinkwraps npm 12 removes support for shrinkwraps. Additionally, VS Code has switched to pnpm and this will make generating the shrinkwraps less straightforward. Exact pins in the package.json would not be a sufficient replacement since that does not cover transitive dependencies. The recommendation for end user packages installed globally with npm seems to be to be to bundle dependencies. One idea would be to build for every platform and bundle them all, but the whole reason we have the npm package is to support platforms for which we are not building. If we build them, we could just add a regular release for that platform on GitHub. So instead for each native module we would need to add rebuild commands in the postinstall. And ideally remove the current platform builds to at least try keeping the tarball size down. I am not sure it is worth the effort for what it feels like fighting with npm, so this change does not attempt that. * Remove devDependencies from extensions package.json Not strictly necessary since we only install production dependencies in the postinstall, but might as well save some bytes. * Update Code to 1.146.0 * Support pnpm for post-install * Get Node version from package.json lib/vscode/remote/.npmrc no longer exists * Switch to pnpm VS Code recently switched to pnpm so various scripts needed to be updated, and we might as well follow suite with code-server's own dependencies. In general this change just swaps out "npm" invocations for "pnpm" plus any necessary flag changes to match but to call out some less obvious changes: 1. The extensions directory no longer has a post-install script, so there is no need to copy one anymore. 2. When merging the remote package.json, only copy the dependencies since that is all we need, to avoid copying in new properties like packageManager. 3. Remove unused publish:npm. It points to a nonexistent file anyway. 4. Remove publish:docker and just call the script directly, to avoid an npm/pnpm dependency in a job that really has no need for it. * Update nfpm maintainer
185 lines
5.2 KiB
Bash
Executable File
185 lines
5.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -Eeuo pipefail
|
|
|
|
function unapply_patches() {
|
|
local -i exit_code=0
|
|
quiet quilt pop -af 2>&1 || exit_code=$?
|
|
case $exit_code in
|
|
# Sucessfully unapplied.
|
|
0) ;;
|
|
# No more patches to unapply.
|
|
2) ;;
|
|
# Some error.
|
|
*) return $exit_code ;;
|
|
esac
|
|
}
|
|
|
|
function apply_patches() {
|
|
local -i exit_code=0
|
|
quiet quilt push -a 2>&1 || exit_code=$?
|
|
case $exit_code in
|
|
# Sucessfully applied.
|
|
0) ;;
|
|
# No more patches to apply.
|
|
2) ;;
|
|
# Some error.
|
|
*) return $exit_code ;;
|
|
esac
|
|
}
|
|
|
|
function update_vscode() {
|
|
pushd lib/vscode
|
|
if ! git checkout 2>&1 "$target_vscode_version" ; then
|
|
echo "$target_vscode_version does not exist locally, fetching..."
|
|
git fetch --all --prune --tags
|
|
echo "Checking out $target_vscode_version again..."
|
|
git checkout "$target_vscode_version"
|
|
fi
|
|
popd
|
|
}
|
|
|
|
function refresh_patches() {
|
|
local -i exit_code=0
|
|
while quiet quilt push 2>&1 ; ! (( exit_code=$? )) ; do
|
|
quilt refresh 2>&1
|
|
done
|
|
case $exit_code in
|
|
# No more patches to apply.
|
|
2) ;;
|
|
# Some error.
|
|
*) return $exit_code ;;
|
|
esac
|
|
}
|
|
|
|
function update_node() {
|
|
local node_version
|
|
node_version=$(cat .node-version)
|
|
local target_node_version
|
|
target_node_version=$(jq --raw-output .nativeBuild.target lib/vscode/remote/package.json)
|
|
if [[ $node_version == "$target_node_version" ]] ; then
|
|
echo "Already set to $target_node_version"
|
|
else
|
|
echo "Updating from $node_version to $target_node_version..."
|
|
echo "$target_node_version" > .node-version
|
|
fi
|
|
}
|
|
|
|
function update_package_manager() {
|
|
local manager_version
|
|
manager_version=$(jq --raw-output .packageManager package.json)
|
|
local target_manager_version
|
|
target_manager_version=$(jq --raw-output .packageManager lib/vscode/remote/package.json)
|
|
if [[ $manager_version == "$target_manager_version" ]] ; then
|
|
echo "Already set to $target_manager_version"
|
|
else
|
|
echo "Updating from $manager_version to $target_manager_version..."
|
|
sed -i.bak "s#$manager_version#$target_manager_version#" package.json
|
|
fi
|
|
}
|
|
|
|
function get-webview-script-hash() {
|
|
local html
|
|
html=$(<"$1")
|
|
local start_tag='<script async type="module">'
|
|
if [[ $file == */webWorkerExtensionHostIframe.html ]] ; then
|
|
start_tag='<script>'
|
|
fi
|
|
local end_tag="</script>"
|
|
html=${html##*"$start_tag"}
|
|
html=${html%%"$end_tag"*}
|
|
echo -n "$html" | openssl sha256 -binary | openssl base64
|
|
}
|
|
|
|
function delete_csp() {
|
|
quilt delete csp-hashes.diff || true
|
|
}
|
|
|
|
function update_csp() {
|
|
apply_patches
|
|
|
|
local files=(
|
|
./lib/vscode/src/vs/workbench/contrib/webview/browser/pre/index.html
|
|
./lib/vscode/src/vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html
|
|
)
|
|
|
|
quilt new csp-hashes.diff
|
|
|
|
local file
|
|
for file in "${files[@]}" ; do
|
|
quilt add "$file"
|
|
|
|
local hash
|
|
hash=$(get-webview-script-hash "$file")
|
|
echo "Calculated hash as $hash"
|
|
# Use octothorpe as a delimiter since the hash may contain a slash.
|
|
sed -i.bak "s#'sha256-[^']\+'#'sha256-$hash'#" "$file"
|
|
# For the web worker extension host iframe, there is a matching sha in the
|
|
# web server.
|
|
if [[ $file == */webWorkerExtensionHostIframe.html ]] ; then
|
|
quilt add ./lib/vscode/src/vs/server/node/webClientServer.ts
|
|
sed -i.bak \
|
|
"s#webWorkerExtensionHostIframeScriptSHA = 'sha256-[^']\+'#webWorkerExtensionHostIframeScriptSHA = 'sha256-$hash'#" \
|
|
./lib/vscode/src/vs/server/node/webClientServer.ts
|
|
fi
|
|
done
|
|
|
|
quilt refresh
|
|
}
|
|
|
|
function add_changelog() {
|
|
local file=CHANGELOG.md
|
|
if grep --quiet "Code $target_vscode_version" "$file" ; then
|
|
echo "Changelog for $target_vscode_version already exists"
|
|
else
|
|
# TODO: This is not exactly robust. In particular, it needs to handle if
|
|
# there is already a "changed" section.
|
|
sed -i.bak "s/## Unreleased/## Unreleased\n\nCode v$target_vscode_version\n\n### Changed\n\n- Update to Code $target_vscode_version/" "$file"
|
|
fi
|
|
}
|
|
|
|
function main() {
|
|
cd "$(dirname "${0}")/../.."
|
|
|
|
source ./ci/lib.sh
|
|
|
|
declare -a steps
|
|
|
|
# Hashes are always regenerated to avoid having to resolve conflicts..
|
|
steps+=("Revert CSP hashes" "delete_csp")
|
|
|
|
# If version is not set, assume we are already at the target version and the
|
|
# user is just trying to resolve conflics.
|
|
local target_vscode_version
|
|
if [[ ${VERSION-} ]] ; then
|
|
# Removing patches only needs to be done locally; in CI we start from a
|
|
# fresh clone each time.
|
|
if [[ ! ${CI-} ]] ; then
|
|
steps+=("Unapplying patches" "unapply_patches")
|
|
fi
|
|
target_vscode_version="${VERSION#v}"
|
|
steps+=(
|
|
"Update Code to $target_vscode_version" "update_vscode"
|
|
"Refresh Code patches" "refresh_patches"
|
|
)
|
|
else
|
|
target_vscode_version="$(git -C lib/vscode describe --tags --exact-match)"
|
|
echo "Detected Code version $target_vscode_version"
|
|
fi
|
|
|
|
steps+=(
|
|
"Update Node version" "update_node"
|
|
"Update package manager version" "update_package_manager"
|
|
"Regenerate CSP hashes" "update_csp"
|
|
"Add changelog note" "add_changelog"
|
|
)
|
|
|
|
# Even if a step failed, still output the last checkmark.
|
|
run-steps "${steps[@]}" || true
|
|
|
|
# This step is always manual.
|
|
echo "- [ ] Verify changelog" >> .cache/checklist
|
|
}
|
|
|
|
main "$@"
|