Skip to content

Commit

Permalink
Adopt type=module (d3#179)
Browse files Browse the repository at this point in the history
* Adopt type=module

follow changes in d3-format:
* type=module
* add exports
* remove zip
* license: ISC
* update dependencies

* es6 rather than no-undef

* use the "falls through" comment to make eslint's "no-fallthrough" rule happy

* remove Sublime project

* add eslint.json

* stricter eslint

* cleaner imports

* update dependencies

* Update README

Co-authored-by: Mike Bostock <mbostock@gmail.com>
  • Loading branch information
Fil and mbostock committed Jun 4, 2021
1 parent 54f0f11 commit 0aa3677
Show file tree
Hide file tree
Showing 62 changed files with 2,015 additions and 2,140 deletions.
7 changes: 2 additions & 5 deletions .eslintrc.json
Expand Up @@ -5,12 +5,9 @@
"ecmaVersion": 8
},
"env": {
"es6": true,
"node": true,
"browser": true
"es6": true
},
"rules": {
"no-cond-assign": 0,
"no-fallthrough": 0
"no-cond-assign": 0
}
}
18 changes: 18 additions & 0 deletions .github/eslint.json
@@ -0,0 +1,18 @@
{
"problemMatcher": [
{
"owner": "eslint-compact",
"pattern": [
{
"regexp": "^(.+):\\sline\\s(\\d+),\\scol\\s(\\d+),\\s(Error|Warning|Info)\\s-\\s(.+)\\s\\((.+)\\)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5,
"code": 6
}
]
}
]
}
30 changes: 30 additions & 0 deletions .github/workflows/node.js.yml
@@ -0,0 +1,30 @@
# https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn --frozen-lockfile
- run: |
echo ::add-matcher::.github/eslint.json
yarn run eslint src test --format=compact
- run: yarn test
40 changes: 13 additions & 27 deletions LICENSE
@@ -1,27 +1,13 @@
Copyright 2010-2015 Mike Bostock
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the author nor the names of contributors may be used to
endorse or promote products derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Copyright 2010-2021 Mike Bostock

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
21 changes: 16 additions & 5 deletions README.md
Expand Up @@ -26,18 +26,29 @@ For more, read [Introducing d3-shape](https://medium.com/@mbostock/introducing-d

## Installing

If you use NPM, `npm install d3-shape`. Otherwise, download the [latest release](https://github.com/d3/d3-shape/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-shape.v2.min.js) or as part of [D3](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:
If you use npm, `npm install d3-shape`. You can also download the [latest release on GitHub](https://github.com/d3/d3-shape/releases/latest). For vanilla HTML in modern browsers, import d3-shape from Skypack:

```html
<script src="https://d3js.org/d3-path.v2.min.js"></script>
<script src="https://d3js.org/d3-shape.v2.min.js"></script>
<script>
<script type="module">
import {line} from "https://cdn.skypack.dev/d3-shape@3";
const line = d3.line();
const l = line();
</script>
```

For legacy environments, you can load d3-shape’s UMD bundle from an npm-based CDN such as jsDelivr; a `d3` global is exported:

```html
<script src="https://cdn.jsdelivr.net/npm/d3-path@3"></script>
<script src="https://cdn.jsdelivr.net/npm/d3-shape@3"></script>
<script>
const l = d3.line();
</script>
```

## API Reference

Expand Down
17 changes: 0 additions & 17 deletions d3-shape.sublime-project

This file was deleted.

47 changes: 27 additions & 20 deletions package.json
Expand Up @@ -2,6 +2,11 @@
"name": "d3-shape",
"version": "2.1.0",
"description": "Graphical primitives for visualization, such as lines and areas.",
"homepage": "https://d3js.org/d3-shape/",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-shape.git"
},
"keywords": [
"d3",
"d3-module",
Expand All @@ -10,39 +15,41 @@
"canvas",
"svg"
],
"homepage": "https://d3js.org/d3-shape/",
"license": "BSD-3-Clause",
"license": "ISC",
"author": {
"name": "Mike Bostock",
"url": "http://bost.ocks.org/mike"
},
"main": "dist/d3-shape.js",
"unpkg": "dist/d3-shape.min.js",
"jsdelivr": "dist/d3-shape.min.js",
"module": "src/index.js",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-shape.git"
},
"type": "module",
"files": [
"dist/**/*.js",
"src/**/*.js"
],
"scripts": {
"pretest": "rollup -c",
"test": "tape 'test/**/*-test.js' && eslint src",
"prepublishOnly": "rm -rf dist && yarn test",
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd - && zip -j dist/${npm_package_name}.zip -- LICENSE README.md dist/${npm_package_name}.js dist/${npm_package_name}.min.js"
"module": "src/index.js",
"main": "src/index.js",
"jsdelivr": "dist/d3-shape.min.js",
"unpkg": "dist/d3-shape.min.js",
"exports": {
"umd": "./dist/d3-shape.min.js",
"default": "./src/index.js"
},
"sideEffects": false,
"dependencies": {
"d3-path": "1 - 2"
"d3-path": "1 - 3"
},
"sideEffects": false,
"devDependencies": {
"d3-polygon": "1 - 2",
"d3-polygon": "1 - 3",
"eslint": "7",
"mocha": "8",
"rollup": "2",
"rollup-plugin-terser": "7",
"tape": "4"
"rollup-plugin-terser": "7"
},
"scripts": {
"test": "mocha 'test/**/*-test.js' && eslint src test",
"prepublishOnly": "rm -rf dist && yarn test && rollup -c",
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd -"
},
"engines": {
"node": ">=12"
}
}
4 changes: 2 additions & 2 deletions src/curve/basis.js
Expand Up @@ -27,7 +27,7 @@ Basis.prototype = {
},
lineEnd: function() {
switch (this._point) {
case 3: point(this, this._x1, this._y1); // proceed
case 3: point(this, this._x1, this._y1); // falls through
case 2: this._context.lineTo(this._x1, this._y1); break;
}
if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
Expand All @@ -38,7 +38,7 @@ Basis.prototype = {
switch (this._point) {
case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
case 1: this._point = 2; break;
case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // falls through
default: point(this, x, y); break;
}
this._x0 = this._x1, this._x1 = x;
Expand Down
2 changes: 1 addition & 1 deletion src/curve/basisOpen.js
Expand Up @@ -26,7 +26,7 @@ BasisOpen.prototype = {
case 0: this._point = 1; break;
case 1: this._point = 2; break;
case 2: this._point = 3; var x0 = (this._x0 + 4 * this._x1 + x) / 6, y0 = (this._y0 + 4 * this._y1 + y) / 6; this._line ? this._context.lineTo(x0, y0) : this._context.moveTo(x0, y0); break;
case 3: this._point = 4; // proceed
case 3: this._point = 4; // falls through
default: point(this, x, y); break;
}
this._x0 = this._x1, this._x1 = x;
Expand Down
2 changes: 1 addition & 1 deletion src/curve/bump.js
Expand Up @@ -25,7 +25,7 @@ class Bump {
else this._context.moveTo(x, y);
break;
}
case 1: this._point = 2; // proceed
case 1: this._point = 2; // falls through
default: {
if (this._x) this._context.bezierCurveTo(this._x0 = (this._x0 + x) / 2, this._y0, this._x0, y, x, y);
else this._context.bezierCurveTo(this._x0, this._y0 = (this._y0 + y) / 2, x, this._y0, x, y);
Expand Down
2 changes: 1 addition & 1 deletion src/curve/cardinal.js
Expand Up @@ -39,7 +39,7 @@ Cardinal.prototype = {
switch (this._point) {
case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
case 2: this._point = 3; // proceed
case 2: this._point = 3; // falls through
default: point(this, x, y); break;
}
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
Expand Down
2 changes: 1 addition & 1 deletion src/curve/cardinalOpen.js
Expand Up @@ -27,7 +27,7 @@ CardinalOpen.prototype = {
case 0: this._point = 1; break;
case 1: this._point = 2; break;
case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
case 3: this._point = 4; // proceed
case 3: this._point = 4; // falls through
default: point(this, x, y); break;
}
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
Expand Down
2 changes: 1 addition & 1 deletion src/curve/catmullRom.js
Expand Up @@ -63,7 +63,7 @@ CatmullRom.prototype = {
switch (this._point) {
case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
case 1: this._point = 2; break;
case 2: this._point = 3; // proceed
case 2: this._point = 3; // falls through
default: point(this, x, y); break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/curve/catmullRomOpen.js
Expand Up @@ -37,7 +37,7 @@ CatmullRomOpen.prototype = {
case 0: this._point = 1; break;
case 1: this._point = 2; break;
case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
case 3: this._point = 4; // proceed
case 3: this._point = 4; // falls through
default: point(this, x, y); break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/curve/linear.js
Expand Up @@ -20,7 +20,7 @@ Linear.prototype = {
x = +x, y = +y;
switch (this._point) {
case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
case 1: this._point = 2; // proceed
case 1: this._point = 2; // falls through
default: this._context.lineTo(x, y); break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/curve/step.js
Expand Up @@ -23,7 +23,7 @@ Step.prototype = {
x = +x, y = +y;
switch (this._point) {
case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
case 1: this._point = 2; // proceed
case 1: this._point = 2; // falls through
default: {
if (this._t <= 0) {
this._context.lineTo(this._x, y);
Expand Down
11 changes: 11 additions & 0 deletions test/.eslintrc.json
@@ -0,0 +1,11 @@
{
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 8
},
"env": {
"es6": true,
"mocha": true
}
}

0 comments on commit 0aa3677

Please sign in to comment.