pure-md5 0.2.0 → 0.2.2

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.
Files changed (177) hide show
  1. package/README.md +38 -24
  2. package/dist/adapters/ie11.cjs +1 -2
  3. package/dist/adapters/ie11.js +1 -2
  4. package/dist/adapters/node.cjs +1 -2
  5. package/dist/adapters/node.js +1 -2
  6. package/dist/adapters/webcrypto.cjs +1 -2
  7. package/dist/adapters/webcrypto.js +1 -2
  8. package/dist/index.cjs +1 -2
  9. package/dist/index.d.ts +149 -5
  10. package/dist/index.js +3 -2
  11. package/dist/md5.cjs +1 -0
  12. package/dist/md5.d.ts +20 -0
  13. package/dist/md5.js +1 -0
  14. package/dist/stream/md5-stream.cjs +1 -2
  15. package/dist/stream/md5-stream.js +1 -2
  16. package/dist/stream/whatwg-stream.cjs +1 -2
  17. package/dist/stream/whatwg-stream.js +1 -2
  18. package/dist/utils/detect.cjs +1 -2
  19. package/dist/utils/detect.js +3 -2
  20. package/package.json +10 -15
  21. package/pure-md5-0.2.1.tgz +0 -0
  22. package/test-tree-shake.mjs +12 -0
  23. package/.aliases +0 -19
  24. package/.bash_profile +0 -12
  25. package/.bash_prompt +0 -56
  26. package/.changeset/README.md +0 -32
  27. package/.changeset/config.json +0 -16
  28. package/.continue/mcpServers/new-mcp-server.yaml +0 -10
  29. package/.continue/rules +0 -29
  30. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -35
  31. package/.github/ISSUE_TEMPLATE/documentation.md +0 -20
  32. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  33. package/.github/PULL_REQUEST_TEMPLATE.md +0 -35
  34. package/.github/workflows/npm-publish.yml +0 -33
  35. package/.github/workflows/release.yml +0 -42
  36. package/CHANGELOG.md +0 -9
  37. package/CONTRIBUTING.md +0 -203
  38. package/MIGRATION_GUIDE_STREAMS.md +0 -374
  39. package/STREAM_API.md +0 -582
  40. package/STREAM_BENCHMARKS.md +0 -232
  41. package/STREAM_EXAMPLES.md +0 -669
  42. package/STREAM_OPTIMIZATION_REPORT.md +0 -136
  43. package/STREAM_TROUBLESHOOTING.md +0 -537
  44. package/WEB_CRYPTO_TESTS_SUMMARY.md +0 -140
  45. package/WHATWG_STREAMS.md +0 -191
  46. package/__tests__/adapters/node-crypto.test.ts +0 -167
  47. package/__tests__/adapters/web-crypto-node.test.ts +0 -73
  48. package/__tests__/adapters/web-crypto.test.ts +0 -195
  49. package/__tests__/add32.test.ts +0 -33
  50. package/__tests__/fallback.test.ts +0 -345
  51. package/__tests__/hex.test.ts +0 -38
  52. package/__tests__/hex_chr.test.ts +0 -20
  53. package/__tests__/index.test.ts +0 -87
  54. package/__tests__/integration/fixtures/test-file.txt +0 -1
  55. package/__tests__/integration/md5-stream-file.test.ts +0 -293
  56. package/__tests__/integration/node-crypto-file.test.ts +0 -86
  57. package/__tests__/integration/web-crypto.test.ts +0 -38
  58. package/__tests__/md51.test.ts +0 -73
  59. package/__tests__/md5block.test.ts +0 -61
  60. package/__tests__/md5cycle.test.ts +0 -48
  61. package/__tests__/round-functions.test.ts +0 -87
  62. package/__tests__/stream/fs-utils.test.ts +0 -209
  63. package/__tests__/stream/md5-stream-edge-cases.test.ts +0 -461
  64. package/__tests__/stream/md5-stream.test.ts +0 -418
  65. package/__tests__/stream/whatwg-stream.test.ts +0 -355
  66. package/__tests__/stream/whatwg-stream.test.ts.bak2 +0 -335
  67. package/benchmarks/md5-stream.bench.ts +0 -212
  68. package/benchmarks/whatwg-stream.bench.ts +0 -180
  69. package/dist/adapters/ie11.cjs.map +0 -1
  70. package/dist/adapters/ie11.js.map +0 -1
  71. package/dist/adapters/node.cjs.map +0 -1
  72. package/dist/adapters/node.js.map +0 -1
  73. package/dist/adapters/webcrypto.cjs.map +0 -1
  74. package/dist/adapters/webcrypto.js.map +0 -1
  75. package/dist/chunk-2YXXFGBV.js +0 -2
  76. package/dist/chunk-2YXXFGBV.js.map +0 -1
  77. package/dist/chunk-4KSCMS4Q.js +0 -2
  78. package/dist/chunk-4KSCMS4Q.js.map +0 -1
  79. package/dist/chunk-6P2QV5SR.js +0 -4
  80. package/dist/chunk-6P2QV5SR.js.map +0 -1
  81. package/dist/chunk-G5WHEAIQ.js +0 -2
  82. package/dist/chunk-G5WHEAIQ.js.map +0 -1
  83. package/dist/chunk-H2K353LR.js +0 -2
  84. package/dist/chunk-H2K353LR.js.map +0 -1
  85. package/dist/chunk-JKVD5LHZ.js +0 -2
  86. package/dist/chunk-JKVD5LHZ.js.map +0 -1
  87. package/dist/chunk-NWQ4N5RX.js +0 -2
  88. package/dist/chunk-NWQ4N5RX.js.map +0 -1
  89. package/dist/chunk-PHZ7FTYF.js +0 -2
  90. package/dist/chunk-PHZ7FTYF.js.map +0 -1
  91. package/dist/chunk-PNZTVQA7.js +0 -2
  92. package/dist/chunk-PNZTVQA7.js.map +0 -1
  93. package/dist/chunk-R4JB5MBR.js +0 -2
  94. package/dist/chunk-R4JB5MBR.js.map +0 -1
  95. package/dist/chunk-VFOAY6XI.js +0 -2
  96. package/dist/chunk-VFOAY6XI.js.map +0 -1
  97. package/dist/chunk-XB5BQIEX.js +0 -2
  98. package/dist/chunk-XB5BQIEX.js.map +0 -1
  99. package/dist/core/index.cjs +0 -2
  100. package/dist/core/index.cjs.map +0 -1
  101. package/dist/core/index.d.cts +0 -19
  102. package/dist/core/index.d.ts +0 -19
  103. package/dist/core/index.js +0 -2
  104. package/dist/core/index.js.map +0 -1
  105. package/dist/index.cjs.map +0 -1
  106. package/dist/index.d.cts +0 -84
  107. package/dist/index.js.map +0 -1
  108. package/dist/stream/adapter.cjs +0 -2
  109. package/dist/stream/adapter.cjs.map +0 -1
  110. package/dist/stream/adapter.d.cts +0 -63
  111. package/dist/stream/adapter.d.ts +0 -63
  112. package/dist/stream/adapter.js +0 -2
  113. package/dist/stream/adapter.js.map +0 -1
  114. package/dist/stream/fs-utils.cjs +0 -2
  115. package/dist/stream/fs-utils.cjs.map +0 -1
  116. package/dist/stream/fs-utils.d.cts +0 -137
  117. package/dist/stream/fs-utils.d.ts +0 -137
  118. package/dist/stream/fs-utils.js +0 -2
  119. package/dist/stream/fs-utils.js.map +0 -1
  120. package/dist/stream/index.cjs +0 -2
  121. package/dist/stream/index.cjs.map +0 -1
  122. package/dist/stream/index.d.cts +0 -4
  123. package/dist/stream/index.d.ts +0 -4
  124. package/dist/stream/index.js +0 -2
  125. package/dist/stream/index.js.map +0 -1
  126. package/dist/stream/light/index.cjs +0 -2
  127. package/dist/stream/light/index.cjs.map +0 -1
  128. package/dist/stream/light/index.d.cts +0 -4
  129. package/dist/stream/light/index.d.ts +0 -4
  130. package/dist/stream/light/index.js +0 -2
  131. package/dist/stream/light/index.js.map +0 -1
  132. package/dist/stream/md5-stream.cjs.map +0 -1
  133. package/dist/stream/md5-stream.js.map +0 -1
  134. package/dist/stream/whatwg-stream.cjs.map +0 -1
  135. package/dist/stream/whatwg-stream.js.map +0 -1
  136. package/dist/types-edGoGJ5V.d.cts +0 -42
  137. package/dist/types-edGoGJ5V.d.ts +0 -42
  138. package/dist/utils/detect.cjs.map +0 -1
  139. package/dist/utils/detect.js.map +0 -1
  140. package/planning/03-optimization-size-tree-shaking/01-es-modules-tree-shaking.md +0 -152
  141. package/planning/03-optimization-size-tree-shaking/02-consolidate-modules.md +0 -65
  142. package/planning/03-optimization-size-tree-shaking/03-remove-duplicate-add32.md +0 -93
  143. package/planning/03-optimization-size-tree-shaking/04-remove-runtime-check.md +0 -102
  144. package/planning/03-optimization-size-tree-shaking/05-optimize-loops-performance.md +0 -107
  145. package/planning/03-optimization-size-tree-shaking/06-tsup-formats-configuration.md +0 -227
  146. package/planning/03-optimization-size-tree-shaking/07-multiple-build-formats.md +0 -228
  147. package/planning/03-optimization-size-tree-shaking/08-benchmarks-metrics.md +0 -34
  148. package/planning/03-optimization-size-tree-shaking/MIGRATION_GUIDE.md +0 -260
  149. package/planning/03-optimization-size-tree-shaking/README.md +0 -173
  150. package/planning/03-optimization-size-tree-shaking/SUMMARY.md +0 -168
  151. package/planning/04-adapter-backend/03-backend-web-crypto.md +0 -149
  152. package/planning/04-adapter-backend/04-backend-node-crypto.md +0 -181
  153. package/planning/04-adapter-backend/05-backend-pure-js.md +0 -174
  154. package/planning/04-adapter-backend/06-backend-ie11.md +0 -158
  155. package/planning/04-adapter-backend/07-detection-environment.md +0 -232
  156. package/planning/04-adapter-backend/08-detection-backend.md +0 -210
  157. package/planning/04-adapter-backend/09-adapter-unified.md +0 -255
  158. package/planning/04-adapter-backend/10-fallback-mechanism.md +0 -333
  159. package/planning/04-adapter-backend/11-tests-backend-web-crypto.md +0 -191
  160. package/planning/04-adapter-backend/12-tests-backend-node-crypto.md +0 -222
  161. package/planning/04-adapter-backend/README.md +0 -45
  162. package/planning/05-documentation-publishing/01-README-optimization.md +0 -105
  163. package/planning/05-documentation-publishing/02-VitePress-site-evaluation.md +0 -136
  164. package/planning/05-documentation-publishing/03-Changeset-setup.md +0 -192
  165. package/planning/05-documentation-publishing/04-GitHub-templates.md +0 -252
  166. package/planning/05-documentation-publishing/README.md +0 -22
  167. package/planning/05-documentation-publishing/STATUS.md +0 -222
  168. package/planning/prd.md +0 -405
  169. package/planning/streams/01-create-md5stream-class.md +0 -69
  170. package/planning/streams/02-create-factory-api.md +0 -65
  171. package/planning/streams/03-fs-integration.md +0 -37
  172. package/planning/streams/04-whatwg-streams-support.md +0 -37
  173. package/planning/streams/05-audit-optimization.md +0 -121
  174. package/planning/streams/06-comprehensive-tests-docs.md +0 -137
  175. package/planning/streams/07-architecture-integration.md +0 -38
  176. package/planning/streams/README.md +0 -98
  177. package/tsup.config.ts +0 -24
