Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Feb 11, 2025
1 parent 2d9f1ac commit 5ca4023
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 200 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ delete globals.browser['AudioWorkletGlobalScope '];
*/
export default [
{
ignores: ['build/**', 'coverage/**']
ignores: ['node_modules', 'build/**', 'coverage/**']
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
Expand Down
5 changes: 4 additions & 1 deletion examples/examples.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Ajv, ErrorObject} from 'ajv';
import addFormats from 'ajv-formats';
import draft6Schema from 'ajv/lib/refs/json-schema-draft-06.json';
import fs from 'fs';
import path from 'path';
Expand All @@ -11,6 +10,10 @@ import * as log from '../src/log/index.js';
import {TopLevelSpec} from '../src/spec/index.js';
import {duplicate} from '../src/util.js';

// Workaround for https://github.com/ajv-validator/ajv-formats/issues/85
import _addFormats from 'ajv-formats';
const addFormats = _addFormats as unknown as typeof _addFormats.default;

// import {inspect} from 'util';

const ajv = new Ajv({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"build:examples-full": "TZ=America/Los_Angeles scripts/build-examples.sh 1",
"build:example": "TZ=America/Los_Angeles scripts/build-example.sh",
"build:toc": "yarn build:jekyll && scripts/generate-toc",
"build:site": "rollup -c site/rollup.config.mjs",
"build:site": "rollup -c site/rollup.config.js",
"build:jekyll": "pushd site && bundle exec jekyll build -q && popd",
"build:versions": "scripts/update-version.sh",
"clean": "yarn clean:build && del-cli 'site/data/*' 'examples/compiled/*.png' && find site/examples ! -name 'index.md' ! -name 'data' -type f -delete",
Expand Down
88 changes: 88 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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'};

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

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.');
}
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?');
}
return null;
}
};
}

const outputs = [
{
input: 'src/index.ts',
output: {
file: pkg.exports.default,
format: 'esm',
sourcemap: true
},
plugins: [
nodeResolve({browser: true, extensions}),
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'
}
}),
nodeResolve({browser: true, extensions}),
commonjs(),
json(),
typescript({
tsconfig: './tsconfig.build.json'
}),
terser(),
bundleSize()
],
external: ['vega']
}
];

export default outputs;
86 changes: 0 additions & 86 deletions rollup.config.mjs

This file was deleted.

30 changes: 15 additions & 15 deletions scripts/build-normalized-example
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node
'use strict';

/*
* This script normalizes the given spec in examples/specs and
Expand All @@ -9,19 +8,20 @@
* redundant Vega output specs.
*/

const fs = require('fs');
const vl = require('../build/vega-lite');
const stableStringify = require('fast-json-stable-stringify');
const compactStringify = require('json-stringify-pretty-compact');
import fs from "fs";
import vl from "../build/vega-lite/index.js";
import stableStringify from "fast-json-stable-stringify";
import compactStringify from "json-stringify-pretty-compact";
import yargs from "yargs";

const args = require('yargs').demand(0).argv;
const args = yargs.demand(0).argv;

const DIR = __dirname + '/..';
const SPECS = '/examples/specs';
const DIR = import.meta.dirname + "/..";
const SPECS = "/examples/specs";

const example = args._[0] || '/dev/stdin';
if (example && example.includes('.vl.json')) {
const path = DIR + SPECS + '/' + example;
const example = args._[0] || "/dev/stdin";
if (example?.includes(".vl.json")) {
const path = DIR + SPECS + "/" + example;
const spec = JSON.parse(fs.readFileSync(path));

const preNormalized = stableStringify(spec);
Expand All @@ -32,11 +32,11 @@ if (example && example.includes('.vl.json')) {
if (preNormalized !== postNormalized) {
const postNormalizedOutput = compactStringify(fullSpec);
// -8 is cutting .vl.json
const newFilename = example.slice(0, -8) + '_normalized.vl.json';
const newFilenameAndPath = DIR + SPECS + '/normalized/' + newFilename;
fs.writeFile(newFilenameAndPath, postNormalizedOutput, err => {
const newFilename = example.slice(0, -8) + "_normalized.vl.json";
const newFilenameAndPath = DIR + SPECS + "/normalized/" + newFilename;
fs.writeFile(newFilenameAndPath, postNormalizedOutput, (err) => {
if (err) return console.log(err);
console.log('Built:', newFilename);
console.log("Built:", newFilename);
});
}
}
20 changes: 10 additions & 10 deletions scripts/build-normalized-examples
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
'use strict';
"use strict";

/*
* This script normalizes all the specs in examples/specs and
Expand All @@ -9,18 +9,18 @@
* redundant Vega output specs.
*/

const fs = require('fs');
const vl = require('../build/vega-lite');
const stableStringify = require('fast-json-stable-stringify');
const fs = require("fs");
const vl = require("../build/vega-lite");
const stableStringify = require("fast-json-stable-stringify");

const DIR = __dirname + '/..';
const SPECS = '/examples/specs';
const DIR = import.meta.dirname + "/..";
const SPECS = "/examples/specs";
const examples = fs.readdirSync(DIR + SPECS);

async function main() {
const {default: compactStringify} = await import('json-stringify-pretty-compact');
const { default: compactStringify } = await import("json-stringify-pretty-compact");

const vlExamples = examples.filter(example => example.includes('.vl.json'));
const vlExamples = examples.filter((example) => example.includes(".vl.json"));
for (const example of vlExamples) {
const path = `${DIR + SPECS}/${example}`;
const spec = JSON.parse(fs.readFileSync(path));
Expand All @@ -31,9 +31,9 @@ async function main() {

// console.log(preNormalized, postNormalized);
if (preNormalized !== postNormalized) {
const postNormalizedOutput = compactStringify(fullSpec, {indent: 2});
const postNormalizedOutput = compactStringify(fullSpec, { indent: 2 });
// -8 is cutting .vl.json
const newFilename = example.slice(0, -8) + '_normalized.vl.json';
const newFilename = example.slice(0, -8) + "_normalized.vl.json";
const newFilenameAndPath = `${DIR + SPECS}/normalized/${newFilename}`;
fs.writeFileSync(newFilenameAndPath, postNormalizedOutput);
}
Expand Down
11 changes: 5 additions & 6 deletions scripts/create-example-pages
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
#!/usr/bin/env node
'use strict';

/**
* This script creates pages for all examples for the website.
*/

const fs = require('fs');
const examples = require('../site/_data/examples.json');
import fs from "fs";
import examples from "../site/_data/examples.json" with { type: "json" };

function createPage(example) {
return `---
layout: page
${example.description ? `description: "${example.description.replace(/"/g, '\\"')}"` : ''}
${example.description ? `description: "${example.description.replace(/"/g, '\\"')}"` : ""}
title: ${example.title}
menu: examples
permalink: /examples/${example.name}.html
image: /examples/${example.name}.png
edit_path: _data/examples.json
---
${example.description || ''}
${example.description || ""}
{% include example.html spec='${example.name}'%}
`;
Expand All @@ -30,7 +29,7 @@ for (const category of Object.keys(examples)) {
for (const example of examples[category][subcategory]) {
const name = example.name;

console.log('Processing', name);
console.log("Processing", name);

const fileContent = fs.readFileSync(`examples/specs/${name}.vl.json`);

Expand Down
Loading

0 comments on commit 5ca4023

Please sign in to comment.