From e5dbb2a5e2a4360315373b544a1bb1cde7ea0197 Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Tue, 12 Oct 2021 19:14:50 +0300 Subject: [PATCH] web: add empty build-config package (#25965) --- .github/workflows/lsif.yml | 1 + .vscode/settings.json | 1 + client/build-config/.eslintignore | 1 + client/build-config/.eslintrc.js | 13 +++++++++++++ client/build-config/README.md | 3 +++ client/build-config/babel.config.js | 5 +++++ client/build-config/jest.config.js | 14 ++++++++++++++ client/build-config/package.json | 13 +++++++++++++ client/build-config/src/index.ts | 1 + client/build-config/src/paths.ts | 3 +++ client/build-config/tsconfig.json | 11 +++++++++++ client/storybook/package.json | 3 +++ client/storybook/src/main.ts | 17 +++++++++-------- client/storybook/tsconfig.json | 2 +- dev/foreach-ts-project.sh | 1 + jest.config.js | 1 + tsconfig.all.json | 1 + 17 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 client/build-config/.eslintignore create mode 100644 client/build-config/.eslintrc.js create mode 100644 client/build-config/README.md create mode 100644 client/build-config/babel.config.js create mode 100644 client/build-config/jest.config.js create mode 100644 client/build-config/package.json create mode 100644 client/build-config/src/index.ts create mode 100644 client/build-config/src/paths.ts create mode 100644 client/build-config/tsconfig.json diff --git a/.github/workflows/lsif.yml b/.github/workflows/lsif.yml index e8fa2c4a881..5393a7aaa7b 100644 --- a/.github/workflows/lsif.yml +++ b/.github/workflows/lsif.yml @@ -49,6 +49,7 @@ jobs: root: - client/branded - client/browser + - client/build-config - client/shared - client/web - client/wildcard diff --git a/.vscode/settings.json b/.vscode/settings.json index 0146ffe339e..361655dd383 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -59,6 +59,7 @@ "./dev/release", "./client/web", "./client/browser", + "./client/build-config", "./client/shared", "./client/branded", "./client/wildcard", diff --git a/client/build-config/.eslintignore b/client/build-config/.eslintignore new file mode 100644 index 00000000000..89f9ac04aac --- /dev/null +++ b/client/build-config/.eslintignore @@ -0,0 +1 @@ +out/ diff --git a/client/build-config/.eslintrc.js b/client/build-config/.eslintrc.js new file mode 100644 index 00000000000..3747f40c469 --- /dev/null +++ b/client/build-config/.eslintrc.js @@ -0,0 +1,13 @@ +// @ts-check + +const baseConfig = require('../../.eslintrc.js') + +module.exports = { + extends: '../../.eslintrc.js', + parserOptions: { + ...baseConfig.parserOptions, + project: [__dirname + '/tsconfig.json'], + }, + rules: {}, + overrides: baseConfig.overrides, +} diff --git a/client/build-config/README.md b/client/build-config/README.md new file mode 100644 index 00000000000..0d5f6795ff5 --- /dev/null +++ b/client/build-config/README.md @@ -0,0 +1,3 @@ +# Build config + +Shared build configuration. diff --git a/client/build-config/babel.config.js b/client/build-config/babel.config.js new file mode 100644 index 00000000000..73a95d310cd --- /dev/null +++ b/client/build-config/babel.config.js @@ -0,0 +1,5 @@ +// @ts-check + +module.exports = { + extends: '../../babel.config.js', +} diff --git a/client/build-config/jest.config.js b/client/build-config/jest.config.js new file mode 100644 index 00000000000..c994e943e0b --- /dev/null +++ b/client/build-config/jest.config.js @@ -0,0 +1,14 @@ +// @ts-check + +const config = require('../../jest.config.base') + +const exportedConfig = { + ...config, + displayName: 'build-config', + rootDir: __dirname, + collectCoverage: false, // Collected through Puppeteer + roots: [''], + verbose: true, +} + +module.exports = exportedConfig diff --git a/client/build-config/package.json b/client/build-config/package.json new file mode 100644 index 00000000000..589bc18551e --- /dev/null +++ b/client/build-config/package.json @@ -0,0 +1,13 @@ +{ + "private": true, + "name": "@sourcegraph/build-config", + "version": "0.0.1", + "description": "Sourcegraph Build configuration", + "main": "./src/index.ts", + "sideEffects": false, + "license": "Apache-2.0", + "scripts": { + "eslint": "eslint --cache 'src/**/*.[jt]s?(x)'", + "test": "jest" + } +} diff --git a/client/build-config/src/index.ts b/client/build-config/src/index.ts new file mode 100644 index 00000000000..676f1e5f90b --- /dev/null +++ b/client/build-config/src/index.ts @@ -0,0 +1 @@ +export * from './paths' diff --git a/client/build-config/src/paths.ts b/client/build-config/src/paths.ts new file mode 100644 index 00000000000..140a82bf9f4 --- /dev/null +++ b/client/build-config/src/paths.ts @@ -0,0 +1,3 @@ +import path from 'path' + +export const ROOT_PATH = path.resolve(__dirname, '../../../') diff --git a/client/build-config/tsconfig.json b/client/build-config/tsconfig.json new file mode 100644 index 00000000000..f7ccf2fabb2 --- /dev/null +++ b/client/build-config/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "sourceRoot": "src", + "rootDir": ".", + "outDir": "./out", + "baseUrl": "./src", + }, + "include": ["./src/**/*", "./*.ts"], +} diff --git a/client/storybook/package.json b/client/storybook/package.json index 910c801f285..79cf731bf45 100644 --- a/client/storybook/package.json +++ b/client/storybook/package.json @@ -14,5 +14,8 @@ "start:dll": "TS_NODE_TRANSPILE_ONLY=true WEBPACK_DLL_PLUGIN=true start-storybook -p 9001 -c ./src -s ./assets", "clean:dll": "rm -rf assets/dll-bundle storybook-static/*-stats.json", "test": "jest" + }, + "devDependencies": { + "@sourcegraph/build-config": "0.0.1" } } diff --git a/client/storybook/src/main.ts b/client/storybook/src/main.ts index ab384543c97..0e61be7706c 100644 --- a/client/storybook/src/main.ts +++ b/client/storybook/src/main.ts @@ -17,10 +17,11 @@ import webpack, { } from 'webpack' import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer' +import { ROOT_PATH } from '@sourcegraph/build-config' + import { ensureDllBundleIsReady } from './dllPlugin' import { environment } from './environment-config' import { - rootPath, monacoEditorPath, dllPluginConfig, dllBundleManifestPath, @@ -35,18 +36,18 @@ import { const getStoriesGlob = (): string[] => { if (process.env.STORIES_GLOB) { - return [path.resolve(rootPath, process.env.STORIES_GLOB)] + return [path.resolve(ROOT_PATH, process.env.STORIES_GLOB)] } // Stories in `Chromatic.story.tsx` are guarded by the `isChromatic()` check. It will result in noop in all other environments. - const chromaticStoriesGlob = path.resolve(rootPath, 'client/storybook/src/chromatic-story/Chromatic.story.tsx') + const chromaticStoriesGlob = path.resolve(ROOT_PATH, 'client/storybook/src/chromatic-story/Chromatic.story.tsx') // Due to an issue with constant recompiling (https://github.com/storybookjs/storybook/issues/14342) // we need to make the globs more specific (`(web|shared..)` also doesn't work). Once the above issue // is fixed, this can be removed and watched for `client/**/*.story.tsx` again. const directoriesWithStories = ['branded', 'browser', 'shared', 'web', 'wildcard'] const storiesGlobs = directoriesWithStories.map(packageDirectory => - path.resolve(rootPath, `client/${packageDirectory}/src/**/*.story.tsx`) + path.resolve(ROOT_PATH, `client/${packageDirectory}/src/**/*.story.tsx`) ) return [...storiesGlobs, chromaticStoriesGlob] @@ -59,7 +60,7 @@ const getCSSLoaders = (...loaders: RuleSetUseItem[]): RuleSetUse => [ loader: 'sass-loader', options: { sassOptions: { - includePaths: [path.resolve(rootPath, 'node_modules'), path.resolve(rootPath, 'client')], + includePaths: [path.resolve(ROOT_PATH, 'node_modules'), path.resolve(ROOT_PATH, 'client')], }, }, }, @@ -157,8 +158,8 @@ const config = { config: [ __filename, path.resolve(storybookWorkspacePath, 'babel.config.js'), - path.resolve(rootPath, 'babel.config.js'), - path.resolve(rootPath, 'postcss.config.js'), + path.resolve(ROOT_PATH, 'babel.config.js'), + path.resolve(ROOT_PATH, 'postcss.config.js'), path.resolve(__dirname, './webpack.config.dll.ts'), ], }, @@ -172,7 +173,7 @@ const config = { loader: require.resolve('babel-loader'), options: { cacheDirectory: true, - configFile: path.resolve(rootPath, 'babel.config.js'), + configFile: path.resolve(ROOT_PATH, 'babel.config.js'), }, }) diff --git a/client/storybook/tsconfig.json b/client/storybook/tsconfig.json index cdb52c96b58..fb8f29e6ea0 100644 --- a/client/storybook/tsconfig.json +++ b/client/storybook/tsconfig.json @@ -8,6 +8,6 @@ "baseUrl": "./src", "jsx": "react", }, - "references": [{ "path": "../shared" }], + "references": [{ "path": "../shared" }, { "path": "../build-config" }], "include": ["./src/**/*", "./*.ts"], } diff --git a/dev/foreach-ts-project.sh b/dev/foreach-ts-project.sh index a3d45577b65..852bc7b25e9 100755 --- a/dev/foreach-ts-project.sh +++ b/dev/foreach-ts-project.sh @@ -15,6 +15,7 @@ DIRS=( client/shared client/branded client/browser + client/build-config client/wildcard client/extension-api client/eslint-plugin-sourcegraph diff --git a/jest.config.js b/jest.config.js index 3b3d8d7f7ed..8539f5a381d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,6 +7,7 @@ const config = require('./jest.config.base') module.exports = { projects: [ 'client/browser/jest.config.js', + 'client/build-config/jest.config.js', 'client/shared/jest.config.js', 'client/branded/jest.config.js', 'client/web/jest.config.js', diff --git a/tsconfig.all.json b/tsconfig.all.json index 9c6630fecf7..e280548af4e 100644 --- a/tsconfig.all.json +++ b/tsconfig.all.json @@ -1,6 +1,7 @@ { "extends": "./tsconfig.json", "references": [ + { "path": "client/build-config" }, { "path": "client/shared" }, { "path": "client/shared/src/testing" }, { "path": "client/branded" },