@jscutlery/swc-angular 0.12.0 → 0.13.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/CHANGELOG.md CHANGED
@@ -1,60 +1,63 @@
1
- ## 0.12.0 (2024-04-12)
1
+ ## 0.13.1 (2024-05-03)
2
2
 
3
3
 
4
- ### 🚀 Features
4
+ ### 🩹 Fixes
5
5
 
6
- - **swc-angular:** ✨ rename swc-angular packages ([#324](https://github.com/jscutlery/devkit/pull/324))
6
+ - **swc-angular:** 🐞 fix stackblitz support ([#364](https://github.com/jscutlery/devkit/pull/364))
7
7
 
8
8
 
9
9
  ### ❤️ Thank You
10
10
 
11
11
  - Younes Jaaidi
12
12
 
13
- ## 0.3.0 (2024-04-11)
14
-
13
+ ## 0.12.0 (2024-04-12)
15
14
 
16
15
  ### 🚀 Features
17
16
 
18
- - **swc-angular-preset:** ✨ fail gracefully if @swc/core is incompatible ([#322](https://github.com/jscutlery/devkit/pull/322))
17
+ - **swc-angular:** ✨ rename swc-angular packages ([#324](https://github.com/jscutlery/devkit/pull/324))
18
+
19
+ ### ❤️ Thank You
19
20
 
21
+ - Younes Jaaidi
20
22
 
21
- ### ❤️ Thank You
23
+ ## 0.3.0 (2024-04-11)
24
+
25
+ ### 🚀 Features
26
+
27
+ - **swc-angular-preset:** ✨ fail gracefully if @swc/core is
28
+ incompatible ([#322](https://github.com/jscutlery/devkit/pull/322))
29
+
30
+ ### ❤️ Thank You
22
31
 
23
32
  - Younes Jaaidi
24
33
 
25
34
  ## 0.2.2 (2024-04-09)
26
35
 
27
-
28
36
  ### 🩹 Fixes
29
37
 
30
38
  - **swc-angular-preset:** 🐞 fix jest preset typing ([9c6de1c](https://github.com/jscutlery/devkit/commit/9c6de1c))
31
39
 
32
-
33
- ### ❤️ Thank You
40
+ ### ❤️ Thank You
34
41
 
35
42
  - Younes Jaaidi
36
43
 
37
44
  ## 0.2.1 (2024-04-08)
38
45
 
39
-
40
46
  ### 🩹 Fixes
41
47
 
42
48
  - **swc-plugin-angular:** 🐞 transform async/await ([#313](https://github.com/jscutlery/devkit/pull/313))
43
49
 
44
-
45
- ### ❤️ Thank You
50
+ ### ❤️ Thank You
46
51
 
47
52
  - Younes Jaaidi
48
53
 
49
54
  ## 0.2.0 (2024-04-04)
50
55
 
51
-
52
56
  ### 🚀 Features
53
57
 
54
58
  - **swc-angular-preset:** ✨ add vite support ([#307](https://github.com/jscutlery/devkit/pull/307))
55
59
 
56
-
57
- ### ❤️ Thank You
60
+ ### ❤️ Thank You
58
61
 
59
62
  - Younes Jaaidi
60
63
 
@@ -64,28 +67,24 @@
64
67
 
65
68
  - **swc-angular-preset:** 🐞 publish dist artefact
66
69
 
67
-
68
70
  ## 0.1.1 (2024-03-29)
69
71
 
70
-
71
72
  ### 🩹 Fixes
72
73
 
73
- - **swc-angular-preset:** 🐞 allow recent versions of swc-plugin-angular ([c715414](https://github.com/jscutlery/devkit/commit/c715414))
74
-
74
+ - **swc-angular-preset:** 🐞 allow recent versions of
75
+ swc-plugin-angular ([c715414](https://github.com/jscutlery/devkit/commit/c715414))
75
76
 
76
- ### ❤️ Thank You
77
+ ### ❤️ Thank You
77
78
 
78
79
  - Edouard Bozon @edbzn
79
80
  - Younes Jaaidi
80
81
 
81
82
  ## 0.1.0 (2024-03-26)
82
83
 
83
-
84
84
  ### 🚀 Features
85
85
 
86
86
  - ✨ add swc-angular-preset and swc-plugin-angular ([#273](https://github.com/jscutlery/devkit/pull/273))
87
87
 
88
-
89
- ### ❤️ Thank You
88
+ ### ❤️ Thank You
90
89
 
91
90
  - Edouard Bozon @edbzn
package/README.md CHANGED
@@ -1,11 +1,34 @@
1
1
  # ⚡️ Speed Up Angular Testing with SWC 🦀
2
2
 
3
+ <!-- TOC -->
4
+
5
+ * [⚡️ Speed Up Angular Testing with SWC 🦀](#-speed-up-angular-testing-with-swc-)
6
+ * [👀 What is this?](#-what-is-this)
7
+ * [🤔 Context](#-context)
8
+ * [🥇 Benchmark Summary](#-benchmark-summary)
9
+ * [🎭 Setup with Jest](#-setup-with-jest)
10
+ * [1. Install](#1-install)
11
+ * [2. Configure](#2-configure)
12
+ * [3. Add `reflect-metadata`](#3-add-reflect-metadata)
13
+ * [⚡️Setup with Vitest](#setup-with-vitest)
14
+ * [1. Install](#1-install-1)
15
+ * [2. Configure](#2-configure-1)
16
+ * [3. Add `reflect-metadata`](#3-add-reflect-metadata-1)
17
+ * [🥇 Benchmark Data](#-benchmark-data)
18
+ * [🔥 No Cache](#-no-cache)
19
+ * [⚡️ With Cache](#-with-cache)
20
+ * [🥱 Cold Start](#-cold-start)
21
+ * [Configurations](#configurations)
22
+ * [Source](#source)
23
+
24
+ <!-- TOC -->
25
+
3
26
  ## 👀 What is this?
4
27
 
5
28
  This is a set of Angular presets that enable you to use [SWC (Speedy Web Compiler)](https://swc.rs/) with Jest or
6
29
  Vitest.
7
30
 
8
- **Switching to SWC can speed up your tests by 2x to 5x.**
31
+ **Switching to SWC can speed up your tests by 2x to 12x.**
9
32
 
10
33
  ## 🤔 Context
11
34
 
@@ -18,13 +41,16 @@ fast.
18
41
  This package enables you to use SWC with Angular projects by setting the right configuration for SWC and using
19
42
  our Angular plugin for SWC [`@jscutlery/swc-angular-plugin`](../swc-angular-plugin)
20
43
 
21
- ## 🥇 Benchmark
44
+ ## 🥇 Benchmark Summary
22
45
 
23
- | ts-jest | @swc/jest |
24
- |---------|---------------------|
25
- | 85s | 35s _(2.4x faster)_ |
46
+ ![Benchmark](benchmark.svg)
26
47
 
27
- 💻 try it yourself: https://github.com/yjaaidi/experiments/tree/angular-jest-swc-benchmark
48
+ _This chart is based on the [benchmark where all caches were disabled](#-no-cache) as in most cases we will still have
49
+ to transform the code that we changed and which is affecting our tests._
50
+ _In addition to that, incremental build tools like [Nx](https://nx.dev) (or jest/vitest `changedSince`/`changed`
51
+ options) will reduce the amount of transforms._
52
+
53
+ _Cf. [Detailed Benchmark Data](#-no-cache)_
28
54
 
29
55
  ## 🎭 Setup with Jest
30
56
 
@@ -49,14 +75,13 @@ export default {
49
75
  // ...
50
76
  transform: {
51
77
  '^.+\\.(ts|mjs|js)$': swcAngularJestTransformer(),
52
- '^.+\\.(html)$':
53
- [
54
- 'jest-preset-angular',
55
- {
56
- tsconfig: '<rootDir>/tsconfig.spec.json',
57
- stringifyContentPathRegex: '\\.(html|svg)$',
58
- },
59
- ],
78
+ '^.+\\.(html)$': [
79
+ 'jest-preset-angular',
80
+ {
81
+ tsconfig: '<rootDir>/tsconfig.spec.json',
82
+ stringifyContentPathRegex: '\\.(html|svg)$',
83
+ },
84
+ ],
60
85
  },
61
86
  transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
62
87
  // ...
@@ -108,3 +133,78 @@ located at `src/test-setup.ts`.
108
133
  ```ts
109
134
  import 'reflect-metadata';
110
135
  ```
136
+
137
+ ## 🥇 Benchmark Data
138
+
139
+ ### 🔥 No Cache
140
+
141
+ All caches are cleared before each benchmark run.
142
+
143
+ | Configuration | Relative | Mean [s] | Min [s] | Max [s] |
144
+ |:------------------------------|-------------:|---------------:|--------:|--------:|
145
+ | 🥇`vitest-swc-no-isolate` | 1.00 | 3.137 ± 0.061 | 3.042 | 3.227 |
146
+ | 🥈`jest-swc` | 3.31 ± 0.15 | 10.393 ± 0.429 | 9.745 | 10.994 |
147
+ | 🥉`angular-cli-karma` | 3.52 ± 0.53 | 11.041 ± 1.642 | 10.218 | 15.690 |
148
+ | `angular-cli-web-test-runner` | 5.46 ± 0.45 | 17.118 ± 1.362 | 16.473 | 20.911 |
149
+ | `jest` | 5.78 ± 0.25 | 18.132 ± 0.716 | 17.553 | 19.998 |
150
+ | `angular-cli-jest` | 8.61 ± 0.63 | 27.009 ± 1.902 | 24.938 | 30.450 |
151
+ | `vitest-swc` | 8.94 ± 0.21 | 28.038 ± 0.402 | 27.539 | 28.617 |
152
+ | `vitest` | 11.43 ± 0.32 | 35.872 ± 0.727 | 34.452 | 37.340 |
153
+ | `vitest-no-isolate` | 11.49 ± 0.25 | 36.061 ± 0.369 | 35.414 | 36.502 |
154
+
155
+ ### ⚡️ With Cache
156
+
157
+ All tests are ran once to warm up the cache before running the benchmark.
158
+
159
+ | Configuration | Relative | Mean [s] | Min [s] | Max [s] |
160
+ |:------------------------------|-------------:|---------------:|--------:|--------:|
161
+ | 🥇`vitest-swc-no-isolate` | 1.00 | 3.092 ± 0.090 | 3.030 | 3.301 |
162
+ | 🥈`angular-cli-karma` | 1.91 ± 0.07 | 5.901 ± 0.139 | 5.718 | 6.131 |
163
+ | 🥉`jest-swc` | 2.93 ± 0.18 | 9.045 ± 0.494 | 8.513 | 10.065 |
164
+ | `jest` | 4.07 ± 0.25 | 12.581 ± 0.663 | 11.572 | 13.915 |
165
+ | `angular-cli-web-test-runner` | 5.96 ± 0.29 | 18.428 ± 0.711 | 17.497 | 19.262 |
166
+ | `angular-cli-jest` | 8.46 ± 1.04 | 26.170 ± 3.117 | 23.350 | 31.983 |
167
+ | `vitest-swc` | 9.28 ± 0.36 | 28.691 ± 0.728 | 27.977 | 30.488 |
168
+ | `vitest-no-isolate` | 11.74 ± 0.45 | 36.286 ± 0.880 | 35.107 | 38.018 |
169
+ | `vitest` | 12.18 ± 0.63 | 37.666 ± 1.625 | 35.563 | 41.503 |
170
+
171
+ - _Note that, as of
172
+ today, [vitest doesn't cache transformed files](https://vitest.dev/config/#cache:~:text=At%20the%20moment%20Vitest%20stores%20cache%20for%20test%20results%20to%20run%20the%20longer%20and%20failed%20tests%20first)._
173
+
174
+ ### 🥱 Cold Start
175
+
176
+ Run a single test module just and try to measure the bootstrap time.
177
+
178
+ | Configuration | Relative | Mean [s] | Min [s] | Max [s] |
179
+ |:------------------------------|------------:|--------------:|--------:|--------:|
180
+ | 🥇`vitest-swc-no-isolate` | 1.00 | 1.260 ± 0.024 | 1.241 | 1.314 |
181
+ | 🥈`vitest-swc` | 1.00 ± 0.03 | 1.262 ± 0.026 | 1.225 | 1.305 |
182
+ | 🥉`jest-swc` | 1.44 ± 0.15 | 1.812 ± 0.186 | 1.714 | 2.310 |
183
+ | `vitest-no-isolate` | 1.47 ± 0.05 | 1.846 ± 0.056 | 1.797 | 1.949 |
184
+ | `vitest` | 1.61 ± 0.16 | 2.030 ± 0.198 | 1.814 | 2.423 |
185
+ | `jest` | 1.69 ± 0.08 | 2.136 ± 0.094 | 2.017 | 2.356 |
186
+ | `angular-cli-jest` | 1.73 ± 0.39 | 2.186 ± 0.495 | 1.869 | 3.119 |
187
+ | `angular-cli-web-test-runner` | 2.06 ± 1.15 | 2.602 ± 1.451 | 2.080 | 6.730 |
188
+ | `angular-cli-karma` | 5.08 ± 1.30 | 6.400 ± 1.636 | 5.377 | 10.177 |
189
+
190
+ ### Configurations
191
+
192
+ | | Configuration | Test Isolation\* |
193
+ |-------------------------------|:-------------------------------|-----------------:|
194
+ | `angular-cli-karma` | Angular CLI's Karma | false |
195
+ | `angular-cli-jest` | Angular CLI's Jest | true |
196
+ | `angular-cli-web-test-runner` | Angular CLI's @web/test-runner | true |
197
+ | `jest` | Jest | true |
198
+ | `jest-swc` | Jest + SWC | true |
199
+ | `vitest` | Vitest | true |
200
+ | `vitest-no-isolate` | Vitest + No Isolation | false |
201
+ | `vitest-swc` | Vitest + SWC | true |
202
+ | `vitest-swc-no-isolate` | Vitest + SWC + No Isolation | false |
203
+
204
+ - _Test Isolation: this tells whether each test module has its own testing environment or if each one is isolated. (i.e.
205
+ globals like the DOM are shared, asynchronous code might bleed between tests, etc...)_
206
+
207
+ ### Source
208
+
209
+ 💻 try it yourself: https://github.com/yjaaidi/experiments/tree/angular-jest-swc-benchmark
210
+ or checkout the last benchmark results: https://github.com/yjaaidi/experiments/actions/workflows/benchmark.yml
package/index.cjs.js CHANGED
@@ -3,6 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@swc/core');
6
+ var node_fs = require('node:fs');
7
+ var node_path = require('node:path');
6
8
 
7
9
  function _extends() {
8
10
  _extends = Object.assign || function assign(target) {
@@ -15,7 +17,15 @@ function _extends() {
15
17
  return _extends.apply(this, arguments);
16
18
  }
17
19
 
18
- assertCompatibleSwcCoreVersion();
20
+ class FileSystem {
21
+ readJsonFile(path) {
22
+ const content = node_fs.readFileSync(path, 'utf-8');
23
+ return JSON.parse(content);
24
+ }
25
+ }
26
+ const fileSystem = new FileSystem();
27
+
28
+ assertCompatibleSwcCoreVersion(core.version);
19
29
  function swcAngularPreset(options = {}) {
20
30
  return {
21
31
  jsc: {
@@ -72,10 +82,15 @@ function swcAngularUnpluginOptions() {
72
82
  /**
73
83
  * @deprecated Use {@link swcAngularVitePreset}, {@link swcAngularJestTransformer} or {@link swcAngularPreset} instead.
74
84
  */ var index = swcAngularPreset();
75
- function assertCompatibleSwcCoreVersion() {
76
- if (!core.version.startsWith('1.4.')) {
77
- console.warn(`
78
- @swc/core version ${core.version} is incompatible with @jscutlery/swc-angular.
85
+ function assertCompatibleSwcCoreVersion(version) {
86
+ /* Fallback to reading version from package.json when not exported.
87
+ * This happens on Stackblitz. */ if (version == undefined) {
88
+ const packageJsonPath = node_path.join(node_path.dirname(require.resolve('@swc/core')), 'package.json');
89
+ version = fileSystem.readJsonFile(packageJsonPath).version;
90
+ }
91
+ if (!version.startsWith('1.4.')) {
92
+ console.error(`
93
+ @swc/core version ${version} is incompatible with @jscutlery/swc-angular.
79
94
  Please use @swc/core version 1.4.x.
80
95
  > npm add -D @swc/core@~1.4.0
81
96
  `);
package/index.esm.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { version } from '@swc/core';
2
+ import { readFileSync } from 'node:fs';
3
+ import { join, dirname } from 'node:path';
2
4
 
3
5
  function _extends() {
4
6
  _extends = Object.assign || function assign(target) {
@@ -11,7 +13,15 @@ function _extends() {
11
13
  return _extends.apply(this, arguments);
12
14
  }
13
15
 
14
- assertCompatibleSwcCoreVersion();
16
+ class FileSystem {
17
+ readJsonFile(path) {
18
+ const content = readFileSync(path, 'utf-8');
19
+ return JSON.parse(content);
20
+ }
21
+ }
22
+ const fileSystem = new FileSystem();
23
+
24
+ assertCompatibleSwcCoreVersion(version);
15
25
  function swcAngularPreset(options = {}) {
16
26
  return {
17
27
  jsc: {
@@ -68,9 +78,14 @@ function swcAngularUnpluginOptions() {
68
78
  /**
69
79
  * @deprecated Use {@link swcAngularVitePreset}, {@link swcAngularJestTransformer} or {@link swcAngularPreset} instead.
70
80
  */ var index = swcAngularPreset();
71
- function assertCompatibleSwcCoreVersion() {
81
+ function assertCompatibleSwcCoreVersion(version) {
82
+ /* Fallback to reading version from package.json when not exported.
83
+ * This happens on Stackblitz. */ if (version == undefined) {
84
+ const packageJsonPath = join(dirname(require.resolve('@swc/core')), 'package.json');
85
+ version = fileSystem.readJsonFile(packageJsonPath).version;
86
+ }
72
87
  if (!version.startsWith('1.4.')) {
73
- console.warn(`
88
+ console.error(`
74
89
  @swc/core version ${version} is incompatible with @jscutlery/swc-angular.
75
90
  Please use @swc/core version 1.4.x.
76
91
  > npm add -D @swc/core@~1.4.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jscutlery/swc-angular",
3
- "version": "0.12.0",
3
+ "version": "0.13.1",
4
4
  "repository": {
5
5
  "url": "https://github.com/jscutlery/devkit"
6
6
  },
package/src/utils.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare class FileSystem {
2
+ readJsonFile<T>(path: string): T;
3
+ }
4
+ export declare const fileSystem: FileSystem;