Use babel and closure without bundler for type checking

This commit is contained in:
Andreas Hocevar
2018-02-08 17:50:16 +01:00
parent 9c12b351e5
commit 287723902c
4 changed files with 28 additions and 18 deletions
+9
View File
@@ -0,0 +1,9 @@
{
"plugins": ["jsdoc-closure"],
"parserOpts": {
"parser": "recast"
},
"generatorOpts": {
"generator": "recast"
}
}
+7 -1
View File
@@ -15,7 +15,10 @@
"karma": "karma start test/karma.config.js", "karma": "karma start test/karma.config.js",
"serve-examples": "mkdir -p build/examples && webpack --config examples/webpack/config.js --watch & serve build/examples", "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": "webpack --config config/webpack.js" "build-index": "node tasks/generate-index.js",
"build": "npm run build-index && webpack --config config/webpack.js",
"src-closure": "babel --out-dir build/src-closure src/",
"typecheck": "npm run build-index && npm run src-closure && node tasks/typecheck"
}, },
"main": "src/ol/index.js", "main": "src/ol/index.js",
"repository": { "repository": {
@@ -37,7 +40,9 @@
}, },
"devDependencies": { "devDependencies": {
"async": "2.6.0", "async": "2.6.0",
"babel-cli": "^6.26.0",
"babel-minify-webpack-plugin": "^0.3.0", "babel-minify-webpack-plugin": "^0.3.0",
"babel-plugin-jsdoc-closure": "^1.0.2",
"clean-css-cli": "4.1.10", "clean-css-cli": "4.1.10",
"copy-webpack-plugin": "^4.0.1", "copy-webpack-plugin": "^4.0.1",
"coveralls": "3.0.0", "coveralls": "3.0.0",
@@ -67,6 +72,7 @@
"nomnom": "1.8.1", "nomnom": "1.8.1",
"pixelmatch": "^4.0.2", "pixelmatch": "^4.0.2",
"proj4": "2.4.4", "proj4": "2.4.4",
"recast": "^0.13.0",
"serve": "^6.0.6", "serve": "^6.0.6",
"sinon": "4.2.2", "sinon": "4.2.2",
"url-polyfill": "^1.0.7", "url-polyfill": "^1.0.7",
+7 -3
View File
@@ -20,6 +20,10 @@ function getSymbols(callback) {
}); });
} }
function getPath(name) {
const fullPath = require.resolve(path.resolve('src', name));
return './' + path.posix.relative('src/', fullPath);
}
/** /**
* Generate a list of symbol names. * Generate a list of symbol names.
@@ -36,12 +40,12 @@ function addImports(symbols, callback) {
if (defaultExport.length > 1) { if (defaultExport.length > 1) {
const from = defaultExport[0].replace(/^module\:/, './'); const from = defaultExport[0].replace(/^module\:/, './');
const importName = from.replace(/[.\/]+/g, '$'); const importName = from.replace(/[.\/]+/g, '$');
const defaultImport = `import ${importName} from '${from}.js';`; const defaultImport = `import ${importName} from '${getPath(from)}';`;
imports[defaultImport] = true; imports[defaultImport] = true;
} else if (namedExport.length > 1) { } else if (namedExport.length > 1) {
const from = namedExport[0].replace(/^module\:/, './'); const from = namedExport[0].replace(/^module\:/, './');
const importName = from.replace(/[.\/]+/g, '_'); const importName = from.replace(/[.\/]+/g, '_');
const namedImport = `import * as ${importName} from '${from}.js';`; const namedImport = `import * as ${importName} from '${getPath(from)}';`;
imports[namedImport] = true; imports[namedImport] = true;
} }
}); });
@@ -135,7 +139,7 @@ function main(callback) {
if (require.main === module) { if (require.main === module) {
async.waterfall([ async.waterfall([
main, main,
fs.outputFile.bind(fs, path.join('src', 'index.js')) fs.outputFile.bind(fs, path.resolve('src', 'index.js'))
], function(err) { ], function(err) {
if (err) { if (err) {
process.stderr.write(err.message + '\n'); process.stderr.write(err.message + '\n');
@@ -2,28 +2,19 @@ const Compiler = require('google-closure-compiler').compiler;
const compiler = new Compiler({ const compiler = new Compiler({
js: [ js: [
'./src/**.js', './build/src-closure/**.js',
'./node_modules/pbf/package.json', './node_modules/pbf/**.js', './node_modules/ieee754/**.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/pixelworks/package.json', './node_modules/pixelworks/**.js',
'./node_modules/rbush/package.json', './node_modules/rbush/**.js', 'node_modules/quickselect/**.js' './node_modules/rbush/package.json', './node_modules/rbush/**.js', 'node_modules/quickselect/**.js'
], ],
entry_point: './src/index.js', entry_point: './build/src-closure/index.js',
module_resolution: 'NODE', module_resolution: 'NODE',
//FIXME Use compilation_level: 'ADVANCED' after we have switched to path types dependency_mode: 'STRICT',
compilation_level: 'SIMPLE', process_common_js_modules: true,
new_type_inf: true, checks_only: 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 //FIXME Change newCheckTypes to jscomp_error when we have path types everywhere
jscomp_warning: ['newCheckTypes'], jscomp_warning: ['newCheckTypes'],
// Options to make dependencies work // Options to make dependencies work
process_common_js_modules: true,
dependency_mode: 'STRICT',
hide_warnings_for: 'node_modules' hide_warnings_for: 'node_modules'
}); });