Skip to content

Commit 8fc14d0

Browse files
Filmbostock
andauthored
Adopt type=module (#37)
* Adopt type=module follow changes in d3-format: * type=module * add exports * remove zip * license: ISC * update dependencies * reinstate colorbrewer license * related d3/d3#3502; extract copyrights from LICENSE * remove Sublime project * add eslint.json * update dependencies * update homepage * Update README Co-authored-by: Mike Bostock <[email protected]>
1 parent 90e7c02 commit 8fc14d0

11 files changed

+924
-777
lines changed

.eslintrc.json

-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,5 @@
33
"parserOptions": {
44
"sourceType": "module",
55
"ecmaVersion": 8
6-
},
7-
"env": {
8-
"es6": true,
9-
"node": true,
10-
"browser": true
11-
},
12-
"rules": {
13-
"no-cond-assign": 0
146
}
157
}

.github/eslint.json

+18
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

+30
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

+14-30
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
1-
Copyright 2010-2018 Mike Bostock
2-
All rights reserved.
1+
Copyright 2010-2021 Mike Bostock
32

4-
Redistribution and use in source and binary forms, with or without modification,
5-
are permitted provided that the following conditions are met:
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.
66

7-
* Redistributions of source code must retain the above copyright notice, this
8-
list of conditions and the following disclaimer.
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.
914

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.
15+
Apache-Style Software License for ColorBrewer software and ColorBrewer Color Schemes
1316

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.
28-
29-
Apache-Style Software License for ColorBrewer software and ColorBrewer Color
30-
Schemes
31-
32-
Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State
33-
University.
17+
Copyright 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State University
3418

3519
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
36-
this file except in compliance with the License. You may obtain a copy of the
20+
this file except in compliance with the License. You may obtain a copy of the
3721
License at
3822

3923
http://www.apache.org/licenses/LICENSE-2.0

README.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,31 @@ var piyg = d3.scaleSequential(d3.interpolatePiYG);
2222

2323
## Installing
2424

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

2727
```html
28-
<script src="https://d3js.org/d3-color.v2.min.js"></script>
29-
<script src="https://d3js.org/d3-interpolate.v2.min.js"></script>
30-
<script src="https://d3js.org/d3-scale-chromatic.v2.min.js"></script>
31-
<script>
28+
<script type="module">
29+
30+
import {interpolateYlGn} from "https://cdn.skypack.dev/d3-scale-chromatic@3";
3231
33-
var yellow = d3.interpolateYlGn(0), // "rgb(255, 255, 229)"
34-
yellowGreen = d3.interpolateYlGn(0.5), // "rgb(120, 197, 120)"
35-
green = d3.interpolateYlGn(1); // "rgb(0, 69, 41)"
32+
const yellow = interpolateYlGn(0); // "rgb(255, 255, 229)"
33+
const yellowGreen = interpolateYlGn(0.5); // "rgb(120, 197, 120)"
34+
const green = interpolateYlGn(1); // "rgb(0, 69, 41)"
3635
3736
</script>
3837
```
3938

