fix(config): update .smartconfig.json handling and harden bundler runtime compatibility
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tsbundle',
|
||||
version: '2.10.1',
|
||||
version: '2.10.2',
|
||||
description: 'a multi-bundler tool supporting esbuild, rolldown, and rspack for painless bundling of web projects'
|
||||
}
|
||||
|
||||
+10
-12
@@ -40,29 +40,27 @@ export class AssetsHandler {
|
||||
// copies the html
|
||||
public async processAssets(optionsArg?: { from?: string; to?: string }) {
|
||||
// lets assemble the options
|
||||
optionsArg = {
|
||||
...{
|
||||
from: this.defaultFromDirPath,
|
||||
to: this.defaultToDirPath,
|
||||
},
|
||||
const options = {
|
||||
from: this.defaultFromDirPath,
|
||||
to: this.defaultToDirPath,
|
||||
...(optionsArg || {}),
|
||||
};
|
||||
await this.ensureAssetsDir();
|
||||
optionsArg.from = plugins.smartpath.transform.toAbsolute(
|
||||
optionsArg.from,
|
||||
options.from = plugins.smartpath.transform.toAbsolute(
|
||||
options.from,
|
||||
paths.cwd,
|
||||
) as string;
|
||||
optionsArg.to = plugins.smartpath.transform.toAbsolute(
|
||||
optionsArg.to,
|
||||
options.to = plugins.smartpath.transform.toAbsolute(
|
||||
options.to,
|
||||
paths.cwd,
|
||||
) as string;
|
||||
|
||||
// lets clean the target directory
|
||||
const toExists = await plugins.fs.directory(optionsArg.to).exists();
|
||||
const toExists = await plugins.fs.directory(options.to).exists();
|
||||
if (toExists) {
|
||||
await plugins.fs.directory(optionsArg.to).delete();
|
||||
await plugins.fs.directory(options.to).delete();
|
||||
}
|
||||
|
||||
await this.copyDirectoryRecursive(optionsArg.from, optionsArg.to);
|
||||
await this.copyDirectoryRecursive(options.from, options.to);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export class CustomBundleHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load configuration from smartconfig.json
|
||||
* Load configuration from .smartconfig.json
|
||||
*/
|
||||
public async loadConfig(): Promise<boolean> {
|
||||
const smartconfigInstance = new plugins.smartconfig.Smartconfig(this.cwd);
|
||||
|
||||
@@ -83,9 +83,11 @@ export class TsBundleProcess {
|
||||
const run = async () => {
|
||||
try {
|
||||
console.log('running spawned compilation process');
|
||||
const transportOptions: interfaces.IEnvTransportOptions = JSON.parse(
|
||||
process.env.transportOptions,
|
||||
);
|
||||
const transportOptionsJson = process.env.transportOptions;
|
||||
if (!transportOptionsJson) {
|
||||
throw new Error('Missing transportOptions environment variable');
|
||||
}
|
||||
const transportOptions: interfaces.IEnvTransportOptions = JSON.parse(transportOptionsJson);
|
||||
console.log('=======> ESBUILD');
|
||||
console.log(transportOptions);
|
||||
process.chdir(transportOptions.cwd);
|
||||
|
||||
+13
-15
@@ -21,30 +21,28 @@ export class HtmlHandler {
|
||||
to?: string;
|
||||
minify?: boolean;
|
||||
}) {
|
||||
optionsArg = {
|
||||
...{
|
||||
from: this.defaultFromPath,
|
||||
to: this.defaultToPath,
|
||||
minify: false,
|
||||
},
|
||||
const options = {
|
||||
from: this.defaultFromPath,
|
||||
to: this.defaultToPath,
|
||||
minify: false,
|
||||
...optionsArg,
|
||||
};
|
||||
if (await this.checkIfExists()) {
|
||||
console.log(`${optionsArg.from} replaces file at ${optionsArg.to}`);
|
||||
console.log(`${options.from} replaces file at ${options.to}`);
|
||||
}
|
||||
optionsArg.from = plugins.smartpath.transform.toAbsolute(
|
||||
optionsArg.from,
|
||||
options.from = plugins.smartpath.transform.toAbsolute(
|
||||
options.from,
|
||||
paths.cwd,
|
||||
) as string;
|
||||
optionsArg.to = plugins.smartpath.transform.toAbsolute(
|
||||
optionsArg.to,
|
||||
options.to = plugins.smartpath.transform.toAbsolute(
|
||||
options.to,
|
||||
paths.cwd,
|
||||
) as string;
|
||||
let fileString = (await plugins.fs
|
||||
.file(optionsArg.from)
|
||||
.file(options.from)
|
||||
.encoding('utf8')
|
||||
.read()) as string;
|
||||
if (optionsArg.minify) {
|
||||
if (options.minify) {
|
||||
fileString = plugins.htmlMinifier.minify(fileString, {
|
||||
minifyCSS: true,
|
||||
minifyJS: true,
|
||||
@@ -56,9 +54,9 @@ export class HtmlHandler {
|
||||
removeComments: true,
|
||||
});
|
||||
}
|
||||
const toDir = plugins.path.dirname(optionsArg.to);
|
||||
const toDir = plugins.path.dirname(options.to);
|
||||
await plugins.fs.directory(toDir).create();
|
||||
await plugins.fs.file(optionsArg.to).encoding('utf8').write(fileString);
|
||||
await plugins.fs.file(options.to).encoding('utf8').write(fileString);
|
||||
console.log(`html processing succeeded!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,11 +40,11 @@ export class InitHandler {
|
||||
|
||||
constructor(cwd: string = paths.cwd) {
|
||||
this.cwd = cwd;
|
||||
this.smartconfigPath = plugins.path.join(this.cwd, 'smartconfig.json');
|
||||
this.smartconfigPath = plugins.path.join(this.cwd, '.smartconfig.json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load existing smartconfig.json or create empty config
|
||||
* Load existing .smartconfig.json or create empty config
|
||||
*/
|
||||
private async loadExistingConfig(): Promise<any> {
|
||||
const fileExists = await plugins.fs.file(this.smartconfigPath).exists();
|
||||
@@ -60,12 +60,12 @@ export class InitHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Save config to smartconfig.json
|
||||
* Save config to .smartconfig.json
|
||||
*/
|
||||
private async saveConfig(config: any): Promise<void> {
|
||||
const content = JSON.stringify(config, null, 2);
|
||||
await plugins.fs.file(this.smartconfigPath).encoding('utf8').write(content);
|
||||
console.log(`\n✅ Configuration saved to smartconfig.json`);
|
||||
console.log(`\n✅ Configuration saved to .smartconfig.json`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +73,7 @@ export class InitHandler {
|
||||
*/
|
||||
public async runWizard(): Promise<void> {
|
||||
console.log('\n🚀 tsbundle configuration wizard\n');
|
||||
console.log('This wizard will help you configure bundle settings in smartconfig.json.\n');
|
||||
console.log('This wizard will help you configure bundle settings in .smartconfig.json.\n');
|
||||
|
||||
const smartconfigJson = await this.loadExistingConfig();
|
||||
|
||||
|
||||
@@ -90,9 +90,11 @@ export class TsBundleProcess {
|
||||
|
||||
const run = async () => {
|
||||
console.log('running spawned compilation process');
|
||||
const transportOptions: interfaces.IEnvTransportOptions = JSON.parse(
|
||||
process.env.transportOptions,
|
||||
);
|
||||
const transportOptionsJson = process.env.transportOptions;
|
||||
if (!transportOptionsJson) {
|
||||
throw new Error('Missing transportOptions environment variable');
|
||||
}
|
||||
const transportOptions: interfaces.IEnvTransportOptions = JSON.parse(transportOptionsJson);
|
||||
console.log('=======> ROLLDOWN');
|
||||
console.log(transportOptions);
|
||||
process.chdir(transportOptions.cwd);
|
||||
|
||||
@@ -52,6 +52,7 @@ export class TsBundleProcess {
|
||||
output: {
|
||||
path: outputDir,
|
||||
filename: outputFilename,
|
||||
module: true,
|
||||
library: {
|
||||
type: 'module' as const,
|
||||
},
|
||||
@@ -86,9 +87,6 @@ export class TsBundleProcess {
|
||||
},
|
||||
],
|
||||
},
|
||||
experiments: {
|
||||
outputModule: true,
|
||||
},
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -98,6 +96,10 @@ export class TsBundleProcess {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
if (!stats) {
|
||||
reject(new Error('Rspack did not return stats'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (stats.hasErrors()) {
|
||||
console.error(stats.toString());
|
||||
@@ -140,6 +142,7 @@ export class TsBundleProcess {
|
||||
output: {
|
||||
path: outputDir,
|
||||
filename: outputFilename,
|
||||
module: true,
|
||||
library: {
|
||||
type: 'module' as const,
|
||||
},
|
||||
@@ -184,9 +187,6 @@ export class TsBundleProcess {
|
||||
usedExports: true,
|
||||
sideEffects: true,
|
||||
},
|
||||
experiments: {
|
||||
outputModule: true,
|
||||
},
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -196,6 +196,10 @@ export class TsBundleProcess {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
if (!stats) {
|
||||
reject(new Error('Rspack did not return stats'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (stats.hasErrors()) {
|
||||
console.error(stats.toString());
|
||||
@@ -221,9 +225,11 @@ export class TsBundleProcess {
|
||||
|
||||
const run = async () => {
|
||||
console.log('running spawned compilation process');
|
||||
const transportOptions: interfaces.IEnvTransportOptions = JSON.parse(
|
||||
process.env.transportOptions,
|
||||
);
|
||||
const transportOptionsJson = process.env.transportOptions;
|
||||
if (!transportOptionsJson) {
|
||||
throw new Error('Missing transportOptions environment variable');
|
||||
}
|
||||
const transportOptions: interfaces.IEnvTransportOptions = JSON.parse(transportOptionsJson);
|
||||
console.log('=======> RSPACK');
|
||||
console.log(transportOptions);
|
||||
process.chdir(transportOptions.cwd);
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import { runInit } from './mod_init/index.js';
|
||||
export const runCli = async () => {
|
||||
const tsBundleCli = new plugins.smartcli.Smartcli();
|
||||
|
||||
// Default command: run custom bundles from smartconfig.json
|
||||
// Default command: run custom bundles from .smartconfig.json
|
||||
tsBundleCli.standardCommand().subscribe(async (argvArg) => {
|
||||
await runCustomBundles();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user