From 9c6b787845b84370a2f4956945bcbcf48d9c9eef Mon Sep 17 00:00:00 2001 From: Paul Taylor Date: Mon, 26 Feb 2018 14:05:35 -0800 Subject: [PATCH] compile src/bin as es5-cjs to all output targets --- js/gulp/arrow-task.js | 8 ++++---- js/gulp/closure-task.js | 6 +++++- js/gulp/typescript-task.js | 25 ++++++++++++++++++------- js/gulp/uglify-task.js | 2 ++ js/gulpfile.js | 8 ++++---- js/src/bin/arrow2csv.ts | 2 -- js/tsconfig/tsconfig.base.json | 2 +- js/tsconfig/tsconfig.bin.cjs.json | 12 ++++++++++++ 8 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 js/tsconfig/tsconfig.bin.cjs.json diff --git a/js/gulp/arrow-task.js b/js/gulp/arrow-task.js index d1e8046e67a..eb83a6da310 100644 --- a/js/gulp/arrow-task.js +++ b/js/gulp/arrow-task.js @@ -31,10 +31,10 @@ const arrowTask = ((cache) => memoizeTask(cache, function copyMain(target, forma const dtsGlob = `${targetDir(`es2015`, `cjs`)}/**/*.ts`; const cjsGlob = `${targetDir(`es2015`, `cjs`)}/**/*.js`; const esmGlob = `${targetDir(`es2015`, `esm`)}/**/*.js`; - const es5UmdGlob = `${targetDir(`es5`, `umd`)}/**/*.js`; - const es5UmdMaps = `${targetDir(`es5`, `umd`)}/**/*.map`; - const es2015UmdGlob = `${targetDir(`es2015`, `umd`)}/**/*.js`; - const es2015UmdMaps = `${targetDir(`es2015`, `umd`)}/**/*.map`; + const es5UmdGlob = `${targetDir(`es5`, `umd`)}/*.js`; + const es5UmdMaps = `${targetDir(`es5`, `umd`)}/*.map`; + const es2015UmdGlob = `${targetDir(`es2015`, `umd`)}/*.js`; + const es2015UmdMaps = `${targetDir(`es2015`, `umd`)}/*.map`; const ch_ext = (ext) => gulpRename((p) => { p.extname = ext; }); const append = (ap) => gulpRename((p) => { p.basename += ap; }); return Observable.forkJoin( diff --git a/js/gulp/closure-task.js b/js/gulp/closure-task.js index 0b2ef1b846b..8833c2c2228 100644 --- a/js/gulp/closure-task.js +++ b/js/gulp/closure-task.js @@ -27,6 +27,7 @@ const gulp = require('gulp'); const path = require('path'); const sourcemaps = require('gulp-sourcemaps'); const { memoizeTask } = require('./memoize-task'); +const { compileBinFiles } = require('./typescript-task'); const ASTBuilders = require('ast-types').builders; const transformAST = require('gulp-transform-js-ast'); const { Observable, ReplaySubject } = require('rxjs'); @@ -55,7 +56,10 @@ const closureTask = ((cache) => memoizeTask(cache, function closure(target, form // rename the sourcemaps from *.js.map files to *.min.js.map sourcemaps.write(`.`, { mapFile: (mapPath) => mapPath.replace(`.js.map`, `.${target}.min.js.map`) }), gulp.dest(out) - ).publish(new ReplaySubject()).refCount(); + ) + .merge(compileBinFiles(target, format)) + .takeLast(1) + .publish(new ReplaySubject()).refCount(); }))({}); const createClosureArgs = (entry, externs) => ({ diff --git a/js/gulp/typescript-task.js b/js/gulp/typescript-task.js index c42357adb2f..0fdd1c73266 100644 --- a/js/gulp/typescript-task.js +++ b/js/gulp/typescript-task.js @@ -30,22 +30,33 @@ const { Observable, ReplaySubject } = require('rxjs'); const typescriptTask = ((cache) => memoizeTask(cache, function typescript(target, format) { const out = targetDir(target, format); - const tsconfigFile = `tsconfig.${tsconfigName(target, format)}.json`; - const tsProject = ts.createProject(path.join(`tsconfig`, tsconfigFile), { typescript: require(`typescript`) }); + const tsconfigPath = path.join(`tsconfig`, `tsconfig.${tsconfigName(target, format)}.json`); + return compileTypescript(out, tsconfigPath) + .merge(compileBinFiles(target, format)).takeLast(1) + .concat(maybeCopyRawJSArrowFormatFiles(target, format)) + .publish(new ReplaySubject()).refCount(); +}))({}); + +function compileBinFiles(target, format) { + const out = targetDir(target, format); + const tsconfigPath = path.join(`tsconfig`, `tsconfig.${tsconfigName('bin', 'cjs')}.json`); + return compileTypescript(path.join(out, 'bin'), tsconfigPath); +} + +function compileTypescript(out, tsconfigPath) { + const tsProject = ts.createProject(tsconfigPath, { typescript: require(`typescript`) }); const { stream: { js, dts } } = observableFromStreams( tsProject.src(), sourcemaps.init(), tsProject(ts.reporter.defaultReporter()) ); const writeDTypes = observableFromStreams(dts, gulp.dest(out)); const writeJS = observableFromStreams(js, sourcemaps.write(), gulp.dest(out)); - return Observable - .forkJoin(writeDTypes, writeJS) - .concat(maybeCopyRawJSArrowFormatFiles(target, format)) - .publish(new ReplaySubject()).refCount(); -}))({}); + return Observable.forkJoin(writeDTypes, writeJS); +} module.exports = typescriptTask; module.exports.typescriptTask = typescriptTask; +module.exports.compileBinFiles = compileBinFiles; function maybeCopyRawJSArrowFormatFiles(target, format) { if (target !== `es5` || format !== `cls`) { diff --git a/js/gulp/uglify-task.js b/js/gulp/uglify-task.js index 9ba3e41a16f..f8dc123cae7 100644 --- a/js/gulp/uglify-task.js +++ b/js/gulp/uglify-task.js @@ -27,6 +27,7 @@ const { const path = require('path'); const webpack = require(`webpack`); const { memoizeTask } = require('./memoize-task'); +const { compileBinFiles } = require('./typescript-task'); const { Observable, ReplaySubject } = require('rxjs'); const UglifyJSPlugin = require(`uglifyjs-webpack-plugin`); const esmRequire = require(`@std/esm`)(module, { cjs: true, esm: `js`, warnings: false }); @@ -73,6 +74,7 @@ const uglifyTask = ((cache, commonConfig) => memoizeTask(cache, function uglifyJ const compilers = webpack(webpackConfigs); return Observable .bindNodeCallback(compilers.run.bind(compilers))() + .merge(compileBinFiles(target, format)).takeLast(1) .multicast(new ReplaySubject()).refCount(); }))({}, { resolve: { mainFields: [`module`, `main`] }, diff --git a/js/gulpfile.js b/js/gulpfile.js index 7b82962035e..891d6c79b38 100644 --- a/js/gulpfile.js +++ b/js/gulpfile.js @@ -58,15 +58,15 @@ knownTargets.forEach((target) => ) ); -// The main "apache-arrow" module builds the es5/cjs, es5/umd, -// es2015/esm, es2015/umd, and ts targets, then copies and -// renames the compiled output into the apache-arrow folder +// The main "apache-arrow" module builds the es5/umd, es2015/cjs, +// es2015/esm, and es2015/umd targets, then copies and renames the +// compiled output into the apache-arrow folder gulp.task(`build:${npmPkgName}`, gulp.series( cleanTask(npmPkgName), gulp.parallel( - `build:${taskName(`es5`, `cjs`)}`, `build:${taskName(`es5`, `umd`)}`, + `build:${taskName(`es2015`, `cjs`)}`, `build:${taskName(`es2015`, `esm`)}`, `build:${taskName(`es2015`, `umd`)}` ), diff --git a/js/src/bin/arrow2csv.ts b/js/src/bin/arrow2csv.ts index ee956132378..6d197c7b6b4 100644 --- a/js/src/bin/arrow2csv.ts +++ b/js/src/bin/arrow2csv.ts @@ -84,12 +84,10 @@ if (!files.length) { } files.forEach((source) => { - debugger; let table: Arrow.Table, input = fs.readFileSync(source); try { table = Arrow.Table.from(input); } catch (e) { - debugger; table = Arrow.Table.from(parse(input + '')); } if (argv.schema && argv.schema.length) { diff --git a/js/tsconfig/tsconfig.base.json b/js/tsconfig/tsconfig.base.json index 8b821019896..d0b813ef38e 100644 --- a/js/tsconfig/tsconfig.base.json +++ b/js/tsconfig/tsconfig.base.json @@ -1,5 +1,5 @@ { - "exclude": ["../node_modules"], + "exclude": ["../node_modules", "../src/bin/*.ts"], "include": ["../src/**/*.ts"], "compileOnSave": false, "compilerOptions": { diff --git a/js/tsconfig/tsconfig.bin.cjs.json b/js/tsconfig/tsconfig.bin.cjs.json new file mode 100644 index 00000000000..e17c1b589ac --- /dev/null +++ b/js/tsconfig/tsconfig.bin.cjs.json @@ -0,0 +1,12 @@ +//Compiler configuaration to build the ES5 CommonJS bin files +{ + "extends": "./tsconfig.base.json", + "exclude": ["../node_modules"], + "include": ["../src/bin/*.ts"], + "compilerOptions": { + "target": "ES5", + "module": "commonjs", + "declaration": false + } + } + \ No newline at end of file