Skip to content

Commit eb849a7

Browse files
committed
Switch to "type": "module".
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent ab3698f commit eb849a7

File tree

11 files changed

+65
-61
lines changed

11 files changed

+65
-61
lines changed

app/main/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {sentryInit} from "./sentry.ts";
3232
import {setAutoLaunch} from "./startup.ts";
3333
import {ipcMain, send} from "./typed-ipc-main.ts";
3434

35-
import "gatemaker/electron-setup"; // eslint-disable-line import/no-unassigned-import
35+
import "gatemaker/electron-setup.js"; // eslint-disable-line import/no-unassigned-import
3636

3737
// eslint-disable-next-line @typescript-eslint/naming-convention
3838
const {GDK_BACKEND} = process.env;
@@ -87,7 +87,7 @@ function createMainWindow(): BrowserWindow {
8787
minWidth: 500,
8888
minHeight: 400,
8989
webPreferences: {
90-
preload: path.join(bundlePath, "renderer.js"),
90+
preload: path.join(bundlePath, "renderer.cjs"),
9191
sandbox: false,
9292
webviewTag: true,
9393
},

app/renderer/js/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ export class ServerManagerView {
412412
await this.openNetworkTroubleshooting(index);
413413
},
414414
onTitleChange: this.updateBadge.bind(this),
415-
preload: url.pathToFileURL(path.join(bundlePath, "preload.js")).href,
415+
preload: url.pathToFileURL(path.join(bundlePath, "preload.cjs")).href,
416416
unsupportedMessage: DomainUtil.getUnsupportedMessage(server),
417417
}),
418418
});

