@dr.pogodin/react-utils 1.23.8 → 1.23.10
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.
- package/README.md +4 -2
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +2 -2
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js.map +1 -1
- package/build/development/shared/components/Button/index.js +1 -1
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/CodeSplit/index.js.map +1 -1
- package/build/development/shared/components/Dropdown/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/MetaTags.js.map +1 -1
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/ScalableRect/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/utils/Barrier.js +10 -49
- package/build/development/shared/utils/Barrier.js.map +1 -1
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/index.js +5 -6
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +12 -86
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/web.bundle.js +73 -62
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js +1 -1
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +2 -2
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js.map +1 -1
- package/build/production/shared/components/Button/index.js +1 -1
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/CodeSplit/index.js.map +1 -1
- package/build/production/shared/components/Dropdown/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/MetaTags.js.map +1 -1
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/ScalableRect/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/utils/Barrier.js +4 -5
- package/build/production/shared/utils/Barrier.js.map +1 -1
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/index.js +2 -2
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +2 -52
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/package.json +29 -28
- package/build/development/shared/utils/Emitter.js +0 -61
- package/build/development/shared/utils/Emitter.js.map +0 -1
- package/build/development/shared/utils/Semaphore.js +0 -81
- package/build/development/shared/utils/Semaphore.js.map +0 -1
- package/build/production/shared/utils/Emitter.js +0 -19
- package/build/production/shared/utils/Emitter.js.map +0 -1
- package/build/production/shared/utils/Semaphore.js +0 -24
- package/build/production/shared/utils/Semaphore.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_buildInfo","require","_environmentCheck","getMode","process","env","NODE_ENV","isDevBuild","isProdBuild","buildTimestamp","getBuildInfo","timestamp"],"sources":["../../../../../src/shared/utils/isomorphy/index.js"],"sourcesContent":["import { getBuildInfo } from './buildInfo';\nimport { IS_CLIENT_SIDE, IS_SERVER_SIDE } from './environment-check';\n\n/**\n * @ignore\n * @return {string} Code mode: \"development\" or \"production\".\n */\nfunction getMode() {\n return process.env.NODE_ENV;\n}\n\n/**\n * Returns `true` if development version of the code is running;\n * `false` otherwise.\n * @return {boolean}\n */\nexport function isDevBuild() {\n return getMode() === 'development';\n}\n\n/**\n * Returns `true` if production build of the code is running;\n * `false` otherwise.\n * @return {boolean}\n */\nexport function isProdBuild() {\n return getMode() === 'production';\n}\n\n/**\n * Returns build timestamp of the front-end JS bundle.\n * @return {string} ISO date/time string.\n */\nexport function buildTimestamp() {\n return getBuildInfo().timestamp;\n}\n\nexport { IS_CLIENT_SIDE, IS_SERVER_SIDE, getBuildInfo };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA,SAASE,OAAOA,CAAA,EAAG;EACjB,OAAOC,OAAO,CAACC,GAAG,CAACC,QAAQ;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,UAAUA,CAAA,EAAG;EAC3B,OAAOJ,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","names":["_buildInfo","require","_environmentCheck","getMode","process","env","NODE_ENV","isDevBuild","isProdBuild","buildTimestamp","getBuildInfo","timestamp"],"sources":["../../../../../src/shared/utils/isomorphy/index.js"],"sourcesContent":["import { getBuildInfo } from './buildInfo';\nimport { IS_CLIENT_SIDE, IS_SERVER_SIDE } from './environment-check';\n\n/**\n * @ignore\n * @return {string} Code mode: \"development\" or \"production\".\n */\nfunction getMode() {\n return process.env.NODE_ENV;\n}\n\n/**\n * Returns `true` if development version of the code is running;\n * `false` otherwise.\n * @return {boolean}\n */\nexport function isDevBuild() {\n return getMode() === 'development';\n}\n\n/**\n * Returns `true` if production build of the code is running;\n * `false` otherwise.\n * @return {boolean}\n */\nexport function isProdBuild() {\n return getMode() === 'production';\n}\n\n/**\n * Returns build timestamp of the front-end JS bundle.\n * @return {string} ISO date/time string.\n */\nexport function buildTimestamp() {\n return getBuildInfo().timestamp;\n}\n\nexport { IS_CLIENT_SIDE, IS_SERVER_SIDE, getBuildInfo };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA,SAASE,OAAOA,CAAA,EAAG;EACjB,OAAOC,OAAO,CAACC,GAAG,CAACC,QAAQ;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,UAAUA,CAAA,EAAG;EAC3B,OAAOJ,OAAO,CAAC,CAAC,KAAK,aAAa;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASK,WAAWA,CAAA,EAAG;EAC5B,OAAOL,OAAO,CAAC,CAAC,KAAK,YAAY;AACnC;;AAEA;AACA;AACA;AACA;AACO,SAASM,cAAcA,CAAA,EAAG;EAC/B,OAAO,IAAAC,uBAAY,EAAC,CAAC,CAACC,SAAS;AACjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"E2eSsrEnv.js","names":["_path","_interopRequireDefault","require","_renderer","_lodash","_register","_jestEnvironmentJsdom","_memfs","_webpack","E2eSsrEnv","JsdomEnv","loadWebpackConfig","options","pragmas","JSON","parse","defaults","context","testFolder","fs","global","webpackOutputFs","factory","path","resolve","rootDir","webpackConfig","buildInfo","existsSync","readFileSync","runWebpack","compiler","webpack","outputFileSystem","Promise","done","fail","run","err","stats","hasErrors","console","error","toJson","errors","Error","webpackStats","runSsr","logger","undefined","debug","noop","info","log","warn","root","process","cwd","register","envName","babelEnv","extensions","entry","p","Application","entryExportName","renderer","ssrFactory","status","markup","ssrRequest","cookie","send","set","value","locals","devMiddleware","ssrMarkup","ssrOptions","ssrStatus","constructor","config","docblockPragmas","request","url","csrfToken","projectConfig","dom","createFsFromVolume","Volume","dirname","testPath","withSsr","setup","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","cache","forEach","key","revert","exports","default"],"sources":["../../../../../src/shared/utils/jest/E2eSsrEnv.js"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n/* eslint-disable global-require, import/no-dynamic-require */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\nimport path from 'path';\nimport ssrFactory from 'server/renderer';\n\nimport { defaults, noop, set } from 'lodash';\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\nimport register from '@babel/register';\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { createFsFromVolume, Volume } from 'memfs';\nimport webpack from 'webpack';\n/* eslint-enable import/no-extraneous-dependencies */\n\nexport default class E2eSsrEnv extends JsdomEnv {\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n loadWebpackConfig() {\n let options = this.pragmas['webpack-config-options'];\n options = options ? JSON.parse(options) : {};\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n let factory = this.pragmas['webpack-config-factory'] || '';\n factory = require(path.resolve(this.rootDir, factory));\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs;\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8');\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack() {\n this.loadWebpackConfig();\n\n const compiler = webpack(this.global.webpackConfig);\n compiler.outputFileSystem = this.global.webpackOutputFs;\n return new Promise((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats.hasErrors()) {\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr() {\n let options = this.pragmas['ssr-options'];\n options = options ? JSON.parse(options) : {};\n\n // TODO: This is temporary to shortcut the logging added to SSR.\n if (options.logger === undefined) {\n options.logger = {\n debug: noop,\n info: noop,\n log: noop,\n warn: noop,\n };\n }\n\n let root;\n switch (options.root) {\n case 'TEST': root = this.testFolder; break;\n default: root = process.cwd();\n }\n\n // Note: This enables Babel transformation for the code dynamically loaded\n // below, as the usual Jest Babel setup does not seem to apply to\n // the environment code, and imports from it.\n register({\n envName: options.babelEnv,\n extensions: ['.js', '.jsx', '.svg'],\n root,\n });\n\n if (!options.buildInfo) options.buildInfo = this.global.buildInfo;\n\n if (options.entry) {\n const p = path.resolve(this.testFolder, options.entry);\n options.Application = require(p)[options.entryExportName || 'default'];\n }\n\n const renderer = ssrFactory(this.global.webpackConfig, options);\n let status = 200; // OK\n const markup = await new Promise((done, fail) => {\n renderer(\n this.ssrRequest,\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) => {\n status = value;\n },\n\n // This is how up-to-date Webpack stats are passed to the server in\n // development mode, and we use this here always, instead of having\n // to pass some information via filesystem.\n locals: {\n webpack: {\n devMiddleware: {\n stats: this.webpackStats,\n },\n },\n },\n },\n\n (error) => {\n if (error) fail(error);\n else done('');\n },\n );\n });\n\n this.global.ssrMarkup = markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = status;\n }\n\n constructor(config, context) {\n const pragmas = context.docblockPragmas;\n let request = pragmas['ssr-request'];\n request = request ? JSON.parse(request) : {};\n if (!request.url) request.url = '/';\n request.csrfToken = noop;\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n }\n\n async setup() {\n await super.setup();\n await this.runWebpack();\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\n\n async teardown() {\n delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n // Resets module cache and @babel/register. Effectively this ensures that\n // the next time an instance of this environment is set up, all modules are\n // transformed by Babel from scratch, thus taking into account the latest\n // Babel config (which may change between different environment instances,\n // which does not seem to be taken into account by Babel / Node caches\n // automatically).\n Object.keys(require.cache).forEach((key) => {\n delete require.cache[key];\n });\n register.revert();\n super.teardown();\n }\n}\n"],"mappings":";;;;;;;AAiBA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AAKA,IAAAG,SAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,qBAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAP,sBAAA,CAAAC,OAAA;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA;AACA;AACA;AAKA;AAEe,MAAMO,SAAS,SAASC,6BAAQ,CAAC;EAC9C;AACF;AACA;AACA;EACEC,iBAAiBA,CAAA,EAAG;IAClB,IAAIC,OAAO,GAAG,IAAI,CAACC,OAAO,CAAC,wBAAwB,CAAC;IACpDD,OAAO,GAAGA,OAAO,GAAGE,IAAI,CAACC,KAAK,CAACH,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAAI,gBAAQ,EAACJ,OAAO,EAAE;MAChBK,OAAO,EAAE,IAAI,CAACC,UAAU;MACxBC,EAAE,EAAE,IAAI,CAACC,MAAM,CAACC;IAClB,CAAC,CAAC;IAEF,IAAIC,OAAO,GAAG,IAAI,CAACT,OAAO,CAAC,wBAAwB,CAAC,IAAI,EAAE;IAC1DS,OAAO,GAAGpB,OAAO,CAACqB,aAAI,CAACC,OAAO,CAAC,IAAI,CAACC,OAAO,EAAEH,OAAO,CAAC,CAAC;IACtD,IAAI,CAACF,MAAM,CAACM,aAAa,GAAGJ,OAAO,CAACV,OAAO,CAAC;IAE5C,MAAMO,EAAE,GAAG,IAAI,CAACC,M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MAAM;MAAEH;IAAc,CAAC,GAAGL,MAAM;IAChC,IAAI,CAACxD,OAAO,GAAG6D,aAAa,CAAC7D,OAAO;IACpC,IAAI,CAACP,UAAU,GAAGK,aAAI,CAACmE,OAAO,CAACzE,OAAO,CAAC0E,QAAQ,CAAC;IAChD,IAAI,CAACC,OAAO,GAAG,CAAC/E,OAAO,CAAC,QAAQ,CAAC;IACjC,IAAI,CAACyD,UAAU,GAAGa,OAAO;IACzB,IAAI,CAACtE,OAAO,GAAGA,OAAO;EACxB;EAEA,MAAMgF,KAAKA,CAAA,EAAG;IACZ,MAAM,KAAK,CAACA,KAAK,EAAE;IACnB,MAAM,IAAI,CAAC/D,UAAU,EAAE;IACvB,IAAI,IAAI,CAAC8D,OAAO,EAAE,MAAM,IAAI,CAAC7C,MAAM,EAAE;IACrC,IAAI,CAAC3B,MAAM,CAAC0E,6BAA6B,GAAG,IAAI;EAClD;EAEA,MAAMC,QAAQA,CAAA,EAAG;IACf,OAAO,IAAI,CAAC3E,MAAM,CAAC0E,6BAA6B;;IAEhD;IACA;IACA;IACA;IACA;IACA;IACAE,MAAM,CAACC,IAAI,CAAC/F,OAAO,CAACgG,KAAK,CAAC,CAACC,OAAO,CAAEC,GAAG,IAAK;MAC1C,OAAOlG,OAAO,CAACgG,KAAK,CAACE,GAAG,CAAC;IAC3B,CAAC,CAAC;IACF1C,iBAAQ,CAAC2C,MAAM,EAAE;IACjB,KAAK,CAACN,QAAQ,EAAE;EAClB;AACF;AAACO,OAAA,CAAAC,OAAA,GAAA9F,SAAA"}
|
|
1
|
+
{"version":3,"file":"E2eSsrEnv.js","names":["_path","_interopRequireDefault","require","_renderer","_lodash","_register","_jestEnvironmentJsdom","_memfs","_webpack","E2eSsrEnv","JsdomEnv","loadWebpackConfig","options","pragmas","JSON","parse","defaults","context","testFolder","fs","global","webpackOutputFs","factory","path","resolve","rootDir","webpackConfig","buildInfo","existsSync","readFileSync","runWebpack","compiler","webpack","outputFileSystem","Promise","done","fail","run","err","stats","hasErrors","console","error","toJson","errors","Error","webpackStats","runSsr","logger","undefined","debug","noop","info","log","warn","root","process","cwd","register","envName","babelEnv","extensions","entry","p","Application","entryExportName","renderer","ssrFactory","status","markup","ssrRequest","cookie","send","set","value","locals","devMiddleware","ssrMarkup","ssrOptions","ssrStatus","constructor","config","docblockPragmas","request","url","csrfToken","projectConfig","dom","createFsFromVolume","Volume","dirname","testPath","withSsr","setup","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","cache","forEach","key","revert","exports","default"],"sources":["../../../../../src/shared/utils/jest/E2eSsrEnv.js"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n/* eslint-disable global-require, import/no-dynamic-require */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\nimport path from 'path';\nimport ssrFactory from 'server/renderer';\n\nimport { defaults, noop, set } from 'lodash';\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\nimport register from '@babel/register';\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { createFsFromVolume, Volume } from 'memfs';\nimport webpack from 'webpack';\n/* eslint-enable import/no-extraneous-dependencies */\n\nexport default class E2eSsrEnv extends JsdomEnv {\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n loadWebpackConfig() {\n let options = this.pragmas['webpack-config-options'];\n options = options ? JSON.parse(options) : {};\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n let factory = this.pragmas['webpack-config-factory'] || '';\n factory = require(path.resolve(this.rootDir, factory));\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs;\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8');\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack() {\n this.loadWebpackConfig();\n\n const compiler = webpack(this.global.webpackConfig);\n compiler.outputFileSystem = this.global.webpackOutputFs;\n return new Promise((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats.hasErrors()) {\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr() {\n let options = this.pragmas['ssr-options'];\n options = options ? JSON.parse(options) : {};\n\n // TODO: This is temporary to shortcut the logging added to SSR.\n if (options.logger === undefined) {\n options.logger = {\n debug: noop,\n info: noop,\n log: noop,\n warn: noop,\n };\n }\n\n let root;\n switch (options.root) {\n case 'TEST': root = this.testFolder; break;\n default: root = process.cwd();\n }\n\n // Note: This enables Babel transformation for the code dynamically loaded\n // below, as the usual Jest Babel setup does not seem to apply to\n // the environment code, and imports from it.\n register({\n envName: options.babelEnv,\n extensions: ['.js', '.jsx', '.svg'],\n root,\n });\n\n if (!options.buildInfo) options.buildInfo = this.global.buildInfo;\n\n if (options.entry) {\n const p = path.resolve(this.testFolder, options.entry);\n options.Application = require(p)[options.entryExportName || 'default'];\n }\n\n const renderer = ssrFactory(this.global.webpackConfig, options);\n let status = 200; // OK\n const markup = await new Promise((done, fail) => {\n renderer(\n this.ssrRequest,\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) => {\n status = value;\n },\n\n // This is how up-to-date Webpack stats are passed to the server in\n // development mode, and we use this here always, instead of having\n // to pass some information via filesystem.\n locals: {\n webpack: {\n devMiddleware: {\n stats: this.webpackStats,\n },\n },\n },\n },\n\n (error) => {\n if (error) fail(error);\n else done('');\n },\n );\n });\n\n this.global.ssrMarkup = markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = status;\n }\n\n constructor(config, context) {\n const pragmas = context.docblockPragmas;\n let request = pragmas['ssr-request'];\n request = request ? JSON.parse(request) : {};\n if (!request.url) request.url = '/';\n request.csrfToken = noop;\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n }\n\n async setup() {\n await super.setup();\n await this.runWebpack();\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\n\n async teardown() {\n delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n // Resets module cache and @babel/register. Effectively this ensures that\n // the next time an instance of this environment is set up, all modules are\n // transformed by Babel from scratch, thus taking into account the latest\n // Babel config (which may change between different environment instances,\n // which does not seem to be taken into account by Babel / Node caches\n // automatically).\n Object.keys(require.cache).forEach((key) => {\n delete require.cache[key];\n });\n register.revert();\n super.teardown();\n }\n}\n"],"mappings":";;;;;;;AAiBA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AAKA,IAAAG,SAAA,GAAAJ,s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O;IACzB,IAAI,CAACtE,OAAO,GAAGA,OAAO;EACxB;EAEA,MAAMgF,KAAKA,CAAA,EAAG;IACZ,MAAM,KAAK,CAACA,KAAK,CAAC,CAAC;IACnB,MAAM,IAAI,CAAC/D,UAAU,CAAC,CAAC;IACvB,IAAI,IAAI,CAAC8D,OAAO,EAAE,MAAM,IAAI,CAAC7C,MAAM,CAAC,CAAC;IACrC,IAAI,CAAC3B,MAAM,CAAC0E,6BAA6B,GAAG,IAAI;EAClD;EAEA,MAAMC,QAAQA,CAAA,EAAG;IACf,OAAO,IAAI,CAAC3E,MAAM,CAAC0E,6BAA6B;;IAEhD;IACA;IACA;IACA;IACA;IACA;IACAE,MAAM,CAACC,IAAI,CAAC/F,OAAO,CAACgG,KAAK,CAAC,CAACC,OAAO,CAAEC,GAAG,IAAK;MAC1C,OAAOlG,OAAO,CAACgG,KAAK,CAACE,GAAG,CAAC;IAC3B,CAAC,CAAC;IACF1C,iBAAQ,CAAC2C,MAAM,CAAC,CAAC;IACjB,KAAK,CAACN,QAAQ,CAAC,CAAC;EAClB;AACF;AAACO,OAAA,CAAAC,OAAA,GAAA9F,SAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_mockdate","_interopRequireDefault","require","_client","_testUtils","_interopRequireWildcard","_reactTestRenderer","_shallow","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","global","IS_REACT_ACT_ENVIRONMENT","originalProcessVersions","process","versions","mockClientSide","value","unmockClientSide","writable","getMockUuid","seed","x","toString","padStart","slice","mockTimer","time","mockdate","Date","now","jest","advanceTimersByTime","mount","scene","root","res","document","createElement","body","appendChild","destroy","act","unmount","remove","createRoot","render","component","Renderer","create","toJSON","shallowRender","renderer","ShallowRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","TU","Simulate","exports"],"sources":["../../../../../src/shared/utils/jest/index.jsx"],"sourcesContent":["/* global expect, jest, document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport mockdate from 'mockdate';\nimport { createRoot } from 'react-dom/client';\nimport TU, { act } from 'react-dom/test-utils';\n\n/* eslint-disable import/no-extraneous-dependencies */\nimport Renderer from 'react-test-renderer';\nimport ShallowRenderer from 'react-test-renderer/shallow';\n/* eslint-enable import/no-extraneous-dependencies */\n\n/**\n * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)\n * from `react-dom/test-utils`.\n * @param {function} action\n */\nexport { act };\n\nglobal.IS_REACT_ACT_ENVIRONMENT = true;\n\nconst originalProcessVersions = process.versions;\n\n/**\n * Tricks **react-utils** into thinking the test is running within client-side\n * (browser) environment.\n */\nexport function mockClientSide() {\n Object.defineProperty(process, 'versions', { value: null });\n}\n\n/**\n * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.\n */\nexport function unmockClientSide() {\n Object.defineProperty(process, 'versions', {\n value: originalProcessVersions,\n writable: false,\n });\n}\n\n/**\n * Generates a mock UUID, or better said it determenistically transforms given\n * `seed` number into a UUID-formatted string.\n * @param {number} seed\n * @return {string}\n */\nexport function getMockUuid(seed = 0) {\n const x = seed.toString(16).padStart(32, '0');\n return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;\n}\n\n/**\n * Advances mock timers, and mock date by the specified time.\n * @param {number} time Time step [ms].\n * @returns {Promise} Wait for this to \"jump after\" any async code which should\n * be executed because of the mock time movement.\n */\nexport async function mockTimer(time) {\n mockdate.set(time + Date.now());\n jest.advanceTimersByTime(time);\n}\n\n/**\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param {React.ReactNode} scene\n * @return {HTMLElement} Created container DOM element with destroy() function\n * attached.\n */\nexport function mount(scene) {\n let root;\n const res = document.createElement('div');\n document.body.appendChild(res);\n res.destroy = () => {\n act(() => root.unmount());\n res.remove();\n };\n act(() => {\n root = createRoot(res);\n root.render(scene);\n });\n return res;\n}\n\n/* OLD STUFF BELOW THIS MARK */\n\n/**\n * Renders provided ReactJS component into JSON representation of the component\n * tree, using [`react-test-renderer`](https://www.npmjs.com/package/react-test-renderer).\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the rendered tree.\n * @example\n * import { JU } from '@dr.pogodin/react-utils';\n * console.log(JU.render(<div>Example</div>));\n */\nexport function render(component) {\n return Renderer.create(component).toJSON();\n}\n\n/**\n * Generates a shallow render of given ReactJS component, using\n * [react-test-renderer/shallow](https://reactjs.org/docs/shallow-renderer.html)\n * and returns the result.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the shallow component's render tree.\n */\nexport function shallowRender(component) {\n const renderer = new ShallowRenderer();\n renderer.render(component);\n return renderer.getRenderOutput();\n}\n\n/**\n * Makes a shallow snapshot test of the given ReactJS component, and also\n * returns JSON representation of the rendered component tree. Under the hood\n * it uses {@link module:JU.shallowRender shallowRender(..)} to generate\n * the render, then executes `expect(RENDER_RESULT).toMatchSnapshot()`,\n * and finally returns the `RENDER_RESULT` to the caller.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of shallow render.\n */\nexport function shallowSnapshot(component) {\n const res = shallowRender(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\n/**\n * Makes snapshot test of the given ReactJS component, and also returns JSON\n * representation of the rendered component tree. Under the hood, it uses\n * {@link module:JU.render render(..)} to render it, then executes\n * `expect(RENDER_RESULT).toMatchSnapshot()`, and then returns `RENDER_RESULT`.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON render of the component.\n */\nexport function snapshot(component) {\n const res = render(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\nexport const simulate = TU.Simulate;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;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A;AAT1D;AACA;;AAMA;;AAGA;AAEA;AACA;AACA;AACA;AACA;AAGAW,MAAM,CAACC,wBAAwB,GAAG,IAAI;AAEtC,MAAMC,uBAAuB,GAAGC,OAAO,CAACC,QAAQ;;AAEhD;AACA;AACA;AACA;AACO,SAASC,cAAcA,CAAA,EAAG;EAC/Bd,MAAM,CAACC,cAAc,CAACW,OAAO,EAAE,UAAU,EAAE;IAAEG,KAAK,EAAE;EAAK,CAAC,CAAC;AAC7D;;AAEA;AACA;AACA;AACO,SAASC,gBAAgBA,CAAA,EAAG;EACjChB,MAAM,CAACC,cAAc,CAACW,OAAO,EAAE,UAAU,EAAE;IACzCG,KAAK,EAAEJ,uBAAuB;IAC9BM,QAAQ,EAAE;EACZ,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,WAAWA,CAACC,IAAI,GAAG,CAAC,EAAE;EACpC,MAAMC,CAAC,GAAGD,IAAI,CAACE,QAAQ,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC;EAC7C,OAAQ,GAAEF,CAAC,CAACG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAE,IAAGH,CAAC,CAACG,KAAK,CAAC,CAAC,EAAE,EAAE,CAAE,IAAGH,CAAC,CAACG,KAAK,CAAC,EAAE,EAAE,EAAE,CAAE,IAAGH,CAAC,CAACG,KAAK,CAAC,EAAE,EAAE,EAAE,CAAE,IAAGH,CAAC,CAACG,KAAK,CAAC,EAAE,CAAE,EAAC;AAClG;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeC,SAASA,CAACC,IAAI,EAAE;EACpCC,iBAAQ,CAAClB,GAAG,CAACiB,IAAI,GAAGE,IAAI,CAACC,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","names":["_mockdate","_interopRequireDefault","require","_client","_testUtils","_interopRequireWildcard","_reactTestRenderer","_shallow","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","global","IS_REACT_ACT_ENVIRONMENT","originalProcessVersions","process","versions","mockClientSide","value","unmockClientSide","writable","getMockUuid","seed","x","toString","padStart","slice","mockTimer","time","mockdate","Date","now","jest","advanceTimersByTime","mount","scene","root","res","document","createElement","body","appendChild","destroy","act","unmount","remove","createRoot","render","component","Renderer","create","toJSON","shallowRender","renderer","ShallowRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","TU","Simulate","exports"],"sources":["../../../../../src/shared/utils/jest/index.jsx"],"sourcesContent":["/* global expect, jest, document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport mockdate from 'mockdate';\nimport { createRoot } from 'react-dom/client';\nimport TU, { act } from 'react-dom/test-utils';\n\n/* eslint-disable import/no-extraneous-dependencies */\nimport Renderer from 'react-test-renderer';\nimport ShallowRenderer from 'react-test-renderer/shallow';\n/* eslint-enable import/no-extraneous-dependencies */\n\n/**\n * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)\n * from `react-dom/test-utils`.\n * @param {function} action\n */\nexport { act };\n\nglobal.IS_REACT_ACT_ENVIRONMENT = true;\n\nconst originalProcessVersions = process.versions;\n\n/**\n * Tricks **react-utils** into thinking the test is running within client-side\n * (browser) environment.\n */\nexport function mockClientSide() {\n Object.defineProperty(process, 'versions', { value: null });\n}\n\n/**\n * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.\n */\nexport function unmockClientSide() {\n Object.defineProperty(process, 'versions', {\n value: originalProcessVersions,\n writable: false,\n });\n}\n\n/**\n * Generates a mock UUID, or better said it determenistically transforms given\n * `seed` number into a UUID-formatted string.\n * @param {number} seed\n * @return {string}\n */\nexport function getMockUuid(seed = 0) {\n const x = seed.toString(16).padStart(32, '0');\n return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;\n}\n\n/**\n * Advances mock timers, and mock date by the specified time.\n * @param {number} time Time step [ms].\n * @returns {Promise} Wait for this to \"jump after\" any async code which should\n * be executed because of the mock time movement.\n */\nexport async function mockTimer(time) {\n mockdate.set(time + Date.now());\n jest.advanceTimersByTime(time);\n}\n\n/**\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param {React.ReactNode} scene\n * @return {HTMLElement} Created container DOM element with destroy() function\n * attached.\n */\nexport function mount(scene) {\n let root;\n const res = document.createElement('div');\n document.body.appendChild(res);\n res.destroy = () => {\n act(() => root.unmount());\n res.remove();\n };\n act(() => {\n root = createRoot(res);\n root.render(scene);\n });\n return res;\n}\n\n/* OLD STUFF BELOW THIS MARK */\n\n/**\n * Renders provided ReactJS component into JSON representation of the component\n * tree, using [`react-test-renderer`](https://www.npmjs.com/package/react-test-renderer).\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the rendered tree.\n * @example\n * import { JU } from '@dr.pogodin/react-utils';\n * console.log(JU.render(<div>Example</div>));\n */\nexport function render(component) {\n return Renderer.create(component).toJSON();\n}\n\n/**\n * Generates a shallow render of given ReactJS component, using\n * [react-test-renderer/shallow](https://reactjs.org/docs/shallow-renderer.html)\n * and returns the result.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the shallow component's render tree.\n */\nexport function shallowRender(component) {\n const renderer = new ShallowRenderer();\n renderer.render(component);\n return renderer.getRenderOutput();\n}\n\n/**\n * Makes a shallow snapshot test of the given ReactJS component, and also\n * returns JSON representation of the rendered component tree. Under the hood\n * it uses {@link module:JU.shallowRender shallowRender(..)} to generate\n * the render, then executes `expect(RENDER_RESULT).toMatchSnapshot()`,\n * and finally returns the `RENDER_RESULT` to the caller.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of shallow render.\n */\nexport function shallowSnapshot(component) {\n const res = shallowRender(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\n/**\n * Makes snapshot test of the given ReactJS component, and also returns JSON\n * representation of the rendered component tree. Under the hood, it uses\n * {@link module:JU.render render(..)} to render it, then executes\n * `expect(RENDER_RESULT).toMatchSnapshot()`, and then returns `RENDER_RESULT`.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON render of the component.\n */\nexport function snapshot(component) {\n const res = render(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\nexport const simulate = TU.Simulate;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAC,uBAAA,CAAAH,OAAA;AAGA,IAAAI,kBAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,QAAA,GAAAN,sBAAA,CAAAC,OAAA;AAA0D,SAAAM,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,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;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,eAAeA,CAACR,SAAS,EAAE;EACzC,MAAMX,GAAG,GAAGe,aAAa,CAACJ,SAAS,CAAC;EACpCS,MAAM,CAACpB,GAAG,CAAC,CAACqB,eAAe,CAAC,CAAC;EAC7B,OAAOrB,GAAG;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASsB,QAAQA,CAACX,SAAS,EAAE;EAClC,MAAMX,GAAG,GAAGU,MAAM,CAACC,SAAS,CAAC;EAC7BS,MAAM,CAACpB,GAAG,CAAC,CAACqB,eAAe,CAAC,CAAC;EAC7B,OAAOrB,GAAG;AACZ;AAEO,MAAMuB,QAAQ,GAAGC,kBAAE,CAACC,QAAQ;AAACC,OAAA,CAAAH,QAAA,GAAAA,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitComponent.js","names":["_react","require","_CodeSplit","_interopRequireDefault","splitComponent","chunkName","getComponent","placeholder","children","props","createElement","CodeSplit"],"sources":["../../../../src/shared/utils/splitComponent.js"],"sourcesContent":["/* eslint-disable react/jsx-props-no-spreading */\n\nimport { createElement } from 'react';\n\nimport CodeSplit from 'components/CodeSplit';\n\n/**\n * Wraps a regular React component into a \"code splitting\" component,\n * i.e. all code used exclusively by that component and its sub-tree\n * will go into a separate, asynchronously loaded, code chunk for\n * the client-side.\n * @param {object} options\n * @param {string} options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent({\n chunkName,\n getComponent,\n placeholder,\n}) {\n // eslint-disable-next-line react/prop-types\n return ({ children, ...props } = {}) => createElement(\n CodeSplit,\n {\n ...props,\n chunkName,\n getComponent,\n placeholder,\n },\n children,\n );\n}\n"],"mappings":";;;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AAJA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,cAAcA,CAAC;EACrCC,SAAS;EACTC,YAAY;EACZC;AACF,CAAC,EAAE;EACD;EACA,OAAO,CAAC;IAAEC,QAAQ;IAAE,GAAGC;EAAM,CAAC,GAAG,CAAC,CAAC,kBAAK,IAAAC,oBAAa,EACnDC,kBAAS,EACT;IACE,GAAGF,KAAK;IACRJ,SAAS;IACTC,YAAY;IACZC;EACF,CAAC,EACDC,
|
|
1
|
+
{"version":3,"file":"splitComponent.js","names":["_react","require","_CodeSplit","_interopRequireDefault","splitComponent","chunkName","getComponent","placeholder","children","props","createElement","CodeSplit"],"sources":["../../../../src/shared/utils/splitComponent.js"],"sourcesContent":["/* eslint-disable react/jsx-props-no-spreading */\n\nimport { createElement } from 'react';\n\nimport CodeSplit from 'components/CodeSplit';\n\n/**\n * Wraps a regular React component into a \"code splitting\" component,\n * i.e. all code used exclusively by that component and its sub-tree\n * will go into a separate, asynchronously loaded, code chunk for\n * the client-side.\n * @param {object} options\n * @param {string} options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent({\n chunkName,\n getComponent,\n placeholder,\n}) {\n // eslint-disable-next-line react/prop-types\n return ({ children, ...props } = {}) => createElement(\n CodeSplit,\n {\n ...props,\n chunkName,\n getComponent,\n placeholder,\n },\n children,\n );\n}\n"],"mappings":";;;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AAJA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,cAAcA,CAAC;EACrCC,SAAS;EACTC,YAAY;EACZC;AACF,CAAC,EAAE;EACD;EACA,OAAO,CAAC;IAAEC,QAAQ;IAAE,GAAGC;EAAM,CAAC,GAAG,CAAC,CAAC,kBAAK,IAAAC,oBAAa,EACnDC,kBAAS,EACT;IACE,GAAGF,KAAK;IACRJ,SAAS;IACTC,YAAY;IACZC;EACF,CAAC,EACDC,QACF,CAAC;AACH"}
|
|
@@ -5,98 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
exports.timer = timer;
|
|
9
8
|
exports.useCurrent = useCurrent;
|
|
10
9
|
exports.useTimezoneOffset = useTimezoneOffset;
|
|
11
10
|
var _cookie = _interopRequireDefault(require("cookie"));
|
|
12
11
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
13
12
|
var _lodash = require("lodash");
|
|
14
13
|
var _react = require("react");
|
|
14
|
+
var _jsUtils = require("@dr.pogodin/js-utils");
|
|
15
15
|
var _reactGlobalState = require("@dr.pogodin/react-global-state");
|
|
16
|
-
var _Barrier = require("./Barrier");
|
|
17
16
|
/* global document */
|
|
18
17
|
|
|
19
|
-
/**
|
|
20
|
-
* @static
|
|
21
|
-
* @const SEC_MS
|
|
22
|
-
* @desc One second, expressed in milliseconds (equals 1000 ms).
|
|
23
|
-
* @example
|
|
24
|
-
* import { time } from '@dr.pogodin/react-utils';
|
|
25
|
-
* console.log(time.SEC_MS); // Prints: 1000
|
|
26
|
-
*/
|
|
27
|
-
_dayjs.default.SEC_MS = 1000;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @static
|
|
31
|
-
* @const MIN_MS
|
|
32
|
-
* @desc One minute, expressed in milliseconds (equals 60 × `SEC_MS`).
|
|
33
|
-
* @example
|
|
34
|
-
* import { time } from '@dr.pogodin/react-utils';
|
|
35
|
-
* console.log(time.MIN_MS); // Prints: 60000
|
|
36
|
-
*/
|
|
37
|
-
_dayjs.default.MIN_MS = 60 * _dayjs.default.SEC_MS;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @static
|
|
41
|
-
* @const HOUR_MS
|
|
42
|
-
* @desc One hour, expressed in milliseconds (equals 60 × `MIN_MS`).
|
|
43
|
-
* @example
|
|
44
|
-
* import { time } from '@dr.pogodin/react-utils';
|
|
45
|
-
* console.log(time.HOUR_MS); // Prints: 3600000
|
|
46
|
-
*/
|
|
47
|
-
_dayjs.default.HOUR_MS = 60 * _dayjs.default.MIN_MS;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @static
|
|
51
|
-
* @const DAY_MS
|
|
52
|
-
* @desc One day, expressed in milliseconds (equals 24 × `HOUR_MS`).
|
|
53
|
-
* @example
|
|
54
|
-
* import { time } from '@dr.pogodin/react-utils';
|
|
55
|
-
* console.log(time.DAY_MS); // Prints: 86400000
|
|
56
|
-
*/
|
|
57
|
-
_dayjs.default.DAY_MS = 24 * _dayjs.default.HOUR_MS;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @static
|
|
61
|
-
* @const YEAR_MS
|
|
62
|
-
* @desc One year, expressed in milliseconds (equals 365 × `DAY_MS`,
|
|
63
|
-
* thus a normal, non-leap year).
|
|
64
|
-
* @example
|
|
65
|
-
* import { time } from '@dr.pogodin/react-utils';
|
|
66
|
-
* console.log(time.YEAR_MS); // Prints: 31536000000
|
|
67
|
-
*/
|
|
68
|
-
_dayjs.default.YEAR_MS = 365 * _dayjs.default.DAY_MS;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @static
|
|
72
|
-
* @func now
|
|
73
|
-
* @desc Returns Unix timestamp [ms] (thus, it is just an alias for `Date.now`).
|
|
74
|
-
* @return {number}
|
|
75
|
-
* @example
|
|
76
|
-
* import { time } from '@dr.pogodin/react-utils';
|
|
77
|
-
* console.log(time.now()); // Prints the current timestamp, e.g. 1618608761000.
|
|
78
|
-
*/
|
|
79
|
-
_dayjs.default.now = Date.now;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Creates a Promise, which resolves after the given timeout.
|
|
83
|
-
* @param {number} timeout Timeout [ms].
|
|
84
|
-
* @return {Barrier} Resolves after the timeout. It has additional
|
|
85
|
-
* .abort() method attached, which cancels the pending timer resolution
|
|
86
|
-
* (without resolving or rejecting the barrier).
|
|
87
|
-
*/
|
|
88
|
-
async function timer(timeout) {
|
|
89
|
-
const res = new _Barrier.Barrier();
|
|
90
|
-
if (timeout > 0) {
|
|
91
|
-
const id = setTimeout(res.resolve.bind(res), timeout);
|
|
92
|
-
res.abort = () => clearTimeout(id);
|
|
93
|
-
} else {
|
|
94
|
-
res.abort = _lodash.noop;
|
|
95
|
-
res.resolve();
|
|
96
|
-
}
|
|
97
|
-
return res;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
18
|
/**
|
|
101
19
|
* This react hook wraps Date.now() function in a SSR friendly way,
|
|
102
20
|
* ensuring that all calls to useCurrent() within the same render return
|
|
@@ -180,9 +98,17 @@ function useTimezoneOffset({
|
|
|
180
98
|
}, [cookieName, setOffset]);
|
|
181
99
|
return offset;
|
|
182
100
|
}
|
|
183
|
-
_dayjs.default
|
|
184
|
-
|
|
185
|
-
|
|
101
|
+
(0, _lodash.assign)(_dayjs.default, {
|
|
102
|
+
DAY_MS: _jsUtils.DAY_MS,
|
|
103
|
+
HOUR_MS: _jsUtils.HOUR_MS,
|
|
104
|
+
MIN_MS: _jsUtils.MIN_MS,
|
|
105
|
+
SEC_MS: _jsUtils.SEC_MS,
|
|
106
|
+
YEAR_MS: _jsUtils.YEAR_MS,
|
|
107
|
+
now: Date.now,
|
|
108
|
+
timer: _jsUtils.timer,
|
|
109
|
+
useCurrent,
|
|
110
|
+
useTimezoneOffset
|
|
111
|
+
});
|
|
186
112
|
var _default = _dayjs.default;
|
|
187
113
|
exports.default = _default;
|
|
188
114
|
//# sourceMappingURL=time.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","names":["_cookie","_interopRequireDefault","require","_dayjs","_lodash","_react","
|
|
1
|
+
{"version":3,"file":"time.js","names":["_cookie","_interopRequireDefault","require","_dayjs","_lodash","_react","_jsUtils","_reactGlobalState","useCurrent","autorefresh","globalStatePath","precision","dayjs","SEC_MS","now","setter","useGlobalState","Date","useEffect","timerId","update","old","neu","Math","abs","setTimeout","clearTimeout","useTimezoneOffset","cookieName","ssrContext","getSsrContext","offset","setOffset","value","req","cookies","parseInt","date","getTimezoneOffset","document","cookie","Cookie","serialize","path","assign","DAY_MS","HOUR_MS","MIN_MS","YEAR_MS","timer","_default","exports","default"],"sources":["../../../../src/shared/utils/time.js"],"sourcesContent":["/* global document */\n\nimport Cookie from 'cookie';\nimport dayjs from 'dayjs';\nimport { assign } from 'lodash';\nimport { useEffect } from 'react';\n\nimport {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n timer,\n} from '@dr.pogodin/js-utils';\n\nimport { getSsrContext, useGlobalState } from '@dr.pogodin/react-global-state';\n\n/**\n * This react hook wraps Date.now() function in a SSR friendly way,\n * ensuring that all calls to useCurrent() within the same render return\n * exactly the same time (which is retrieved from Date.now() first, and\n * then stored in the global state to be reused in all other calls), which\n * is also passed and used in the first client side render, and then updated\n * with a finite precision to avoid infinite re-rendering loops.\n * @param {object} [options] Optional settings.\n * @param {string} [options.globalStatePath=\"currentTime\"] Global state path\n * to keep the current time value.\n * @param {number} [options.precision= 5 * time.SEC_MS] Current time precision.\n * The hook won't update the current time stored in the global state unless it\n * is different from Date.now() result by this number (in milliseconds).\n * Default to 5 seconds.\n * @param {boolean} [options.autorefresh=false] Set `true` to automatically\n * refresh time stored in the global state with the given `precision` (and\n * thus automatically re-rendering components dependent on this hook, or\n * the global state with the period equal to the `precision`.\n * @return {number} Unix timestamp in milliseconds.\n */\nexport function useCurrent({\n autorefresh = false,\n globalStatePath = 'currentTime',\n precision = 5 * dayjs.SEC_MS,\n} = {}) {\n const [now, setter] = useGlobalState(globalStatePath, Date.now);\n useEffect(() => {\n let timerId;\n const update = () => {\n setter((old) => {\n const neu = Date.now();\n return Math.abs(neu - old) > precision ? neu : old;\n });\n if (autorefresh) timerId = setTimeout(update, precision);\n };\n update();\n return () => {\n if (timerId) clearTimeout(timerId);\n };\n }, [autorefresh, precision, setter]);\n return now;\n}\n\n/**\n * Wraps the standard Date.getTimezoneOffset() method in a SSR-friendly way.\n * This hook retrieves the offset value at the client side and uses a cookie\n * to pass it to the server in subsequent requests from that user. At the server\n * side the value from cookie is used in renders and passed back to the client\n * via the global state. Prior to the value being known (in the very first\n * request from the user, when the cookie is still missing), zero value is used\n * as the default value.\n *\n * @param {object} [options] Optional settings.\n * @param {string} [options.cookieName=\"timezoneOffset\"] Optional. The name of\n * cookie to use to store the timezone offset. Defaults \"timezoneOffset\". Set\n * to a falsy value to forbid using cookies altogether (in that case the hook\n * will always return zero value at the server-side, and in the first render\n * at the client-side).\n * @param {string} [options.timezoneOffset=\"timezoneOffset\"] Optional.\n * The global state path to store the offset. Defaults \"timezoneOffset\".\n * @return {number} Timezone offset.\n */\nexport function useTimezoneOffset({\n cookieName = 'timezoneOffset',\n globalStatePath = 'timezoneOffset',\n} = {}) {\n const ssrContext = getSsrContext(false);\n const [offset, setOffset] = useGlobalState(globalStatePath, () => {\n const value = cookieName && ssrContext?.req?.cookies?.[cookieName];\n return value ? parseInt(value, 10) : 0;\n });\n useEffect(() => {\n const date = new Date();\n const value = date.getTimezoneOffset();\n setOffset(value);\n if (cookieName) {\n document.cookie = Cookie.serialize(cookieName, value, { path: '/' });\n }\n }, [cookieName, setOffset]);\n return offset;\n}\n\nassign(dayjs, {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n now: Date.now,\n timer,\n useCurrent,\n useTimezoneOffset,\n});\n\nexport default dayjs;\n"],"mappings":";;;;;;;;;AAEA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,QAAA,GAAAJ,OAAA;AASA,IAAAK,iBAAA,GAAAL,OAAA;AAhBA;;AAkBA;AACA;AACA;AACA;AAC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