mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-10 10:40:54 +00:00
git/package: add and upgrade engines and deps, use esbuild custom scripts
This commit is contained in:
parent
fbd30ab2db
commit
2a2b5d4e2e
11737
package-lock.json
generated
11737
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
84
package.json
84
package.json
@ -8,70 +8,42 @@
|
|||||||
"name": "Alain Pitiot"
|
"name": "Alain Pitiot"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.js",
|
"exports": {
|
||||||
|
".": "./src/index.js",
|
||||||
|
"./css": "./src/index.css",
|
||||||
|
"./package": "./package.json"
|
||||||
|
},
|
||||||
|
"main": "./src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run build:js && npm run build:css && npm run build:docs",
|
"build": "npm run build:js && npm run build:css && npm run build:docs",
|
||||||
"build:css": "npx cross-var postcss -o dist/psychojs-$npm_package_version.css src/index.css",
|
"build:css": "node ./scripts/build.css.cjs",
|
||||||
"build:docs": "jsdoc src -r -d docs",
|
"build:docs": "jsdoc src -r -d docs",
|
||||||
"build:js": "rollup -c",
|
"build:js": "node ./scripts/build.js.cjs",
|
||||||
"lint": "npm run lint:js && npm run lint:css",
|
"lint": "npm run lint:js && npm run lint:css",
|
||||||
"lint:css": "stylelint src/**/*.css",
|
"lint:css": "csslint src",
|
||||||
"lint:js": "eslint rollup.config.js src/**/*.js",
|
"lint:js": "eslint src",
|
||||||
|
"lint:scripts": "eslint scripts --ext .cjs",
|
||||||
"start": "npm run build"
|
"start": "npm run build"
|
||||||
},
|
},
|
||||||
"babel": {
|
"dependencies": {
|
||||||
"presets": [
|
"howler": "^2.2.1",
|
||||||
[
|
"log4javascript": "github:Ritzlgrmft/log4javascript",
|
||||||
"@babel/preset-env",
|
"moment": "^2.29.1",
|
||||||
{
|
"pako": "^1.0.10",
|
||||||
"modules": false,
|
"pixi.js-legacy": "^6.0.4",
|
||||||
"targets": {
|
"preload-js": "^0.6.3",
|
||||||
"ie": 11
|
"seedrandom": "^3.0.5",
|
||||||
},
|
"tone": "^14.7.77",
|
||||||
"spec": true,
|
"xlsx": "^0.17.0"
|
||||||
"forceAllTransforms": true,
|
|
||||||
"debug": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"browserslist": [
|
|
||||||
"last 2 versions"
|
|
||||||
],
|
|
||||||
"stylelint": {
|
|
||||||
"extends": "stylelint-config-standard",
|
|
||||||
"rules": {
|
|
||||||
"no-descending-specificity": [
|
|
||||||
true,
|
|
||||||
{
|
|
||||||
"severity": "warning"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dependencies": {},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.12.3",
|
"csslint": "^1.0.5",
|
||||||
"@babel/preset-env": "^7.12.1",
|
"esbuild": "^0.12.1",
|
||||||
"@rollup/plugin-babel": "^5.2.1",
|
"eslint": "^7.26.0",
|
||||||
"cross-var": "^1.1.0",
|
"jsdoc": "^3.6.7"
|
||||||
"cssnano": "^4.1.10",
|
|
||||||
"eslint": "^7.24.0",
|
|
||||||
"jsdoc": "^3.6.6",
|
|
||||||
"postcss": "^8.1.3",
|
|
||||||
"postcss-cli": "^8.1.0",
|
|
||||||
"postcss-preset-env": "^6.7.0",
|
|
||||||
"rollup": "^2.32.1",
|
|
||||||
"stylelint": "^13.7.2",
|
|
||||||
"stylelint-config-standard": "^20.0.0",
|
|
||||||
"terser": "^5.3.8"
|
|
||||||
},
|
},
|
||||||
"postcss": {
|
"engines": {
|
||||||
"plugins": {
|
"node": ">=14.15.0",
|
||||||
"postcss-preset-env": {},
|
"npm": ">=6.14.8"
|
||||||
"cssnano": {
|
|
||||||
"autoprefixer": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
212
rollup.config.js
212
rollup.config.js
@ -1,212 +0,0 @@
|
|||||||
// ES native imports courtesy of using type module in 'package.json'
|
|
||||||
import path from 'path';
|
|
||||||
import fs from 'fs';
|
|
||||||
import { minify } from 'terser';
|
|
||||||
import babel from '@rollup/plugin-babel';
|
|
||||||
import pkg from './package.json';
|
|
||||||
|
|
||||||
// Manually set default version here for easier
|
|
||||||
// diffing when comparing to original build script output
|
|
||||||
const { VERSION: version = pkg.version } = process.env;
|
|
||||||
|
|
||||||
// Enabled in the original, even though
|
|
||||||
// source maps missing for sample provided
|
|
||||||
const sourcemap = false;
|
|
||||||
|
|
||||||
// Might be 'build' or similar
|
|
||||||
const destination = './dist';
|
|
||||||
|
|
||||||
// Could be 'src' or 'lib'
|
|
||||||
const source = './src';
|
|
||||||
|
|
||||||
// Start fresh
|
|
||||||
try {
|
|
||||||
if (fs.existsSync(destination)) {
|
|
||||||
// Clear out JS files before rebuilding
|
|
||||||
const contents = fs.readdirSync(destination).filter(item => item.endsWith('js'));
|
|
||||||
|
|
||||||
for (const item of contents) {
|
|
||||||
const target = path.join(destination, item);
|
|
||||||
const stat = fs.statSync(target);
|
|
||||||
|
|
||||||
// Delete
|
|
||||||
fs.unlinkSync(target);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Create 'dist' if missing
|
|
||||||
fs.mkdirSync(destination);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// For sorting legacy/IE11 bundle components
|
|
||||||
const orderOfAppearance = [ 'util', 'data', 'core', 'visual', 'sound' ];
|
|
||||||
const last = [ ...orderOfAppearance ].pop();
|
|
||||||
const footer = `
|
|
||||||
// Add a few top level variables for convenience, this makes it
|
|
||||||
// possible to eg. use "return Scheduler.Event.NEXT;" instead of "util.Scheduler.Event.NEXT;"
|
|
||||||
PsychoJS = core.PsychoJS;
|
|
||||||
TrialHandler = data.TrialHandler;
|
|
||||||
Scheduler = util.Scheduler;`;
|
|
||||||
|
|
||||||
const plugins = [
|
|
||||||
babel({
|
|
||||||
babelHelpers: 'bundled',
|
|
||||||
exclude: 'node_modules/**',
|
|
||||||
include: `${destination}/*.iife.js`
|
|
||||||
}),
|
|
||||||
minifier({
|
|
||||||
compress: false,
|
|
||||||
mangle: false,
|
|
||||||
output: {
|
|
||||||
beautify: true
|
|
||||||
},
|
|
||||||
sourceMap: false,
|
|
||||||
toplevel: false
|
|
||||||
})
|
|
||||||
];
|
|
||||||
|
|
||||||
// List source directory contents
|
|
||||||
const components = fs.readdirSync(source)
|
|
||||||
// Need subdirectories only
|
|
||||||
.filter((item) => {
|
|
||||||
const target = path.join(source, item);
|
|
||||||
const stat = fs.statSync(target);
|
|
||||||
|
|
||||||
return stat.isDirectory();
|
|
||||||
})
|
|
||||||
// Put in order
|
|
||||||
.sort((a, b) => orderOfAppearance.indexOf(a) - orderOfAppearance.indexOf(b))
|
|
||||||
// Prepare an output object for each component module
|
|
||||||
.map((component, _, contents) => ({
|
|
||||||
// So I don't have to specify full paths
|
|
||||||
external: (id) => {
|
|
||||||
// Decompose current component path
|
|
||||||
const segments = id.split('/');
|
|
||||||
|
|
||||||
// Mark as external if contents within source
|
|
||||||
// directory tree, excluding the current component
|
|
||||||
return contents
|
|
||||||
.filter(item => item !== component)
|
|
||||||
.some(item => segments.includes(item));
|
|
||||||
},
|
|
||||||
input: `${source}/${component}/index.js`,
|
|
||||||
// Disable circular dependency warnings
|
|
||||||
onwarn,
|
|
||||||
output: [
|
|
||||||
{
|
|
||||||
file: `${destination}/${component}-${version}.js`,
|
|
||||||
format: 'module',
|
|
||||||
globals: {
|
|
||||||
performance: 'performance'
|
|
||||||
},
|
|
||||||
// Find which module the import points to
|
|
||||||
// and fix path in place
|
|
||||||
paths: (id) => {
|
|
||||||
const name = findName(id, contents);
|
|
||||||
|
|
||||||
return `./${name}-${version}.js`;
|
|
||||||
},
|
|
||||||
sourcemap,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
esModule: false,
|
|
||||||
file: `${destination}/${component}-${version}.iife.js`,
|
|
||||||
format: 'iife',
|
|
||||||
globals: id => findName(id, contents),
|
|
||||||
name: component,
|
|
||||||
paths: (id) => {
|
|
||||||
const name = findName(id, contents);
|
|
||||||
|
|
||||||
return `./${name}-${version}.iife.js`;
|
|
||||||
},
|
|
||||||
sourcemap,
|
|
||||||
plugins: [
|
|
||||||
appender({
|
|
||||||
target: `${destination}/psychojs-${version}.js`,
|
|
||||||
// Mirrors rollup's 'outputOptions' hook
|
|
||||||
outputOptions: (options) => {
|
|
||||||
if (options.file.includes(last)) {
|
|
||||||
options.footer = footer;
|
|
||||||
}
|
|
||||||
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
plugins
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
export default [
|
|
||||||
...components,
|
|
||||||
{
|
|
||||||
// Add a UMD build for Thomas
|
|
||||||
input: `${source}/index.js`,
|
|
||||||
onwarn,
|
|
||||||
output: {
|
|
||||||
file: `${destination}/psychojs-${version}.umd.js`,
|
|
||||||
format: 'umd',
|
|
||||||
name: 'psychojs'
|
|
||||||
},
|
|
||||||
plugins
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
// https://rollupjs.org/guide/en/#onwarn
|
|
||||||
function onwarn(message, warn) {
|
|
||||||
// Skip circular dependency warnings
|
|
||||||
if (message.code === 'CIRCULAR_DEPENDENCY') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
warn(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper for extracting module name from contents array by rollup id (path to file)
|
|
||||||
function findName(id, contents) {
|
|
||||||
return id.split(path.sep).find(item => contents.includes(item));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Minimal terser plugin
|
|
||||||
function minifier(options) {
|
|
||||||
return {
|
|
||||||
name: 'minifier',
|
|
||||||
async renderChunk(code) {
|
|
||||||
try {
|
|
||||||
// Includes code and map keys
|
|
||||||
const result = await minify(code, options);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Custom plugin for cancatenating IIFE's sans cat(1)
|
|
||||||
function appender({ target = '', outputOptions = () => {} } = {}) {
|
|
||||||
return {
|
|
||||||
name: 'appender',
|
|
||||||
outputOptions: (options) => outputOptions(options),
|
|
||||||
async generateBundle(options, bundle) {
|
|
||||||
const { file } = options;
|
|
||||||
const id = file.split('/').pop();
|
|
||||||
const { code } = bundle[id];
|
|
||||||
|
|
||||||
// Should be expected to throw if `target` missing
|
|
||||||
fs.appendFile(target, code, (error) => {
|
|
||||||
if (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Prevent write out
|
|
||||||
delete bundle[id];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
13
scripts/build.css.cjs
Normal file
13
scripts/build.css.cjs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const { buildSync } = require('esbuild');
|
||||||
|
const pkg = require('psychojs/package');
|
||||||
|
|
||||||
|
const versionMaybe = process.env.npm_config_outver;
|
||||||
|
const dirMaybe = process.env.npm_config_outdir;
|
||||||
|
const [,,, dir = dirMaybe || 'out', version = versionMaybe || pkg.version] = process.argv;
|
||||||
|
|
||||||
|
buildSync({
|
||||||
|
bundle: true,
|
||||||
|
entryPoints: ['src/index.css'],
|
||||||
|
minify: true,
|
||||||
|
outfile: `./${dir}/psycho-${version}.css`
|
||||||
|
});
|
14
scripts/build.js.cjs
Normal file
14
scripts/build.js.cjs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
const { buildSync } = require('esbuild');
|
||||||
|
const pkg = require('psychojs/package');
|
||||||
|
|
||||||
|
const versionMaybe = process.env.npm_config_outver;
|
||||||
|
const dirMaybe = process.env.npm_config_outdir;
|
||||||
|
const [,,, dir = dirMaybe || 'out', version = versionMaybe || pkg.version] = process.argv;
|
||||||
|
|
||||||
|
buildSync({
|
||||||
|
bundle: true,
|
||||||
|
entryPoints: ['src/index.js'],
|
||||||
|
format: 'esm',
|
||||||
|
minify: true,
|
||||||
|
outfile: `./${dir}/psycho-${version}.js`
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user