mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-21 03:20:36 +03:00
switch to playwright test runner, use esbuild for dev builds, switch to array destructuring
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
loose: true,
|
||||
bugfixes: true,
|
||||
targets: {
|
||||
esmodules: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
loose: true,
|
||||
targets: {
|
||||
ie: '11',
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
module.exports = {
|
||||
project: null,
|
||||
mode: 'build',
|
||||
paths: {
|
||||
src: './src',
|
||||
dist: './dist',
|
||||
types: './types',
|
||||
},
|
||||
versions: {
|
||||
minified: true,
|
||||
module: true,
|
||||
},
|
||||
alias: {},
|
||||
rollup: {
|
||||
input: './src/index',
|
||||
output: {
|
||||
sourcemap: true,
|
||||
exports: 'auto',
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,107 @@
|
||||
const path = require('path');
|
||||
const { babel: rollupBabelInputPlugin } = require('@rollup/plugin-babel');
|
||||
const { terser: rollupTerser } = require('rollup-plugin-terser');
|
||||
const rollupTs = require('rollup-plugin-ts');
|
||||
|
||||
const babelConfigUmd = require('./babel.config.umd');
|
||||
const babelConfigEsm = require('./babel.config.esm');
|
||||
const { rollupCommonjs, rollupResolve, rollupAlias } = require('./pipeline.common.plugins');
|
||||
const { extensions } = require('../../resolve.config.json');
|
||||
|
||||
const createOutputWithMinifiedVersion = (output, esm, buildMinifiedVersion) =>
|
||||
[output].concat(
|
||||
buildMinifiedVersion
|
||||
? [
|
||||
{
|
||||
...output,
|
||||
compact: true,
|
||||
file: output.file.replace('.js', '.min.js'),
|
||||
sourcemap: false,
|
||||
plugins: [
|
||||
...(output.plugins || []),
|
||||
rollupTerser({
|
||||
ecma: esm ? 2015 : 5,
|
||||
safari10: true,
|
||||
mangle: {
|
||||
safari10: true,
|
||||
properties: {
|
||||
regex: /^_/,
|
||||
},
|
||||
},
|
||||
compress: {
|
||||
evaluate: false,
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
]
|
||||
: []
|
||||
);
|
||||
|
||||
module.exports = (esm, options, declarationFiles = false) => {
|
||||
const { rollup, paths, versions, alias } = options;
|
||||
const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup;
|
||||
const { name, file, globals, exports, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput;
|
||||
const { minified: buildMinifiedVersion } = versions;
|
||||
const { src: srcPath, dist: distPath, types: typesPath } = paths;
|
||||
const sourcemap = rawSourcemap;
|
||||
|
||||
const output = createOutputWithMinifiedVersion(
|
||||
{
|
||||
...outputConfig,
|
||||
...(!esm && {
|
||||
name,
|
||||
globals,
|
||||
exports,
|
||||
}),
|
||||
sourcemap,
|
||||
format: esm ? 'esm' : 'umd',
|
||||
generatedCode: esm ? 'es2015' : 'es5',
|
||||
file: path.resolve(distPath, `${file}${esm ? '.esm' : ''}.js`),
|
||||
},
|
||||
esm,
|
||||
buildMinifiedVersion
|
||||
);
|
||||
|
||||
return {
|
||||
input,
|
||||
output,
|
||||
...rollupOptions,
|
||||
plugins: [
|
||||
rollupAlias(alias),
|
||||
rollupTs({
|
||||
tsconfig: (resolvedConfig) => ({
|
||||
...resolvedConfig,
|
||||
declaration: declarationFiles,
|
||||
declarationDir: typesPath,
|
||||
}),
|
||||
include: ['*.ts+(|x)', '**/*.ts+(|x)'],
|
||||
exclude: ['node_modules', '**/node_modules/*'],
|
||||
}),
|
||||
rollupResolve(srcPath),
|
||||
rollupCommonjs(sourcemap),
|
||||
rollupBabelInputPlugin({
|
||||
...(esm ? babelConfigEsm : babelConfigUmd),
|
||||
assumptions: {
|
||||
iterableIsArray: true,
|
||||
noNewArrows: true,
|
||||
noClassCalls: true,
|
||||
ignoreToPrimitiveHint: true,
|
||||
ignoreFunctionLength: true,
|
||||
},
|
||||
plugins: [
|
||||
'@babel/plugin-transform-runtime',
|
||||
['@babel/plugin-proposal-class-properties', { loose: true }],
|
||||
['@babel/plugin-proposal-private-methods', { loose: true }],
|
||||
],
|
||||
babelHelpers: 'runtime',
|
||||
shouldPrintComment: () => false,
|
||||
caller: {
|
||||
name: 'babel-rollup-build',
|
||||
},
|
||||
extensions,
|
||||
}),
|
||||
...plugins,
|
||||
],
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
const { nodeResolve: rollupPluginResolve } = require('@rollup/plugin-node-resolve');
|
||||
const rollupPluginCommonjs = require('@rollup/plugin-commonjs');
|
||||
const rollupPluginAlias = require('@rollup/plugin-alias');
|
||||
const { extensions, directories } = require('../../resolve.config.json');
|
||||
|
||||
module.exports = {
|
||||
rollupAlias: (aliasEntries) =>
|
||||
rollupPluginAlias({
|
||||
entries: aliasEntries,
|
||||
}),
|
||||
rollupCommonjs: (sourcemap) =>
|
||||
rollupPluginCommonjs({
|
||||
sourceMap: sourcemap,
|
||||
extensions,
|
||||
}),
|
||||
rollupResolve: (srcPath) =>
|
||||
rollupPluginResolve({
|
||||
mainFields: ['browser', 'umd:main', 'module', 'main'],
|
||||
rootDir: srcPath,
|
||||
moduleDirectories: directories,
|
||||
extensions,
|
||||
}),
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
const path = require('path');
|
||||
const { default: rollupEsBuild } = require('rollup-plugin-esbuild');
|
||||
const { rollupCommonjs, rollupResolve, rollupAlias } = require('./pipeline.common.plugins');
|
||||
|
||||
module.exports = (options) => {
|
||||
const { rollup, paths, alias } = options;
|
||||
const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup;
|
||||
const { file, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput;
|
||||
const { src: srcPath, dist: distPath } = paths;
|
||||
const sourcemap = rawSourcemap;
|
||||
|
||||
const output = {
|
||||
...outputConfig,
|
||||
sourcemap: true,
|
||||
format: 'esm',
|
||||
generatedCode: 'es2015',
|
||||
file: path.resolve(distPath, `${file}.js`),
|
||||
};
|
||||
|
||||
return {
|
||||
input,
|
||||
output,
|
||||
...rollupOptions,
|
||||
plugins: [
|
||||
rollupAlias(alias),
|
||||
rollupResolve(srcPath),
|
||||
rollupEsBuild({
|
||||
include: /\.[jt]sx?$/,
|
||||
sourceMap: true,
|
||||
target: 'es6',
|
||||
tsconfig: './tsconfig.json',
|
||||
}),
|
||||
rollupCommonjs(sourcemap),
|
||||
...plugins,
|
||||
],
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,107 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const glob = require('glob');
|
||||
const resolve = require('../../resolve.config.json');
|
||||
const pkg = require('../../package.json');
|
||||
|
||||
const defaultOptions = require('./defaultOptions');
|
||||
const pipelineBuild = require('./pipeline.build');
|
||||
const pipelineDev = require('./pipeline.dev');
|
||||
|
||||
const repoRoot = path.resolve(__dirname, '../../');
|
||||
|
||||
const appendExtension = (file) =>
|
||||
path.extname(file) === '' ? file + resolve.extensions.find((ext) => fs.existsSync(path.resolve(`${file}${ext}`))) : file;
|
||||
|
||||
const normalizePath = (pathName) => (pathName ? pathName.split(path.sep).join(path.posix.sep) : pathName);
|
||||
|
||||
const resolvePath = (basePath, pathToResolve, appendExt) => {
|
||||
const result = pathToResolve ? (path.isAbsolute(pathToResolve) ? pathToResolve : path.resolve(basePath, pathToResolve)) : null;
|
||||
return normalizePath(result && appendExt ? appendExtension(result) : result);
|
||||
};
|
||||
|
||||
const getWorkspaceAliases = () =>
|
||||
pkg.workspaces
|
||||
.map((pattern) => glob.sync(pattern, { cwd: repoRoot }))
|
||||
.flat()
|
||||
.reduce((obj, resolvedPath) => {
|
||||
let projTsConfig;
|
||||
const absolutePath = path.resolve(repoRoot, resolvedPath);
|
||||
try {
|
||||
projTsConfig = require(`${path.resolve(repoRoot, resolvedPath)}/tsconfig.json`);
|
||||
} catch {}
|
||||
|
||||
obj[`@/${path.basename(absolutePath)}`] = `${normalizePath(
|
||||
path.resolve(absolutePath, projTsConfig?.compilerOptions?.baseUrl || defaultOptions.paths.src)
|
||||
)}`;
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
const mergeAndResolveOptions = (userOptions) => {
|
||||
const { mode: defaultMode, paths: defaultPaths, versions: defaultVersions, alias: defaultAlias, rollup: defaultRollup } = defaultOptions;
|
||||
const { project, mode: rawMode, paths: rawPaths = {}, versions: rawVersions = {}, alias: rawAlias = {}, rollup: rawRollup = {} } = userOptions;
|
||||
const projectPath = process.cwd();
|
||||
const mergedOptions = {
|
||||
project: project || path.basename(projectPath),
|
||||
mode: rawMode || defaultMode,
|
||||
repoRoot,
|
||||
paths: {
|
||||
...defaultPaths,
|
||||
...rawPaths,
|
||||
},
|
||||
versions: {
|
||||
...defaultVersions,
|
||||
...rawVersions,
|
||||
},
|
||||
alias: {
|
||||
...getWorkspaceAliases(),
|
||||
...defaultAlias,
|
||||
...rawAlias,
|
||||
},
|
||||
rollup: {
|
||||
...defaultRollup,
|
||||
...rawRollup,
|
||||
output: {
|
||||
...defaultRollup.output,
|
||||
...(rawRollup.output || {}),
|
||||
},
|
||||
},
|
||||
};
|
||||
const { src, dist, types, tests } = mergedOptions.paths;
|
||||
|
||||
mergedOptions.paths.src = resolvePath(projectPath, src);
|
||||
mergedOptions.paths.dist = resolvePath(projectPath, dist);
|
||||
mergedOptions.paths.types = resolvePath(projectPath, types);
|
||||
mergedOptions.paths.tests = resolvePath(projectPath, tests);
|
||||
|
||||
mergedOptions.rollup.input = resolvePath(projectPath, mergedOptions.rollup.input, true);
|
||||
mergedOptions.rollup.output = {
|
||||
...(mergedOptions.rollup.output || {}),
|
||||
name: mergedOptions.rollup.output?.name || mergedOptions.project,
|
||||
file: mergedOptions.rollup.output?.file || mergedOptions.project.toLocaleLowerCase(),
|
||||
};
|
||||
|
||||
return mergedOptions;
|
||||
};
|
||||
|
||||
const createConfig = (userOptions = {}) => {
|
||||
const options = mergeAndResolveOptions(userOptions);
|
||||
const { project, mode, versions } = options;
|
||||
const { module: buildModuleVersion } = versions;
|
||||
const isBuild = mode === 'build';
|
||||
|
||||
if (isBuild) {
|
||||
console.log('');
|
||||
console.log('PROJECT : ', project);
|
||||
console.log('OPTIONS : ', options);
|
||||
|
||||
const umd = pipelineBuild(false, options, true);
|
||||
const esm = buildModuleVersion ? pipelineBuild(true, options) : null;
|
||||
|
||||
return [umd, esm].filter((build) => !!build);
|
||||
}
|
||||
|
||||
return pipelineDev(options);
|
||||
};
|
||||
|
||||
module.exports = createConfig;
|
||||
Reference in New Issue
Block a user