Skip to content

Commit

Permalink
refactor: simplify api.js bundling (#4277)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonas Kruckenberg <iterpre@protonmail.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
3 people authored Oct 4, 2022
1 parent d4cac20 commit 1129f4f
Show file tree
Hide file tree
Showing 15 changed files with 669 additions and 2,322 deletions.
5 changes: 5 additions & 0 deletions .changes/api-node14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"api": minor
---

**Breaking change:** Node.js v12 is no longer supported.
8 changes: 8 additions & 0 deletions core/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion core/tauri/scripts/bundle.js

This file was deleted.

2 changes: 1 addition & 1 deletion core/tauri/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ impl<R: Runtime> WindowManager<R> {
}

let bundle_script = if with_global_tauri {
include_str!("../scripts/bundle.js")
include_str!("../scripts/bundle.global.js")
} else {
""
};
Expand Down
14 changes: 0 additions & 14 deletions tooling/api/babel.config.js

This file was deleted.

18 changes: 3 additions & 15 deletions tooling/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"./package.json": "./package.json"
},
"scripts": {
"build": "rimraf ./dist && rollup -c --silent && node ./scripts/after-build.cjs",
"build": "yarn tsup && node ./scripts/after-build.cjs",
"npm-pack": "yarn build && cd ./dist && npm pack",
"npm-publish": "yarn build && cd ./dist && yarn publish --access public --loglevel silly",
"lint": "eslint --ext ts \"./src/**/*.ts\"",
Expand All @@ -36,19 +36,11 @@
"access": "public"
},
"engines": {
"node": ">= 12.22.0",
"node": ">= 14.6.0",
"npm": ">= 6.6.0",
"yarn": ">= 1.19.1"
},
"devDependencies": {
"@babel/core": "7.19.3",
"@babel/preset-env": "7.19.3",
"@babel/preset-typescript": "7.18.6",
"@rollup/plugin-babel": "5.3.1",
"@rollup/plugin-commonjs": "22.0.2",
"@rollup/plugin-node-resolve": "13.3.0",
"@rollup/plugin-sucrase": "4.0.4",
"@rollup/plugin-typescript": "8.5.0",
"@typescript-eslint/eslint-plugin": "5.38.1",
"@typescript-eslint/parser": "5.38.1",
"eslint": "8.24.0",
Expand All @@ -60,11 +52,7 @@
"eslint-plugin-promise": "6.0.1",
"eslint-plugin-security": "1.5.0",
"prettier": "2.7.1",
"regenerator-runtime": "0.13.9",
"rimraf": "3.0.2",
"rollup": "2.79.1",
"rollup-plugin-terser": "7.0.2",
"tslib": "2.4.0",
"tsup": "6.0.1",
"typedoc": "0.23.15",
"typedoc-plugin-markdown": "3.13.6",
"typedoc-plugin-mdn-links": "2.0.0",
Expand Down
103 changes: 0 additions & 103 deletions tooling/api/rollup.config.js

This file was deleted.

1 change: 1 addition & 0 deletions tooling/api/scripts/after-build.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const modules = readdirSync('src')

const outputPkg = {
...pkg,
devDependencies: {},
exports: Object.assign(
{},
...modules.map((mod) => {
Expand Down
44 changes: 0 additions & 44 deletions tooling/api/src/bundle.ts

This file was deleted.

40 changes: 39 additions & 1 deletion tooling/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,42 @@
* @module
*/

export * from './bundle'
import * as app from './app'
import * as cli from './cli'
import * as clipboard from './clipboard'
import * as dialog from './dialog'
import * as event from './event'
import * as fs from './fs'
import * as globalShortcut from './globalShortcut'
import * as http from './http'
import * as notification from './notification'
import * as path from './path'
import * as process from './process'
import * as shell from './shell'
import * as tauri from './tauri'
import * as updater from './updater'
import * as window from './window'
import * as os from './os'

/** @ignore */
const invoke = tauri.invoke

export {
invoke,
app,
cli,
clipboard,
dialog,
event,
fs,
globalShortcut,
http,
notification,
path,
process,
shell,
tauri,
updater,
window,
os
}
3 changes: 2 additions & 1 deletion tooling/api/src/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* @module
*/

import { once, listen, emit, UnlistenFn, TauriEvent } from './event'
import { once, listen, emit, TauriEvent } from './event'
import { UnlistenFn } from './helpers/event'

/**
* @since 1.0.0
Expand Down
9 changes: 8 additions & 1 deletion tooling/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2151,4 +2151,11 @@ export {
availableMonitors
}

export type { Theme, Monitor, ScaleFactorChanged, FileDropEvent, WindowOptions }
export type {
Theme,
TitleBarStyle,
Monitor,
ScaleFactorChanged,
FileDropEvent,
WindowOptions
}
20 changes: 9 additions & 11 deletions tooling/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"compilerOptions": {
"target": "es2020",
"module": "esnext",
"strict": true,
"allowJs": true,
"esModuleInterop": true,
"baseUrl": ".",
"paths": {
"types": ["@types"]
},
"declaration": true,
"declarationDir": "dist",
"rootDir": "src",
"moduleResolution": "node"
},
"include": ["./src"]
"moduleResolution": "node",
"skipLibCheck": true,
"noUnusedLocals": true,
"noImplicitAny": true,
"resolveJsonModule": true,
"noEmit": true
}
}
30 changes: 30 additions & 0 deletions tooling/api/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { defineConfig } from 'tsup'

export default defineConfig(() => [
{
entry: ['src/*.ts'],
outDir: 'dist',
format: ['esm', 'cjs'],
clean: true,
minify: true,
platform: 'browser',
dts: {
resolve: true
}
},
{
entry: { bundle: 'src/index.ts' },
outDir: '../../core/tauri/scripts',
format: ['iife'],
globalName: '__TAURI_IIFE__',
clean: false,
minify: true,
platform: 'browser',
dts: false,
// esbuild `globalName` option generates `var __TAURI_IIFE__ = (() => {})()`
// and var is not guaranted to assign to the global `window` object so we make sure to assign it
footer: {
js: 'window.__TAURI__ = __TAURI_IIFE__'
}
}
])
Loading

0 comments on commit 1129f4f

Please sign in to comment.