diff --git a/package.json b/package.json index 33b6a2b..73f8687 100644 --- a/package.json +++ b/package.json @@ -67,4 +67,4 @@ "browserslist": [ "last 1 chrome versions" ] -} +} \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index c4b76ba..ef8c42c 100644 --- a/test/test.ts +++ b/test/test.ts @@ -9,7 +9,8 @@ tap.test('should bundle test', async () => { process.cwd() + '/test', './ts_web/index.ts', './dist_manual/test.js', - 'rollup' + 'rollup', + {} ); }); @@ -18,7 +19,9 @@ tap.test('should bundle production', async () => { await tsbundleInstance.buildProduction( process.cwd(), './test/ts_web/index.ts', - './test/dist_manual/production.js' + './test/dist_manual/production.js', + 'rollup', + {} ); }); diff --git a/ts/tsbundle.class.tsbundle.ts b/ts/tsbundle.class.tsbundle.ts index c0b801b..12b0cda 100644 --- a/ts/tsbundle.class.tsbundle.ts +++ b/ts/tsbundle.class.tsbundle.ts @@ -2,7 +2,7 @@ import * as plugins from './tsbundle.plugins.js'; import { logger } from './tsbundle.logging.js'; export class TsBundle { - public async buildTest ( + public async buildTest( cwdArg: string, fromArg: string, toArg: string, @@ -11,7 +11,10 @@ export class TsBundle { ) { const done = plugins.smartpromise.defer(); const threadsimple = new plugins.smartspawn.ThreadSimple( - plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), './tsbundle.class.tsbundleprocess.js'), + plugins.path.join( + plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), + './tsbundle.class.tsbundleprocess.js' + ), [], { env: { @@ -21,7 +24,7 @@ export class TsBundle { tsbundleFrom: fromArg, tsbundleTo: toArg, tsbundleBundler: bundlerArg, - tsbundleArgv: argvArg, + tsbundleArgv: argvArg ? JSON.stringify(argvArg) : '{}', }, } ); @@ -32,7 +35,7 @@ export class TsBundle { await done.promise; } - public async buildProduction ( + public async buildProduction( cwdArg: string, fromArg: string, toArg: string, @@ -41,7 +44,10 @@ export class TsBundle { ) { const done = plugins.smartpromise.defer(); const threadsimple = new plugins.smartspawn.ThreadSimple( - plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), './tsbundle.class.tsbundleprocess.js'), + plugins.path.join( + plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), + './tsbundle.class.tsbundleprocess.js' + ), [], { env: { @@ -51,7 +57,7 @@ export class TsBundle { tsbundleFrom: fromArg, tsbundleTo: toArg, tsbundleBundler: bundlerArg, - tsbundleArgv: argvArg, + tsbundleArgv: argvArg ? JSON.stringify(argvArg) : '{}', }, } ); diff --git a/ts/tsbundle.class.tsbundleprocess.ts b/ts/tsbundle.class.tsbundleprocess.ts index 8b39987..2f7fe94 100644 --- a/ts/tsbundle.class.tsbundleprocess.ts +++ b/ts/tsbundle.class.tsbundleprocess.ts @@ -44,16 +44,22 @@ export class TsBundleProcess { moduleResolution: 'node12', allowSyntheticDefaultImports: true, importsNotUsedAsValues: 'preserve', - ...argvArg && argvArg.skiplibcheck ? { - skipLibCheck: true - } : {}, - ...argvArg && argvArg.allowimplicitany ? { - noImplicitAny: false - } : {}, - ...argvArg && argvArg.commonjs ? { - module: 'commonjs', - moduleResolution: 'node', - } : {}, + ...(argvArg && argvArg.skiplibcheck + ? { + skipLibCheck: true, + } + : {}), + ...(argvArg && argvArg.allowimplicitany + ? { + noImplicitAny: false, + } + : {}), + ...(argvArg && argvArg.commonjs + ? { + module: 'commonjs', + moduleResolution: 'node', + } + : {}), }), (plugins.rollupJson as any)(), // Allow node_modules resolution, so you can use 'external' to control @@ -69,11 +75,19 @@ export class TsBundleProcess { return baseOptions; } - public getOptionsTest(fromArg: string, toArg: string, argvArg: any): plugins.rollup.RollupOptions { + public getOptionsTest( + fromArg: string, + toArg: string, + argvArg: any + ): plugins.rollup.RollupOptions { return this.getBaseOptions(fromArg, toArg, argvArg); } - public getOptionsProduction(fromArg: string, toArg: string, argvArg: any): plugins.rollup.RollupOptions { + public getOptionsProduction( + fromArg: string, + toArg: string, + argvArg: any + ): plugins.rollup.RollupOptions { const productionOptions = this.getBaseOptions(fromArg, toArg, argvArg); productionOptions.plugins.push( plugins.rollupTerser({ @@ -147,10 +161,14 @@ const run = async () => { process.env.tsbundleFrom, process.env.tsbundleTo, process.env.tsbundleBundler as 'rollup' | 'parcel', - process.env.tsbundleArgv + JSON.parse(process.env.tsbundleArgv) ); } else { - tsbundleProcessInstance.buildProduction(process.env.tsbundleFrom, process.env.tsbundleTo, process.env.tsbundleArgv); + tsbundleProcessInstance.buildProduction( + process.env.tsbundleFrom, + process.env.tsbundleTo, + JSON.parse(process.env.tsbundleArgv) + ); } };