@dr.pogodin/react-utils 1.55.0-alpha.4 → 1.55.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/bin/build.js +6 -6
  2. package/build/development/server/utils/index.js +1 -0
  3. package/build/development/server/utils/index.js.map +1 -1
  4. package/build/development/server/utils/modules.js +71 -0
  5. package/build/development/server/utils/modules.js.map +1 -0
  6. package/build/development/shared/utils/jest/E2eSsrEnv/ssr-preload.js +2 -21
  7. package/build/development/shared/utils/jest/E2eSsrEnv/ssr-preload.js.map +1 -1
  8. package/build/development/shared/utils/jest/E2eSsrEnv/ssr.js +6 -25
  9. package/build/development/shared/utils/jest/E2eSsrEnv/ssr.js.map +1 -1
  10. package/build/production/server/utils/index.js +1 -1
  11. package/build/production/server/utils/index.js.map +1 -1
  12. package/build/production/server/utils/modules.js +12 -0
  13. package/build/production/server/utils/modules.js.map +1 -0
  14. package/build/production/shared/utils/jest/E2eSsrEnv/ssr-preload.js +1 -3
  15. package/build/production/shared/utils/jest/E2eSsrEnv/ssr-preload.js.map +1 -1
  16. package/build/production/shared/utils/jest/E2eSsrEnv/ssr.js +3 -2
  17. package/build/production/shared/utils/jest/E2eSsrEnv/ssr.js.map +1 -1
  18. package/build/types-code/server/utils/index.d.ts +1 -0
  19. package/build/types-code/server/utils/modules.d.ts +18 -0
  20. package/build/web/server/utils/index.js +1 -1
  21. package/build/web/server/utils/index.js.map +1 -1
  22. package/build/web/server/utils/modules.js +12 -0
  23. package/build/web/server/utils/modules.js.map +1 -0
  24. package/build/web/shared/utils/jest/E2eSsrEnv/ssr-preload.js +1 -3
  25. package/build/web/shared/utils/jest/E2eSsrEnv/ssr-preload.js.map +1 -1
  26. package/build/web/shared/utils/jest/E2eSsrEnv/ssr.js +3 -2
  27. package/build/web/shared/utils/jest/E2eSsrEnv/ssr.js.map +1 -1
  28. package/config/babel/webpack.d.ts +2 -1
  29. package/config/babel/webpack.js +6 -1
  30. package/config/jest/default.js +1 -11
  31. package/package.json +9 -17
  32. package/tsconfig.types.json +1 -0
