Switch to "type": "module".

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2025-07-31 18:41:04 -07:00
parent ab3698f56c
commit eb849a7b3d
11 changed files with 65 additions and 61 deletions

View File

@@ -32,7 +32,7 @@ import {sentryInit} from "./sentry.ts";
import {setAutoLaunch} from "./startup.ts"; import {setAutoLaunch} from "./startup.ts";
import {ipcMain, send} from "./typed-ipc-main.ts"; import {ipcMain, send} from "./typed-ipc-main.ts";
import "gatemaker/electron-setup"; // eslint-disable-line import/no-unassigned-import import "gatemaker/electron-setup.js"; // eslint-disable-line import/no-unassigned-import
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention
const {GDK_BACKEND} = process.env; const {GDK_BACKEND} = process.env;
@@ -87,7 +87,7 @@ function createMainWindow(): BrowserWindow {
minWidth: 500, minWidth: 500,
minHeight: 400, minHeight: 400,
webPreferences: { webPreferences: {
preload: path.join(bundlePath, "renderer.js"), preload: path.join(bundlePath, "renderer.cjs"),
sandbox: false, sandbox: false,
webviewTag: true, webviewTag: true,
}, },

View File

@@ -412,7 +412,7 @@ export class ServerManagerView {
await this.openNetworkTroubleshooting(index); await this.openNetworkTroubleshooting(index);
}, },
onTitleChange: this.updateBadge.bind(this), onTitleChange: this.updateBadge.bind(this),
preload: url.pathToFileURL(path.join(bundlePath, "preload.js")).href, preload: url.pathToFileURL(path.join(bundlePath, "preload.cjs")).href,
unsupportedMessage: DomainUtil.getUnsupportedMessage(server), unsupportedMessage: DomainUtil.getUnsupportedMessage(server),
}), }),
}); });

View File

