diff --git a/config/jest/client.config.js b/config/jest/client.config.js index d5cc83ce3..507257368 100644 --- a/config/jest/client.config.js +++ b/config/jest/client.config.js @@ -24,6 +24,7 @@ module.exports = { ], moduleNameMapper: { "^talk-admin/(.*)$": "/src/core/client/admin/$1", + "^talk-auth/(.*)$": "/src/core/client/auth/$1", "^talk-ui/(.*)$": "/src/core/client/ui/$1", "^talk-stream/(.*)$": "/src/core/client/stream/$1", "^talk-framework/(.*)$": "/src/core/client/framework/$1", diff --git a/config/watcher.ts b/config/watcher.ts index 277ec34ec..a05f22b0c 100644 --- a/config/watcher.ts +++ b/config/watcher.ts @@ -31,6 +31,23 @@ const config: Config = { runOnInit: true, }), }, + compileRelayAuth: { + paths: [ + "core/client/auth/**/*.ts", + "core/client/auth/**/*.tsx", + "core/client/auth/**/*.graphql", + "core/server/**/*.graphql", + ], + ignore: [ + "core/**/*.d.ts", + "core/**/*.graphql.ts", + "**/test/**/*", + "core/**/*.spec.*", + ], + executor: new CommandExecutor("npm run compile:relay-auth", { + runOnInit: true, + }), + }, compileCSSTypes: { paths: ["**/*.css"], executor: new CommandExecutor("npm run compile:css-types", { @@ -59,9 +76,15 @@ const config: Config = { "runWebpackDevServer", "compileCSSTypes", "compileRelayStream", + "compileRelayAuth", ], docz: ["runDocz", "compileCSSTypes"], - compile: ["compileSchema", "compileCSSTypes", "compileRelayStream"], + compile: [ + "compileSchema", + "compileCSSTypes", + "compileRelayStream", + "compileRelayAuth", + ], }, }; diff --git a/package.json b/package.json index d02d7d0ef..d546b9c17 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "compile": "npm-run-all --parallel compile:*", "compile:css-types": "tcm src/core/client/", "compile:relay-stream": "ts-node ./scripts/compileRelay --src ./src/core/client/stream --schema tenant", + "compile:relay-auth": "ts-node ./scripts/compileRelay --src ./src/core/client/auth --schema tenant", "compile:schema": "node ./scripts/generateSchemaTypes.js", "docz": "docz", "start": "node dist/index.js", diff --git a/src/core/build/createWebpackConfig.ts b/src/core/build/createWebpackConfig.ts index e14cb250a..ea6d4b196 100644 --- a/src/core/build/createWebpackConfig.ts +++ b/src/core/build/createWebpackConfig.ts @@ -80,6 +80,28 @@ export default function createWebpackConfig({ }, ]; + const localesOptions = { + pathToLocales: paths.appLocales, + + // Default locale if non could be negotiated. + defaultLocale: "en-US", + + // Fallback locale if a translation was not found. + // If not set, will use the text that is already + // in the code base. + fallbackLocale: "en-US", + + // Common fluent files are always included in the locale bundles. + commonFiles: ["framework.ftl", "common.ftl"], + + // Locales that come with the main bundle. Others are loaded on demand. + bundled: ["en-US"], + + // All available locales can be loadable on demand. + // To restrict available locales set: + // availableLocales: ["en-US"], + }; + const additionalPlugins = isProduction ? [ // Minify the code. @@ -214,29 +236,26 @@ export default function createWebpackConfig({ { loader: "locales-loader", options: { - pathToLocales: paths.appLocales, - - // Default locale if non could be negotiated. - defaultLocale: "en-US", - - // Fallback locale if a translation was not found. - // If not set, will use the text that is already - // in the code base. - fallbackLocale: "en-US", - - // Common fluent files are always included in the locale bundles. - commonFiles: ["framework.ftl", "common.ftl"], - - // Locales that come with the main bundle. Others are loaded on demand. - bundled: ["en-US"], - + ...localesOptions, // Target specifies the prefix for fluent files to be loaded. // ${target}-xyz.ftl and ${†arget}.ftl are loaded into the locales. target: "stream", - - // All available locales can be loadable on demand. - // To restrict available locales set: - // availableLocales: ["en-US"], + }, + }, + ], + }, + { + test: paths.appAuthLocalesTemplate, + use: [ + // This is the locales loader that loads available locales + // from a particular target. + { + loader: "locales-loader", + options: { + ...localesOptions, + // Target specifies the prefix for fluent files to be loaded. + // ${target}-xyz.ftl and ${†arget}.ftl are loaded into the locales. + target: "auth", }, }, ], @@ -380,6 +399,24 @@ export default function createWebpackConfig({ paths.appStreamIndex, // Remove deactivated entries. ].filter(s => s), + auth: [ + // We ship polyfills by default + paths.appPolyfill, + // 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'), + (isProduction && "") || + require.resolve("react-dev-utils/webpackHotDevClient"), + paths.appAuthIndex, + // Remove deactivated entries. + ].filter(s => s), }, plugins: [ ...baseConfig.plugins!, @@ -391,6 +428,14 @@ export default function createWebpackConfig({ inject: "body", ...htmlWebpackConfig, }), + // Generates an `auth.html` file with the