Skip to content

Commit ab4adb0

Browse files
authored
Merge pull request #189 from appwrite/fix-web-polyfills
fix(web): implement polyfills by default and not conditional
2 parents 760752a + 786bc94 commit ab4adb0

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

src/SDK/Language/Web.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public function getFiles()
6060
'template' => '/web/tsconfig.json.twig',
6161
'minify' => false,
6262
],
63+
[
64+
'scope' => 'default',
65+
'destination' => 'rollup.config.js',
66+
'template' => '/web/rollup.config.js.twig',
67+
'minify' => false,
68+
],
6369
[
6470
'scope' => 'default',
6571
'destination' => 'dist/cjs/package.json',

templates/web/package.json.twig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
"url": "{{ sdk.gitURL }}"
2020
},
2121
"scripts": {
22-
"build": "npm run build:types && npm run build:esm && npm run build:cjs && npm run build:iife",
22+
"build": "npm run build:types && npm run build:libs",
2323
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types",
24-
"build:esm": "tsc --module es6 --outDir dist/esm",
25-
"build:cjs": "rollup dist/esm/sdk.js --format cjs --name Appwrite -e cross-fetch/polyfill --context global -m --no-esModule -o dist/cjs/sdk.js",
26-
"build:iife": "rollup dist/esm/sdk.js --format iife --name Appwrite -e cross-fetch/polyfill --context window -m --no-esModule -o dist/iife/sdk.js"
24+
"build:libs": "rollup -c"
2725
},
2826
"devDependencies": {
27+
"@rollup/plugin-typescript": "^8.2.1",
2928
"playwright": "^1.10.0",
3029
"rollup": "^2.43.0",
3130
"serve-handler": "^6.1.3",
31+
"tslib": "^2.2.0",
3232
"typescript": "^4.2.3"
3333
},
3434
"dependencies": {
3535
"cross-fetch": "^3.1.0",
36-
"form-data": "^4.0.0"
36+
"isomorphic-form-data": "^2.0.0"
3737
},
3838
"jsdelivr": "dist/iife/sdk.js",
3939
"unpkg": "dist/iife/sdk.js"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pkg from "./package.json";
2+
import typescript from "@rollup/plugin-typescript";
3+
4+
export default {
5+
external: Object.keys(pkg.dependencies),
6+
input: "src/sdk.ts",
7+
plugins: [typescript()],
8+
output: [
9+
{
10+
format: "cjs",
11+
file: pkg.main,
12+
esModule: false,
13+
sourcemap: true,
14+
},
15+
{
16+
format: "es",
17+
file: pkg.module,
18+
sourcemap: true,
19+
},
20+
{
21+
format: "iife",
22+
file: pkg.jsdelivr,
23+
name: "Appwrite",
24+
esModule: false,
25+
globals: {
26+
"cross-fetch": "window",
27+
"FormData": "FormData",
28+
},
29+
},
30+
],
31+
};

templates/web/src/sdk.ts.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import "isomorphic-form-data";
2+
import { fetch } from "cross-fetch";
3+
14
type Payload = {
25
[key: string]: any;
36
}
@@ -6,9 +9,6 @@ type Headers = {
69
[key: string]: string;
710
}
811

9-
const FormData = typeof window === 'undefined' ? require('form-data') : window.FormData;
10-
const fetch = typeof window === 'undefined' ? require('cross-fetch') : window.fetch;
11-
1212
class {{spec.title | caseUcfirst}}Exception extends Error {
1313
code: number;
1414
response: string;

templates/web/tsconfig.json.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"declaration": false,
77
"esModuleInterop": true,
88
"inlineSourceMap": false,
9-
"lib": ["ES6", "DOM"],
9+
"lib": ["ESNext", "DOM"],
1010
"listEmittedFiles": false,
1111
"listFiles": false,
1212
"moduleResolution": "node",

0 commit comments

Comments
 (0)