mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-11 16:18:11 +00:00
Migrate to esbuild
This commit is contained in:
parent
76e7508024
commit
810ed7a3d1
5
.changeset/esbuild.md
Normal file
5
.changeset/esbuild.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@jspsych/config": major
|
||||
---
|
||||
|
||||
Migrate the build chain from TypeScript, Babel, and Terser to [esbuild](https://esbuild.github.io/). Babel and Terser are no longer included as dependencies and the Babel configuration at `@jspsych/config/babel` has been removed. The minified browser builds are only transpiled down to [ES2015](https://caniuse.com/es6) now.
|
2666
package-lock.json
generated
2666
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -4,10 +4,6 @@
|
||||
"description": "Shared (build) configuration for jsPsych packages",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./babel": {
|
||||
"import": null,
|
||||
"require": "./babel.cjs"
|
||||
},
|
||||
"./gulp": {
|
||||
"import": "./gulp.js",
|
||||
"require": null
|
||||
@ -39,20 +35,15 @@
|
||||
},
|
||||
"homepage": "https://www.jspsych.org/latest/developers/configuration",
|
||||
"dependencies": {
|
||||
"@babel/cli": "7.17.10",
|
||||
"@babel/core": "7.17.10",
|
||||
"@babel/preset-env": "7.17.10",
|
||||
"@rollup/plugin-babel": "5.3.1",
|
||||
"@rollup/plugin-commonjs": "22.0.0",
|
||||
"@rollup/plugin-json": "4.1.0",
|
||||
"@rollup/plugin-node-resolve": "13.3.0",
|
||||
"@rollup/plugin-replace": "4.0.0",
|
||||
"@rollup/plugin-commonjs": "23.0.2",
|
||||
"@rollup/plugin-json": "5.0.1",
|
||||
"@rollup/plugin-node-resolve": "15.0.1",
|
||||
"@sucrase/jest-plugin": "3.0.0",
|
||||
"@types/gulp": "4.0.9",
|
||||
"@types/jest": "29.2.3",
|
||||
"alias-hq": "github:bjoluc/alias-hq#fix-jest-plugin",
|
||||
"babel-preset-minify": "0.5.2",
|
||||
"canvas": "2.9.1",
|
||||
"esbuild": "0.15.14",
|
||||
"gulp": "4.0.2",
|
||||
"gulp-cli": "2.3.0",
|
||||
"gulp-file": "0.4.0",
|
||||
@ -62,10 +53,10 @@
|
||||
"jest": "29.3.1",
|
||||
"jest-environment-jsdom": "29.3.1",
|
||||
"merge-stream": "2.0.0",
|
||||
"regenerator-runtime": "0.13.9",
|
||||
"rollup": "2.73.0",
|
||||
"rollup-plugin-terser": "7.0.2",
|
||||
"rollup-plugin-typescript2": "0.31.2",
|
||||
"rollup": "3.3.0",
|
||||
"rollup-plugin-dts": "5.0.0",
|
||||
"rollup-plugin-esbuild": "5.0.0",
|
||||
"rollup-plugin-node-externals": "5.0.2",
|
||||
"sucrase": "3.29.0",
|
||||
"tslib": "2.4.0",
|
||||
"typescript": "4.6.4"
|
||||
|
@ -1,112 +1,120 @@
|
||||
import { DEFAULT_EXTENSIONS as babelDefaultExtensions } from "@babel/core";
|
||||
import { babel } from "@rollup/plugin-babel";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
|
||||
import commonjs from "@rollup/plugin-commonjs";
|
||||
import json from "@rollup/plugin-json";
|
||||
import resolve from "@rollup/plugin-node-resolve";
|
||||
import replace from "@rollup/plugin-replace";
|
||||
import { defineConfig } from "rollup";
|
||||
import { terser } from "rollup-plugin-terser";
|
||||
import typescript from "rollup-plugin-typescript2";
|
||||
import dts from "rollup-plugin-dts";
|
||||
import esbuild from "rollup-plugin-esbuild";
|
||||
import externals from "rollup-plugin-node-externals";
|
||||
import ts from "typescript";
|
||||
|
||||
const getTsCompilerOptions = () => {
|
||||
const cwd = process.cwd();
|
||||
return ts.parseJsonConfigFileContent(
|
||||
ts.readConfigFile(path.join(cwd, "tsconfig.json"), ts.sys.readFile).config,
|
||||
ts.sys,
|
||||
cwd
|
||||
).options;
|
||||
};
|
||||
|
||||
const getPackageInfo = () => {
|
||||
const { name, version } = JSON.parse(readFileSync("./package.json"));
|
||||
return { name, version };
|
||||
};
|
||||
|
||||
const makeConfig = ({
|
||||
outputOptions = {},
|
||||
globalOptions = {},
|
||||
iifeOutputOptions = {},
|
||||
isNodeOnlyBuild = false,
|
||||
}) => {
|
||||
const source = "src/index";
|
||||
const destination = "dist/index";
|
||||
const input = "src/index.ts";
|
||||
const destinationDirectory = "dist";
|
||||
const destination = `${destinationDirectory}/index`;
|
||||
|
||||
outputOptions = {
|
||||
sourcemap: true,
|
||||
...outputOptions,
|
||||
};
|
||||
|
||||
const commonConfig = defineConfig({
|
||||
input: `${source}.ts`,
|
||||
plugins: [
|
||||
resolve({ preferBuiltins: isNodeOnlyBuild }),
|
||||
typescript({
|
||||
typescript: ts,
|
||||
tsconfigDefaults: {
|
||||
exclude: ["./tests", "**/*.spec.ts", "**/*.test.ts", "./dist"],
|
||||
},
|
||||
tsconfigOverride: {
|
||||
// Non-babel builds
|
||||
const config = defineConfig([
|
||||
// Type definitions (bundled as a single .d.ts file)
|
||||
{
|
||||
input,
|
||||
output: [{ file: `${destination}.d.ts`, format: "es" }],
|
||||
plugins: [
|
||||
dts({
|
||||
compilerOptions: {
|
||||
rootDir: "./src",
|
||||
outDir: "./dist",
|
||||
...getTsCompilerOptions(),
|
||||
noEmit: false,
|
||||
paths: {}, // Do not include files referenced via `paths`
|
||||
},
|
||||
},
|
||||
}),
|
||||
json(),
|
||||
commonjs(),
|
||||
],
|
||||
...globalOptions,
|
||||
});
|
||||
|
||||
/** @type {import("rollup").OutputOptions} */
|
||||
const output = [
|
||||
{
|
||||
// Build file to be used as an ES import
|
||||
file: `${destination}.js`,
|
||||
format: "esm",
|
||||
...outputOptions,
|
||||
},
|
||||
{
|
||||
// Build commonjs module (for tools that do not fully support ES6 modules)
|
||||
file: `${destination}.cjs`,
|
||||
format: "cjs",
|
||||
...outputOptions,
|
||||
},
|
||||
];
|
||||
|
||||
if (!isNodeOnlyBuild) {
|
||||
output.push({
|
||||
// Build file to be used for tinkering in modern browsers
|
||||
file: `${destination}.browser.js`,
|
||||
format: "iife",
|
||||
...outputOptions,
|
||||
...iifeOutputOptions,
|
||||
});
|
||||
}
|
||||
|
||||
// Non-babel builds
|
||||
const config = defineConfig([{ ...commonConfig, output }]);
|
||||
|
||||
if (!isNodeOnlyBuild) {
|
||||
// Babel build
|
||||
config.push({
|
||||
...commonConfig,
|
||||
plugins: [
|
||||
// Import `regenerator-runtime` if requested:
|
||||
replace({
|
||||
values: {
|
||||
"// __rollup-babel-import-regenerator-runtime__":
|
||||
'import "regenerator-runtime/runtime.js";',
|
||||
},
|
||||
delimiters: ["", ""],
|
||||
preventAssignment: true,
|
||||
}),
|
||||
...commonConfig.plugins,
|
||||
babel({
|
||||
babelHelpers: "bundled",
|
||||
extends: "@jspsych/config/babel",
|
||||
// https://github.com/ezolenko/rollup-plugin-typescript2#rollupplugin-babel
|
||||
extensions: [...babelDefaultExtensions, ".ts"],
|
||||
}),
|
||||
],
|
||||
},
|
||||
|
||||
// Module builds
|
||||
{
|
||||
...globalOptions,
|
||||
input,
|
||||
plugins: [externals(), json(), esbuild({ target: "node14" }), commonjs()],
|
||||
output: [
|
||||
{
|
||||
// Minified production build file
|
||||
file: `${destination}.browser.min.js`,
|
||||
format: "iife",
|
||||
plugins: [terser()],
|
||||
...outputOptions,
|
||||
...iifeOutputOptions,
|
||||
},
|
||||
{ file: `${destination}.js`, format: "esm", ...outputOptions },
|
||||
{ file: `${destination}.cjs`, format: "cjs", ...outputOptions },
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
if (!isNodeOnlyBuild) {
|
||||
// In builds that are published to NPM (potentially every CI build), point to sourcemaps via the
|
||||
// package's canonical unpkg URL
|
||||
let sourcemapBaseUrl;
|
||||
if (process.env.CI) {
|
||||
const { name, version } = getPackageInfo();
|
||||
sourcemapBaseUrl = `https://unpkg.com/${name}@${version}/${destinationDirectory}/`;
|
||||
}
|
||||
|
||||
// IIFE build for tinkering in modern browsers
|
||||
config.push({
|
||||
...globalOptions,
|
||||
input,
|
||||
plugins: [
|
||||
externals({ deps: false }),
|
||||
resolve({ preferBuiltins: false }),
|
||||
json(),
|
||||
esbuild({ target: "esnext" }),
|
||||
commonjs(),
|
||||
],
|
||||
output: {
|
||||
file: `${destination}.browser.js`,
|
||||
format: "iife",
|
||||
sourcemapBaseUrl,
|
||||
...outputOptions,
|
||||
...iifeOutputOptions,
|
||||
},
|
||||
});
|
||||
|
||||
// Minified production IIFE build
|
||||
config.push({
|
||||
...globalOptions,
|
||||
input,
|
||||
plugins: [
|
||||
externals({ deps: false }),
|
||||
resolve({ preferBuiltins: false }),
|
||||
json(),
|
||||
esbuild({ target: "es2015", minify: true }),
|
||||
commonjs(),
|
||||
],
|
||||
output: {
|
||||
file: `${destination}.browser.min.js`,
|
||||
format: "iife",
|
||||
sourcemapBaseUrl,
|
||||
...outputOptions,
|
||||
...iifeOutputOptions,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -148,5 +156,5 @@ export const makeCoreRollupConfig = () =>
|
||||
export const makeNodeRollupConfig = () =>
|
||||
makeConfig({
|
||||
globalOptions: { external: ["jspsych"] },
|
||||
nodeOnly: true,
|
||||
isNodeOnlyBuild: true,
|
||||
});
|
||||
|
@ -42,9 +42,7 @@
|
||||
"homepage": "https://www.jspsych.org",
|
||||
"dependencies": {
|
||||
"auto-bind": "^4.0.0",
|
||||
"lodash.get": "^4.4.2",
|
||||
"lodash.has": "^4.5.2",
|
||||
"lodash.set": "^4.3.2",
|
||||
"lodash": "^4.17.21",
|
||||
"random-words": "^1.1.1",
|
||||
"seedrandom": "^3.0.5",
|
||||
"type-fest": "^2.9.0"
|
||||
@ -53,9 +51,7 @@
|
||||
"@fontsource/open-sans": "4.5.3",
|
||||
"@jspsych/config": "^1.3.1",
|
||||
"@types/dom-mediacapture-record": "^1.0.11",
|
||||
"@types/lodash.get": "^4.4.6",
|
||||
"@types/lodash.has": "^4.5.7",
|
||||
"@types/lodash.set": "^4.3.7",
|
||||
"@types/lodash": "^4.14.189",
|
||||
"base64-inline-loader": "^2.0.1",
|
||||
"css-loader": "^6.6.0",
|
||||
"mini-css-extract-plugin": "^2.5.3",
|
||||
|
@ -65,3 +65,4 @@ export { JsPsych } from "./JsPsych";
|
||||
export type { JsPsychPlugin, PluginInfo, TrialType } from "./modules/plugins";
|
||||
export { ParameterType } from "./modules/plugins";
|
||||
export type { JsPsychExtension, JsPsychExtensionInfo } from "./modules/extensions";
|
||||
export { DataCollection } from "./modules/data/DataCollection";
|
||||
|
@ -1,6 +1,6 @@
|
||||
import get from "lodash.get";
|
||||
import has from "lodash.has";
|
||||
import set from "lodash.set";
|
||||
import get from "lodash/get.js";
|
||||
import has from "lodash/has.js";
|
||||
import set from "lodash/set.js";
|
||||
|
||||
import type { Timeline } from "./Timeline";
|
||||
import {
|
||||
|
Loading…
Reference in New Issue
Block a user