mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-05-17 03:59:39 +03:00
improve structure & switch to yarn
This commit is contained in:
+3
-2
@@ -1,5 +1,6 @@
|
||||
node_modules
|
||||
coverage
|
||||
dist
|
||||
__build__
|
||||
types
|
||||
.build
|
||||
.coverage
|
||||
.pptr
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
const resolve = require('./resolve.config');
|
||||
const puppeteerRollupConfig = require('./config/jest-puppeteer.rollup.config.js');
|
||||
|
||||
module.exports = {
|
||||
extends: ['plugin:@typescript-eslint/recommended', 'plugin:react/recommended', 'airbnb', 'prettier'],
|
||||
@@ -69,7 +70,7 @@ module.exports = {
|
||||
'no-void': 'off',
|
||||
'no-empty-function': 'off',
|
||||
'no-new-func': 'off',
|
||||
'import/no-unresolved': ['error', { ignore: ['./__build__/build.html$'] }],
|
||||
'import/no-unresolved': ['error', { ignore: [`./${puppeteerRollupConfig.build}/${puppeteerRollupConfig.html.output}$`] }],
|
||||
},
|
||||
globals: {
|
||||
page: true,
|
||||
|
||||
+3
-5
@@ -4,11 +4,9 @@
|
||||
node_modules/
|
||||
|
||||
# generated
|
||||
coverage/
|
||||
__build__/
|
||||
|
||||
# coverage
|
||||
/.nyc_output
|
||||
.build/
|
||||
.coverage/
|
||||
.pptr/
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
node_modules
|
||||
coverage
|
||||
dist
|
||||
types
|
||||
.coverage
|
||||
.build
|
||||
.pptr
|
||||
@@ -12,7 +12,7 @@ class PuppeteerRollupEnvironment extends PuppeteerEnvironment {
|
||||
|
||||
async setup() {
|
||||
// setup
|
||||
await setupRollupTest(this.ctx.testPath, this.cfg.cache, this.cfg.cacheDirectory);
|
||||
await setupRollupTest(this.cfg.rootDir, this.ctx.testPath, this.cfg.cache && this.cfg.cacheDirectory);
|
||||
await super.setup();
|
||||
|
||||
// coverage
|
||||
@@ -24,7 +24,7 @@ class PuppeteerRollupEnvironment extends PuppeteerEnvironment {
|
||||
// coverage
|
||||
const { page } = this.global;
|
||||
const [jsCoverage, cssCoverage] = await Promise.all([page.coverage.stopJSCoverage(), page.coverage.stopCSSCoverage()]);
|
||||
pti.write([...jsCoverage, ...cssCoverage], { includeHostname: true, storagePath: './.nyc_output' });
|
||||
pti.write([...jsCoverage, ...cssCoverage], { includeHostname: true, storagePath: './.pptr' });
|
||||
|
||||
// cleanup
|
||||
cleanupRollupTest(this.ctx.testPath, this.cfg.cache);
|
||||
@@ -1,5 +1,5 @@
|
||||
module.exports = {
|
||||
build: '__build__',
|
||||
build: '.build',
|
||||
html: {
|
||||
input: 'index.html',
|
||||
output: 'build.html',
|
||||
@@ -5,10 +5,9 @@ const del = require('del');
|
||||
const rollup = require('rollup');
|
||||
const rollupPluginHtml = require('@rollup/plugin-html');
|
||||
const rollupPluginStyles = require('rollup-plugin-styles');
|
||||
const rollupConfig = require('./rollup.config.js');
|
||||
const resolve = require('./resolve.config.json');
|
||||
const config = require('./jest-puppeteer.rollup.config.js');
|
||||
const deploymentConfig = require('./jest-puppeteer.rollup.config.js');
|
||||
|
||||
const rollupConfigName = 'rollup.config.js';
|
||||
const rollupNodeEnv = 'build';
|
||||
const cacheFilePrefix = 'jest-puppeteer-overlayscrollbars-cache-';
|
||||
const cacheEncoding = 'utf8';
|
||||
@@ -66,7 +65,7 @@ const getAllFilesFrom = (dir, except) => {
|
||||
|
||||
const createCacheObj = (testPath) => {
|
||||
const testFileName = path.basename(testPath);
|
||||
const testFiles = getAllFilesFrom(path.dirname(testPath), [config.build, testFileName]);
|
||||
const testFiles = getAllFilesFrom(path.dirname(testPath), [deploymentConfig.build, testFileName]);
|
||||
const obj = {};
|
||||
|
||||
testFiles.forEach((dir) => {
|
||||
@@ -91,43 +90,32 @@ const filesChanged = (testPath, cacheDir) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
const getRollupInfos = (testPath) => {
|
||||
const projectRootPath = path.resolve(__dirname, resolve.projectRoot);
|
||||
const setupRollupTest = async (rootDir, testPath, cacheDir) => {
|
||||
const testDir = path.dirname(testPath);
|
||||
const input = path.resolve(testDir, config.js.input);
|
||||
const dist = path.resolve(testDir, config.build);
|
||||
const testName = path.basename(testDir);
|
||||
const changed = cacheDir ? filesChanged(testPath, cacheDir) : true;
|
||||
const buildFolderExists = fs.existsSync(path.resolve(testDir, deploymentConfig.build));
|
||||
|
||||
return {
|
||||
projectRootPath,
|
||||
testDir,
|
||||
testName,
|
||||
input,
|
||||
dist,
|
||||
};
|
||||
};
|
||||
|
||||
const setupRollupTest = async (testPath, cache, cacheDir) => {
|
||||
const { projectRootPath, input, dist, testName, testDir } = getRollupInfos(testPath);
|
||||
const changed = !cache || filesChanged(testPath, cacheDir);
|
||||
|
||||
if (changed || !fs.existsSync(path.resolve(testDir, config.build))) {
|
||||
const testPathSplit = path.relative(projectRootPath, testPath).split(path.sep);
|
||||
if (testPathSplit.length > 0) {
|
||||
const [project] = testPathSplit;
|
||||
if (changed || !buildFolderExists) {
|
||||
const env = process.env.NODE_ENV;
|
||||
|
||||
try {
|
||||
process.env.NODE_ENV = rollupNodeEnv;
|
||||
const htmlFilePath = path.resolve(testDir, config.html.input);
|
||||
|
||||
const rollupConfigPath = path.resolve(rootDir, rollupConfigName);
|
||||
|
||||
if (fs.existsSync(rollupConfigPath)) {
|
||||
const rollupConfig = require(rollupConfigPath); // eslint-disable-line
|
||||
|
||||
if (typeof rollupConfig === 'function') {
|
||||
try {
|
||||
const htmlFilePath = path.resolve(testDir, deploymentConfig.html.input);
|
||||
const htmlFileContent = fs.existsSync(htmlFilePath) ? fs.readFileSync(htmlFilePath, 'utf8') : null;
|
||||
let rollupConfigObj = rollupConfig(
|
||||
{ 'config-project': project },
|
||||
{
|
||||
overwrite: {
|
||||
input,
|
||||
dist,
|
||||
file: config.js.output,
|
||||
|
||||
let rollupConfigObj = rollupConfig(undefined, {
|
||||
project: rootDir,
|
||||
overwrite: (rollupConfigDefaults) => ({
|
||||
input: path.resolve(testDir, deploymentConfig.js.input),
|
||||
dist: path.resolve(testDir, deploymentConfig.build),
|
||||
file: deploymentConfig.js.output,
|
||||
types: null,
|
||||
minVersions: false,
|
||||
esmBuild: false,
|
||||
@@ -135,20 +123,18 @@ const setupRollupTest = async (testPath, cache, cacheDir) => {
|
||||
name: testName,
|
||||
pipeline: [
|
||||
rollupPluginStyles(),
|
||||
...rollupConfig.defaults.pipeline,
|
||||
...rollupConfigDefaults.pipeline,
|
||||
rollupPluginHtml({
|
||||
title: `Jest-Puppeteer: ${testName}`,
|
||||
fileName: config.html.output,
|
||||
fileName: deploymentConfig.html.output,
|
||||
template: genHtmlTemplateFunc(htmlFileContent),
|
||||
meta: [{ charset: 'utf-8' }, { 'http-equiv': 'X-UA-Compatible', content: 'IE=edge' }],
|
||||
}),
|
||||
],
|
||||
},
|
||||
}),
|
||||
silent: true,
|
||||
fast: true,
|
||||
check: false,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (!Array.isArray(rollupConfigObj)) {
|
||||
rollupConfigObj = [rollupConfigObj];
|
||||
@@ -173,15 +159,16 @@ const setupRollupTest = async (testPath, cache, cacheDir) => {
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
process.env.NODE_ENV = env;
|
||||
}
|
||||
}
|
||||
|
||||
process.env.NODE_ENV = env;
|
||||
}
|
||||
};
|
||||
|
||||
const cleanupRollupTest = (testPath, cache) => {
|
||||
if (!cache) {
|
||||
const { dist } = getRollupInfos(testPath);
|
||||
del(dist);
|
||||
del(path.resolve(path.dirname(testPath), deploymentConfig.build));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,6 +3,6 @@ const express = require('express');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(express.static(path.join(__dirname, '.')));
|
||||
app.use(express.static(path.join(__dirname, '../')));
|
||||
|
||||
app.listen(process.env.TEST_SERVER_PORT);
|
||||
@@ -0,0 +1,10 @@
|
||||
const path = require('path');
|
||||
const jestPuppeteerConfig = require('../jest-puppeteer.config.base');
|
||||
|
||||
module.exports = {
|
||||
process: (src, filePath, config) => {
|
||||
const deploymentPath = path.relative(path.dirname(config.globals.baseConfig), filePath);
|
||||
const split = deploymentPath.split(path.sep);
|
||||
return `module.exports = ${JSON.stringify(`http://localhost:${jestPuppeteerConfig.server.port}/${path.posix.join(...split)}`)}`;
|
||||
},
|
||||
};
|
||||
@@ -1,5 +1,8 @@
|
||||
const path = require('path');
|
||||
|
||||
const { TEST_SERVER_PORT } = process.env;
|
||||
const port = TEST_SERVER_PORT ? Number(TEST_SERVER_PORT) : 8080;
|
||||
const testServerPath = path.resolve(__dirname, './config/jest-test-server.js');
|
||||
|
||||
process.env.TEST_SERVER_PORT = port;
|
||||
|
||||
@@ -7,7 +10,7 @@ module.exports = {
|
||||
browser: 'chromium',
|
||||
browserContext: 'incognito',
|
||||
server: {
|
||||
command: `cross-env TEST_SERVER_PORT=${port} node jest-test-server`,
|
||||
command: `cross-env TEST_SERVER_PORT=${port} node ${testServerPath}`,
|
||||
port,
|
||||
launchTimeout: 4000,
|
||||
},
|
||||
@@ -1,11 +0,0 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
process: (src, filePath) => {
|
||||
const deploymentPath = path.relative(__dirname, filePath);
|
||||
const split = deploymentPath.split(path.sep);
|
||||
const { TEST_SERVER_PORT } = process.env;
|
||||
|
||||
return `module.exports = ${JSON.stringify(`http://localhost:${TEST_SERVER_PORT}/${path.posix.join(...split)}`)}`;
|
||||
},
|
||||
};
|
||||
@@ -1,5 +1,9 @@
|
||||
const path = require('path');
|
||||
const resolve = require('./resolve.config');
|
||||
const puppeteerRollupConfig = require('./jest-puppeteer.rollup.config.js');
|
||||
const puppeteerRollupConfig = require('./config/jest-puppeteer.rollup.config.js');
|
||||
|
||||
const testEnvironmentPath = path.resolve(__dirname, './config/jest-puppeteer.env.js');
|
||||
const testServerLoaderPath = path.resolve(__dirname, './config/jest-test-server.loader.js');
|
||||
|
||||
// For a detailed explanation regarding each configuration property, visit:
|
||||
// https://jestjs.io/docs/en/configuration.html
|
||||
@@ -7,31 +11,34 @@ const puppeteerRollupConfig = require('./jest-puppeteer.rollup.config.js');
|
||||
const base = {
|
||||
clearMocks: true,
|
||||
collectCoverage: true,
|
||||
coverageDirectory: 'coverage',
|
||||
coverageDirectory: './.coverage',
|
||||
moduleDirectories: resolve.directories,
|
||||
moduleFileExtensions: resolve.extensions.map((ext) => ext.replace(/\./, '')),
|
||||
testPathIgnorePatterns: ['\\\\node_modules\\\\'],
|
||||
verbose: true,
|
||||
globals: {
|
||||
baseConfig: __filename,
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
...base,
|
||||
projects: [
|
||||
{
|
||||
...base,
|
||||
displayName: 'jsdom',
|
||||
testMatch: ['**/__tests__/jsdom/**/*.test.[jt]s?(x)'],
|
||||
testMatch: ['**/tests/jsdom/**/*.test.[jt]s?(x)'],
|
||||
},
|
||||
{
|
||||
...base,
|
||||
preset: 'jest-puppeteer',
|
||||
displayName: 'puppeteer',
|
||||
setupFilesAfterEnv: ['expect-puppeteer'],
|
||||
testMatch: ['**/__tests__/puppeteer/**/*.test.[jt]s?(x)'],
|
||||
testEnvironment: './jest-puppeteer.env.js',
|
||||
testMatch: ['**/tests/puppeteer/**/*.test.[jt]s?(x)'],
|
||||
testEnvironment: testEnvironmentPath,
|
||||
coveragePathIgnorePatterns: ['/node_modules/', `/${puppeteerRollupConfig.build}/`],
|
||||
transform: {
|
||||
'^.+\\.[jt]sx?$': 'babel-jest',
|
||||
[`^.+${puppeteerRollupConfig.build}.+${puppeteerRollupConfig.html.output}?$`]: './jest-test-server.loader.js',
|
||||
[`^.+${puppeteerRollupConfig.build}.+${puppeteerRollupConfig.html.output}?$`]: testServerLoaderPath,
|
||||
},
|
||||
},
|
||||
],
|
||||
Generated
-14764
File diff suppressed because it is too large
Load Diff
+4
-2
@@ -55,8 +55,10 @@
|
||||
"utf-8-validate": "^5.0.2"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest --coverage --runInBand --detectOpenHandles",
|
||||
"build": "cross-env NODE_ENV=build rollup -c --config-project='overlayscrollbars' && cross-env NODE_ENV=build rollup -c --config-project='overlayscrollbars-jquery'",
|
||||
"test": "cd ./packages/overlayscrollbars && yarn test",
|
||||
"test:jsdom": "cd ./packages/overlayscrollbars && yarn test:jsdom",
|
||||
"test:pptr": "cd ./packages/overlayscrollbars && yarn test:pptr",
|
||||
"build": "cd ./packages/overlayscrollbars && yarn build",
|
||||
"lint": "npx eslint --fix ."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = require('../../babel.config.base');
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"name": "OverlayScrollbars",
|
||||
"exports": "auto",
|
||||
"globals": {
|
||||
"jquery": "jQuery"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
? (module.exports = factory())
|
||||
: typeof define === 'function' && define.amd
|
||||
? define(factory)
|
||||
: ((global = global || self), (global.OverlayScrollbars = factory()));
|
||||
: ((global = typeof globalThis !== 'undefined' ? globalThis : global || self), (global.OverlayScrollbars = factory()));
|
||||
})(this, function () {
|
||||
'use strict';
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
module.exports = require('../../jest-puppeteer.config.base');
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = require('../../jest.config.base');
|
||||
@@ -1,5 +1,12 @@
|
||||
{
|
||||
"name": "overlayscrollbars",
|
||||
"private": true,
|
||||
"description": "OverlayScrollbars version 2",
|
||||
"version": "0.0.1"
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"test": "jest --coverage --runInBand --detectOpenHandles",
|
||||
"test:jsdom": "jest --coverage --runInBand --detectOpenHandles --selectProjects jsdom",
|
||||
"test:pptr": "jest --coverage --runInBand --detectOpenHandles --selectProjects puppeteer",
|
||||
"build": "cross-env NODE_ENV=build rollup -c"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
const base = require('../../rollup.config.base');
|
||||
|
||||
const config = {
|
||||
name: 'OverlayScrollbars',
|
||||
exports: 'auto',
|
||||
globals: {
|
||||
jquery: 'jQuery',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = (_, ...args) => base(config, ...args);
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import url from './__build__/build.html';
|
||||
import url from './.build/build.html';
|
||||
|
||||
describe('Environment', () => {
|
||||
beforeAll(async () => {
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
{
|
||||
"extensions": [".json", ".js", "jsx", ".mjs", ".ts", ".tsx"],
|
||||
"directories": ["node_modules", "src"],
|
||||
"projectRoot": "./packages"
|
||||
"directories": ["node_modules", "src"]
|
||||
}
|
||||
|
||||
@@ -9,13 +9,12 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const resolve = require('./resolve.config.json');
|
||||
|
||||
const buildConfigNames = ['build.config.js', 'build.config.json'];
|
||||
const buildConfigDefaults = {
|
||||
const rollupConfigDefaults = {
|
||||
input: './src/index',
|
||||
src: './src',
|
||||
dist: './dist',
|
||||
types: './types',
|
||||
tests: './__tests__',
|
||||
tests: './tests',
|
||||
cache: [],
|
||||
minVersions: true,
|
||||
sourcemap: true,
|
||||
@@ -60,30 +59,31 @@ const appendExtension = (file) => {
|
||||
return file;
|
||||
};
|
||||
|
||||
const getBuildConfig = (projectPath) => {
|
||||
const buildConfigName = buildConfigNames.find((name) => fs.existsSync(path.resolve(projectPath, name)));
|
||||
return buildConfigName ? path.resolve(projectPath, buildConfigName) : '';
|
||||
};
|
||||
|
||||
const resolvePath = (projectPath, rPath, appendExt) => {
|
||||
const result = rPath ? (path.isAbsolute(rPath) ? rPath : path.resolve(projectPath, rPath)) : null;
|
||||
const resolvePath = (basePath, pathToResolve, appendExt) => {
|
||||
const result = pathToResolve ? (path.isAbsolute(pathToResolve) ? pathToResolve : path.resolve(basePath, pathToResolve)) : null;
|
||||
return result && appendExt ? appendExtension(result) : result;
|
||||
};
|
||||
|
||||
const rollupConfig = (config, { overwrite: overwriteBuildConfig, silent, fast, check = true } = {}) => {
|
||||
const { 'config-project': project } = config;
|
||||
const resolveConfig = (config) => {
|
||||
if (typeof config === 'function') {
|
||||
return config(rollupConfigDefaults) || {};
|
||||
}
|
||||
return config;
|
||||
};
|
||||
|
||||
const projectPath = path.resolve(__dirname, resolve.projectRoot, project);
|
||||
const packageJSONPath = path.resolve(projectPath, 'package.json');
|
||||
const tsconfigJSONPath = path.resolve(projectPath, 'tsconfig.json');
|
||||
const buildConfigPath = getBuildConfig(projectPath);
|
||||
const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, silent, fast } = {}) => {
|
||||
const projectPath = resolvePath(__dirname, project);
|
||||
const projectName = path.basename(project);
|
||||
|
||||
const packageJSONPath = resolvePath(projectPath, 'package.json');
|
||||
const tsconfigJSONPath = resolvePath(projectPath, 'tsconfig.json');
|
||||
|
||||
const isTypeScriptProject = fs.existsSync(tsconfigJSONPath);
|
||||
const buildConfig = {
|
||||
...buildConfigDefaults,
|
||||
...{ name: project, file: project },
|
||||
...require(buildConfigPath),
|
||||
...(overwriteBuildConfig || {}),
|
||||
...rollupConfigDefaults,
|
||||
...{ name: projectName, file: projectName },
|
||||
...resolveConfig(config),
|
||||
...resolveConfig(overwrite),
|
||||
};
|
||||
|
||||
const { input, src, dist, types, tests, file, cache, minVersions, sourcemap, esmBuild, name, exports, globals, pipeline } = buildConfig;
|
||||
@@ -127,7 +127,8 @@ const rollupConfig = (config, { overwrite: overwriteBuildConfig, silent, fast, c
|
||||
commonjs: rollupCommonjs(),
|
||||
typescript: isTypeScriptProject
|
||||
? rollupTypescript({
|
||||
check,
|
||||
check: !fast,
|
||||
clean: true,
|
||||
useTsconfigDeclarationDir: true,
|
||||
tsconfig: tsconfigJSONPath,
|
||||
tsconfigOverride: {
|
||||
@@ -224,6 +225,4 @@ const rollupConfig = (config, { overwrite: overwriteBuildConfig, silent, fast, c
|
||||
return builds;
|
||||
};
|
||||
|
||||
rollupConfig.defaults = buildConfigDefaults;
|
||||
|
||||
module.exports = rollupConfig;
|
||||
Reference in New Issue
Block a user