Skip to content

Commit

Permalink
feat!: esm only package
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Feb 11, 2025
1 parent 9325b67 commit 03b1908
Show file tree
Hide file tree
Showing 10 changed files with 635 additions and 443 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
92 changes: 92 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import tsParser from '@typescript-eslint/parser';
import prettierConfig from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import vitest from 'eslint-plugin-vitest';

delete globals.browser['AudioWorkletGlobalScope '];

/**
* @type {import('eslint').Linter.Config[]}
*/
export default [
{
ignores: ['build/**', 'coverage/**'],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: './tsconfig.eslint.json',
tsconfigRootDir: import.meta.dirname,
},
},
},
{
files: ['**/*.ts'],
plugins: {
vitest,
},
languageOptions: {
parser: tsParser,
globals: {
...globals.browser,
},
},
settings: {
vitest: {
typecheck: true,
},
},
rules: {
...vitest.configs.recommended.rules,
'prettier/prettier': 'warn',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
vars: 'all',
args: 'after-used',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-base-to-string': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'linebreak-style': ['error', 'unix'],
'no-irregular-whitespace': ['error', {skipComments: true}],
'no-alert': 'error',
'prefer-const': 'error',
'no-return-assign': 'error',
'no-useless-call': 'error',
'no-useless-concat': 'error',
'prefer-template': 'error',
'no-unused-vars': 'off',
// "no-undef": "off", // typescript takes care of this for us
'no-unreachable': 'off', // typescript takes care of this for us
},
},
prettierConfig,
{
files: ['**/*.js'],
...tseslint.configs.disableTypeChecked,
},
];
39 changes: 18 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
"chart",
"visualization"
],
"main": "build/vega-lite.js",
"unpkg": "build/vega-lite.min.js",
"jsdelivr": "build/vega-lite.min.js",
"module": "build/src/index",
"types": "build/src/index.d.ts",
"type": "module",
"exports": {
"types": "./build/index.d.ts",
"default": "./build/index.js"
},
"unpkg": "build/vega-embed.min.js",
"jsdelivr": "build/vega-embed.min.js",
"bin": {
"vl2pdf": "./bin/vl2pdf",
"vl2png": "./bin/vl2png",
Expand All @@ -37,7 +39,7 @@
"changelog": "conventional-changelog -p angular -r 2",
"prebuild": "yarn clean:build",
"build": "yarn build:only",
"build:only": "tsc -p tsconfig.build.json && rollup -c",
"build:only": "rollup -c",
"prebuild:examples": "yarn build:only",
"build:examples": "yarn data && TZ=America/Los_Angeles scripts/build-examples.sh",
"prebuild:examples-full": "yarn build:only",
Expand Down Expand Up @@ -79,45 +81,42 @@
"url": "https://github.com/vega/vega-lite/issues"
},
"devDependencies": {
"@babel/core": "^7.26.7",
"@babel/preset-env": "^7.26.7",
"@babel/preset-typescript": "^7.26.0",
"@release-it/conventional-changelog": "^10.0.0",
"@rollup/plugin-alias": "^5.1.1",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^28.0.2",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.2",
"@types/d3": "^7.4.3",
"@types/jest": "^29.5.14",
"@types/node": "^22.12.0",
"@types/node": "^22.13.1",
"@types/pako": "^2.0.3",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"@typescript-eslint/eslint-plugin": "^8.24.0",
"@typescript-eslint/parser": "^8.24.0",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"cheerio": "^1.0.0",
"conventional-changelog-cli": "^5.0.0",
"d3": "^7.9.0",
"del-cli": "^6.0.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint": "^9.20.1",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-jest": "^28.11.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-prettier": "^5.2.3",
"fast-json-stable-stringify": "~2.1.0",
"highlight.js": "^11.11.1",
"jest": "^29.7.0",
"jest-dev-server": "^11.0.0",
"mkdirp": "^3.0.1",
"pako": "^2.1.0",
"prettier": "^3.4.2",
"prettier": "^3.5.0",
"puppeteer": "^15.0.0",
"release-it": "18.1.2",
"rollup": "^4.32.1",
"rollup": "^4.34.6",
"rollup-plugin-bundle-size": "^1.0.3",
"serve": "^14.2.4",
"terser": "^5.37.0",
"terser": "^5.38.2",
"ts-jest": "^29.2.5",
"ts-json-schema-generator": "^2.3.0",
"typescript": "~5.7.3",
Expand All @@ -133,8 +132,6 @@
"vega-event-selector": "~3.0.1",
"vega-expression": "~5.1.2",
"vega-util": "~1.17.3",
"vega-expression": "~5.1.2",
"vega-util": "~1.17.3",
"yargs": "~17.7.2"
},
"peerDependencies": {
Expand Down
21 changes: 21 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @see https://prettier.io/docs/en/configuration.html
* @type {import("prettier").Config}
*/
const config = {
printWidth: 120,
proseWrap: 'never',
overrides: [
{
files: '*.{js,jsx,ts,tsx}',
options: {
bracketSpacing: false,
singleQuote: true,
arrowParens: 'avoid',
trailingComma: 'none',
},
},
],
};

export default config;
113 changes: 55 additions & 58 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,89 +1,86 @@
import alias from '@rollup/plugin-alias';
import babel from '@rollup/plugin-babel';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import bundleSize from 'rollup-plugin-bundle-size';
import alias from "@rollup/plugin-alias";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import nodeResolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import bundleSize from "rollup-plugin-bundle-size";

import pkg from './package.json' with {type: 'json'};
import pkg from "./package.json" with { type: "json" };

export function disallowedImports() {
return {
resolveId: module => {
if (['vega', 'util', 'd3'].includes(module)) {
throw new Error('Cannot import from Vega, Node Util, or D3 in Vega-Lite.');
resolveId: (module) => {
if (["vega", "util", "d3"].includes(module)) {
throw new Error("Cannot import from Vega, Node Util, or D3 in Vega-Lite.");
}
return null;
}
},
};
}

export function debugImports() {
return {
resolveId: module => {
if (module === 'pako') {
throw new Error('Do not import pako in builds. Did you forget to remove drawDataflow?');
resolveId: (module) => {
if (module === "pako") {
throw new Error("Do not import pako in builds. Did you forget to remove drawDataflow?");
}
return null;
}
},
};
}

const extensions = ['.js', '.ts'];

const globals = {
vega: 'vega'
};

const outputs = [
{
input: 'src/index.ts',
output: [
{
file: pkg.main,
format: 'umd',
sourcemap: true,
name: 'vegaLite',
globals
},
{
file: pkg.unpkg,
format: 'umd',
sourcemap: true,
name: 'vegaLite',
plugins: [terser()],
globals
}
input: "src/index.ts",
output: {
file: pkg.exports.default,
format: "esm",
sourcemap: true,
},
plugins: [
nodeResolve(),
commonjs(),
json(),
typescript({
tsconfig: "./tsconfig.build.json",
}),
bundleSize(),
],
external: [...Object.keys(pkg.dependencies), ...Object.keys(pkg.peerDependencies)],
},
{
input: "src/index.ts",
output: {
file: pkg.unpkg,
format: "umd",
name: "vegaLite",
sourcemap: true,
globals: {
vega: "vega",
},
},
plugins: [
disallowedImports(),
debugImports(),
alias({
entries: {
'vega-event-selector': 'vega',
'vega-expression': 'vega',
'vega-util': 'vega'
}
"vega-event-selector": "vega",
"vega-expression": "vega",
"vega-util": "vega",
},
}),
resolve({browser: true, extensions}),
nodeResolve(),
commonjs(),
json(),
babel({
extensions,
babelHelpers: 'bundled',
presets: [
[
'@babel/env',
{
targets: 'defaults'
}
],
'@babel/typescript'
]
typescript({
tsconfig: "./tsconfig.build.json",
}),
bundleSize()
terser(),
bundleSize(),
],
external: ['vega']
}
external: ["vega"],
},
];

export default outputs;
1 change: 0 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "build",
"noEmit": false,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
Expand Down
7 changes: 3 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "Node",

"target": "ES2022",
"module": "Node16",
"moduleResolution": "Node16",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
Expand Down
Loading

0 comments on commit 03b1908

Please sign in to comment.