40-
Or, as part of the [D3 default bundle](https://github.com/d3/d3):
39+
For legacy environments, you can load d3-scale-chromatic’s UMD bundle from an npm-based CDN such as jsDelivr; a `d3` global is exported:
4140

4241
```html
43-
<script src="https://d3js.org/d3.v6.min.js"></script>
42+
<script src="https://cdn.jsdelivr.net/npm/d3-color@3"></script>
43+
<script src="https://cdn.jsdelivr.net/npm/d3-interpolate@3"></script>
44+
<script src="https://cdn.jsdelivr.net/npm/d3-scale-chromatic@3"></script>
4445
<script>
4546
46-
var yellow = d3.interpolateYlGn(0), // "rgb(255, 255, 229)"
47-
yellowGreen = d3.interpolateYlGn(0.5), // "rgb(120, 197, 120)"
48-
green = d3.interpolateYlGn(1); // "rgb(0, 69, 41)"
47+
const yellow = d3.interpolateYlGn(0); // "rgb(255, 255, 229)"
48+
const yellowGreen = d3.interpolateYlGn(0.5); // "rgb(120, 197, 120)"
49+
const green = d3.interpolateYlGn(1); // "rgb(0, 69, 41)"
4950
5051
</script>
5152
```

d3-scale-chromatic.sublime-project

-17
This file was deleted.

package.json

+30-23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
"name": "d3-scale-chromatic",
33
"version": "2.0.0",
44
"description": "Sequential, diverging and categorical color schemes.",
5+
"homepage": "https://d3js.org/d3-scale-chromatic/",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/d3/d3-scale-chromatic.git"
9+
},
510
"keywords": [
611
"d3",
712
"d3-module",
@@ -10,39 +15,41 @@
1015
"sequential",
1116
"colorbrewer"
1217
],
13-
"homepage": "https://d3js.org/d3-scale-chromatic/",
14-
"license": "BSD-3-Clause",
18+
"license": "ISC",
1519
"author": {
1620
"name": "Mike Bostock",
17-
"url": "http://bost.ocks.org/mike"
18-
},
19-
"main": "dist/d3-scale-chromatic.js",
20-
"unpkg": "dist/d3-scale-chromatic.min.js",
21-
"jsdelivr": "dist/d3-scale-chromatic.min.js",
22-
"module": "src/index.js",
23-
"repository": {
24-
"type": "git",
25-
"url": "https://github.com/d3/d3-scale-chromatic.git"
21+
"url": "https://bost.ocks.org/mike"
2622
},
23+
"type": "module",
2724
"files": [
2825
"dist/**/*.js",
2926
"src/**/*.js"
3027
],
31-
"sideEffects": false,
32-
"scripts": {
33-
"pretest": "rollup -c",
34-
"test": "tape 'test/**/*-test.js' && eslint src",
35-
"prepublishOnly": "rm -rf dist && yarn test",
36-
"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"
28+
"module": "src/index.js",
29+
"main": "src/index.js",
30+
"jsdelivr": "dist/d3-scale-chromatic.min.js",
31+
"unpkg": "dist/d3-scale-chromatic.min.js",
32+
"exports": {
33+
"umd": "./dist/d3-scale-chromatic.min.js",
34+
"default": "./src/index.js"
3735
},
36+
"sideEffects": false,
3837
"dependencies": {
39-
"d3-color": "1 - 2",
40-
"d3-interpolate": "1 - 2"
38+
"d3-color": "1 - 3",
39+
"d3-interpolate": "1 - 3"
4140
},
4241
"devDependencies": {
43-
"eslint": "6",
44-
"rollup": "1",
45-
"rollup-plugin-terser": "5",
46-
"tape": "4"
42+
"eslint": "7",
43+
"mocha": "8",
44+
"rollup": "2",
45+
"rollup-plugin-terser": "7"
46+
},
47+
"scripts": {
48+
"test": "mocha 'test/**/*-test.js' && eslint src test",
49+
"prepublishOnly": "rm -rf dist && yarn test && rollup -c",
50+
"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 -"
51+
},
52+
"engines": {
53+
"node": ">=12"
4754
}
4855
}

rollup.config.js

+9-1
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

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"parserOptions": {
4+
"sourceType": "module",
5+
"ecmaVersion": 8
6+
},
7+
"env": {
8+
"mocha": true
9+
}
10+
}

test/index-test.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var tape = require("tape"),
2-
d3 = require("../");
1+
import assert from "assert";
2+
import * as d3 from "../src/index.js";
33

4-
tape("exports the expected schemes", function(test) {
5-
test.deepEqual(Object.keys(d3).sort(), [
4+
it("exports the expected schemes", () => {
5+
assert.deepStrictEqual(Object.keys(d3).sort(), [
66
"interpolateBlues",
77
"interpolateBrBG",
88
"interpolateBuGn",
@@ -79,5 +79,4 @@ tape("exports the expected schemes", function(test) {
7979
"schemeYlOrBr",
8080
"schemeYlOrRd"
8181
]);
82-
test.end();
8382
});

0 commit comments

Comments
 (0)