@intlayer/react-intl 9.0.0-canary.1 → 9.0.0-canary.3
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.
|
@@ -10,15 +10,39 @@ let vite_intlayer = require("vite-intlayer");
|
|
|
10
10
|
|
|
11
11
|
//#region src/plugin/index.ts
|
|
12
12
|
/**
|
|
13
|
-
* Caller
|
|
13
|
+
* Caller configurations for react-intl's two message APIs.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* react-intl encodes both the dictionary key and the field path in a single
|
|
16
|
+
* dotted id string, so the `path-first-segment` namespace source extracts the
|
|
17
|
+
* first segment as the dictionary key and `translationFunction: 'self'` records
|
|
18
|
+
* the second segment as the consumed field:
|
|
19
|
+
*
|
|
20
|
+
* `'home.title'` → dictionaryKey='home', field='title'
|
|
21
|
+
* `'greeting'` → dictionaryKey='greeting', field='all' (single segment)
|
|
22
|
+
* dynamic id → unresolvable → skipped (all fields kept)
|
|
23
|
+
*
|
|
24
|
+
* Both call sites are tracked:
|
|
25
|
+
* - `intl.formatMessage({ id })` — matched as a method on any object.
|
|
26
|
+
* - `<FormattedMessage id />` — matched as a JSX element (import-gated).
|
|
27
|
+
*
|
|
28
|
+
* The JSX form is mandatory: the prune context is shared across all files, so
|
|
29
|
+
* tracking only `formatMessage` would let a field referenced solely from
|
|
30
|
+
* `<FormattedMessage>` be pruned away whenever the same dictionary is also read
|
|
31
|
+
* through `formatMessage`.
|
|
20
32
|
*/
|
|
21
|
-
const REACT_INTL_COMPAT_CALLERS = [
|
|
33
|
+
const REACT_INTL_COMPAT_CALLERS = [{
|
|
34
|
+
callerName: "formatMessage",
|
|
35
|
+
importSources: ["react-intl", "@intlayer/react-intl"],
|
|
36
|
+
matchAsMethod: true,
|
|
37
|
+
namespace: { from: "path-first-segment" },
|
|
38
|
+
translationFunction: "self"
|
|
39
|
+
}, {
|
|
40
|
+
callerName: "FormattedMessage",
|
|
41
|
+
importSources: ["react-intl", "@intlayer/react-intl"],
|
|
42
|
+
jsxIdAttribute: "id",
|
|
43
|
+
namespace: { from: "path-first-segment" },
|
|
44
|
+
translationFunction: "self"
|
|
45
|
+
}];
|
|
22
46
|
/**
|
|
23
47
|
* A Vite plugin for react-intl compat that wraps vite-intlayer
|
|
24
48
|
* and injects a resolve alias mapping `react-intl` to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["ANSIColors"],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { PluginOption } from 'vite';\nimport { type CompatCallerConfig, intlayer } from 'vite-intlayer';\n\n/**\n * Caller
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["ANSIColors"],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { PluginOption } from 'vite';\nimport { type CompatCallerConfig, intlayer } from 'vite-intlayer';\n\n/**\n * Caller configurations for react-intl's two message APIs.\n *\n * react-intl encodes both the dictionary key and the field path in a single\n * dotted id string, so the `path-first-segment` namespace source extracts the\n * first segment as the dictionary key and `translationFunction: 'self'` records\n * the second segment as the consumed field:\n *\n * `'home.title'` → dictionaryKey='home', field='title'\n * `'greeting'` → dictionaryKey='greeting', field='all' (single segment)\n * dynamic id → unresolvable → skipped (all fields kept)\n *\n * Both call sites are tracked:\n * - `intl.formatMessage({ id })` — matched as a method on any object.\n * - `<FormattedMessage id />` — matched as a JSX element (import-gated).\n *\n * The JSX form is mandatory: the prune context is shared across all files, so\n * tracking only `formatMessage` would let a field referenced solely from\n * `<FormattedMessage>` be pruned away whenever the same dictionary is also read\n * through `formatMessage`.\n */\nconst REACT_INTL_COMPAT_CALLERS: CompatCallerConfig[] = [\n {\n callerName: 'formatMessage',\n importSources: ['react-intl', '@intlayer/react-intl'],\n matchAsMethod: true,\n namespace: { from: 'path-first-segment' },\n translationFunction: 'self',\n },\n // `<FormattedMessage id=\"home.title\" />` — the dominant react-intl API. This\n // JSX form MUST be tracked alongside `formatMessage`: the prune context is\n // global across files, so a field referenced only from JSX would otherwise be\n // pruned away when the same dictionary is also read via `formatMessage`.\n {\n callerName: 'FormattedMessage',\n importSources: ['react-intl', '@intlayer/react-intl'],\n jsxIdAttribute: 'id',\n namespace: { from: 'path-first-segment' },\n translationFunction: 'self',\n },\n];\n\n/**\n * A Vite plugin for react-intl compat that wraps vite-intlayer\n * and injects a resolve alias mapping `react-intl` to\n * `@intlayer/react-intl`.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import reactIntlVitePlugin from '@intlayer/react-intl/plugin';\n *\n * export default defineConfig({\n * plugins: [reactIntlVitePlugin()],\n * });\n * ```\n */\nexport const reactIntlVitePlugin = (\n options?: Parameters<typeof intlayer>[0]\n): PluginOption[] => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const basePlugins = intlayer({\n ...options,\n compatCallers: [\n ...(options?.compatCallers ?? []),\n ...REACT_INTL_COMPAT_CALLERS,\n ],\n });\n\n const compatPlugin: PluginOption = {\n name: 'vite-react-intl-compat-plugin',\n config: () => ({\n resolve: {\n alias: {\n 'react-intl': '@intlayer/react-intl',\n },\n },\n }),\n };\n\n return [\n ...(Array.isArray(basePlugins) ? basePlugins : [basePlugins]),\n compatPlugin,\n ];\n};\n\nexport default reactIntlVitePlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAM,4BAAkD,CACtD;CACE,YAAY;CACZ,eAAe,CAAC,cAAc,sBAAsB;CACpD,eAAe;CACf,WAAW,EAAE,MAAM,qBAAqB;CACxC,qBAAqB;AACvB,GAKA;CACE,YAAY;CACZ,eAAe,CAAC,cAAc,sBAAsB;CACpD,gBAAgB;CAChB,WAAW,EAAE,MAAM,qBAAqB;CACxC,qBAAqB;AACvB,CACF;;;;;;;;;;;;;;;;AAiBA,MAAa,uBACX,YACmB;CACnB,MAAM,6DAAkC;CACxC,MAAM,sDAAyB,cAAc;CAE7C,0DAEI,eAAe,OAAO,SACtB,aACA,SACA,iCACF,SACM;EACJ,UAAU,uCAEN,+CACAA,wBAAW,IACb,yCAEE,iDACAA,wBAAW,UACb,CACF,CAAC;CACH,GACA,EACE,gBAAgB,MAAO,KAAK,GAC9B,CACF;CAEA,MAAM,0CAAuB;EAC3B,GAAG;EACH,eAAe,CACb,GAAI,SAAS,iBAAiB,CAAC,GAC/B,GAAG,yBACL;CACF,CAAC;CAED,MAAM,eAA6B;EACjC,MAAM;EACN,eAAe,EACb,SAAS,EACP,OAAO,EACL,cAAc,uBAChB,EACF,EACF;CACF;CAEA,OAAO,CACL,GAAI,MAAM,QAAQ,WAAW,IAAI,cAAc,CAAC,WAAW,GAC3D,YACF;AACF"}
|
|
@@ -7,15 +7,39 @@ import { intlayer } from "vite-intlayer";
|
|
|
7
7
|
|
|
8
8
|
//#region src/plugin/index.ts
|
|
9
9
|
/**
|
|
10
|
-
* Caller
|
|
10
|
+
* Caller configurations for react-intl's two message APIs.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* react-intl encodes both the dictionary key and the field path in a single
|
|
13
|
+
* dotted id string, so the `path-first-segment` namespace source extracts the
|
|
14
|
+
* first segment as the dictionary key and `translationFunction: 'self'` records
|
|
15
|
+
* the second segment as the consumed field:
|
|
16
|
+
*
|
|
17
|
+
* `'home.title'` → dictionaryKey='home', field='title'
|
|
18
|
+
* `'greeting'` → dictionaryKey='greeting', field='all' (single segment)
|
|
19
|
+
* dynamic id → unresolvable → skipped (all fields kept)
|
|
20
|
+
*
|
|
21
|
+
* Both call sites are tracked:
|
|
22
|
+
* - `intl.formatMessage({ id })` — matched as a method on any object.
|
|
23
|
+
* - `<FormattedMessage id />` — matched as a JSX element (import-gated).
|
|
24
|
+
*
|
|
25
|
+
* The JSX form is mandatory: the prune context is shared across all files, so
|
|
26
|
+
* tracking only `formatMessage` would let a field referenced solely from
|
|
27
|
+
* `<FormattedMessage>` be pruned away whenever the same dictionary is also read
|
|
28
|
+
* through `formatMessage`.
|
|
17
29
|
*/
|
|
18
|
-
const REACT_INTL_COMPAT_CALLERS = [
|
|
30
|
+
const REACT_INTL_COMPAT_CALLERS = [{
|
|
31
|
+
callerName: "formatMessage",
|
|
32
|
+
importSources: ["react-intl", "@intlayer/react-intl"],
|
|
33
|
+
matchAsMethod: true,
|
|
34
|
+
namespace: { from: "path-first-segment" },
|
|
35
|
+
translationFunction: "self"
|
|
36
|
+
}, {
|
|
37
|
+
callerName: "FormattedMessage",
|
|
38
|
+
importSources: ["react-intl", "@intlayer/react-intl"],
|
|
39
|
+
jsxIdAttribute: "id",
|
|
40
|
+
namespace: { from: "path-first-segment" },
|
|
41
|
+
translationFunction: "self"
|
|
42
|
+
}];
|
|
19
43
|
/**
|
|
20
44
|
* A Vite plugin for react-intl compat that wraps vite-intlayer
|
|
21
45
|
* and injects a resolve alias mapping `react-intl` to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { PluginOption } from 'vite';\nimport { type CompatCallerConfig, intlayer } from 'vite-intlayer';\n\n/**\n * Caller
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { PluginOption } from 'vite';\nimport { type CompatCallerConfig, intlayer } from 'vite-intlayer';\n\n/**\n * Caller configurations for react-intl's two message APIs.\n *\n * react-intl encodes both the dictionary key and the field path in a single\n * dotted id string, so the `path-first-segment` namespace source extracts the\n * first segment as the dictionary key and `translationFunction: 'self'` records\n * the second segment as the consumed field:\n *\n * `'home.title'` → dictionaryKey='home', field='title'\n * `'greeting'` → dictionaryKey='greeting', field='all' (single segment)\n * dynamic id → unresolvable → skipped (all fields kept)\n *\n * Both call sites are tracked:\n * - `intl.formatMessage({ id })` — matched as a method on any object.\n * - `<FormattedMessage id />` — matched as a JSX element (import-gated).\n *\n * The JSX form is mandatory: the prune context is shared across all files, so\n * tracking only `formatMessage` would let a field referenced solely from\n * `<FormattedMessage>` be pruned away whenever the same dictionary is also read\n * through `formatMessage`.\n */\nconst REACT_INTL_COMPAT_CALLERS: CompatCallerConfig[] = [\n {\n callerName: 'formatMessage',\n importSources: ['react-intl', '@intlayer/react-intl'],\n matchAsMethod: true,\n namespace: { from: 'path-first-segment' },\n translationFunction: 'self',\n },\n // `<FormattedMessage id=\"home.title\" />` — the dominant react-intl API. This\n // JSX form MUST be tracked alongside `formatMessage`: the prune context is\n // global across files, so a field referenced only from JSX would otherwise be\n // pruned away when the same dictionary is also read via `formatMessage`.\n {\n callerName: 'FormattedMessage',\n importSources: ['react-intl', '@intlayer/react-intl'],\n jsxIdAttribute: 'id',\n namespace: { from: 'path-first-segment' },\n translationFunction: 'self',\n },\n];\n\n/**\n * A Vite plugin for react-intl compat that wraps vite-intlayer\n * and injects a resolve alias mapping `react-intl` to\n * `@intlayer/react-intl`.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import reactIntlVitePlugin from '@intlayer/react-intl/plugin';\n *\n * export default defineConfig({\n * plugins: [reactIntlVitePlugin()],\n * });\n * ```\n */\nexport const reactIntlVitePlugin = (\n options?: Parameters<typeof intlayer>[0]\n): PluginOption[] => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig.system.baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const basePlugins = intlayer({\n ...options,\n compatCallers: [\n ...(options?.compatCallers ?? []),\n ...REACT_INTL_COMPAT_CALLERS,\n ],\n });\n\n const compatPlugin: PluginOption = {\n name: 'vite-react-intl-compat-plugin',\n config: () => ({\n resolve: {\n alias: {\n 'react-intl': '@intlayer/react-intl',\n },\n },\n }),\n };\n\n return [\n ...(Array.isArray(basePlugins) ? basePlugins : [basePlugins]),\n compatPlugin,\n ];\n};\n\nexport default reactIntlVitePlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAM,4BAAkD,CACtD;CACE,YAAY;CACZ,eAAe,CAAC,cAAc,sBAAsB;CACpD,eAAe;CACf,WAAW,EAAE,MAAM,qBAAqB;CACxC,qBAAqB;AACvB,GAKA;CACE,YAAY;CACZ,eAAe,CAAC,cAAc,sBAAsB;CACpD,gBAAgB;CAChB,WAAW,EAAE,MAAM,qBAAqB;CACxC,qBAAqB;AACvB,CACF;;;;;;;;;;;;;;;;AAiBA,MAAa,uBACX,YACmB;CACnB,MAAM,iBAAiB,iBAAiB;CACxC,MAAM,YAAY,aAAa,cAAc;CAE7C,QACE,KACE,eAAe,OAAO,SACtB,aACA,SACA,iCACF,SACM;EACJ,UAAU,CACR,SACE,+CACA,WAAW,IACb,GACA,SACE,iDACA,WAAW,UACb,CACF,CAAC;CACH,GACA,EACE,gBAAgB,MAAO,KAAK,GAC9B,CACF;CAEA,MAAM,cAAc,SAAS;EAC3B,GAAG;EACH,eAAe,CACb,GAAI,SAAS,iBAAiB,CAAC,GAC/B,GAAG,yBACL;CACF,CAAC;CAED,MAAM,eAA6B;EACjC,MAAM;EACN,eAAe,EACb,SAAS,EACP,OAAO,EACL,cAAc,uBAChB,EACF,EACF;CACF;CAEA,OAAO,CACL,GAAI,MAAM,QAAQ,WAAW,IAAI,cAAc,CAAC,WAAW,GAC3D,YACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugin/index.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugin/index.ts"],"mappings":";;;;;;AAiEA;;;;;;;;;;;;;cAAa,mBAAA,GACX,OAAA,GAAU,UAAA,QAAkB,QAAA,SAC3B,YAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/react-intl",
|
|
3
|
-
"version": "9.0.0-canary.
|
|
3
|
+
"version": "9.0.0-canary.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "react-intl API adapter for intlayer — drop-in compatibility layer",
|
|
6
6
|
"keywords": [
|
|
@@ -76,13 +76,13 @@
|
|
|
76
76
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@intlayer/chokidar": "9.0.0-canary.
|
|
80
|
-
"@intlayer/config": "9.0.0-canary.
|
|
81
|
-
"@intlayer/core": "9.0.0-canary.
|
|
82
|
-
"@intlayer/dictionaries-entry": "9.0.0-canary.
|
|
83
|
-
"@intlayer/types": "9.0.0-canary.
|
|
84
|
-
"react-intlayer": "9.0.0-canary.
|
|
85
|
-
"vite-intlayer": "9.0.0-canary.
|
|
79
|
+
"@intlayer/chokidar": "9.0.0-canary.3",
|
|
80
|
+
"@intlayer/config": "9.0.0-canary.3",
|
|
81
|
+
"@intlayer/core": "9.0.0-canary.3",
|
|
82
|
+
"@intlayer/dictionaries-entry": "9.0.0-canary.3",
|
|
83
|
+
"@intlayer/types": "9.0.0-canary.3",
|
|
84
|
+
"react-intlayer": "9.0.0-canary.3",
|
|
85
|
+
"vite-intlayer": "9.0.0-canary.3"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@types/node": "25.9.3",
|