Merge branch '21703-collection-update-lock'
[arvados.git] / services / workbench2 / config / paths.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 'use strict';
6
7 const path = require('path');
8 const fs = require('fs');
9 const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath');
10
11 // Make sure any symlinks in the project folder are resolved:
12 // https://github.com/facebook/create-react-app/issues/637
13 const appDirectory = fs.realpathSync(process.cwd());
14 const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
15
16 // We use `PUBLIC_URL` environment variable or "homepage" field to infer
17 // "public path" at which the app is served.
18 // webpack needs to know it to put the right <script> hrefs into HTML even in
19 // single-page apps that may serve index.html for nested URLs like /todos/42.
20 // We can't use a relative path in HTML because we don't want to load something
21 // like /todos/42/static/js/bundle.7289d.js. We have to know the root.
22 const publicUrlOrPath = getPublicUrlOrPath(
23   process.env.NODE_ENV === 'development',
24   require(resolveApp('package.json')).homepage,
25   process.env.PUBLIC_URL
26 );
27
28 const buildPath = process.env.BUILD_PATH || 'build';
29
30 const moduleFileExtensions = [
31   'web.mjs',
32   'mjs',
33   'web.js',
34   'js',
35   'web.ts',
36   'ts',
37   'web.tsx',
38   'tsx',
39   'json',
40   'web.jsx',
41   'jsx',
42 ];
43
44 // Resolve file paths in the same order as webpack
45 const resolveModule = (resolveFn, filePath) => {
46   const extension = moduleFileExtensions.find(extension =>
47     fs.existsSync(resolveFn(`${filePath}.${extension}`))
48   );
49
50   if (extension) {
51     return resolveFn(`${filePath}.${extension}`);
52   }
53
54   return resolveFn(`${filePath}.js`);
55 };
56
57 // config after eject: we're in ./config/
58 module.exports = {
59   dotenv: resolveApp('.env'),
60   appPath: resolveApp('.'),
61   appBuild: resolveApp(buildPath),
62   appPublic: resolveApp('public'),
63   appHtml: resolveApp('public/index.html'),
64   appIndexJs: resolveModule(resolveApp, 'src/index'),
65   appPackageJson: resolveApp('package.json'),
66   appSrc: resolveApp('src'),
67   appTsConfig: resolveApp('tsconfig.json'),
68   appJsConfig: resolveApp('jsconfig.json'),
69   yarnLockFile: resolveApp('yarn.lock'),
70   testsSetup: resolveModule(resolveApp, 'src/setupTests'),
71   proxySetup: resolveApp('src/setupProxy.js'),
72   appNodeModules: resolveApp('node_modules'),
73   appWebpackCache: resolveApp('node_modules/.cache'),
74   appTsBuildInfoFile: resolveApp('node_modules/.cache/tsconfig.tsbuildinfo'),
75   swSrc: resolveModule(resolveApp, 'src/service-worker'),
76   publicUrlOrPath,
77 };
78
79
80
81 module.exports.moduleFileExtensions = moduleFileExtensions;