Skip to content

Commit 9cbf7f0

Browse files
authored
Revert "[PM-14485] Remove manifest and index.html logic from gulp (#11861)"
This reverts commit c388697.
1 parent c388697 commit 9cbf7f0

File tree

13 files changed

+5362
-351
lines changed

13 files changed

+5362
-351
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ storybook-static
1212

1313
apps/browser/config/config.js
1414
apps/browser/src/auth/scripts/duo.js
15-
apps/browser/webpack/manifest.js
1615

1716
apps/desktop/desktop_native
1817
apps/desktop/src/auth/scripts/duo.js

.github/workflows/build-browser.yml

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -164,92 +164,72 @@ jobs:
164164
165165
zip -r browser-source.zip browser-source
166166
167-
- name: Upload browser source
168-
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
169-
with:
170-
name: browser-source-${{ env._BUILD_NUMBER }}.zip
171-
path: browser-source.zip
172-
if-no-files-found: error
173-
174167
- name: NPM setup
175168
run: npm ci
176169
working-directory: browser-source/
177170

178-
- name: Build Chrome
179-
run: npm run dist:chrome
171+
- name: Build
172+
run: npm run dist
180173
working-directory: browser-source/apps/browser
181174

182-
- name: Upload Chrome MV3 artifact
175+
- name: Build Manifest v3
176+
run: npm run dist:mv3
177+
working-directory: browser-source/apps/browser
178+
179+
- name: Upload Opera artifact
183180
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
184181
with:
185-
name: dist-chrome-MV3-${{ env._BUILD_NUMBER }}.zip
186-
path: browser-source/apps/browser/dist/dist-chrome.zip
182+
name: dist-opera-${{ env._BUILD_NUMBER }}.zip
183+
path: browser-source/apps/browser/dist/dist-opera.zip
187184
if-no-files-found: error
188185

189-
- name: Build Edge
190-
run: npm run dist:edge
191-
working-directory: browser-source/apps/browser
192-
193-
- name: Upload Edge artifact
186+
- name: Upload Opera MV3 artifact (DO NOT USE FOR PROD)
194187
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
195188
with:
196-
name: dist-edge-${{ env._BUILD_NUMBER }}.zip
197-
path: browser-source/apps/browser/dist/dist-edge.zip
189+
name: DO-NOT-USE-FOR-PROD-dist-opera-MV3-${{ env._BUILD_NUMBER }}.zip
190+
path: browser-source/apps/browser/dist/dist-opera-mv3.zip
198191
if-no-files-found: error
199192

200-
- name: Build Edge (MV3)
201-
run: npm run dist:edge:mv3
202-
working-directory: browser-source/apps/browser
203-
204-
- name: Upload Edge MV3 artifact (DO NOT USE FOR PROD)
193+
- name: Upload Chrome MV3 artifact
205194
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
206195
with:
207-
name: DO-NOT-USE-FOR-PROD-dist-edge-MV3-${{ env._BUILD_NUMBER }}.zip
208-
path: browser-source/apps/browser/dist/dist-edge.zip
196+
name: dist-chrome-MV3-${{ env._BUILD_NUMBER }}.zip
197+
path: browser-source/apps/browser/dist/dist-chrome-mv3.zip
209198
if-no-files-found: error
210199

211-
- name: Build Firefox
212-
run: npm run dist:firefox
213-
working-directory: browser-source/apps/browser
214-
215200
- name: Upload Firefox artifact
216201
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
217202
with:
218203
name: dist-firefox-${{ env._BUILD_NUMBER }}.zip
219204
path: browser-source/apps/browser/dist/dist-firefox.zip
220205
if-no-files-found: error
221206

222-
- name: Build Firefox (MV3)
223-
run: npm run dist:firefox:mv3
224-
working-directory: browser-source/apps/browser
225-
226207
- name: Upload Firefox MV3 artifact (DO NOT USE FOR PROD)
227208
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
228209
with:
229210
name: DO-NOT-USE-FOR-PROD-dist-firefox-MV3-${{ env._BUILD_NUMBER }}.zip
230-
path: browser-source/apps/browser/dist/dist-firefox.zip
211+
path: browser-source/apps/browser/dist/dist-firefox-mv3.zip
231212
if-no-files-found: error
232213

233-
- name: Build Opera
234-
run: npm run dist:opera
235-
working-directory: browser-source/apps/browser
236-
237-
- name: Upload Opera artifact
214+
- name: Upload Edge artifact
238215
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
239216
with:
240-
name: dist-opera-${{ env._BUILD_NUMBER }}.zip
241-
path: browser-source/apps/browser/dist/dist-opera.zip
217+
name: dist-edge-${{ env._BUILD_NUMBER }}.zip
218+
path: browser-source/apps/browser/dist/dist-edge.zip
242219
if-no-files-found: error
243220

244-
- name: Build Opera (MV3)
245-
run: npm run dist:opera:mv3
246-
working-directory: browser-source/apps/browser
221+
- name: Upload Edge MV3 artifact (DO NOT USE FOR PROD)
222+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
223+
with:
224+
name: DO-NOT-USE-FOR-PROD-dist-edge-MV3-${{ env._BUILD_NUMBER }}.zip
225+
path: browser-source/apps/browser/dist/dist-edge-mv3.zip
226+
if-no-files-found: error
247227