@@ -1,6 +1,4 @@
"use strict"; const config = {
module.exports = {
createOldCatalogs: false, createOldCatalogs: false,
defaultValue: (locale, namespace, key, value) => defaultValue: (locale, namespace, key, value) =>
locale === "en" ? key : value, locale === "en" ? key : value,
@@ -15,3 +13,4 @@ module.exports = {
output: "public/translations/$LOCALE.json", output: "public/translations/$LOCALE.json",
sort: (a, b) => (a < b ? -1 : a > b ? 1 : 0), sort: (a, b) => (a < b ? -1 : a > b ? 1 : 0),
}; };
export default config;

View File

@@ -2,7 +2,7 @@
"name": "zulip", "name": "zulip",
"productName": "Zulip", "productName": "Zulip",
"version": "5.12.0", "version": "5.12.0",
"main": "./dist-electron", "main": "./dist-electron/index.cjs",
"description": "Zulip Desktop App", "description": "Zulip Desktop App",
"license": "Apache-2.0", "license": "Apache-2.0",
"copyright": "Kandra Labs, Inc.", "copyright": "Kandra Labs, Inc.",
@@ -17,6 +17,7 @@
"bugs": { "bugs": {
"url": "https://github.com/zulip/zulip-desktop/issues" "url": "https://github.com/zulip/zulip-desktop/issues"
}, },
"type": "module",
"engines": { "engines": {
"node": ">=18" "node": ">=18"
}, },

View File

@@ -1,12 +1,11 @@
"use strict"; import {chan, put, take} from "medium";
const {chan, put, take} = require("medium"); import test from "tape";
const test = require("tape");
const setup = require("./setup.js"); import * as setup from "./setup.js";
test("app runs", async (t) => { test("app runs", async (t) => {
t.timeoutAfter(10e3); t.timeoutAfter(10e3);
setup.resetTestDataDir(); setup.resetTestDataDirectory();
const app = await setup.createApp(); const app = await setup.createApp();
try { try {
const windows = chan(); const windows = chan();

View File

@@ -1,5 +1,6 @@
{ {
"version": "5.9.3", "version": "5.9.3",
"productName": "ZulipTest", "productName": "ZulipTest",
"main": "../dist-electron" "type": "module",
"main": "../dist-electron/index.cjs"
} }

View File

@@ -1,28 +1,23 @@
"use strict"; import fs from "node:fs";
const fs = require("node:fs"); import path from "node:path";
const path = require("node:path"); import process from "node:process";
const process = require("node:process");
const {_electron} = require("playwright-core"); import {_electron} from "playwright-core";
const testsPkg = require("./package.json"); const testsPackage = JSON.parse(
fs.readFileSync(new URL("package.json", import.meta.url), "utf8"),
module.exports = { );
createApp,
endTest,
resetTestDataDir: resetTestDataDirectory,
};
// Runs Zulip Desktop. // Runs Zulip Desktop.
// Returns a promise that resolves to an Electron Application once the app has loaded. // Returns a promise that resolves to an Electron Application once the app has loaded.
function createApp() { export function createApp() {
return _electron.launch({ return _electron.launch({
args: [path.join(__dirname)], // Ensure this dir has a package.json file with a 'main' entry point args: [import.meta.dirname], // Ensure this dir has a package.json file with a 'main' entry point
}); });
} }
// Quit the app, end the test // Quit the app, end the test
async function endTest(app) { export async function endTest(app) {
await app.close(); await app.close();
} }
@@ -52,11 +47,11 @@ function getAppDataDirectory() {
} }
console.log("Detected App Data Dir base:", base); console.log("Detected App Data Dir base:", base);
return path.join(base, testsPkg.productName); return path.join(base, testsPackage.productName);
} }
// Resets the test directory, containing domain.json, window-state.json, etc // Resets the test directory, containing domain.json, window-state.json, etc
function resetTestDataDirectory() { export function resetTestDataDirectory() {
const appDataDirectory = getAppDataDirectory(); const appDataDirectory = getAppDataDirectory();
fs.rmSync(appDataDirectory, {force: true, recursive: true}); fs.rmSync(appDataDirectory, {force: true, recursive: true});
} }

View File

@@ -1,12 +1,11 @@
"use strict"; import {chan, put, take} from "medium";
const {chan, put, take} = require("medium"); import test from "tape";
const test = require("tape");
const setup = require("./setup.js"); import * as setup from "./setup.js";
test("add-organization", async (t) => { test("add-organization", async (t) => {
t.timeoutAfter(50e3); t.timeoutAfter(50e3);
setup.resetTestDataDir(); setup.resetTestDataDirectory();
const app = await setup.createApp(); const app = await setup.createApp();
try { try {
const windows = chan(); const windows = chan();

View File

@@ -1,14 +1,13 @@
"use strict"; import {chan, put, take} from "medium";
const {chan, put, take} = require("medium"); import test from "tape";
const test = require("tape");
const setup = require("./setup.js"); import * as setup from "./setup.js";
// Create new org link should open in the default browser [WIP] // Create new org link should open in the default browser [WIP]
test("new-org-link", async (t) => { test("new-org-link", async (t) => {
t.timeoutAfter(50e3); t.timeoutAfter(50e3);
setup.resetTestDataDir(); setup.resetTestDataDirectory();
const app = await setup.createApp(); const app = await setup.createApp();
try { try {
const windows = chan(); const windows = chan();

View File

@@ -1,7 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable @typescript-eslint/naming-convention */
import * as path from "node:path";
import {defineConfig} from "vite"; import {defineConfig} from "vite";
import electron from "vite-plugin-electron"; import electron from "vite-plugin-electron";
@@ -9,14 +7,20 @@ export default defineConfig({
plugins: [ plugins: [
electron([ electron([
{ {
vite: {
build: {
lib: {
entry: { entry: {
index: "app/main", index: "app/main",
}, },
vite: { formats: ["cjs"],
build: { },
sourcemap: true, sourcemap: true,
rollupOptions: { rollupOptions: {
external: ["electron", /^electron\//, /^gatemaker\//], external: ["electron", /^electron\//, /^gatemaker\//],
output: {
entryFileNames: "[name].cjs",
},
}, },
ssr: true, ssr: true,
}, },
@@ -31,27 +35,39 @@ export default defineConfig({
}, },
}, },
{ {
vite: {
build: {
lib: {
entry: { entry: {
preload: "app/renderer/js/preload.ts", preload: "app/renderer/js/preload.ts",
}, },
vite: { formats: ["cjs"],
build: { },
sourcemap: "inline", sourcemap: "inline",
rollupOptions: { rollupOptions: {
external: ["electron", /^electron\//], external: ["electron", /^electron\//],
output: {
entryFileNames: "[name].cjs",
},
}, },
}, },
}, },
}, },
{ {
vite: {
build: {
lib: {
entry: { entry: {
renderer: "app/renderer/js/main.ts", renderer: "app/renderer/js/main.ts",
}, },
vite: { formats: ["cjs"],
build: { },
sourcemap: true, sourcemap: true,
rollupOptions: { rollupOptions: {
external: ["electron", /^electron\//], external: ["electron", /^electron\//],
output: {
entryFileNames: "[name].cjs",
},
}, },
}, },
resolve: { resolve: {
@@ -68,10 +84,10 @@ export default defineConfig({
sourcemap: true, sourcemap: true,
rollupOptions: { rollupOptions: {
input: { input: {
renderer: path.join(__dirname, "app/renderer/main.html"), renderer: "app/renderer/main.html",
network: path.join(__dirname, "app/renderer/network.html"), network: "app/renderer/network.html",
about: path.join(__dirname, "app/renderer/about.html"), about: "app/renderer/about.html",
preference: path.join(__dirname, "app/renderer/preference.html"), preference: "app/renderer/preference.html",
}, },
}, },
}, },

View File

@@ -128,12 +128,7 @@ module.exports = {
}, },
}, },
{ {
files: [ files: ["**.cjs"],
"**.cjs",
"i18next-parser.config.js",
"scripts/win-sign.js",
"tests/**/*.js",
],
parserOptions: { parserOptions: {
sourceType: "script", sourceType: "script",
}, },