diff --git a/package.json b/package.json index efa61b4eb9..4ff98147bf 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "workspaces": [ "./src/constants", "./src/types", + "./src/middleware", "./src/deckgl-layers", "./src/layers", "./src/processors" diff --git a/src/index.js b/src/index.js index 0568703744..99b3af1cc9 100644 --- a/src/index.js +++ b/src/index.js @@ -43,7 +43,7 @@ export * from './layers'; export * from './styles'; // Middleware -export * from './middleware'; +export * from '@kepler.gl/middleware'; // Utils export * from './utils'; diff --git a/src/middleware/babel.config.js b/src/middleware/babel.config.js new file mode 100644 index 0000000000..7aec54a783 --- /dev/null +++ b/src/middleware/babel.config.js @@ -0,0 +1,65 @@ +// Copyright (c) 2022 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +const KeplerPackage = require('./package'); + +const PRESETS = ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript']; +const PLUGINS = [ + ['@babel/plugin-transform-typescript', {isTSX: true, allowDeclareFields: true}], + '@babel/plugin-transform-modules-commonjs', + '@babel/plugin-proposal-export-namespace-from', + '@babel/plugin-proposal-optional-chaining', + [ + '@babel/transform-runtime', + { + regenerator: true + } + ], + [ + 'search-and-replace', + { + rules: [ + { + search: '__PACKAGE_VERSION__', + replace: KeplerPackage.version + } + ] + } + ] +]; +const ENV = { + test: { + plugins: ['istanbul'] + }, + debug: { + sourceMaps: 'inline', + retainLines: true + } +}; + +module.exports = function babel(api) { + api.cache(true); + + return { + presets: PRESETS, + plugins: PLUGINS, + env: ENV + }; +}; diff --git a/src/middleware/package.json b/src/middleware/package.json new file mode 100644 index 0000000000..dc37a4c94d --- /dev/null +++ b/src/middleware/package.json @@ -0,0 +1,65 @@ +{ + "name": "@kepler.gl/middleware", + "author": "Shan He ", + "version": "2.5.5", + "description": "kepler.gl middleware used by kepler.gl components, actions and reducers", + "license": "MIT", + "main": "dist/index.js", + "types": "index.d.ts", + "keywords": [ + "babel", + "es6", + "react", + "webgl", + "visualization", + "deck.gl" + ], + "repository": { + "type": "git", + "url": "https://github.com/keplergl/kepler.gl.git" + }, + "scripts": { + "build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'", + "build:umd": "webpack --config ./webpack/umd.js --progress --env.prod", + "build:types": "tsc --project ./tsconfig.production.json", + "prepublish": "uber-licence && yarn build && yarn build:umd && yarn build:types", + "stab": "mkdir -p dist && touch dist/index.js" + }, + "files": [ + "dist", + "umd" + ], + "dependencies": { + "@babel/runtime": "^7.12.1", + "colorbrewer": "^1.5.0", + "d3-scale": "^3.2.3", + "global": "^4.3.0", + "keymirror": "^0.1.1", + "react-map-gl-draw": "0.14.8", + "@kepler.gl/types": "2.5.5" + }, + "exports": { + ".": "./dist/index.js", + "./*": "./dist/*" + }, + "typesVersions": { + "*": { + "*": ["dist/*"] + } + }, + "nyc": { + "sourceMap": false, + "instrument": false + }, + "engines": { + "node": ">=12.0.0" + }, + "maintainers": [ + "Shan He ", + "Giuseppe Macri " + ], + "volta": { + "node": "12.22.0", + "yarn": "1.22.17" + } +} diff --git a/src/middleware/index.ts b/src/middleware/src/index.ts similarity index 100% rename from src/middleware/index.ts rename to src/middleware/src/index.ts diff --git a/src/middleware/tsconfig.production.json b/src/middleware/tsconfig.production.json new file mode 100644 index 0000000000..07c5bef6e2 --- /dev/null +++ b/src/middleware/tsconfig.production.json @@ -0,0 +1,38 @@ +{ + "compilerOptions": { + "target": "es2020", + "allowJs": false, + "checkJs": false, + "jsx": "react", + "module": "esnext", + "moduleResolution": "node", + "declaration":true, + "emitDeclarationOnly":true, + "noImplicitAny": false, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "outDir": "dist", + "sourceMap": true, + "strictNullChecks": true, + "suppressImplicitAnyIndexErrors": false, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true, + "strict": true, + "resolveJsonModule": true, + "isolatedModules": true, + "baseUrl": "./src", + "paths": { + "*": ["*"] + } + }, + "include": [ + "src" + ], + "exclude": [ + "*/actions/**/*", + "*/utils/**/*", + "../components/**/*" + ] +} diff --git a/src/middleware/webpack/umd.js b/src/middleware/webpack/umd.js new file mode 100644 index 0000000000..3eb025d5e4 --- /dev/null +++ b/src/middleware/webpack/umd.js @@ -0,0 +1,120 @@ +// Copyright (c) 2022 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +const resolve = require('path').resolve; +const join = require('path').join; + +// Import package.json to read version +const KeplerPackage = require('../package'); + +const SRC_DIR = resolve(__dirname, '../src'); +const OUTPUT_DIR = resolve(__dirname, '../umd'); + +const LIBRARY_BUNDLE_CONFIG = env => ({ + entry: { + KeplerGl: join(SRC_DIR, 'index.ts') + }, + + // Silence warnings about big bundles + stats: { + warnings: false + }, + + output: { + // Generate the bundle in dist folder + path: OUTPUT_DIR, + filename: 'keplergl.min.js', + globalObject: 'this', + library: '[name]', + libraryTarget: 'umd' + }, + + // let's put everything in + externals: { + react: { + root: 'React', + commonjs2: 'react', + commonjs: 'react', + amd: 'react', + umd: 'react' + }, + 'react-dom': { + root: 'ReactDOM', + commonjs2: 'react-dom', + commonjs: 'react-dom', + amd: 'react-dom', + umd: 'react-dom' + }, + redux: { + root: 'Redux', + commonjs2: 'redux', + commonjs: 'redux', + amd: 'redux', + umd: 'redux' + }, + 'react-redux': { + root: 'ReactRedux', + commonjs2: 'react-redux', + commonjs: 'react-redux', + amd: 'react-redux', + umd: 'react-redux' + }, + 'styled-components': { + commonjs: 'styled-components', + commonjs2: 'styled-components', + amd: 'styled-components', + root: 'styled' + } + }, + resolve: { + extensions: ['.tsx', '.ts', '.js'], + modules: ['node_modules', SRC_DIR] + }, + module: { + rules: [ + { + test: /\.(js|ts|tsx)$/, + loader: 'babel-loader', + include: [SRC_DIR], + options: { + plugins: [ + [ + 'search-and-replace', + { + rules: [ + { + search: '__PACKAGE_VERSION__', + replace: KeplerPackage.version + } + ] + } + ] + ] + } + } + ] + }, + + node: { + fs: 'empty' + } +}); + +module.exports = env => LIBRARY_BUNDLE_CONFIG(env);