Skip to content

Commit

Permalink
refactor: Deprecate Rollup strategy.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkobits committed Jul 12, 2023
1 parent 4227901 commit 8cbf9b3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 206 deletions.
49 changes: 30 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@
"@darkobits/log": "^2.0.0-beta.15",
"@darkobits/valida": "^0.1.6",
"@esbuild-plugins/tsconfig-paths": "^0.1.2",
"@rollup/plugin-typescript": "^11.1.2",
"@types/yargs": "^17.0.24",
"camelcase-keys": "^8.0.2",
"cosmiconfig": "^8.2.0",
"deepmerge": "^4.3.1",
"esbuild": "^0.18.11",
"esbuild-node-externals": "^1.8.0",
"fs-extra": "^11.1.1",
"node-version": "^3.0.0",
"read-pkg-up": "^10.0.0",
"rollup": "^3.26.2",
"rollup-plugin-node-externals": "^6.1.1",
"tsconfck": "^2.1.1",
"yargs": "^17.7.2"
},
Expand Down
25 changes: 1 addition & 24 deletions src/lib/configuration/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import merge from 'deepmerge';

import validators from 'etc/validators';
import { esbuildStrategy } from 'lib/configuration/strategies/esbuild';
import { rollupStrategy } from 'lib/configuration/strategies/rollup';
import log from 'lib/log';
import { getPackageInfo } from 'lib/package';

Expand Down Expand Up @@ -77,13 +76,7 @@ async function ecmaScriptLoader(filePath: string /* , contents: string */) {
/**
* Strategy 2: esbuild
*
* This strategy will work for files that:
* - import nothing
* - only import other code that does not require a transpilation step
* - do not use any custom path mappings
*
* It is faster than Rollup and should cover the vast majority of cases where
* a simple dynamic import will not work.
* Uses esbuild to transpile the indicated file.
*/
try {
const result = await esbuildStrategy(filePath, pkgInfo);
Expand All @@ -94,22 +87,6 @@ async function ecmaScriptLoader(filePath: string /* , contents: string */) {
}


/**
* Strategy 3: Rollup
*
* This is the slowest strategy, but the most robust. It will inline and
* transpile any code that the configuration file imports, allowing the
* output file to be imported as a standalone bundle.
*/
try {
const result = await rollupStrategy(filePath, pkgInfo);
log.verbose(prefix, 'Used strategy:', log.chalk.bold('rollup'));
return getDefaultExport(result);
} catch (err: any) {
errors.push(new Error(`${prefix} Failed to load file with ${log.chalk.bold('rollup')}: ${err}`));
}


if (errors.length > 0) throw new AggregateError(errors, 'All parsing strategies failed.');
}

Expand Down
3 changes: 1 addition & 2 deletions src/lib/configuration/strategies/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { TsconfigPathsPlugin } from '@esbuild-plugins/tsconfig-paths';
import * as esbuild from 'esbuild';
import { nodeExternalsPlugin } from 'esbuild-node-externals';
import fs from 'fs-extra';
import currentNodeVersion from 'node-version';
import * as tsConfck from 'tsconfck';

import log from 'lib/log';
Expand Down Expand Up @@ -70,7 +69,7 @@ export async function esbuildStrategy<M = any>(filePath: string, pkgInfo: Packag
try {
const buildOptions: esbuild.BuildOptions = {
entryPoints: [filePath],
target: `node${currentNodeVersion.major}`,
target: 'node16',
outfile: tempFilePath,
format,
platform: 'node',
Expand Down

0 comments on commit 8cbf9b3

Please sign in to comment.