Skip to content

Commit 8c091c1

Browse files
Filmbostock
andauthored
Adopt type=module (#78)
* Adopt type=module follow changes in d3-format: * type=module * add exports * remove zip * license: ISC * update dependencies * browser instead of no-undef * remove Sublime project * add eslint.json * fix #51; extract copyrights from license * update dependencies * update README * update homepage * push on prepublishOnly * cleaner imports * snapshot tests Co-authored-by: Mike Bostock <[email protected]>
1 parent 4fc4f2b commit 8c091c1

18 files changed

+954
-955
lines changed

.eslintrc.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
"ecmaVersion": 8
66
},
77
"env": {
8-
"es6": true,
9-
"node": true,
10-
"browser": true
11-
},
12-
"rules": {
13-
"no-cond-assign": 0
8+
"browser": true,
9+
"node": true
1410
}
1511
}

.github/eslint.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "eslint-compact",
5+
"pattern": [
6+
{
7+
"regexp": "^(.+):\\sline\\s(\\d+),\\scol\\s(\\d+),\\s(Error|Warning|Info)\\s-\\s(.+)\\s\\((.+)\\)$",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"severity": 4,
12+
"message": 5,
13+
"code": 6
14+
}
15+
]
16+
}
17+
]
18+
}

.github/workflows/node.js.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
2+
3+
name: Node.js CI
4+
5+
on:
6+
push:
7+
branches: [ main ]
8+
pull_request:
9+
branches: [ main ]
10+
11+
jobs:
12+
build:
13+
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version: [14.x]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v1
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
- run: yarn --frozen-lockfile
27+
- run: |
28+
echo ::add-matcher::.github/eslint.json
29+
yarn run eslint src test --format=compact
30+
- run: yarn test

