Skip to content

Commit

Permalink
meta: set ESM as default JS type (#18)
Browse files Browse the repository at this point in the history
This is necessary to improve compatibility with Webpack.
  • Loading branch information
aduh95 authored Feb 21, 2021
1 parent 6cb5b21 commit 20d5a24
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ jobs:
- name: Prepare tests
run:
rm package.json && npm i mocha && npm i viz.js-vunreleased+${{
github.sha }}.tar.gz
- name: Run tests
github.sha }}.tar.gz && echo 'const assert=require("assert");' >
test/node.cjs && awk '/^describe\(/{o=1} { if (o==1) { print } }'
test/node.js >> test/node.cjs
- name: Run CJS tests
run:
node ./node_modules/.bin/mocha test/node.js -f "should render a graph
node ./node_modules/.bin/mocha test/node.cjs -f "should render a graph
using sync version"

test-deno:
Expand Down
2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
yarnPath: ./.yarn/releases/yarn-berry.js
yarnPath: ./.yarn/releases/yarn-berry.cjs
nodeLinker: node-modules
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ $(DEPS_FOLDER):
$(error You must run `make deps` first.)

async/index.js sync/index.js: %/index.js: | %
echo "module.exports=require('../dist/render_$(@D).js')" > $@
echo "module.exports=require('../dist/render_$(@D).cjs')" > $@
async/index.d.ts sync/index.d.ts: %/index.d.ts: dist/render_%.d.ts | %
echo "export {default} from '../dist/render_$(@D)'" > $@

Expand Down Expand Up @@ -138,9 +138,9 @@ dist/render.browser.js dist/render.node.mjs: dist/%: build/% node_modules/terser
dist/render.wasm: build/render.wasm | dist
cp $< $@

dist/render_async.js: build/render_async.js node_modules/terser | dist
dist/render_async.cjs: build/render_async.js node_modules/terser | dist
sed 's/export default/module.exports=/' $< | $(TERSER) --toplevel > $@
dist/render_sync.js: build/render_sync.js build/asm build/viz_wrapper.js node_modules/rollup node_modules/terser | dist
dist/render_sync.cjs: build/render_sync.js build/asm build/viz_wrapper.js node_modules/rollup node_modules/terser | dist
$(ROLLUP) -f commonjs --exports default $< | $(TERSER) --toplevel > $@
endif

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
},
"./async": "./dist/render_async.js",
"./sync": "./dist/render_sync.js",
"./async": "./dist/render_async.cjs",
"./sync": "./dist/render_sync.cjs",
"./wasm": "./dist/render.wasm",
"./worker": {
"import": "./dist/render.node.mjs",
"browser": "./dist/render.browser.js"
}
},
"type": "commonjs",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/aduh95/viz.js.git"
Expand All @@ -36,9 +36,9 @@
"dist/render.node.mjs",
"dist/render.browser.js",
"dist/render.wasm",
"dist/render_async.js",
"dist/render_async.cjs",
"dist/render_async.d.ts",
"dist/render_sync.js",
"dist/render_sync.cjs",
"dist/render_sync.d.ts",
"async/index.js",
"async/index.d.ts",
Expand Down
5 changes: 3 additions & 2 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"env": { "node": true, "mocha": true, "es2020": true },
"env": { "node": false, "mocha": true, "es2020": true },
"extends": ["plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 2020
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {
"no-implicit-globals": "error",
Expand Down
4 changes: 2 additions & 2 deletions test/browser.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* globals getViz, parseSVG */
/* eslint-env browser, es6 */

const assert = require("assert");
const puppeteer = require("puppeteer");
import assert from "assert";
import puppeteer from "puppeteer";

const args = puppeteer.defaultArgs();
args[args.findIndex((flag) => /enable-features/.test(flag))] +=
Expand Down
5 changes: 1 addition & 4 deletions test/deno-files/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"env": { "browser": true, "node": false, "mocha": false },
"ignorePatterns": ["render.wasm.arraybuffer.js"],
"parserOptions": {
"sourceType": "module"
}
"ignorePatterns": ["render.wasm.arraybuffer.js"]
}
5 changes: 4 additions & 1 deletion test/node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const assert = require("assert");
import assert from "assert";
import { createRequire } from "module";

const require = createRequire(import.meta.url);

async function getViz() {
const worker = await import("@aduh95/viz.js/worker").then((module) =>
Expand Down
5 changes: 1 addition & 4 deletions test/web-server/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"env": { "mocha": false },
"parserOptions": {
"sourceType": "module"
}
"env": { "mocha": false }
}

0 comments on commit 20d5a24

Please sign in to comment.