libphonenumber-js 1.9.42 → 1.9.43

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/exports/README.md CHANGED
@@ -1,18 +1,30 @@
1
1
  # Node ES Modules Support
2
2
 
3
- These are some experiments on supporting Node.js EcmaScript Modules feature.
3
+ These are some notes on potentially implementing Node.js's native EcmaScript Modules support.
4
4
 
5
- [Original discussion](https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/42#note_718767070)
5
+ ## Why
6
6
 
7
- [TypeScript support](https://www.typescriptlang.org/docs/handbook/esm-node.html)
7
+ It originally started with a non-reproducible [issue report](https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/42).
8
+
9
+ Turns out, Node.js 14+ introduced native support for `import` syntax, but did it in its own weird way. The native support for `import` syntax can be turned on by adding `type: "module"` flag in the application's `package.json` or by using `*.mjs` file extension. It also imposes a needless and stupid requirement to always specify the file extension when `import`ing from relative paths.
10
+
11
+ <!--
12
+ Turns out, Node.js 14+ introduced native support for `import` syntax, but did it in its own weird incompatible way. The native support for `import` syntax can be turned on by adding `type: "module"` flag in the application's `package.json` or by using `*.mjs` file extension, but that also breaks "named exports" when importing from "legacy" packages — ones that neither use the `type: "module"` flag in their `package.json`, nor the `*.mjs` file extension.
13
+
14
+ As a workaround, "named exports" can still be accessed from the `default` export, but that would look a bit hacky, and would also only work exclusively in Node.js 14+, and won't cross-compile between server side and client side when writing "isomorphic" code because on client side the `default` export won't contain any of the "named exports".
15
+
16
+ As another workaround, one could create a file
17
+
18
+ In order to fix that incompatibility, the library would have to include a separate build just for this new Node.js module subsystem.
19
+ -->
8
20
 
9
21
  ## Status
10
22
 
11
- I have decided not to do this for now because it seems too convoluted. The new ES Modules feature in Node.js has several weird and needless restrictions that overcomplicate the whole process of supporting that feature. Among those restrictions, requiring a developer to specify an explicit file extension is just stupid.
23
+ The solution is outlined below, but I have decided not to add it to the library for now because it seems too convoluted. The new ES Modules feature in Node.js has several weird and needless restrictions that overcomplicate the whole process of making 3rd-party libraries compatible. Among those restrictions, requiring a developer to specify an explicit file extension on all relative imports is especially stupid.
12
24
 
13
- Even if someone decides to implement all this and submit a pull request, I don't think that it would get merged because it's still to convoluted. They should come up with a better designed ES Module importing system.
25
+ Even if someone decides to implement all this and submit a pull request, I don't think that it would get merged because it's still convoluted. Node.js developers should come up with a better designed ES Module importing system.
14
26
 
15
- ## Steps
27
+ ## Solution
16
28
 
17
29
  First, add the entries from `exports/package.json` file to `package.json` file.
18
30
 
@@ -75,4 +87,12 @@ Test if it works in:
75
87
  * Webpack 6.
76
88
  * TypeScript — See if it finds the "typings" for those `exports` entries when `import`ing from `libphonenumber-js/min`, etc.
77
89
  * Without `"compilerOptions": { "module": "nodenext" }` config.
78
- * With `"compilerOptions": { "module": "nodenext" }` config.
90
+ * With `"compilerOptions": { "module": "nodenext" }` config.
91
+
92
+ ## References
93
+
94
+ [Node.js EcmaScript Modules](https://nodejs.org/api/packages.html)
95
+
96
+ [TypeScript support](https://www.typescriptlang.org/docs/handbook/esm-node.html)
97
+
98
+ [Using `esm` package instead of `type: "module"` to support `import` syntax in Node.js](https://www.npmjs.com/package/esm)