Skip to content

Commit

Permalink
rollup build
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish committed Sep 29, 2023
1 parent f3a10cd commit afbf7e7
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 98 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
"require": "./renderer/index.js",
"import": "./esm/renderer/index.js"
},
"./preload": "./preload/index.js"
"./preload": {
"require": "./preload/index.js",
"import": "./esm/preload/index.js"
}
},
"repository": "https://github.com/getsentry/sentry-electron.git",
"author": "Sentry",
Expand All @@ -35,24 +38,18 @@
},
"scripts": {
"prebuild": "yarn clean && node scripts/update-version.js",
"build": "run-p build:es6 build:esm build:preload",
"build:es6": "tsc -p tsconfig.build.json",
"build:esm": "tsc -p tsconfig.esm.json",
"build:preload": "node scripts/build-preload.js",
"build:watch": "run-p build:watch:es6 build:watch:esm",
"build:watch:es6": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"build:watch:esm": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
"build": "rollup --config rollup.config.js",
"clean": "rimraf coverage esm main preload renderer index.* integrations.* ipc.* sentry-electron*.tgz",
"prelint": "node scripts/update-version.js",
"update-electron-versions": "electron-latest-versions --start 2 > ./test/e2e/versions.json",
"update-sdk-versions": "node ./scripts/update-sdk-versions.mjs",
"lint": "run-s lint:prettier lint:eslint",
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
"lint:eslint": "eslint . --cache --format stylish",
"fix": "run-s fix:eslint fix:prettier",
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
"fix:eslint": "eslint . --format stylish --fix",
"pretest": "yarn build",
"update-electron-versions": "electron-latest-versions --start 2 > ./test/e2e/versions.json",
"update-sdk-versions": "node ./scripts/update-sdk-versions.mjs",
"test": "cross-env TS_NODE_PROJECT=tsconfig.json xvfb-maybe electron-mocha --require ts-node/register/transpile-only --timeout 120000 ./test/unit/**/*.ts",
"pree2e": "rimraf test/e2e/dist/**/node_modules/@sentry/** test/e2e/dist/**/yarn.lock test/e2e/dist/**/package-lock.json && node scripts/clean-cache.js && yarn build && npm pack",
"e2e": "cross-env TS_NODE_PROJECT=tsconfig.json xvfb-maybe mocha --require ts-node/register/transpile-only --retries 3 ./test/e2e/*.ts"
Expand All @@ -68,6 +65,8 @@
"tslib": "^2.5.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-typescript": "^11.1.4",
"@sentry-internal/eslint-config-sdk": "7.68.0",
"@sentry-internal/typescript": "7.68.0",
"@types/busboy": "^0.2.3",
Expand Down Expand Up @@ -97,6 +96,7 @@
"npm-run-all": "^4.1.5",
"prettier": "^2.8.4",
"rimraf": "^3.0.2",
"rollup": "^3.29.4",
"tmp": "^0.2.1",
"ts-node": "^10.9.1",
"typescript": "^4.9.5",
Expand Down
63 changes: 63 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const { builtinModules } = require('module');
const { resolve } = require('path');

const typescript = require('@rollup/plugin-typescript');

const dependencies = Object.keys(require(resolve(process.cwd(), 'package.json')).dependencies || {});

const commonOutputOptions = {
sourcemap: true,
strict: false,
freeze: false,
externalLiveBindings: false,
generatedCode: {
preset: 'es2015',
symbols: false,
},
};

function transpileFiles(format, input, outDir) {
return {
input,
output: {
...commonOutputOptions,
format,
dir: outDir,
preserveModules: true,
},
treeshake: { moduleSideEffects: false },
plugins: [
typescript({
outDir,
tsconfig: './tsconfig.build.json',
}),
],
external: [...builtinModules, 'electron', ...dependencies],
};
}

function bundlePreload(format, input, output) {
return {
input,
output: {
...commonOutputOptions,
format,
file: output,
},
plugins: [
typescript({
tsconfig: './tsconfig.preload.json',
}),
],
external: [...builtinModules, 'electron', ...dependencies],
};
}

module.exports = [
transpileFiles('cjs', ['src/index.ts', 'src/main/index.ts', 'src/renderer/index.ts'], '.'),
transpileFiles('esm', ['src/index.ts', 'src/main/index.ts', 'src/renderer/index.ts'], './esm'),
bundlePreload('cjs', 'src/preload/index.ts', './preload/index.js'),
bundlePreload('cjs', 'src/preload/legacy.ts', './preload/legacy.js'),
bundlePreload('esm', 'src/preload/index.ts', './esm/preload/index.js'),
bundlePreload('esm', 'src/preload/legacy.ts', './esm/preload/legacy.js'),
];
45 changes: 0 additions & 45 deletions scripts/build-preload.js

This file was deleted.

16 changes: 10 additions & 6 deletions src/main/electron-normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ export const isPackaged = (() => {

/** A promise that is resolved when the app is ready */
export const whenAppReady: Promise<void> = (() => {
return app.isReady()
? Promise.resolve()
: new Promise<void>((resolve) => {
app.once('ready', () => {
resolve();
if (app) {
return app.isReady()
? Promise.resolve()
: new Promise<void>((resolve) => {
app.once('ready', () => {
resolve();
});
});
});
} else {
return Promise.resolve();
}
})();

/**
Expand Down
5 changes: 2 additions & 3 deletions src/main/fs.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { app } from 'electron';
import { mkdir, readdir, readFile, rename, stat, statSync, unlink, writeFile } from 'fs';
import { mkdir, readdir, readFile, stat, statSync, unlink, writeFile } from 'fs';
import { dirname, join, resolve } from 'path';
import { promisify } from 'util';

export const sentryCachePath = join(app.getPath('userData'), 'sentry');
export const sentryCachePath = join(app ? app.getPath('userData') : '', 'sentry');

export const writeFileAsync = promisify(writeFile);
export const readFileAsync = promisify(readFile);
export const mkdirAsync = promisify(mkdir);
export const statAsync = promisify(stat);
export const unlinkAsync = promisify(unlink);
export const readDirAsync = promisify(readdir);
export const renameAsync = promisify(rename);

// mkdir with recursive was only added in Node 10+

Expand Down
2 changes: 0 additions & 2 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* This preload script may be used with sandbox mode enabled which means regular require is not available.
*
* npm script `build:preload` calls `node ./scripts/build-preload.js` which inlines ipc and transpiles to JavaScript
*/

import { contextBridge, ipcRenderer } from 'electron';
Expand Down
2 changes: 0 additions & 2 deletions src/preload/legacy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* This preload script may be used with sandbox mode enabled which means regular require is not available.
*
* npm script `build:preload` calls `node ./scripts/build-preload.js` which inlines ipc and transpiles to JavaScript
*/

import { contextBridge, crashReporter, ipcRenderer } from 'electron';
Expand Down
20 changes: 6 additions & 14 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
{
"extends": "./node_modules/@sentry-internal/typescript/tsconfig.json",
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"src/preload/*.ts"
],
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "src/preload/**/*.ts"],
"compilerOptions": {
"skipLibCheck": true,
"baseUrl": ".",
"lib": [
"es7",
"dom"
],
"module": "commonjs",
"lib": ["ES7", "DOM"],
"module": "ESNext",
"outDir": ".",
"rootDir": "src",
"target": "es6",
"esModuleInterop": true,
"target": "ES6",
"esModuleInterop": true
}
}
8 changes: 0 additions & 8 deletions tsconfig.esm.json

This file was deleted.

12 changes: 4 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"extends": "./tsconfig.build.json",
"include": [
"src/**/*.ts",
"test/**/*.ts"
],
"exclude": [
"dist"
],
"include": ["src/**/*.ts", "test/**/*.ts"],
"exclude": ["node_modules"],
"compilerOptions": {
"rootDir": ".",
"module": "CommonJS",
"rootDir": "."
}
}
9 changes: 9 additions & 0 deletions tsconfig.preload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.build.json",
"include": ["src/preload/**/*.ts"],
"exclude": ["node_modules"],
"compilerOptions": {
"declaration": false,
"declarationMap": false
}
}
Loading

0 comments on commit afbf7e7

Please sign in to comment.