LICENSE

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
1-
Copyright 2010-2016 Mike Bostock
2-
All rights reserved.
3-
4-
Redistribution and use in source and binary forms, with or without modification,
5-
are permitted provided that the following conditions are met:
6-
7-
* Redistributions of source code must retain the above copyright notice, this
8-
list of conditions and the following disclaimer.
9-
10-
* Redistributions in binary form must reproduce the above copyright notice,
11-
this list of conditions and the following disclaimer in the documentation
12-
and/or other materials provided with the distribution.
13-
14-
* Neither the name of the author nor the names of contributors may be used to
15-
endorse or promote products derived from this software without specific prior
16-
written permission.
17-
18-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22-
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25-
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1+
Copyright 2010-2021 Mike Bostock
2+
3+
Permission to use, copy, modify, and/or distribute this software for any purpose
4+
with or without fee is hereby granted, provided that the above copyright notice
5+
and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13+
THIS SOFTWARE.

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@ The axis component renders human-readable reference marks for [scales](https://g
44

55
## Installing
66

7-
If you use NPM, `npm install d3-axis`. Otherwise, download the [latest release](https://github.com/d3/d3-axis/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-axis.v2.min.js) or as part of [D3](https://github.com/d3/d3). (To be useful, you’ll also want to use [d3-scale](https://github.com/d3/d3-scale) and [d3-selection](https://github.com/d3/d3-selection), but these are soft dependencies.) AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:
7+
If you use npm, `npm install d3-axis`. You can also download the [latest release on GitHub](https://github.com/d3/d3-axis/releases/latest). For vanilla HTML in modern browsers, import d3-axis from Skypack:
88

99
```html
10-
<script src="https://d3js.org/d3-axis.v2.min.js"></script>
10+
<script type="module">
11+
12+
import {axisLeft} from "https://cdn.skypack.dev/d3-axis@3";
13+
14+
const axis = axisLeft(scale);
15+
16+
</script>
17+
```
18+
19+
For legacy environments, you can load d3-axis’s UMD bundle from an npm-based CDN such as jsDelivr; a `d3` global is exported:
20+
21+
```html
22+
<script src="https://cdn.jsdelivr.net/npm/d3-axis@3"></script>
1123
<script>
1224
13-
var axis = d3.axisLeft(scale);
25+
const axis = d3.axisLeft(scale);
1426
1527
</script>
1628
```

d3-axis.sublime-project

Lines changed: 0 additions & 17 deletions
This file was deleted.

package.json

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,53 @@
22
"name": "d3-axis",
33
"version": "2.1.0",
44
"description": "Displays automatic reference lines for scales.",
5+
"homepage": "https://d3js.org/d3-axis/",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/d3/d3-axis.git"
9+
},
510
"keywords": [
611
"d3",
712
"d3-module",
813
"axis",
914
"scale",
1015
"visualization"
1116
],
12-
"homepage": "https://d3js.org/d3-axis/",
13-
"license": "BSD-3-Clause",
17+
"license": "ISC",
1418
"author": {
1519
"name": "Mike Bostock",
16-
"url": "http://bost.ocks.org/mike"
17-
},
18-
"main": "dist/d3-axis.js",
19-
"unpkg": "dist/d3-axis.min.js",
20-
"jsdelivr": "dist/d3-axis.min.js",
21-
"module": "src/index.js",
22-
"repository": {
23-
"type": "git",
24-
"url": "https://github.com/d3/d3-axis.git"
20+
"url": "https://bost.ocks.org/mike"
2521
},
22+
"type": "module",
2623
"files": [
2724
"dist/**/*.js",
2825
"src/**/*.js"
2926
],
30-
"scripts": {
31-
"pretest": "rollup -c",
32-
"test": "tape 'test/**/*-test.js' && eslint src test",
33-
"prepublishOnly": "rm -rf dist && yarn test",
34-
"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"
27+
"module": "src/index.js",
28+
"main": "src/index.js",
29+
"jsdelivr": "dist/d3-axis.min.js",
30+
"unpkg": "dist/d3-axis.min.js",
31+
"exports": {
32+
"umd": "./dist/d3-axis.min.js",
33+
"default": "./src/index.js"
3534
},
3635
"sideEffects": false,
3736
"devDependencies": {
38-
"d3-scale": "2 - 3",
39-
"d3-selection": "1 - 2",
37+
"d3-scale": "2 - 4",
38+
"d3-selection": "1 - 3",
4039
"eslint": "7",
40+
"js-beautify": "1",
4141
"jsdom": "16",
42+
"mocha": "9",
4243
"rollup": "2",
43-
"rollup-plugin-terser": "7",
44-
"tape": "4"
44+
"rollup-plugin-terser": "7"
45+
},
46+
"scripts": {
47+
"test": "mocha 'test/**/*-test.js' && eslint src test",
48+
"prepublishOnly": "rm -rf dist && yarn test && rollup -c && git push",
49+
"postpublish": "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 -"
50+
},
51+
"engines": {
52+
"node": ">=12"
4553
}
4654
}

rollup.config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
import {readFileSync} from "fs";
12
import {terser} from "rollup-plugin-terser";
23
import * as meta from "./package.json";
34

5+
// Extract copyrights from the LICENSE.
6+
const copyright = readFileSync("./LICENSE", "utf-8")
7+
.split(/\n/g)
8+
.filter(line => /^Copyright\s+/.test(line))
9+
.map(line => line.replace(/^Copyright\s+/, ""))
10+
.join(", ");
11+
412
const config = {
513
input: "src/index.js",
614
external: Object.keys(meta.dependencies || {}).filter(key => /^d3-/.test(key)),
@@ -10,7 +18,7 @@ const config = {
1018
format: "umd",
1119
indent: false,
1220
extend: true,
13-
banner: `// ${meta.homepage} v${meta.version} Copyright ${(new Date).getFullYear()} ${meta.author.name}`,
21+
banner: `// ${meta.homepage} v${meta.version} Copyright ${copyright}`,
1422
globals: Object.assign({}, ...Object.keys(meta.dependencies || {}).filter(key => /^d3-/.test(key)).map(key => ({[key]: "d3"})))
1523
},
1624
plugins: []

test/.eslintrc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"parserOptions": {
4+
"sourceType": "module",
5+
"ecmaVersion": 8
6+
},
7+
"env": {
8+
"browser": true,
9+
"node": true,
10+
"mocha": true
11+
}
12+
}

test/axis-left-500.html

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)