Skip to content

Commit 134f327

Browse files
committedApr 3, 2023
build: Typescript update
1 parent 7dec25f commit 134f327

9 files changed

+1291
-566
lines changed
 

‎.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"rules": {
1111
"no-console": "off",
1212
"new-cap": "off",
13+
"no-throw-literal": "off",
1314
"@typescript-eslint/no-this-alias": "off"
1415
}
1516
}

‎LICENSE

+166-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,166 @@
1-
MIT License
2-
3-
Copyright (c) 2023 Jonson B. <https://github.com/who-jonson>
4-
5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
11-
12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
14-
15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
1+
Apache License
2+
Version 2.0, January 2004
3+
http://www.apache.org/licenses/
4+
5+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6+
7+
1. Definitions.
8+
"License" shall mean the terms and conditions for use, reproduction,
9+
and distribution as defined by Sections 1 through 9 of this document.
10+
"Licensor" shall mean the copyright owner or entity authorized by
11+
the copyright owner that is granting the License.
12+
"Legal Entity" shall mean the union of the acting entity and all
13+
other entities that control, are controlled by, or are under common
14+
control with that entity. For the purposes of this definition,
15+
"control" means (i) the power, direct or indirect, to cause the
16+
direction or management of such entity, whether by contract or
17+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
18+
outstanding shares, or (iii) beneficial ownership of such entity.
19+
"You" (or "Your") shall mean an individual or Legal Entity
20+
exercising permissions granted by this License.
21+
"Source" form shall mean the preferred form for making modifications,
22+
including but not limited to software source code, documentation
23+
source, and configuration files.
24+
"Object" form shall mean any form resulting from mechanical
25+
transformation or translation of a Source form, including but
26+
not limited to compiled object code, generated documentation,
27+
and conversions to other media types.
28+
"Work" shall mean the work of authorship, whether in Source or
29+
Object form, made available under the License, as indicated by a
30+
copyright notice that is included in or attached to the work
31+
(an example is provided in the Appendix below).
32+
"Derivative Works" shall mean any work, whether in Source or Object
33+
form, that is based on (or derived from) the Work and for which the
34+
editorial revisions, annotations, elaborations, or other modifications
35+
represent, as a whole, an original work of authorship. For the purposes
36+
of this License, Derivative Works shall not include works that remain
37+
separable from, or merely link (or bind by name) to the interfaces of,
38+
the Work and Derivative Works thereof.
39+
"Contribution" shall mean any work of authorship, including
40+
the original version of the Work and any modifications or additions
41+
to that Work or Derivative Works thereof, that is intentionally
42+
submitted to Licensor for inclusion in the Work by the copyright owner
43+
or by an individual or Legal Entity authorized to submit on behalf of
44+
the copyright owner. For the purposes of this definition, "submitted"
45+
means any form of electronic, verbal, or written communication sent
46+
to the Licensor or its representatives, including but not limited to
47+
communication on electronic mailing lists, source code control systems,
48+
and issue tracking systems that are managed by, or on behalf of, the
49+
Licensor for the purpose of discussing and improving the Work, but
50+
excluding communication that is conspicuously marked or otherwise
51+
designated in writing by the copyright owner as "Not a Contribution."
52+
"Contributor" shall mean Licensor and any individual or Legal Entity
53+
on behalf of whom a Contribution has been received by Licensor and
54+
subsequently incorporated within the Work.
55+
56+
2. Grant of Copyright License. Subject to the terms and conditions of
57+
this License, each Contributor hereby grants to You a perpetual,
58+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
59+
copyright license to reproduce, prepare Derivative Works of,
60+
publicly display, publicly perform, sublicense, and distribute the
61+
Work and such Derivative Works in Source or Object form.
62+
63+
3. Grant of Patent License. Subject to the terms and conditions of
64+
this License, each Contributor hereby grants to You a perpetual,
65+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66+
(except as stated in this section) patent license to make, have made,
67+
use, offer to sell, sell, import, and otherwise transfer the Work,
68+
where such license applies only to those patent claims licensable
69+
by such Contributor that are necessarily infringed by their
70+
Contribution(s) alone or by combination of their Contribution(s)
71+
with the Work to which such Contribution(s) was submitted. If You
72+
institute patent litigation against any entity (including a
73+
cross-claim or counterclaim in a lawsuit) alleging that the Work
74+
or a Contribution incorporated within the Work constitutes direct
75+
or contributory patent infringement, then any patent licenses
76+
granted to You under this License for that Work shall terminate
77+
as of the date such litigation is filed.
78+
79+
4. Redistribution. You may reproduce and distribute copies of the
80+
Work or Derivative Works thereof in any medium, with or without
81+
modifications, and in Source or Object form, provided that You
82+
meet the following conditions:
83+
84+
(a) You must give any other recipients of the Work or
85+
Derivative Works a copy of this License; and
86+
87+
(b) You must cause any modified files to carry prominent notices
88+
stating that You changed the files; and
89+
90+
(c) You must retain, in the Source form of any Derivative Works
91+
that You distribute, all copyright, patent, trademark, and
92+
attribution notices from the Source form of the Work,
93+
excluding those notices that do not pertain to any part of
94+
the Derivative Works; and
95+
96+
(d) If the Work includes a "NOTICE" text file as part of its
97+
distribution, then any Derivative Works that You distribute must
98+
include a readable copy of the attribution notices contained
99+
within such NOTICE file, excluding those notices that do not
100+
pertain to any part of the Derivative Works, in at least one
101+
of the following places: within a NOTICE text file distributed
102+
as part of the Derivative Works; within the Source form or
103+
documentation, if provided along with the Derivative Works; or,
104+
within a display generated by the Derivative Works, if and
105+
wherever such third-party notices normally appear. The contents
106+
of the NOTICE file are for informational purposes only and
107+
do not modify the License. You may add Your own attribution
108+
notices within Derivative Works that You distribute, alongside
109+
or as an addendum to the NOTICE text from the Work, provided
110+
that such additional attribution notices cannot be construed
111+
as modifying the License.
112+
113+
You may add Your own copyright statement to Your modifications and
114+
may provide additional or different license terms and conditions
115+
for use, reproduction, or distribution of Your modifications, or
116+
for any such Derivative Works as a whole, provided Your use,
117+
reproduction, and distribution of the Work otherwise complies with
118+
the conditions stated in this License.
119+
120+
5. Submission of Contributions. Unless You explicitly state otherwise,
121+
any Contribution intentionally submitted for inclusion in the Work
122+
by You to the Licensor shall be under the terms and conditions of
123+
this License, without any additional terms or conditions.
124+
Notwithstanding the above, nothing herein shall supersede or modify
125+
the terms of any separate license agreement you may have executed
126+
with Licensor regarding such Contributions.
127+
128+
6. Trademarks. This License does not grant permission to use the trade
129+
names, trademarks, service marks, or product names of the Licensor,
130+
except as required for reasonable and customary use in describing the
131+
origin of the Work and reproducing the content of the NOTICE file.
132+
133+
7. Disclaimer of Warranty. Unless required by applicable law or
134+
agreed to in writing, Licensor provides the Work (and each
135+
Contributor provides its Contributions) on an "AS IS" BASIS,
136+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
137+
implied, including, without limitation, any warranties or conditions
138+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
139+
PARTICULAR PURPOSE. You are solely responsible for determining the
140+
appropriateness of using or redistributing the Work and assume any
141+
risks associated with Your exercise of permissions under this License.
142+
143+
8. Limitation of Liability. In no event and under no legal theory,
144+
whether in tort (including negligence), contract, or otherwise,
145+
unless required by applicable law (such as deliberate and grossly
146+
negligent acts) or agreed to in writing, shall any Contributor be
147+
liable to You for damages, including any direct, indirect, special,
148+
incidental, or consequential damages of any character arising as a
149+
result of this License or out of the use or inability to use the
150+
Work (including but not limited to damages for loss of goodwill,
151+
work stoppage, computer failure or malfunction, or any and all
152+
other commercial damages or losses), even if such Contributor
153+
has been advised of the possibility of such damages.
154+
155+
9. Accepting Warranty or Additional Liability. While redistributing
156+
the Work or Derivative Works thereof, You may choose to offer,
157+
and charge a fee for, acceptance of support, warranty, indemnity,
158+
or other liability obligations and/or rights consistent with this
159+
License. However, in accepting such obligations, You may act only
160+
on Your own behalf and on Your sole responsibility, not on behalf
161+
of any other Contributor, and only if You agree to indemnify,
162+
defend, and hold each Contributor harmless for any liability
163+
incurred by, or claims asserted against, such Contributor by reason
164+
of your accepting any such warranty or additional liability.
165+
166+
END OF TERMS AND CONDITIONS

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# @whoj/boxdk
44

