@open-charging-cloud/chargy-core 0.3.0 → 0.4.0

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 CHANGED
@@ -1,45 +1,102 @@
1
- # Chargy Core
2
-
3
- The ChargyCore TypeScript library shared between Chargy Desktop, Web & Mobile applications.
4
-
5
- ## Usage
6
-
7
- ```ts
8
- import { Chargy } from "@open-charging-cloud/chargy-core";
9
- import { OCMF } from "@open-charging-cloud/chargy-core";
10
- ```
11
-
12
- The package is published as modern ESM and ships generated TypeScript declarations.
13
-
14
- ## Development
15
-
16
- ```bash
17
- npm install
18
- npm run typecheck
19
- npm test
20
- npm run build
21
- ```
22
-
23
- The build emits the package into `dist/`.
24
-
25
-
26
- ```bash
27
- npm version 0.3.0 --no-git-tag-version
28
- npm run verify
29
- npm pack --dry-run
30
- npm pack
31
- npm login
32
- npm whoami
33
- npm publish
34
- ```
35
-
36
-
37
- ## Funding
38
-
39
- This Open Source project is partially funded by the [NGI Zero Commons Fund](https://nlnet.nl/commonsfund/) as part of our [EVQI project](https://nlnet.nl/project/EVQI/).
40
-
41
- We also appreciate any additional funding and long-term support for the Chargy family, for example via [GitHub Sponsors](https://github.com/sponsors/GraphDefined), as it helps us keep the project sustainable, independent and useful for the entire e-mobility community.
42
-
43
- <center>
44
- <img src="images/NGI0_tag.svg" height="30">
45
- </center>
1
+ # Chargy Core
2
+
3
+ The ChargyCore TypeScript library shared between Chargy Desktop, Web & Mobile applications.
4
+
5
+ The package is published as modern ESM and ships generated TypeScript declarations.
6
+
7
+
8
+ ## Usage
9
+
10
+ ```ts
11
+ import { Chargy } from "@open-charging-cloud/chargy-core";
12
+ ```
13
+
14
+
15
+ ## Runtime Architecture
16
+
17
+ ChargyCore is consumed in different JavaScript runtimes. The browser-based Chargy WebApp and Electron renderer processes have Web APIs such as `DOMParser`, `Blob`, `TextEncoder`, `ImageData`, `DOMMatrix`, `Path2D`, and browser worker loading semantics. Node.js-based tests, command line tools, server-side verification, and build-time checks do not provide the same environment.
18
+
19
+ For that reason the package ships two JavaScript builds behind one public import:
20
+
21
+ ```text
22
+ dist/browser/index.js
23
+ dist/node/index.js
24
+ ```
25
+
26
+ The runtime-specific file is selected through conditional package exports in `package.json`. Browser bundlers should resolve the `browser` condition and receive `dist/browser/index.js`. Node.js resolves the `node` condition and receives `dist/node/index.js`.
27
+
28
+ This split is especially important for PDF.js. Browser contexts should use the normal `pdfjs-dist` build, because the browser already provides the canvas and DOM APIs PDF.js expects. Node.js should use `pdfjs-dist/legacy/build/pdf.mjs`, because the legacy build contains Node-oriented setup for the missing canvas-related globals and avoids the modern browser-only assumptions.
29
+
30
+ Keeping these paths separate has several advantages:
31
+
32
+ - Browser bundles do not include the Node/legacy PDF.js path as an unused lazy chunk.
33
+ - Node tests and CLI-style usage do not depend on browser-only PDF.js behavior.
34
+ - Chargy apps do not need local Webpack aliases or test polyfills for ChargyCore internals.
35
+ - Bundle checks can verify that the browser build only references browser PDF.js imports and the Node build only references legacy PDF.js imports.
36
+
37
+ When adding runtime-sensitive dependencies, avoid branching on runtime inside shared source code if that would make bundlers see both implementations. Prefer a small adapter under `src/` and let the build or conditional exports select the runtime-specific implementation.
38
+
39
+
40
+ ## Development
41
+
42
+ ```bash
43
+ npm install
44
+ npm run typecheck
45
+ npm run lint
46
+ npm run build
47
+ npm run test:node
48
+ npm run test:bundle
49
+ npm run test:browser
50
+ npm test
51
+ npm run verify
52
+ ```
53
+
54
+ The build emits the package into `dist/`.
55
+
56
+
57
+ ### Expected Test Flow
58
+
59
+ For code changes, use the full verification flow before publishing or handing a package to the Chargy apps:
60
+
61
+ ```bash
62
+ npm run verify
63
+ ```
64
+
65
+ `verify` runs the following checks:
66
+
67
+ - `npm run typecheck`: validates the TypeScript sources and test/config TypeScript files.
68
+ - `npm run lint`: runs the strict type-aware ESLint setup. Existing migration findings are warnings, new unused variables are errors.
69
+ - `npm test`: runs all runtime checks:
70
+ - `npm run test:node`: runs the Chargy fixture tests in Vitest's Node environment and uses the Node PDF.js adapter.
71
+ - `npm run build`: creates both package builds.
72
+ - `npm run test:bundle`: checks the generated bundles so the browser build only references the browser PDF.js path and the Node build only references the legacy PDF.js path.
73
+ - `npm run test:browser`: imports `dist/browser/index.js` in headless Chromium via Vitest Browser Mode and verifies the public browser entry can be loaded and instantiated.
74
+ - `npm run build`: recreates the final publishable `dist/` output.
75
+
76
+ For dependency, build, export, PDF.js, or browser-facing changes, run the individual steps while iterating and finish with `npm run verify`. The browser test requires Playwright's Chromium browser; if it is missing locally, run:
77
+
78
+ ```bash
79
+ npx playwright install chromium
80
+ ```
81
+
82
+
83
+ ```bash
84
+ npm version 0.4.0 --no-git-tag-version
85
+ npm run verify
86
+ npm pack --dry-run
87
+ npm pack
88
+ npm login
89
+ npm whoami
90
+ npm publish
91
+ ```
92
+
93
+
94
+ ## Funding
95
+
96
+ This Open Source project is partially funded by the [NGI Zero Commons Fund](https://nlnet.nl/commonsfund/) as part of our [EVQI project](https://nlnet.nl/project/EVQI/).
97
+
98
+ We also appreciate any additional funding and long-term support for the Chargy family, for example via [GitHub Sponsors](https://github.com/sponsors/GraphDefined), as it helps us keep the project sustainable, independent and useful for the entire e-mobility community.
99
+
100
+ <center>
101
+ <img src="images/NGI0_tag.svg" height="30">
102
+ </center>