@reflex-stack/tsp 0.1.11 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -45
- package/package.json +5 -5
- package/src/cli.js +55 -58
- package/src/commands/init.js +65 -28
- package/src/commands/size-report.js +29 -34
- package/src/config.js +0 -2
- package/src/tests.js +1 -4
- package/src/utils.js +5 -3
- package/tests/example-package/LICENCE +0 -21
- package/tests/example-package/README.md +0 -31
- package/tests/example-package/dist/common-dep.d.ts +0 -1
- package/tests/example-package/dist/common-dep.js +0 -1
- package/tests/example-package/dist/index.d.ts +0 -2
- package/tests/example-package/dist/index.js +0 -2
- package/tests/example-package/dist/root-dep.d.ts +0 -1
- package/tests/example-package/dist/root-dep.js +0 -1
- package/tests/example-package/dist/stuff.d.ts +0 -1
- package/tests/example-package/dist/stuff.js +0 -5
- package/tests/example-package/dist/submodule/index.d.ts +0 -1
- package/tests/example-package/dist/submodule/index.js +0 -5
- package/tests/example-package/dist/submodule/submodule-dep.d.ts +0 -1
- package/tests/example-package/dist/submodule/submodule-dep.js +0 -1
- package/tests/example-package/package-lock.json +0 -1061
- package/tests/example-package/package.json +0 -47
- package/tests/example-package/reports/main-dark.svg +0 -1
- package/tests/example-package/reports/main-light.svg +0 -1
- package/tests/example-package/reports/submodule-dark.svg +0 -1
- package/tests/example-package/reports/submodule-light.svg +0 -1
- package/tests/example-package/reports/total-dark.svg +0 -1
- package/tests/example-package/reports/total-light.svg +0 -1
- package/tests/example-package/tests/test.js +0 -25
- package/tests/example-package/tests/tsconfig.json +0 -5
- package/tests/example-package/tsconfig.json +0 -36
|
@@ -98,51 +98,46 @@ export async function sizeReport ( bundles, config ) {
|
|
|
98
98
|
return allBundleSizes
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
export async function cleanSizeReports ( config ) {
|
|
102
|
-
const dir = new Directory( join(config.cwd, config.reports) )
|
|
103
|
-
await dir.ensureParents()
|
|
104
|
-
await dir.clean()
|
|
105
|
-
}
|
|
106
|
-
|
|
107
101
|
export function generateJSON ( sizeReport, config ) {
|
|
108
102
|
writeFileSync(
|
|
109
|
-
join(config.cwd,
|
|
103
|
+
join(config.cwd, 'bundle-sizes.json'),
|
|
110
104
|
JSON.stringify( sizeReport ),
|
|
111
105
|
{ encoding: 'utf-8' }
|
|
112
106
|
)
|
|
113
107
|
}
|
|
114
108
|
|
|
115
|
-
async function
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
109
|
+
async function replaceBundleSizeInFile( filePath, id, size ) {
|
|
110
|
+
// Open file and replace tags like <bundle-size id="{id}">{size}</bundle-size>
|
|
111
|
+
// If you find any tag with any size in it, with this ID, replace the size with the new from arguments
|
|
112
|
+
// For ex: ("README.md", "main", 500b)
|
|
113
|
+
// Before: <bundle-size id="main">200b</bundle-size>
|
|
114
|
+
// After: <bundle-size id="main">500b</bundle-size>
|
|
115
|
+
// Should do it for all instances in file. Can be done sync if possible.
|
|
116
|
+
const file = new File( filePath )
|
|
117
|
+
await file.load()
|
|
118
|
+
const escapedId = id.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' )
|
|
119
|
+
const regex = new RegExp( `<bundle-size id="${ escapedId }">.*?</bundle-size>`, 'g' )
|
|
120
|
+
file.content( ( content ) => {
|
|
121
|
+
return content.replaceAll( regex, `<bundle-size id="${ id }">${ size }</bundle-size>` )
|
|
122
|
+
})
|
|
123
|
+
await file.save()
|
|
128
124
|
}
|
|
129
125
|
|
|
130
|
-
export async function
|
|
126
|
+
export async function replaceBundleSizes ( sizeReport, config ) {
|
|
127
|
+
const files = ["README.md"] // fixme add config
|
|
131
128
|
let total = 0
|
|
132
|
-
for (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
await
|
|
129
|
+
for (const file of files) {
|
|
130
|
+
// Per bundle size
|
|
131
|
+
for ( const bundle of sizeReport ) {
|
|
132
|
+
const size = bundle.sizes[2]
|
|
133
|
+
total += size
|
|
134
|
+
const sizeContent = naiveHumanFileSize( size )
|
|
135
|
+
await replaceBundleSizeInFile(file, bundle.name, sizeContent)
|
|
139
136
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const filePath = join( config.cwd, config.reports, `total-${scheme}.svg` )
|
|
145
|
-
await generateTextSVG( filePath, scheme, sizeContent )
|
|
137
|
+
// Total size
|
|
138
|
+
if ( sizeReport.length > 1 ) {
|
|
139
|
+
const sizeContent = naiveHumanFileSize( total )
|
|
140
|
+
await replaceBundleSizeInFile(file, "total", sizeContent)
|
|
146
141
|
}
|
|
147
142
|
}
|
|
148
143
|
}
|
package/src/config.js
CHANGED
|
@@ -9,9 +9,7 @@ export let getConfig = (userPackage) => {
|
|
|
9
9
|
tests: './tests',
|
|
10
10
|
"test-files": ['test.js'],
|
|
11
11
|
tmp: './tmp',
|
|
12
|
-
reports: './reports',
|
|
13
12
|
'generate-json-report': true,
|
|
14
|
-
'generate-svg-report': true,
|
|
15
13
|
// Override with package config
|
|
16
14
|
...((userPackage ?? {})['tsp'] ?? {})
|
|
17
15
|
}
|
package/src/tests.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
2
|
let total = 0
|
|
4
3
|
let success = 0
|
|
5
4
|
let failed = 0
|
|
@@ -14,14 +13,12 @@ export function startTest () {
|
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
16
|
export const describe = ( name, fn ) => {
|
|
20
17
|
console.log(`${ name }`)
|
|
21
18
|
fn()
|
|
22
19
|
}
|
|
23
20
|
|
|
24
|
-
export const
|
|
21
|
+
export const test = ( name, fn ) => {
|
|
25
22
|
++total
|
|
26
23
|
try {
|
|
27
24
|
fn()
|
package/src/utils.js
CHANGED
|
@@ -45,9 +45,11 @@ export function showIntroMessage ( noThrow = false ) {
|
|
|
45
45
|
* Very naive implementation.
|
|
46
46
|
*/
|
|
47
47
|
export function naiveHumanFileSize ( size ) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
if ( size >= 1000000 )
|
|
49
|
+
size = ~~( size / 10000 ) / 100 + 'mb'
|
|
50
|
+
else if ( size >= 1000 )
|
|
51
|
+
size = ~~( size / 10 ) / 100 + 'kb'
|
|
52
|
+
return size + 'b'
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
// Get git remote repo URL if in a git repo
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Alexis Bouhet
|
|
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,31 +0,0 @@
|
|
|
1
|
-
# TSP Example
|
|
2
|
-
|
|
3
|
-
## This is a test package for @reflex-stack/tsp, do not use it
|
|
4
|
-
|
|
5
|
-
Main bundle is <picture style="display: inline-block"><source media="(prefers-color-scheme: dark)" srcset="./reports/main-dark.svg"><img src="./reports/main-light.svg"></picture>
|
|
6
|
-
and optional submodule is only <picture style="display: inline-block"><source media="(prefers-color-scheme: dark)" srcset="./reports/submodule-dark.svg"><img src="./reports/submodule-light.svg"></picture>
|
|
7
|
-
|
|
8
|
-
## Install
|
|
9
|
-
|
|
10
|
-
`npm i @reflex-stack/tsp-example`
|
|
11
|
-
|
|
12
|
-
## Usage
|
|
13
|
-
|
|
14
|
-
##### Main module
|
|
15
|
-
- `import { ... } from "{{ packageNPMName }}"`
|
|
16
|
-
|
|
17
|
-
##### Sub module
|
|
18
|
-
- `import { ... } from "{{ packageNPMName }}/submodule"`
|
|
19
|
-
|
|
20
|
-
## Build commands
|
|
21
|
-
|
|
22
|
-
##### Build
|
|
23
|
-
- `npm run build`
|
|
24
|
-
##### Test
|
|
25
|
-
- `npm run test`
|
|
26
|
-
##### Publish
|
|
27
|
-
- `npm run publish`
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
## TSP
|
|
31
|
-
This package has been created with [tsp](https://github.com/reflex-stack/tsp)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const commonDep = "common dependency";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const commonDep = "common dependency";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const rootDep = "root dependency";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const rootDep = "root dependency";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function doStuff(): string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function doSubmoduleStuff(): string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const submoduleDep = "submodule dependency";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const submoduleDep = "submodule dependency";
|