astro-intlayer 9.5.4 → 9.5.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.
- package/README.md +2 -2
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +28 -0
- package/dist/cjs/client/format/index.cjs +57 -0
- package/dist/cjs/client/index.cjs +81 -0
- package/dist/cjs/client/localeRedirect.cjs +64 -0
- package/dist/cjs/client/localeRedirect.cjs.map +1 -0
- package/dist/cjs/format/index.cjs +20 -0
- package/dist/cjs/format/useCompact.cjs +18 -0
- package/dist/cjs/format/useCompact.cjs.map +1 -0
- package/dist/cjs/format/useCurrency.cjs +18 -0
- package/dist/cjs/format/useCurrency.cjs.map +1 -0
- package/dist/cjs/format/useDate.cjs +27 -0
- package/dist/cjs/format/useDate.cjs.map +1 -0
- package/dist/cjs/format/useIntl.cjs +24 -0
- package/dist/cjs/format/useIntl.cjs.map +1 -0
- package/dist/cjs/format/useList.cjs +18 -0
- package/dist/cjs/format/useList.cjs.map +1 -0
- package/dist/cjs/format/useNumber.cjs +21 -0
- package/dist/cjs/format/useNumber.cjs.map +1 -0
- package/dist/cjs/format/usePercentage.cjs +18 -0
- package/dist/cjs/format/usePercentage.cjs.map +1 -0
- package/dist/cjs/format/useRelativeTime.cjs +18 -0
- package/dist/cjs/format/useRelativeTime.cjs.map +1 -0
- package/dist/cjs/format/useUnit.cjs +18 -0
- package/dist/cjs/format/useUnit.cjs.map +1 -0
- package/dist/cjs/html/index.cjs +33 -0
- package/dist/cjs/index.cjs +33 -35
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/integration.cjs +77 -0
- package/dist/cjs/integration.cjs.map +1 -0
- package/dist/cjs/markdown/index.cjs +45 -0
- package/dist/cjs/middleware.cjs +103 -0
- package/dist/cjs/middleware.cjs.map +1 -0
- package/dist/cjs/requestStorage.cjs +24 -0
- package/dist/cjs/requestStorage.cjs.map +1 -0
- package/dist/cjs/useDictionary.cjs +38 -0
- package/dist/cjs/useDictionary.cjs.map +1 -0
- package/dist/cjs/useIntlayer.cjs +38 -0
- package/dist/cjs/useIntlayer.cjs.map +1 -0
- package/dist/cjs/useLocale.cjs +41 -0
- package/dist/cjs/useLocale.cjs.map +1 -0
- package/dist/cjs/withInertOnChange.cjs +17 -0
- package/dist/cjs/withInertOnChange.cjs.map +1 -0
- package/dist/esm/client/format/index.mjs +3 -0
- package/dist/esm/client/index.mjs +3 -0
- package/dist/esm/client/localeRedirect.mjs +62 -0
- package/dist/esm/client/localeRedirect.mjs.map +1 -0
- package/dist/esm/format/index.mjs +11 -0
- package/dist/esm/format/useCompact.mjs +17 -0
- package/dist/esm/format/useCompact.mjs.map +1 -0
- package/dist/esm/format/useCurrency.mjs +17 -0
- package/dist/esm/format/useCurrency.mjs.map +1 -0
- package/dist/esm/format/useDate.mjs +26 -0
- package/dist/esm/format/useDate.mjs.map +1 -0
- package/dist/esm/format/useIntl.mjs +23 -0
- package/dist/esm/format/useIntl.mjs.map +1 -0
- package/dist/esm/format/useList.mjs +17 -0
- package/dist/esm/format/useList.mjs.map +1 -0
- package/dist/esm/format/useNumber.mjs +20 -0
- package/dist/esm/format/useNumber.mjs.map +1 -0
- package/dist/esm/format/usePercentage.mjs +17 -0
- package/dist/esm/format/usePercentage.mjs.map +1 -0
- package/dist/esm/format/useRelativeTime.mjs +17 -0
- package/dist/esm/format/useRelativeTime.mjs.map +1 -0
- package/dist/esm/format/useUnit.mjs +17 -0
- package/dist/esm/format/useUnit.mjs.map +1 -0
- package/dist/esm/html/index.mjs +3 -0
- package/dist/esm/index.mjs +30 -36
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/integration.mjs +75 -0
- package/dist/esm/integration.mjs.map +1 -0
- package/dist/esm/markdown/index.mjs +3 -0
- package/dist/esm/middleware.mjs +100 -0
- package/dist/esm/middleware.mjs.map +1 -0
- package/dist/esm/requestStorage.mjs +21 -0
- package/dist/esm/requestStorage.mjs.map +1 -0
- package/dist/esm/useDictionary.mjs +37 -0
- package/dist/esm/useDictionary.mjs.map +1 -0
- package/dist/esm/useIntlayer.mjs +37 -0
- package/dist/esm/useIntlayer.mjs.map +1 -0
- package/dist/esm/useLocale.mjs +40 -0
- package/dist/esm/useLocale.mjs.map +1 -0
- package/dist/esm/withInertOnChange.mjs +16 -0
- package/dist/esm/withInertOnChange.mjs.map +1 -0
- package/dist/types/client/format/index.d.ts +2 -0
- package/dist/types/client/index.d.ts +2 -0
- package/dist/types/client/localeRedirect.d.ts +26 -0
- package/dist/types/client/localeRedirect.d.ts.map +1 -0
- package/dist/types/format/index.d.ts +10 -0
- package/dist/types/format/useCompact.d.ts +5 -0
- package/dist/types/format/useCompact.d.ts.map +1 -0
- package/dist/types/format/useCurrency.d.ts +5 -0
- package/dist/types/format/useCurrency.d.ts.map +1 -0
- package/dist/types/format/useDate.d.ts +8 -0
- package/dist/types/format/useDate.d.ts.map +1 -0
- package/dist/types/format/useIntl.d.ts +15 -0
- package/dist/types/format/useIntl.d.ts.map +1 -0
- package/dist/types/format/useList.d.ts +5 -0
- package/dist/types/format/useList.d.ts.map +1 -0
- package/dist/types/format/useNumber.d.ts +8 -0
- package/dist/types/format/useNumber.d.ts.map +1 -0
- package/dist/types/format/usePercentage.d.ts +5 -0
- package/dist/types/format/usePercentage.d.ts.map +1 -0
- package/dist/types/format/useRelativeTime.d.ts +5 -0
- package/dist/types/format/useRelativeTime.d.ts.map +1 -0
- package/dist/types/format/useUnit.d.ts +5 -0
- package/dist/types/format/useUnit.d.ts.map +1 -0
- package/dist/types/html/index.d.ts +2 -0
- package/dist/types/index.d.ts +13 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/integration.d.ts +41 -0
- package/dist/types/integration.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +2 -0
- package/dist/types/middleware.d.ts +54 -0
- package/dist/types/middleware.d.ts.map +1 -0
- package/dist/types/requestStorage.d.ts +22 -0
- package/dist/types/requestStorage.d.ts.map +1 -0
- package/dist/types/useDictionary.d.ts +29 -0
- package/dist/types/useDictionary.d.ts.map +1 -0
- package/dist/types/useIntlayer.d.ts +28 -0
- package/dist/types/useIntlayer.d.ts.map +1 -0
- package/dist/types/useLocale.d.ts +29 -0
- package/dist/types/useLocale.d.ts.map +1 -0
- package/dist/types/withInertOnChange.d.ts +12 -0
- package/dist/types/withInertOnChange.d.ts.map +1 -0
- package/package.json +96 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let _intlayer_engine_build = require("@intlayer/engine/build");
|
|
7
|
-
let vite_intlayer = require("vite-intlayer");
|
|
2
|
+
const require_requestStorage = require('./requestStorage.cjs');
|
|
3
|
+
const require_useDictionary = require('./useDictionary.cjs');
|
|
4
|
+
const require_useIntlayer = require('./useIntlayer.cjs');
|
|
5
|
+
const require_useLocale = require('./useLocale.cjs');
|
|
8
6
|
|
|
9
7
|
//#region src/index.ts
|
|
10
8
|
/**
|
|
11
|
-
*
|
|
12
|
-
* Vite environment Astro renders from.
|
|
9
|
+
* Package self-reference to the Node-only half of the integration.
|
|
13
10
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
11
|
+
* Kept in a variable so the `import()` below is not statically analyzable:
|
|
12
|
+
* Astro bundles this package into the server build (`ssr.noExternal`), and a
|
|
13
|
+
* literal specifier would make the bundler follow it into `vite-intlayer`,
|
|
14
|
+
* `@intlayer/engine` and the framework compilers — which have no business in
|
|
15
|
+
* the server build, and do not even bundle (`velocityjs`, …). Left alone, the
|
|
16
|
+
* import only runs from `astro.config`, in Node.
|
|
17
17
|
*/
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const integrationSpecifier = "astro-intlayer/integration";
|
|
19
|
+
const loadIntegration = () => import(
|
|
20
|
+
/* @vite-ignore */
|
|
21
|
+
integrationSpecifier
|
|
22
|
+
);
|
|
22
23
|
/**
|
|
23
24
|
* Astro integration for Intlayer.
|
|
24
25
|
*
|
|
@@ -26,12 +27,14 @@ const intlayerNoExternalEnvironments = () => ({
|
|
|
26
27
|
* 1. Preparing Intlayer resources (dictionaries) at config setup.
|
|
27
28
|
* 2. Injecting Vite plugins for aliases, locale-based routing (middleware), and build optimizations (prune).
|
|
28
29
|
* 3. Configuring Vite aliases for dictionary access.
|
|
29
|
-
* 4.
|
|
30
|
+
* 4. Registering the `astro-intlayer/middleware`, which resolves the request
|
|
31
|
+
* locale into `Astro.locals.intlayer` for the `useLocale` / `useIntlayer` /
|
|
32
|
+
* `useDictionary` hooks of this package.
|
|
33
|
+
* 5. Emitting the prerendered pages at their rewritten (localized) URLs.
|
|
30
34
|
*
|
|
31
|
-
* The
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* content edit twice.
|
|
35
|
+
* The implementation is loaded lazily: this entry is also the one pages import
|
|
36
|
+
* their hooks from, and it must not drag the Node-only tooling into their
|
|
37
|
+
* server bundle.
|
|
35
38
|
*
|
|
36
39
|
* @returns An Astro integration object.
|
|
37
40
|
*
|
|
@@ -49,22 +52,13 @@ const intlayerNoExternalEnvironments = () => ({
|
|
|
49
52
|
const intlayer = () => ({
|
|
50
53
|
name: "astro-intlayer",
|
|
51
54
|
hooks: {
|
|
52
|
-
"astro:config:setup": async (
|
|
53
|
-
const
|
|
54
|
-
await (
|
|
55
|
-
updateConfig({ vite: {
|
|
56
|
-
plugins: [(0, vite_intlayer.intlayer)(), intlayerNoExternalEnvironments()],
|
|
57
|
-
resolve: { alias: { ...(0, _intlayer_config_utils.getAlias)({
|
|
58
|
-
configuration,
|
|
59
|
-
formatter: (value) => (0, node_path.resolve)(value)
|
|
60
|
-
}) } },
|
|
61
|
-
ssr: { noExternal: [vite_intlayer.INTLAYER_NO_EXTERNAL_PATTERN] }
|
|
62
|
-
} });
|
|
55
|
+
"astro:config:setup": async (options) => {
|
|
56
|
+
const { configSetup } = await loadIntegration();
|
|
57
|
+
await configSetup(options);
|
|
63
58
|
},
|
|
64
|
-
"astro:build:done": async (
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
if (emittedPages.length > 0) logger.info(`Emitted ${emittedPages.length} rewritten page(s): ${emittedPages.map(([from, to]) => `${from} \u2192 ${to}`).join(", ")}`);
|
|
59
|
+
"astro:build:done": async (options) => {
|
|
60
|
+
const { buildDone } = await loadIntegration();
|
|
61
|
+
await buildDone(options);
|
|
68
62
|
}
|
|
69
63
|
}
|
|
70
64
|
});
|
|
@@ -72,4 +66,8 @@ const intlayer = () => ({
|
|
|
72
66
|
//#endregion
|
|
73
67
|
exports.default = intlayer;
|
|
74
68
|
exports.intlayer = intlayer;
|
|
69
|
+
exports.getIntlayerLocals = require_requestStorage.getIntlayerLocals;
|
|
70
|
+
exports.useDictionary = require_useDictionary.useDictionary;
|
|
71
|
+
exports.useIntlayer = require_useIntlayer.useIntlayer;
|
|
72
|
+
exports.useLocale = require_useLocale.useLocale;
|
|
75
73
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import type { AstroIntegration } from 'astro';\n\nexport type { IntlayerLocals } from './middleware';\nexport { getIntlayerLocals } from './requestStorage';\nexport { useDictionary } from './useDictionary';\nexport { useIntlayer } from './useIntlayer';\nexport type { UseLocaleProps, UseLocaleResult } from './useLocale';\nexport { useLocale } from './useLocale';\n\n/**\n * Package self-reference to the Node-only half of the integration.\n *\n * Kept in a variable so the `import()` below is not statically analyzable:\n * Astro bundles this package into the server build (`ssr.noExternal`), and a\n * literal specifier would make the bundler follow it into `vite-intlayer`,\n * `@intlayer/engine` and the framework compilers — which have no business in\n * the server build, and do not even bundle (`velocityjs`, …). Left alone, the\n * import only runs from `astro.config`, in Node.\n */\nconst integrationSpecifier = 'astro-intlayer/integration';\n\nconst loadIntegration = (): Promise<typeof import('./integration')> =>\n import(/* @vite-ignore */ integrationSpecifier);\n\n/**\n * Astro integration for Intlayer.\n *\n * It handles:\n * 1. Preparing Intlayer resources (dictionaries) at config setup.\n * 2. Injecting Vite plugins for aliases, locale-based routing (middleware), and build optimizations (prune).\n * 3. Configuring Vite aliases for dictionary access.\n * 4. Registering the `astro-intlayer/middleware`, which resolves the request\n * locale into `Astro.locals.intlayer` for the `useLocale` / `useIntlayer` /\n * `useDictionary` hooks of this package.\n * 5. Emitting the prerendered pages at their rewritten (localized) URLs.\n *\n * The implementation is loaded lazily: this entry is also the one pages import\n * their hooks from, and it must not drag the Node-only tooling into their\n * server bundle.\n *\n * @returns An Astro integration object.\n *\n * @example\n * ```ts\n * // astro.config.mjs\n * import { defineConfig } from 'astro/config';\n * import { intlayer } from 'astro-intlayer';\n *\n * export default defineConfig({\n * integrations: [intlayer()],\n * });\n * ```\n */\nexport const intlayer = (): AstroIntegration =>\n ({\n name: 'astro-intlayer',\n hooks: {\n 'astro:config:setup': async (options) => {\n const { configSetup } = await loadIntegration();\n\n await configSetup(options);\n },\n 'astro:build:done': async (options) => {\n const { buildDone } = await loadIntegration();\n\n await buildDone(options);\n },\n },\n }) satisfies AstroIntegration;\n\n/**\n * Alias of {@link intlayer}, kept so `astro add astro-intlayer` works.\n *\n * Astro's CLI codemod always writes a default import\n * (`import intlayer from 'astro-intlayer'`) without checking what the package\n * exports, so the integration has to be reachable that way too. The named\n * export stays the documented one.\n */\nexport default intlayer;\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,MAAM,uBAAuB;AAE7B,MAAM,wBACJ;;CAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+B5B,MAAa,kBACV;CACC,MAAM;CACN,OAAO;EACL,sBAAsB,OAAO,YAAY;GACvC,MAAM,EAAE,gBAAgB,MAAM,gBAAgB;GAE9C,MAAM,YAAY,OAAO;EAC3B;EACA,oBAAoB,OAAO,YAAY;GACrC,MAAM,EAAE,cAAc,MAAM,gBAAgB;GAE5C,MAAM,UAAU,OAAO;EACzB;CACF;AACF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_emitRewrittenPages = require('./emitRewrittenPages.cjs');
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
5
|
+
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
6
|
+
let _intlayer_config_node = require("@intlayer/config/node");
|
|
7
|
+
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
8
|
+
let _intlayer_engine_build = require("@intlayer/engine/build");
|
|
9
|
+
let vite_intlayer = require("vite-intlayer");
|
|
10
|
+
|
|
11
|
+
//#region src/integration.ts
|
|
12
|
+
/**
|
|
13
|
+
* Keeps the intlayer packages out of Node's native module loader in *every*
|
|
14
|
+
* Vite environment Astro renders from.
|
|
15
|
+
*
|
|
16
|
+
* A static dev server renders from `ssr`, but other setups render from Astro's
|
|
17
|
+
* `astro` or `prerender` environments, and a top-level `ssr.noExternal` only
|
|
18
|
+
* seeds the `ssr` one. Declaring it per environment covers the rest.
|
|
19
|
+
*/
|
|
20
|
+
const intlayerNoExternalEnvironments = () => ({
|
|
21
|
+
name: "astro-intlayer-no-external",
|
|
22
|
+
configEnvironment: () => ({ resolve: { noExternal: [vite_intlayer.INTLAYER_NO_EXTERNAL_PATTERN] } })
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* `astro:config:setup`:
|
|
26
|
+
* 1. Prepares the Intlayer resources (dictionaries).
|
|
27
|
+
* 2. Injects the Vite plugins for aliases, locale-based routing and build
|
|
28
|
+
* optimizations (prune).
|
|
29
|
+
* 3. Configures the Vite aliases for dictionary access.
|
|
30
|
+
* 4. Registers the `astro-intlayer/middleware`, which resolves the request
|
|
31
|
+
* locale into `Astro.locals.intlayer` for the hooks and redirects
|
|
32
|
+
* server-rendered requests to the visitor's locale.
|
|
33
|
+
* 5. Injects the client-side locale redirect, which does the same for
|
|
34
|
+
* prerendered pages: served as static files, nothing else can read the
|
|
35
|
+
* stored locale there.
|
|
36
|
+
*
|
|
37
|
+
* The dev-time content watcher is not started here: the bundled
|
|
38
|
+
* `vite-intlayer` plugin already starts one from `configureServer`, and
|
|
39
|
+
* `watch()` subscribes anew on every call, so doing both would rebuild each
|
|
40
|
+
* content edit twice.
|
|
41
|
+
*/
|
|
42
|
+
const configSetup = async ({ command, updateConfig, addMiddleware, injectScript }) => {
|
|
43
|
+
const configuration = (0, _intlayer_config_node.getConfiguration)();
|
|
44
|
+
await (0, _intlayer_engine_build.prepareIntlayer)(configuration);
|
|
45
|
+
addMiddleware({
|
|
46
|
+
entrypoint: "astro-intlayer/middleware",
|
|
47
|
+
order: "pre"
|
|
48
|
+
});
|
|
49
|
+
if ((0, _intlayer_core_localization.resolveProxyMode)(configuration.routing.enableProxy) !== "disabled") {
|
|
50
|
+
injectScript("page", `import { redirectToStoredLocale } from 'astro-intlayer/client/locale-redirect';\nredirectToStoredLocale();`);
|
|
51
|
+
if (command === "preview") (0, _intlayer_config_logger.getAppLogger)(configuration)((0, _intlayer_core_localization.formatProxyEnabledMessage)(false), { level: "info" });
|
|
52
|
+
}
|
|
53
|
+
updateConfig({ vite: {
|
|
54
|
+
plugins: [(0, vite_intlayer.intlayer)(), intlayerNoExternalEnvironments()],
|
|
55
|
+
resolve: { alias: { ...(0, _intlayer_config_utils.getAlias)({
|
|
56
|
+
configuration,
|
|
57
|
+
formatter: (value) => (0, node_path.resolve)(value)
|
|
58
|
+
}) } },
|
|
59
|
+
ssr: { noExternal: [vite_intlayer.INTLAYER_NO_EXTERNAL_PATTERN] }
|
|
60
|
+
} });
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* `astro:build:done`: Astro renders each page from its canonical file-system
|
|
64
|
+
* route, so a static build has no file for the localized paths declared in
|
|
65
|
+
* `routing.rewrite`. Mirror them here, otherwise the URLs produced by
|
|
66
|
+
* `getLocalizedUrl` (links, hreflang, sitemap) 404 once deployed.
|
|
67
|
+
*/
|
|
68
|
+
const buildDone = async ({ dir, logger }) => {
|
|
69
|
+
const configuration = (0, _intlayer_config_node.getConfiguration)();
|
|
70
|
+
const emittedPages = await require_emitRewrittenPages.emitRewrittenPages(configuration, dir);
|
|
71
|
+
if (emittedPages.length > 0) logger.info(`Emitted ${emittedPages.length} rewritten page(s): ${emittedPages.map(([from, to]) => `${from} \u2192 ${to}`).join(", ")}`);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.buildDone = buildDone;
|
|
76
|
+
exports.configSetup = configSetup;
|
|
77
|
+
//# sourceMappingURL=integration.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.cjs","names":["INTLAYER_NO_EXTERNAL_PATTERN","getConfiguration","prepareIntlayer","resolveProxyMode","formatProxyEnabledMessage","viteIntlayerPlugin","getAlias","resolve","emitRewrittenPages"],"sources":["../../src/integration.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport {\n formatProxyEnabledMessage,\n resolveProxyMode,\n} from '@intlayer/core/localization';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport type { AstroIntegration } from 'astro';\nimport type { PluginOption } from 'vite';\nimport {\n INTLAYER_NO_EXTERNAL_PATTERN,\n intlayer as viteIntlayerPlugin,\n} from 'vite-intlayer';\nimport { emitRewrittenPages } from './emitRewrittenPages';\n\n/**\n * Keeps the intlayer packages out of Node's native module loader in *every*\n * Vite environment Astro renders from.\n *\n * A static dev server renders from `ssr`, but other setups render from Astro's\n * `astro` or `prerender` environments, and a top-level `ssr.noExternal` only\n * seeds the `ssr` one. Declaring it per environment covers the rest.\n */\nconst intlayerNoExternalEnvironments = (): PluginOption => ({\n name: 'astro-intlayer-no-external',\n configEnvironment: () => ({\n resolve: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] },\n }),\n});\n\n/**\n * Node-only half of the integration, loaded lazily by the `astro-intlayer`\n * entry when a hook runs.\n *\n * Pages import their hooks from that same entry, and Astro bundles the whole\n * package into the server build (`ssr.noExternal`), so the config loader,\n * `@intlayer/engine` and `vite-intlayer` must stay behind a dynamic import:\n * a static one would put them in the module graph of every page.\n */\n\ntype ConfigSetupOptions = Parameters<\n NonNullable<AstroIntegration['hooks']['astro:config:setup']>\n>[0];\n\ntype BuildDoneOptions = Parameters<\n NonNullable<AstroIntegration['hooks']['astro:build:done']>\n>[0];\n\n/**\n * `astro:config:setup`:\n * 1. Prepares the Intlayer resources (dictionaries).\n * 2. Injects the Vite plugins for aliases, locale-based routing and build\n * optimizations (prune).\n * 3. Configures the Vite aliases for dictionary access.\n * 4. Registers the `astro-intlayer/middleware`, which resolves the request\n * locale into `Astro.locals.intlayer` for the hooks and redirects\n * server-rendered requests to the visitor's locale.\n * 5. Injects the client-side locale redirect, which does the same for\n * prerendered pages: served as static files, nothing else can read the\n * stored locale there.\n *\n * The dev-time content watcher is not started here: the bundled\n * `vite-intlayer` plugin already starts one from `configureServer`, and\n * `watch()` subscribes anew on every call, so doing both would rebuild each\n * content edit twice.\n */\nexport const configSetup = async ({\n command,\n updateConfig,\n addMiddleware,\n injectScript,\n}: ConfigSetupOptions): Promise<void> => {\n const configuration = getConfiguration();\n\n // Prepare once per process start to ensure generated entries exist\n await prepareIntlayer(configuration);\n\n // Runs before the user middleware so `Astro.locals.intlayer` is set\n // everywhere, including in a hand-written `src/middleware.ts`.\n addMiddleware({\n entrypoint: 'astro-intlayer/middleware',\n order: 'pre',\n });\n\n const proxyMode = resolveProxyMode(configuration.routing.enableProxy);\n\n if (proxyMode !== 'disabled') {\n injectScript(\n 'page',\n `import { redirectToStoredLocale } from 'astro-intlayer/client/locale-redirect';\\nredirectToStoredLocale();`\n );\n\n // `dev` and `build` are announced by the bundled `vite-intlayer` plugin.\n // `astro preview` runs no Vite plugin, so the served output is announced\n // here: the stored locale drives redirects again once the output is\n // served — by the middleware on server-rendered pages, by the injected\n // script on static ones.\n if (command === 'preview') {\n getAppLogger(configuration)(formatProxyEnabledMessage(false), {\n level: 'info',\n });\n }\n }\n\n updateConfig({\n vite: {\n plugins: [\n viteIntlayerPlugin(),\n intlayerNoExternalEnvironments(),\n ] as PluginOption[],\n resolve: {\n alias: {\n ...getAlias({\n configuration,\n formatter: (value) => resolve(value),\n }),\n },\n },\n // `astro-intlayer` is tagged with the `astro` keyword, so Astro\n // treats it as an Astro package and crawls its dependency tree\n // (`vitefu`), force-externalizing every dependency it finds —\n // `@intlayer/core`, `@intlayer/config`, … — into\n // `resolve.external`. Vite checks `external` before `noExternal`,\n // so the `ssr.noExternal` that `vite-intlayer` returns from its\n // Vite `config` hook loses that race and the packages are loaded\n // natively by Node, stranding dictionary edits behind Node's\n // require cache. Declaring it here instead runs before the crawl,\n // which drops explicitly no-externalized packages from its result.\n ssr: {\n noExternal: [INTLAYER_NO_EXTERNAL_PATTERN],\n },\n },\n });\n};\n\n/**\n * `astro:build:done`: Astro renders each page from its canonical file-system\n * route, so a static build has no file for the localized paths declared in\n * `routing.rewrite`. Mirror them here, otherwise the URLs produced by\n * `getLocalizedUrl` (links, hreflang, sitemap) 404 once deployed.\n */\nexport const buildDone = async ({\n dir,\n logger,\n}: BuildDoneOptions): Promise<void> => {\n const configuration = getConfiguration();\n\n const emittedPages = await emitRewrittenPages(configuration, dir);\n\n if (emittedPages.length > 0) {\n logger.info(\n `Emitted ${emittedPages.length} rewritten page(s): ${emittedPages\n .map(([from, to]) => `${from} \\u2192 ${to}`)\n .join(', ')}`\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyBA,MAAM,wCAAsD;CAC1D,MAAM;CACN,0BAA0B,EACxB,SAAS,EAAE,YAAY,CAACA,0CAA4B,EAAE,EACxD;AACF;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,cAAc,OAAO,EAChC,SACA,cACA,eACA,mBACuC;CACvC,MAAM,oBAAgBC,wCAAiB;CAGvC,UAAMC,wCAAgB,aAAa;CAInC,cAAc;EACZ,YAAY;EACZ,OAAO;CACT,CAAC;CAID,QAFkBC,8CAAiB,cAAc,QAAQ,WAE7C,MAAM,YAAY;EAC5B,aACE,QACA,4GACF;EAOA,IAAI,YAAY,WACd,0CAAa,aAAa,CAAC,KAACC,uDAA0B,KAAK,GAAG,EAC5D,OAAO,OACT,CAAC;CAEL;CAEA,aAAa,EACX,MAAM;EACJ,SAAS,KACPC,wBAAmB,GACnB,+BAA+B,CACjC;EACA,SAAS,EACP,OAAO,EACL,OAAGC,iCAAS;GACV;GACA,YAAY,cAAUC,mBAAQ,KAAK;EACrC,CAAC,EACH,EACF;EAWA,KAAK,EACH,YAAY,CAACP,0CAA4B,EAC3C;CACF,EACF,CAAC;AACH;;;;;;;AAQA,MAAa,YAAY,OAAO,EAC9B,KACA,aACqC;CACrC,MAAM,oBAAgBC,wCAAiB;CAEvC,MAAM,eAAe,MAAMO,8CAAmB,eAAe,GAAG;CAEhE,IAAI,aAAa,SAAS,GACxB,OAAO,KACL,WAAW,aAAa,OAAO,sBAAsB,aAClD,KAAK,CAAC,MAAM,QAAQ,GAAG,KAAK,UAAU,IAAI,CAAC,CAC3C,KAAK,IAAI,GACd;AAEJ"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let vanilla_intlayer_markdown = require("vanilla-intlayer/markdown");
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, 'compileMarkdown', {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
get: function () {
|
|
7
|
+
return vanilla_intlayer_markdown.compileMarkdown;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
Object.defineProperty(exports, 'installIntlayerMarkdown', {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return vanilla_intlayer_markdown.installIntlayerMarkdown;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, 'installIntlayerMarkdownDynamic', {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return vanilla_intlayer_markdown.installIntlayerMarkdownDynamic;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, 'parseMarkdown', {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return vanilla_intlayer_markdown.parseMarkdown;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, 'renderMarkdown', {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return vanilla_intlayer_markdown.renderMarkdown;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, 'useMarkdown', {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () {
|
|
37
|
+
return vanilla_intlayer_markdown.useMarkdown;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, 'useMarkdownRenderer', {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () {
|
|
43
|
+
return vanilla_intlayer_markdown.useMarkdownRenderer;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_requestStorage = require('./requestStorage.cjs');
|
|
4
|
+
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
5
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
6
|
+
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
7
|
+
let vite_intlayer_web_proxy_handler = require("vite-intlayer/web-proxy-handler");
|
|
8
|
+
|
|
9
|
+
//#region src/middleware.ts
|
|
10
|
+
/**
|
|
11
|
+
* Whether `astro dev` is serving the app. Vite inlines `import.meta.env.DEV`
|
|
12
|
+
* into the server bundle; the optional chain keeps the module loadable where
|
|
13
|
+
* no bundler defines it (`process.env.NODE_ENV` cannot be used instead: the
|
|
14
|
+
* package build inlines it).
|
|
15
|
+
*/
|
|
16
|
+
const isDevServer = {}.env?.DEV === true;
|
|
17
|
+
const configuration = _intlayer_config_built;
|
|
18
|
+
const { internationalization, routing } = configuration;
|
|
19
|
+
/**
|
|
20
|
+
* Locale-routing proxy shared with the Vite dev server and the Nitro handler.
|
|
21
|
+
*
|
|
22
|
+
* `undefined` when `routing.enableProxy` is `false`. In auto mode (option
|
|
23
|
+
* unset) `astro dev` keeps routing URL-driven: the stored locale is not a
|
|
24
|
+
* redirect source, exactly like the Vite proxy mounted on the same dev server,
|
|
25
|
+
* so the two never disagree.
|
|
26
|
+
*/
|
|
27
|
+
const proxy = (0, _intlayer_core_localization.resolveProxyMode)(routing.enableProxy) === "disabled" ? void 0 : (0, vite_intlayer_web_proxy_handler.createIntlayerWebProxyHandler)({
|
|
28
|
+
configuration,
|
|
29
|
+
isDevServer
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Appends the headers the proxy produced (the persisted locale cookie) to the
|
|
33
|
+
* rendered response. Some responses ship immutable headers, in which case the
|
|
34
|
+
* body is re-wrapped in a fresh `Response`.
|
|
35
|
+
*/
|
|
36
|
+
const withProxyHeaders = (response, headers) => {
|
|
37
|
+
const entries = [...headers];
|
|
38
|
+
if (entries.length === 0) return response;
|
|
39
|
+
const applyHeaders = (target) => {
|
|
40
|
+
for (const [name, value] of entries) target.headers.append(name, value);
|
|
41
|
+
return target;
|
|
42
|
+
};
|
|
43
|
+
try {
|
|
44
|
+
return applyHeaders(response);
|
|
45
|
+
} catch {
|
|
46
|
+
return applyHeaders(new Response(response.body, response));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Astro middleware resolving the request locale into `Astro.locals.intlayer`.
|
|
51
|
+
*
|
|
52
|
+
* Priority: the URL (path prefix or `?locale=` search param, in every routing
|
|
53
|
+
* mode but `no-prefix`), then the locale persisted by the client (cookie or
|
|
54
|
+
* custom header), then `Accept-Language` negotiation.
|
|
55
|
+
*
|
|
56
|
+
* On server-rendered requests it also runs the Intlayer locale-routing proxy,
|
|
57
|
+
* so a visitor whose stored locale is `fr` is redirected from `/` to `/fr`
|
|
58
|
+
* (per `routing.mode`) and the resolved locale is persisted on the response.
|
|
59
|
+
* Only redirects are honoured: the proxy's internal rewrites target
|
|
60
|
+
* prefix-based routers, while Astro pages already resolve the locale from the
|
|
61
|
+
* URL they are rendered for. Prerendered pages are served as static files, so
|
|
62
|
+
* nothing can redirect them at request time and the proxy is skipped.
|
|
63
|
+
*
|
|
64
|
+
* The `intlayer()` integration registers it automatically, before the user
|
|
65
|
+
* middleware, so `Astro.locals.intlayer` is available in every page, endpoint
|
|
66
|
+
* and middleware. The rest of the request renders inside an
|
|
67
|
+
* `AsyncLocalStorage` scope bound to those locals, which is how the hooks of
|
|
68
|
+
* `astro-intlayer/server` read the locale with no argument.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* // src/middleware.ts — only needed when composing it by hand
|
|
73
|
+
* import { onRequest as intlayer } from 'astro-intlayer/middleware';
|
|
74
|
+
* import { sequence } from 'astro:middleware';
|
|
75
|
+
*
|
|
76
|
+
* export const onRequest = sequence(intlayer, myMiddleware);
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
const onRequest = async (context, next) => {
|
|
80
|
+
let proxyOutcome;
|
|
81
|
+
if (proxy && !context.isPrerendered) {
|
|
82
|
+
const outcome = proxy({
|
|
83
|
+
url: context.url,
|
|
84
|
+
headers: context.request.headers
|
|
85
|
+
});
|
|
86
|
+
if (outcome.kind === "response") return outcome.response;
|
|
87
|
+
proxyOutcome = outcome;
|
|
88
|
+
}
|
|
89
|
+
context.locals.intlayer = {
|
|
90
|
+
locale: await (0, _intlayer_core_localization.getLocaleFromRequest)({
|
|
91
|
+
url: context.url,
|
|
92
|
+
headers: context.isPrerendered ? new Headers() : context.request.headers
|
|
93
|
+
}),
|
|
94
|
+
defaultLocale: internationalization.defaultLocale,
|
|
95
|
+
availableLocales: internationalization.locales
|
|
96
|
+
};
|
|
97
|
+
const response = await require_requestStorage.requestStorage.run(context.locals, next);
|
|
98
|
+
return proxyOutcome ? withProxyHeaders(response, proxyOutcome.headers) : response;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
exports.onRequest = onRequest;
|
|
103
|
+
//# sourceMappingURL=middleware.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.cjs","names":["builtConfiguration","resolveProxyMode","createIntlayerWebProxyHandler","getLocaleFromRequest","requestStorage"],"sources":["../../src/middleware.ts"],"sourcesContent":["import * as builtConfiguration from '@intlayer/config/built';\nimport {\n getLocaleFromRequest,\n resolveProxyMode,\n} from '@intlayer/core/localization';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport type { MiddlewareHandler } from 'astro';\nimport {\n createIntlayerWebProxyHandler,\n type WebProxyOutcome,\n} from 'vite-intlayer/web-proxy-handler';\nimport { requestStorage } from './requestStorage';\n\n/** Proxy outcome letting the request continue to the page. */\ntype WebProxyNextOutcome = Extract<WebProxyOutcome, { kind: 'next' }>;\n\n/**\n * Whether `astro dev` is serving the app. Vite inlines `import.meta.env.DEV`\n * into the server bundle; the optional chain keeps the module loadable where\n * no bundler defines it (`process.env.NODE_ENV` cannot be used instead: the\n * package build inlines it).\n */\nconst isDevServer =\n (import.meta as { env?: { DEV?: boolean } }).env?.DEV === true;\n\nconst configuration = builtConfiguration as unknown as IntlayerConfig;\nconst { internationalization, routing } = configuration;\n\n/**\n * Locale-routing proxy shared with the Vite dev server and the Nitro handler.\n *\n * `undefined` when `routing.enableProxy` is `false`. In auto mode (option\n * unset) `astro dev` keeps routing URL-driven: the stored locale is not a\n * redirect source, exactly like the Vite proxy mounted on the same dev server,\n * so the two never disagree.\n */\nconst proxy =\n resolveProxyMode(routing.enableProxy) === 'disabled'\n ? undefined\n : createIntlayerWebProxyHandler({\n configuration,\n isDevServer,\n });\n\n/**\n * Appends the headers the proxy produced (the persisted locale cookie) to the\n * rendered response. Some responses ship immutable headers, in which case the\n * body is re-wrapped in a fresh `Response`.\n */\nconst withProxyHeaders = (response: Response, headers: Headers): Response => {\n const entries = [...headers];\n if (entries.length === 0) return response;\n\n const applyHeaders = (target: Response) => {\n for (const [name, value] of entries) {\n target.headers.append(name, value);\n }\n return target;\n };\n\n try {\n return applyHeaders(response);\n } catch {\n return applyHeaders(new Response(response.body, response));\n }\n};\n\n/**\n * Intlayer state stored in `Astro.locals.intlayer` by the {@link onRequest} middleware.\n */\nexport type IntlayerLocals = {\n /** Locale resolved for the current request. */\n locale: DeclaredLocales;\n /** Locale configured as fallback in `intlayer.config.ts`. */\n defaultLocale: DeclaredLocales;\n /** Every locale declared in `intlayer.config.ts`. */\n availableLocales: DeclaredLocales[];\n};\n\ndeclare global {\n namespace App {\n interface Locals {\n intlayer: IntlayerLocals;\n }\n }\n}\n\n/**\n * Astro middleware resolving the request locale into `Astro.locals.intlayer`.\n *\n * Priority: the URL (path prefix or `?locale=` search param, in every routing\n * mode but `no-prefix`), then the locale persisted by the client (cookie or\n * custom header), then `Accept-Language` negotiation.\n *\n * On server-rendered requests it also runs the Intlayer locale-routing proxy,\n * so a visitor whose stored locale is `fr` is redirected from `/` to `/fr`\n * (per `routing.mode`) and the resolved locale is persisted on the response.\n * Only redirects are honoured: the proxy's internal rewrites target\n * prefix-based routers, while Astro pages already resolve the locale from the\n * URL they are rendered for. Prerendered pages are served as static files, so\n * nothing can redirect them at request time and the proxy is skipped.\n *\n * The `intlayer()` integration registers it automatically, before the user\n * middleware, so `Astro.locals.intlayer` is available in every page, endpoint\n * and middleware. The rest of the request renders inside an\n * `AsyncLocalStorage` scope bound to those locals, which is how the hooks of\n * `astro-intlayer/server` read the locale with no argument.\n *\n * @example\n * ```ts\n * // src/middleware.ts — only needed when composing it by hand\n * import { onRequest as intlayer } from 'astro-intlayer/middleware';\n * import { sequence } from 'astro:middleware';\n *\n * export const onRequest = sequence(intlayer, myMiddleware);\n * ```\n */\nexport const onRequest: MiddlewareHandler = async (context, next) => {\n let proxyOutcome: WebProxyNextOutcome | undefined;\n\n if (proxy && !context.isPrerendered) {\n const outcome = proxy({\n url: context.url,\n headers: context.request.headers,\n });\n\n if (outcome.kind === 'response') return outcome.response;\n proxyOutcome = outcome;\n }\n\n context.locals.intlayer = {\n locale: await getLocaleFromRequest({\n url: context.url,\n // A prerendered page is rendered once and served to every visitor, so\n // its locale can only come from the URL. Reading the request headers\n // there would also make Astro warn on every page of the build.\n headers: context.isPrerendered ? new Headers() : context.request.headers,\n }),\n defaultLocale: internationalization.defaultLocale as DeclaredLocales,\n availableLocales: internationalization.locales as DeclaredLocales[],\n };\n\n const response = await requestStorage.run(context.locals, next);\n\n return proxyOutcome\n ? withProxyHeaders(response, proxyOutcome.headers)\n : response;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAuBA,MAAM,iBACyC,KAAK,QAAQ;AAE5D,MAAM,gBAAgBA;AACtB,MAAM,EAAE,sBAAsB,YAAY;;;;;;;;;AAU1C,MAAM,YACJC,8CAAiB,QAAQ,WAAW,MAAM,aACtC,aACAC,+DAA8B;CAC5B;CACA;AACF,CAAC;;;;;;AAOP,MAAM,oBAAoB,UAAoB,YAA+B;CAC3E,MAAM,UAAU,CAAC,GAAG,OAAO;CAC3B,IAAI,QAAQ,WAAW,GAAG,OAAO;CAEjC,MAAM,gBAAgB,WAAqB;EACzC,KAAK,MAAM,CAAC,MAAM,UAAU,SAC1B,OAAO,QAAQ,OAAO,MAAM,KAAK;EAEnC,OAAO;CACT;CAEA,IAAI;EACF,OAAO,aAAa,QAAQ;CAC9B,QAAQ;EACN,OAAO,aAAa,IAAI,SAAS,SAAS,MAAM,QAAQ,CAAC;CAC3D;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAa,YAA+B,OAAO,SAAS,SAAS;CACnE,IAAI;CAEJ,IAAI,SAAS,CAAC,QAAQ,eAAe;EACnC,MAAM,UAAU,MAAM;GACpB,KAAK,QAAQ;GACb,SAAS,QAAQ,QAAQ;EAC3B,CAAC;EAED,IAAI,QAAQ,SAAS,YAAY,OAAO,QAAQ;EAChD,eAAe;CACjB;CAEA,QAAQ,OAAO,WAAW;EACxB,QAAQ,UAAMC,kDAAqB;GACjC,KAAK,QAAQ;GAIb,SAAS,QAAQ,gBAAgB,IAAI,QAAQ,IAAI,QAAQ,QAAQ;EACnE,CAAC;EACD,eAAe,qBAAqB;EACpC,kBAAkB,qBAAqB;CACzC;CAEA,MAAM,WAAW,MAAMC,sCAAe,IAAI,QAAQ,QAAQ,IAAI;CAE9D,OAAO,eACH,iBAAiB,UAAU,aAAa,OAAO,IAC/C;AACN"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let node_async_hooks = require("node:async_hooks");
|
|
3
|
+
|
|
4
|
+
//#region src/requestStorage.ts
|
|
5
|
+
/**
|
|
6
|
+
* `Astro.locals` of the request being rendered, made available to every
|
|
7
|
+
* function running inside the middleware scope — page and component
|
|
8
|
+
* frontmatter, endpoints, nested middleware — without passing `Astro` around.
|
|
9
|
+
*/
|
|
10
|
+
const requestStorage = new node_async_hooks.AsyncLocalStorage();
|
|
11
|
+
/**
|
|
12
|
+
* Returns the Intlayer locals of the request being rendered, if any.
|
|
13
|
+
*/
|
|
14
|
+
const getIntlayerLocals = () => requestStorage.getStore()?.intlayer;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the locale of the request being rendered, if any.
|
|
17
|
+
*/
|
|
18
|
+
const getRequestLocale = () => getIntlayerLocals()?.locale;
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.getIntlayerLocals = getIntlayerLocals;
|
|
22
|
+
exports.getRequestLocale = getRequestLocale;
|
|
23
|
+
exports.requestStorage = requestStorage;
|
|
24
|
+
//# sourceMappingURL=requestStorage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestStorage.cjs","names":["AsyncLocalStorage"],"sources":["../../src/requestStorage.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport type { IntlayerLocals } from './middleware';\n\n/**\n * `Astro.locals` of the request being rendered, made available to every\n * function running inside the middleware scope — page and component\n * frontmatter, endpoints, nested middleware — without passing `Astro` around.\n */\nexport const requestStorage = new AsyncLocalStorage<{\n intlayer?: IntlayerLocals;\n}>();\n\n/**\n * Returns the Intlayer locals of the request being rendered, if any.\n */\nexport const getIntlayerLocals = (): IntlayerLocals | undefined =>\n requestStorage.getStore()?.intlayer;\n\n/**\n * Returns the locale of the request being rendered, if any.\n */\nexport const getRequestLocale = (): DeclaredLocales | undefined =>\n getIntlayerLocals()?.locale;\n"],"mappings":";;;;;;;;;AASA,MAAa,iBAAiB,IAAIA,mCAE/B;;;;AAKH,MAAa,0BACX,eAAe,SAAS,CAAC,EAAE;;;;AAK7B,MAAa,yBACX,kBAAkB,CAAC,EAAE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_requestStorage = require('./requestStorage.cjs');
|
|
3
|
+
const require_withInertOnChange = require('./withInertOnChange.cjs');
|
|
4
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
5
|
+
let vanilla_intlayer = require("vanilla-intlayer");
|
|
6
|
+
|
|
7
|
+
//#region src/useDictionary.ts
|
|
8
|
+
/**
|
|
9
|
+
* Transforms an imported dictionary (or qualified dictionary group) and returns
|
|
10
|
+
* its content for the locale of the request being rendered, read from
|
|
11
|
+
* `Astro.locals.intlayer`.
|
|
12
|
+
*
|
|
13
|
+
* The second argument is either a locale or a selector object
|
|
14
|
+
* (`{ item }`, `{ variant }`, optionally with `locale`); it takes precedence
|
|
15
|
+
* over the request locale.
|
|
16
|
+
*
|
|
17
|
+
* Same signature and content shape as the client-side hook this entry resolves
|
|
18
|
+
* to in the browser (`vanilla-intlayer`).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```astro
|
|
22
|
+
* ---
|
|
23
|
+
* import { useDictionary } from 'astro-intlayer';
|
|
24
|
+
* import homeContent from '../content/home.content';
|
|
25
|
+
*
|
|
26
|
+
* const { title } = useDictionary(homeContent);
|
|
27
|
+
* ---
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const useDictionary = (dictionary, localeOrSelector) => require_withInertOnChange.withInertOnChange((0, vanilla_intlayer.getDictionary)(dictionary, (0, _intlayer_core_dictionaryManipulator.resolveDictionaryArgument)({
|
|
31
|
+
localeOrSelector,
|
|
32
|
+
contextLocale: require_requestStorage.getRequestLocale(),
|
|
33
|
+
dictionaryKey: dictionary.key
|
|
34
|
+
})));
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.useDictionary = useDictionary;
|
|
38
|
+
//# sourceMappingURL=useDictionary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":["withInertOnChange","getDictionary","resolveDictionaryArgument","getRequestLocale"],"sources":["../../src/useDictionary.ts"],"sourcesContent":["import { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n type DeepTransformContent,\n getDictionary,\n type WithOnChange,\n} from 'vanilla-intlayer';\nimport { getRequestLocale } from './requestStorage';\nimport { withInertOnChange } from './withInertOnChange';\n\n/**\n * Transforms an imported dictionary (or qualified dictionary group) and returns\n * its content for the locale of the request being rendered, read from\n * `Astro.locals.intlayer`.\n *\n * The second argument is either a locale or a selector object\n * (`{ item }`, `{ variant }`, optionally with `locale`); it takes precedence\n * over the request locale.\n *\n * Same signature and content shape as the client-side hook this entry resolves\n * to in the browser (`vanilla-intlayer`).\n *\n * @example\n * ```astro\n * ---\n * import { useDictionary } from 'astro-intlayer';\n * import homeContent from '../content/home.content';\n *\n * const { title } = useDictionary(homeContent);\n * ---\n * ```\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): WithOnChange<\n DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n >\n> =>\n withInertOnChange(\n getDictionary<T, A>(\n dictionary,\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: getRequestLocale(),\n dictionaryKey: dictionary.key,\n }) as A\n )\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,iBAMX,YACA,qBAOAA,gDACEC,gCACE,gBACAC,gEAA0B;CACxB;CACA,eAAeC,wCAAiB;CAChC,eAAe,WAAW;AAC5B,CAAC,CACH,CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_requestStorage = require('./requestStorage.cjs');
|
|
3
|
+
const require_withInertOnChange = require('./withInertOnChange.cjs');
|
|
4
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
5
|
+
let vanilla_intlayer = require("vanilla-intlayer");
|
|
6
|
+
|
|
7
|
+
//#region src/useIntlayer.ts
|
|
8
|
+
/**
|
|
9
|
+
* Picks one dictionary by its key and returns its content for the locale of
|
|
10
|
+
* the request being rendered, read from `Astro.locals.intlayer`.
|
|
11
|
+
*
|
|
12
|
+
* The second argument is either a locale or a selector object
|
|
13
|
+
* (`{ item }`, `{ variant }`, optionally with `locale`); it takes precedence
|
|
14
|
+
* over the request locale.
|
|
15
|
+
*
|
|
16
|
+
* Same signature and content shape as the client-side hook this entry resolves
|
|
17
|
+
* to in the browser (`vanilla-intlayer`), so a call moves between the
|
|
18
|
+
* frontmatter and a `<script>` unchanged.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```astro
|
|
22
|
+
* ---
|
|
23
|
+
* import { useIntlayer } from 'astro-intlayer';
|
|
24
|
+
*
|
|
25
|
+
* const { title, description } = useIntlayer('home');
|
|
26
|
+
* ---
|
|
27
|
+
* <h1>{title}</h1>
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const useIntlayer = (key, localeOrSelector) => require_withInertOnChange.withInertOnChange((0, vanilla_intlayer.getIntlayer)(key, (0, _intlayer_core_dictionaryManipulator.resolveDictionaryArgument)({
|
|
31
|
+
localeOrSelector,
|
|
32
|
+
contextLocale: require_requestStorage.getRequestLocale(),
|
|
33
|
+
dictionaryKey: key
|
|
34
|
+
})));
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.useIntlayer = useIntlayer;
|
|
38
|
+
//# sourceMappingURL=useIntlayer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIntlayer.cjs","names":["withInertOnChange","getIntlayer","resolveDictionaryArgument","getRequestLocale"],"sources":["../../src/useIntlayer.ts"],"sourcesContent":["import { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n type DeepTransformContent,\n getIntlayer,\n type WithOnChange,\n} from 'vanilla-intlayer';\nimport { getRequestLocale } from './requestStorage';\nimport { withInertOnChange } from './withInertOnChange';\n\n/**\n * Picks one dictionary by its key and returns its content for the locale of\n * the request being rendered, read from `Astro.locals.intlayer`.\n *\n * The second argument is either a locale or a selector object\n * (`{ item }`, `{ variant }`, optionally with `locale`); it takes precedence\n * over the request locale.\n *\n * Same signature and content shape as the client-side hook this entry resolves\n * to in the browser (`vanilla-intlayer`), so a call moves between the\n * frontmatter and a `<script>` unchanged.\n *\n * @example\n * ```astro\n * ---\n * import { useIntlayer } from 'astro-intlayer';\n *\n * const { title, description } = useIntlayer('home');\n * ---\n * <h1>{title}</h1>\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): WithOnChange<\n DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>\n> =>\n withInertOnChange(\n getIntlayer<T, A>(\n key,\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: getRequestLocale(),\n dictionaryKey: key as string,\n }) as A\n )\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAa,eAIX,KACA,qBAIAA,gDACEC,8BACE,SACAC,gEAA0B;CACxB;CACA,eAAeC,wCAAiB;CAChC,eAAe;AACjB,CAAC,CACH,CACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_requestStorage = require('./requestStorage.cjs');
|
|
3
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
+
|
|
5
|
+
//#region src/useLocale.ts
|
|
6
|
+
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the locale of the request being rendered, read from
|
|
9
|
+
* `Astro.locals.intlayer`, with the configured default and available locales.
|
|
10
|
+
*
|
|
11
|
+
* Falls back to the default locale outside of a request, i.e. when the
|
|
12
|
+
* `astro-intlayer/middleware` did not run.
|
|
13
|
+
*
|
|
14
|
+
* Same shape as the client-side hook this entry resolves to in the browser
|
|
15
|
+
* (`vanilla-intlayer`). A request has no locale to switch, so `setLocale` and
|
|
16
|
+
* `subscribe` are inert here: switch the locale from a `<script>`, where the
|
|
17
|
+
* same import gives the client implementation.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```astro
|
|
21
|
+
* ---
|
|
22
|
+
* import { useLocale } from 'astro-intlayer';
|
|
23
|
+
*
|
|
24
|
+
* const { locale, availableLocales } = useLocale();
|
|
25
|
+
* ---
|
|
26
|
+
* <html lang={locale}>
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const useLocale = (_props = {}) => ({
|
|
30
|
+
locale: require_requestStorage.getRequestLocale() ?? defaultLocale,
|
|
31
|
+
defaultLocale,
|
|
32
|
+
availableLocales,
|
|
33
|
+
setLocale: () => {
|
|
34
|
+
console.warn("[astro-intlayer] setLocale() has no effect during a server render. Call it from a client <script> instead.");
|
|
35
|
+
},
|
|
36
|
+
subscribe: () => () => {}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.useLocale = useLocale;
|
|
41
|
+
//# sourceMappingURL=useLocale.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":["internationalization","getRequestLocale"],"sources":["../../src/useLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport type {\n UseLocaleProps,\n UseLocaleResult as VanillaUseLocaleResult,\n} from 'vanilla-intlayer';\nimport { getRequestLocale } from './requestStorage';\n\nexport type { UseLocaleProps } from 'vanilla-intlayer';\n\nexport type UseLocaleResult = VanillaUseLocaleResult;\n\nconst { defaultLocale, locales: availableLocales } = internationalization;\n\n/**\n * Returns the locale of the request being rendered, read from\n * `Astro.locals.intlayer`, with the configured default and available locales.\n *\n * Falls back to the default locale outside of a request, i.e. when the\n * `astro-intlayer/middleware` did not run.\n *\n * Same shape as the client-side hook this entry resolves to in the browser\n * (`vanilla-intlayer`). A request has no locale to switch, so `setLocale` and\n * `subscribe` are inert here: switch the locale from a `<script>`, where the\n * same import gives the client implementation.\n *\n * @example\n * ```astro\n * ---\n * import { useLocale } from 'astro-intlayer';\n *\n * const { locale, availableLocales } = useLocale();\n * ---\n * <html lang={locale}>\n * ```\n */\nexport const useLocale = (_props: UseLocaleProps = {}): UseLocaleResult => ({\n locale: getRequestLocale() ?? (defaultLocale as DeclaredLocales),\n defaultLocale: defaultLocale as DeclaredLocales,\n availableLocales: availableLocales as DeclaredLocales[],\n setLocale: () => {\n console.warn(\n '[astro-intlayer] setLocale() has no effect during a server render. Call it from a client <script> instead.'\n );\n },\n subscribe: () => () => {},\n});\n"],"mappings":";;;;;AAYA,MAAM,EAAE,eAAe,SAAS,qBAAqBA;;;;;;;;;;;;;;;;;;;;;;;AAwBrD,MAAa,aAAa,SAAyB,CAAC,OAAwB;CAC1E,QAAQC,wCAAiB,KAAM;CAChB;CACG;CAClB,iBAAiB;EACf,QAAQ,KACN,4GACF;CACF;CACA,uBAAuB,CAAC;AAC1B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region src/withInertOnChange.ts
|
|
3
|
+
/**
|
|
4
|
+
* Gives server-rendered content the `.onChange()` of its client counterpart.
|
|
5
|
+
*
|
|
6
|
+
* The locale cannot change during a server render, so the subscription never
|
|
7
|
+
* fires; it only keeps the content shape identical on both sides of the
|
|
8
|
+
* `astro-intlayer` entry.
|
|
9
|
+
*/
|
|
10
|
+
const withInertOnChange = (content) => {
|
|
11
|
+
if (content !== null && typeof content === "object") content.onChange = () => content;
|
|
12
|
+
return content;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.withInertOnChange = withInertOnChange;
|
|
17
|
+
//# sourceMappingURL=withInertOnChange.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withInertOnChange.cjs","names":[],"sources":["../../src/withInertOnChange.ts"],"sourcesContent":["import type { WithOnChange } from 'vanilla-intlayer';\n\n/**\n * Gives server-rendered content the `.onChange()` of its client counterpart.\n *\n * The locale cannot change during a server render, so the subscription never\n * fires; it only keeps the content shape identical on both sides of the\n * `astro-intlayer` entry.\n */\nexport const withInertOnChange = <T>(content: T): WithOnChange<T> => {\n // A selector can resolve to null or a primitive; only objects carry `.onChange`.\n if (content !== null && typeof content === 'object') {\n (content as WithOnChange<T>).onChange = () => content as WithOnChange<T>;\n }\n\n return content as WithOnChange<T>;\n};\n"],"mappings":";;;;;;;;;AASA,MAAa,qBAAwB,YAAgC;CAEnE,IAAI,YAAY,QAAQ,OAAO,YAAY,UACzC,AAAC,QAA4B,iBAAiB;CAGhD,OAAO;AACT"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { getDictionary, getIntlayer, installIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage } from "vanilla-intlayer";
|
|
2
|
+
|
|
3
|
+
export { getDictionary, getIntlayer, installIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage };
|