Skip to content

Commit 9e1817b

Browse files
authored
Adopt ESM (#344)
* esm * node 18 * next * 5.0.0-rc.1 * remove jsdom * break circular import * bump versions in README
1 parent d9c5077 commit 9e1817b

30 files changed

+1096
-1792
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"extends": "eslint:recommended",
33
"parserOptions": {
44
"sourceType": "module",
5-
"ecmaVersion": 8
5+
"ecmaVersion": 2020
66
},
77
"env": {
88
"browser": true,
99
"es6": true,
10+
"es2020": true,
1011
"node": true
1112
},
1213
"rules": {

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
node-version: [14.x, 16.x]
11+
node-version: [14.x, 16.x, 18.x]
1212

1313
steps:
1414
- uses: actions/checkout@v1

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ For example, to render the “hello” cell from the [“Hello World” notebook
99
```html
1010
<!DOCTYPE html>
1111
<meta charset="utf-8">
12-
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@observablehq/inspector@3/dist/inspector.css">
12+
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@observablehq/inspector@4/dist/inspector.css">
1313
<body>
1414
<script type="module">
1515
16-
import {Runtime, Inspector} from "https://cdn.jsdelivr.net/npm/@observablehq/runtime@4/dist/runtime.js";
17-
import define from "https://api.observablehq.com/@observablehq/hello-world.js?v=3";
16+
import {Runtime, Inspector} from "https://cdn.jsdelivr.net/npm/@observablehq/runtime@5/dist/runtime.js";
17+
import define from "https://api.observablehq.com/@observablehq/hello-world.js?v=4";
1818
1919
const runtime = new Runtime();
2020
const main = runtime.module(define, name => {

package.json

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,49 @@
11
{
22
"name": "@observablehq/runtime",
3-
"version": "4.28.0",
4-
"license": "ISC",
5-
"main": "dist/runtime.umd.js",
6-
"module": "src/index.js",
3+
"version": "5.0.0-rc.1",
74
"author": {
85
"name": "Observable, Inc.",
96
"url": "https://observablehq.com"
107
},
8+
"license": "ISC",
9+
"type": "module",
10+
"main": "src/index.js",
11+
"module": "src/index.js",
12+
"jsdelivr": "dist/runtime.umd.js",
13+
"unpkg": "dist/runtime.umd.js",
14+
"exports": {
15+
"umd": "./dist/runtime.umd.js",
16+
"default": "./src/index.js"
17+
},
1118
"repository": {
1219
"type": "git",
1320
"url": "https://github.com/observablehq/runtime.git"
1421
},
22+
"files": [
23+
"dist/**/*.js",
24+
"src/**/*.js"
25+
],
1526
"scripts": {
16-
"test": "tape -r esm 'test/**/*-test.js'",
27+
"test": "mocha 'test/**/*-test.js' && eslint src test",
1728
"prepublishOnly": "rm -rf dist && rollup -c",
1829
"postpublish": "git push && git push --tags"
1930
},
20-
"files": [
21-
"src/**/*.js",
22-
"dist/**/*.js"
23-
],
31+
"_moduleAliases": {
32+
"@observablehq/runtime": "./src/index.js"
33+
},
2434
"dependencies": {
25-
"@observablehq/inspector": "^3.2.2",
26-
"@observablehq/stdlib": "^3.4.1"
35+
"@observablehq/inspector": "4.0.0-rc.1",
36+
"@observablehq/stdlib": "4.0.0-rc.1"
2737
},
2838
"devDependencies": {
29-
"eslint": "^7.18.0",
30-
"esm": "^3.2.25",
31-
"jsdom": "^17.0.0",
32-
"rollup": "^2.37.1",
33-
"rollup-plugin-node-resolve": "^5.2.0",
34-
"rollup-plugin-terser": "^7.0.2",
35-
"tape": "^4.13.3",
36-
"tape-await": "^0.1.2"
39+
"@rollup/plugin-node-resolve": "^15.0.1",
40+
"eslint": "^8.27.0",
41+
"mocha": "^10.1.0",
42+
"module-alias": "^2.2.2",
43+
"rollup": "^3.2.5",
44+
"rollup-plugin-terser": "^7.0.2"
45+
},
46+
"publishConfig": {
47+
"tag": "next"
3748
}
3849
}

rollup.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import node from "rollup-plugin-node-resolve";
1+
import node from "@rollup/plugin-node-resolve";
22
import {terser} from "rollup-plugin-terser";
3-
import * as meta from "./package.json";
3+
import * as meta from "./package.json" assert {type: "json"};
44

55
const copyright = `// @observablehq/runtime v${meta.version} Copyright ${(new Date).getFullYear()} Observable, Inc.`;
66

src/array.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
var prototype = Array.prototype;
2-
export var map = prototype.map;
3-
export var forEach = prototype.forEach;
1+
const prototype = Array.prototype;
2+
export const map = prototype.map;
3+
export const forEach = prototype.forEach;

src/constant.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export default function(x) {
2-
return function() {
3-
return x;
4-
};
1+
export function constant(x) {
2+
return () => x;
53
}

src/errors.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export function RuntimeError(message, input) {
2-
this.message = message + "";
3-
this.input = input;
1+
export class RuntimeError extends Error {
2+
constructor(message, input) {
3+
super(message);
4+
this.input = input;
5+
}
46
}
57

6-
RuntimeError.prototype = Object.create(Error.prototype);
78
RuntimeError.prototype.name = "RuntimeError";
8-
RuntimeError.prototype.constructor = RuntimeError;

src/generatorish.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default function generatorish(value) {
1+
export function generatorish(value) {
22
return value
33
&& typeof value.next === "function"
44
&& typeof value.return === "function";

src/identity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export default function(x) {
1+
export function identity(x) {
22
return x;
33
}

0 commit comments

Comments
 (0)