@@ -1,228 +0,0 @@
1
- # Задача 7: Анализ бандла и метрики
2
-
3
- ## Контекст
4
-
5
- После настройки tsup и создания разных сборок (Задачи 1 и 6) необходимо измерить и проанализировать результаты оптимизаций. Без количественных метрик невозможно оценить эффективность проделанной работы.
6
-
7
- ## Цель
8
-
9
- Создать систему для измерения и анализа:
10
-
11
- 1. Размера бандла до/после оптимизаций
12
- 2. Эффективности tree-shaking
13
- 3. Производительности MD5 реализации
14
- 4. Качества TypeScript типов
15
-
16
- ## Требуемые действия
17
-
18
- ### Шаг 1: Установить инструменты для анализа
19
-
20
- 1. Установить инструменты для анализа бандла и типов:
21
- ```bash
22
- npm install -D @arethetypeswrong/cli bundlewatch
23
- ```
24
- 2. Установить инструменты для бенчмарков:
25
- ```bash
26
- npm install -D benchmark microtime
27
- ```
28
-
29
- ### Шаг 2: Создать скрипты для анализа размера
30
-
31
- 1. Создать `scripts/analyze-size.js`:
32
-
33
- ```javascript
34
- // scripts/analyze-size.js
35
- import fs from 'fs';
36
- import { gzipSync } from 'zlib';
37
- import { brotliCompressSync } from 'zlib';
38
-
39
- const files = [
40
- 'dist/index.js',
41
- 'dist/index.mjs',
42
- 'dist/index.min.js',
43
- 'dist/index.browser.js'
44
- ];
45
-
46
- console.log('=== Bundle Size Analysis ===\n');
47
-
48
- files.forEach((file) => {
49
- if (fs.existsSync(file)) {
50
- const content = fs.readFileSync(file);
51
- const rawSize = content.length;
52
- const gzippedSize = gzipSync(content).length;
53
- const brotliSize = brotliCompressSync(content).length;
54
-
55
- console.log(`${file}:`);
56
- console.log(` Raw: ${(rawSize / 1024).toFixed(2)} KB`);
57
- console.log(` Gzipped: ${(gzippedSize / 1024).toFixed(2)} KB`);
58
- console.log(` Brotli: ${(brotliSize / 1024).toFixed(2)} KB`);
59
- console.log(
60
- ` Gzip reduction: ${((1 - gzippedSize / rawSize) * 100).toFixed(1)}%`
61
- );
62
- console.log();
63
- }
64
- });
65
- ```
66
-
67
- ### Шаг 3: Создать бенчмарки производительности
68
-
69
- 1. Создать `benchmarks/performance.js`:
70
-
71
- ```javascript
72
- // benchmarks/performance.js
73
- import { md5 } from '../dist/index.mjs';
74
- import Benchmark from 'benchmark';
75
-
76
- const suite = new Benchmark.Suite('MD5 Performance');
77
-
78
- // Тестовые данные
79
- const testCases = [
80
- { name: 'Short string (10 chars)', data: 'Hello World' },
81
- { name: 'Medium string (100 chars)', data: 'x'.repeat(100) },
82
- { name: 'Long string (1000 chars)', data: 'x'.repeat(1000) },
83
- { name: 'Binary data (1KB)', data: Buffer.alloc(1024, 'x').toString() }
84
- ];
85
-
86
- testCases.forEach(({ name, data }) => {
87
- suite.add(name, () => {
88
- md5(data);
89
- });
90
- });
91
-
92
- suite
93
- .on('cycle', (event) => {
94
- console.log(String(event.target));
95
- })
96
- .on('complete', function () {
97
- console.log('\nFastest is: ' + this.filter('fastest').map('name'));
98
- })
99
- .run({ async: true });
100
- ```
101
-
102
- ### Шаг 4: Проверить качество TypeScript типов
103
-
104
- 1. Добавить скрипт для проверки типов:
105
- ```json
106
- "scripts": {
107
- "check-types": "tsc --noEmit",
108
- "check-exports": "attw --pack ."
109
- }
110
- ```
111
- 2. Создать `scripts/check-exports.js` для проверки exports
112
-
113
- ### Шаг 5: Создать метрики tree-shaking
114
-
115
- 1. Создать тестовый проект для проверки tree-shaking
116
- 2. Импортировать только `md5` функцию
117
- 3. Собрать проект и проверить что неиспользуемый код удален
118
- 4. Использовать `@arethetypeswrong/cli` для анализа
119
-
120
- ### Шаг 6: Создать baseline измерений
121
-
122
- 1. Сохранить текущие метрики (до оптимизаций):
123
- ```bash
124
- npm run build
125
- node scripts/analyze-size.js > benchmarks/baseline-size.json
126
- node benchmarks/performance.js > benchmarks/baseline-performance.json
127
- ```
128
- 2. Создать файлы с baseline данными
129
-
130
- ### Шаг 7: Создать скрипт для сравнения
131
-
132
- 1. Создать `scripts/compare-metrics.js`:
133
-
134
- ```javascript
135
- // scripts/compare-metrics.js
136
- import fs from 'fs';
137
-
138
- const baseline = JSON.parse(
139
- fs.readFileSync('benchmarks/baseline-size.json', 'utf8')
140
- );
141
- const current = JSON.parse(
142
- fs.readFileSync('benchmarks/current-size.json', 'utf8')
143
- );
144
-
145
- console.log('=== Size Comparison (Before vs After) ===\n');
146
-
147
- Object.keys(baseline).forEach((file) => {
148
- if (current[file]) {
149
- const baselineSize = baseline[file].raw;
150
- const currentSize = current[file].raw;
151
- const change = (
152
- ((currentSize - baselineSize) / baselineSize) *
153
- 100
154
- ).toFixed(1);
155
-
156
- console.log(`${file}:`);
157
- console.log(` Before: ${(baselineSize / 1024).toFixed(2)} KB`);
158
- console.log(` After: ${(currentSize / 1024).toFixed(2)} KB`);
159
- console.log(` Change: ${change}%`);
160
- console.log();
161
- }
162
- });
163
- ```
164
-
165
- ### Шаг 8: Интегрировать в CI/CD
166
-
167
- 1. Обновить GitHub Actions workflow:
168
- ```yaml
169
- # .github/workflows/ci.yml
170
- jobs:
171
- analyze:
172
- runs-on: ubuntu-latest
173
- steps:
174
- - uses: actions/checkout@v3
175
- - uses: actions/setup-node@v3
176
- - run: npm ci
177
- - run: npm run build
178
- - run: npm run analyze-size
179
- - run: npm run check-types
180
- - run: npm run check-exports
181
- ```
182
- 2. Добавить проверки на регрессии
183
-
184
- ### Шаг 9: Документировать результаты
185
-
186
- 1. Создать `BENCHMARKS.md` в корне проекта
187
- 2. Задокументировать методологию измерений
188
- 3. Привести результаты до/после оптимизаций
189
- 4. Сделать выводы об эффективности
190
-
191
- ## Ожидаемый результат
192
-
193
- - Полная система метрик и анализа
194
- - Измерения размера бандла до/после
195
- - Измерения производительности до/после
196
- - Проверка качества TypeScript типов
197
- - Интеграция в CI/CD
198
- - Документация результатов
199
-
200
- ## Проверка прогресса
201
-
202
- - [ ] Установлены инструменты для анализа
203
- - [ ] Созданы скрипты для анализа размера
204
- - [ ] Созданы бенчмарки производительности
205
- - [ ] Настроена проверка TypeScript типов
206
- - [ ] Созданы метрики tree-shaking
207
- - [ ] Создан baseline измерений
208
- - [ ] Создан скрипт для сравнения
209
- - [ ] Интегрировано в CI/CD
210
- - [ ] Документированы результаты
211
-
212
- ## Примечания
213
-
214
- 1. Измерения должны быть воспроизводимыми
215
- 2. Учитывать variance в измерениях производительности
216
- 3. Проводить multiple runs для статистической значимости
217
- 4. Сохранять историю измерений для tracking
218
-
219
- ## Метрики успеха
220
-
221
- 1. Уменьшение размера бандла на 20-30%
222
- 2. Улучшение производительности на 10-20%
223
- 3. Эффективное tree-shaking
224
- 4. Качественные TypeScript типы (no errors)
225
-
226
- ## Следующий шаг
227
-
228
- После настройки системы метрик перейти к Задаче 8: Обновление документации и CI/CD.
@@ -1,34 +0,0 @@
1
- # Задача 8: Бенчмарки, метрики, документация и CI/CD
2
-
3
- ## Контекст
4
-
5
- После всех оптимизаций необходимо измерить и задокументировать улучшения, обновить документацию и настроить CI/CD процессы. Это обеспечит:
6
-
7
- 1. Количественные метрики эффективности оптимизаций
8
- 2. Четкие инструкции для пользователей
9
- 3. Автоматическую проверку качества
10
- 4. Отслеживание регрессий
11
- 5. Профессиональную поддержку проекта
12
-
13
- ## Цель
14
-
15
- Создать полную систему бенчмарков, метрик, обновить документацию и настроить CI/CD для измерения:
16
-
17
- 1. Производительности до/после оптимизаций
18
- 2. Размера бандла до/после
19
- 3. Эффективности tree-shaking
20
- 4. Потребления памяти
21
- 5. Документировать и автоматизировать процессы
22
-
23
- ## Требуемые действия
24
-
25
- ### Шаг 1: Создать бенчмарки производительности
26
-
27
- 1. Создать файл `benchmarks/performance.js`
28
- 2. Реализовать тесты для разных сценариев:
29
- - Хеширование коротких строк
30
- - Хеширование длинных строк
31
- - Хеширование бинарных данных
32
- - Многократное хеширование
33
-
34
- **Пример бенчмарка:**
@@ -1,260 +0,0 @@
1
- # Migration Guide to tsup
2
-
3
- ## Overview
4
-
5
- This guide describes the migration process from the outdated Webpack+Babel+TypeScript stack to modern tsup.
6
-
7
- ## Migration Benefits
8
-
9
- ### Before migration:
10
-
11
- - Webpack 4.34.0 (2019)
12
- - TypeScript 3.5.2 (2019)
13
- - Babel for transpilation
14
- - 13 dev dependencies
15
- - Slow builds
16
- - Complex configuration
17
-
18
- ### After migration:
19
-
20
- - tsup (modern)
21
- - TypeScript 5+ (latest version)
22
- - Native TypeScript transpilation
23
- - 3-5 dev dependencies
24
- - 10-100x faster builds
25
- - Minimal configuration
26
-
27
- ## Step-by-Step Migration Plan
28
-
29
- ### Step 0: Preparation
30
-
31
- 1. Ensure all tests pass: `npm test`
32
- 2. Create backup of current configuration
33
- 3. Check current bundle size (baseline)
34
-
35
- ### Step 1: Install tsup
36
-
37
- ```bash
38
- # Install tsup and update TypeScript
39
- npm install -D tsup typescript@latest
40
-
41
- # Verify installation
42
- npx tsup --version
43
- npx tsc --version
44
- ```
45
-
46
- ### Step 2: Remove Outdated Dependencies
47
-
48
- ```bash
49
- # Remove Webpack and Babel
50
- npm uninstall -D webpack webpack-cli babel-loader \
51
- @babel/core @babel/preset-env @babel/preset-typescript \
52
- @babel/plugin-proposal-class-properties @babel/plugin-proposal-object-rest-spread
53
-
54
- # Remove configuration files
55
- rm webpack.config.js .babelrc
56
- ```
57
-
58
- ### Step 3: Basic tsup Configuration
59
-
60
- Create `tsup.config.ts`:
61
-
62
- ```typescript
63
- import { defineConfig } from 'tsup';
64
-
65
- export default defineConfig({
66
- entry: ['src/index.ts'],
67
- format: ['cjs', 'esm'],
68
- dts: true,
69
- sourcemap: true,
70
- clean: true,
71
- treeshake: true
72
- });
73
- ```
74
-
75
- ### Step 4: Update TypeScript Configuration
76
-
77
- Update `tsconfig.json`:
78
-
79
- ```json
80
- {
81
- "compilerOptions": {
82
- "target": "es2020",
83
- "module": "esnext",
84
- "moduleResolution": "node",
85
- "declaration": true,
86
- "outDir": "./dist",
87
- "strict": true,
88
- "esModuleInterop": true,
89
- "skipLibCheck": true,
90
- "forceConsistentCasingInFileNames": true
91
- },
92
- "include": ["src/**/*"],
93
- "exclude": ["node_modules", "**/*.test.ts"]
94
- }
95
- ```
96
-
97
- ### Step 5: Update package.json
98
-
99
- ```json
100
- {
101
- "scripts": {
102
- "build": "tsup",
103
- "build:watch": "tsup --watch",
104
- "dev": "tsup --watch",
105
- "test": "jest"
106
- },
107
- "main": "./dist/index.js",
108
- "module": "./dist/index.mjs",
109
- "types": "./dist/index.d.ts",
110
- "exports": {
111
- ".": {
112
- "import": "./dist/index.mjs",
113
- "require": "./dist/index.js",
114
- "types": "./dist/index.d.ts"
115
- }
116
- }
117
- }
118
- ```
119
-
120
- ### Step 6: First Build
121
-
122
- ```bash
123
- # First build
124
- npm run build
125
-
126
- # Check created files
127
- ls -la dist/
128
-
129
- # Check sizes
130
- ls -lh dist/*
131
- ```
132
-
133
- ### Step 7: Verification
134
-
135
- ```bash
136
- # Run tests
137
- npm test
138
-
139
- # Check import in Node.js
140
- node -e "const { md5 } = require('./dist/index.js'); console.log(md5('test'))"
141
-
142
- # Check as ES module (if supported)
143
- node --loader ts-node/esm -e "import { md5 } from './dist/index.mjs'; console.log(md5('test'))"
144
- ```
145
-
146
- ### Step 8: Additional Configurations
147
-
148
- Create additional configurations as needed:
149
-
150
- - `tsup.config.prod.ts` - for production
151
- - `tsup.config.umd.ts` - for browser
152
- - `tsup.config.min.ts` - minimal build
153
-
154
- ## Troubleshooting
155
-
156
- ### Problem 1: TypeScript Errors After Update
157
-
158
- **Solution:**
159
-
160
- 1. Check TypeScript breaking changes
161
- 2. Update types gradually
162
- 3. Use `tsc --noEmit` for verification
163
-
164
- ### Problem 2: .d.ts Files Not Generated
165
-
166
- **Solution:**
167
-
168
- 1. Check that `dts: true` in configuration
169
- 2. Ensure TypeScript is properly configured
170
- 3. Check with `@arethetypeswrong/cli`
171
-
172
- ### Problem 3: Tree-Shaking Not Working
173
-
174
- **Solution:**
175
-
176
- 1. Check that `treeshake: true`
177
- 2. Ensure ES modules are used
178
- 3. Check side effects in package.json
179
-
180
- ### Problem 4: Import Errors
181
-
182
- **Solution:**
183
-
184
- 1. Check exports in package.json
185
- 2. Ensure correct paths
186
- 3. Check compatibility with consumers
187
-
188
- ## Verification Checklist
189
-
190
- - [ ] tsup installed
191
- - [ ] Outdated dependencies removed
192
- - [ ] tsup configuration created
193
- - [ ] TypeScript updated and configured
194
- - [ ] package.json updated
195
- - [ ] Build works
196
- - [ ] Tests pass
197
- - [ ] Import works
198
- - [ ] .d.ts files generated
199
- - [ ] Tree-shaking works
200
- - [ ] Bundle size reduced
201
-
202
- ## Additional Optimizations
203
-
204
- ### 1. Configuration for Different Formats
205
-
206
- ```typescript
207
- // tsup.config.prod.ts
208
- export default defineConfig({
209
- entry: ['src/index.ts'],
210
- format: ['cjs', 'esm'],
211
- dts: true,
212
- sourcemap: false,
213
- minify: true,
214
- treeshake: true
215
- });
216
- ```
217
-
218
- ### 2. Browser Configuration
219
-
220
- ```typescript
221
- // tsup.config.umd.ts
222
- export default defineConfig({
223
- entry: ['src/index.ts'],
224
- format: ['iife'],
225
- globalName: 'pureMD5',
226
- minify: true,
227
- target: 'es2020',
228
- platform: 'browser'
229
- });
230
- ```
231
-
232
- ### 3. Minimal Build
233
-
234
- ```typescript
235
- // tsup.config.min.ts
236
- export default defineConfig({
237
- entry: ['src/index.ts'],
238
- format: ['esm'],
239
- dts: false,
240
- sourcemap: false,
241
- minify: true,
242
- treeshake: true,
243
- pure: ['console.log']
244
- });
245
- ```
246
-
247
- ## Resources
248
-
249
- - [tsup Documentation](https://tsup.egoist.dev/)
250
- - [TypeScript 5 Breaking Changes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html)
251
- - [Tree-shaking in tsup](https://tsup.egoist.dev/#tree-shaking)
252
- - [Configuration Examples](https://github.com/egoist/tsup/tree/main/examples)
253
-
254
- ## Support
255
-
256
- If problems occur:
257
-
258
- 1. Check tsup documentation
259
- 2. Create issue in repository
260
- 3. Contact TypeScript community
@@ -1,173 +0,0 @@
1
- # Phase 3: Size Optimization and Tree-Shaking Configuration
2
-
3
- ## Goal
4
-
5
- Reduce bundle size, improve tree-shaking, and optimize MD5 implementation performance.
6
-
7
- ## Current Analysis
8
-
9
- ### Problems:
10
-
11
- 1. **Outdated bundler** - Webpack 4 + Babel + TypeScript 3.5 (2019)
12
- 2. **CommonJS modules** - poorly suited for tree-shaking in modern bundlers
13
- 3. **Many small files** - create import overhead
14
- 4. **Runtime check** in `index.ts` increases bundle size
15
- 5. **Code duplication** - `add32` is defined in two places
16
- 6. **Suboptimal loops** - performance can be improved
17
-
18
- ### Metrics before optimization:
19
-
20
- - Total number of files in `src/`: 16
21
- - Used dependencies: 0 (pure TypeScript)
22
- - Current build: Webpack 4 + Babel + TypeScript 3.5 (outdated stack)
23
- - Dev dependencies: 13 packages (can be reduced)
24
-
25
- ## Optimization Tasks
26
-
27
- ### Task 1: Migration from Webpack to tsup
28
-
29
- **Goal**: Replace outdated Webpack+Babel+TypeScript stack with modern tsup for faster builds and better tree-shaking.
30
- **Actions:**
31
-
32
- 1. Install tsup and remove outdated dependencies
33
- 2. Configure tsup for TypeScript library builds
34
- 3. Update TypeScript to modern version
35
- 4. Configure .d.ts file generation
36
-
37
- **Expected result:** 10-100x faster builds, improved tree-shaking, reduced dependencies.
38
- **Progress:** [ ] Not started
39
-
40
- ---
41
-
42
- ### Task 2: Consolidation of Small Modules
43
-
44
- **Goal**: Combine related functions into larger modules to reduce overhead.
45
-
46
- **Actions:**
47
-
48
- 1. Combine `ff.ts`, `gg.ts`, `hh.ts`, `ii.ts` into one module `round-functions.ts`
49
- 2. Combine `hex.ts` and `rhex.ts` (or inline rhex)
50
- 3. Consider inlining `cmn.ts` into `md5cycle.ts`
51
-
52
- **Expected result:** Reduction of file count from 16 to ~10.
53
-
54
- **Progress:** [ ] Not started
55
-
56
- ---
57
-
58
- ### Task 3: Elimination of Code Duplication
59
-
60
- **Goal**: Remove duplication of the `add32` function.
61
-
62
- **Actions:**
63
-
64
- 1. Remove inline definition of `add32` from `index.ts`
65
- 2. Ensure import from `add32.ts` is used everywhere
66
- 3. Optimize `add32` implementation for performance
67
-
68
- **Expected result:** Single implementation of `add32`.
69
-
70
- **Progress:** [ ] Not started
71
-
72
- ---
73
-
74
- ### Task 4: Moving Runtime Check to Compile-Time
75
-
76
- **Goal**: Remove `hex(md51('hello'))` check from runtime.
77
-
78
- **Actions:**
79
-
80
- 1. Create a test to verify MD5 correctness
81
- 2. Remove runtime check from `index.ts`
82
- 3. Add compile-time check via TypeScript or in the build
83
-
84
- **Expected result:** Reduced bundle size and improved performance.
85
-
86
- **Progress:** [ ] Not started
87
-
88
- ---
89
-
90
- ### Task 5: Loop and Operation Optimization
91
-
92
- **Goal**: Improve performance of critical code sections.
93
-
94
- **Actions:**
95
-
96
- 1. Optimize loops in `md51.ts`
97
- 2. Improve bit operations in `add32.ts`
98
- 3. Consider using typed arrays for performance
99
-
100
- **Expected result:** 10-20% performance improvement.
101
-
102
- **Progress:** [ ] Not started
103
-
104
- ---
105
-
106
- ### Task 6: tsup Configuration for Different Formats
107
-
108
- **Goal**: Configure tsup to create different builds for different environments.
109
- **Actions:**
110
-
111
- 1. Configure tsup to generate CommonJS, ES modules, and UMD
112
- 2. Add minification and dead code elimination
113
- 3. Configure source maps
114
- 4. Create minimal build
115
-
116
- **Expected result:** Flexible optimized builds for all environments.
117
- **Progress:** [ ] Not started
118
-
119
- ---
120
-
121
- ### Task 7: Bundle Analysis and Metrics
122
-
123
- **Goal**: Measure and analyze optimization results.
124
- **Actions:**
125
-
126
- 1. Install and configure bundle analyzer
127
- 2. Measure bundle size before and after optimizations
128
- 3. Check tree-shaking effectiveness
129
- 4. Create performance benchmarks
130
-
131
- **Expected result:** Quantitative improvement metrics, understanding of what can be optimized further.
132
- **Progress:** [ ] Not started
133
-
134
- ---
135
-
136
- ### Task 8: Documentation and CI/CD Update
137
-
138
- **Goal**: Update documentation and CI/CD for the new stack.
139
- **Actions:**
140
-
141
- 1. Update README with build instructions
142
- 2. Update package.json with new scripts
143
- 3. Configure GitHub Actions for the new stack
144
- 4. Add automatic benchmarks to CI
145
-
146
- **Expected result:** Complete documentation and automated CI/CD.
147
- **Progress:** [ ] Not started
148
-
149
- ## Success Criteria
150
-
151
- 1. 10-100x faster builds
152
- 2. 20-30% reduction in bundle size
153
- 3. Improved tree-shaking (dead code elimination)
154
- 4. Reduction of dev dependencies from 13 to 3-5 packages
155
- 5. Maintain 100% test coverage
156
- 6. Compatibility with all current use cases
157
-
158
- ## Priorities
159
-
160
- 1. Migration to tsup (Task 1)
161
- 2. Tree-shaking and consolidation (Tasks 2, 6)
162
- 3. Size reduction (Tasks 3, 4)
163
- 4. Performance and metrics (Tasks 5, 7, 8)
164
-
165
- ## Risks
166
-
167
- 1. Breaking backward compatibility
168
- 2. Issues with .d.ts file generation
169
- 3. Incompatibility with existing consumers
170
-
171
- ## Next Steps
172
-
173
- After completing this phase, move to: 4. File system integration 5. WHATWG Streams support 6. Comprehensive testing and documentation