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/README.md +6 -0
- package/bundle/libphonenumber-js.min.js +1 -1
- package/bundle/libphonenumber-js.min.js.map +1 -1
- package/bundle/libphonenumber-max.js +1 -1
- package/bundle/libphonenumber-max.js.map +1 -1
- package/bundle/libphonenumber-min.js +1 -1
- package/bundle/libphonenumber-min.js.map +1 -1
- package/bundle/libphonenumber-mobile.js +1 -1
- package/bundle/libphonenumber-mobile.js.map +1 -1
- package/exports/README.md +27 -7
- package/metadata.full.json +1 -1
- package/metadata.full.json.js +1 -1
- package/metadata.max.json +1 -1
- package/metadata.max.json.js +1 -1
- package/metadata.min.json +1 -1
- package/metadata.min.json.js +1 -1
- package/metadata.mobile.json +1 -1
- package/metadata.mobile.json.js +1 -1
- package/package.json +1 -1
package/exports/README.md
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
# Node ES Modules Support
|
|
2
2
|
|
|
3
|
-
These are some
|
|
3
|
+
These are some notes on potentially implementing Node.js's native EcmaScript Modules support.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Why
|
|
6
6
|
|
|
7
|
-
[
|
|
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
|
|
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
|
|
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
|
-
##
|
|
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)
|