Skip to content

Commit

Permalink
Merge upstream neuroglancer
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Kanzer authored and Aaron Kanzer committed Jan 16, 2025
2 parents 9afa653 + 7782f2c commit bac1a1d
Show file tree
Hide file tree
Showing 302 changed files with 41,496 additions and 23,389 deletions.
16 changes: 0 additions & 16 deletions .eslintignore

This file was deleted.

68 changes: 0 additions & 68 deletions .eslintrc.yml

This file was deleted.

15 changes: 11 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ on:
tags:
- v**
pull_request:
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: "Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)"
required: false
default: false

jobs:
client:
Expand Down Expand Up @@ -97,12 +104,12 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# Uncomment the action below for an interactive shell
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
- uses: ./.github/actions/setup-firefox
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
- name: Install Python packaging/test tools
run: pip install tox nox wheel numpy -r python/requirements-test.txt
- uses: ./.github/actions/setup-firefox
- run: nox -s lint format mypy
- name: Check for dirty working directory
run: git diff --exit-code
Expand Down
5 changes: 5 additions & 0 deletions .ncurc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
reject:
# API break
- "gl-matrix"
- "@types/gl-matrix"
- "codemirror"
6 changes: 3 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ prune examples
exclude .clang-format
exclude .editorconfig
exclude .eslintignore
exclude .eslintrc
exclude .style.yapf
exclude cors_webserver.py
exclude gulpfile.js
Expand All @@ -36,8 +35,9 @@ exclude MANIFEST.in
exclude *.ts
exclude .prettierrc.yml
exclude .prettierignore
exclude .eslintrc.yml
exclude eslint.config.js
exclude .ncurc.yml
exclude index.html
exclude webpack.config.js
exclude rspack.config.js
exclude firebase.json
exclude .firebaserc
15 changes: 12 additions & 3 deletions build_tools/after-version-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@ await Promise.all(
await execFileAsync("npm", ["install", "--no-audit", "--no-fund"], {
cwd: exampleDir,
});
await execFileAsync("git", ["add", "package-lock.json"], {
cwd: exampleDir,
});
}),
);

await execFileAsync(
"git",
[
"add",
...(await glob("examples/*/*/package-lock.json", {
absolute: false,
cwd: rootDir,
})),
],
{ cwd: rootDir },
);
28 changes: 21 additions & 7 deletions build_tools/build-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ function buildDeclarationFiles(
program.emit();
}