package/bin/build.js CHANGED
@@ -188,9 +188,8 @@ function buildWebBundle() {
188
188
  * @param extensions - Optional. Array of extensions
189
189
  * to transform, each starting with the leading dot (e.g. '.ts'). If absent,
190
190
  * Babel will use its default set of extensions.
191
- * @param keepFileExtensions - Optional. If set, Babel will
192
- * keep the original extensions for the transformed files; otherwise the will
193
- * be turned into '.js' files.
191
+ * @param outFileExtension - Optional. Allows to set arbitrary file extension of
192
+ * output files.
194
193
  * @param outDir - Output folder.
195
194
  * @param srcDir - Source folder.
196
195
  * @param watch - Optional. If set, Babel will be run in watch
@@ -201,8 +200,8 @@ async function runBabel({
201
200
  configPath,
202
201
  copyFiles,
203
202
  extensions,
204
- keepFileExtensions,
205
203
  outDir,
204
+ outFileExtension,
206
205
  srcDir,
207
206
  watch
208
207
  }) {
@@ -214,7 +213,7 @@ async function runBabel({
214
213
  }
215
214
  if (copyFiles) command += ' --copy-files';
216
215
  command += ` -x ${extensions.join(',')}`;
217
- if (keepFileExtensions) command += ' --keep-file-extension';
216
+ if (outFileExtension) command += ` --out-file-extension ${outFileExtension}`;
218
217
  if (watch) command += ' --watch';
219
218
  await exec(command, {
220
219
  env: {
@@ -265,8 +264,8 @@ async function buildWithBabelForServerSide({
265
264
  buildType,
266
265
  configPath,
267
266
  extensions: ['.svg'],
268
- keepFileExtensions: true,
269
267
  outDir,
268
+ outFileExtension: '.svg.js',
270
269
  srcDir
271
270
  });
272
271
  }
@@ -322,6 +321,7 @@ void (async () => {
322
321
  }
323
322
  await buildWithBabelForServerSide({
324
323
  buildType,
324
+ configPath: 'babel.build.config.js',
325
325
  outDir: buildDir,
326
326
  srcDir: sourceDir
327
327
  });
@@ -1,3 +1,4 @@
1
1
  // Aggregates utility modules together.
2
2
  export * from "./errors.js";
3
+ export * from "./modules.js";
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/server/utils/index.ts"],"sourcesContent":["// Aggregates utility modules together.\n\nexport * from './errors';\n"],"mappings":"AAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/server/utils/index.ts"],"sourcesContent":["// Aggregates utility modules together.\n\nexport * from './errors';\nexport * from './modules';\n"],"mappings":"AAAA;AAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,71 @@
1
+ import { existsSync, readFileSync, statSync } from "node:fs";
2
+ import { createRequire, registerHooks } from "node:module";
3
+ import { basename, dirname } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ const CANDIDATE_EXTENSIONS = [".js", ".jsx", ".ts", ".tsx"];
6
+ const require = createRequire(import.meta.url); /**
7
+ * It looks like, as of Babel v8, @babel/node does not quite work with ES module
8
+ * codebase. This function registers a Node module API hook that customizes ES
9
+ * module loading, to run Babel transformation on them.
10
+ *{(
11
+ * BEWARE: It is intended for development environments only.
12
+ */
13
+ export function registerBabelLoader({
14
+ envName = "development",
15
+ root = process.cwd()
16
+ } = {}) {
17
+ // eslint-disable-next-line import/no-extraneous-dependencies
18
+ const {
19
+ transformSync
20
+ } = require("@babel/core");
21
+ const cache = new Map();
22
+ registerHooks({
23
+ load(url, context, next) {
24
+ const cached = cache.get(url);
25
+ if (cached !== undefined) return cached;
26
+ if (url.startsWith("file://") && !url.includes("/node_modules/") && !url.includes("/config/babel/") && url.match(/.(js|jsx|svg|ts|tsx)$/)) {
27
+ const path = fileURLToPath(url);
28
+ const source = readFileSync(path, "utf8");
29
+ const transformed = transformSync(source, {
30
+ cwd: dirname(path),
31
+ envName,
32
+ filename: basename(path),
33
+ root
34
+ });
35
+ const res = {
36
+ format: "module",
37
+ shortCircuit: true,
38
+ source: transformed?.code ?? ""
39
+ };
40
+ cache.set(url, res);
41
+ return res;
42
+ }
43
+ return next(url, context);
44
+ }
45
+ });
46
+ } /**
47
+ * Registers a Node module API hook that customizes ES module resolution
48
+ * to make mandatory file extensions optional.
49
+ */
50
+ export function registerResolver() {
51
+ registerHooks({
52
+ resolve(specifier, context, next) {
53
+ let target = specifier;
54
+ if ((target.startsWith(".") || target.startsWith("/")) && context.conditions.includes("import")) {
55
+ target = new URL(target, context.parentURL).pathname;
56
+ if (existsSync(target) && statSync(target).isDirectory()) {
57
+ target += "/index";
58
+ }
59
+ for (const ext of CANDIDATE_EXTENSIONS) {
60
+ const resolved = target + ext;
61
+ if (existsSync(resolved)) {
62
+ target = resolved;
63
+ break;
64
+ }
65
+ }
66
+ }
67
+ return next(target, context);
68
+ }
69
+ });
70
+ }
71
+ //# sourceMappingURL=modules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.js","names":[],"sources":["../../../../src/server/utils/modules.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from 'node:fs';\nimport { type LoadFnOutput, createRequire, registerHooks } from 'node:module';\nimport { basename, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type * as BabelCore from '@babel/core';\n\nconst CANDIDATE_EXTENSIONS = [\n '.js',\n '.jsx',\n '.ts',\n '.tsx',\n];\n\nconst require = createRequire(import.meta.url);\n\ntype RegisterBabelLoaderArgT = {\n envName?: string;\n root?: string;\n};\n\n/**\n * It looks like, as of Babel v8, @babel/node does not quite work with ES module\n * codebase. This function registers a Node module API hook that customizes ES\n * module loading, to run Babel transformation on them.\n *{(\n * BEWARE: It is intended for development environments only.\n */\nexport function registerBabelLoader({\n envName = 'development',\n root = process.cwd(),\n}: RegisterBabelLoaderArgT = {}): void {\n // eslint-disable-next-line import/no-extraneous-dependencies\n const { transformSync } = require('@babel/core') as typeof BabelCore;\n\n const cache = new Map<string, LoadFnOutput>();\n\n registerHooks({\n load(url, context, next) {\n const cached = cache.get(url);\n if (cached !== undefined) return cached;\n\n if (\n url.startsWith('file://')\n && !url.includes('/node_modules/')\n && !url.includes('/config/babel/')\n && url.match(/.(js|jsx|svg|ts|tsx)$/)\n ) {\n const path = fileURLToPath(url);\n const source = readFileSync(path, 'utf8');\n\n const transformed = transformSync(source, {\n cwd: dirname(path),\n envName,\n filename: basename(path),\n root,\n });\n\n const res: LoadFnOutput = {\n format: 'module',\n shortCircuit: true,\n source: transformed?.code ?? '',\n };\n\n cache.set(url, res);\n return res;\n }\n\n return next(url, context);\n },\n });\n}\n\n/**\n * Registers a Node module API hook that customizes ES module resolution\n * to make mandatory file extensions optional.\n */\nexport function registerResolver(): void {\n registerHooks({\n resolve(specifier, context, next) {\n let target = specifier;\n\n if (\n (target.startsWith('.') || target.startsWith('/'))\n && context.conditions.includes('import')\n ) {\n target = new URL(target, context.parentURL).pathname;\n\n if (existsSync(target) && statSync(target).isDirectory()) {\n target += '/index';\n }\n\n for (const ext of CANDIDATE_EXTENSIONS) {\n const resolved = target + ext;\n if (existsSync(resolved)) {\n target = resolved;\n break;\n }\n }\n }\n\n return next(target, context);\n },\n });\n}\n"],"mappings":"AAAA,SAAS,UAAU,EAAE,YAAY,EAAE,QAAQ,QAAQ,SAAS;AAC5D,SAA4B,aAAa,EAAE,aAAa,QAAQ,aAAa;AAC7E,SAAS,QAAQ,EAAE,OAAO,QAAQ,WAAW;AAC7C,SAAS,aAAa,QAAQ,UAAU;AAIxC,MAAM,oBAAoB,GAAG,CAC3B,KAAK,EACL,MAAM,EACN,KAAK,EACL,MAAM,CACP;AAED,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAO9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,mBAAmB,CAAC;EAClC,OAAO,GAAG,aAAa;EACvB,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;AACI,CAAC,GAAG,CAAC,CAAC,EAAQ;EACrC;EACA,MAAM;IAAE;EAAc,CAAC,GAAG,OAAO,CAAC,aAAa,CAAqB;EAEpE,MAAM,KAAK,GAAG,IAAI,GAA2B,CAA3B,CAA2B;EAE7C,aAAa,CAAC;IACZ,IAAI,CAAC,GAA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M,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ;QAEpD,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,EAAE;UACxD,MAAM,IAAI,QAAQ;QACpB;QAEA,KAAK,MAAM,GAAG,IAAI,oBAAoB,EAAE;UACtC,MAAM,QAAQ,GAAG,MAAM,GAAG,GAAG;UAC7B,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE;YACxB,MAAM,GAAG,QAAQ;YACjB;UACF;QACF;MACF;MAEA,OAAO,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;IAC9B;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -1,23 +1,4 @@
1
- import { existsSync, statSync } from "node:fs";
2
- import { registerHooks } from "node:module";
3
- const TRIAL = ["", ".cjs", ".js", ".jsx", ".mjs", ".ts", ".tsx"];
4
- registerHooks({
5
- resolve: (specifier, context, next) => {
6
- let path = specifier; // This works around the regular ESM limitation of having to have explicit
7
- // file extensions on import specifiers.
8
- if ((specifier.startsWith(".") || specifier.startsWith("/")) && context.conditions.includes("import")) {
9
- const url = new URL(specifier, context.parentURL);
10
- path = url.pathname;
11
- if (existsSync(path) && statSync(path).isDirectory()) path += "/index";
12
- for (const ext of TRIAL) {
13
- if (existsSync(path + ext)) {
14
- path += ext;
15
- break;
16
- }
17
- }
18
- }
19
- return next(path, context);
20
- }
21
- }); // eslint-disable-next-line import/dynamic-import-chunkname
1
+ import { registerResolver } from "../../../../server/utils/modules.js";
2
+ registerResolver(); // eslint-disable-next-line import/dynamic-import-chunkname
22
3
  void import("./ssr.js");
23
4
  //# sourceMappingURL=ssr-preload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssr-preload.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr-preload.ts"],"sourcesContent":["import { existsSync, statSync } from 'node:fs';\nimport { registerHooks } from 'node:module';\n\nconst TRIAL = [\n '',\n '.cjs',\n '.js',\n '.jsx',\n '.mjs',\n '.ts',\n '.tsx',\n];\n\nregisterHooks({\n resolve: (specifier, context, next) => {\n let path = specifier;\n\n // This works around the regular ESM limitation of having to have explicit\n // file extensions on import specifiers.\n if ((\n specifier.startsWith('.') || specifier.startsWith('/')\n ) && context.conditions.includes('import')) {\n const url = new URL(specifier, context.parentURL);\n path = url.pathname;\n\n if (existsSync(path) && statSync(path).isDirectory()) path += '/index';\n\n for (const ext of TRIAL) {\n if (existsSync(path + ext)) {\n path += ext;\n break;\n }\n }\n }\n\n return next(path, context);\n },\n});\n\n// eslint-disable-next-line import/dynamic-import-chunkname\nvoid import('./ssr');\n"],"mappings":"AAAA,SAAS,UAAU,EAAE,QAAQ,QAAQ,SAAS;AAC9C,SAAS,aAAa,QAAQ,aAAa;AAE3C,MAAM,KAAK,GAAG,CACZ,EAAE,EACF,MAAM,EACN,KAAK,EACL,MAAM,EACN,MAAM,EACN,KAAK,EACL,MAAM,CACP;AAED,aAAa,CAAC;EACZ,OAAO,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,KAAK;IACrC,IAAI,IAAI,GAAG,SAAS,CAEpB;IACA;IACA,IAAI,CACF,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,KACnD,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;MAC1C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC;MACjD,IAAI,GAAG,GAAG,CAAC,QAAQ;MAEnB,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,IAAI,QAAQ;MAEtE,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;QACvB,IAAI,UAAU,CAAC,IAAI,GAAG,GAAG,CAAC,EAAE;UAC1B,IAAI,IAAI,GAAG;UACX;QACF;MACF;IACF;IAEA,OAAO,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC;EAC5B;AACF,CAAC,CAAC,CAEF;AACA,KAAK,MAAM,YAAS","ignoreList":[]}
1
+ {"version":3,"file":"ssr-preload.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr-preload.ts"],"sourcesContent":["import { registerResolver } from 'server/utils/modules';\n\nregisterResolver();\n\n// eslint-disable-next-line import/dynamic-import-chunkname\nvoid import('./ssr');\n"],"mappings":"SAAS,gBAAgB;AAEzB,gBAAgB,CAAC,CAAC,CAElB;AACA,KAAK,MAAM,YAAS","ignoreList":[]}
@@ -1,8 +1,5 @@
1
- /* eslint-disable import/dynamic-import-chunkname, import/no-extraneous-dependencies */import { readFileSync } from "node:fs";
2
- import { registerHooks } from "node:module";
3
- import { basename, dirname, resolve } from "node:path";
4
- import { fileURLToPath } from "node:url";
5
- import { transformSync } from "@babel/core";
1
+ import { resolve } from "node:path";
2
+ import { registerBabelLoader } from "../../../../server/index.js";
6
3
  import ssrFactory from "../../../../server/renderer.js";
7
4
  function noop() {// NOOP
8
5
  }
@@ -19,28 +16,12 @@ async function run({
19
16
  // API, and Babel's core, to transpile all modules loaded further into
20
17
  // CommonJS. I guess, later we'll be able to get rid of this, as Babel
21
18
  // register supports runtime transformation of modules loaded with import().
22
- registerHooks({
23
- load(url, context, nextLoad) {
24
- if (url.startsWith("file://") && !url.includes("/node_modules/") && !url.includes("/config/babel/") && url.match(/\.(js|jsx|ts|tsx|svg)$/)) {
25
- const path = fileURLToPath(url);
26
- let code = readFileSync(path, "utf8");
27
- code = transformSync(code, {
28
- cwd: dirname(path),
29
- envName: options.babelEnv,
30
- filename: basename(path),
31
- root
32
- })?.code ?? "";
33
- return {
34
- format: "module",
35
- shortCircuit: true,
36
- source: code
37
- };
38
- }
39
- return nextLoad(url, context);
40
- }
19
+ registerBabelLoader({
20
+ envName: options.babelEnv,
21
+ root
41
22
  });
42
23
  if (options.entry) {
43
- const p = resolve(testFolder, options.entry);
24
+ const p = resolve(testFolder, options.entry); // eslint-disable-next-line import/dynamic-import-chunkname
44
25
  const babelModule = await import(p); // TODO: This is basically a hotfix hack, which works both for the library
45
26
  // itself, and for dependent projects... (those tested so far). It sure has
46
27
  // to be reworked later.
@@ -1 +1 @@
1
- {"version":3,"file":"ssr.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr.ts"],"sourcesContent":["/* eslint-disable import/dynamic-import-chunkname, import/no-extraneous-dependencies */\n\nimport { readFileSync } from 'node:fs';\nimport { registerHooks } from 'node:module';\nimport { basename, dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { Request, Response } from 'express';\nimport type { Configuration } from 'webpack';\n\nimport { transformSync } from '@babel/core';\n\nimport ssrFactory from 'server/renderer';\n\nexport type LaunchT = {\n // TODO: Should it be typed as the renderer's options type?\n options: Record<string, unknown>;\n\n root: string;\n ssrRequest: object;\n testFolder: string;\n webpackConfig: Configuration;\n};\n\nexport type ResultT = {\n markup: string;\n status: number;\n};\n\nfunction noop() {\n // NOOP\n}\n\nasync function run({\n options,\n root,\n ssrRequest,\n testFolder,\n webpackConfig,\n}: LaunchT) {\n // NOTE: It looks like @babel/register does not work for us here, because\n // it only supports transpiling of modules loaded with require(), so here\n // is, presumably, a temporary workaround relying on the new NodeJS module\n // API, and Babel's core, to transpile all modules loaded further into\n // CommonJS. I guess, later we'll be able to get rid of this, as Babel\n // register supports runtime transformation of modules loaded with import().\n registerHooks({\n load(url, context, nextLoad) {\n if (\n url.startsWith('file://')\n && !url.includes('/node_modules/')\n && !url.includes('/config/babel/')\n && url.match(/\\.(js|jsx|ts|tsx|svg)$/)\n ) {\n const path = fileURLToPath(url);\n let code = readFileSync(path, 'utf8');\n code = transformSync(code, {\n cwd: dirname(path),\n envName: options.babelEnv as string,\n filename: basename(path),\n root,\n })?.code ?? '';\n return {\n format: 'module',\n shortCircuit: true,\n source: code,\n };\n }\n\n return nextLoad(url, context);\n },\n });\n\n if (options.entry) {\n const p = resolve(testFolder, options.entry as string);\n const babelModule = await import(p) as NodeJS.Module;\n\n // TODO: This is basically a hotfix hack, which works both for the library\n // itself, and for dependent projects... (those tested so far). It sure has\n // to be reworked later.\n /* eslint-disable no-underscore-dangle */\n const module = (\n '__esModule' in babelModule\n && typeof babelModule.__esModule === 'boolean'\n && babelModule.__esModule\n && 'default' in babelModule\n ? babelModule.default : babelModule\n ) as NodeJS.Module;\n /* eslint-enable no-underscore-dangle */\n\n const exportName = (options.entryExportName as string) || 'default';\n if (exportName in module) {\n // eslint-disable-next-line no-param-reassign\n options.Application = (\n module as unknown as Record<string, unknown>\n )[exportName];\n // eslint-disable-next-line no-param-reassign\n } else options.Application = module;\n }\n\n const renderer = ssrFactory(webpackConfig, options);\n let status = 200; // OK\n\n // eslint-disable-next-line no-param-reassign\n (ssrRequest as Request).csrfToken = () => '';\n\n const markup = await new Promise<string>((done, fail) => {\n void renderer(\n ssrRequest as Request,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n ({\n cookie: noop,\n send: done,\n set: noop,\n status: (value: number) => {\n status = value;\n },\n } as unknown) as Response,\n\n (error) => {\n // TODO: Strictly speaking, that error as Error casting is not all\n // correct, but it works, so no need to spend time on it right now.\n if (error) fail(error as Error);\n else done('');\n },\n );\n });\n\n process.send?.({ markup, status } satisfies ResultT);\n}\n\nprocess.on('message', (message: LaunchT) => {\n void run(message);\n});\n"],"mappings":"AAAA,uFAEA,SAAS,YAAY,QAAQ,SAAS;AACtC,SAAS,aAAa,QAAQ,aAAa;AAC3C,SAAS,QAAQ,EAAE,OAAO,EAAE,OAAO,QAAQ,WAAW;AACtD,SAAS,aAAa,QAAQ,UAAU;AAKxC,SAAS,aAAa,QAAQ,aAAa;AAAC,OAErC,UAAU;AAiBjB,SAAS,IAAI,GAAG,CACd;AAAA;AA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,CAClB;IAEA,MAAM,UAAU,GAAI,OAAO,CAAC,eAAe,IAAe,SAAS;IACnE,IAAI,UAAU,IAAI,MAAM,EAAE;MACxB;MACA,OAAO,CAAC,WAAW,GACjB,MAAM,CACN,UAAU,CAAC,CACb;IACF,CAAC,MAAM,OAAO,CAAC,WAAW,GAAG,MAAM;EACrC;EAEA,MAAM,QAAQ,GAAG,UAAU,CAAC,aAAa,EAAE,OAAO,CAAC;EACnD,IAAI,MAAM,GAAG,GAAG,CAAE;EAElB;EACC,UAAU,CAAa,SAAS,GAAG,MAAM,EAAE;EAE5C,MAAM,MAAM,GAAG,MAAM,IAAI,OAAO,CAAS,CAAC,IAAI,EAAE,IAAI,KAAK;IACvD,KAAK,QAAQ,CACX,UAAU;IAEV;IACA;IACA;IACC;MACC,MAAM,EAAE,IAAI;MACZ,IAAI,EAAE,IAAI;MACV,GAAG,EAAE,IAAI;MACT,MAAM,EAAG,KAAa,IAAK;QACzB,MAAM,GAAG,KAAK;MAChB;IACF,CAAC,EAEA,KAAK,IAAK;MACT;MACA;MACA,IAAI,KAAK,EAAE,IAAI,CAAC,KAAc,CAAC,CAAC,KAC3B,IAAI,CAAC,EAAE,CAAC;IACf,CACF,CAAC;EACH,CAAC,CAAC;EAEF,OAAO,CAAC,IAAI,GAAG;IAAE,MAAM;IAAE;EAAO,CAAmB,CAAC;AACtD;AAEA,OAAO,CAAC,EAAE,CAAC,SAAS,EAAG,OAAgB,IAAK;EAC1C,KAAK,GAAG,CAAC,OAAO,CAAC;AACnB,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"ssr.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr.ts"],"sourcesContent":["import { resolve } from 'node:path';\n\nimport type { Request, Response } from 'express';\nimport type { Configuration } from 'webpack';\n\nimport { registerBabelLoader } from 'server';\nimport ssrFactory from 'server/renderer';\n\nexport type LaunchT = {\n // TODO: Should it be typed as the renderer's options type?\n options: Record<string, unknown>;\n\n root: string;\n ssrRequest: object;\n testFolder: string;\n webpackConfig: Configuration;\n};\n\nexport type ResultT = {\n markup: string;\n status: number;\n};\n\nfunction noop() {\n // NOOP\n}\n\nasync function run({\n options,\n root,\n ssrRequest,\n testFolder,\n webpackConfig,\n}: LaunchT) {\n // NOTE: It looks like @babel/register does not work for us here, because\n // it only supports transpiling of modules loaded with require(), so here\n // is, presumably, a temporary workaround relying on the new NodeJS module\n // API, and Babel's core, to transpile all modules loaded further into\n // CommonJS. I guess, later we'll be able to get rid of this, as Babel\n // register supports runtime transformation of modules loaded with import().\n registerBabelLoader({ envName: options.babelEnv as string, root });\n\n if (options.entry) {\n const p = resolve(testFolder, options.entry as string);\n // eslint-disable-next-line import/dynamic-import-chunkname\n const babelModule = await import(p) as NodeJS.Module;\n\n // TODO: This is basically a hotfix hack, which works both for the library\n // itself, and for dependent projects... (those tested so far). It sure has\n // to be reworked later.\n /* eslint-disable no-underscore-dangle */\n const module = (\n '__esModule' in babelModule\n && typeof babelModule.__esModule === 'boolean'\n && babelModule.__esModule\n && 'default' in babelModule\n ? babelModule.default : babelModule\n ) as NodeJS.Module;\n /* eslint-enable no-underscore-dangle */\n\n const exportName = (options.entryExportName as string) || 'default';\n if (exportName in module) {\n // eslint-disable-next-line no-param-reassign\n options.Application = (\n module as unknown as Record<string, unknown>\n )[exportName];\n // eslint-disable-next-line no-param-reassign\n } else options.Application = module;\n }\n\n const renderer = ssrFactory(webpackConfig, options);\n let status = 200; // OK\n\n // eslint-disable-next-line no-param-reassign\n (ssrRequest as Request).csrfToken = () => '';\n\n const markup = await new Promise<string>((done, fail) => {\n void renderer(\n ssrRequest as Request,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n ({\n cookie: noop,\n send: done,\n set: noop,\n status: (value: number) => {\n status = value;\n },\n } as unknown) as Response,\n\n (error) => {\n // TODO: Strictly speaking, that error as Error casting is not all\n // correct, but it works, so no need to spend time on it right now.\n if (error) fail(error as Error);\n else done('');\n },\n );\n });\n\n process.send?.({ markup, status } satisfies ResultT);\n}\n\nprocess.on('message', (message: LaunchT) => {\n void run(message);\n});\n"],"mappings":"AAAA,SAAS,OAAO,QAAQ,WAAW;AAAC,SAK3B,mBAAmB;AAAA,OACrB,UAAU;AAiBjB,SAAS,IAAI,GAAG,CACd;AAAA;AAGF,eAAe,GAAG,CAAC;EACjB,OAAO;EACP,IAAI;EACJ,UAAU;EACV,UAAU;EACV;AACO,CAAC,EAAE;EACV;EACA;EACA;EACA;EACA;EACA;EACA,mBAAmB,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC,QAAkB;IAAE;EAAK,CAAC,CAAC;EAElE,IAAI,OAAO,CAAC,KAAK,EAAE;IACjB,MAAM,CAAC,GAAG,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,KAAe,CAAC,CACtD;IACA,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,CAAC,CAAkB,CAEpD;IACA;IACA;IACA;IACA,MAAM,MAAM,GACV,YAAY,IAAI,WAAW,IACxB,OAAO,WAAW,CAAC,UAAU,KAAK,SAAS,IAC3C,WAAW,CAAC,UAAU,IACtB,SAAS,IAAI,WAAW,GACvB,WAAW,CAAC,OAAO,GAAG,WACV,CAClB;IAEA,MAAM,UAAU,GAAI,OAAO,CAAC,eAAe,IAAe,SAAS;IACnE,IAAI,UAAU,IAAI,MAAM,EAAE;MACxB;MACA,OAAO,CAAC,WAAW,GACjB,MAAM,CACN,UAAU,CAAC,CACb;IACF,CAAC,MAAM,OAAO,CAAC,WAAW,GAAG,MAAM;EACrC;EAEA,MAAM,QAAQ,GAAG,UAAU,CAAC,aAAa,EAAE,OAAO,CAAC;EACnD,IAAI,MAAM,GAAG,GAAG,CAAE;EAElB;EACC,UAAU,CAAa,SAAS,GAAG,MAAM,EAAE;EAE5C,MAAM,MAAM,GAAG,MAAM,IAAI,OAAO,CAAS,CAAC,IAAI,EAAE,IAAI,KAAK;IACvD,KAAK,QAAQ,CACX,UAAU;IAEV;IACA;IACA;IACC;MACC,MAAM,EAAE,IAAI;MACZ,IAAI,EAAE,IAAI;MACV,GAAG,EAAE,IAAI;MACT,MAAM,EAAG,KAAa,IAAK;QACzB,MAAM,GAAG,KAAK;MAChB;IACF,CAAC,EAEA,KAAK,IAAK;MACT;MACA;MACA,IAAI,KAAK,EAAE,IAAI,CAAC,KAAc,CAAC,CAAC,KAC3B,IAAI,CAAC,EAAE,CAAC;IACf,CACF,CAAC;EACH,CAAC,CAAC;EAEF,OAAO,CAAC,IAAI,GAAG;IAAE,MAAM;IAAE;EAAO,CAAmB,CAAC;AACtD;AAEA,OAAO,CAAC,EAAE,CAAC,SAAS,EAAG,OAAgB,IAAK;EAC1C,KAAK,GAAG,CAAC,OAAO,CAAC;AACnB,CAAC,CAAC","ignoreList":[]}
@@ -1,3 +1,3 @@
1
1
  // Aggregates utility modules together.
2
- export*from"./errors.js";
2
+ export*from"./errors.js";export*from"./modules.js";
3
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/server/utils/index.ts"],"sourcesContent":["// Aggregates utility modules together.\n\nexport * from './errors';\n"],"mappings":"AAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/server/utils/index.ts"],"sourcesContent":["// Aggregates utility modules together.\n\nexport * from './errors';\nexport * from './modules';\n"],"mappings":"AAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ import{existsSync,readFileSync,statSync}from"node:fs";import{createRequire,registerHooks}from"node:module";import{basename,dirname}from"node:path";import{fileURLToPath}from"node:url";const CANDIDATE_EXTENSIONS=[".js",".jsx",".ts",".tsx"];const require=createRequire(import.meta.url);/**
2
+ * It looks like, as of Babel v8, @babel/node does not quite work with ES module
3
+ * codebase. This function registers a Node module API hook that customizes ES
4
+ * module loading, to run Babel transformation on them.
5
+ *{(
6
+ * BEWARE: It is intended for development environments only.
7
+ */export function registerBabelLoader({envName="development",root=process.cwd()}={}){// eslint-disable-next-line import/no-extraneous-dependencies
8
+ const{transformSync}=require("@babel/core");const cache=new Map;registerHooks({load(url,context,next){const cached=cache.get(url);if(cached!==undefined)return cached;if(url.startsWith("file://")&&!url.includes("/node_modules/")&&!url.includes("/config/babel/")&&url.match(/.(js|jsx|svg|ts|tsx)$/)){const path=fileURLToPath(url);const source=readFileSync(path,"utf8");const transformed=transformSync(source,{cwd:dirname(path),envName,filename:basename(path),root});const res={format:"module",shortCircuit:true,source:transformed?.code??""};cache.set(url,res);return res;}return next(url,context);}});}/**
9
+ * Registers a Node module API hook that customizes ES module resolution
10
+ * to make mandatory file extensions optional.
11
+ */export function registerResolver(){registerHooks({resolve(specifier,context,next){let target=specifier;if((target.startsWith(".")||target.startsWith("/"))&&context.conditions.includes("import")){target=new URL(target,context.parentURL).pathname;if(existsSync(target)&&statSync(target).isDirectory()){target+="/index";}for(const ext of CANDIDATE_EXTENSIONS){const resolved=target+ext;if(existsSync(resolved)){target=resolved;break;}}}return next(target,context);}});}
12
+ //# sourceMappingURL=modules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.js","names":[],"sources":["../../../../src/server/utils/modules.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from 'node:fs';\nimport { type LoadFnOutput, createRequire, registerHooks } from 'node:module';\nimport { basename, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type * as BabelCore from '@babel/core';\n\nconst CANDIDATE_EXTENSIONS = [\n '.js',\n '.jsx',\n '.ts',\n '.tsx',\n];\n\nconst require = createRequire(import.meta.url);\n\ntype RegisterBabelLoaderArgT = {\n envName?: string;\n root?: string;\n};\n\n/**\n * It looks like, as of Babel v8, @babel/node does not quite work with ES module\n * codebase. This function registers a Node module API hook that customizes ES\n * module loading, to run Babel transformation on them.\n *{(\n * BEWARE: It is intended for development environments only.\n */\nexport function registerBabelLoader({\n envName = 'development',\n root = process.cwd(),\n}: RegisterBabelLoaderArgT = {}): void {\n // eslint-disable-next-line import/no-extraneous-dependencies\n const { transformSync } = require('@babel/core') as typeof BabelCore;\n\n const cache = new Map<string, LoadFnOutput>();\n\n registerHooks({\n load(url, context, next) {\n const cached = cache.get(url);\n if (cached !== undefined) return cached;\n\n if (\n url.startsWith('file://')\n && !url.includes('/node_modules/')\n && !url.includes('/config/babel/')\n && url.match(/.(js|jsx|svg|ts|tsx)$/)\n ) {\n const path = fileURLToPath(url);\n const source = readFileSync(path, 'utf8');\n\n const transformed = transformSync(source, {\n cwd: dirname(path),\n envName,\n filename: basename(path),\n root,\n });\n\n const res: LoadFnOutput = {\n format: 'module',\n shortCircuit: true,\n source: transformed?.code ?? '',\n };\n\n cache.set(url, res);\n return res;\n }\n\n return next(url, context);\n },\n });\n}\n\n/**\n * Registers a Node module API hook that customizes ES module resolution\n * to make mandatory file extensions optional.\n */\nexport function registerResolver(): void {\n registerHooks({\n resolve(specifier, context, next) {\n let target = specifier;\n\n if (\n (target.startsWith('.') || target.startsWith('/'))\n && context.conditions.includes('import')\n ) {\n target = new URL(target, context.parentURL).pathname;\n\n if (existsSync(target) && statSync(target).isDirectory()) {\n target += '/index';\n }\n\n for (const ext of CANDIDATE_EXTENSIONS) {\n const resolved = target + ext;\n if (existsSync(resolved)) {\n target = resolved;\n break;\n }\n }\n }\n\n return next(target, context);\n },\n });\n}\n"],"mappings":"AAAA,OAAS,UAAU,CAAE,YAAY,CAAE,QAAQ,KAAQ,SAAS,CAC5D,OAA4B,aAAa,CAAE,aAAa,KAAQ,aAAa,CAC7E,OAAS,QAAQ,CAAE,OAAO,KAAQ,WAAW,CAC7C,OAAS,aAAa,KAAQ,UAAU,CAIxC,KAAM,qBAAoB,CAAG,CAC3B,KAAK,CACL,MAAM,CACN,KAAK,CACL,MAAM,CACP,CAED,KAAM,QAAO,CAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAO9C;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,SAAS,oBAA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AAC,CACZ,OAAO,CAAC,SAAS,CAAE,OAAO,CAAE,IAAI,CAAE,CAChC,GAAI,OAAM,CAAG,SAAS,CAEtB,GACE,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,EAAI,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,GAC9C,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CACxC,CACA,MAAM,CAAG,GAAI,IAAG,CAAC,MAAM,CAAE,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,CAEpD,GAAI,UAAU,CAAC,MAAM,CAAC,EAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,CAAE,CACxD,MAAM,EAAI,QAAQ,CACpB,CAEA,IAAK,KAAM,IAAG,GAAI,qBAAoB,CAAE,CACtC,KAAM,SAAQ,CAAG,MAAM,CAAG,GAAG,CAC7B,GAAI,UAAU,CAAC,QAAQ,CAAC,CAAE,CACxB,MAAM,CAAG,QAAQ,CACjB,MACF,CACF,CACF,CAEA,MAAO,KAAI,CAAC,MAAM,CAAE,OAAO,CAAC,CAC9B,CACF,CAAC,CAAC,CACJ","ignoreList":[]}
@@ -1,5 +1,3 @@
1
- import{existsSync,statSync}from"node:fs";import{registerHooks}from"node:module";const TRIAL=["",".cjs",".js",".jsx",".mjs",".ts",".tsx"];registerHooks({resolve:(specifier,context,next)=>{let path=specifier;// This works around the regular ESM limitation of having to have explicit
2
- // file extensions on import specifiers.
3
- if((specifier.startsWith(".")||specifier.startsWith("/"))&&context.conditions.includes("import")){const url=new URL(specifier,context.parentURL);path=url.pathname;if(existsSync(path)&&statSync(path).isDirectory())path+="/index";for(const ext of TRIAL){if(existsSync(path+ext)){path+=ext;break;}}}return next(path,context);}});// eslint-disable-next-line import/dynamic-import-chunkname
1
+ import{registerResolver}from"../../../../server/utils/modules.js";registerResolver();// eslint-disable-next-line import/dynamic-import-chunkname
4
2
  void import("./ssr.js");
5
3
  //# sourceMappingURL=ssr-preload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssr-preload.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr-preload.ts"],"sourcesContent":["import { existsSync, statSync } from 'node:fs';\nimport { registerHooks } from 'node:module';\n\nconst TRIAL = [\n '',\n '.cjs',\n '.js',\n '.jsx',\n '.mjs',\n '.ts',\n '.tsx',\n];\n\nregisterHooks({\n resolve: (specifier, context, next) => {\n let path = specifier;\n\n // This works around the regular ESM limitation of having to have explicit\n // file extensions on import specifiers.\n if ((\n specifier.startsWith('.') || specifier.startsWith('/')\n ) && context.conditions.includes('import')) {\n const url = new URL(specifier, context.parentURL);\n path = url.pathname;\n\n if (existsSync(path) && statSync(path).isDirectory()) path += '/index';\n\n for (const ext of TRIAL) {\n if (existsSync(path + ext)) {\n path += ext;\n break;\n }\n }\n }\n\n return next(path, context);\n },\n});\n\n// eslint-disable-next-line import/dynamic-import-chunkname\nvoid import('./ssr');\n"],"mappings":"AAAA,OAAS,UAAU,CAAE,QAAQ,KAAQ,SAAS,CAC9C,OAAS,aAAa,KAAQ,aAAa,CAE3C,KAAM,MAAK,CAAG,CACZ,EAAE,CACF,MAAM,CACN,KAAK,CACL,MAAM,CACN,MAAM,CACN,KAAK,CACL,MAAM,CACP,CAED,aAAa,CAAC,CACZ,OAAO,CAAE,CAAC,SAAS,CAAE,OAAO,CAAE,IAAI,GAAK,CACrC,GAAI,KAAI,CAAG,SAAS,CAEpB;AACA;AACA,GAAI,CACF,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,GACnD,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAE,CAC1C,KAAM,IAAG,CAAG,GAAI,IAAG,CAAC,SAAS,CAAE,OAAO,CAAC,SAAS,CAAC,CACjD,IAAI,CAAG,GAAG,CAAC,QAAQ,CAEnB,GAAI,UAAU,CAAC,IAAI,CAAC,EAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,CAAC,CAAE,IAAI,EAAI,QAAQ,CAEtE,IAAK,KAAM,IAAG,GAAI,MAAK,CAAE,CACvB,GAAI,UAAU,CAAC,IAAI,CAAG,GAAG,CAAC,CAAE,CAC1B,IAAI,EAAI,GAAG,CACX,MACF,CACF,CACF,CAEA,MAAO,KAAI,CAAC,IAAI,CAAE,OAAO,CAAC,CAC5B,CACF,CAAC,CAAC,CAEF;AACA,IAAK,OAAM,YAAS","ignoreList":[]}
1
+ {"version":3,"file":"ssr-preload.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr-preload.ts"],"sourcesContent":["import { registerResolver } from 'server/utils/modules';\n\nregisterResolver();\n\n// eslint-disable-next-line import/dynamic-import-chunkname\nvoid import('./ssr');\n"],"mappings":"OAAS,gBAAgB,2CAEzB,gBAAgB,CAAC,CAAC,CAElB;AACA,IAAK,OAAM,YAAS","ignoreList":[]}
@@ -1,11 +1,12 @@
1
- /* eslint-disable import/dynamic-import-chunkname, import/no-extraneous-dependencies */import{readFileSync}from"node:fs";import{registerHooks}from"node:module";import{basename,dirname,resolve}from"node:path";import{fileURLToPath}from"node:url";import{transformSync}from"@babel/core";import ssrFactory from"../../../../server/renderer.js";function noop(){// NOOP
1
+ import{resolve}from"node:path";import{registerBabelLoader}from"../../../../server/index.js";import ssrFactory from"../../../../server/renderer.js";function noop(){// NOOP
2
2
  }async function run({options,root,ssrRequest,testFolder,webpackConfig}){// NOTE: It looks like @babel/register does not work for us here, because
3
3
  // it only supports transpiling of modules loaded with require(), so here
4
4
  // is, presumably, a temporary workaround relying on the new NodeJS module
5
5
  // API, and Babel's core, to transpile all modules loaded further into
6
6
  // CommonJS. I guess, later we'll be able to get rid of this, as Babel
7
7
  // register supports runtime transformation of modules loaded with import().
8
- registerHooks({load(url,context,nextLoad){if(url.startsWith("file://")&&!url.includes("/node_modules/")&&!url.includes("/config/babel/")&&url.match(/\.(js|jsx|ts|tsx|svg)$/)){const path=fileURLToPath(url);let code=readFileSync(path,"utf8");code=transformSync(code,{cwd:dirname(path),envName:options.babelEnv,filename:basename(path),root})?.code??"";return{format:"module",shortCircuit:true,source:code};}return nextLoad(url,context);}});if(options.entry){const p=resolve(testFolder,options.entry);const babelModule=await import(p);// TODO: This is basically a hotfix hack, which works both for the library
8
+ registerBabelLoader({envName:options.babelEnv,root});if(options.entry){const p=resolve(testFolder,options.entry);// eslint-disable-next-line import/dynamic-import-chunkname
9
+ const babelModule=await import(p);// TODO: This is basically a hotfix hack, which works both for the library
9
10
  // itself, and for dependent projects... (those tested so far). It sure has
10
11
  // to be reworked later.
11
12
  /* eslint-disable no-underscore-dangle */const module="__esModule"in babelModule&&typeof babelModule.__esModule==="boolean"&&babelModule.__esModule&&"default"in babelModule?babelModule.default:babelModule;/* eslint-enable no-underscore-dangle */const exportName=options.entryExportName||"default";if(exportName in module){// eslint-disable-next-line no-param-reassign
@@ -1 +1 @@
1
- {"version":3,"file":"ssr.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr.ts"],"sourcesContent":["/* eslint-disable import/dynamic-import-chunkname, import/no-extraneous-dependencies */\n\nimport { readFileSync } from 'node:fs';\nimport { registerHooks } from 'node:module';\nimport { basename, dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { Request, Response } from 'express';\nimport type { Configuration } from 'webpack';\n\nimport { transformSync } from '@babel/core';\n\nimport ssrFactory from 'server/renderer';\n\nexport type LaunchT = {\n // TODO: Should it be typed as the renderer's options type?\n options: Record<string, unknown>;\n\n root: string;\n ssrRequest: object;\n testFolder: string;\n webpackConfig: Configuration;\n};\n\nexport type ResultT = {\n markup: string;\n status: number;\n};\n\nfunction noop() {\n // NOOP\n}\n\nasync function run({\n options,\n root,\n ssrRequest,\n testFolder,\n webpackConfig,\n}: LaunchT) {\n // NOTE: It looks like @babel/register does not work for us here, because\n // it only supports transpiling of modules loaded with require(), so here\n // is, presumably, a temporary workaround relying on the new NodeJS module\n // API, and Babel's core, to transpile all modules loaded further into\n // CommonJS. I guess, later we'll be able to get rid of this, as Babel\n // register supports runtime transformation of modules loaded with import().\n registerHooks({\n load(url, context, nextLoad) {\n if (\n url.startsWith('file://')\n && !url.includes('/node_modules/')\n && !url.includes('/config/babel/')\n && url.match(/\\.(js|jsx|ts|tsx|svg)$/)\n ) {\n const path = fileURLToPath(url);\n let code = readFileSync(path, 'utf8');\n code = transformSync(code, {\n cwd: dirname(path),\n envName: options.babelEnv as string,\n filename: basename(path),\n root,\n })?.code ?? '';\n return {\n format: 'module',\n shortCircuit: true,\n source: code,\n };\n }\n\n return nextLoad(url, context);\n },\n });\n\n if (options.entry) {\n const p = resolve(testFolder, options.entry as string);\n const babelModule = await import(p) as NodeJS.Module;\n\n // TODO: This is basically a hotfix hack, which works both for the library\n // itself, and for dependent projects... (those tested so far). It sure has\n // to be reworked later.\n /* eslint-disable no-underscore-dangle */\n const module = (\n '__esModule' in babelModule\n && typeof babelModule.__esModule === 'boolean'\n && babelModule.__esModule\n && 'default' in babelModule\n ? babelModule.default : babelModule\n ) as NodeJS.Module;\n /* eslint-enable no-underscore-dangle */\n\n const exportName = (options.entryExportName as string) || 'default';\n if (exportName in module) {\n // eslint-disable-next-line no-param-reassign\n options.Application = (\n module as unknown as Record<string, unknown>\n )[exportName];\n // eslint-disable-next-line no-param-reassign\n } else options.Application = module;\n }\n\n const renderer = ssrFactory(webpackConfig, options);\n let status = 200; // OK\n\n // eslint-disable-next-line no-param-reassign\n (ssrRequest as Request).csrfToken = () => '';\n\n const markup = await new Promise<string>((done, fail) => {\n void renderer(\n ssrRequest as Request,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n ({\n cookie: noop,\n send: done,\n set: noop,\n status: (value: number) => {\n status = value;\n },\n } as unknown) as Response,\n\n (error) => {\n // TODO: Strictly speaking, that error as Error casting is not all\n // correct, but it works, so no need to spend time on it right now.\n if (error) fail(error as Error);\n else done('');\n },\n );\n });\n\n process.send?.({ markup, status } satisfies ResultT);\n}\n\nprocess.on('message', (message: LaunchT) => {\n void run(message);\n});\n"],"mappings":"AAAA,uFAEA,OAAS,YAAY,KAAQ,SAAS,CACtC,OAAS,aAAa,KAAQ,aAAa,CAC3C,OAAS,QAAQ,CAAE,OAAO,CAAE,OAAO,KAAQ,WAAW,CACtD,OAAS,aAAa,KAAQ,UAAU,CAKxC,OAAS,aAAa,KAAQ,aAAa,CAAC,MAErC,WAAU,sCAiBjB,QAAS,KAAI,EAAG,CACd;AAAA,CAGF,cAAe,IAAG,CAAC,CACjB,OAAO,CACP,IAAI,CACJ,UAAU,CACV,UAAU,CACV,aACO,CAAC,CAAE,CACV;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,CAAC,CACZ,IAAI,CAAC,GAAG,CAAE,OAAO,CAAE,QAAQ,CAAE,CAC3B,GACE,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EACtB,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAC/B,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAC/B,GAAG,CAAC,KAAK,CAAC,wBAAwB,CAAC,CACtC,CACA,KAAM,KAAI,CAAG,aAAa,CAAC,GAAG,CAAC,CAC/B,GAAI,KAAI,CAAG,YAAY,CAAC,IAAI,CAAE,MAAM,CAAC,CACrC,IAAI,CAAG,aAAa,CAAC,IAAI,CAAE,CACzB,GAAG,CAAE,OAAO,CAAC,IAAI,CAAC,CAClB,OAAO,CAAE,OAAO,CAAC,QAAkB,CACnC,QAAQ,CAAE,QAAQ,CAAC,IAAI,CAAC,CACxB,IACF,CAAC,CAAC,EAAE,IAAI,EAAI,EAAE,CACd,MAAO,CACL,MAAM,CAAE,QAAQ,CAChB,YAAY,CAAE,IAAI,CAClB,MAAM,CAAE,IACV,CAAC,CACH,CAEA,MAAO,SAAQ,CAAC,GAAG,CAAE,OAAO,CAAC,CAC/B,CACF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E,CAAC,SAAS,CAAG,OAAgB,EAAK,CAC1C,IAAK,IAAG,CAAC,OAAO,CAAC,CACnB,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"ssr.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr.ts"],"sourcesContent":["import { resolve } from 'node:path';\n\nimport type { Request, Response } from 'express';\nimport type { Configuration } from 'webpack';\n\nimport { registerBabelLoader } from 'server';\nimport ssrFactory from 'server/renderer';\n\nexport type LaunchT = {\n // TODO: Should it be typed as the renderer's options type?\n options: Record<string, unknown>;\n\n root: string;\n ssrRequest: object;\n testFolder: string;\n webpackConfig: Configuration;\n};\n\nexport type ResultT = {\n markup: string;\n status: number;\n};\n\nfunction noop() {\n // NOOP\n}\n\nasync function run({\n options,\n root,\n ssrRequest,\n testFolder,\n webpackConfig,\n}: LaunchT) {\n // NOTE: It looks like @babel/register does not work for us here, because\n // it only supports transpiling of modules loaded with require(), so here\n // is, presumably, a temporary workaround relying on the new NodeJS module\n // API, and Babel's core, to transpile all modules loaded further into\n // CommonJS. I guess, later we'll be able to get rid of this, as Babel\n // register supports runtime transformation of modules loaded with import().\n registerBabelLoader({ envName: options.babelEnv as string, root });\n\n if (options.entry) {\n const p = resolve(testFolder, options.entry as string);\n // eslint-disable-next-line import/dynamic-import-chunkname\n const babelModule = await import(p) as NodeJS.Module;\n\n // TODO: This is basically a hotfix hack, which works both for the library\n // itself, and for dependent projects... (those tested so far). It sure has\n // to be reworked later.\n /* eslint-disable no-underscore-dangle */\n const module = (\n '__esModule' in babelModule\n && typeof babelModule.__esModule === 'boolean'\n && babelModule.__esModule\n && 'default' in babelModule\n ? babelModule.default : babelModule\n ) as NodeJS.Module;\n /* eslint-enable no-underscore-dangle */\n\n const exportName = (options.entryExportName as string) || 'default';\n if (exportName in module) {\n // eslint-disable-next-line no-param-reassign\n options.Application = (\n module as unknown as Record<string, unknown>\n )[exportName];\n // eslint-disable-next-line no-param-reassign\n } else options.Application = module;\n }\n\n const renderer = ssrFactory(webpackConfig, options);\n let status = 200; // OK\n\n // eslint-disable-next-line no-param-reassign\n (ssrRequest as Request).csrfToken = () => '';\n\n const markup = await new Promise<string>((done, fail) => {\n void renderer(\n ssrRequest as Request,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n ({\n cookie: noop,\n send: done,\n set: noop,\n status: (value: number) => {\n status = value;\n },\n } as unknown) as Response,\n\n (error) => {\n // TODO: Strictly speaking, that error as Error casting is not all\n // correct, but it works, so no need to spend time on it right now.\n if (error) fail(error as Error);\n else done('');\n },\n );\n });\n\n process.send?.({ markup, status } satisfies ResultT);\n}\n\nprocess.on('message', (message: LaunchT) => {\n void run(message);\n});\n"],"mappings":"AAAA,OAAS,OAAO,KAAQ,WAAW,CAAC,OAK3B,mBAAmB,yCACrB,WAAU,sCAiBjB,QAAS,KAAI,EAAG,CACd;AAAA,CAGF,cAAe,IAAG,CAAC,CACjB,OAAO,CACP,IAAI,CACJ,UAAU,CACV,UAAU,CACV,aACO,CAAC,CAAE,CACV;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB,CAAC,CAAE,OAAO,CAAE,OAAO,CAAC,QAAkB,CAAE,IAAK,CAAC,CAAC,CAElE,GAAI,OAAO,CAAC,KAAK,CAAE,CACjB,KAAM,EAAC,CAAG,OAAO,CAAC,UAAU,CAAE,OAAO,CAAC,KAAe,CAAC,CACtD;AACA,KAAM,YAAW,CAAG,KAAM,OAAM,CAAC,CAAC,CAAkB,CAEpD;AACA;AACA;AACA,yCACA,KAAM,OAAM,CACV,YAAY,EAAI,YAAW,EACxB,MAAO,YAAW,CAAC,UAAU,GAAK,SAAS,EAC3C,WAAW,CAAC,UAAU,EACtB,SAAS,EAAI,YAAW,CACvB,WAAW,CAAC,OAAO,CAAG,WACV,CAClB,wCAEA,KAAM,WAAU,CAAI,OAAO,CAAC,eAAe,EAAe,SAAS,CACnE,GAAI,UAAU,GAAI,OAAM,CAAE,CACxB;AACA,OAAO,CAAC,WAAW,CACjB,MAAM,CACN,UAAU,CAAC,CACb;AACF,CAAC,IAAM,QAAO,CAAC,WAAW,CAAG,MAAM,CACrC,CAEA,KAAM,SAAQ,CAAG,UAAU,CAAC,aAAa,CAAE,OAAO,CAAC,CACnD,GAAI,OAAM,CAAG,GAAG,CAAE;AAElB;AACC,UAAU,CAAa,SAAS,CAAG,IAAM,EAAE,CAE5C,KAAM,OAAM,CAAG,KAAM,IAAI,QAAO,CAAS,CAAC,IAAI,CAAE,IAAI,GAAK,CACvD,IAAK,SAAQ,CACX,UAAU,CAEV;AACA;AACA;AACC,CACC,MAAM,CAAE,IAAI,CACZ,IAAI,CAAE,IAAI,CACV,GAAG,CAAE,IAAI,CACT,MAAM,CAAG,KAAa,EAAK,CACzB,MAAM,CAAG,KAAK,CAChB,CACF,CAAC,CAEA,KAAK,EAAK,CACT;AACA;AACA,GAAI,KAAK,CAAE,IAAI,CAAC,KAAc,CAAC,CAAC,IAC3B,KAAI,CAAC,EAAE,CAAC,CACf,CACF,CAAC,CACH,CAAC,CAAC,CAEF,OAAO,CAAC,IAAI,GAAG,CAAE,MAAM,CAAE,MAAO,CAAmB,CAAC,CACtD,CAEA,OAAO,CAAC,EAAE,CAAC,SAAS,CAAG,OAAgB,EAAK,CAC1C,IAAK,IAAG,CAAC,OAAO,CAAC,CACnB,CAAC,CAAC","ignoreList":[]}
@@ -1 +1,2 @@
1
1
  export * from './errors';
2
+ export * from './modules';
@@ -0,0 +1,18 @@
1
+ type RegisterBabelLoaderArgT = {
2
+ envName?: string;
3
+ root?: string;
4
+ };
5
+ /**
6
+ * It looks like, as of Babel v8, @babel/node does not quite work with ES module
7
+ * codebase. This function registers a Node module API hook that customizes ES
8
+ * module loading, to run Babel transformation on them.
9
+ *{(
10
+ * BEWARE: It is intended for development environments only.
11
+ */
12
+ export declare function registerBabelLoader({ envName, root, }?: RegisterBabelLoaderArgT): void;
13
+ /**
14
+ * Registers a Node module API hook that customizes ES module resolution
15
+ * to make mandatory file extensions optional.
16
+ */
17
+ export declare function registerResolver(): void;
18
+ export {};
@@ -1,3 +1,3 @@
1
1
  // Aggregates utility modules together.
2
- export*from"./errors.js";
2
+ export*from"./errors.js";export*from"./modules.js";
3
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/server/utils/index.ts"],"sourcesContent":["// Aggregates utility modules together.\n\nexport * from './errors';\n"],"mappings":"AAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/server/utils/index.ts"],"sourcesContent":["// Aggregates utility modules together.\n\nexport * from './errors';\nexport * from './modules';\n"],"mappings":"AAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ import{existsSync,readFileSync,statSync}from"node:fs";import{createRequire,registerHooks}from"node:module";import{basename,dirname}from"node:path";import{fileURLToPath}from"node:url";const CANDIDATE_EXTENSIONS=[".js",".jsx",".ts",".tsx"];const require=createRequire(import.meta.url);/**
2
+ * It looks like, as of Babel v8, @babel/node does not quite work with ES module
3
+ * codebase. This function registers a Node module API hook that customizes ES
4
+ * module loading, to run Babel transformation on them.
5
+ *{(
6
+ * BEWARE: It is intended for development environments only.
7
+ */export function registerBabelLoader({envName="development",root=process.cwd()}={}){// eslint-disable-next-line import/no-extraneous-dependencies
8
+ const{transformSync}=require("@babel/core");const cache=new Map;registerHooks({load(url,context,next){const cached=cache.get(url);if(cached!==undefined)return cached;if(url.startsWith("file://")&&!url.includes("/node_modules/")&&!url.includes("/config/babel/")&&url.match(/.(js|jsx|svg|ts|tsx)$/)){const path=fileURLToPath(url);const source=readFileSync(path,"utf8");const transformed=transformSync(source,{cwd:dirname(path),envName,filename:basename(path),root});const res={format:"module",shortCircuit:true,source:transformed?.code??""};cache.set(url,res);return res;}return next(url,context);}});}/**
9
+ * Registers a Node module API hook that customizes ES module resolution
10
+ * to make mandatory file extensions optional.
11
+ */export function registerResolver(){registerHooks({resolve(specifier,context,next){let target=specifier;if((target.startsWith(".")||target.startsWith("/"))&&context.conditions.includes("import")){target=new URL(target,context.parentURL).pathname;if(existsSync(target)&&statSync(target).isDirectory()){target+="/index";}for(const ext of CANDIDATE_EXTENSIONS){const resolved=target+ext;if(existsSync(resolved)){target=resolved;break;}}}return next(target,context);}});}
12
+ //# sourceMappingURL=modules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.js","names":[],"sources":["../../../../src/server/utils/modules.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from 'node:fs';\nimport { type LoadFnOutput, createRequire, registerHooks } from 'node:module';\nimport { basename, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type * as BabelCore from '@babel/core';\n\nconst CANDIDATE_EXTENSIONS = [\n '.js',\n '.jsx',\n '.ts',\n '.tsx',\n];\n\nconst require = createRequire(import.meta.url);\n\ntype RegisterBabelLoaderArgT = {\n envName?: string;\n root?: string;\n};\n\n/**\n * It looks like, as of Babel v8, @babel/node does not quite work with ES module\n * codebase. This function registers a Node module API hook that customizes ES\n * module loading, to run Babel transformation on them.\n *{(\n * BEWARE: It is intended for development environments only.\n */\nexport function registerBabelLoader({\n envName = 'development',\n root = process.cwd(),\n}: RegisterBabelLoaderArgT = {}): void {\n // eslint-disable-next-line import/no-extraneous-dependencies\n const { transformSync } = require('@babel/core') as typeof BabelCore;\n\n const cache = new Map<string, LoadFnOutput>();\n\n registerHooks({\n load(url, context, next) {\n const cached = cache.get(url);\n if (cached !== undefined) return cached;\n\n if (\n url.startsWith('file://')\n && !url.includes('/node_modules/')\n && !url.includes('/config/babel/')\n && url.match(/.(js|jsx|svg|ts|tsx)$/)\n ) {\n const path = fileURLToPath(url);\n const source = readFileSync(path, 'utf8');\n\n const transformed = transformSync(source, {\n cwd: dirname(path),\n envName,\n filename: basename(path),\n root,\n });\n\n const res: LoadFnOutput = {\n format: 'module',\n shortCircuit: true,\n source: transformed?.code ?? '',\n };\n\n cache.set(url, res);\n return res;\n }\n\n return next(url, context);\n },\n });\n}\n\n/**\n * Registers a Node module API hook that customizes ES module resolution\n * to make mandatory file extensions optional.\n */\nexport function registerResolver(): void {\n registerHooks({\n resolve(specifier, context, next) {\n let target = specifier;\n\n if (\n (target.startsWith('.') || target.startsWith('/'))\n && context.conditions.includes('import')\n ) {\n target = new URL(target, context.parentURL).pathname;\n\n if (existsSync(target) && statSync(target).isDirectory()) {\n target += '/index';\n }\n\n for (const ext of CANDIDATE_EXTENSIONS) {\n const resolved = target + ext;\n if (existsSync(resolved)) {\n target = resolved;\n break;\n }\n }\n }\n\n return next(target, context);\n },\n });\n}\n"],"mappings":"AAAA,OAAS,UAAU,CAAE,YAAY,CAAE,QAAQ,KAAQ,SAAS,CAC5D,OAA4B,aAAa,CAAE,aAAa,KAAQ,aAAa,CAC7E,OAAS,QAAQ,CAAE,OAAO,KAAQ,WAAW,CAC7C,OAAS,aAAa,KAAQ,UAAU,CAIxC,KAAM,qBAAoB,CAAG,CAC3B,KAAK,CACL,MAAM,CACN,KAAK,CACL,MAAM,CACP,CAED,KAAM,QAAO,CAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAO9C;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,SAAS,oBAAmB,CAAC,CAClC,OAAO,CAAG,aAAa,CACvB,IAAI,CAAG,OAAO,CAAC,GAAG,CAAC,CACI,CAAC,CAAG,CAAC,CAAC,CAAQ,CACrC;AACA,KAAM,CAAE,aAAc,CAAC,CAAG,OAAO,CAAC,aAAa,CAAqB,CAEpE,KAAM,MAAK,CAAG,GAAI,IAA2B,CAE7C,aAAa,CAAC,CACZ,IAAI,CAAC,GAAG,CAAE,OAAO,CAAE,IAAI,CAAE,CACvB,KAAM,OAAM,CAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAC7B,GAAI,MAAM,GAAK,SAAS,CAAE,MAAO,OAAM,CAEvC,GACE,GAAG,CAAC,UAAU,CAAC,SAA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AAM,EAAI,QAAQ,CACpB,CAEA,IAAK,KAAM,IAAG,GAAI,qBAAoB,CAAE,CACtC,KAAM,SAAQ,CAAG,MAAM,CAAG,GAAG,CAC7B,GAAI,UAAU,CAAC,QAAQ,CAAC,CAAE,CACxB,MAAM,CAAG,QAAQ,CACjB,MACF,CACF,CACF,CAEA,MAAO,KAAI,CAAC,MAAM,CAAE,OAAO,CAAC,CAC9B,CACF,CAAC,CAAC,CACJ","ignoreList":[]}
@@ -1,5 +1,3 @@
1
- import{existsSync,statSync}from"node:fs";import{registerHooks}from"node:module";const TRIAL=["",".cjs",".js",".jsx",".mjs",".ts",".tsx"];registerHooks({resolve:(specifier,context,next)=>{let path=specifier;// This works around the regular ESM limitation of having to have explicit
2
- // file extensions on import specifiers.
3
- if((specifier.startsWith(".")||specifier.startsWith("/"))&&context.conditions.includes("import")){const url=new URL(specifier,context.parentURL);path=url.pathname;if(existsSync(path)&&statSync(path).isDirectory())path+="/index";for(const ext of TRIAL){if(existsSync(path+ext)){path+=ext;break;}}}return next(path,context);}});// eslint-disable-next-line import/dynamic-import-chunkname
1
+ import{registerResolver}from"../../../../server/utils/modules.js";registerResolver();// eslint-disable-next-line import/dynamic-import-chunkname
4
2
  void import("./ssr.js");
5
3
  //# sourceMappingURL=ssr-preload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssr-preload.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr-preload.ts"],"sourcesContent":["import { existsSync, statSync } from 'node:fs';\nimport { registerHooks } from 'node:module';\n\nconst TRIAL = [\n '',\n '.cjs',\n '.js',\n '.jsx',\n '.mjs',\n '.ts',\n '.tsx',\n];\n\nregisterHooks({\n resolve: (specifier, context, next) => {\n let path = specifier;\n\n // This works around the regular ESM limitation of having to have explicit\n // file extensions on import specifiers.\n if ((\n specifier.startsWith('.') || specifier.startsWith('/')\n ) && context.conditions.includes('import')) {\n const url = new URL(specifier, context.parentURL);\n path = url.pathname;\n\n if (existsSync(path) && statSync(path).isDirectory()) path += '/index';\n\n for (const ext of TRIAL) {\n if (existsSync(path + ext)) {\n path += ext;\n break;\n }\n }\n }\n\n return next(path, context);\n },\n});\n\n// eslint-disable-next-line import/dynamic-import-chunkname\nvoid import('./ssr');\n"],"mappings":"AAAA,OAAS,UAAU,CAAE,QAAQ,KAAQ,SAAS,CAC9C,OAAS,aAAa,KAAQ,aAAa,CAE3C,KAAM,MAAK,CAAG,CACZ,EAAE,CACF,MAAM,CACN,KAAK,CACL,MAAM,CACN,MAAM,CACN,KAAK,CACL,MAAM,CACP,CAED,aAAa,CAAC,CACZ,OAAO,CAAE,CAAC,SAAS,CAAE,OAAO,CAAE,IAAI,GAAK,CACrC,GAAI,KAAI,CAAG,SAAS,CAEpB;AACA;AACA,GAAI,CACF,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,GACnD,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAE,CAC1C,KAAM,IAAG,CAAG,GAAI,IAAG,CAAC,SAAS,CAAE,OAAO,CAAC,SAAS,CAAC,CACjD,IAAI,CAAG,GAAG,CAAC,QAAQ,CAEnB,GAAI,UAAU,CAAC,IAAI,CAAC,EAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,CAAC,CAAE,IAAI,EAAI,QAAQ,CAEtE,IAAK,KAAM,IAAG,GAAI,MAAK,CAAE,CACvB,GAAI,UAAU,CAAC,IAAI,CAAG,GAAG,CAAC,CAAE,CAC1B,IAAI,EAAI,GAAG,CACX,MACF,CACF,CACF,CAEA,MAAO,KAAI,CAAC,IAAI,CAAE,OAAO,CAAC,CAC5B,CACF,CAAC,CAAC,CAEF;AACA,IAAK,OAAM,YAAS","ignoreList":[]}
1
+ {"version":3,"file":"ssr-preload.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr-preload.ts"],"sourcesContent":["import { registerResolver } from 'server/utils/modules';\n\nregisterResolver();\n\n// eslint-disable-next-line import/dynamic-import-chunkname\nvoid import('./ssr');\n"],"mappings":"OAAS,gBAAgB,2CAEzB,gBAAgB,CAAC,CAAC,CAElB;AACA,IAAK,OAAM,YAAS","ignoreList":[]}
@@ -1,11 +1,12 @@
1
- /* eslint-disable import/dynamic-import-chunkname, import/no-extraneous-dependencies */import{readFileSync}from"node:fs";import{registerHooks}from"node:module";import{basename,dirname,resolve}from"node:path";import{fileURLToPath}from"node:url";import{transformSync}from"@babel/core";import ssrFactory from"../../../../server/renderer.js";function noop(){// NOOP
1
+ import{resolve}from"node:path";import{registerBabelLoader}from"../../../../server/index.js";import ssrFactory from"../../../../server/renderer.js";function noop(){// NOOP
2
2
  }async function run({options,root,ssrRequest,testFolder,webpackConfig}){// NOTE: It looks like @babel/register does not work for us here, because
3
3
  // it only supports transpiling of modules loaded with require(), so here
4
4
  // is, presumably, a temporary workaround relying on the new NodeJS module
5
5
  // API, and Babel's core, to transpile all modules loaded further into
6
6
  // CommonJS. I guess, later we'll be able to get rid of this, as Babel
7
7
  // register supports runtime transformation of modules loaded with import().
8
- registerHooks({load(url,context,nextLoad){if(url.startsWith("file://")&&!url.includes("/node_modules/")&&!url.includes("/config/babel/")&&url.match(/\.(js|jsx|ts|tsx|svg)$/)){const path=fileURLToPath(url);let code=readFileSync(path,"utf8");code=transformSync(code,{cwd:dirname(path),envName:options.babelEnv,filename:basename(path),root})?.code??"";return{format:"module",shortCircuit:true,source:code};}return nextLoad(url,context);}});if(options.entry){const p=resolve(testFolder,options.entry);const babelModule=await import(p);// TODO: This is basically a hotfix hack, which works both for the library
8
+ registerBabelLoader({envName:options.babelEnv,root});if(options.entry){const p=resolve(testFolder,options.entry);// eslint-disable-next-line import/dynamic-import-chunkname
9
+ const babelModule=await import(p);// TODO: This is basically a hotfix hack, which works both for the library
9
10
  // itself, and for dependent projects... (those tested so far). It sure has
10
11
  // to be reworked later.
11
12
  /* eslint-disable no-underscore-dangle */const module="__esModule"in babelModule&&typeof babelModule.__esModule==="boolean"&&babelModule.__esModule&&"default"in babelModule?babelModule.default:babelModule;/* eslint-enable no-underscore-dangle */const exportName=options.entryExportName||"default";if(exportName in module){// eslint-disable-next-line no-param-reassign
@@ -1 +1 @@
1
- {"version":3,"file":"ssr.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr.ts"],"sourcesContent":["/* eslint-disable import/dynamic-import-chunkname, import/no-extraneous-dependencies */\n\nimport { readFileSync } from 'node:fs';\nimport { registerHooks } from 'node:module';\nimport { basename, dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { Request, Response } from 'express';\nimport type { Configuration } from 'webpack';\n\nimport { transformSync } from '@babel/core';\n\nimport ssrFactory from 'server/renderer';\n\nexport type LaunchT = {\n // TODO: Should it be typed as the renderer's options type?\n options: Record<string, unknown>;\n\n root: string;\n ssrRequest: object;\n testFolder: string;\n webpackConfig: Configuration;\n};\n\nexport type ResultT = {\n markup: string;\n status: number;\n};\n\nfunction noop() {\n // NOOP\n}\n\nasync function run({\n options,\n root,\n ssrRequest,\n testFolder,\n webpackConfig,\n}: LaunchT) {\n // NOTE: It looks like @babel/register does not work for us here, because\n // it only supports transpiling of modules loaded with require(), so here\n // is, presumably, a temporary workaround relying on the new NodeJS module\n // API, and Babel's core, to transpile all modules loaded further into\n // CommonJS. I guess, later we'll be able to get rid of this, as Babel\n // register supports runtime transformation of modules loaded with import().\n registerHooks({\n load(url, context, nextLoad) {\n if (\n url.startsWith('file://')\n && !url.includes('/node_modules/')\n && !url.includes('/config/babel/')\n && url.match(/\\.(js|jsx|ts|tsx|svg)$/)\n ) {\n const path = fileURLToPath(url);\n let code = readFileSync(path, 'utf8');\n code = transformSync(code, {\n cwd: dirname(path),\n envName: options.babelEnv as string,\n filename: basename(path),\n root,\n })?.code ?? '';\n return {\n format: 'module',\n shortCircuit: true,\n source: code,\n };\n }\n\n return nextLoad(url, context);\n },\n });\n\n if (options.entry) {\n const p = resolve(testFolder, options.entry as string);\n const babelModule = await import(p) as NodeJS.Module;\n\n // TODO: This is basically a hotfix hack, which works both for the library\n // itself, and for dependent projects... (those tested so far). It sure has\n // to be reworked later.\n /* eslint-disable no-underscore-dangle */\n const module = (\n '__esModule' in babelModule\n && typeof babelModule.__esModule === 'boolean'\n && babelModule.__esModule\n && 'default' in babelModule\n ? babelModule.default : babelModule\n ) as NodeJS.Module;\n /* eslint-enable no-underscore-dangle */\n\n const exportName = (options.entryExportName as string) || 'default';\n if (exportName in module) {\n // eslint-disable-next-line no-param-reassign\n options.Application = (\n module as unknown as Record<string, unknown>\n )[exportName];\n // eslint-disable-next-line no-param-reassign\n } else options.Application = module;\n }\n\n const renderer = ssrFactory(webpackConfig, options);\n let status = 200; // OK\n\n // eslint-disable-next-line no-param-reassign\n (ssrRequest as Request).csrfToken = () => '';\n\n const markup = await new Promise<string>((done, fail) => {\n void renderer(\n ssrRequest as Request,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n ({\n cookie: noop,\n send: done,\n set: noop,\n status: (value: number) => {\n status = value;\n },\n } as unknown) as Response,\n\n (error) => {\n // TODO: Strictly speaking, that error as Error casting is not all\n // correct, but it works, so no need to spend time on it right now.\n if (error) fail(error as Error);\n else done('');\n },\n );\n });\n\n process.send?.({ markup, status } satisfies ResultT);\n}\n\nprocess.on('message', (message: LaunchT) => {\n void run(message);\n});\n"],"mappings":"AAAA,uFAEA,OAAS,YAAY,KAAQ,SAAS,CACtC,OAAS,aAAa,KAAQ,aAAa,CAC3C,OAAS,QAAQ,CAAE,OAAO,CAAE,OAAO,KAAQ,WAAW,CACtD,OAAS,aAAa,KAAQ,UAAU,CAKxC,OAAS,aAAa,KAAQ,aAAa,CAAC,MAErC,WAAU,sCAiBjB,QAAS,KAAI,EAAG,CACd;AAAA,CAGF,cAAe,IAAG,CAAC,CACjB,OAAO,CACP,IAAI,CACJ,UAAU,CACV,UAAU,CACV,aACO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UAAU,GAAI,OAAM,CAAE,CACxB;AACA,OAAO,CAAC,WAAW,CACjB,MAAM,CACN,UAAU,CAAC,CACb;AACF,CAAC,IAAM,QAAO,CAAC,WAAW,CAAG,MAAM,CACrC,CAEA,KAAM,SAAQ,CAAG,UAAU,CAAC,aAAa,CAAE,OAAO,CAAC,CACnD,GAAI,OAAM,CAAG,GAAG,CAAE;AAElB;AACC,UAAU,CAAa,SAAS,CAAG,IAAM,EAAE,CAE5C,KAAM,OAAM,CAAG,KAAM,IAAI,QAAO,CAAS,CAAC,IAAI,CAAE,IAAI,GAAK,CACvD,IAAK,SAAQ,CACX,UAAU,CAEV;AACA;AACA;AACC,CACC,MAAM,CAAE,IAAI,CACZ,IAAI,CAAE,IAAI,CACV,GAAG,CAAE,IAAI,CACT,MAAM,CAAG,KAAa,EAAK,CACzB,MAAM,CAAG,KAAK,CAChB,CACF,CAAC,CAEA,KAAK,EAAK,CACT;AACA;AACA,GAAI,KAAK,CAAE,IAAI,CAAC,KAAc,CAAC,CAAC,IAC3B,KAAI,CAAC,EAAE,CAAC,CACf,CACF,CAAC,CACH,CAAC,CAAC,CAEF,OAAO,CAAC,IAAI,GAAG,CAAE,MAAM,CAAE,MAAO,CAAmB,CAAC,CACtD,CAEA,OAAO,CAAC,EAAE,CAAC,SAAS,CAAG,OAAgB,EAAK,CAC1C,IAAK,IAAG,CAAC,OAAO,CAAC,CACnB,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"ssr.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr.ts"],"sourcesContent":["import { resolve } from 'node:path';\n\nimport type { Request, Response } from 'express';\nimport type { Configuration } from 'webpack';\n\nimport { registerBabelLoader } from 'server';\nimport ssrFactory from 'server/renderer';\n\nexport type LaunchT = {\n // TODO: Should it be typed as the renderer's options type?\n options: Record<string, unknown>;\n\n root: string;\n ssrRequest: object;\n testFolder: string;\n webpackConfig: Configuration;\n};\n\nexport type ResultT = {\n markup: string;\n status: number;\n};\n\nfunction noop() {\n // NOOP\n}\n\nasync function run({\n options,\n root,\n ssrRequest,\n testFolder,\n webpackConfig,\n}: LaunchT) {\n // NOTE: It looks like @babel/register does not work for us here, because\n // it only supports transpiling of modules loaded with require(), so here\n // is, presumably, a temporary workaround relying on the new NodeJS module\n // API, and Babel's core, to transpile all modules loaded further into\n // CommonJS. I guess, later we'll be able to get rid of this, as Babel\n // register supports runtime transformation of modules loaded with import().\n registerBabelLoader({ envName: options.babelEnv as string, root });\n\n if (options.entry) {\n const p = resolve(testFolder, options.entry as string);\n // eslint-disable-next-line import/dynamic-import-chunkname\n const babelModule = await import(p) as NodeJS.Module;\n\n // TODO: This is basically a hotfix hack, which works both for the library\n // itself, and for dependent projects... (those tested so far). It sure has\n // to be reworked later.\n /* eslint-disable no-underscore-dangle */\n const module = (\n '__esModule' in babelModule\n && typeof babelModule.__esModule === 'boolean'\n && babelModule.__esModule\n && 'default' in babelModule\n ? babelModule.default : babelModule\n ) as NodeJS.Module;\n /* eslint-enable no-underscore-dangle */\n\n const exportName = (options.entryExportName as string) || 'default';\n if (exportName in module) {\n // eslint-disable-next-line no-param-reassign\n options.Application = (\n module as unknown as Record<string, unknown>\n )[exportName];\n // eslint-disable-next-line no-param-reassign\n } else options.Application = module;\n }\n\n const renderer = ssrFactory(webpackConfig, options);\n let status = 200; // OK\n\n // eslint-disable-next-line no-param-reassign\n (ssrRequest as Request).csrfToken = () => '';\n\n const markup = await new Promise<string>((done, fail) => {\n void renderer(\n ssrRequest as Request,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n ({\n cookie: noop,\n send: done,\n set: noop,\n status: (value: number) => {\n status = value;\n },\n } as unknown) as Response,\n\n (error) => {\n // TODO: Strictly speaking, that error as Error casting is not all\n // correct, but it works, so no need to spend time on it right now.\n if (error) fail(error as Error);\n else done('');\n },\n );\n });\n\n process.send?.({ markup, status } satisfies ResultT);\n}\n\nprocess.on('message', (message: La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,GAAG,CAAE,IAAI,CACT,MAAM,CAAG,KAAa,EAAK,CACzB,MAAM,CAAG,KAAK,CAChB,CACF,CAAC,CAEA,KAAK,EAAK,CACT;AACA;AACA,GAAI,KAAK,CAAE,IAAI,CAAC,KAAc,CAAC,CAAC,IAC3B,KAAI,CAAC,EAAE,CAAC,CACf,CACF,CAAC,CACH,CAAC,CAAC,CAEF,OAAO,CAAC,IAAI,GAAG,CAAE,MAAM,CAAE,MAAO,CAAmB,CAAC,CACtD,CAEA,OAAO,CAAC,EAAE,CAAC,SAAS,CAAG,OAAgB,EAAK,CAC1C,IAAK,IAAG,CAAC,OAAO,CAAC,CACnB,CAAC,CAAC","ignoreList":[]}
@@ -1,4 +1,5 @@
1
1
  import type { InputOptions, PluginItem, PresetItem } from '@babel/core';
2
+ import type { OptionsT as AddImportExtensionOptions } from '@dr.pogodin/babel-plugin-add-import-extension';
2
3
  export type ConfigurationT = InputOptions & {
3
4
  plugins: PluginItem[];
4
5
  presets: PresetItem[];
@@ -16,7 +17,7 @@ export declare enum ENVIRONMENTS {
16
17
  }
17
18
  type ModuleT = 'amd' | 'auto' | 'cjs' | 'commonjs' | 'systemjs' | 'umd' | false;
18
19
  export type OptionsT = {
19
- addImportExtensions?: boolean;
20
+ addImportExtensions?: AddImportExtensionOptions | boolean;
20
21
  modules?: ModuleT;
21
22
  noRR?: boolean;
22
23
  noReactCompiler?: boolean;
@@ -25,7 +25,12 @@ function newBaseConfig(options) {
25
25
  root: ['./src/shared', './src'],
26
26
  }], '@babel/transform-runtime', ['polyfill-corejs3', { method: 'usage-pure', version: '3.49' }]);
27
27
  if (options.addImportExtensions) {
28
- plugins.push('@dr.pogodin/add-import-extension');
28
+ plugins.push(['@dr.pogodin/add-import-extension',
29
+ typeof options.addImportExtensions === 'object'
30
+ ? options.addImportExtensions
31
+ : {
32
+ replacements: { svg: 'svg.js' },
33
+ }]);
29
34
  }
30
35
  return {
31
36
  parserOpts: {
@@ -3,20 +3,13 @@ import { execPath } from 'node:process';
3
3
 
4
4
  const globalLibDir = resolve(execPath, '../../lib/node_modules');
5
5
 
6
- const modulesToTransform = [
7
- '@dr.pogodin/react-global-state',
8
- '@dr.pogodin/react-utils',
9
- 'cookie',
10
- 'lodash-es',
11
- ];
12
-
13
6
  export default {
14
7
  collectCoverage: true,
15
8
  collectCoverageFrom: [
16
9
  'src/**/*.{js,jsx,ts,tsx}',
17
10
  ],
18
11
  coverageDirectory: '__coverage__',
19
- extensionsToTreatAsEsm: ['.ts', '.tsx'],
12
+ extensionsToTreatAsEsm: ['.svg', '.ts', '.tsx'],
20
13
  moduleDirectories: [
21
14
  'node_modules',
22
15
  globalLibDir,
@@ -41,7 +34,4 @@ export default {
41
34
  transform: {
42
35
  '\\.((j|t)sx?|svg)$': 'babel-jest',
43
36
  },
44
- transformIgnorePatterns: [
45
- `/node_modules/(?!${modulesToTransform.join('|')})`,
46
- ],
47
37
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.55.0-alpha.4",
2
+ "version": "1.55.0-alpha.6",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-setup": "bin/setup.js"
@@ -33,8 +33,8 @@
33
33
  "morgan": "^1.11.0",
34
34
  "qs": "^6.15.3",
35
35
  "raf": "^3.4.1",
36
- "react": "^19.2.7",
37
- "react-dom": "^19.2.7",
36
+ "react": "^19.2.8",
37
+ "react-dom": "^19.2.8",
38
38
  "react-router": "^8.2.0",
39
39
  "request-ip": "^3.3.0",
40
40
  "rimraf": "^6.1.3",
@@ -47,13 +47,12 @@
47
47
  "devDependencies": {
48
48
  "@babel/cli": "^8.0.4",
49
49
  "@babel/core": "^8.0.1",
50
- "@babel/node": "^8.0.1",
51
50
  "@babel/plugin-transform-runtime": "^8.0.1",
52
51
  "@babel/preset-env": "^8.0.2",
53
52
  "@babel/preset-react": "^8.0.1",
54
53
  "@babel/preset-typescript": "^8.0.1",
55
54
  "@babel/register": "^8.0.1",
56
- "@dr.pogodin/babel-plugin-add-import-extension": "^2.3.2",
55
+ "@dr.pogodin/babel-plugin-add-import-extension": "^3.0.0",
57
56
  "@dr.pogodin/babel-plugin-transform-assets": "^2.0.0",
58
57
  "@dr.pogodin/babel-preset-svgr": "^2.0.0",
59
58
  "@dr.pogodin/eslint-configs": "^0.3.1",
@@ -98,17 +97,17 @@
98
97
  "mockdate": "^3.0.5",
99
98
  "nodelist-foreach-polyfill": "^1.2.0",
100
99
  "patch-package": "^8.0.1",
101
- "postcss": "^8.5.20",
100
+ "postcss": "^8.5.21",
102
101
  "postcss-loader": "^8.2.1",
103
102
  "postcss-scss": "^4.0.9",
104
103
  "pretty": "^2.0.0",
105
104
  "react-refresh": "^0.18.0",
106
105
  "resolve-url-loader": "^5.0.0",
107
- "sass": "^1.101.0",
106
+ "sass": "^1.101.3",
108
107
  "sass-loader": "^17.0.0",
109
108
  "sitemap": "^9.0.1",
110
109
  "source-map-loader": "^5.0.0",
111
- "stylelint": "^17.14.0",
110
+ "stylelint": "^17.14.1",
112
111
  "stylelint-config-standard-scss": "^17.0.0",
113
112
  "supertest": "^7.2.2",
114
113
  "tsc-alias": "1.9.1",
@@ -131,17 +130,10 @@
131
130
  "types": "./build/types-code/index.d.ts",
132
131
  "exports": {
133
132
  ".": {
134
- "browser": "./build/web/index.js",
135
133
  "types": "./build/types-code/index.d.ts",
136
134
  "webpack": "./build/web/index.js",
137
- "node": {
138
- "development": "./build/development/index.js",
139
- "default": "./build/production/index.js"
140
- },
141
- "react-native": {
142
- "default": "./build/production/index.js",
143
- "types": "./build/types-code/index.d.ts"
144
- }
135
+ "development": "./build/development/index.js",
136
+ "default": "./build/production/index.js"
145
137
  },
146
138
  "./client": {
147
139
  "types": "./build/types-code/client/index.d.ts",
@@ -36,6 +36,7 @@
36
36
 
37
37
  "components": ["./src/shared/components"],
38
38
  "components/*": ["./src/shared/components/*"],
39
+ "server": ["./src/server"],
39
40
  "server/*": ["./src/server/*"],
40
41
  "utils": ["./src/shared/utils"],
41
42
  "utils/*": ["./src/shared/utils/*"],