5+
[![NPM version](https://img.shields.io/npm/v/@whoj/boxdk?color=a1b858&label=)](https://www.npmjs.com/package/@whoj/boxdk)
6+
57
Typed version of [Box Clientside SDK](https://github.com/allenmichael/box-javascript-sdk)
68

79
## Installation

‎package.json

+42-26
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "@whoj/boxdk",
33
"description": "Typed version of [Box Clientside SDK]",
44
"version": "1.0.0-beta.6",
5-
"license": "MIT",
6-
"packageManager": "pnpm@7.27.1",
5+
"license": "Apache-2.0",
6+
"packageManager": "pnpm@7.29.3",
77
"author": {
88
"name": "Jonson B.",
99
"email": "www.jbc.bd@gmail.com",
@@ -23,22 +23,29 @@
2323
},
2424
"exports": {
2525
".": {
26-
"browser": "./dist/boxdk.esm-browser.js",
27-
"import": "./boxdk.esm-bundler.js",
28-
"module": "./boxdk.esm-bundler.js",
29-
"require": "./dist/boxdk.cjs"
30-
}
26+
"types": "./dist/boxdk.d.ts",
27+
"node": {
28+
"import": "./dist/boxdk.mjs",
29+
"require": "./dist/boxdk.cjs"
30+
},
31+
"browser": "./dist/boxdk.esm-browser.js"
32+
},
33+
"./*": [
34+
"./dist/*",
35+
"./dist/*.d.ts"
36+
]
3137
},
3238
"main": "./dist/boxdk.cjs",
33-
"module": "./boxdk.esm-bundler.js",
39+
"module": "./dist/boxdk.mjs",
3440
"types": "./dist/boxdk.d.ts",
3541
"iife": "./dist/boxdk.iife.js",
3642
"unpkg": "./dist/boxdk.iife.js",
3743
"jsdelivr": "./dist/boxdk.iife.js",
3844
"typesVersions": {
39-
"*": {
45+
"<=4.9": {
4046
"*": [
41-
"./dist/boxdk.d.ts"
47+
"./dist/*",
48+
"./*"
4249
]
4350
}
4451
},
@@ -47,8 +54,10 @@
4754
],
4855
"scripts": {
4956
"dev": "vite --host",
50-
"prepublishOnly": "rm -rf dist && tsc --noEmit && rollup -c rollup.config.mjs && npm run build:dts",
51-
"build:dts": "dts-bundle-generator --config ./dts-bundle-generator.config.ts",
57+
"build": "rm -rf dist && run-p build:types build:lib",
58+
"build:lib": "rollup --config rollup.config.mjs",
59+
"build:types": "tsc --declaration --emitDeclarationOnly --outDir ./dist",
60+
"prepublishOnly": "pnpm run build && rm dist/index.d.ts",
5261
"lint": "eslint .",
5362
"lint:fix": "eslint . --fix",
5463
"test": "vitest",
@@ -58,26 +67,33 @@
5867
"uninstall-husky": "npm uninstall husky --no-save && git config --unset core.hooksPath && npx rimraf .husky"
5968
},
6069
"dependencies": {
70+
"@whoj/utils-core": "^1.7.0",
6171
"rusha": "^0.8.14",
62-
"whatwg-fetch": "^3.6.2",
63-
"@whoj/utils-core": "^1.5.0"
72+
"whatwg-fetch": "^3.6.2"
6473
},
6574
"devDependencies": {
75+
"@rollup/plugin-commonjs": "^24.0.1",
76+
"@rollup/plugin-node-resolve": "^15.0.1",
6677
"@rollup/plugin-replace": "^5.0.2",
67-
"@rollup/plugin-typescript": "^11.0.0",
68-
"@types/node": "^18.11.18",
78+
"@rollup/plugin-terser": "^0.4.0",
79+
"@types/node": "^18.15.11",
6980
"@types/rusha": "^0.8.0",
70-
"@whoj/eslint-config": "^1.2.0",
71-
"bumpp": "^8.2.1",
72-
"dts-bundle-generator": "^7.1.0",
73-
"eslint": "^8.33.0",
81+
"@whoj/eslint-config": "^1.3.0",
82+
"bumpp": "^9.1.0",
83+
"esbuild": "^0.17.15",
84+
"eslint": "^8.37.0",
7485
"husky": "^8.0.3",
75-
"lint-staged": "^13.1.0",
86+
"lint-staged": "^13.2.0",
87+
"npm-run-all": "^4.1.5",
88+
"rollup": "^3.20.2",
89+
"rollup-plugin-analyzer": "^4.0.0",
90+
"rollup-plugin-dts": "^5.3.0",
91+
"rollup-plugin-esbuild": "^5.0.0",
92+
"rollup-plugin-progress": "^1.1.2",
7693
"ts-node": "^10.9.1",
77-
"rollup-plugin-import-map": "^3.0.0",
78-
"typescript": "^4.9.5",
79-
"vite": "^4.1.1",
80-
"vite-plugin-externals-extension": "^0.0.7",
81-
"vitest": "^0.28.4"
94+
"tsc-prog": "^2.2.1",
95+
"typescript": "^5.0.3",
96+
"vite": "^4.2.1",
97+
"vitest": "^0.29.8"
8298
}
8399
}

‎pnpm-lock.yaml

+957-457
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rollup.config.mjs

+118-56
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,127 @@
1+
import { resolve } from 'path';
2+
import { readFileSync } from 'fs';
13
import { defineConfig } from 'rollup';
2-
import replace from '@rollup/plugin-replace';
3-
import typescript from '@rollup/plugin-typescript';
4-
import { rollupImportMapPlugin } from 'rollup-plugin-import-map';
4+
import analyze from 'rollup-plugin-analyzer';
5+
import esbuild from 'rollup-plugin-esbuild';
6+
import terser from '@rollup/plugin-terser';
7+
import progress from 'rollup-plugin-progress';
8+
9+
const { name, version } = JSON.parse(readFileSync(resolve('./package.json'), 'utf8'));
510

611
const input = './src/boxdk.ts';
712

8-
// const _external = ['@whoj/utils', 'rusha', 'whatwg-fetch'];
13+
const external = [
14+
'@whoj/utils-core',
15+
'whatwg-fetch',
16+
'rusha'
17+
];
918

10-
const plugins = [
11-
typescript(),
12-
replace({
13-
preventAssignment: true,
14-
'import.meta.env.VITE_BOX_APP_TOKEN': 'undefined'
15-
})
16-
]
19+
const banner = `/**
20+
* @module ${name}
21+
* @version ${version}
22+
* @copyright ${new Date().getFullYear()} Jonson B.. All rights reserved.
23+
*/
24+
`;
1725

18-
export default defineConfig([
19-
{
20-
input,
21-
output: [
22-
{
23-
file: './dist/boxdk.esm-browser.js',
24-
format: 'esm',
25-
sourcemap: true
26-
}
27-
],
28-
plugins: [
29-
...plugins,
30-
rollupImportMapPlugin([
31-
{
32-
imports: {
33-
'@whoj/utils-core': 'https://cdn.jsdelivr.net/npm/@whoj/utils-core/+esm',
34-
'whatwg-fetch': 'https://cdn.jsdelivr.net/npm/whatwg-fetch/+esm',
35-
'rusha': 'https://cdn.jsdelivr.net/npm/rusha/+esm',
36-
}
37-
}
38-
])
39-
]
40-
},
41-
{
42-
input,
43-
output: {
44-
file: './dist/boxdk.iife.js',
45-
format: 'iife',
46-
name: 'BoxSdk',
47-
sourcemap: true
48-
},
49-
plugins
26+
let analyzePluginIterations = 0;
27+
28+
const plugins = (minify = false, isBrowser = false) => [
29+
progress(),
30+
esbuild({
31+
platform: isBrowser ? 'browser' : 'node',
32+
legalComments: 'eof',
33+
tsconfig: './tsconfig.json',
34+
optimizeDeps: {
35+
include: external,
36+
exclude: ['vue-demi']
5037
},
51-
{
52-
input,
53-
output: [
54-
{
55-
file: './dist/boxdk.esm-bundler.js',
56-
format: 'es'
57-
},
58-
{
59-
file: './dist/boxdk.cjs',
60-
format: 'cjs'
61-
}
62-
],
63-
plugins
38+
define: {
39+
'import.meta.env.VITE_BOX_APP_TOKEN': 'undefined'
6440
}
41+
}),
42+
minify && terser(),
43+
analyze({
44+
hideDeps: true,
45+
onAnalysis: () => {
46+
if (analyzePluginIterations > 0) {
47+
throw '';
48+
}
49+
analyzePluginIterations++;
50+
}
51+
})
52+
];
53+
54+
const commonOutputOptions = {
55+
banner,
56+
name: 'BoxSdk',
57+
exports: 'auto',
58+
freeze: false,
59+
sourcemap: true,
60+
minifyInternalExports: false,
61+
generatedCode: {
62+
constBindings: true
63+
}
64+
};
65+
66+
function esmBrowserConfig(input, file, minify = false) {
67+
return {
68+
input,
69+
plugins: plugins(minify, true),
70+
external,
71+
treeshake: true,
72+
shimMissingExports: true,
73+
output: [
74+
{
75+
file,
76+
format: 'esm',
77+
...commonOutputOptions
78+
}
79+
]
80+
};
81+
}
82+
83+
function iifeConfig(input, file, minify = false) {
84+
return {
85+
input,
86+
plugins: plugins(minify, true),
87+
output: {
88+
file,
89+
format: 'iife',
90+
...commonOutputOptions
91+
}
92+
};
93+
}
94+
95+
export default defineConfig([
96+
esmBrowserConfig(input, './dist/boxdk.esm-browser.js'),
97+
esmBrowserConfig(input, './dist/boxdk.esm-browser.min.js', true),
98+
99+
iifeConfig(input, './dist/boxdk.iife.js'),
100+
iifeConfig(input, './dist/boxdk.iife.min.js', true),
101+
102+
{
103+
input,
104+
external,
105+
plugins: plugins(),
106+
output: [
107+
{
108+
// file: './dist/boxdk.mjs',
109+
dir: './dist',
110+
format: 'esm',
111+
...commonOutputOptions,
112+
preserveModules: true,
113+
preserveModulesRoot: 'src',
114+
entryFileNames: '[name].mjs'
115+
},
116+
{
117+
file: './dist/boxdk.cjs',
118+
format: 'cjs',
119+
interop: 'compat',
120+
...commonOutputOptions
121+
}
122+
],
123+
treeshake: true,
124+
shimMissingExports: true,
125+
makeAbsoluteExternalsRelative: 'ifRelativeSource'
126+
}
65127
]);

‎src/boxdk.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import BasicBoxClient from './box-client';
22
import PersistentBoxClient from './persistent-box-client';
33

4-
export default class Boxdk {
4+
export default class BoxSdk {
55
private readonly _BasicBoxClient;
66

77
private readonly _PersistentBoxClient;

‎src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import Boxdk from './boxdk';
1+
import BoxSdk from './boxdk';
22

3-
const box = new Boxdk();
3+
const box = new BoxSdk();
44

55
const accessToken = import.meta.env.VITE_BOX_APP_TOKEN;
66

‎tsconfig.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
22
"compilerOptions": {
3-
"rootDir": "./src",
43
"target": "ESNext",
54
"module": "ESNext",
65
"lib": ["ESNext", "DOM"],
7-
"moduleResolution": "Node",
6+
"moduleResolution": "Bundler",
87
"strict": true,
98
"allowJs": true,
109
"sourceMap": true,
11-
"resolveJsonModule": true,
10+
"declarationMap": true,
1211
"esModuleInterop": true,
1312
"noUnusedLocals": true,
1413
"skipLibCheck": true,

0 commit comments

Comments
 (0)
Please sign in to comment.