feat(bundler): Integrate rolldown bundler support and update bundler selection logic
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tsbundle',
|
||||
version: '2.2.5',
|
||||
version: '2.3.0',
|
||||
description: 'a bundler using rollup for painless bundling of web projects'
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ export interface ICliOptions {
|
||||
commonjs?: boolean;
|
||||
skiplibcheck?: boolean;
|
||||
production?: boolean;
|
||||
bundler: 'parcel' | 'esbuild' | 'rollup'
|
||||
bundler: 'parcel' | 'esbuild' | 'rollup' | 'rolldown'
|
||||
}
|
||||
|
||||
export interface IEnvTransportOptions {
|
||||
|
105
ts/mod_rolldown/index.child.ts
Normal file
105
ts/mod_rolldown/index.child.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import * as paths from '../paths.js';
|
||||
import * as interfaces from '../interfaces/index.js';
|
||||
import { logger } from '../tsbundle.logging.js';
|
||||
|
||||
export class TsBundleProcess {
|
||||
constructor() {
|
||||
// Nothing here
|
||||
}
|
||||
|
||||
public async getAliases() {
|
||||
try {
|
||||
const aliasObject: Record<string, string> = {};
|
||||
const localTsConfig = plugins.smartfile.fs.toObjectSync(
|
||||
plugins.path.join(paths.cwd, 'tsconfig.json')
|
||||
);
|
||||
if (localTsConfig.compilerOptions && localTsConfig.compilerOptions.paths) {
|
||||
for (const alias of Object.keys(localTsConfig.compilerOptions.paths)) {
|
||||
const aliasPath = localTsConfig.compilerOptions.paths[alias][0];
|
||||
aliasObject[alias] = aliasPath;
|
||||
}
|
||||
}
|
||||
return aliasObject;
|
||||
} catch (error) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a bundle for the test enviroment
|
||||
*/
|
||||
public async buildTest(fromArg: string, toArg: string, argvArg: any) {
|
||||
// create a bundle
|
||||
const result = await plugins.rolldown({
|
||||
input: fromArg,
|
||||
resolve: {
|
||||
alias: await this.getAliases(),
|
||||
tsconfigFilename: paths.tsconfigPath,
|
||||
},
|
||||
});
|
||||
|
||||
await result.write({
|
||||
file: toArg,
|
||||
format: 'es',
|
||||
sourcemap: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a bundle for the production environment
|
||||
*/
|
||||
public async buildProduction(fromArg: string, toArg: string, argvArg: any) {
|
||||
// create a bundle
|
||||
console.log('rolldown specific:');
|
||||
console.log(`from: ${fromArg}`);
|
||||
console.log(`to: ${toArg}`);
|
||||
|
||||
const result = await plugins.rolldown({
|
||||
input: fromArg,
|
||||
resolve: {
|
||||
alias: await this.getAliases(),
|
||||
tsconfigFilename: paths.tsconfigPath,
|
||||
},
|
||||
experimental: {
|
||||
enableComposingJsPlugins: true,
|
||||
},
|
||||
});
|
||||
|
||||
await result.write({
|
||||
file: toArg,
|
||||
format: 'es',
|
||||
sourcemap: true,
|
||||
minify: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const run = async () => {
|
||||
console.log('running spawned compilation process');
|
||||
const transportOptions: interfaces.IEnvTransportOptions = JSON.parse(
|
||||
process.env.transportOptions
|
||||
);
|
||||
console.log('=======> ROLLDOWN');
|
||||
console.log(transportOptions);
|
||||
process.chdir(transportOptions.cwd);
|
||||
console.log(`switched to ${process.cwd()}`);
|
||||
const tsbundleProcessInstance = new TsBundleProcess();
|
||||
if (transportOptions.mode === 'test') {
|
||||
console.log('building for test:');
|
||||
await tsbundleProcessInstance.buildTest(
|
||||
plugins.smartpath.transform.makeAbsolute(transportOptions.from, process.cwd()),
|
||||
plugins.smartpath.transform.makeAbsolute(transportOptions.to, process.cwd()),
|
||||
transportOptions.argv
|
||||
);
|
||||
} else {
|
||||
console.log('building for production:');
|
||||
await tsbundleProcessInstance.buildProduction(
|
||||
plugins.smartpath.transform.makeAbsolute(transportOptions.from, process.cwd()),
|
||||
plugins.smartpath.transform.makeAbsolute(transportOptions.to, process.cwd()),
|
||||
transportOptions.argv
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
run();
|
5
ts/mod_rolldown/plugins.ts
Normal file
5
ts/mod_rolldown/plugins.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export * from '../plugins.js';
|
||||
|
||||
import { rolldown } from 'rolldown';
|
||||
|
||||
export { rolldown }
|
@@ -12,10 +12,17 @@ export class TsBundle {
|
||||
) {
|
||||
const done = plugins.smartpromise.defer();
|
||||
const getBundlerPath = () => {
|
||||
if (argvArg.bundler === 'esbuild') {
|
||||
return './mod_esbuild/index.child.js'
|
||||
switch (argvArg.bundler) {
|
||||
case 'rolldown':
|
||||
return './mod_rolldown/index.child.js';
|
||||
case 'rollup':
|
||||
return './mod_rollup/index.child.js';
|
||||
case 'parcel':
|
||||
return './mod_parcel/index.child.js';
|
||||
case 'esbuild':
|
||||
default:
|
||||
return './mod_esbuild/index.child.js';
|
||||
}
|
||||
return './mod_esbuild/index.child.js'
|
||||
}
|
||||
const transportOptions: interfaces.IEnvTransportOptions = {
|
||||
cwd: cwdArg,
|
||||
@@ -23,7 +30,6 @@ export class TsBundle {
|
||||
to: toArg,
|
||||
mode: argvArg && argvArg.production ? 'production' : 'test',
|
||||
argv: {
|
||||
bundler: 'esbuild',
|
||||
...argvArg
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user