-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This builds up on @achingbrain 's work on #863 with build improvements and full support This adds: - `ipjs` for ESM modules - auto-detected - `types` property transformation, allowing real time ts check in dev and path update for dist folder (TLDR no dist in the path) - `release` for ESM modules will navigate to the dist to publish its content - Dockerfile to bundlesize action per actions/runner#772 (comment) as we need node14+ for ESM One of the problematic modules in skypack using aegir is `uint8arrays`. It is a CJS module that depends on a ESM first module (multiformats), which makes skypack to get bad dependency paths. I tested this out shipping `uint8arrays` achingbrain/uint8arrays#22 PR and everything working smoothly 🎉 Original release: https://codepen.io/vascosantos/pen/KKmXoPV?editors=0011 Scoped release using `aegir`: https://codepen.io/vascosantos/pen/bGWoONq?editors=0011 (see browser built in console for errors) Co-authored-by: achingbrain <alex@achingbrain.net>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package-lock.json | ||
yarn.lock | ||
node_modules | ||
/node_modules | ||
/actions/bundle-size/node_modules | ||
/coverage | ||
/dist | ||
/docs | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
** | ||
!/dist |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Just enough docker until github gets a new node16 runner | ||
# see: https://github.com/actions/runner/issues/772 | ||
FROM node:16-alpine | ||
WORKDIR /usr/src/app | ||
COPY dist/index.js . | ||
CMD [ "node", "index.js" ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# ESM support | ||
|
||
## Setup | ||
|
||
`aegir` leverages [ipjs](https://github.com/mikeal/ipjs) to output a build with `cjs` and `esm` for maximum compatibility. The general guidelines for writing a module in `esm` are detailed on the `ipjs` README. `aegir` will automatically identify a `esm` repo by the `module` property in `package.json`. | ||
|
||
## Electron testing | ||
|
||
Electron does [not support ESM](https://github.com/electron/electron/issues/21457) at the time of writing. When writing a module using ESM, we need to compile the tests to `cjs` and rely on them. For generating the build including the tests: | ||
|
||
```bash | ||
aegir build --esm-tests | ||
``` | ||
|
||
## Lerna Monorepo | ||
|
||
When using a lerna monorepo, local dependencies are symlinked by lerna on install. This means that an `esm` module will not use the resulting `dist` folder as symlink. This can become a problem if we are testing the `cjs` build of a module. | ||
|
||
To work around the above problem, we can use `publishConfig.directory = "dist"` in `package.json` to notice lerna about the symlink path. After running the `aegir build` command, it is necessary to run `lerna link` to update the symlinks. | ||
|
||
## Release | ||
|
||
When releasing an `esm` module, the published content will be the generated `dist` folder content, as indicated by [ipjs](https://github.com/mikeal/ipjs). | ||
|
||
## Examples | ||
|
||
TODO: List examples when merged (`ipfs-unixfs`, `uint8arrays`) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const { expect } = require('../utils/chai') | ||
const execa = require('execa') | ||
const { copy, existsSync } = require('fs-extra') | ||
const { join } = require('path') | ||
const bin = require.resolve('../') | ||
const tempy = require('tempy') | ||
|
||
describe('build', () => { | ||
describe('esm', () => { | ||
let projectDir = '' | ||
|
||
before(async () => { | ||
projectDir = tempy.directory() | ||
|
||
await copy(join(__dirname, 'fixtures', 'esm', 'an-esm-project'), projectDir) | ||
}) | ||
|
||
it('should build an esm project', async function () { | ||
this.timeout(20 * 1000) // slow ci is slow | ||
|
||
await execa(bin, ['build'], { | ||
cwd: projectDir | ||
}) | ||
|
||
expect(existsSync(join(projectDir, 'dist', 'esm'))).to.be.true() | ||
expect(existsSync(join(projectDir, 'dist', 'cjs'))).to.be.true() | ||
|
||
const module = require(join(projectDir, 'dist')) | ||
|
||
expect(module).to.have.property('useHerp').that.is.a('function') | ||
expect(module).to.have.property('useDerp').that.is.a('function') | ||
}) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "an-esm-project", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "src/index.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"eslintConfig": { | ||
"extends": "ipfs", | ||
"parserOptions": { | ||
"sourceType": "module" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import herp from 'a-cjs-dep' | ||
import derp from 'an-esm-dep' | ||
|
||
export const useHerp = () => { | ||
herp() | ||
} | ||
|
||
export const useDerp = () => { | ||
derp() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
'use strict' | ||
|
||
require('./build') | ||
require('./lint') | ||
require('./fixtures') | ||
require('./dependants') | ||
|