mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-08 15:52:29 +03:00
fix npm ci
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
import glob from 'fast-glob';
|
||||
import { esbuild } from '@~local-docs/esbuild';
|
||||
import { esbuild } from '@~local/esbuild';
|
||||
|
||||
const processArgs = process.argv.slice(2);
|
||||
const watch = processArgs.includes('-w');
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"private": true,
|
||||
"sideEffects": false,
|
||||
"main": "src/esbuild.js",
|
||||
"type": "module"
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
import esbuildOriginal from 'esbuild';
|
||||
import { writeOnlyChanges } from './writeOnlyChanges.js';
|
||||
import { esbuildClearOldBuild } from './plugins/clearOldBuild.js';
|
||||
import { esbuildPluginStyles } from './plugins/styles.js';
|
||||
import { esbuildPluginTailwind } from './plugins/tailwind.js';
|
||||
import { esbuildPluginExternal } from './plugins/external.js';
|
||||
|
||||
const changesMap = new Map();
|
||||
const writeBuild = async (build) => {
|
||||
if (build?.outputFiles) {
|
||||
await writeOnlyChanges(build.outputFiles, changesMap);
|
||||
}
|
||||
};
|
||||
|
||||
export const esbuild = async (options = {}, { tailwindConfig = './tailwind.config.js' } = {}) => {
|
||||
const buildOptions = {
|
||||
bundle: true,
|
||||
splitting: true,
|
||||
allowOverwrite: true,
|
||||
incremental: true,
|
||||
metafile: true,
|
||||
write: false,
|
||||
format: 'esm',
|
||||
platform: 'node',
|
||||
chunkNames: 'chunks/[name]-[hash]',
|
||||
assetNames: 'assets/[dir]/[name]',
|
||||
entryNames: '[dir]/[name]',
|
||||
jsx: 'automatic',
|
||||
...options,
|
||||
external: [...(options.external || [])],
|
||||
watch: options.watch && {
|
||||
async onRebuild(_, rebuildResult) {
|
||||
await writeBuild(rebuildResult);
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
esbuildClearOldBuild(),
|
||||
esbuildPluginStyles({
|
||||
sassFilesRegex: /\.s[ac]ss$/,
|
||||
cssFilesRegex: /\.css$/,
|
||||
cssModulesRegex: /\.module\.\S+$/,
|
||||
}),
|
||||
esbuildPluginTailwind({
|
||||
tailwindConfig,
|
||||
tailwindCssFileRegex: /tailwind.*\.css$/,
|
||||
}),
|
||||
esbuildPluginExternal(),
|
||||
...(options.plugins || []),
|
||||
],
|
||||
};
|
||||
const build = await esbuildOriginal.build(buildOptions);
|
||||
await writeBuild(build);
|
||||
return build;
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
export const esbuildClearOldBuild = () => {
|
||||
let cleared = false;
|
||||
return {
|
||||
name: 'clearOldBuild',
|
||||
setup(build) {
|
||||
const initBuildOptions = build.initialOptions;
|
||||
|
||||
build.onStart(() => {
|
||||
if (!cleared && initBuildOptions.outdir) {
|
||||
fs.rmSync(path.resolve(initBuildOptions.outdir), { recursive: true, force: true });
|
||||
cleared = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -1,25 +0,0 @@
|
||||
const externalRegex = /node_modules/;
|
||||
|
||||
export const esbuildPluginExternal = () => ({
|
||||
name: 'external',
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /.*/, namespace: 'file' }, async (args) => {
|
||||
const { resolveDir, kind } = args;
|
||||
|
||||
if (kind !== 'entry-point') {
|
||||
const { path: resolvedPath } = await build.resolve(args.path, {
|
||||
resolveDir,
|
||||
kind,
|
||||
namespace: 'resolve-pls',
|
||||
});
|
||||
|
||||
if (externalRegex.test(resolvedPath)) {
|
||||
return {
|
||||
path: args.path,
|
||||
external: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -1,243 +0,0 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import crypto from 'node:crypto';
|
||||
import sass from 'sass';
|
||||
import esbuild from 'esbuild';
|
||||
import { writeOnlyChanges } from '../writeOnlyChanges.js';
|
||||
|
||||
const externalRegex = /node_modules/;
|
||||
const isExtendedLengthPath = /^\\\\\?\\/;
|
||||
|
||||
const normalizePathSlashes = (pathToNormalize) =>
|
||||
isExtendedLengthPath.test(pathToNormalize)
|
||||
? pathToNormalize
|
||||
: pathToNormalize.replace(/\\/g, '/');
|
||||
|
||||
const getHash = (content) => crypto.createHash('sha1').update(content).digest('hex');
|
||||
|
||||
export const esbuildPluginStyles = (options) => {
|
||||
const changesMap = new Map();
|
||||
const {
|
||||
cssBuildOptions = {},
|
||||
cssModulesRegex = /\.module\.\S+$/,
|
||||
sassFilesRegex = /\.s[ac]ss$/,
|
||||
cssFilesRegex = /\.css$/,
|
||||
} = options;
|
||||
const sassCache = new Map();
|
||||
const esbuildCache = new Map();
|
||||
|
||||
const replaceExtension = (filePath, replacement = '') => {
|
||||
const replacementRegex = /\.[^.]*$/;
|
||||
return filePath.replace(
|
||||
replacementRegex,
|
||||
typeof replacement === 'function'
|
||||
? replacement((filePath.match(replacementRegex) || [])[0] || '')
|
||||
: replacement
|
||||
);
|
||||
};
|
||||
|
||||
const resolveFile = async (build, onResolveArgs) => {
|
||||
const { resolveDir, importer } = onResolveArgs;
|
||||
const { path: resolvedPath } = await build.resolve(onResolveArgs.path, {
|
||||
resolveDir,
|
||||
importer,
|
||||
kind: 'entry-point',
|
||||
namespace: 'resolve-pls',
|
||||
});
|
||||
const external = externalRegex.test(resolvedPath);
|
||||
|
||||
return [resolvedPath, external];
|
||||
};
|
||||
|
||||
const resolveProcessedCss = (args) => ({
|
||||
path: args.path,
|
||||
namespace: 'css-processed',
|
||||
pluginData: args.pluginData,
|
||||
});
|
||||
|
||||
const setupSassResolve = (build) => {
|
||||
build.onResolve({ filter: sassFilesRegex, namespace: 'file' }, async (args) => {
|
||||
const [resolvedPath, external] = await resolveFile(build, args);
|
||||
|
||||
return external
|
||||
? {
|
||||
path: args.path,
|
||||
external: true,
|
||||
}
|
||||
: {
|
||||
path: cssModulesRegex.test(resolvedPath)
|
||||
? `${resolvedPath}.module.css`
|
||||
: `${resolvedPath}.css`,
|
||||
namespace: 'sass',
|
||||
pluginData: {
|
||||
resolvedPath,
|
||||
},
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const setupCssResolve = (build) => {
|
||||
build.onResolve({ filter: cssFilesRegex, namespace: 'file' }, async (args) => {
|
||||
const [resolvedPath, external] = await resolveFile(build, args);
|
||||
|
||||
return external
|
||||
? {
|
||||
path: args.path,
|
||||
external: true,
|
||||
}
|
||||
: {
|
||||
path: resolvedPath,
|
||||
namespace: 'css',
|
||||
pluginData: {
|
||||
resolvedPath,
|
||||
},
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const transpileSass = (css, filePath) => {
|
||||
const currHash = getHash(css);
|
||||
const [cacheHash] = sassCache.get(filePath) || [];
|
||||
|
||||
if (currHash !== cacheHash) {
|
||||
try {
|
||||
const result = sass.compile(filePath);
|
||||
sassCache.set(filePath, [currHash, result.css]);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
return sassCache.get(filePath)[1] || css;
|
||||
};
|
||||
|
||||
const esbuildCss = async (initialBuildOptions, stdin, filePath) => {
|
||||
const source = stdin.contents;
|
||||
const currHash = getHash(source);
|
||||
const [cacheHash] = esbuildCache.get(filePath) || [];
|
||||
|
||||
if (currHash !== cacheHash) {
|
||||
const finalCssBuildOptions =
|
||||
typeof cssBuildOptions === 'function'
|
||||
? cssBuildOptions(initialBuildOptions)
|
||||
: cssBuildOptions;
|
||||
const { assetNames } = initialBuildOptions;
|
||||
const { outputFiles, metafile, errors, warnings } = await esbuild.build({
|
||||
...initialBuildOptions,
|
||||
stdin,
|
||||
write: false,
|
||||
bundle: true,
|
||||
metafile: true,
|
||||
entryNames: assetNames,
|
||||
entryPoints: [],
|
||||
plugins: [],
|
||||
...finalCssBuildOptions,
|
||||
});
|
||||
|
||||
if (errors?.length) {
|
||||
return {
|
||||
errors,
|
||||
};
|
||||
}
|
||||
|
||||
const { outputs } = metafile;
|
||||
const watchFiles = Object.values(outputs).reduce((arr, { inputs }) => {
|
||||
arr.push(...Object.keys(inputs).map((input) => path.resolve(input)));
|
||||
return arr;
|
||||
}, []);
|
||||
const entry = Object.keys(outputs).find((out) => outputs[out].entryPoint);
|
||||
const entryFile = outputFiles.find((file) =>
|
||||
normalizePathSlashes(file.path).endsWith(normalizePathSlashes(entry))
|
||||
);
|
||||
|
||||
const result = {
|
||||
outputFiles,
|
||||
entryFile,
|
||||
watchFiles,
|
||||
warnings,
|
||||
};
|
||||
|
||||
esbuildCache.set(filePath, [currHash, result]);
|
||||
}
|
||||
|
||||
return esbuildCache.get(filePath)[1];
|
||||
};
|
||||
|
||||
return {
|
||||
name: 'esbuild-plugin-styles',
|
||||
|
||||
async setup(build) {
|
||||
const initBuildOptions = build.initialOptions;
|
||||
|
||||
setupSassResolve(build);
|
||||
setupCssResolve(build);
|
||||
|
||||
// move newly crete stub modules to 'css-processed' namespace
|
||||
build.onResolve({ filter: cssFilesRegex, namespace: 'sass' }, resolveProcessedCss);
|
||||
build.onResolve({ filter: cssFilesRegex, namespace: 'css' }, resolveProcessedCss);
|
||||
|
||||
// resolve asset imports for generated css files
|
||||
build.onResolve({ filter: /.*/, namespace: 'css-processed' }, async (args) =>
|
||||
// since we don't consume them its fine that the imports are wrong
|
||||
({
|
||||
path: args.path,
|
||||
external: true,
|
||||
})
|
||||
);
|
||||
|
||||
build.onLoad({ filter: cssFilesRegex }, async (args) => {
|
||||
const { namespace, pluginData } = args;
|
||||
|
||||
if (namespace === 'css-processed') {
|
||||
const { contents } = pluginData;
|
||||
return {
|
||||
contents,
|
||||
loader: 'copy',
|
||||
resolveDir: path.dirname(args.path),
|
||||
};
|
||||
}
|
||||
|
||||
const { resolvedPath } = pluginData;
|
||||
const fileName = path.basename(resolvedPath);
|
||||
const resolveDir = path.dirname(resolvedPath);
|
||||
const css = await fs.promises.readFile(resolvedPath);
|
||||
const source = namespace === 'sass' ? transpileSass(css, resolvedPath) : css;
|
||||
|
||||
const { outputFiles, entryFile, watchFiles, warnings, errors } = await esbuildCss(
|
||||
initBuildOptions,
|
||||
{
|
||||
contents: source,
|
||||
sourcefile: fileName,
|
||||
resolveDir,
|
||||
loader: 'css',
|
||||
},
|
||||
resolvedPath
|
||||
);
|
||||
|
||||
if (errors) {
|
||||
return {
|
||||
errors,
|
||||
};
|
||||
}
|
||||
|
||||
const entryFilePath = path.resolve(
|
||||
path.dirname(entryFile.path),
|
||||
`${path.basename(replaceExtension(args.path))}${path
|
||||
.basename(entryFile.path)
|
||||
.replace('stdin', '')}`
|
||||
);
|
||||
const adaptedOutputFiles = outputFiles.filter((file) => file !== entryFile);
|
||||
|
||||
await writeOnlyChanges(adaptedOutputFiles, changesMap);
|
||||
|
||||
return {
|
||||
contents: `export { default } from ${JSON.stringify(entryFilePath)};`,
|
||||
resolveDir,
|
||||
watchFiles,
|
||||
warnings,
|
||||
pluginData: {
|
||||
contents: entryFile.contents,
|
||||
},
|
||||
};
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -1,49 +0,0 @@
|
||||
import path from 'node:path';
|
||||
import minimatch from 'minimatch';
|
||||
import postcss from 'postcss';
|
||||
import tailwindcss from 'tailwindcss';
|
||||
|
||||
import { resolveConfig } from '../resolveConfig.js';
|
||||
|
||||
export const esbuildPluginTailwind = ({
|
||||
tailwindCssFileRegex = /tailwind.*\.css$/,
|
||||
tailwindConfig = './tailwind.config.js',
|
||||
} = {}) => ({
|
||||
name: 'tailwind',
|
||||
async setup(build) {
|
||||
const resolvedTailwindConfig = await resolveConfig(tailwindConfig);
|
||||
|
||||
build.onEnd(async (result) => {
|
||||
if (result) {
|
||||
const { metafile, outputFiles } = result;
|
||||
const { inputs } = metafile;
|
||||
const tailwindFile = outputFiles.find(({ path: outputFilePath }) =>
|
||||
tailwindCssFileRegex.test(outputFilePath)
|
||||
);
|
||||
|
||||
if (tailwindFile) {
|
||||
const { path: tailwindFilePath, text: tailwindFileCss } = tailwindFile;
|
||||
const tailwindContentGlobs = (resolvedTailwindConfig?.content || []).filter(
|
||||
(entry) => typeof entry === 'string'
|
||||
);
|
||||
const inputFilePaths = Object.keys(inputs).map((input) => path.resolve(input));
|
||||
const includedFiles = Array.from(
|
||||
new Set(
|
||||
tailwindContentGlobs
|
||||
.map((glob) => minimatch.match(inputFilePaths, glob, { dot: true }))
|
||||
.flat()
|
||||
)
|
||||
);
|
||||
|
||||
const postcssResult = await postcss([
|
||||
tailwindcss({ ...(resolvedTailwindConfig || {}), content: includedFiles }),
|
||||
]).process(tailwindFileCss, {
|
||||
from: tailwindFilePath,
|
||||
});
|
||||
|
||||
tailwindFile.contents = Buffer.from(postcssResult.css);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -1,13 +0,0 @@
|
||||
import url from 'node:url';
|
||||
import path from 'node:path';
|
||||
|
||||
export const resolveConfig = async (configPath) => {
|
||||
if (configPath) {
|
||||
const loadedConfig = (
|
||||
await import(url.pathToFileURL(path.resolve(configPath))).catch(() => ({}))
|
||||
).default;
|
||||
if (loadedConfig) {
|
||||
return loadedConfig;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,25 +0,0 @@
|
||||
import fs from 'node:fs';
|
||||
import crypto from 'node:crypto';
|
||||
import path from 'node:path';
|
||||
|
||||
const getHash = (content) => crypto.createHash('md5').update(content).digest('hex');
|
||||
|
||||
export const writeOnlyChanges = async (outputFiles, changesMap) => {
|
||||
await Promise.all(
|
||||
outputFiles.map(({ path: filepath }) =>
|
||||
fs.promises.mkdir(path.dirname(filepath), { recursive: true })
|
||||
)
|
||||
);
|
||||
await Promise.all(
|
||||
outputFiles.map(({ path: filepath, contents }) => {
|
||||
const currContentsHash = getHash(contents);
|
||||
const cacheHash = changesMap.get(filepath);
|
||||
|
||||
if (cacheHash !== currContentsHash) {
|
||||
changesMap.set(filepath, currContentsHash);
|
||||
return fs.promises.writeFile(filepath, contents);
|
||||
}
|
||||
return null;
|
||||
})
|
||||
);
|
||||
};
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"private": true,
|
||||
"main": "tailwind.config.js"
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
const defaultTheme = require('tailwindcss/defaultTheme');
|
||||
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
theme: {
|
||||
extend: {},
|
||||
container: {
|
||||
center: true,
|
||||
},
|
||||
fontFamily: {
|
||||
sans: ['Noto Sans', ...defaultTheme.fontFamily.sans],
|
||||
},
|
||||
fontWeight: {
|
||||
normal: 400,
|
||||
medium: 600,
|
||||
bold: 800,
|
||||
},
|
||||
screens: {
|
||||
xxs: '374px',
|
||||
xs: '640px',
|
||||
sm: '768px',
|
||||
md: '960px',
|
||||
lg: '1280px',
|
||||
xl: '1440px',
|
||||
xxl: '1536px',
|
||||
},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
||||
Generated
-7418
File diff suppressed because it is too large
Load Diff
@@ -11,8 +11,6 @@
|
||||
"react-dom": "18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@~local-docs/esbuild": "file:./local/esbuild",
|
||||
"@~local-docs/tailwind": "file:./local/tailwind",
|
||||
"@types/node": "18.7.20",
|
||||
"@types/react": "18.0.21",
|
||||
"@types/react-dom": "18.0.6",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
// eslint-disable-next-line global-require
|
||||
presets: [require('@~local-docs/tailwind')],
|
||||
presets: [require('@~local/tailwind')],
|
||||
content: ['**/*.{js,ts,jsx,tsx}'],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user