Skip to content

Commit a9167d2

Browse files
authored
feat: move and upload sourcemaps (#2545)
1 parent e1f7642 commit a9167d2

File tree

4 files changed

+190
-0
lines changed

4 files changed

+190
-0
lines changed

.github/workflows/insider-spearhead.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
GH_REPO_PATH: ${{ github.repository }}
2929
ORG_NAME: ${{ github.repository_owner }}
3030
OS_NAME: osx
31+
SOURCEMAPS_REPOSITORY: ${{ github.repository_owner }}/sourcemaps
3132
VERSIONS_REPOSITORY: ${{ github.repository_owner }}/versions
3233
VSCODE_ARCH: arm64
3334
VSCODE_LATEST: ${{ github.event.inputs.dont_update == 'true' && 'no' || 'yes' }}
@@ -76,6 +77,10 @@ jobs:
7677
run: ./prepare_src.sh
7778
if: env.SHOULD_BUILD == 'yes'
7879

80+
- name: Upload sourcemaps
81+
run: ./upload_sourcemaps.sh
82+
if: env.SHOULD_BUILD == 'yes'
83+
7984
- name: Release source
8085
env:
8186
GITHUB_TOKEN: ${{ secrets.STRONGER_GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ build/linux/appimage/VSCodium
1414
build/windows/msi/releasedir
1515
build/windows/msi/Files*.wxs
1616
build/windows/msi/Files*.wixobj
17+
sourcemaps/
1718
stores/snapcraft/insider/*.snap
1819
stores/snapcraft/stable/*.snap

patches/sourcemaps.patch

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
diff --git a/build/gulpfile.extensions.js b/build/gulpfile.extensions.js
2+
index 7826f48..ff0e2f0 100644
3+
--- a/build/gulpfile.extensions.js
4+
+++ b/build/gulpfile.extensions.js
5+
@@ -74,3 +74,3 @@ const compilations = [
6+
7+
-const getBaseUrl = out => `https://main.vscode-cdn.net/sourcemaps/${commit}/${out}`;
8+
+const getBaseUrl = out => `https://github.com/VSCodium/sourcemaps/releases/download/${commit}/${out.replaceAll('/', '-')}`;
9+
10+
diff --git a/build/gulpfile.reh.js b/build/gulpfile.reh.js
11+
index 10b7b44..895b25b 100644
12+
--- a/build/gulpfile.reh.js
13+
+++ b/build/gulpfile.reh.js
14+
@@ -454,3 +454,3 @@ function tweakProductForServerWeb(product) {
15+
util.rimraf(`out-vscode-${type}-min`),
16+
- optimize.minifyTask(`out-vscode-${type}`, `https://main.vscode-cdn.net/sourcemaps/${commit}/core`)
17+
+ optimize.minifyTask(`out-vscode-${type}`, `https://github.com/VSCodium/sourcemaps/releases/download/${commit}/core`)
18+
));
19+
diff --git a/build/gulpfile.vscode.js b/build/gulpfile.vscode.js
20+
index ed06b6a..ebedfc4 100644
21+
--- a/build/gulpfile.vscode.js
22+
+++ b/build/gulpfile.vscode.js
23+
@@ -147,3 +147,3 @@ gulp.task(bundleVSCodeTask);
24+
25+
-const sourceMappingURLBase = `https://main.vscode-cdn.net/sourcemaps/${commit}`;
26+
+const sourceMappingURLBase = `https://github.com/VSCodium/sourcemaps/releases/download/${commit}`;
27+
const minifyVSCodeTask = task.define('minify-vscode', task.series(
28+
diff --git a/build/gulpfile.vscode.web.js b/build/gulpfile.vscode.web.js
29+
index 295a977..ba0a598 100644
30+
--- a/build/gulpfile.vscode.web.js
31+
+++ b/build/gulpfile.vscode.web.js
32+
@@ -140,3 +140,3 @@ const minifyVSCodeWebTask = task.define('minify-vscode-web', task.series(
33+
util.rimraf('out-vscode-web-min'),
34+
- optimize.minifyTask('out-vscode-web', `https://main.vscode-cdn.net/sourcemaps/${commit}/core`)
35+
+ optimize.minifyTask('out-vscode-web', `https://github.com/VSCodium/sourcemaps/releases/download/${commit}/core`)
36+
));
37+
diff --git a/build/lib/extensions.js b/build/lib/extensions.js
38+
index c80a1be..000cf9f 100644
39+
--- a/build/lib/extensions.js
40+
+++ b/build/lib/extensions.js
41+
@@ -76,3 +76,3 @@ const root = path_1.default.dirname(path_1.default.dirname(__dirname));
42+
const commit = (0, getVersion_1.getVersion)(root);
43+
-const sourceMappingURLBase = `https://main.vscode-cdn.net/sourcemaps/${commit}`;
44+
+const sourceMappingURLBase = `https://github.com/VSCodium/sourcemaps/releases/download/${commit}`;
45+
function minifyExtensionResources(input) {
46+
@@ -205,3 +205,3 @@ function fromLocalWebpack(extensionPath, webpackConfigFileName, disableMangle) {
47+
data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) {
48+
- return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions/${path_1.default.basename(extensionPath)}/${relativeOutputPath}/${g1}`;
49+
+ return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions-${path_1.default.basename(extensionPath).replaceAll('/', '-')}-${relativeOutputPath.replaceAll('/', '-')}-${g1.replaceAll('/', '-')}`;
50+
}), 'utf8');
51+
diff --git a/build/lib/extensions.ts b/build/lib/extensions.ts
52+
index 9e7cf9f..e5f7c24 100644
53+
--- a/build/lib/extensions.ts
54+
+++ b/build/lib/extensions.ts
55+
@@ -31,3 +31,3 @@ const root = path.dirname(path.dirname(__dirname));
56+
const commit = getVersion(root);
57+
-const sourceMappingURLBase = `https://main.vscode-cdn.net/sourcemaps/${commit}`;
58+
+const sourceMappingURLBase = `https://github.com/VSCodium/sourcemaps/releases/download/${commit}`;
59+
60+
@@ -179,3 +179,3 @@ function fromLocalWebpack(extensionPath: string, webpackConfigFileName: string,
61+
data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) {
62+
- return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/${relativeOutputPath}/${g1}`;
63+
+ return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions-${path.basename(extensionPath).replaceAll('/', '-')}-${relativeOutputPath.replaceAll('/', '-')}-${g1.replaceAll('/', '-')}`;
64+
}), 'utf8');
65+
diff --git a/build/lib/optimize.js b/build/lib/optimize.js
66+
index fbc455b..4e7fe85 100644
67+
--- a/build/lib/optimize.js
68+
+++ b/build/lib/optimize.js
69+
@@ -186,3 +186,3 @@ function bundleTask(opts) {
70+
function minifyTask(src, sourceMapBaseUrl) {
71+
- const sourceMappingURL = sourceMapBaseUrl ? ((f) => `${sourceMapBaseUrl}/${f.relative}.map`) : undefined;
72+
+ const sourceMappingURL = sourceMapBaseUrl ? ((f) => `${sourceMapBaseUrl}-${f.relative.replaceAll('/', '-')}.map`) : undefined;
73+
return cb => {
74+
diff --git a/build/lib/optimize.ts b/build/lib/optimize.ts
75+
index d89d0d6..fca30cf 100644
76+
--- a/build/lib/optimize.ts
77+
+++ b/build/lib/optimize.ts
78+
@@ -211,3 +211,3 @@ export function bundleTask(opts: IBundleESMTaskOpts): () => NodeJS.ReadWriteStre
79+
export function minifyTask(src: string, sourceMapBaseUrl?: string): (cb: any) => void {
80+
- const sourceMappingURL = sourceMapBaseUrl ? ((f: any) => `${sourceMapBaseUrl}/${f.relative}.map`) : undefined;
81+
+ const sourceMappingURL = sourceMapBaseUrl ? ((f: any) => `${sourceMapBaseUrl}-${f.relative.replaceAll('/', '-')}.map`) : undefined;
82+
83+
diff --git a/build/lib/util.js b/build/lib/util.js
84+
index 389b9e0..9abdb3c 100644
85+
--- a/build/lib/util.js
86+
+++ b/build/lib/util.js
87+
@@ -235,4 +235,4 @@ function rewriteSourceMappingURL(sourceMappingURLBase) {
88+
const contents = f.contents.toString('utf8');
89+
- const str = `//# sourceMappingURL=${sourceMappingURLBase}/${path_1.default.dirname(f.relative).replace(/\\/g, '/')}/$1`;
90+
- f.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, str));
91+
+ const fp = path_1.default.dirname(f.relative).replace(/\\/g, '/').replaceAll('/', '-');
92+
+ f.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, (_m, p) => `//# sourceMappingURL=${sourceMappingURLBase}/${fp}-${p.replaceAll('/', '-')}`));
93+
return f;
94+
diff --git a/build/lib/util.ts b/build/lib/util.ts
95+
index 4931342..833091c 100644
96+
--- a/build/lib/util.ts
97+
+++ b/build/lib/util.ts
98+
@@ -285,4 +285,4 @@ export function rewriteSourceMappingURL(sourceMappingURLBase: string): NodeJS.Re
99+
const contents = (<Buffer>f.contents).toString('utf8');
100+
- const str = `//# sourceMappingURL=${sourceMappingURLBase}/${path.dirname(f.relative).replace(/\\/g, '/')}/$1`;
101+
- f.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, str));
102+
+ const fp = path.dirname(f.relative).replace(/\\/g, '/').replaceAll('/', '-');
103+
+ f.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, (_m, p) => `//# sourceMappingURL=${sourceMappingURLBase}/${fp}-${p.replaceAll('/', '-')}`));
104+
return f;

upload_sourcemaps.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
npm install -g checksum github-release-cli
6+
7+
mkdir -p sourcemaps
8+
cd sourcemaps
9+
10+
SOURCE_DIR="../vscode/.build/extensions"
11+
DESTINATION_DIR="extensions"
12+
13+
find "${SOURCE_DIR}" -type f -name "*.js.map" | while read -r SOURCE_FILE_PATH; do
14+
RELATIVE_PATH="${SOURCE_FILE_PATH#$SOURCE_DIR/}"
15+
FLATTENED_FILENAME="${RELATIVE_PATH//\//-}"
16+
17+
cp "${SOURCE_FILE_PATH}" "$DESTINATION_DIR-${FLATTENED_FILENAME}"
18+
done
19+
20+
SOURCE_DIR="../vscode/out-vscode-min"
21+
DESTINATION_DIR="core"
22+
23+
find "${SOURCE_DIR}" -type f -name "*.js.map" | while read -r SOURCE_FILE_PATH; do
24+
RELATIVE_PATH="${SOURCE_FILE_PATH#$SOURCE_DIR/}"
25+
FLATTENED_FILENAME="${RELATIVE_PATH//\//-}"
26+
27+
cp "${SOURCE_FILE_PATH}" "$DESTINATION_DIR-${FLATTENED_FILENAME}"
28+
done
29+
30+
find . -type f -exec checksum -a sha256 {} \; > checksum.txt
31+
32+
checksum -a sha256 checksum.txt > checksum.txt.sha256
33+
34+
REPOSITORY_OWNER="${SOURCEMAPS_REPOSITORY/\/*/}"
35+
REPOSITORY_NAME="${SOURCEMAPS_REPOSITORY/*\//}"
36+
37+
gh release create "${BUILD_SOURCEVERSION}" --repo "${SOURCEMAPS_REPOSITORY}" --title "${RELEASE_VERSION}"
38+
39+
set +e
40+
41+
for FILE in *; do
42+
if [[ -f "${FILE}" ]]; then
43+
echo "::group::Uploading '${FILE}' at $( date "+%T" )"
44+
gh release upload --repo "${SOURCEMAPS_REPOSITORY}" "${RELEASE_VERSION}" "${FILE}"
45+
46+
EXIT_STATUS=$?
47+
echo "exit: ${EXIT_STATUS}"
48+
49+
if (( "${EXIT_STATUS}" )); then
50+
for (( i=0; i<10; i++ )); do
51+
github-release delete --owner "${REPOSITORY_OWNER}" --repo "${REPOSITORY_NAME}" --tag "${BUILD_SOURCEVERSION}" "${FILE}"
52+
53+
sleep $(( 15 * (i + 1)))
54+
55+
echo "RE-Uploading '${FILE}' at $( date "+%T" )"
56+
gh release upload --repo "${SOURCEMAPS_REPOSITORY}" "${BUILD_SOURCEVERSION}" "${FILE}"
57+
58+
EXIT_STATUS=$?
59+
echo "exit: ${EXIT_STATUS}"
60+
61+
if ! (( "${EXIT_STATUS}" )); then
62+
break
63+
fi
64+
done
65+
echo "exit: ${EXIT_STATUS}"
66+
67+
if (( "${EXIT_STATUS}" )); then
68+
echo "'${FILE}' hasn't been uploaded!"
69+
70+
github-release delete --owner "${REPOSITORY_OWNER}" --repo "${REPOSITORY_NAME}" --tag "${BUILD_SOURCEVERSION}" "${FILE}"
71+
72+
exit 1
73+
fi
74+
fi
75+
76+
echo "::endgroup::"
77+
fi
78+
done
79+
80+
cd ..

0 commit comments

Comments
 (0)