async function buildPackage(options: { inplace?: boolean }) {
const { inplace = false } = options;
async function buildPackage(options: {
inplace?: boolean;
skipDeclarations?: boolean;
}) {
const { inplace = false, skipDeclarations = false } = options;

const srcDir = path.resolve(rootDir, "src");
const outDir = inplace ? rootDir : path.resolve(rootDir, "dist", "package");
Expand Down Expand Up @@ -80,10 +83,12 @@ async function buildPackage(options: { inplace?: boolean }) {
"./",
).options;
}
buildDeclarationFiles(entryPoints, {
...compilerOptionsFromConfigFile,
outDir: libDir,
});
if (!skipDeclarations) {
buildDeclarationFiles(entryPoints, {
...compilerOptionsFromConfigFile,
outDir: libDir,
});
}

const otherSources = await glob(["**/*.{css,js,html,wasm}"], {
cwd: srcDir,
Expand Down Expand Up @@ -117,6 +122,7 @@ async function buildPackage(options: { inplace?: boolean }) {
const { postpack } = packageJson["scripts"];
delete packageJson["scripts"];
packageJson["scripts"] = { postpack };
packageJson["files"] = ["lib/**/*"];
} else {
delete packageJson["private"];
packageJson["scripts"] = {};
Expand Down Expand Up @@ -156,6 +162,11 @@ async function parseArgsAndRunMain() {
default: false,
description: "Convert package to built format inplace.",
},
["skip-declarations"]: {
type: "boolean",
default: false,
description: "Skip generating .d.ts files.",
},
["if-not-toplevel"]: {
type: "boolean",
default: false,
Expand Down Expand Up @@ -193,7 +204,10 @@ async function parseArgsAndRunMain() {
return;
}
}
buildPackage({ inplace: argv.inplace });
buildPackage({
inplace: argv.inplace,
skipDeclarations: argv.skipDeclarations,
});
}

if (process.argv[1] === import.meta.filename) {
Expand Down
38 changes: 18 additions & 20 deletions build_tools/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@

// Command-line interface for building Neuroglancer.

/// <reference types="webpack-dev-server" />

import process from "node:process";
import { pathToFileURL } from "node:url";
import path from "path";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import type { Configuration } from "webpack";
import webpackCli from "webpack-cli/lib/bootstrap.js"; // eslint-disable-line import/default
import { RspackCLI } from "@rspack/cli";
import type { Configuration } from "@rspack/core";
import ESLintPlugin from "eslint-rspack-plugin";
import { TsCheckerRspackPlugin } from "ts-checker-rspack-plugin";
import * as webpackMerge from "webpack-merge";
import yargs from "yargs";
import { normalizeConfigurationWithDefine } from "./webpack/configuration_with_define.js";
import { setConfig } from "./webpack/webpack_config_from_cli.cjs";
import { normalizeConfigurationWithDefine } from "./rspack/configuration_with_define.js";
import { setConfig } from "./rspack/rspack_config_from_cli.js";

export interface WebpackConfigurationWithDefine extends Configuration {
define?: Record<string, any> | undefined;
Expand Down Expand Up @@ -81,7 +80,7 @@ async function getWebpackConfig(
...extraConfigs: WebpackConfigurationWithDefine[]
): Promise<(...args: any[]) => Configuration> {
const configPaths = [
pathToFileURL(path.resolve(import.meta.dirname, "../webpack.config.js"))
pathToFileURL(path.resolve(import.meta.dirname, "../rspack.config.js"))
.href,
...argv.config.map((configPath) => pathToFileURL(configPath).href),
];
Expand Down Expand Up @@ -109,15 +108,15 @@ async function getWebpackConfig(
outDir = path.resolve(outDir);
}
const plugins = [];
if (argv.typecheck || argv.lint) {
if (argv.typecheck) {
plugins.push(new TsCheckerRspackPlugin());
}
if (argv.lint) {
plugins.push(
new ForkTsCheckerWebpackPlugin({
typescript: argv.typecheck,
eslint: argv.lint
? {
files: ".",
}
: undefined,
new ESLintPlugin({
configType: "flat",
files: ".",
threads: true,
}),
);
}
Expand All @@ -141,12 +140,11 @@ async function getWebpackConfig(
}

async function runWebpack(...args: string[]) {
// @ts-expect-error: no typings available
await webpackCli([
await new RspackCLI().run([
...process.argv.slice(0, 2),
...args,
"--config",
path.resolve(import.meta.dirname, "webpack", "webpack_config_from_cli.cjs"),
path.resolve(import.meta.dirname, "rspack", "rspack_config_from_cli.js"),
]);
}

Expand Down Expand Up @@ -211,7 +209,7 @@ function parseArgs() {
group: "Development server options",
type: "number",
nargs: 1,
default: 8080,
default: 0,
description: "Port number for the development server",
},
host: {
Expand Down
33 changes: 21 additions & 12 deletions config/generate-code.ts → build_tools/generate-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
* limitations under the License.
*/

"use strict";
import fs from "node:fs";
import path from "node:path";
import nunjucks from "nunjucks";

const nunjucks = require("nunjucks");
const fs = require("fs");
const path = require("path");

const rootDir = path.resolve(__dirname, "..");
const srcDir = path.resolve(rootDir, "src");
const rootDir = path.resolve(import.meta.dirname, "..");
const templatesDir = path.resolve(rootDir, "templates");

const env = nunjucks.configure(rootDir, {
Expand All @@ -34,15 +31,23 @@ const env = nunjucks.configure(rootDir, {
},
});

function writeGenerated(sourcePath, outputPath, contents) {
function writeGenerated(
sourcePath: string,
outputPath: string,
contents: string,
) {
fs.writeFileSync(
path.resolve(rootDir, "src", outputPath),
`// DO NOT EDIT. Generated from templates/${sourcePath}.
` + contents,
);
}

function renderTemplate(sourcePath, outputPath, context) {
function renderTemplate(
sourcePath: string,
outputPath: string,
context: Record<string, string | number>,
) {
writeGenerated(
sourcePath,
outputPath,
Expand All @@ -58,7 +63,7 @@ function writeSegmentationCompression() {
{},
);
for (const dataType of ["uint64", "uint32"]) {
const context = {
const context: Record<string, string | number> = {
dataType,
strideMultiplier: dataType === "uint64" ? 2 : 1,
};
Expand All @@ -72,7 +77,11 @@ function writeSegmentationCompression() {
}
}

function makeSubstitutions(inputPath, outputPath, replacements) {
function makeSubstitutions(
inputPath: string,
outputPath: string,
replacements: [string | RegExp, string][],
) {
let inputContents = fs.readFileSync(path.resolve(templatesDir, inputPath), {
encoding: "utf-8",
});
Expand Down Expand Up @@ -107,7 +116,7 @@ function writeDataStructures() {
const nextPrevReplacements = [
[/NEXT_PROPERTY/g, `next${i}`],
[/PREV_PROPERTY/g, `prev${i}`],
];
] as [string | RegExp, string][];
makeSubstitutions(
path.join(baseDir, "linked_list.template.ts"),
path.join(baseDir, `linked_list.${i}.ts`),
Expand Down
Loading

0 comments on commit bac1a1d

Please sign in to comment.