i18next-parser.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"use strict";
2-
3-
module.exports = {
1+
const config = {
42
createOldCatalogs: false,
53
defaultValue: (locale, namespace, key, value) =>
64
locale === "en" ? key : value,
@@ -15,3 +13,4 @@ module.exports = {
1513
output: "public/translations/$LOCALE.json",
1614
sort: (a, b) => (a < b ? -1 : a > b ? 1 : 0),
1715
};
16+
export default config;

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "zulip",
33
"productName": "Zulip",
44
"version": "5.12.0",
5-
"main": "./dist-electron",
5+
"main": "./dist-electron/index.cjs",
66
"description": "Zulip Desktop App",
77
"license": "Apache-2.0",
88
"copyright": "Kandra Labs, Inc.",
@@ -17,6 +17,7 @@
1717
"bugs": {
1818
"url": "https://github.com/zulip/zulip-desktop/issues"
1919
},
20+
"type": "module",
2021
"engines": {
2122
"node": ">=18"
2223
},

tests/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
"use strict";
2-
const {chan, put, take} = require("medium");
3-
const test = require("tape");
1+
import {chan, put, take} from "medium";
2+
import test from "tape";
43

5-
const setup = require("./setup.js");
4+
import * as setup from "./setup.js";
65

76
test("app runs", async (t) => {
87
t.timeoutAfter(10e3);
9-
setup.resetTestDataDir();
8+
setup.resetTestDataDirectory();
109
const app = await setup.createApp();
1110
try {
1211
const windows = chan();

tests/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"version": "5.9.3",
33
"productName": "ZulipTest",
4-
"main": "../dist-electron"
4+
"type": "module",
5+
"main": "../dist-electron/index.cjs"
56
}

tests/setup.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
"use strict";
2-
const fs = require("node:fs");
3-
const path = require("node:path");
4-
const process = require("node:process");
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
import process from "node:process";
54

6-
const {_electron} = require("playwright-core");
5+
import {_electron} from "playwright-core";
76

8-
const testsPkg = require("./package.json");
9-
10-
module.exports = {
11-
createApp,
12-
endTest,
13-
resetTestDataDir: resetTestDataDirectory,
14-
};
7+
const testsPackage = JSON.parse(
8+
fs.readFileSync(new URL("package.json", import.meta.url), "utf8"),
9+
);
1510

1611
// Runs Zulip Desktop.
1712
// Returns a promise that resolves to an Electron Application once the app has loaded.
18-
function createApp() {
13+
export function createApp() {
1914
return _electron.launch({
20-
args: [path.join(__dirname)], // Ensure this dir has a package.json file with a 'main' entry point
15+
args: [import.meta.dirname], // Ensure this dir has a package.json file with a 'main' entry point
2116
});
2217
}
2318

2419
// Quit the app, end the test
25-
async function endTest(app) {
20+
export async function endTest(app) {
2621
await app.close();
2722
}
2823

@@ -52,11 +47,11 @@ function getAppDataDirectory() {
5247
}
5348

5449
console.log("Detected App Data Dir base:", base);
55-
return path.join(base, testsPkg.productName);
50+
return path.join(base, testsPackage.productName);
5651
}
5752

5853
// Resets the test directory, containing domain.json, window-state.json, etc
59-
function resetTestDataDirectory() {
54+
export function resetTestDataDirectory() {
6055
const appDataDirectory = getAppDataDirectory();
6156
fs.rmSync(appDataDirectory, {force: true, recursive: true});
6257
}

tests/test-add-organization.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
"use strict";
2-
const {chan, put, take} = require("medium");
3-
const test = require("tape");
1+
import {chan, put, take} from "medium";
2+
import test from "tape";
43

5-
const setup = require("./setup.js");
4+
import * as setup from "./setup.js";
65

76
test("add-organization", async (t) => {
87
t.timeoutAfter(50e3);
9-
setup.resetTestDataDir();
8+
setup.resetTestDataDirectory();
109
const app = await setup.createApp();
1110
try {
1211
const windows = chan();

tests/test-new-organization.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
"use strict";
2-
const {chan, put, take} = require("medium");
3-
const test = require("tape");
1+
import {chan, put, take} from "medium";
2+
import test from "tape";
43

5-
const setup = require("./setup.js");
4+
import * as setup from "./setup.js";
65

76
// Create new org link should open in the default browser [WIP]
87

98
test("new-org-link", async (t) => {
109
t.timeoutAfter(50e3);
11-
setup.resetTestDataDir();
10+
setup.resetTestDataDirectory();
1211
const app = await setup.createApp();
1312
try {
1413
const windows = chan();

vite.config.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
/* eslint-disable @typescript-eslint/naming-convention */
22

3-
import * as path from "node:path";
4-
53
import {defineConfig} from "vite";
64
import electron from "vite-plugin-electron";
75

86
export default defineConfig({
97
plugins: [
108
electron([
119
{
12-
entry: {
13-
index: "app/main",
14-
},
1510
vite: {
1611
build: {
12+
lib: {
13+
entry: {
14+
index: "app/main",
15+
},
16+
formats: ["cjs"],
17+
},
1718
sourcemap: true,
1819
rollupOptions: {
1920
external: ["electron", /^electron\//, /^gatemaker\//],
21+
output: {
22+
entryFileNames: "[name].cjs",
23+
},
2024
},
2125
ssr: true,
2226
},
@@ -31,27 +35,39 @@ export default defineConfig({
3135
},
3236
},
3337
{
34-
entry: {
35-
preload: "app/renderer/js/preload.ts",
36-
},
3738
vite: {
3839
build: {
40+
lib: {
41+
entry: {
42+
preload: "app/renderer/js/preload.ts",
43+
},
44+
formats: ["cjs"],
45+
},
3946
sourcemap: "inline",
4047
rollupOptions: {
4148
external: ["electron", /^electron\//],
49+
output: {
50+
entryFileNames: "[name].cjs",
51+
},
4252
},
4353
},
4454
},
4555
},
4656
{
47-
entry: {
48-
renderer: "app/renderer/js/main.ts",
49-
},
5057
vite: {
5158
build: {
59+
lib: {
60+
entry: {
61+
renderer: "app/renderer/js/main.ts",
62+
},
63+
formats: ["cjs"],
64+
},
5265
sourcemap: true,
5366
rollupOptions: {
5467
external: ["electron", /^electron\//],
68+
output: {
69+
entryFileNames: "[name].cjs",
70+
},
5571
},
5672
},
5773
resolve: {
@@ -68,10 +84,10 @@ export default defineConfig({
6884
sourcemap: true,
6985
rollupOptions: {
7086
input: {
71-
renderer: path.join(__dirname, "app/renderer/main.html"),
72-
network: path.join(__dirname, "app/renderer/network.html"),
73-
about: path.join(__dirname, "app/renderer/about.html"),
74-
preference: path.join(__dirname, "app/renderer/preference.html"),
87+
renderer: "app/renderer/main.html",
88+
network: "app/renderer/network.html",
89+
about: "app/renderer/about.html",
90+
preference: "app/renderer/preference.html",
7591
},
7692
},
7793
},

0 commit comments

Comments
 (0)