@jspsych/config 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @jspsych/config
2
2
 
3
+ ## 3.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#2858](https://github.com/jspsych/jsPsych/pull/2858) [`76e75080`](https://github.com/jspsych/jsPsych/commit/76e75080247e936c6ae8a8227517fb95ce74974b) Thanks [@bjoluc](https://github.com/bjoluc)! - Activate TypeScript's `isolatedModules` flag in the root `tsconfig.json` file. If you are facing any TypeScript errors due to `isolatedModules`, please update your code according to the error messages.
8
+
9
+ - [#2858](https://github.com/jspsych/jsPsych/pull/2858) [`810ed7a3`](https://github.com/jspsych/jsPsych/commit/810ed7a3d1d9181cf25a9cb11ddd37914cd97483) Thanks [@bjoluc](https://github.com/bjoluc)! - 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.
10
+
11
+ ## 2.0.2
12
+
13
+ ### Patch Changes
14
+
15
+ - [#3293](https://github.com/jspsych/jsPsych/pull/3293) [`7bcd4e0a`](https://github.com/jspsych/jsPsych/commit/7bcd4e0a25b46e2cf384f6b747092e75fabce00f) Thanks [@becky-gilbert](https://github.com/becky-gilbert)! - This fixes an error in the gulp task that creates the dist archive for a release, which was causing the dist archive to fail.
16
+
3
17
  ## 2.0.1
4
18
 
5
19
  ### Patch Changes
package/gulp.js CHANGED
@@ -83,7 +83,7 @@ export const createCoreDistArchive = () =>
83
83
  src("packages/jspsych/css/jspsych.css").pipe(rename("/dist/jspsych.css")),
84
84
 
85
85
  // survey.css
86
- src("packages/survey/css/survey.css").pipe(rename("/dist/survey.css")),
86
+ src("packages/plugin-survey/css/survey.css").pipe(rename("/dist/survey.css")),
87
87
 
88
88
  // Examples
89
89
  src("examples/**/*", { base: "." })
package/jest.cjs CHANGED
@@ -8,6 +8,7 @@ module.exports.makePackageConfig = (dirname) => {
8
8
  return {
9
9
  transform: { "\\.(js|jsx|ts|tsx)$": "@sucrase/jest-plugin" },
10
10
  moduleNameMapper: hq.load(dirname + "/tsconfig.json").get("jest"),
11
+
11
12
  testEnvironment: "jsdom",
12
13
  testEnvironmentOptions: {
13
14
  fetchExternalResources: true,
package/package.json CHANGED
@@ -1,13 +1,9 @@
1
1
  {
2
2
  "name": "@jspsych/config",
3
- "version": "2.0.1",
3
+ "version": "3.0.0",
4
4
  "description": "Shared (build) configuration for jsPsych packages",
5
5
  "type": "module",
6
6
  "exports": {
7
- "./babel": {
8
- "import": null,
9
- "require": "./babel.cjs"
10
- },
11
7
  "./gulp": {
12
8
  "import": "./gulp.js",
13
9
  "require": null
@@ -39,33 +35,27 @@
39
35
  },
40
36
  "homepage": "https://www.jspsych.org/latest/developers/configuration",
41
37
  "dependencies": {
42
- "@babel/cli": "7.23.0",
43
- "@babel/core": "7.23.3",
44
- "@babel/preset-env": "7.23.3",
45
- "@rollup/plugin-babel": "6.0.4",
46
38
  "@rollup/plugin-commonjs": "25.0.7",
47
- "@rollup/plugin-json": "6.0.1",
48
39
  "@rollup/plugin-node-resolve": "15.2.3",
49
- "@rollup/plugin-replace": "5.0.5",
50
- "@rollup/plugin-terser": "0.4.4",
51
40
  "@sucrase/jest-plugin": "3.0.0",
52
41
  "@types/gulp": "4.0.17",
53
42
  "@types/jest": "29.5.8",
54
43
  "alias-hq": "6.2.3",
55
- "babel-preset-minify": "0.5.2",
56
44
  "canvas": "^2.11.2",
45
+ "esbuild": "0.15.14",
57
46
  "gulp": "4.0.2",
58
47
  "gulp-cli": "2.3.0",
59
- "gulp-file": "^0.4.0",
48
+ "gulp-file": "0.4.0",
60
49
  "gulp-rename": "2.0.0",
61
50
  "gulp-replace": "1.1.4",
62
51
  "gulp-zip": "6.0.0",
63
52
  "jest": "29.7.0",
64
53
  "jest-environment-jsdom": "29.7.0",
65
54
  "merge-stream": "2.0.0",
66
- "regenerator-runtime": "0.14.0",
67
55
  "rollup": "4.3.0",
68
- "rollup-plugin-typescript2": "0.36.0",
56
+ "rollup-plugin-dts": "5.0.0",
57
+ "rollup-plugin-esbuild": "5.0.0",
58
+ "rollup-plugin-node-externals": "5.0.2",
69
59
  "sucrase": "3.34.0",
70
60
  "tslib": "2.6.2",
71
61
  "typescript": "^5.2.2"
package/rollup.js CHANGED
@@ -1,16 +1,23 @@
1
1
  import { readFileSync } from "node:fs";
2
+ import path from "path";
2
3
 
3
- import { DEFAULT_EXTENSIONS as babelDefaultExtensions } from "@babel/core";
4
- import { babel } from "@rollup/plugin-babel";
5
4
  import commonjs from "@rollup/plugin-commonjs";
6
- import json from "@rollup/plugin-json";
7
5
  import resolve from "@rollup/plugin-node-resolve";
8
- import replace from "@rollup/plugin-replace";
9
- import terser from "@rollup/plugin-terser";
10
6
  import { defineConfig } from "rollup";
11
- import typescript from "rollup-plugin-typescript2";
7
+ import dts from "rollup-plugin-dts";
8
+ import esbuild from "rollup-plugin-esbuild";
9
+ import externals from "rollup-plugin-node-externals";
12
10
  import ts from "typescript";
13
11
 
12
+ const getTsCompilerOptions = () => {
13
+ const cwd = process.cwd();
14
+ return ts.parseJsonConfigFileContent(
15
+ ts.readConfigFile(path.join(cwd, "tsconfig.json"), ts.sys.readFile).config,
16
+ ts.sys,
17
+ cwd
18
+ ).options;
19
+ };
20
+
14
21
  const getPackageInfo = () => {
15
22
  const { name, version } = JSON.parse(readFileSync("./package.json"));
16
23
  return { name, version };
@@ -22,7 +29,7 @@ const makeConfig = ({
22
29
  iifeOutputOptions = {},
23
30
  isNodeOnlyBuild = false,
24
31
  }) => {
25
- const source = "src/index";
32
+ const input = "src/index.ts";
26
33
  const destinationDirectory = "dist";
27
34
  const destination = `${destinationDirectory}/index`;
28
35
 
@@ -31,100 +38,94 @@ const makeConfig = ({
31
38
  ...outputOptions,
32
39
  };
33
40
 
34
- const commonConfig = defineConfig({
35
- input: `${source}.ts`,
36
- plugins: [
37
- resolve({ preferBuiltins: isNodeOnlyBuild }),
38
- typescript({
39
- typescript: ts,
40
- tsconfigDefaults: {
41
- exclude: ["./tests", "**/*.spec.ts", "**/*.test.ts", "./dist"],
42
- },
43
- tsconfigOverride: {
41
+ /** @type{import("rollup-plugin-esbuild").Options} */
42
+ const esBuildPluginOptions = {
43
+ loaders: { ".json": "json" },
44
+ };
45
+
46
+ /** @type{import("@rollup/plugin-commonjs").RollupCommonJSOptions} */
47
+ const commonjsPluginOptions = {
48
+ extensions: [".js", ".json"],
49
+ };
50
+
51
+ // Non-babel builds
52
+ const config = defineConfig([
53
+ // Type definitions (bundled as a single .d.ts file)
54
+ {
55
+ input,
56
+ output: [{ file: `${destination}.d.ts`, format: "es" }],
57
+ plugins: [
58
+ dts({
44
59
  compilerOptions: {
45
- rootDir: "./src",
46
- outDir: "./dist",
60
+ ...getTsCompilerOptions(),
61
+ noEmit: false,
47
62
  paths: {}, // Do not include files referenced via `paths`
48
63
  },
49
- },
50
- }),
51
- json(),
52
- commonjs(),
53
- ],
54
- ...globalOptions,
55
- });
56
-
57
- /** @type {import("rollup").OutputOptions} */
58
- const output = [
59
- {
60
- // Build file to be used as an ES import
61
- file: `${destination}.js`,
62
- format: "esm",
63
- ...outputOptions,
64
+ }),
65
+ ],
64
66
  },
67
+
68
+ // Module builds
65
69
  {
66
- // Build commonjs module (for tools that do not fully support ES6 modules)
67
- file: `${destination}.cjs`,
68
- format: "cjs",
69
- ...outputOptions,
70
+ ...globalOptions,
71
+ input,
72
+ plugins: [
73
+ externals(),
74
+ esbuild({ ...esBuildPluginOptions, target: "node18" }),
75
+ commonjs(commonjsPluginOptions),
76
+ ],
77
+ output: [
78
+ { file: `${destination}.js`, format: "esm", ...outputOptions },
79
+ { file: `${destination}.cjs`, format: "cjs", ...outputOptions },
80
+ ],
70
81
  },
71
- ];
82
+ ]);
72
83
 
73
- let sourcemapBaseUrl;
74
84
  if (!isNodeOnlyBuild) {
75
85
  // In builds that are published to NPM (potentially every CI build), point to sourcemaps via the
76
86
  // package's canonical unpkg URL
87
+ let sourcemapBaseUrl;
77
88
  if (process.env.CI) {
78
89
  const { name, version } = getPackageInfo();
79
90
  sourcemapBaseUrl = `https://unpkg.com/${name}@${version}/${destinationDirectory}/`;
80
91
  }
81
92
 
82
- output.push({
83
- // Build file to be used for tinkering in modern browsers
84
- file: `${destination}.browser.js`,
85
- format: "iife",
86
- sourcemapBaseUrl,
87
- ...outputOptions,
88
- ...iifeOutputOptions,
93
+ // IIFE build for tinkering in modern browsers
94
+ config.push({
95
+ ...globalOptions,
96
+ input,
97
+ plugins: [
98
+ externals({ deps: false }),
99
+ resolve({ preferBuiltins: false }),
100
+ esbuild({ ...esBuildPluginOptions, target: "esnext" }),
101
+ commonjs(commonjsPluginOptions),
102
+ ],
103
+ output: {
104
+ file: `${destination}.browser.js`,
105
+ format: "iife",
106
+ sourcemapBaseUrl,
107
+ ...outputOptions,
108
+ ...iifeOutputOptions,
109
+ },
89
110
  });
90
- }
91
111
 
92
- // Non-babel builds
93
- const config = defineConfig([{ ...commonConfig, output }]);
94
-
95
- if (!isNodeOnlyBuild) {
96
- // Babel build
112
+ // Minified production IIFE build
97
113
  config.push({
98
- ...commonConfig,
114
+ ...globalOptions,
115
+ input,
99
116
  plugins: [
100
- // Import `regenerator-runtime` if requested:
101
- replace({
102
- values: {
103
- "// __rollup-babel-import-regenerator-runtime__":
104
- 'import "regenerator-runtime/runtime.js";',
105
- },
106
- delimiters: ["", ""],
107
- preventAssignment: true,
108
- }),
109
- ...commonConfig.plugins,
110
- babel({
111
- babelHelpers: "bundled",
112
- extends: "@jspsych/config/babel",
113
- // https://github.com/ezolenko/rollup-plugin-typescript2#rollupplugin-babel
114
- extensions: [...babelDefaultExtensions, ".ts"],
115
- }),
116
- ],
117
- output: [
118
- {
119
- // Minified production build file
120
- file: `${destination}.browser.min.js`,
121
- format: "iife",
122
- plugins: [terser()],
123
- sourcemapBaseUrl,
124
- ...outputOptions,
125
- ...iifeOutputOptions,
126
- },
117
+ externals({ deps: false }),
118
+ resolve({ preferBuiltins: false }),
119
+ esbuild({ ...esBuildPluginOptions, target: "es2015", minify: true }),
120
+ commonjs(commonjsPluginOptions),
127
121
  ],
122
+ output: {
123
+ file: `${destination}.browser.min.js`,
124
+ format: "iife",
125
+ sourcemapBaseUrl,
126
+ ...outputOptions,
127
+ ...iifeOutputOptions,
128
+ },
128
129
  });
129
130
  }
130
131
 
@@ -7,8 +7,7 @@
7
7
  "jspsych": ["../jspsych/src"],
8
8
  "@jspsych/*": ["../*/src"]
9
9
  },
10
- // allow resolving json modules in tests (needed for transitive imports of jspsych in tests;
11
- // the jspsych package itself uses https://stackoverflow.com/a/61426303 instead)
10
+ // allow resolving json modules in tests (needed for transitive imports of jspsych)
12
11
  "resolveJsonModule": true
13
12
  }
14
13
  }
package/tsconfig.json CHANGED
@@ -1,33 +1,21 @@
1
1
  {
2
- // shared base tsconfig for all jsPsych packages
3
- // based on https://github.com/formium/tsdx/blob/462af2d002987f985695b98400e0344b8f2754b7/templates/basic/tsconfig.json
4
- // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
5
2
  "compilerOptions": {
6
3
  "target": "ES6",
7
4
  "module": "ESNext",
8
5
  "lib": ["dom", "esnext"],
9
6
  "importHelpers": true,
10
- // output .d.ts declaration files for consumers
11
7
  "declaration": true,
12
- // output .js.map sourcemap files for consumers
13
8
  "sourceMap": true,
14
- // stricter type-checking for stronger correctness. Recommended by TS
15
9
  "strict": false, // should be enabled one lucky day
16
- // linter checks for common issues
17
10
  "noImplicitReturns": true,
18
11
  "noFallthroughCasesInSwitch": true,
19
- // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative
20
12
  "noUnusedLocals": false, // should be enabled one lucky day
21
13
  "noUnusedParameters": false, // should be enabled one lucky day
22
- // use Node's module resolution algorithm, instead of the legacy TS one
23
14
  "moduleResolution": "node",
24
- // interop between ESM and CJS modules. Recommended by TS
25
15
  "esModuleInterop": true,
26
- // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS
27
16
  "skipLibCheck": true,
28
- // error out if import and file system have a casing mismatch. Recommended by TS
29
17
  "forceConsistentCasingInFileNames": true,
30
- // do not emit build output when running `tsc`
31
- "noEmit": true
18
+ "noEmit": true,
19
+ "isolatedModules": true // required by Sucrase
32
20
  }
33
21
  }
package/babel.cjs DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- presets: ["@babel/preset-env"],
3
- };