mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-24 12:14:05 +03:00
fix(api): add top-level main
, module
and types
fields (#8267)
This commit is contained in:
parent
b8756bc34e
commit
5046270273
5
.changes/api-top-level-main-module.md
Normal file
5
.changes/api-top-level-main-module.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'@tauri-apps/api': 'patch:bug'
|
||||
---
|
||||
|
||||
Add top-level `main`, `module` and `types` fields in `package.json` to be compliant with typescripts's `"moduleResolution": "node"`
|
3
.github/workflows/lint-js.yml
vendored
3
.github/workflows/lint-js.yml
vendored
@ -49,6 +49,9 @@ jobs:
|
||||
- name: install deps via yarn
|
||||
working-directory: ./tooling/api/
|
||||
run: yarn
|
||||
- name: run ts:check
|
||||
working-directory: ./tooling/api/
|
||||
run: yarn ts:check
|
||||
- name: run lint
|
||||
working-directory: ./tooling/api/
|
||||
run: yarn lint
|
||||
|
@ -11,7 +11,7 @@ if [ -z "$(git diff --name-only tooling/api)" ]; then
|
||||
else
|
||||
cd tooling/api
|
||||
yarn format
|
||||
yarn lint-fix
|
||||
yarn lint:fix
|
||||
cd ../..
|
||||
fi
|
||||
|
||||
|
5
.prettierrc
Normal file
5
.prettierrc
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
module.exports = {
|
||||
singleQuote: true,
|
||||
semi: false,
|
||||
trailingComma: 'none'
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -11,8 +11,9 @@
|
||||
"url": "https://github.com/tauri-apps/tauri.git"
|
||||
},
|
||||
"scripts": {
|
||||
"format": "prettier --write --end-of-line=auto \"./**/*.{cjs,js,jsx,ts,tsx,html,css,json}\" --ignore-path .prettierignore",
|
||||
"postinstall": "husky install"
|
||||
"format": "prettier --write . --config .prettierrc --ignore-path .prettierignore",
|
||||
"format:check": "prettier --check . --config .prettierrc --ignore-path .prettierignore",
|
||||
"postinstall": "husky install"
|
||||
},
|
||||
"devDependencies": {
|
||||
"covector": "^0.7.3",
|
||||
|
51
tooling/api/.eslintrc
Normal file
51
tooling/api/.eslintrc
Normal file
@ -0,0 +1,51 @@
|
||||
{
|
||||
"root": true,
|
||||
|
||||
"env": {
|
||||
"node": true,
|
||||
"jest": true
|
||||
},
|
||||
|
||||
"parser": "@typescript-eslint/parser",
|
||||
|
||||
"extends": [
|
||||
"plugin:@typescript-eslint/recommended-requiring-type-checking",
|
||||
// TODO: make this work with typescript
|
||||
// "plugin:node/recommended"
|
||||
"prettier"
|
||||
],
|
||||
|
||||
"plugins": ["@typescript-eslint", "node", "security"],
|
||||
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
|
||||
"globals": {
|
||||
"__statics": true,
|
||||
"process": true
|
||||
},
|
||||
|
||||
// add your custom rules here
|
||||
"rules": {
|
||||
"no-debugger": "error",
|
||||
"no-process-exit": "off",
|
||||
"security/detect-non-literal-fs-filename": "warn",
|
||||
"security/detect-unsafe-regex": "error",
|
||||
"security/detect-buffer-noassert": "error",
|
||||
"security/detect-child-process": "warn",
|
||||
"security/detect-disable-mustache-escape": "error",
|
||||
"security/detect-eval-with-expression": "error",
|
||||
"security/detect-no-csrf-before-method-override": "error",
|
||||
"security/detect-non-literal-regexp": "error",
|
||||
"security/detect-non-literal-require": "warn",
|
||||
"security/detect-object-injection": "warn",
|
||||
"security/detect-possible-timing-attacks": "error",
|
||||
"security/detect-pseudoRandomBytes": "error",
|
||||
"space-before-function-paren": "off",
|
||||
"@typescript-eslint/default-param-last": "off",
|
||||
"@typescript-eslint/strict-boolean-expressions": 0,
|
||||
"no-return-await": "warn",
|
||||
"@typescript-eslint/return-await": "off"
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
|
||||
env: {
|
||||
node: true,
|
||||
jest: true
|
||||
},
|
||||
|
||||
parser: '@typescript-eslint/parser',
|
||||
|
||||
extends: [
|
||||
'standard-with-typescript',
|
||||
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
||||
// TODO: make this work with typescript
|
||||
// 'plugin:node/recommended'
|
||||
'prettier'
|
||||
],
|
||||
|
||||
plugins: ['@typescript-eslint', 'node', 'security'],
|
||||
|
||||
parserOptions: {
|
||||
tsconfigRootDir: __dirname,
|
||||
project: './tsconfig.json'
|
||||
},
|
||||
|
||||
globals: {
|
||||
__statics: true,
|
||||
process: true
|
||||
},
|
||||
|
||||
// add your custom rules here
|
||||
rules: {
|
||||
// allow console.log during development only
|
||||
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
|
||||
// allow debugger during development only
|
||||
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
|
||||
'no-process-exit': 'off',
|
||||
'security/detect-non-literal-fs-filename': 'warn',
|
||||
'security/detect-unsafe-regex': 'error',
|
||||
'security/detect-buffer-noassert': 'error',
|
||||
'security/detect-child-process': 'warn',
|
||||
'security/detect-disable-mustache-escape': 'error',
|
||||
'security/detect-eval-with-expression': 'error',
|
||||
'security/detect-no-csrf-before-method-override': 'error',
|
||||
'security/detect-non-literal-regexp': 'error',
|
||||
'security/detect-non-literal-require': 'warn',
|
||||
'security/detect-object-injection': 'warn',
|
||||
'security/detect-possible-timing-attacks': 'error',
|
||||
'security/detect-pseudoRandomBytes': 'error',
|
||||
'space-before-function-paren': 'off',
|
||||
'@typescript-eslint/default-param-last': 'off',
|
||||
'@typescript-eslint/strict-boolean-expressions': 0,
|
||||
'no-return-await': 'warn',
|
||||
'@typescript-eslint/return-await': 'off'
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
module.exports = {
|
||||
singleQuote: true,
|
||||
semi: false,
|
||||
trailingComma: 'none'
|
||||
}
|
@ -31,7 +31,7 @@
|
||||
|
||||
## \[1.3.0]
|
||||
|
||||
- Return correct type for ` event.payload ` in `onResized` and `onMoved` window event handlers.
|
||||
- Return correct type for `event.payload ` in `onResized` and `onMoved` window event handlers.
|
||||
- [0b46637e](https://www.github.com/tauri-apps/tauri/commit/0b46637ebaba54403afa32a1cb466f09df2db999) fix(api): construct correct object for onResized and onMoved, closes [#6507](https://www.github.com/tauri-apps/tauri/pull/6507) ([#6509](https://www.github.com/tauri-apps/tauri/pull/6509)) on 2023-04-03
|
||||
- Added the `WindowOptions::contentProtected` option and `WebviewWindow#setContentProtected` to change it at runtime.
|
||||
- [4ab5545b](https://www.github.com/tauri-apps/tauri/commit/4ab5545b7a831c549f3c65e74de487ede3ab7ce5) feat: add content protection api, closes [#5132](https://www.github.com/tauri-apps/tauri/pull/5132) ([#5513](https://www.github.com/tauri-apps/tauri/pull/5513)) on 2022-12-13
|
||||
@ -168,65 +168,84 @@
|
||||
## \[1.0.0-rc.0]
|
||||
|
||||
- Add `fileDropEnabled` property to `WindowOptions` so you can now disable it when creating windows from js.
|
||||
|
||||
- [1bfc32a3](https://www.github.com/tauri-apps/tauri/commit/1bfc32a3b2f31b962ce8a5c611b60cb008360923) fix(api.js): add `fileDropEnabled` to `WindowOptions`, closes [#2968](https://www.github.com/tauri-apps/tauri/pull/2968) ([#2989](https://www.github.com/tauri-apps/tauri/pull/2989)) on 2021-12-09
|
||||
|
||||
- Add `logDir` function to the `path` module to access the suggested log directory.
|
||||
Add `BaseDirectory.Log` to the `fs` module.
|
||||
|
||||
- [acbb3ae7](https://www.github.com/tauri-apps/tauri/commit/acbb3ae7bb0165846b9456aea103269f027fc548) feat: add Log directory ([#2736](https://www.github.com/tauri-apps/tauri/pull/2736)) on 2021-10-16
|
||||
- [62c7a8ad](https://www.github.com/tauri-apps/tauri/commit/62c7a8ad30fd3031b8679960590e5ef3eef8e4da) chore(covector): prepare for `rc` release ([#3376](https://www.github.com/tauri-apps/tauri/pull/3376)) on 2022-02-10
|
||||
|
||||
- Expose `ask`, `message` and `confirm` APIs on the dialog module.
|
||||
|
||||
- [e98c1af4](https://www.github.com/tauri-apps/tauri/commit/e98c1af44279a5ff6c8a6f0a506ecc219c9f77af) feat(core): expose message dialog APIs, fix window.confirm, implement HasRawWindowHandle for Window, closes [#2535](https://www.github.com/tauri-apps/tauri/pull/2535) ([#2700](https://www.github.com/tauri-apps/tauri/pull/2700)) on 2021-10-02
|
||||
|
||||
- Event `emit` now automatically serialize non-string types.
|
||||
|
||||
- [06000996](https://www.github.com/tauri-apps/tauri/commit/060009969627890fa9018e2f1105bad13299394c) feat(api): support unknown types for event emit payload, closes [#2929](https://www.github.com/tauri-apps/tauri/pull/2929) ([#2964](https://www.github.com/tauri-apps/tauri/pull/2964)) on 2022-01-07
|
||||
|
||||
- Fix `http.fetch` throwing error if the response is successful but the body is empty.
|
||||
|
||||
- [50c63900](https://www.github.com/tauri-apps/tauri/commit/50c63900c7313064037e2ceb798a6432fcd1bcda) fix(api.js): fix `http.fetch` throwing error if response body is empty, closes [#2831](https://www.github.com/tauri-apps/tauri/pull/2831) ([#3008](https://www.github.com/tauri-apps/tauri/pull/3008)) on 2021-12-09
|
||||
|
||||
- Add `title` option to file open/save dialogs.
|
||||
|
||||
- [e1d6a6e6](https://www.github.com/tauri-apps/tauri/commit/e1d6a6e6445637723e2331ca799a662e720e15a8) Create api-file-dialog-title.md ([#3235](https://www.github.com/tauri-apps/tauri/pull/3235)) on 2022-01-16
|
||||
- [62c7a8ad](https://www.github.com/tauri-apps/tauri/commit/62c7a8ad30fd3031b8679960590e5ef3eef8e4da) chore(covector): prepare for `rc` release ([#3376](https://www.github.com/tauri-apps/tauri/pull/3376)) on 2022-02-10
|
||||
|
||||
- Fix `os.platform` returning `macos` and `windows` instead of `darwin` and `win32`.
|
||||
|
||||
- [3924c3d8](https://www.github.com/tauri-apps/tauri/commit/3924c3d85365df30b376a1ec6c2d933460d66af0) fix(api.js): fix `os.platform` return on macos and windows, closes [#2698](https://www.github.com/tauri-apps/tauri/pull/2698) ([#2699](https://www.github.com/tauri-apps/tauri/pull/2699)) on 2021-10-02
|
||||
|
||||
- The `formatCallback` helper function now returns a number instead of a string.
|
||||
|
||||
- [a48b8b18](https://www.github.com/tauri-apps/tauri/commit/a48b8b18d428bcc404d489daa690bbefe1f57311) feat(core): validate callbacks and event names \[TRI-038] \[TRI-020] ([#21](https://www.github.com/tauri-apps/tauri/pull/21)) on 2022-01-09
|
||||
|
||||
- Added `rawHeaders` to `http > Response`.
|
||||
|
||||
- [b7a2345b](https://www.github.com/tauri-apps/tauri/commit/b7a2345b06ca0306988b4ba3d3deadd449e65af9) feat(core): add raw headers to HTTP API, closes [#2695](https://www.github.com/tauri-apps/tauri/pull/2695) ([#3053](https://www.github.com/tauri-apps/tauri/pull/3053)) on 2022-01-07
|
||||
|
||||
- Removed the `currentDir` API from the `path` module.
|
||||
|
||||
- [a08509c6](https://www.github.com/tauri-apps/tauri/commit/a08509c641f43695e25944a2dd47697b18cd83e2) fix(api): remove `currentDir` API from the `path` module on 2022-02-04
|
||||
|
||||
- Remove `.ts` files on the published package.
|
||||
|
||||
- [0f321ac0](https://www.github.com/tauri-apps/tauri/commit/0f321ac08d56412edd5bc9d166201fbc95d887d8) fix(api): do not ship TS files, closes [#2598](https://www.github.com/tauri-apps/tauri/pull/2598) ([#2645](https://www.github.com/tauri-apps/tauri/pull/2645)) on 2021-09-23
|
||||
|
||||
- **Breaking change:** Replaces all usages of `number[]` with `Uint8Array` to be closer aligned with the wider JS ecosystem.
|
||||
|
||||
- [9b19a805](https://www.github.com/tauri-apps/tauri/commit/9b19a805aa8efa64b22f2dfef193a144b8e0cee3) fix(api.js) Replace `number[]`with `Uint8Array`. fixes [#3306](https://www.github.com/tauri-apps/tauri/pull/3306) ([#3305](https://www.github.com/tauri-apps/tauri/pull/3305)) on 2022-02-05
|
||||
|
||||
- `WindowManager` methods `innerPosition` `outerPosition` now correctly return instance of `PhysicalPosition`.
|
||||
`WindowManager` methods `innerSize` `outerSize` now correctly return instance of `PhysicalSize`.
|
||||
|
||||
- [cc8b1468](https://www.github.com/tauri-apps/tauri/commit/cc8b1468c821df53ceb771061c919409a9c80978) Fix(api): Window size and position returning wrong class (fix: [#2599](https://www.github.com/tauri-apps/tauri/pull/2599)) ([#2621](https://www.github.com/tauri-apps/tauri/pull/2621)) on 2021-09-22
|
||||
|
||||
- Change the `event` field of the `Event` interface to type `EventName` instead of `string`.
|
||||
|
||||
- [b5d9bcb4](https://www.github.com/tauri-apps/tauri/commit/b5d9bcb402380abc86ae1fa1a77c629af2275f9d) Consistent event name usage ([#3228](https://www.github.com/tauri-apps/tauri/pull/3228)) on 2022-01-15
|
||||
- [62c7a8ad](https://www.github.com/tauri-apps/tauri/commit/62c7a8ad30fd3031b8679960590e5ef3eef8e4da) chore(covector): prepare for `rc` release ([#3376](https://www.github.com/tauri-apps/tauri/pull/3376)) on 2022-02-10
|
||||
|
||||
- Now `resolve()`, `join()` and `normalize()` from the `path` module, won't throw errors if the path doesn't exist, which matches NodeJS behavior.
|
||||
|
||||
- [fe381a0b](https://www.github.com/tauri-apps/tauri/commit/fe381a0bde86ebf4014007f6e21af4c1a9e58cef) fix: `join` no longer cares if path doesn't exist, closes [#2499](https://www.github.com/tauri-apps/tauri/pull/2499) ([#2548](https://www.github.com/tauri-apps/tauri/pull/2548)) on 2021-09-21
|
||||
|
||||
- Fixes the dialog `defaultPath` usage on Linux.
|
||||
|
||||
- [2212bd5d](https://www.github.com/tauri-apps/tauri/commit/2212bd5d75146f5a2df27cc2157a057642f626da) fix: dialog default path on Linux, closes [#3091](https://www.github.com/tauri-apps/tauri/pull/3091) ([#3123](https://www.github.com/tauri-apps/tauri/pull/3123)) on 2021-12-27
|
||||
|
||||
- Fixes `window.label` property returning null instead of the actual label.
|
||||
|
||||
- [f5109e0c](https://www.github.com/tauri-apps/tauri/commit/f5109e0c962e3d25404995194968bade1be33b16) fix(api): window label null instead of actual value, closes [#3295](https://www.github.com/tauri-apps/tauri/pull/3295) ([#3332](https://www.github.com/tauri-apps/tauri/pull/3332)) on 2022-02-04
|
||||
|
||||
- Remove the `BaseDirectory::Current` enum variant for security reasons.
|
||||
|
||||
- [696dca58](https://www.github.com/tauri-apps/tauri/commit/696dca58a9f8ee127a1cf857eb848e09f5845d18) refactor(core): remove `BaseDirectory::Current` variant on 2022-01-26
|
||||
|
||||
- Change `WindowLabel` type to `string`.
|
||||
|
||||
- [f68603ae](https://www.github.com/tauri-apps/tauri/commit/f68603aee4e16500dff9e385b217f5dd8b1b39e8) chore(docs): simplify event system documentation on 2021-09-27
|
||||
|
||||
- When building Universal macOS Binaries through the virtual target `universal-apple-darwin`:
|
||||
@ -295,7 +314,7 @@
|
||||
## \[1.0.0-beta.3]
|
||||
|
||||
- Export `Response` and `ResponseType` as value instead of type.
|
||||
- [394b6e05](https://www.github.com/tauri-apps/tauri/commit/394b6e0572e7a0a92e103e462a7f603f7d569319) fix(api): http `ResponseType` export type error ([#2065](https://www.github.com/tauri-apps/tauri/pull/2065)) on 2021-06-24
|
||||
- [394b6e05](https://www.github.com/tauri-apps/tauri/commit/394b6e0572e7a0a92e103e462a7f603f7d569319) fix(api): http `ResponseType` export type error ([#2065](https://www.github.com/tauri-apps/tauri/pull/2065)) on 2021-06-24
|
||||
|
||||
## \[1.0.0-beta.2]
|
||||
|
||||
|
@ -2,23 +2,10 @@
|
||||
"name": "@tauri-apps/api",
|
||||
"version": "1.5.1",
|
||||
"description": "Tauri API definitions",
|
||||
"type": "module",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
},
|
||||
"exports": {
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"scripts": {
|
||||
"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\"",
|
||||
"lint-fix": "eslint --fix --ext ts \"./src/**/*.ts\"",
|
||||
"format": "prettier --write --end-of-line=auto \"./**/*.{cjs,js,jsx,ts,tsx,html,css,json}\" --ignore-path ../../.prettierignore",
|
||||
"format:check": "prettier --check --end-of-line=auto \"./**/*.{cjs,js,jsx,ts,tsx,html,css,json}\" --ignore-path ../../.prettierignore"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/tauri-apps/tauri.git"
|
||||
@ -31,31 +18,45 @@
|
||||
"url": "https://github.com/tauri-apps/tauri/issues"
|
||||
},
|
||||
"homepage": "https://github.com/tauri-apps/tauri#readme",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
"type": "module",
|
||||
"types": "./types/index.d.ts",
|
||||
"main": "./index.cjs",
|
||||
"module": "./index.js",
|
||||
"exports": {
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14.6.0",
|
||||
"npm": ">= 6.6.0",
|
||||
"yarn": ">= 1.19.1"
|
||||
"scripts": {
|
||||
"build": "rollup -c --configPlugin typescript",
|
||||
"npm-pack": "yarn build && cd ./dist && npm pack",
|
||||
"npm-publish": "yarn build && cd ./dist && yarn publish --access public --loglevel silly --tag next",
|
||||
"ts:check": "tsc -noEmit",
|
||||
"lint": "eslint --ext ts \"./src/**/*.ts\"",
|
||||
"lint:fix": "eslint --fix --ext ts \"./src/**/*.ts\"",
|
||||
"format": "prettier --write . --config ../../.prettierrc --ignore-path .gitignore --ignore-path ../../.prettierignore",
|
||||
"format:check": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore --ignore-path ../../.prettierignore"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-terser": "0.4.4",
|
||||
"@rollup/plugin-typescript": "11.1.5",
|
||||
"@types/node": "20.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "5.62.0",
|
||||
"eslint-config-standard-with-typescript": "34.0.1",
|
||||
"@typescript-eslint/parser": "5.62.0",
|
||||
"eslint": "8.53.0",
|
||||
"eslint-config-prettier": "8.10.0",
|
||||
"eslint-config-standard-with-typescript": "34.0.1",
|
||||
"eslint-plugin-import": "2.29.0",
|
||||
"eslint-plugin-n": "15.7.0",
|
||||
"eslint-plugin-node": "11.1.0",
|
||||
"eslint-plugin-promise": "6.1.1",
|
||||
"eslint-plugin-security": "1.7.1",
|
||||
"prettier": "2.8.8",
|
||||
"tsup": "6.7.0",
|
||||
"fast-glob": "3.3.2",
|
||||
"prettier": "3.0.3",
|
||||
"rollup": "3.29.4",
|
||||
"typescript": "5.2.2"
|
||||
},
|
||||
"resolutions": {
|
||||
"semver": ">=7.5.2",
|
||||
"optionator": ">=0.9.3"
|
||||
"engines": {
|
||||
"node": ">= 14.6.0",
|
||||
"npm": ">= 6.6.0",
|
||||
"yarn": ">= 1.19.1"
|
||||
}
|
||||
}
|
||||
|
138
tooling/api/rollup.config.ts
Normal file
138
tooling/api/rollup.config.ts
Normal file
@ -0,0 +1,138 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { defineConfig, Plugin, RollupLog } from 'rollup'
|
||||
import typescript from '@rollup/plugin-typescript'
|
||||
import terser from '@rollup/plugin-terser'
|
||||
import fg from 'fast-glob'
|
||||
import { basename, join } from 'path'
|
||||
import {
|
||||
writeFileSync,
|
||||
copyFileSync,
|
||||
opendirSync,
|
||||
rmSync,
|
||||
Dir,
|
||||
readFileSync
|
||||
} from 'fs'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
// cleanup dist dir
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
||||
cleanDir(join(__dirname, './dist'))
|
||||
|
||||
const modules = fg.sync(['./src/*.ts'])
|
||||
|
||||
export default defineConfig([
|
||||
{
|
||||
input: Object.fromEntries(modules.map((p) => [basename(p, '.ts'), p])),
|
||||
output: [
|
||||
{
|
||||
format: 'esm',
|
||||
dir: './dist',
|
||||
preserveModules: true,
|
||||
preserveModulesRoot: 'src',
|
||||
entryFileNames: '[name].js'
|
||||
},
|
||||
{
|
||||
format: 'cjs',
|
||||
dir: './dist',
|
||||
preserveModules: true,
|
||||
preserveModulesRoot: 'src',
|
||||
entryFileNames: '[name].cjs'
|
||||
}
|
||||
],
|
||||
plugins: [
|
||||
typescript({
|
||||
declaration: true,
|
||||
declarationDir: './dist/types',
|
||||
rootDir: 'src'
|
||||
}),
|
||||
makeFlatPackageInDist()
|
||||
],
|
||||
onwarn
|
||||
},
|
||||
|
||||
{
|
||||
input: 'src/index.ts',
|
||||
output: {
|
||||
format: 'iife',
|
||||
name: '__TAURI_IIFE__',
|
||||
footer: 'window.__TAURI__ = __TAURI_IIFE__',
|
||||
file: '../../core/tauri/scripts/bundle.global.js'
|
||||
},
|
||||
plugins: [typescript(), terser()],
|
||||
onwarn
|
||||
}
|
||||
])
|
||||
|
||||
function onwarn(warning: RollupLog) {
|
||||
// deny warnings by default
|
||||
throw Object.assign(new Error(), warning)
|
||||
}
|
||||
|
||||
function makeFlatPackageInDist(): Plugin {
|
||||
return {
|
||||
name: 'makeFlatPackageInDist',
|
||||
writeBundle() {
|
||||
// append our api modules to `exports` in `package.json` then write it to `./dist`
|
||||
const pkg = JSON.parse(readFileSync('package.json', 'utf8'))
|
||||
const mods = modules.map((p) => basename(p).split('.')[0])
|
||||
|
||||
const outputPkg = {
|
||||
...pkg,
|
||||
devDependencies: {},
|
||||
exports: Object.assign(
|
||||
{},
|
||||
...mods.map((mod) => {
|
||||
const exports: Record<
|
||||
string,
|
||||
{ types: string; import: string; require: string }
|
||||
> = {}
|
||||
const key = mod === 'index' ? '.' : `./${mod}`
|
||||
exports[key] = {
|
||||
types: `./types/${mod}.d.ts`,
|
||||
import: `./${mod}.js`,
|
||||
require: `./${mod}.cjs`
|
||||
}
|
||||
return exports
|
||||
}),
|
||||
// if for some reason in the future we manually add something in the `exports` field
|
||||
// this will ensure it doesn't get overwritten by the logic above
|
||||
{ ...(pkg.exports || {}) }
|
||||
)
|
||||
}
|
||||
writeFileSync(
|
||||
'dist/package.json',
|
||||
JSON.stringify(outputPkg, undefined, 2)
|
||||
)
|
||||
|
||||
// copy necessary files like `CHANGELOG.md` , `README.md` and Licenses to `./dist`
|
||||
fg.sync('(LICENSE*|*.md)').forEach((f) => copyFileSync(f, `dist/${f}`))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function cleanDir(path: string) {
|
||||
let dir: Dir
|
||||
try {
|
||||
dir = opendirSync(path)
|
||||
} catch (err: any) {
|
||||
switch (err.code) {
|
||||
case 'ENOENT':
|
||||
return // Noop when directory don't exists.
|
||||
case 'ENOTDIR':
|
||||
throw new Error(`'${path}' is not a directory.`)
|
||||
default:
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
let file = dir.readSync()
|
||||
while (file) {
|
||||
const filePath = join(path, file.name)
|
||||
rmSync(filePath, { recursive: true })
|
||||
file = dir.readSync()
|
||||
}
|
||||
dir.closeSync()
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
const { readFileSync, readdirSync, writeFileSync, copyFileSync } = require('fs')
|
||||
|
||||
// append our api modules to `exports` in `package.json` then write it to `./dist`
|
||||
const pkg = JSON.parse(readFileSync('package.json', 'utf8'))
|
||||
const modules = readdirSync('src')
|
||||
.filter((e) => e !== 'helpers')
|
||||
.map((mod) => mod.replace('.ts', ''))
|
||||
|
||||
const outputPkg = {
|
||||
...pkg,
|
||||
devDependencies: {},
|
||||
exports: Object.assign(
|
||||
{},
|
||||
...modules.map((mod) => {
|
||||
let temp = {}
|
||||
let key = `./${mod}`
|
||||
if (mod === 'index') {
|
||||
key = '.'
|
||||
}
|
||||
|
||||
temp[key] = {
|
||||
import: `./${mod}.js`,
|
||||
require: `./${mod}.cjs`
|
||||
}
|
||||
return temp
|
||||
}),
|
||||
// if for some reason in the future we manually add something in the `exports` field
|
||||
// this will ensure it doesn't get overwritten by the logic above
|
||||
{ ...(pkg.exports || {}) }
|
||||
)
|
||||
}
|
||||
writeFileSync('dist/package.json', JSON.stringify(outputPkg, undefined, 2))
|
||||
|
||||
// copy necessary files like `CHANGELOG.md` , `README.md` and Licenses to `./dist`
|
||||
const dir = readdirSync('.')
|
||||
const files = [
|
||||
...dir.filter((f) => f.startsWith('LICENSE')),
|
||||
...dir.filter((f) => f.endsWith('.md'))
|
||||
]
|
||||
files.forEach((f) => copyFileSync(f, `dist/${f}`))
|
@ -1,14 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2020",
|
||||
"target": "es2021",
|
||||
"module": "esnext",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"moduleResolution": "node",
|
||||
"moduleResolution": "bundler",
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noImplicitAny": true,
|
||||
"resolveJsonModule": true,
|
||||
"noEmit": true
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
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 guaranteed to assign to the global `window` object so we make sure to assign it
|
||||
footer: {
|
||||
js: 'window.__TAURI__ = __TAURI_IIFE__'
|
||||
}
|
||||
}
|
||||
])
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user