You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add tooling and library updates to 0.15.0 migration guide (documentationjs#424)
* Add initial section for tooling
* Remove unneeded whitespace
* Add some initial updates for core libraries
* Add section for contrib, node, and web libraries
* Add 'replace with Type.Proxy' note
* Drop prepare-0.15 package set note
* Link to es modules script
The above guide doesn't mention the issue with
"use strict"; not getting dropped.
Not sure if we should mention it
here explicitly, but
my script accounts for that.
At the same time, my script
uses bash commands that
may not work the same on MacOS
* Add note about export renaming
Copy file name to clipboardExpand all lines: migration-guides/0.15-Migration-Guide.md
+79-15Lines changed: 79 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,13 @@
1
1
# PureScript 0.15 Migration Guide
2
2
3
-
## ES modules migration guide
3
+
## Tooling
4
+
5
+
-`purescript-psa` does not need to be updated.
6
+
-`spago` needs to be updated to `vT.B.D`.
7
+
-`pulp` needs to be updated to `v16.0.0`.
8
+
-`purs-tidy` needs to be updated to `vT.B.D`.
9
+
10
+
## ES modules migration guide
4
11
5
12
### tl;dr
6
13
@@ -10,7 +17,7 @@
10
17
11
18
### A little bit of background
12
19
13
-
In April 2021 the Node.js LTS version 10 reached end-of-life, which was the last version that did not yet support ES modules (ESM). This means, that all Node.js LTS and current versions support ES modules. And since all major browsers support ESM already since a long time, there is no need anymore in the JS ecosystem to support Common JS (CJS) and the community is advocating to [drop CJS support](https://github.com/sindresorhus/meta/discussions/15), which kinda makes sense. The community is following suit and is dropping its support for CJS, some notable examples are [remark](https://github.com/remarkjs/remark/tree/main/packages/remark#install), [`node-fetch`](https://github.com/node-fetch/node-fetch#commonjs) and [`framer-motion`](https://github.com/framer/motion) amongst many others.
20
+
In April 2021 the Node.js LTS version 10 reached end-of-life, which was the last version that did not yet support ES modules (ESM). This means, that all Node.js LTS and current versions support ES modules. And since all major browsers support ESM already since a long time, there is no need anymore in the JS ecosystem to support Common JS (CJS) and the community is advocating to [drop CJS support](https://github.com/sindresorhus/meta/discussions/15), which kinda makes sense. The community is following suit and is dropping its support for CJS, some notable examples are [remark](https://github.com/remarkjs/remark/tree/main/packages/remark#install), [`node-fetch`](https://github.com/node-fetch/node-fetch#commonjs) and [`framer-motion`](https://github.com/framer/motion) amongst many others.
14
21
15
22
What does that mean for Purescript v0.14? Well, a little bit of bad news, because Purescript v0.14 only supports CJS. Fortunately, there has been a [long-standing PR](https://github.com/purescript/purescript/pull/3791) to support ES modules in Purescript. So time to get this over the finish line and get ESM and
16
23
@@ -32,13 +39,13 @@ However, this has a couple of implications that will need you to migrate your co
32
39
33
40
34
41
* v0.15 drops support for Node.js versions < 12
35
-
42
+
36
43
This is just the logical consequence of Node.js versions < 12 having reached EOL and not supporting ESM. More on this here:
37
44
38
45
[How can I use Purescript on Node.js?](#how-can-i-update-cjs-to-esm)
39
46
40
47
* v0.15 drops `purs bundle` and relies on an external bundlers
41
-
48
+
42
49
Yes, you heard right. The Purescript compiler no longer comes with a built-in `bundle` command. `purs bundle` was already broken in a couple of ways, didn't do a great job on bundle size, and was basically unmaintained. Updating `purs bundle` to ESM would have required a considerable amount of work, taking time away from the compiler team to work on more urgent matters in the compiler.
43
50
44
51
Therefore, v0.15 relies on an external bundler like `esbuild`, `webpack` or `parcel`. And that is good news because these tools are used industry-wide and do a much better job on bundling than `purs bundle`. You will see significantly improved bundle sizes with v0.15, like e.g. for [purescript-halogen template](https://github.com/purescript-halogen/purescript-halogen-template):
@@ -99,7 +106,7 @@ However, this has a couple of implications that will need you to migrate your co
99
106
"use strict";
100
107
$PS["Main"] = $PS["Main"] || {};
101
108
var exports = $PS["Main"];
102
-
var Effect_Console = $PS["Effect.Console"];
109
+
var Effect_Console = $PS["Effect.Console"];
103
110
var main = Effect_Console.log("\ud83c\udf5d");
104
111
exports["main"] = main;
105
112
})(PS);
@@ -112,11 +119,13 @@ However, this has a couple of implications that will need you to migrate your co
112
119
113
120
### How can I update CJS to ESM?
114
121
115
-
When you are writing JS FFI the most common situations where you will see changes are:
122
+
Most of the below changes can be automated (see next section), but this section describes what changes need to be made in more detail.
123
+
124
+
When you are writing JS FFI the most common situations where you will see changes are:
116
125
117
126
* Importing a module
118
127
119
-
In v0.14 you had to import a module using `require`
128
+
In v0.14 you had to import a module using `require`
120
129
121
130
```javascript
122
131
const mymodule = require('mymodule')
@@ -137,11 +146,19 @@ When you are writing JS FFI the most common situations where you will see change
137
146
exports.greet=function() { return"hello "+ world }
138
147
```
139
148
140
-
In v0.15 you need to use `export`
149
+
In v0.15 you need to use `export`
141
150
```javascript
142
151
exportconstworld="🗺"
143
152
144
153
exportfunctiongreet() { return"hello "+ world }
154
+
155
+
// Sometimes, defining the function and then exporting it under
156
+
// a different name is needed to prevent issues with JavaScript
157
+
// keywords. For example, we might use the below FFI
158
+
// to export a function named `new`
159
+
// foreign import new :: Effect SomeObject
160
+
constnewImpl=function () { returnnewSomeObject; }
161
+
export { newImplasnew };
145
162
```
146
163
147
164
Fortunately, there are tools that can automatically perform this conversion for you in most of the cases.
In general though it works well in most of the cases.
169
186
187
+
See also the ["Migrate to ES Modules"](https://github.com/JordanMartinez/purescript-ecosystem-update/blob/master/src/bash/lib/migrateFfiToEs6.sh) script used in the ecosystem updates for inspiration.
170
188
171
189
Another option you can try is [`cjstoesm`](https://github.com/wessberg/cjstoesm).
172
190
@@ -182,7 +200,7 @@ import { main } from 'output/Main/index.js'
182
200
main()
183
201
```
184
202
185
-
and run
203
+
and run
186
204
```bash
187
205
node index.js
188
206
# or if you are on Node.js 12
@@ -212,20 +230,20 @@ For a full discussion see [the github issue](https://github.com/working-group-pu
212
230
213
231
See [`spago` documentation](https://github.com/purescript/spago#bundle-a-project-into-a-single-js-file).
214
232
215
-
Basic usage:
233
+
Basic usage:
216
234
```bash
217
-
spago bundle-app # bundle for the browser
235
+
spago bundle-app # bundle for the browser
218
236
spago bundle-app --platform node # bundle for node
219
-
spago bundle-app --minify # minified bundle for the browser
237
+
spago bundle-app --minify # minified bundle for the browser
220
238
spago bundle-app --platform node --minify # minified bundle for node
221
239
222
-
spago bundle-module # bundle for the browser
240
+
spago bundle-module # bundle for the browser
223
241
spago bundle-module --platform node # bundle for node
224
-
spago bundle-module --minify # minified bundle for the browser
242
+
spago bundle-module --minify # minified bundle for the browser
225
243
spago bundle-module --platform node --minify # minified bundle for node
226
244
```
227
245
228
-
#### Using `esbuild` to bundle
246
+
#### Using `esbuild` to bundle
229
247
230
248
See [`esbuild` documentation](https://esbuild.github.io/).
231
249
@@ -257,3 +275,49 @@ Basic usage:
257
275
parcel build index.html --no-source-maps --no-optimize --no-scope-hoist --dist-dir "dist/"# bundle for the browser
258
276
parcel build index.html --no-source-maps --dist-dir "dist/"# minified bundle for the browser
259
277
```
278
+
279
+
## Breaking Changes Made in Core Libraries
280
+
281
+
### Changes affecting multiple libraries
282
+
283
+
- Migrated all FFI to ES modules and dropped support for CommonJS modules.
- Replace usage of such types with `Type.Proxy (Proxy(..))`.
286
+
- Removed `MonadZero` type class and all of its deprecated instances.
287
+
288
+
### `purescript-prelude` changes
289
+
290
+
- The data type, `NoConstructors`, often used in `Generic`-related code, was changed to newtype `Void`, enabling one to unwrap the newtype and use `absurd`.
291
+
292
+
### `purescript-ordered-collections`: update on `Map`'s `Semigroup` instance
293
+
294
+
This section has yet to be written. Below is what was written in the v0.14.x guide.
295
+
296
+
- Changes we will be making in future releases:
297
+
- v0.14.0
298
+
- `Data.Map.Unbiased` - added
299
+
- `Data.Map`'s `Semigroup` instance unchanged but a deprecation notice is added, warning of future change
300
+
- v0.15.0
301
+
-`Data.Map.Unbiased` - deprecated
302
+
-`Data.Map`'s `Semigroup` instance is changed to `Data.Map.Unbiased` implementation. A deprecation notice is still shown, warning of the change.
303
+
- v0.16.0
304
+
-`Data.Map.Unbiased` - removed
305
+
-`Data.Map` - warning on `Semigroup` instance is removed
306
+
307
+
See [Unbiasing the Semigroup instance for Map](https://discourse.purescript.org/t/unbiasing-the-semigroup-instance-for-map/1935) and [purescript/purescript-ordered-collections#38](https://github.com/purescript/purescript-ordered-collections/pull/38) for more context.
308
+
309
+
### `purescript-foreign-object`'s `Semigroup` instance was changed
310
+
311
+
This section has yet to be written. Including here because it relates to the Map discussion above.
312
+
313
+
## Breaking Changes in the `purescript-contrib` libraries
314
+
315
+
This section has yet to be written
316
+
317
+
## Breaking Changes in the `purescript-node` libraries
318
+
319
+
This section has yet to be written
320
+
321
+
## Breaking Changes in the `purescript-web` libraries
0 commit comments