From 03e244a6a27df9c92b373fbd9c40ef5143c2dbe8 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Mon, 29 Jan 2018 17:07:23 +0100 Subject: [PATCH] Add type checking and full build creation This uses Closure Compiler to create a full build and run type checks. Currently type errors are reported as warnings and the build is created with SIMPLE optimizations until we have transitioned all types to path types. --- package.json | 6 ++++-- tasks/build-typecheck.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 tasks/build-typecheck.js diff --git a/package.json b/package.json index 58a4d107cb..4391ee2603 100644 --- a/package.json +++ b/package.json @@ -11,10 +11,11 @@ "scripts": { "lint": "eslint tasks test src examples transforms", "pretest": "npm run lint", - "test": "npm run karma -- --single-run", + "test": "npm run karma -- --single-run && npm run build-typecheck", "karma": "karma start test/karma.config.js", "serve-examples": "mkdir -p build/examples && webpack --config examples/webpack/config.js --watch & serve build/examples", - "build-examples": "webpack --config examples/webpack/config.js --env=prod" + "build-examples": "webpack --config examples/webpack/config.js --env=prod", + "build-typecheck": "node tasks/generate-index.js && node tasks/build-typecheck.js" }, "main": "src/ol/index.js", "repository": { @@ -46,6 +47,7 @@ "front-matter": "^2.1.2", "fs-extra": "5.0.0", "glob": "7.1.1", + "google-closure-compiler": "^20180101.0.0", "handlebars": "4.0.11", "html-webpack-plugin": "^2.30.1", "istanbul": "0.4.5", diff --git a/tasks/build-typecheck.js b/tasks/build-typecheck.js new file mode 100644 index 0000000000..eee96739e2 --- /dev/null +++ b/tasks/build-typecheck.js @@ -0,0 +1,37 @@ +const Compiler = require('google-closure-compiler').compiler; + +const compiler = new Compiler({ + js: [ + './src/**.js', + './node_modules/pbf/package.json', './node_modules/pbf/**.js', './node_modules/ieee754/**.js', + './node_modules/pixelworks/package.json', './node_modules/pixelworks/**.js', + './node_modules/rbush/package.json', './node_modules/rbush/**.js', 'node_modules/quickselect/**.js' + ], + entry_point: './src/index.js', + module_resolution: 'NODE', + //FIXME Use compilation_level: 'ADVANCED' after we have switched to path types + compilation_level: 'SIMPLE', + new_type_inf: true, + generate_exports: true, + export_local_property_definitions: true, + output_wrapper: '(function(){%output%})() //# sourceMappingURL=ol.js.map', + js_output_file: 'build/ol.js', + create_source_map: '%outname%.map', + source_map_include_content: true, + //FIXME Turn jscomp_error on for * when we have path types everywhere + //FIXME Change newCheckTypes to jscomp_error when we have path types everywhere + jscomp_warning: ['newCheckTypes'], + // Options to make dependencies work + process_common_js_modules: true, + dependency_mode: 'STRICT', + hide_warnings_for: 'node_modules' +}); + +compiler.run((exit, out, err) => { + if (exit) { + process.stderr.write(err, () => process.exit(exit)); + } else { + process.stderr.write(err); + process.stdout.write(out); + } +});