@jspsych/config 1.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 ADDED
@@ -0,0 +1,8 @@
1
+ # @jspsych/config
2
+
3
+ ## 1.0.0
4
+ ### Major Changes
5
+
6
+
7
+
8
+ - [`bc058590`](https://github.com/jspsych/jsPsych/commit/bc058590950285e52116f809e4ccc57bae5a67f5) Thanks [@bjoluc](https://github.com/bjoluc)! - Initial release
package/babel.cjs ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ presets: ["@babel/preset-env"],
3
+ };
package/gulp.js ADDED
@@ -0,0 +1,51 @@
1
+ import { sep as pathSeparator } from "path";
2
+
3
+ import gulp from "gulp";
4
+ import rename from "gulp-rename";
5
+ import replace from "gulp-replace";
6
+ import zip from "gulp-zip";
7
+ import merge from "merge-stream";
8
+
9
+ const { dest, src } = gulp;
10
+
11
+ export const createCoreDistArchive = () =>
12
+ merge(
13
+ // index.browser.js files
14
+ src("packages/*/dist/index.browser.js", { root: "packages/" })
15
+ // Rename dist files
16
+ .pipe(
17
+ rename((path) => {
18
+ const packageName = path.dirname.split(pathSeparator)[0];
19
+
20
+ path.dirname = "/dist";
21
+ path.basename = packageName;
22
+ })
23
+ )
24
+ // Remove sourceMappingURL comments
25
+ .pipe(replace(/\/\/# sourceMappingURL=.*\n/g, "")),
26
+
27
+ // jspsych.css
28
+ src("packages/jspsych/css/jspsych.css").pipe(rename("/dist/jspsych.css")),
29
+
30
+ // Examples
31
+ src("examples/**/*", { base: "." })
32
+ // Rewrite script source paths
33
+ .pipe(
34
+ replace(
35
+ /<script src="(.*)\/packages\/(.*)\/dist\/index\.browser\.js"><\/script>/g,
36
+ '<script src="$1/dist/$2.js"></script>'
37
+ )
38
+ )
39
+ // Rewrite jspsych css source paths
40
+ .pipe(
41
+ replace(
42
+ /<link rel="stylesheet" href="(.*)\/packages\/jspsych\/css\/(.*)" \/>/g,
43
+ '<link rel="stylesheet" href="$1/dist/$2" />'
44
+ )
45
+ ),
46
+
47
+ // Other files
48
+ src(["*.md", "license.txt"])
49
+ )
50
+ .pipe(zip("dist.zip"))
51
+ .pipe(dest("."));
package/jest.cjs ADDED
@@ -0,0 +1,31 @@
1
+ const ts = require("typescript");
2
+ const { pathsToModuleNameMapper } = require("ts-jest/utils");
3
+
4
+ module.exports.makePackageConfig = (dirname) => {
5
+ const packageJson = require(dirname + "/package.json");
6
+ const packageBaseName = packageJson.name.replace("@jspsych/", "");
7
+
8
+ // based on https://github.com/formium/tsdx/blob/462af2d002987f985695b98400e0344b8f2754b7/src/createRollupConfig.ts#L51-L57
9
+ const tsCompilerOptions = ts.parseJsonConfigFileContent(
10
+ ts.readConfigFile(dirname + "/tsconfig.json", ts.sys.readFile).config,
11
+ ts.sys,
12
+ dirname
13
+ ).options;
14
+
15
+ return {
16
+ preset: "ts-jest",
17
+ moduleNameMapper: pathsToModuleNameMapper(tsCompilerOptions.paths, {
18
+ prefix: "<rootDir>/",
19
+ }),
20
+ testEnvironment: "jsdom",
21
+ testEnvironmentOptions: {
22
+ fetchExternalResources: true,
23
+ pretendToBeVisual: true,
24
+ },
25
+ testURL: "http://localhost/",
26
+ displayName: {
27
+ name: packageBaseName,
28
+ color: packageBaseName === "jspsych" ? "white" : "cyanBright",
29
+ },
30
+ };
31
+ };
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@jspsych/config",
3
+ "version": "1.0.0",
4
+ "description": "Shared (build) configuration for jsPsych packages",
5
+ "type": "module",
6
+ "exports": {
7
+ "./babel": {
8
+ "import": null,
9
+ "require": "./babel.cjs"
10
+ },
11
+ "./gulp": {
12
+ "import": "./gulp.js",
13
+ "require": null
14
+ },
15
+ "./jest": {
16
+ "import": null,
17
+ "require": "./jest.cjs"
18
+ },
19
+ "./rollup": {
20
+ "import": "./rollup.js",
21
+ "require": null
22
+ },
23
+ "./tsconfig.json": "./tsconfig.json",
24
+ "./tsconfig.core.json": "./tsconfig.core.json",
25
+ "./tsconfig.contrib.json": "./tsconfig.contrib.json"
26
+ },
27
+ "engines": {
28
+ "node": ">=14.0.0"
29
+ },
30
+ "scripts": {
31
+ "build": "",
32
+ "tsc": ""
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/jspsych/jsPsych.git",
37
+ "directory": "packages/config"
38
+ },
39
+ "author": "bjoluc <mail@bjoluc.de>",
40
+ "license": "MIT",
41
+ "bugs": {
42
+ "url": "https://github.com/jspsych/jsPsych/issues"
43
+ },
44
+ "homepage": "https://www.jspsych.org/latest/developers/configuration",
45
+ "dependencies": {
46
+ "@babel/cli": "7.15.7",
47
+ "@babel/core": "7.15.5",
48
+ "@babel/preset-env": "7.15.6",
49
+ "@rollup/plugin-babel": "5.3.0",
50
+ "@rollup/plugin-commonjs": "19.0.0",
51
+ "@rollup/plugin-json": "4.1.0",
52
+ "@rollup/plugin-node-resolve": "13.0.5",
53
+ "@types/gulp": "4.0.9",
54
+ "@types/jest": "27.0.2",
55
+ "babel-preset-minify": "0.5.1",
56
+ "canvas": "2.8.0",
57
+ "gulp": "4.0.2",
58
+ "gulp-cli": "2.3.0",
59
+ "gulp-rename": "2.0.0",
60
+ "gulp-replace": "1.1.3",
61
+ "gulp-zip": "5.1.0",
62
+ "jest": "27.2.4",
63
+ "jest-environment-jsdom": "27.2.4",
64
+ "merge-stream": "2.0.0",
65
+ "rollup": "2.58.0",
66
+ "rollup-plugin-terser": "7.0.2",
67
+ "rollup-plugin-typescript2": "0.30.0",
68
+ "ts-jest": "27.0.5",
69
+ "tslib": "2.3.1",
70
+ "typescript": "4.4.3"
71
+ }
72
+ }
package/rollup.js ADDED
@@ -0,0 +1,138 @@
1
+ import { babel } from "@rollup/plugin-babel";
2
+ import commonjs from "@rollup/plugin-commonjs";
3
+ import json from "@rollup/plugin-json";
4
+ import resolve from "@rollup/plugin-node-resolve";
5
+ import { defineConfig } from "rollup";
6
+ import { terser } from "rollup-plugin-terser";
7
+ import typescript from "rollup-plugin-typescript2";
8
+ import ts from "typescript";
9
+
10
+ const makeConfig = ({
11
+ outputOptions = {},
12
+ globalOptions = {},
13
+ iifeOutputOptions = {},
14
+ nodeOnly = false,
15
+ }) => {
16
+ const source = "src/index";
17
+ const destination = "dist/index";
18
+
19
+ outputOptions = {
20
+ sourcemap: true,
21
+ ...outputOptions,
22
+ };
23
+
24
+ const commonConfig = defineConfig({
25
+ input: `${source}.ts`,
26
+ plugins: [
27
+ resolve(),
28
+ typescript({
29
+ typescript: ts,
30
+ tsconfigDefaults: {
31
+ exclude: ["./tests", "**/*.spec.ts", "**/*.test.ts", "./dist"],
32
+ },
33
+ tsconfigOverride: {
34
+ compilerOptions: {
35
+ rootDir: "./src",
36
+ outDir: "./dist",
37
+ paths: {}, // Do not include files referenced via `paths`
38
+ },
39
+ },
40
+ }),
41
+ json(),
42
+ commonjs(),
43
+ ],
44
+ ...globalOptions,
45
+ });
46
+
47
+ /** @type {import("rollup").OutputOptions} */
48
+ const output = [
49
+ {
50
+ // Build file to be used as an ES import
51
+ file: `${destination}.js`,
52
+ format: "esm",
53
+ ...outputOptions,
54
+ },
55
+ {
56
+ // Build commonjs module (for tools that do not fully support ES6 modules)
57
+ file: `${destination}.cjs`,
58
+ format: "cjs",
59
+ ...outputOptions,
60
+ },
61
+ ];
62
+
63
+ if (!nodeOnly) {
64
+ output.push({
65
+ // Build file to be used for tinkering in modern browsers
66
+ file: `${destination}.browser.js`,
67
+ format: "iife",
68
+ ...outputOptions,
69
+ ...iifeOutputOptions,
70
+ });
71
+ }
72
+
73
+ // Non-babel builds
74
+ const config = defineConfig([{ ...commonConfig, output }]);
75
+
76
+ if (!nodeOnly) {
77
+ // Babel build
78
+ config.push({
79
+ ...commonConfig,
80
+ plugins: commonConfig.plugins.concat(
81
+ babel({
82
+ babelHelpers: "bundled",
83
+ extends: "@jspsych/config/babel",
84
+ })
85
+ ),
86
+ output: [
87
+ {
88
+ // Minified production build file
89
+ file: `${destination}.browser.min.js`,
90
+ format: "iife",
91
+ plugins: [terser()],
92
+ ...outputOptions,
93
+ ...iifeOutputOptions,
94
+ },
95
+ ],
96
+ });
97
+ }
98
+
99
+ return config;
100
+ };
101
+
102
+ /**
103
+ * Returns a Rollup configuration object for a JsPsych plugin or extension that is written in
104
+ * TypeScript
105
+ *
106
+ * @param {string} iifeName The variable name that will identify the plugin or extension in the
107
+ * global scope in browser builds
108
+ */
109
+ export const makeRollupConfig = (iifeName) =>
110
+ makeConfig({
111
+ outputOptions: {
112
+ exports: "default",
113
+ globals: { jspsych: "jsPsychModule" },
114
+ },
115
+ globalOptions: { external: ["jspsych"] },
116
+ iifeOutputOptions: { name: iifeName },
117
+ });
118
+
119
+ /**
120
+ * Returns the rollup configuration for the core `jspsych` package.
121
+ */
122
+ export const makeCoreRollupConfig = () =>
123
+ makeConfig({
124
+ outputOptions: {
125
+ exports: "named",
126
+ name: "jsPsychModule",
127
+ },
128
+ iifeOutputOptions: { footer: "var initJsPsych = jsPsychModule.initJsPsych;" },
129
+ });
130
+
131
+ /**
132
+ * Returns the rollup configuration for Node.js-only packages
133
+ */
134
+ export const makeNodeRollupConfig = () =>
135
+ makeConfig({
136
+ globalOptions: { external: ["jspsych"] },
137
+ nodeOnly: true,
138
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ // tsconfig for the jspsych-contrib monorepo
3
+ "extends": "@jspsych/config/tsconfig.json",
4
+ "compilerOptions": {
5
+ "paths": {
6
+ // map jspsych-contrib package imports directly to their source files
7
+ "@jspsych-contrib/*": ["../*/src"]
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ // tsconfig for the jsPsych monorepo
3
+ "extends": "@jspsych/config/tsconfig.json",
4
+ "compilerOptions": {
5
+ // map package imports directly to their source files
6
+ "paths": {
7
+ "jspsych": ["../jspsych/src"],
8
+ "@jspsych/*": ["../*/src"]
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)
12
+ "resolveJsonModule": true
13
+ }
14
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,33 @@
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
+ "compilerOptions": {
6
+ "target": "ES6",
7
+ "module": "ESNext",
8
+ "lib": ["dom", "esnext"],
9
+ "importHelpers": true,
10
+ // output .d.ts declaration files for consumers
11
+ "declaration": true,
12
+ // output .js.map sourcemap files for consumers
13
+ "sourceMap": true,
14
+ // stricter type-checking for stronger correctness. Recommended by TS
15
+ "strict": false, // should be enabled one lucky day
16
+ // linter checks for common issues
17
+ "noImplicitReturns": true,
18
+ "noFallthroughCasesInSwitch": true,
19
+ // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative
20
+ "noUnusedLocals": false, // should be enabled one lucky day
21
+ "noUnusedParameters": false, // should be enabled one lucky day
22
+ // use Node's module resolution algorithm, instead of the legacy TS one
23
+ "moduleResolution": "node",
24
+ // interop between ESM and CJS modules. Recommended by TS
25
+ "esModuleInterop": true,
26
+ // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS
27
+ "skipLibCheck": true,
28
+ // error out if import and file system have a casing mismatch. Recommended by TS
29
+ "forceConsistentCasingInFileNames": true,
30
+ // do not emit build output when running `tsc`
31
+ "noEmit": true
32
+ }
33
+ }