improve build and repo setup

This commit is contained in:
Rene Haas
2022-10-27 10:03:00 +02:00
parent 3ecb32b349
commit f00616a5eb
8 changed files with 25 additions and 43 deletions
+1
View File
@@ -90,6 +90,7 @@ module.exports = {
'./examples/**/tsconfig.json', './examples/**/tsconfig.json',
'./website/**/tsconfig.json', './website/**/tsconfig.json',
'./local/**/tsconfig.json', './local/**/tsconfig.json',
'./tsconfig.json',
], ],
}, },
env: { env: {
+2 -2
View File
@@ -37,13 +37,13 @@ module.exports = (resolve, options) => {
const { rollup, paths, versions, alias, extractStyles, banner } = options; const { rollup, paths, versions, alias, extractStyles, banner } = options;
const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup; const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup;
const { name, file, globals, exports, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput; const { name, file, globals, exports, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput;
const { dist: distPath } = paths; const { js: jsPath } = paths;
const sourcemap = rawSourcemap; const sourcemap = rawSourcemap;
return versions return versions
.map(({ format, generatedCode, file: filePathOverride, extension, minifiedVersion }) => { .map(({ format, generatedCode, file: filePathOverride, extension, minifiedVersion }) => {
const needsGlobals = format === 'umd' || format === 'iife'; const needsGlobals = format === 'umd' || format === 'iife';
const filePath = path.resolve(distPath, `${file}${extension || '.js'}`); const filePath = path.resolve(jsPath, `${file}${extension || '.js'}`);
const baseOutput = { const baseOutput = {
...outputConfig, ...outputConfig,
+2 -2
View File
@@ -12,7 +12,7 @@ module.exports = (resolve, options) => {
const { rollup, paths, alias, extractStyles, banner } = options; const { rollup, paths, alias, extractStyles, banner } = options;
const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup; const { output: rollupOutput, input, plugins = [], ...rollupOptions } = rollup;
const { file, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput; const { file, sourcemap: rawSourcemap, ...outputConfig } = rollupOutput;
const { dist: distPath } = paths; const { js: jsPath } = paths;
const sourcemap = rawSourcemap; const sourcemap = rawSourcemap;
const output = { const output = {
@@ -20,7 +20,7 @@ module.exports = (resolve, options) => {
sourcemap, sourcemap,
format: 'esm', format: 'esm',
generatedCode: 'es2015', generatedCode: 'es2015',
file: path.resolve(distPath, `${file}.js`), file: path.resolve(jsPath, `${file}.js`),
}; };
return { return {
+2 -3
View File
@@ -1,5 +1,4 @@
const fs = require('fs'); const fs = require('fs');
const { basename } = require('path');
const path = require('path'); const path = require('path');
const rollupDts = require('rollup-plugin-dts'); const rollupDts = require('rollup-plugin-dts');
@@ -27,7 +26,7 @@ module.exports = (resolve, options) => {
plugins: [rollupTs(input, true)], plugins: [rollupTs(input, true)],
}, },
{ {
input: path.join(typesPath, `${basename(input).replace('.ts', '.d.ts')}`), input: path.join(typesPath, `${path.basename(input).replace('.ts', '.d.ts')}`),
output: { output: {
file: dtsOutput, file: dtsOutput,
}, },
@@ -48,7 +47,7 @@ module.exports = (resolve, options) => {
writeBundle() { writeBundle() {
const filesAndDirs = fs.readdirSync(typesPath); const filesAndDirs = fs.readdirSync(typesPath);
filesAndDirs.forEach((fileOrDir) => { filesAndDirs.forEach((fileOrDir) => {
if (basename(fileOrDir) !== basename(dtsOutput)) { if (path.basename(fileOrDir) !== path.basename(dtsOutput)) {
fs.rmSync(path.join(typesPath, fileOrDir), { recursive: true }); fs.rmSync(path.join(typesPath, fileOrDir), { recursive: true });
} }
}); });
+8 -4
View File
@@ -30,6 +30,7 @@ const resolvePath = (basePath, pathToResolve, appendExt) => {
const mergeAndResolveOptions = (userOptions) => { const mergeAndResolveOptions = (userOptions) => {
const { const {
outDir: defaultOutDir,
paths: defaultPaths, paths: defaultPaths,
versions: defaultVersions, versions: defaultVersions,
alias: defaultAlias, alias: defaultAlias,
@@ -42,6 +43,7 @@ const mergeAndResolveOptions = (userOptions) => {
} = defaultOptions; } = defaultOptions;
const { const {
project, project,
outDir: rawOutDir,
paths: rawPaths = {}, paths: rawPaths = {},
alias: rawAlias = {}, alias: rawAlias = {},
rollup: rawRollup = {}, rollup: rawRollup = {},
@@ -64,6 +66,7 @@ const mergeAndResolveOptions = (userOptions) => {
banner: rawBanner ?? defaultBanner, banner: rawBanner ?? defaultBanner,
versions: rawVersions ?? defaultVersions, versions: rawVersions ?? defaultVersions,
useEsbuild: rawUseEsbuild ?? defaultUseEsbuild, useEsbuild: rawUseEsbuild ?? defaultUseEsbuild,
outDir: rawOutDir ?? defaultOutDir,
paths: { paths: {
...defaultPaths, ...defaultPaths,
...rawPaths, ...rawPaths,
@@ -83,13 +86,14 @@ const mergeAndResolveOptions = (userOptions) => {
}, },
}, },
}; };
const { dist, types, styles } = mergedOptions.paths; const { outDir, paths } = mergedOptions;
const { js, types, styles } = paths;
const pluginFromFn = (plugin) => const pluginFromFn = (plugin) =>
typeof plugin === 'function' ? plugin(mergedOptions, workspaceRoot, workspaces) : plugin; typeof plugin === 'function' ? plugin(mergedOptions, workspaceRoot, workspaces) : plugin;
mergedOptions.paths.dist = resolvePath(projectPath, dist); paths.js = resolvePath(projectPath, path.join(outDir, js));
mergedOptions.paths.types = resolvePath(projectPath, types); paths.types = resolvePath(projectPath, path.join(outDir, types));
mergedOptions.paths.styles = resolvePath(projectPath, styles); paths.styles = resolvePath(projectPath, path.join(outDir, styles));
mergedOptions.rollup.input = resolvePath(projectPath, mergedOptions.rollup.input, true); mergedOptions.rollup.input = resolvePath(projectPath, mergedOptions.rollup.input, true);
mergedOptions.rollup.output = { mergedOptions.rollup.output = {
+2 -1
View File
@@ -3,8 +3,9 @@ module.exports = {
verbose: false, verbose: false,
banner: null, banner: null,
useEsbuild: false, useEsbuild: false,
outDir: './dist',
paths: { paths: {
dist: './dist', js: '.',
types: './types', types: './types',
styles: './styles', styles: './styles',
}, },
@@ -18,7 +18,7 @@ const portRange = {
}; };
const paths = { const paths = {
dist: './.build', outDir: './.build',
input: './index.browser', input: './index.browser',
html: './index.html', html: './index.html',
}; };
@@ -30,7 +30,7 @@ module.exports = (testDir, useEsbuild, dev) => {
}, {}); }, {});
const { min, max } = portRange; const { min, max } = portRange;
const { dist, input, html: htmlPath } = testPaths; const { outDir, input, html: htmlPath } = testPaths;
const name = path.basename(testDir); const name = path.basename(testDir);
const htmlName = `${name}.html`; const htmlName = `${name}.html`;
const port = Math.floor(Math.random() * (max - min + 1) + min); const port = Math.floor(Math.random() * (max - min + 1) + min);
@@ -43,9 +43,7 @@ module.exports = (testDir, useEsbuild, dev) => {
banner: testDir, banner: testDir,
extractStyle: false, extractStyle: false,
extractTypes: false, extractTypes: false,
paths: { outDir,
dist,
},
versions: [ versions: [
{ {
format: 'iife', format: 'iife',
@@ -53,30 +51,6 @@ module.exports = (testDir, useEsbuild, dev) => {
minifiedVersion: false, minifiedVersion: false,
}, },
], ],
// if the import would be 'overlayscrollbars' and the package name is also 'overlayscrollbars' esbuild needs an alias to resolve it correctly
alias: (workspaceRoot, workspaces, resolvePath) =>
workspaces.reduce((obj, resolvedPath) => {
const absolutePath = path.resolve(workspaceRoot, resolvedPath);
try {
// eslint-disable-next-line import/no-dynamic-require, global-require
const projTsConfig = require(`${path.resolve(
workspaceRoot,
resolvedPath
)}/tsconfig.json`);
// eslint-disable-next-line import/no-dynamic-require, global-require
const projPackageJson = require(`${path.resolve(
workspaceRoot,
resolvedPath
)}/package.json`);
const { name: projectName } = projPackageJson;
const { compilerOptions } = projTsConfig;
const { baseUrl } = compilerOptions;
obj[projectName] = resolvePath(absolutePath, path.join(baseUrl, projectName), true);
} catch {}
return obj;
}, {}),
rollup: { rollup: {
input, input,
context: 'this', context: 'this',
@@ -91,7 +65,7 @@ module.exports = (testDir, useEsbuild, dev) => {
), ),
rollupPluginServe({ rollupPluginServe({
port, port,
contentBase: dist, contentBase: outDir,
historyApiFallback: `/${htmlName}`, historyApiFallback: `/${htmlName}`,
host: '127.0.0.1', host: '127.0.0.1',
verbose: isDev, verbose: isDev,
@@ -102,7 +76,7 @@ module.exports = (testDir, useEsbuild, dev) => {
isDev && rollupAdditionalWatchFiles([htmlPath]), isDev && rollupAdditionalWatchFiles([htmlPath]),
isDev && isDev &&
rollupPluginLivereload({ rollupPluginLivereload({
watch: dist, watch: outDir,
port: port - 1, port: port - 1,
verbose: false, verbose: false,
}), }),
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "@~local/tsconfig"
}