248-
- name: Upload Opera MV3 artifact (DO NOT USE FOR PROD)
228+
- name: Upload browser source
249229
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
250230
with:
251-
name: DO-NOT-USE-FOR-PROD-dist-opera-MV3-${{ env._BUILD_NUMBER }}.zip
252-
path: browser-source/apps/browser/dist/dist-opera.zip
231+
name: browser-source-${{ env._BUILD_NUMBER }}.zip
232+
path: browser-source.zip
253233
if-no-files-found: error
254234

255235
build-safari:

.github/workflows/release-browser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
PACKAGE_VERSION: ${{ needs.setup.outputs.release-version }}
122122
run: |
123123
mv browser-source.zip browser-source-$PACKAGE_VERSION.zip
124-
mv dist-chrome.zip dist-chrome-$PACKAGE_VERSION.zip
124+
mv dist-chrome-mv3.zip dist-chrome-$PACKAGE_VERSION.zip
125125
mv dist-opera.zip dist-opera-$PACKAGE_VERSION.zip
126126
mv dist-firefox.zip dist-firefox-$PACKAGE_VERSION.zip
127127
mv dist-edge.zip dist-edge-$PACKAGE_VERSION.zip

apps/browser/gulpfile.js

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
const child = require("child_process");
2+
const fs = require("fs");
3+
4+
const { rimraf } = require("rimraf");
5+
const gulp = require("gulp");
6+
const gulpif = require("gulp-if");
7+
const jeditor = require("gulp-json-editor");
8+
const replace = require("gulp-replace");
9+
10+
const manifest = require("./src/manifest.json");
11+
const manifestVersion = parseInt(process.env.MANIFEST_VERSION || manifest.version);
12+
13+
const paths = {
14+
build: "./build/",
15+
dist: "./dist/",
16+
safari: "./src/safari/",
17+
};
18+
19+
function buildString() {
20+
var build = "";
21+
if (process.env.MANIFEST_VERSION) {
22+
build = `-mv${process.env.MANIFEST_VERSION}`;
23+
}
24+
if (process.env.BUILD_NUMBER && process.env.BUILD_NUMBER !== "") {
25+
build = `-${process.env.BUILD_NUMBER}`;
26+
}
27+
return build;
28+
}
29+
30+
function distFileName(browserName, ext) {
31+
return `dist-${browserName}${buildString()}.${ext}`;
32+
}
33+
34+
async function dist(browserName, manifest) {
35+
const { default: zip } = await import("gulp-zip");
36+
37+
return gulp
38+
.src(paths.build + "**/*")
39+
.pipe(gulpif("popup/index.html", replace("__BROWSER__", "browser_" + browserName)))
40+
.pipe(gulpif("manifest.json", jeditor(manifest)))
41+
.pipe(zip(distFileName(browserName, "zip")))
42+
.pipe(gulp.dest(paths.dist));
43+
}
44+
45+
function distFirefox() {
46+
return dist("firefox", (manifest) => {
47+
if (manifestVersion === 3) {
48+
const backgroundScript = manifest.background.service_worker;
49+
delete manifest.background.service_worker;
50+
manifest.background.scripts = [backgroundScript];
51+
}
52+
delete manifest.storage;
53+
delete manifest.sandbox;
54+
manifest.optional_permissions = manifest.optional_permissions.filter(
55+
(permission) => permission !== "privacy",
56+
);
57+
return manifest;
58+
});
59+
}
60+
61+
function distOpera() {
62+
return dist("opera", (manifest) => {
63+
delete manifest.applications;
64+
65+
// Mv3 on Opera does seem to have sidebar support, however it is not working as expected.
66+
// On install, the extension will crash the browser entirely if the sidebar_action key is set.
67+
// We will remove the sidebar_action key for now until opera implements a fix.
68+
if (manifestVersion === 3) {
69+
delete manifest.sidebar_action;
70+
delete manifest.commands._execute_sidebar_action;
71+
}
72+
73+
return manifest;
74+
});
75+
}
76+
77+
function distChrome() {
78+
return dist("chrome", (manifest) => {
79+
delete manifest.applications;
80+
delete manifest.sidebar_action;
81+
delete manifest.commands._execute_sidebar_action;
82+
return manifest;
83+
});
84+
}
85+
86+
function distEdge() {
87+
return dist("edge", (manifest) => {
88+
delete manifest.applications;
89+
delete manifest.sidebar_action;
90+
delete manifest.commands._execute_sidebar_action;
91+
return manifest;
92+
});
93+
}
94+
95+
function distSafariMas(cb) {
96+
return distSafariApp(cb, "mas");
97+
}
98+
99+
function distSafariMasDev(cb) {
100+
return distSafariApp(cb, "masdev");
101+
}
102+
103+
function distSafariDmg(cb) {
104+
return distSafariApp(cb, "dmg");
105+
}
106+
107+
function distSafariApp(cb, subBuildPath) {
108+
const buildPath = paths.dist + "Safari/" + subBuildPath + "/";
109+
const builtAppexPath = buildPath + "build/Release/safari.appex";
110+
const builtAppexFrameworkPath = buildPath + "build/Release/safari.appex/Contents/Frameworks/";
111+
const entitlementsPath = paths.safari + "safari/safari.entitlements";
112+
var args = [
113+
"--verbose",
114+
"--force",
115+
"-o",
116+
"runtime",
117+
"--sign",
118+
"Developer ID Application: 8bit Solutions LLC",
119+
"--entitlements",
120+
entitlementsPath,
121+
];
122+
if (subBuildPath !== "dmg") {
123+
args = [
124+
"--verbose",
125+
"--force",
126+
"--sign",
127+
subBuildPath === "mas"
128+
? "3rd Party Mac Developer Application: Bitwarden Inc"
129+
: "E7C9978F6FBCE0553429185C405E61F5380BE8EB",
130+
"--entitlements",
131+
entitlementsPath,
132+
];
133+
}
134+
135+
return rimraf([buildPath + "**/*"], { glob: true })
136+
.then(() => safariCopyAssets(paths.safari + "**/*", buildPath))
137+
.then(() => safariCopyBuild(paths.build + "**/*", buildPath + "safari/app"))
138+
.then(() => {
139+
const proc = child.spawn("xcodebuild", [
140+
"-project",
141+
buildPath + "desktop.xcodeproj",
142+
"-alltargets",
143+
"-configuration",
144+
"Release",
145+
]);
146+
stdOutProc(proc);
147+
return new Promise((resolve) => proc.on("close", resolve));
148+
})
149+
.then(async () => {
150+
const libs = fs
151+
.readdirSync(builtAppexFrameworkPath)
152+
.filter((p) => p.endsWith(".dylib"))
153+
.map((p) => builtAppexFrameworkPath + p);
154+
const libPromises = [];
155+
libs.forEach((i) => {
156+
const proc = child.spawn("codesign", args.concat([i]));
157+
stdOutProc(proc);
158+
libPromises.push(new Promise((resolve) => proc.on("close", resolve)));
159+
});
160+
return Promise.all(libPromises);
161+
})
162+
.then(() => {
163+
const proc = child.spawn("codesign", args.concat([builtAppexPath]));
164+
stdOutProc(proc);
165+
return new Promise((resolve) => proc.on("close", resolve));
166+
})
167+
.then(
168+
() => {
169+
return cb;
170+
},
171+
() => {
172+
return cb;
173+
},
174+
);
175+
}
176+
177+
function safariCopyAssets(source, dest) {
178+
return new Promise((resolve, reject) => {
179+
gulp
180+
.src(source)
181+
.on("error", reject)
182+
.pipe(gulpif("safari/Info.plist", replace("0.0.1", manifest.version)))
183+
.pipe(
184+
gulpif("safari/Info.plist", replace("0.0.2", process.env.BUILD_NUMBER || manifest.version)),
185+
)
186+
.pipe(gulpif("desktop.xcodeproj/project.pbxproj", replace("../../../build", "../safari/app")))
187+
.pipe(gulp.dest(dest))
188+
.on("end", resolve);
189+
});
190+
}
191+
192+
async function safariCopyBuild(source, dest) {
193+
return new Promise((resolve, reject) => {
194+
gulp
195+
.src(source)
196+
.on("error", reject)
197+
.pipe(gulpif("popup/index.html", replace("__BROWSER__", "browser_safari")))
198+
.pipe(
199+
gulpif(
200+
"manifest.json",
201+
jeditor((manifest) => {
202+
if (manifestVersion === 3) {
203+
const backgroundScript = manifest.background.service_worker;
204+
delete manifest.background.service_worker;
205+
manifest.background.scripts = [backgroundScript];
206+
}
207+
delete manifest.sidebar_action;
208+
delete manifest.commands._execute_sidebar_action;
209+
delete manifest.optional_permissions;
210+
manifest.permissions.push("nativeMessaging");
211+
return manifest;
212+
}),
213+
),
214+
)
215+
.pipe(gulp.dest(dest))
216+
.on("end", resolve);
217+
});
218+
}
219+
220+
function stdOutProc(proc) {
221+
proc.stdout.on("data", (data) => console.log(data.toString()));
222+
proc.stderr.on("data", (data) => console.error(data.toString()));
223+
}
224+
225+
exports["dist:firefox"] = distFirefox;
226+
exports["dist:chrome"] = distChrome;
227+
exports["dist:opera"] = distOpera;
228+
exports["dist:edge"] = distEdge;
229+
exports["dist:safari"] = gulp.parallel(distSafariMas, distSafariMasDev, distSafariDmg);
230+
exports["dist:safari:mas"] = distSafariMas;
231+
exports["dist:safari:masdev"] = distSafariMasDev;
232+
exports["dist:safari:dmg"] = distSafariDmg;
233+
exports.dist = gulp.parallel(distFirefox, distChrome, distOpera, distEdge);

0 commit comments

Comments
 (0)