feat(bundler): Integrate rolldown bundler support and update bundler selection logic
This commit is contained in:
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 }
|
Reference in New Issue
Block a user