diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..2ba6bc5 --- /dev/null +++ b/.babelrc @@ -0,0 +1,6 @@ +{ + "presets": [ + "react-app" + ], + "sourceType": "unambiguous" +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9d08a1a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.gitignore b/.gitignore index 572e9a7..d2c7d1e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ # production /react-compiled /dist -/bin # misc .DS_Store @@ -17,6 +16,7 @@ .env.development.local .env.test.local .env.production.local +.env npm-debug.log* yarn-debug.log* diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ae2afd1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "bin/rainbow"] + path = bin/rainbow + url = https://github.com/mihirpathak97/rainbow.git + branch = audius-mod diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..d27ac8e --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "endOfLine": "lf", + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "es5" +} diff --git a/.travis.yml b/.travis.yml index 650de51..b4a3662 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,55 +2,55 @@ # Author - Mihir Pathak # # Consists of 2 jobs - -# - Linux environment builds for debian -# - OSX builds for Mac and Windows +# - Ubuntu bionic environment builds for Linux +# - OSX builds for Mac -# Build with Node JS 8 [9+ causes fsevetns build to crash in darwin] +# Language configs language: node_js -node_js: "8" +node_js: '12' # Job for building jobs: include: - if: tag IS present os: linux - dist: trusty + dist: bionic + addons: + apt: + packages: + - python3-pip + - python3-setuptools - if: tag IS present os: osx - osx_image: xcode9.3 + addons: + homebrew: + taps: + - sashkab/python + packages: + - python36 -# Global environment variables -env: - global: - - ELECTRON_CACHE=$HOME/.cache/electron - - ELECTRON_BUILDER_CACHE=$HOME/.cache/electron-builder +# Run the build script depending on OS +script: + - echo "Installing yarn dependencies" + - yarn install -# Cache directorries -cache: - directories: - - node_modules - - $HOME/.cache/electron - - $HOME/.cache/electron-builder + - echo "Building raindow" + - cd bin/rainbow + - pip3 install --upgrade --user pip setuptools wheel + - pip3 install --upgrade --user -r requirements.txt + - python3 setup.py build + - cd ../../ -# Perform build [win32's exe and darwin's dmg in osx and linux's deb in linux] -script: - - echo "Initializing app files..." - - yarn init-app - echo "Compiling React app for production" - yarn build + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then - echo "Packaging Audius for Linux x64 (.deb)"; - chmod a+x bin/ffmpeg/linux/ffmpeg; - chmod a+x bin/rainbow/linux/rainbow; - yarn package-linux; + echo "Packaging Audius for Linux x64 (AppImage)"; + yarn package:linux; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - echo "Packaging Audius for MacOS X (.dmg)"; - chmod a+x bin/ffmpeg/darwin/ffmpeg; - chmod a+x bin/rainbow/darwin/rainbow; - yarn package-mac; - echo "Packaging Audius for Windows x64 (.exe)"; - yarn package-win; + echo "Packaging Audius for MacOS X (DMG)"; + yarn package:mac; fi after_success: diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe19ce..2dd5873 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,44 +1,100 @@ # Changelog + All notable changes to this project will be documented in this file. +## [2.0.0-beta1] - 2020-03-25 + +### Added + +- Option to set spotify and youtube API keys in settings + +### Changed + +- Minor types and defs update +- ⬆️ - ant-design 4.x, react 16.13.x +- Users need to provide their own API keys for YT and Spotify + +## [2.0.0-alpha3] - 2019-08-24 + +### Added + +- TypeScript 🎉 +- Hooks and FC 🎉 +- Redux simplification 🎉 +- Code refactorization 🎉 + +## [2.0.0-alpha2] - 2019-08-24 + +### Fixed + +- Build failing in CI + +## [2.0.0-alpha1] - 2019-08-11 + +### Added + +- New UI 🎉 +- Better code +- Added AppImage for linux + +### Changed + +- Get latest webpack configs from `create-react-app` +- Moved packages to `devDependencies` to reduce asar bundle size + +### Removed + +- `deb` build for linux + ## [1.6.0-beta1] - 2018-01-03 + ### Added + - Custom URI protocol `audius://` for serving static files ### Changed + - Get latest webpack configs from `create-react-app` - Moved packages to `devDependencies` to reduce asar bundle size ### Fixed + - Font issue - Webpack production errors - [Queue] Fix mixing `require` and `exports` ## [1.6.0-beta1] - 2018-01-03 + ### Added + - Support for Spotify links! - **Note** Only track links work. Playlists and albums will be supported in the next point release - Default art work for songs with unknown Spotify data ### Changed + - Minor UI changes - Add `Open Sans` font locally - [Hack] Relative path issue for loading local fonts - [win32] Installer will now install per-user ### Fixed + - Refreshing Spotify access token in runtime - Error dialog while getting Spotify access token ## [1.6.0-alpha1] - 2018-09-30 + ### Added + - Download Queue! - Redux! - Support for YouTube links! - **Note** Some YT links will not fetch Spotify data properly. Working on a fix ### Changed + - Updated node packages - electron - 2.0.7 -> 3.0.2 - react - 16.4.x -> 16.5.2 @@ -50,142 +106,189 @@ All notable changes to this project will be documented in this file. - Fix icons ### Removed + - Nuked audio play functionality as it violates YouTube's terms - Now opens the link in default browser - Nuked `@material-ui/icons`. Using Font Awesome entirely ## [1.5.0] - 2018-08-19 + **NOTE -** This is the final release for 1.x.x. I will shortly begin work on 2.x :grin: This branch may or may not recieve bug fixes. Feel free to fork the repo and make changes ### Changed + - Updated node packages - electron - 2.0.7 -> 2.0.10 ## [1.5.0-beta1] - 2018-08-19 + ### Added + - Logging! Now it's easier to debug the application - Log files location is platform dependent ### Changed + - Updated node packages - electron - 2.0.2 -> 2.0.7 - electron-updater - 2.21.10 -> 3.1.1 - And more! ## [1.4.2] - 2018-08-18 + ### Fixed + - Uncaught error while fetching access token in main process ## [1.4.1] - 2018-08-01 + ### Fixed + - Refresh Spotify token on-demand ## [1.4.0] - 2018-07-01 + ### Changed + - Display upto 10 search results ### Fixed + - "Go back" re-renders current view ## [1.3.0-beta1] - 2018-06-26 + ### Changed + - rainbow is no longer experimental! - Default download format for OSX is m4a - rainbow is enabled by default ## [1.3.0-beta1] - 2018-06-26 + ### Added + - [Experimental] Rainbow can now embed tags in M4A files too! ### Changed + - rainbow now uses positional arguments ## [1.3.0-alpha2] - 2018-06-24 + ### Added + - [Experimental] Added rainbow for all platforms - Added toggle switch in Settigns to embed metadata ### Changed + - Changed the way the app compiles external binaries ### Removed + - All built in binaries inside the repository ## [1.3.0-alpha1] - 2018-06-23 + ### Added + - [Experimental] Added rainbow for embedding ID3 in win32 ### Changed + - Lint ES6 code ## [1.2.1] - 2018-06-22 + ### Changed + - Remove unused dependencies [lesser app size] - NSIS installer will not ask for elevated permissions ## [1.2.0] - 2018-06-22 + ### Changed + - include files for electron-builder ## [1.2.0-beta1] - 2018-06-22 + ### Changed + - New Layout! - Cleaner, Leaner code - Re-organize entire app structure for efficiency ### Fixed + - FFmpeg path issues in production ## [1.1.0] - 2018-06-20 + ### Added + - Auto Update is now fully functional ## [1.0.2] - 2018-06-19 + ### Changed + - Use proper JSX syntax - Query - remove useless code - Modified build scripts ## [1.0.1] - 2018-06-15 + ### Added + - electron-log for logging ### Changed + - Cleanup unnecessary build code - Temporarily drop auto-updater support - Clean up Terms and About ## [1.0.0] - 2018-06-08 + ### Added + - FFmpeg binary for all platforms - Added ability to modify settings ### Changed + - Debian package specific config - Settings - use table layout - Default download location is `$HOME/Misic` - electron-builder publish config ### Fixed + - Fix FFMPEG_PATH related issues for all platforms - Fix Query onSubmit - Fix FFmpeg binary permission issues in OsX and Linux ## [1.0.0-beta3] - 2018-06-06 + ### Added + - Add custom dialog box to display messages and errors - Customize build script - **Drop 32-bit support entirely** ### Changed + - New dialog box layout - Make DialogBox as a separate React component - YouTube and Spotify links are disabled - Removed useless console log calls ### Fixed + - TrackContainer - dialog opens on render() - YTDownload - return on error - QueryField - fixed invalid view error @@ -194,43 +297,57 @@ This branch may or may not recieve bug fixes. Feel free to fork the repo and mak - TrackContainer, Query - dialog will not open after first trigger ## [1.0.0-beta2] - 2018-06-05 + ### Added + - Custom script to build in CI ### Changed + - Travis - use a more complex build config ### Fixed + - FFMPEG_PATH in non-windows platforms - **NOTE** - Linux and OSX users need to manually install FFmpeg and set to PATH ## [1.0.0-beta1] - 2018-06-05 + ### Changed + - Remove unused packages [reduces build size] ### Fixed + - Build failure because of condition require in fluent-ffmpeg ## [1.0.0-alpha3] - 2018-06-05 + ### Added + - Custom README - Travis CI configuration [Supports multi-platform build!] - Added image assets ### Changed -- Final build files will not have ${platform} + +- Final build files will not have \${platform} ### Fixed + - Menu stays open when miniWindow is triggered ## [1.0.0-alpha2] - 2018-06-04 + ### Added + - Module YTDownload for downloading in MP3 - YTDownload - add progress listener - YTDownload - multi-format download (mp3 and m4a) - Settings - basic settings functionalities ### Changed + - TrackContainer - implement YTDownload - TrackContainer - migrate to React.Component - YTDownload - use filter options to grab 'auidioonly' @@ -241,17 +358,22 @@ This branch may or may not recieve bug fixes. Feel free to fork the repo and mak - YTDownload - get Spotify metadata from props ### Fixed + - YTDownload - fix improper module export - TrackContainer - fix CircularProgress on error - Fix class names in About and Terms ## [1.0.0-alpha1] - 2018-06-03 + ### Added + - Terms - add terms of use - About - add basic content ## [1.0.0-pre-alpha] - 2018-06-02 + ### Added + - Module YTCore - streaming audio from YouTube - Module YTSearch - uses YouTube's V3 API to search for songs - Module SpotifyWebApi - uses Spotify's Web API for requesting metadata @@ -265,6 +387,7 @@ This branch may or may not recieve bug fixes. Feel free to fork the repo and mak - VideoContainer - add onClick handler to play audio ### Changed + - Use seperate build directory (react-compiled) for react's production builds - TopAppBar - go back to per-view render mode - TopAppBar - add "go back" in Search @@ -280,7 +403,8 @@ This branch may or may not recieve bug fixes. Feel free to fork the repo and mak - package.json - add important fields (author, productName, description and more) and remove unused packages ### Fixed -- QueryField - wrong URL passed while invoking new BrowserWindow + +- QueryField - wrong URL passed while invoking new BrowserWindow - electron.js - fix URL path - Query - fix displaying encoded URI as title - Query - use decodeURI() before passing to search() diff --git a/README.md b/README.md index fca3118..923dfd3 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ Audius is a cross-platform application which can be used to download songs from YouTube and Spotify -[![Build Status for "master"](https://travis-ci.com/mihirpathak97/audius.svg?token=ebex5hGA4p6XqQ9m8EVi&branch=master)](https://travis-ci.com/mihirpathak97/audius) -[![Node JS dependencies](https://david-dm.org/mihirpathak97/audius.svg)](https://travis-ci.com/mihirpathak97/audius) +[![Build Status for "master"](https://travis-ci.com/mihirpathak97/audius.svg)](https://travis-ci.com/mihirpathak97/audius) +[![Node JS dependencies](https://david-dm.org/mihirpathak97/audius.svg)](https://david-dm.org/mihirpathak97/audius) **Written with [electronjs](https://electronjs.org/)** @@ -16,20 +16,35 @@ Audius is a cross-platform application which can be used to download songs from Audius is currently supported for the following platforms: - Windows 7+ (64-bit) - Mac OS X 10.9+ (64-bit) -- Ubuntu 12.04+/Debian 8+ (64-bit) +- Linux (64-bit) But, this app can be built for any other platform that is officially supported -by [electronjs](https://github.com/electron/electron/blob/v2.0.2/docs/tutorial/support.md#supported-platforms). Head over to the docs for build instructions +by [electronjs](https://github.com/electron/electron/blob/v2.0.2/docs/tutorial/support.md#supported-platforms). Head over to the docs for build instructions. ## Installing Download the latest Audius release [here](https://github.com/mihirpathak97/audius/releases/latest) +**NOTE**: Make sure you have `ffmpeg` in your path, or you have specified the binary location in Settings. + **NOTE**: [OSX] This app is not code-signed so you will have to allow it to be opened in Privacy and Security settings. -**NOTE**: Auto updates are not supported in Linux :broken_heart: +### Installing FFMpeg + +#### Windows + +The recommended way of installing for windows is via [scoop](https://scoop.sh), but you can also use chocolatey 😁 + +#### Linux + +If your distribution supports installing `ffmpeg` via the package manager, go ahead and do it. Or you can always download the +binary from [here](https://ffmpeg.org) and set the path to the binary in the app's settings. + +#### Mac OSX +If you `brew`, then sorted, just run `brew install ffmpeg`, or get yourself the pre-compiled binary from [here](https://ffmpeg.org). + ## Disclaimer This app is subject to YouTube's terms and conditions. diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..082ef16 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,24 @@ +image: Visual Studio 2015 + +skip_non_tags: true + +environment: + PYTHON: "C:\\Python36-x64" + +install: + - ps: Install-Product node 12 + - git submodule update --init --recursive + - '%PYTHON%/Scripts/pip.exe install -U -r bin/rainbow/requirements.txt' + - 'yarn install' + +build_script: + - echo "Building raindow" + - 'cd bin/rainbow && %PYTHON%/python.exe setup.py build && cd ../../' + + - 'yarn build' + + - echo "Packaging Audius for Windows x64 (EXE)"; + - 'yarn package:win' + +artifacts: + - path: dist/AudiusSetup-x64.exe diff --git a/bin/rainbow b/bin/rainbow new file mode 160000 index 0000000..03ff22d --- /dev/null +++ b/bin/rainbow @@ -0,0 +1 @@ +Subproject commit 03ff22d3a80ed4b15eb4af032017a8538da0f9b9 diff --git a/config/env.js b/config/env.js index b0344c5..86297ed 100644 --- a/config/env.js +++ b/config/env.js @@ -15,7 +15,7 @@ if (!NODE_ENV) { } // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use -var dotenvFiles = [ +const dotenvFiles = [ `${paths.dotenv}.${NODE_ENV}.local`, `${paths.dotenv}.${NODE_ENV}`, // Don't include `.env.local` for `test` environment @@ -58,11 +58,10 @@ process.env.NODE_PATH = (process.env.NODE_PATH || '') // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be // injected into the application via DefinePlugin in Webpack configuration. -const REACT_APP = /^REACT_APP_/i; +// const REACT_APP = /^REACT_APP_/i; function getClientEnvironment(publicUrl) { const raw = Object.keys(process.env) - .filter(key => REACT_APP.test(key)) .reduce( (env, key) => { env[key] = process.env[key]; diff --git a/config/jest/fileTransform.js b/config/jest/fileTransform.js index 07010e3..74dc1aa 100644 --- a/config/jest/fileTransform.js +++ b/config/jest/fileTransform.js @@ -1,6 +1,7 @@ 'use strict'; const path = require('path'); +const camelcase = require('camelcase'); // This is a custom Jest transformer turning file imports into filenames. // http://facebook.github.io/jest/docs/en/webpack.html @@ -10,17 +11,26 @@ module.exports = { const assetFilename = JSON.stringify(path.basename(filename)); if (filename.match(/\.svg$/)) { - return `module.exports = { + // Based on how SVGR generates a component name: + // https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6 + const pascalCaseFileName = camelcase(path.parse(filename).name, { + pascalCase: true, + }); + const componentName = `Svg${pascalCaseFileName}`; + return `const React = require('react'); + module.exports = { __esModule: true, default: ${assetFilename}, - ReactComponent: (props) => ({ - $$typeof: Symbol.for('react.element'), - type: 'svg', - ref: null, - key: null, - props: Object.assign({}, props, { - children: ${assetFilename} - }) + ReactComponent: React.forwardRef(function ${componentName}(props, ref) { + return { + $$typeof: Symbol.for('react.element'), + type: 'svg', + ref: ref, + key: null, + props: Object.assign({}, props, { + children: ${assetFilename} + }) + }; }), };`; } diff --git a/config/modules.js b/config/modules.js new file mode 100644 index 0000000..c84210a --- /dev/null +++ b/config/modules.js @@ -0,0 +1,141 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const paths = require('./paths'); +const chalk = require('react-dev-utils/chalk'); +const resolve = require('resolve'); + +/** + * Get additional module paths based on the baseUrl of a compilerOptions object. + * + * @param {Object} options + */ +function getAdditionalModulePaths(options = {}) { + const baseUrl = options.baseUrl; + + // We need to explicitly check for null and undefined (and not a falsy value) because + // TypeScript treats an empty string as `.`. + if (baseUrl == null) { + // If there's no baseUrl set we respect NODE_PATH + // Note that NODE_PATH is deprecated and will be removed + // in the next major release of create-react-app. + + const nodePath = process.env.NODE_PATH || ''; + return nodePath.split(path.delimiter).filter(Boolean); + } + + const baseUrlResolved = path.resolve(paths.appPath, baseUrl); + + // We don't need to do anything if `baseUrl` is set to `node_modules`. This is + // the default behavior. + if (path.relative(paths.appNodeModules, baseUrlResolved) === '') { + return null; + } + + // Allow the user set the `baseUrl` to `appSrc`. + if (path.relative(paths.appSrc, baseUrlResolved) === '') { + return [paths.appSrc]; + } + + // If the path is equal to the root directory we ignore it here. + // We don't want to allow importing from the root directly as source files are + // not transpiled outside of `src`. We do allow importing them with the + // absolute path (e.g. `src/Components/Button.js`) but we set that up with + // an alias. + if (path.relative(paths.appPath, baseUrlResolved) === '') { + return null; + } + + // Otherwise, throw an error. + throw new Error( + chalk.red.bold( + "Your project's `baseUrl` can only be set to `src` or `node_modules`." + + ' Create React App does not support other values at this time.' + ) + ); +} + +/** + * Get webpack aliases based on the baseUrl of a compilerOptions object. + * + * @param {*} options + */ +function getWebpackAliases(options = {}) { + const baseUrl = options.baseUrl; + + if (!baseUrl) { + return {}; + } + + const baseUrlResolved = path.resolve(paths.appPath, baseUrl); + + if (path.relative(paths.appPath, baseUrlResolved) === '') { + return { + src: paths.appSrc, + }; + } +} + +/** + * Get jest aliases based on the baseUrl of a compilerOptions object. + * + * @param {*} options + */ +function getJestAliases(options = {}) { + const baseUrl = options.baseUrl; + + if (!baseUrl) { + return {}; + } + + const baseUrlResolved = path.resolve(paths.appPath, baseUrl); + + if (path.relative(paths.appPath, baseUrlResolved) === '') { + return { + 'src/(.*)$': '/src/$1', + }; + } +} + +function getModules() { + // Check if TypeScript is setup + const hasTsConfig = fs.existsSync(paths.appTsConfig); + const hasJsConfig = fs.existsSync(paths.appJsConfig); + + if (hasTsConfig && hasJsConfig) { + throw new Error( + 'You have both a tsconfig.json and a jsconfig.json. If you are using TypeScript please remove your jsconfig.json file.' + ); + } + + let config; + + // If there's a tsconfig.json we assume it's a + // TypeScript project and set up the config + // based on tsconfig.json + if (hasTsConfig) { + const ts = require(resolve.sync('typescript', { + basedir: paths.appNodeModules, + })); + config = ts.readConfigFile(paths.appTsConfig, ts.sys.readFile).config; + // Otherwise we'll check if there is jsconfig.json + // for non TS projects. + } else if (hasJsConfig) { + config = require(paths.appJsConfig); + } + + config = config || {}; + const options = config.compilerOptions || {}; + + const additionalModulePaths = getAdditionalModulePaths(options); + + return { + additionalModulePaths: additionalModulePaths, + webpackAliases: getWebpackAliases(options), + jestAliases: getJestAliases(options), + hasTsConfig, + }; +} + +module.exports = getModules(); diff --git a/config/paths.js b/config/paths.js index 646c9a6..2d9d988 100644 --- a/config/paths.js +++ b/config/paths.js @@ -38,6 +38,33 @@ function getServedPath(appPackageJson) { return ensureSlash(servedUrl, true); } +const moduleFileExtensions = [ + 'web.mjs', + 'mjs', + 'web.js', + 'js', + 'web.ts', + 'ts', + 'web.tsx', + 'tsx', + 'json', + 'web.jsx', + 'jsx', +]; + +// Resolve file paths in the same order as webpack +const resolveModule = (resolveFn, filePath) => { + const extension = moduleFileExtensions.find(extension => + fs.existsSync(resolveFn(`${filePath}.${extension}`)) + ); + + if (extension) { + return resolveFn(`${filePath}.${extension}`); + } + + return resolveFn(`${filePath}.js`); +}; + // config after eject: we're in ./config/ module.exports = { dotenv: resolveApp('.env'), @@ -45,13 +72,19 @@ module.exports = { appBuild: resolveApp('react-compiled'), appPublic: resolveApp('src'), appHtml: resolveApp('src/app.html'), - appIndexJs: resolveApp('src/app.renderer.js'), + appIndexJs: resolveModule(resolveApp, 'src/app.renderer'), appPackageJson: resolveApp('package.json'), appSrc: resolveApp('src'), + appTsConfig: resolveApp('tsconfig.json'), + appJsConfig: resolveApp('jsconfig.json'), yarnLockFile: resolveApp('yarn.lock'), - testsSetup: resolveApp('src/setupTests.js'), + testsSetup: resolveModule(resolveApp, 'src/setupTests'), proxySetup: resolveApp('src/setupProxy.js'), appNodeModules: resolveApp('node_modules'), publicUrl: getPublicUrl(resolveApp('package.json')), - servedPath: getServedPath(resolveApp('package.json')), + servedPath: 'audius://' }; + + + +module.exports.moduleFileExtensions = moduleFileExtensions; diff --git a/config/pnpTs.js b/config/pnpTs.js new file mode 100644 index 0000000..d1b0539 --- /dev/null +++ b/config/pnpTs.js @@ -0,0 +1,35 @@ +'use strict'; + +const { resolveModuleName } = require('ts-pnp'); + +exports.resolveModuleName = ( + typescript, + moduleName, + containingFile, + compilerOptions, + resolutionHost +) => { + return resolveModuleName( + moduleName, + containingFile, + compilerOptions, + resolutionHost, + typescript.resolveModuleName + ); +}; + +exports.resolveTypeReferenceDirective = ( + typescript, + moduleName, + containingFile, + compilerOptions, + resolutionHost +) => { + return resolveModuleName( + moduleName, + containingFile, + compilerOptions, + resolutionHost, + typescript.resolveTypeReferenceDirective + ); +}; diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js deleted file mode 100644 index f46917c..0000000 --- a/config/webpack.config.dev.js +++ /dev/null @@ -1,396 +0,0 @@ -'use strict'; - -const path = require('path'); -const webpack = require('webpack'); -const PnpWebpackPlugin = require('pnp-webpack-plugin'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); -const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); -const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin'); -const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin'); -const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent'); -const getClientEnvironment = require('./env'); -const paths = require('./paths'); -const ManifestPlugin = require('webpack-manifest-plugin'); -const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier'); -const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin'); - -// Webpack uses `publicPath` to determine where the app is being served from. -// In development, we always serve from the root. This makes config easier. -const publicPath = '/'; -// `publicUrl` is just like `publicPath`, but we will provide it to our app -// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript. -// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz. -const publicUrl = ''; -// Get environment variables to inject into our app. -const env = getClientEnvironment(publicUrl); - -// style files regexes -const cssRegex = /\.css$/; -const cssModuleRegex = /\.module\.css$/; -const sassRegex = /\.(scss|sass)$/; -const sassModuleRegex = /\.module\.(scss|sass)$/; - -// common function to get style loaders -const getStyleLoaders = (cssOptions, preProcessor) => { - const loaders = [ - require.resolve('style-loader'), - { - loader: require.resolve('css-loader'), - options: cssOptions, - }, - { - // Options for PostCSS as we reference these options twice - // Adds vendor prefixing based on your specified browser support in - // package.json - loader: require.resolve('postcss-loader'), - options: { - // Necessary for external CSS imports to work - // https://github.com/facebook/create-react-app/issues/2677 - ident: 'postcss', - plugins: () => [ - require('postcss-flexbugs-fixes'), - require('postcss-preset-env')({ - autoprefixer: { - flexbox: 'no-2009', - }, - stage: 3, - }), - ], - }, - }, - ]; - if (preProcessor) { - loaders.push(require.resolve(preProcessor)); - } - return loaders; -}; - -// This is the development configuration. -// It is focused on developer experience and fast rebuilds. -// The production configuration is different and lives in a separate file. -module.exports = { - mode: 'development', - // You may want 'eval' instead if you prefer to see the compiled output in DevTools. - // See the discussion in https://github.com/facebook/create-react-app/issues/343 - devtool: 'cheap-module-source-map', - // These are the "entry points" to our application. - // This means they will be the "root" imports that are included in JS bundle. - entry: [ - // Include an alternative client for WebpackDevServer. A client's job is to - // connect to WebpackDevServer by a socket and get notified about changes. - // When you save a file, the client will either apply hot updates (in case - // of CSS changes), or refresh the page (in case of JS changes). When you - // make a syntax error, this client will display a syntax error overlay. - // Note: instead of the default WebpackDevServer client, we use a custom one - // to bring better experience for Create React App users. You can replace - // the line below with these two lines if you prefer the stock client: - // require.resolve('webpack-dev-server/client') + '?/', - // require.resolve('webpack/hot/dev-server'), - require.resolve('react-dev-utils/webpackHotDevClient'), - // Finally, this is your app's code: - paths.appIndexJs, - // We include the app code last so that if there is a runtime error during - // initialization, it doesn't blow up the WebpackDevServer client, and - // changing JS code would still trigger a refresh. - ], - output: { - // Add /* filename */ comments to generated require()s in the output. - pathinfo: true, - // This does not produce a real file. It's just the virtual path that is - // served by WebpackDevServer in development. This is the JS bundle - // containing code from all our entry points, and the Webpack runtime. - filename: 'static/js/bundle.js', - // There are also additional JS chunk files if you use code splitting. - chunkFilename: 'static/js/[name].chunk.js', - // This is the URL that app is served from. We use "/" in development. - publicPath: publicPath, - // Point sourcemap entries to original disk location (format as URL on Windows) - devtoolModuleFilenameTemplate: info => - path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'), - }, - optimization: { - // Automatically split vendor and commons - // https://twitter.com/wSokra/status/969633336732905474 - // https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366 - splitChunks: { - chunks: 'all', - name: false, - }, - // Keep the runtime chunk seperated to enable long term caching - // https://twitter.com/wSokra/status/969679223278505985 - runtimeChunk: true, - }, - resolve: { - // This allows you to set a fallback for where Webpack should look for modules. - // We placed these paths second because we want `node_modules` to "win" - // if there are any conflicts. This matches Node resolution mechanism. - // https://github.com/facebook/create-react-app/issues/253 - modules: ['node_modules'].concat( - // It is guaranteed to exist because we tweak it in `env.js` - process.env.NODE_PATH.split(path.delimiter).filter(Boolean) - ), - // These are the reasonable defaults supported by the Node ecosystem. - // We also include JSX as a common component filename extension to support - // some tools, although we do not recommend using it, see: - // https://github.com/facebook/create-react-app/issues/290 - // `web` extension prefixes have been added for better support - // for React Native Web. - extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'], - alias: { - // Support React Native Web - // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ - 'react-native': 'react-native-web', - // electron-log - 'log': path.resolve(__dirname, '../src/modules/log') - }, - plugins: [ - // Adds support for installing with Plug'n'Play, leading to faster installs and adding - // guards against forgotten dependencies and such. - PnpWebpackPlugin, - // Prevents users from importing files from outside of src/ (or node_modules/). - // This often causes confusion because we only process files within src/ with babel. - // To fix this, we prevent you from importing files out of src/ -- if you'd like to, - // please link the files into your node_modules/ and let module-resolution kick in. - // Make sure your source files are compiled, as they will not be processed in any way. - new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), - ], - }, - resolveLoader: { - plugins: [ - // Also related to Plug'n'Play, but this time it tells Webpack to load its loaders - // from the current package. - PnpWebpackPlugin.moduleLoader(module), - ], - }, - module: { - strictExportPresence: true, - rules: [ - // Disable require.ensure as it's not a standard language feature. - { parser: { requireEnsure: false } }, - - // First, run the linter. - // It's important to do this before Babel processes the JS. - { - test: /\.(js|jsx)$/, - enforce: 'pre', - use: [ - { - options: { - formatter: require.resolve('react-dev-utils/eslintFormatter'), - eslintPath: require.resolve('eslint'), - - }, - loader: require.resolve('eslint-loader'), - }, - ], - include: paths.appSrc, - }, - { - // `mjs` support is still in its infancy in the ecosystem, so we don't - // support it. - // Modules who define their `browser` or `module` key as `mjs` force - // the use of this extension, so we need to tell webpack to fall back - // to auto mode (ES Module interop, allows ESM to import CommonJS). - test: /\.mjs$/, - include: /node_modules/, - type: 'javascript/auto', - }, - { - // "oneOf" will traverse all following loaders until one will - // match the requirements. When no loader matches it will fall - // back to the "file" loader at the end of the loader list. - oneOf: [ - // "url" loader works like "file" loader except that it embeds assets - // smaller than specified limit in bytes as data URLs to avoid requests. - // A missing `test` is equivalent to a match. - { - test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/], - loader: require.resolve('url-loader'), - options: { - limit: 10000, - name: 'static/media/[name].[hash:8].[ext]', - }, - }, - // Process application JS with Babel. - // The preset includes JSX, Flow, and some ESnext features. - { - test: /\.(js|jsx)$/, - include: paths.appSrc, - loader: require.resolve('babel-loader'), - options: { - customize: require.resolve( - 'babel-preset-react-app/webpack-overrides' - ), - - plugins: [ - [ - require.resolve('babel-plugin-named-asset-import'), - { - loaderMap: { - svg: { - ReactComponent: '@svgr/webpack?-prettier,-svgo![path]', - }, - }, - }, - ], - ], - // This is a feature of `babel-loader` for webpack (not Babel itself). - // It enables caching results in ./node_modules/.cache/babel-loader/ - // directory for faster rebuilds. - cacheDirectory: true, - // Don't waste time on Gzipping the cache - cacheCompression: false, - }, - }, - // Process any JS outside of the app with Babel. - // Unlike the application JS, we only compile the standard ES features. - { - test: /\.js$/, - exclude: /@babel(?:\/|\\{1,2})runtime/, - loader: require.resolve('babel-loader'), - options: { - babelrc: false, - configFile: false, - compact: false, - presets: [ - [ - require.resolve('babel-preset-react-app/dependencies'), - { helpers: true }, - ], - ], - cacheDirectory: true, - // Don't waste time on Gzipping the cache - cacheCompression: false, - - // If an error happens in a package, it's possible to be - // because it was compiled. Thus, we don't want the browser - // debugger to show the original code. Instead, the code - // being evaluated would be much more helpful. - sourceMaps: false, - }, - }, - // "postcss" loader applies autoprefixer to our CSS. - // "css" loader resolves paths in CSS and adds assets as dependencies. - // "style" loader turns CSS into JS modules that inject