startupjs 0.61.14 → 0.62.0-alpha.0

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/index.js CHANGED
@@ -9,6 +9,33 @@ export * from '@startupjs/hooks'
9
9
  // on the server and on the client
10
10
  export * from '@startupjs/isomorphic-helpers'
11
11
 
12
+ let compatT
13
+
14
+ // COMPAT-ONLY legacy i18n bridge for older LMS code which still imports `t`
15
+ // from the root `startupjs` package. The host app must explicitly register the
16
+ // real translation function via `__setCompatT()`. This mirrors the explicit
17
+ // compat initialization pattern already used for `startupjs/app`.
18
+ export function __setCompatT (fn) {
19
+ if (typeof fn !== 'function') {
20
+ throw new Error('[startupjs] __setCompatT expects a function')
21
+ }
22
+ compatT = fn
23
+ }
24
+
25
+ export function __resetCompatTForTests () {
26
+ compatT = undefined
27
+ }
28
+
29
+ export function t (...args) {
30
+ if (typeof compatT !== 'function') {
31
+ throw new Error(
32
+ '[startupjs] t is not initialized. ' +
33
+ 'The host app must register a compat implementation via __setCompatT().'
34
+ )
35
+ }
36
+ return compatT(...args)
37
+ }
38
+
12
39
  // wrap serverOnly around the value to remove it from the client bundle
13
40
  // (it will be replaced with `undefined` on the client by the babel-plugin-eliminator)
14
41
  export function serverOnly (value) { return value }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "startupjs",
3
3
  "type": "module",
4
- "version": "0.61.14",
4
+ "version": "0.62.0-alpha.0",
5
5
  "engines": {
6
6
  "node": ">= 14"
7
7
  },
@@ -31,18 +31,18 @@
31
31
  "bin": "./cli.js",
32
32
  "license": "MIT",
33
33
  "dependencies": {
34
- "@startupjs/auth": "^0.61.2",
35
- "@startupjs/bundler": "^0.61.7",
36
- "@startupjs/cli": "^0.61.11",
37
- "@startupjs/hooks": "^0.61.0",
38
- "@startupjs/isomorphic-helpers": "^0.61.0",
39
- "@startupjs/registry": "^0.61.0",
40
- "@startupjs/server": "^0.61.0",
41
- "@startupjs/utils": "^0.61.0",
42
- "babel-preset-startupjs": "^0.61.3",
43
- "cssxjs": "^0.2.32",
34
+ "@startupjs/auth": "^0.62.0-alpha.0",
35
+ "@startupjs/bundler": "^0.62.0-alpha.0",
36
+ "@startupjs/cli": "^0.62.0-alpha.0",
37
+ "@startupjs/hooks": "^0.62.0-alpha.0",
38
+ "@startupjs/isomorphic-helpers": "^0.62.0-alpha.0",
39
+ "@startupjs/registry": "^0.62.0-alpha.0",
40
+ "@startupjs/server": "^0.62.0-alpha.0",
41
+ "@startupjs/utils": "^0.62.0-alpha.0",
42
+ "babel-preset-startupjs": "^0.62.0-alpha.0",
43
+ "cssxjs": "^0.3.0-alpha.1",
44
44
  "lodash": "^4.17.20",
45
- "teamplay": "0.3.35"
45
+ "teamplay": "^0.4.0-alpha.64"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@startupjs/worker": "*",
@@ -60,5 +60,5 @@
60
60
  "scripts": {
61
61
  "test": "node --experimental-specifier-resolution=node --test"
62
62
  },
63
- "gitHead": "673f1b736954d8fcf15fb7d43b6b757a710a004a"
63
+ "gitHead": "bb6cf80cd815fcc068d470dbf38a507c3bfa466a"
64
64
  }
package/startWorker.js CHANGED
@@ -1,2 +1,3 @@
1
- import startWorker from '@startupjs/worker'
2
- await startWorker()
1
+ import initWorker from '@startupjs/worker/init'
2
+
3
+ await initWorker()
@@ -3,7 +3,17 @@ import { renderToStaticMarkup } from 'react-dom/server'
3
3
  import test from 'node:test'
4
4
  import assert from 'node:assert/strict'
5
5
 
6
- import { useBackPress, useComponentId } from '../index.js'
6
+ import {
7
+ __resetCompatTForTests,
8
+ __setCompatT,
9
+ t,
10
+ useBackPress,
11
+ useComponentId
12
+ } from '../index.js'
13
+
14
+ test.afterEach(() => {
15
+ __resetCompatTForTests()
16
+ })
7
17
 
8
18
  test('useBackPress compat hook is defined and is a no-op', () => {
9
19
  function Probe () {
@@ -33,3 +43,20 @@ test('useComponentId returns a stable id within the same render pass', () => {
33
43
  assert.notEqual(firstId, '')
34
44
  assert.notEqual(secondId, '')
35
45
  })
46
+
47
+ test('t throws a clear error until compat implementation is registered', () => {
48
+ assert.throws(
49
+ () => t('example', 'Fallback'),
50
+ /t is not initialized/
51
+ )
52
+ })
53
+
54
+ test('t delegates to registered compat implementation', () => {
55
+ __setCompatT((key, defaultValue) => {
56
+ if (key === 'example') return 'Translated'
57
+ return defaultValue
58
+ })
59
+
60
+ assert.equal(t('example', 'Fallback'), 'Translated')
61
+ assert.equal(t('missing', 'Fallback'), 'Fallback')
62
+ })