Skip to content

Commit 5d1deec

Browse files
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
1 parent 4c917dd commit 5d1deec

File tree

1 file changed

+79
-15
lines changed

1 file changed

+79
-15
lines changed

migration-guides/0.15-Migration-Guide.md

Lines changed: 79 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# PureScript 0.15 Migration Guide
22

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
411

512
### tl;dr
613

@@ -10,7 +17,7 @@
1017

1118
### A little bit of background
1219

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.
1421

1522
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
1623

@@ -32,13 +39,13 @@ However, this has a couple of implications that will need you to migrate your co
3239

3340

3441
* v0.15 drops support for Node.js versions < 12
35-
42+
3643
This is just the logical consequence of Node.js versions < 12 having reached EOL and not supporting ESM. More on this here:
3744

3845
[How can I use Purescript on Node.js?](#how-can-i-update-cjs-to-esm)
3946

4047
* v0.15 drops `purs bundle` and relies on an external bundlers
41-
48+
4249
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.
4350

4451
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
99106
"use strict";
100107
$PS["Main"] = $PS["Main"] || {};
101108
var exports = $PS["Main"];
102-
var Effect_Console = $PS["Effect.Console"];
109+
var Effect_Console = $PS["Effect.Console"];
103110
var main = Effect_Console.log("\ud83c\udf5d");
104111
exports["main"] = main;
105112
})(PS);
@@ -112,11 +119,13 @@ However, this has a couple of implications that will need you to migrate your co
112119
113120
### How can I update CJS to ESM?
114121
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:
116125
117126
* Importing a module
118127
119-
In v0.14 you had to import a module using `require`
128+
In v0.14 you had to import a module using `require`
120129
121130
```javascript
122131
const mymodule = require('mymodule')
@@ -137,11 +146,19 @@ When you are writing JS FFI the most common situations where you will see change
137146
exports.greet = function() { return "hello " + world }
138147
```
139148

140-
In v0.15 you need to use `export`
149+
In v0.15 you need to use `export`
141150
```javascript
142151
export const world = "🗺"
143152

144153
export function greet() { 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+
const newImpl = function () { return new SomeObject; }
161+
export { newImpl as new };
145162
```
146163

147164
Fortunately, there are tools that can automatically perform this conversion for you in most of the cases.
@@ -167,6 +184,7 @@ https://github.com/lebab/lebab#unsafe-transforms
167184

168185
In general though it works well in most of the cases.
169186

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.
170188

171189
Another option you can try is [`cjstoesm`](https://github.com/wessberg/cjstoesm).
172190

@@ -182,7 +200,7 @@ import { main } from 'output/Main/index.js'
182200
main()
183201
```
184202

185-
and run
203+
and run
186204
```bash
187205
node index.js
188206
# 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
212230

213231
See [`spago` documentation](https://github.com/purescript/spago#bundle-a-project-into-a-single-js-file).
214232

215-
Basic usage:
233+
Basic usage:
216234
```bash
217-
spago bundle-app # bundle for the browser
235+
spago bundle-app # bundle for the browser
218236
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
220238
spago bundle-app --platform node --minify # minified bundle for node
221239

222-
spago bundle-module # bundle for the browser
240+
spago bundle-module # bundle for the browser
223241
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
225243
spago bundle-module --platform node --minify # minified bundle for node
226244
```
227245

228-
#### Using `esbuild` to bundle
246+
#### Using `esbuild` to bundle
229247

230248
See [`esbuild` documentation](https://esbuild.github.io/).
231249

@@ -257,3 +275,49 @@ Basic usage:
257275
parcel build index.html --no-source-maps --no-optimize --no-scope-hoist --dist-dir "dist/" # bundle for the browser
258276
parcel build index.html --no-source-maps --dist-dir "dist/" # minified bundle for the browser
259277
```
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.
284+
- Removed all kind-specific Proxy types (e.g. `SProxy`, `Proxy2`, `Proxy3`, `RLProxy`, etc.)
285+
- 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
322+
323+
This section has yet to be written

0 commit comments

Comments
 (0)