forked from konveyor/tackle2-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🌱 Add a
common
package, server no longer needed in dev-mode (konvey…
…or#1271) ## Summary Add a `common` package to share envvar and proxy code between `server` and `client` packages. With shared proxy code, the express server is no longer required in client dev mode. ## Motivation The way environment variable handling code was shared between client and server was not optimal. Additionally, webpack-dev-server supports the same proxy package as used by the express server. By creating a common package, both the envvar handling and the proxies can be done in one place and shared to server and client. ## The new `common` package This package is written as an ESM module in typescript and uses rollupjs to generate both ESM and commonjs files. Both module formats are required to support various use cases and runtimes in the repo. The envvar processing now contains typing and centralized default values. Any future changes to configuration envvars will only need to be done here in one spot. ## Changes to `server` - The envvar processing is moved to the `common` package. - The proxy code was extracted to the `common` package. - The express server is doing as little as possible. ## Changes to `client` - The envvar processing is moved to the `common` package. - In the `index.html.ejs` template, the `window._env` variable is now just a string. This allows for more controlled processing as needed. If `_env` is empty, all default values will be used for `Env`. - Adjusted jest to use a typescript configuration file. Since jest, and ts-jest, don't work nicely with pure ESM modules, `common` needs to be available in a commonjs format. Also, when running jest (with ts-jest), ts-node needs to process all of the test sources as commonjs modules. This is why `tsconfig.json` needs a separate `ts-node` section. - `webpack.dev.ts` has been updated to provide the proxies in place of the express `server`. This allows us to skip using `server` when running `npm run start:dev:client`. - Adjust global/module d.ts files location to `client/types`. ## Important considerations - The relative file import rules are different between commonjs and esm packages. This limits the ability to change `client` to be an esm package since it would impact a lot of imports across the code base. - The `moduleResolution: "bundler"` setting for `client` allows for semi-ESM use, and relies on webpack to do proper lookups and code bundling at build time. - The `ts-node` configurations in tsconfig.json impact both the jest runtime and the webpack runtime. Webpack processed files can handle ESM packages, but the webpack runtime (i.e. anything in the `webpack.*.ts` files) is configured to run as a commonjs module. Really it is just subtle differences in import statements, but enough so they have a hard time coexisting. - If jest/ts-jest/ts-node ever properly support ESM code, all of the packages in the repo could move to ESM only configs. - `client/types/@hookform_resolvers_2.9.11.d.ts` exists because with `moduleResolution: "bundler"` the types cannot be found even though they exist. This was fixed in version `@hookform/resolvers@^3` but we can't upgrade to that version yet since it requires `yup@^1`. Signed-off-by: Scott J Dickerson <[email protected]>
- Loading branch information
Showing
25 changed files
with
2,116 additions
and
3,307 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { JestConfigWithTsJest } from "ts-jest"; | ||
|
||
// For a detailed explanation regarding each configuration property, visit: | ||
// https://jestjs.io/docs/en/configuration.html | ||
|
||
const config: JestConfigWithTsJest = { | ||
// Automatically clear mock calls and instances between every test | ||
clearMocks: true, | ||
|
||
// Indicates whether the coverage information should be collected while executing the test | ||
collectCoverage: false, | ||
|
||
// The directory where Jest should output its coverage files | ||
coverageDirectory: "coverage", | ||
|
||
// Stub out resources and provide handling for tsconfig.json paths | ||
moduleNameMapper: { | ||
// stub out files that don't matter for tests | ||
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js", | ||
"\\.(xsd)$": "<rootDir>/__mocks__/styleMock.js", | ||
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": | ||
"<rootDir>/__mocks__/fileMock.js", | ||
"@patternfly/react-icons/dist/esm/icons/": | ||
"<rootDir>/__mocks__/fileMock.js", | ||
|
||
// match the paths in tsconfig.json | ||
"@app/(.*)": "<rootDir>/src/app/$1", | ||
"@assets/(.*)": | ||
"<rootDir>../node_modules/@patternfly/react-core/dist/styles/assets/$1", | ||
}, | ||
|
||
// A list of paths to directories that Jest should use to search for files | ||
roots: ["<rootDir>/src"], | ||
|
||
// The test environment that will be used for testing | ||
testEnvironment: "jest-environment-jsdom", | ||
|
||
// The pattern or patterns Jest uses to find test files | ||
testMatch: ["<rootDir>/src/**/*.{test,spec}.{js,jsx,ts,tsx}"], | ||
|
||
// Process js/jsx/mjs/mjsx/ts/tsx/mts/mtsx with `ts-jest` | ||
transform: { | ||
"^.+\\.(js|mjs|ts|mts)x?$": "ts-jest", | ||
}, | ||
|
||
// Code to set up the testing framework before each test file in the suite is executed | ||
setupFilesAfterEnv: ["<rootDir>/src/app/setupTests.ts"], | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.