react-intlayer 3.5.11 → 4.0.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/dist/esm/client/IntlayerProvider.mjs +0 -1
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/getBrowserLocale.mjs +0 -1
- package/dist/esm/client/getBrowserLocale.mjs.map +1 -1
- package/dist/esm/client/index.mjs +0 -1
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/t.mjs +0 -1
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useContent.mjs +0 -1
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +0 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +0 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useIntlayerAsync.mjs +0 -1
- package/dist/esm/client/useIntlayerAsync.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +0 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +0 -1
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleCookie.mjs +0 -1
- package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +0 -1
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +0 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorConnector.mjs +0 -1
- package/dist/esm/editor/ContentSelectorConnector.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +0 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +0 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/renderContentEditor.mjs +0 -1
- package/dist/esm/editor/renderContentEditor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +0 -1
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getEnumeration.mjs +0 -1
- package/dist/esm/getEnumeration.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +0 -1
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/getIntlayerAsync.mjs +0 -1
- package/dist/esm/getIntlayerAsync.mjs.map +1 -1
- package/dist/esm/getTranslation.mjs +0 -1
- package/dist/esm/getTranslation.mjs.map +1 -1
- package/dist/esm/index.mjs +0 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/processDictionary/index.mjs +0 -1
- package/dist/esm/processDictionary/index.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs +0 -1
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/getLocaleTranslation.mjs +0 -1
- package/dist/esm/server/getLocaleTranslation.mjs.map +1 -1
- package/dist/esm/server/index.mjs +0 -1
- package/dist/esm/server/index.mjs.map +1 -1
- package/dist/esm/server/serverContext.mjs +0 -1
- package/dist/esm/server/serverContext.mjs.map +1 -1
- package/dist/esm/server/t.mjs +0 -1
- package/dist/esm/server/t.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs +0 -1
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +0 -1
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useTraduction.mjs +0 -1
- package/dist/esm/server/useTraduction.mjs.map +1 -1
- package/dist/esm/utils/PoweredByMeta/index.mjs +0 -1
- package/dist/esm/utils/PoweredByMeta/index.mjs.map +1 -1
- package/package.json +16 -34
- package/dist/cjs/cli/react-intlayer.cjs +0 -73
- package/dist/cjs/cli/react-intlayer.cjs.map +0 -1
- package/dist/cjs/craco/craco.config.cjs +0 -32
- package/dist/cjs/craco/craco.config.cjs.map +0 -1
- package/dist/cjs/craco/intlayerCracoPlugin.cjs +0 -93
- package/dist/cjs/craco/intlayerCracoPlugin.cjs.map +0 -1
- package/dist/cjs/utils/removeUndefinedValueObject.cjs +0 -38
- package/dist/cjs/utils/removeUndefinedValueObject.cjs.map +0 -1
- package/dist/cjs/vite/index.cjs +0 -25
- package/dist/cjs/vite/index.cjs.map +0 -1
- package/dist/cjs/vite/intlayerMiddlewarePlugin.cjs +0 -224
- package/dist/cjs/vite/intlayerMiddlewarePlugin.cjs.map +0 -1
- package/dist/cjs/vite/intlayerPlugin.cjs +0 -88
- package/dist/cjs/vite/intlayerPlugin.cjs.map +0 -1
- package/dist/esm/chunk-ZD7AOCMD.mjs +0 -9
- package/dist/esm/chunk-ZD7AOCMD.mjs.map +0 -1
- package/dist/esm/cli/react-intlayer.mjs +0 -50
- package/dist/esm/cli/react-intlayer.mjs.map +0 -1
- package/dist/esm/craco/craco.config.mjs +0 -17
- package/dist/esm/craco/craco.config.mjs.map +0 -1
- package/dist/esm/craco/intlayerCracoPlugin.mjs +0 -74
- package/dist/esm/craco/intlayerCracoPlugin.mjs.map +0 -1
- package/dist/esm/utils/removeUndefinedValueObject.mjs +0 -15
- package/dist/esm/utils/removeUndefinedValueObject.mjs.map +0 -1
- package/dist/esm/vite/index.mjs +0 -3
- package/dist/esm/vite/index.mjs.map +0 -1
- package/dist/esm/vite/intlayerMiddlewarePlugin.mjs +0 -201
- package/dist/esm/vite/intlayerMiddlewarePlugin.mjs.map +0 -1
- package/dist/esm/vite/intlayerPlugin.mjs +0 -55
- package/dist/esm/vite/intlayerPlugin.mjs.map +0 -1
- package/dist/types/cli/react-intlayer.d.ts +0 -9
- package/dist/types/cli/react-intlayer.d.ts.map +0 -1
- package/dist/types/craco/craco.config.d.ts +0 -2
- package/dist/types/craco/craco.config.d.ts.map +0 -1
- package/dist/types/craco/intlayerCracoPlugin.d.ts +0 -24
- package/dist/types/craco/intlayerCracoPlugin.d.ts.map +0 -1
- package/dist/types/utils/removeUndefinedValueObject.d.ts +0 -2
- package/dist/types/utils/removeUndefinedValueObject.d.ts.map +0 -1
- package/dist/types/vite/index.d.ts +0 -3
- package/dist/types/vite/index.d.ts.map +0 -1
- package/dist/types/vite/intlayerMiddlewarePlugin.d.ts +0 -6
- package/dist/types/vite/intlayerMiddlewarePlugin.d.ts.map +0 -1
- package/dist/types/vite/intlayerPlugin.d.ts +0 -16
- package/dist/types/vite/intlayerPlugin.d.ts.map +0 -1
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var intlayerMiddlewarePlugin_exports = {};
|
|
20
|
-
__export(intlayerMiddlewarePlugin_exports, {
|
|
21
|
-
intLayerMiddlewarePlugin: () => intLayerMiddlewarePlugin
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(intlayerMiddlewarePlugin_exports);
|
|
24
|
-
var import_url = require("url");
|
|
25
|
-
var import_config = require("@intlayer/config");
|
|
26
|
-
var import_core = require("@intlayer/core");
|
|
27
|
-
const intlayerConfig = (0, import_config.getConfiguration)();
|
|
28
|
-
const { internationalization, middleware } = intlayerConfig;
|
|
29
|
-
const { locales: supportedLocales, defaultLocale } = internationalization;
|
|
30
|
-
const {
|
|
31
|
-
cookieName,
|
|
32
|
-
headerName,
|
|
33
|
-
prefixDefault,
|
|
34
|
-
noPrefix,
|
|
35
|
-
serverSetCookie,
|
|
36
|
-
basePath = ""
|
|
37
|
-
} = middleware;
|
|
38
|
-
const intLayerMiddlewarePlugin = () => {
|
|
39
|
-
return {
|
|
40
|
-
name: "vite-intlayer-middleware-plugin",
|
|
41
|
-
configureServer: (server) => {
|
|
42
|
-
server.middlewares.use((req, res, next) => {
|
|
43
|
-
if (req.url?.startsWith("/node_modules") || req.url?.startsWith("/@") || req.url?.split("?")[0].match(/\.[a-z]+$/i)) {
|
|
44
|
-
return next();
|
|
45
|
-
}
|
|
46
|
-
const parsedUrl = (0, import_url.parse)(req.url ?? "/", true);
|
|
47
|
-
const originalPath = parsedUrl.pathname ?? "/";
|
|
48
|
-
const cookies = parseCookies(req.headers.cookie ?? "");
|
|
49
|
-
const cookieLocale = getValidLocaleFromCookie(cookies[cookieName]);
|
|
50
|
-
const pathLocale = getPathLocale(originalPath);
|
|
51
|
-
if (noPrefix) {
|
|
52
|
-
handleNoPrefix({
|
|
53
|
-
req,
|
|
54
|
-
res,
|
|
55
|
-
next,
|
|
56
|
-
originalPath,
|
|
57
|
-
cookieLocale
|
|
58
|
-
});
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
handlePrefix({
|
|
62
|
-
req,
|
|
63
|
-
res,
|
|
64
|
-
next,
|
|
65
|
-
originalPath,
|
|
66
|
-
pathLocale,
|
|
67
|
-
cookieLocale
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
const parseCookies = (cookieHeader) => {
|
|
74
|
-
return cookieHeader.split(";").reduce(
|
|
75
|
-
(acc, cookie) => {
|
|
76
|
-
const [key, val] = cookie.trim().split("=");
|
|
77
|
-
acc[key] = val;
|
|
78
|
-
return acc;
|
|
79
|
-
},
|
|
80
|
-
{}
|
|
81
|
-
);
|
|
82
|
-
};
|
|
83
|
-
const getValidLocaleFromCookie = (locale) => {
|
|
84
|
-
if (locale && supportedLocales.includes(locale)) {
|
|
85
|
-
return locale;
|
|
86
|
-
}
|
|
87
|
-
return void 0;
|
|
88
|
-
};
|
|
89
|
-
const getPathLocale = (pathname) => {
|
|
90
|
-
const segments = pathname.split("/").filter(Boolean);
|
|
91
|
-
const firstSegment = segments[0];
|
|
92
|
-
if (firstSegment && supportedLocales.includes(firstSegment)) {
|
|
93
|
-
return firstSegment;
|
|
94
|
-
}
|
|
95
|
-
return void 0;
|
|
96
|
-
};
|
|
97
|
-
const redirectUrl = (res, newUrl) => {
|
|
98
|
-
res.writeHead(301, { Location: newUrl });
|
|
99
|
-
return res.end();
|
|
100
|
-
};
|
|
101
|
-
const rewriteUrl = (req, res, newUrl, locale) => {
|
|
102
|
-
req.url = newUrl;
|
|
103
|
-
if (locale && headerName) {
|
|
104
|
-
res.setHeader(headerName, locale);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const constructPath = (locale, currentPath) => {
|
|
108
|
-
const cleanBasePath = basePath.startsWith("/") ? basePath : `/${basePath}`;
|
|
109
|
-
const normalizedBasePath = cleanBasePath === "/" ? "" : cleanBasePath;
|
|
110
|
-
let newPath = `${normalizedBasePath}/${locale}${currentPath}`;
|
|
111
|
-
if (!prefixDefault && locale === defaultLocale) {
|
|
112
|
-
newPath = `${normalizedBasePath}${currentPath}`;
|
|
113
|
-
}
|
|
114
|
-
return newPath;
|
|
115
|
-
};
|
|
116
|
-
const handleNoPrefix = ({
|
|
117
|
-
req,
|
|
118
|
-
res,
|
|
119
|
-
next,
|
|
120
|
-
originalPath,
|
|
121
|
-
cookieLocale
|
|
122
|
-
}) => {
|
|
123
|
-
let locale = cookieLocale ?? defaultLocale;
|
|
124
|
-
if (!cookieLocale) {
|
|
125
|
-
const detectedLocale = (0, import_core.localeDetector)(
|
|
126
|
-
req.headers,
|
|
127
|
-
supportedLocales,
|
|
128
|
-
defaultLocale
|
|
129
|
-
);
|
|
130
|
-
locale = detectedLocale;
|
|
131
|
-
}
|
|
132
|
-
rewriteUrl(req, res, originalPath, locale);
|
|
133
|
-
return next();
|
|
134
|
-
};
|
|
135
|
-
const handlePrefix = ({
|
|
136
|
-
req,
|
|
137
|
-
res,
|
|
138
|
-
next,
|
|
139
|
-
originalPath,
|
|
140
|
-
pathLocale,
|
|
141
|
-
cookieLocale
|
|
142
|
-
}) => {
|
|
143
|
-
if (!pathLocale) {
|
|
144
|
-
handleMissingPathLocale({
|
|
145
|
-
req,
|
|
146
|
-
res,
|
|
147
|
-
next,
|
|
148
|
-
originalPath,
|
|
149
|
-
cookieLocale
|
|
150
|
-
});
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
handleExistingPathLocale({
|
|
154
|
-
req,
|
|
155
|
-
res,
|
|
156
|
-
next,
|
|
157
|
-
originalPath,
|
|
158
|
-
pathLocale,
|
|
159
|
-
cookieLocale
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
const handleMissingPathLocale = ({
|
|
163
|
-
req,
|
|
164
|
-
res,
|
|
165
|
-
next,
|
|
166
|
-
originalPath,
|
|
167
|
-
cookieLocale
|
|
168
|
-
}) => {
|
|
169
|
-
let locale = cookieLocale ?? (0, import_core.localeDetector)(
|
|
170
|
-
req.headers,
|
|
171
|
-
supportedLocales,
|
|
172
|
-
defaultLocale
|
|
173
|
-
);
|
|
174
|
-
if (!supportedLocales.includes(locale)) {
|
|
175
|
-
locale = defaultLocale;
|
|
176
|
-
}
|
|
177
|
-
const newPath = constructPath(locale, originalPath);
|
|
178
|
-
if (prefixDefault || locale !== defaultLocale) {
|
|
179
|
-
return redirectUrl(res, newPath);
|
|
180
|
-
}
|
|
181
|
-
rewriteUrl(req, res, newPath, locale);
|
|
182
|
-
return next();
|
|
183
|
-
};
|
|
184
|
-
const handleExistingPathLocale = ({
|
|
185
|
-
req,
|
|
186
|
-
res,
|
|
187
|
-
next,
|
|
188
|
-
originalPath,
|
|
189
|
-
pathLocale,
|
|
190
|
-
cookieLocale
|
|
191
|
-
}) => {
|
|
192
|
-
if (cookieLocale && cookieLocale !== pathLocale && serverSetCookie !== "always") {
|
|
193
|
-
const newPath = originalPath.replace(`/${pathLocale}`, `/${cookieLocale}`);
|
|
194
|
-
const finalPath = constructPath(cookieLocale, newPath.replace(/^\/+/, "/"));
|
|
195
|
-
return redirectUrl(res, finalPath);
|
|
196
|
-
}
|
|
197
|
-
handleDefaultLocaleRedirect({
|
|
198
|
-
req,
|
|
199
|
-
res,
|
|
200
|
-
next,
|
|
201
|
-
originalPath,
|
|
202
|
-
pathLocale
|
|
203
|
-
});
|
|
204
|
-
};
|
|
205
|
-
const handleDefaultLocaleRedirect = ({
|
|
206
|
-
req,
|
|
207
|
-
res,
|
|
208
|
-
next,
|
|
209
|
-
originalPath,
|
|
210
|
-
pathLocale
|
|
211
|
-
}) => {
|
|
212
|
-
if (!prefixDefault && pathLocale === defaultLocale) {
|
|
213
|
-
const newPath = originalPath.replace(`/${defaultLocale}`, "") ?? "/";
|
|
214
|
-
rewriteUrl(req, res, newPath, pathLocale);
|
|
215
|
-
return next();
|
|
216
|
-
}
|
|
217
|
-
rewriteUrl(req, res, originalPath, pathLocale);
|
|
218
|
-
return next();
|
|
219
|
-
};
|
|
220
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
221
|
-
0 && (module.exports = {
|
|
222
|
-
intLayerMiddlewarePlugin
|
|
223
|
-
});
|
|
224
|
-
//# sourceMappingURL=intlayerMiddlewarePlugin.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/vite/intlayerMiddlewarePlugin.ts"],"sourcesContent":["import { IncomingMessage, ServerResponse } from 'http';\nimport { parse } from 'url';\nimport { getConfiguration, type Locales } from '@intlayer/config';\nimport { localeDetector } from '@intlayer/core';\n/* @ts-ignore - Vite types error */\nimport type { Connect, Plugin } from 'vite';\n\n// Grab all the config you need.\n// Make sure your config includes the following fields if you want to replicate Next.js logic:\n// - internationalization.locales\n// - internationalization.defaultLocale\n// - middleware.cookieName\n// - middleware.headerName\n// - middleware.prefixDefault\n// - middleware.noPrefix\n// - middleware.serverSetCookie\n// - middleware.basePath\n// - etc.\nconst intlayerConfig = getConfiguration();\nconst { internationalization, middleware } = intlayerConfig;\nconst { locales: supportedLocales, defaultLocale } = internationalization;\n\nconst {\n cookieName,\n headerName,\n prefixDefault,\n noPrefix,\n serverSetCookie,\n basePath = '',\n} = middleware;\n\n/**\n * A Vite plugin that integrates a logic similar to the Next.js intlayer middleware.\n */\nexport const intLayerMiddlewarePlugin = (): Plugin => {\n return {\n name: 'vite-intlayer-middleware-plugin',\n configureServer: (server) => {\n server.middlewares.use((req, res, next) => {\n // 1. Bypass assets and special Vite endpoints\n if (\n req.url?.startsWith('/node_modules') ||\n req.url?.startsWith('/@') ||\n req.url?.split('?')[0].match(/\\.[a-z]+$/i) // checks for file extensions\n ) {\n return next();\n }\n\n // 2. Parse original URL for path and query\n const parsedUrl = parse(req.url ?? '/', true);\n const originalPath = parsedUrl.pathname ?? '/';\n\n // 3. Attempt to read the cookie locale\n const cookies = parseCookies(req.headers.cookie ?? '');\n const cookieLocale = getValidLocaleFromCookie(cookies[cookieName]);\n\n // 4. Check if there's a locale prefix in the path\n const pathLocale = getPathLocale(originalPath);\n\n // 5. If noPrefix is true, we skip prefix logic altogether\n if (noPrefix) {\n handleNoPrefix({\n req,\n res,\n next,\n originalPath,\n cookieLocale,\n });\n return;\n }\n\n // 6. Otherwise, handle prefix logic\n handlePrefix({\n req,\n res,\n next,\n originalPath,\n pathLocale,\n cookieLocale,\n });\n });\n },\n };\n};\n\n/* --------------------------------------------------------------------\n * Helper & Utility Functions\n * --------------------------------------------------------------------\n */\n\n/**\n * Parses cookies from the Cookie header string into an object.\n */\nconst parseCookies = (cookieHeader: string) => {\n return cookieHeader.split(';').reduce(\n (acc, cookie) => {\n const [key, val] = cookie.trim().split('=');\n acc[key] = val;\n return acc;\n },\n {} as Record<string, string>\n );\n};\n\n/**\n * Checks if the cookie locale is valid and is included in the supported locales.\n */\nconst getValidLocaleFromCookie = (\n locale: string | undefined\n): Locales | undefined => {\n if (locale && supportedLocales.includes(locale as Locales)) {\n return locale as Locales;\n }\n return undefined;\n};\n\n/**\n * Extracts the locale from the URL pathname if present as the first segment.\n */\nconst getPathLocale = (pathname: string): Locales | undefined => {\n // e.g. if pathname is /en/some/page or /en\n // we check if \"en\" is in your supportedLocales\n const segments = pathname.split('/').filter(Boolean);\n const firstSegment = segments[0];\n if (firstSegment && supportedLocales.includes(firstSegment as Locales)) {\n return firstSegment as Locales;\n }\n return undefined;\n};\n\n/**\n * Writes a 301 redirect response with the given new URL.\n */\nconst redirectUrl = (res: ServerResponse<IncomingMessage>, newUrl: string) => {\n res.writeHead(301, { Location: newUrl });\n return res.end();\n};\n\n/**\n * \"Rewrite\" the request internally by adjusting req.url;\n * we also set the locale in the response header if needed.\n */\nconst rewriteUrl = (\n req: Connect.IncomingMessage,\n res: ServerResponse<IncomingMessage>,\n newUrl: string,\n locale?: Locales\n) => {\n req.url = newUrl;\n // If you want to mimic Next.js's behavior of setting a header for the locale:\n if (locale && headerName) {\n res.setHeader(headerName, locale);\n }\n};\n\n/**\n * Constructs a new path string, optionally including a locale prefix and basePath.\n * - basePath: (e.g., '/myapp')\n * - locale: (e.g., 'en')\n * - currentPath:(e.g., '/products/shoes')\n */\nconst constructPath = (locale: Locales, currentPath: string) => {\n // Ensure basePath always starts with '/', and remove trailing slash if needed\n const cleanBasePath = basePath.startsWith('/') ? basePath : `/${basePath}`;\n // If basePath is '/', no trailing slash is needed\n const normalizedBasePath = cleanBasePath === '/' ? '' : cleanBasePath;\n\n // Combine basePath + locale + the rest of the path\n // Example: basePath = '/myapp', locale = 'en', currentPath = '/products' => '/myapp/en/products'\n let newPath = `${normalizedBasePath}/${locale}${currentPath}`;\n\n // Special case: if prefixDefault is false and locale is defaultLocale, remove the locale prefix\n if (!prefixDefault && locale === defaultLocale) {\n newPath = `${normalizedBasePath}${currentPath}`;\n }\n\n return newPath;\n};\n\n/* --------------------------------------------------------------------\n * Handlers that mirror Next.js style logic\n * --------------------------------------------------------------------\n */\n\n/**\n * If `noPrefix` is true, we never prefix the locale in the URL.\n * We simply rewrite the request to the same path, but with the best-chosen locale\n * in a header or cookie if desired.\n */\nconst handleNoPrefix = ({\n req,\n res,\n next,\n originalPath,\n cookieLocale,\n}: {\n req: Connect.IncomingMessage;\n res: ServerResponse<IncomingMessage>;\n next: Connect.NextFunction;\n originalPath: string;\n cookieLocale?: Locales;\n}) => {\n // Determine the best locale\n let locale = cookieLocale ?? defaultLocale;\n\n // Use fallback to localeDetector if no cookie\n if (!cookieLocale) {\n const detectedLocale = localeDetector(\n req.headers as Record<string, string>,\n supportedLocales,\n defaultLocale\n );\n locale = detectedLocale;\n }\n\n // Just rewrite the URL in-place (no prefix). We do NOT redirect because we do not want to alter the URL.\n rewriteUrl(req, res, originalPath, locale);\n return next();\n};\n\n/**\n * The main prefix logic:\n * - If there's no pathLocale in the URL, we might want to detect & redirect or rewrite\n * - If there is a pathLocale, handle cookie mismatch or default locale special cases\n */\nconst handlePrefix = ({\n req,\n res,\n next,\n originalPath,\n pathLocale,\n cookieLocale,\n}: {\n req: Connect.IncomingMessage;\n res: ServerResponse<IncomingMessage>;\n next: Connect.NextFunction;\n originalPath: string;\n pathLocale?: Locales;\n cookieLocale?: Locales;\n}) => {\n // 1. If pathLocale is missing, handle\n if (!pathLocale) {\n handleMissingPathLocale({\n req,\n res,\n next,\n originalPath,\n cookieLocale,\n });\n return;\n }\n\n // 2. If pathLocale exists, handle possible mismatch with cookie\n handleExistingPathLocale({\n req,\n res,\n next,\n originalPath,\n pathLocale,\n cookieLocale,\n });\n};\n\n/**\n * Handles requests where the locale is missing from the URL pathname.\n * We detect a locale from cookie / headers / default, then either redirect or rewrite.\n */\nconst handleMissingPathLocale = ({\n req,\n res,\n next,\n originalPath,\n cookieLocale,\n}: {\n req: Connect.IncomingMessage;\n res: ServerResponse<IncomingMessage>;\n next: Connect.NextFunction;\n originalPath: string;\n cookieLocale?: Locales;\n}) => {\n // 1. Choose the best locale\n let locale =\n cookieLocale ??\n localeDetector(\n req.headers as Record<string, string>,\n supportedLocales,\n defaultLocale\n );\n\n // 2. If still invalid, fallback\n if (!supportedLocales.includes(locale)) {\n locale = defaultLocale;\n }\n\n // 3. Construct new path\n const newPath = constructPath(locale, originalPath);\n\n // If we always prefix default or if this is not the default locale, do a 301 redirect\n // so that the user sees the locale in the URL.\n if (prefixDefault || locale !== defaultLocale) {\n return redirectUrl(res, newPath);\n }\n\n // If we do NOT prefix the default locale, just rewrite in place\n rewriteUrl(req, res, newPath, locale);\n return next();\n};\n\n/**\n * Handles requests where the locale prefix is present in the pathname.\n * We verify if the cookie locale differs from the path locale; if so, handle.\n */\nconst handleExistingPathLocale = ({\n req,\n res,\n next,\n originalPath,\n pathLocale,\n cookieLocale,\n}: {\n req: Connect.IncomingMessage;\n res: ServerResponse<IncomingMessage>;\n next: Connect.NextFunction;\n originalPath: string;\n pathLocale: Locales;\n cookieLocale?: Locales;\n}) => {\n // 1. If the cookie locale is set and differs from the path locale,\n // and we're not forcing the cookie to always override\n if (\n cookieLocale &&\n cookieLocale !== pathLocale &&\n serverSetCookie !== 'always'\n ) {\n // We want to swap out the pathLocale with the cookieLocale\n const newPath = originalPath.replace(`/${pathLocale}`, `/${cookieLocale}`);\n const finalPath = constructPath(cookieLocale, newPath.replace(/^\\/+/, '/'));\n return redirectUrl(res, finalPath);\n }\n\n // 2. Otherwise, handle default-locale prefix if needed\n handleDefaultLocaleRedirect({\n req,\n res,\n next,\n originalPath,\n pathLocale,\n });\n};\n\n/**\n * If the path locale is the default locale but we don't want to prefix the default, remove it.\n */\nconst handleDefaultLocaleRedirect = ({\n req,\n res,\n next,\n originalPath,\n pathLocale,\n}: {\n req: Connect.IncomingMessage;\n res: ServerResponse<IncomingMessage>;\n next: Connect.NextFunction;\n originalPath: string;\n pathLocale: Locales;\n}) => {\n // If we don't prefix default AND the path locale is the default locale -> remove it\n if (!prefixDefault && pathLocale === defaultLocale) {\n // Remove the default locale part from the path\n const newPath = originalPath.replace(`/${defaultLocale}`, '') ?? '/';\n rewriteUrl(req, res, newPath, pathLocale);\n return next();\n }\n\n // If we do prefix default or pathLocale != default, keep as is, but rewrite headers\n rewriteUrl(req, res, originalPath, pathLocale);\n return next();\n};\n"],"mappings":"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","names":[]}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var intlayerPlugin_exports = {};
|
|
30
|
-
__export(intlayerPlugin_exports, {
|
|
31
|
-
intlayerPlugin: () => intlayerPlugin
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(intlayerPlugin_exports);
|
|
34
|
-
var import_path = require("path");
|
|
35
|
-
var import_process = __toESM(require("process"));
|
|
36
|
-
var import_chokidar = require("@intlayer/chokidar");
|
|
37
|
-
var import_config = require("@intlayer/config");
|
|
38
|
-
var import_vite = require("vite");
|
|
39
|
-
const intlayerPlugin = (_pluginOptions = {}) => ({
|
|
40
|
-
name: "vite-intlayer-plugin",
|
|
41
|
-
config: (config, { mode }) => {
|
|
42
|
-
const intlayerConfig = (0, import_config.getConfiguration)();
|
|
43
|
-
const { mainDir, baseDir, watch: isWatchMode } = intlayerConfig.content;
|
|
44
|
-
const env = (0, import_config.formatEnvVariable)("vite");
|
|
45
|
-
import_process.default.env = {
|
|
46
|
-
...import_process.default.env,
|
|
47
|
-
...(0, import_vite.loadEnv)(mode, import_process.default.cwd()),
|
|
48
|
-
...env
|
|
49
|
-
};
|
|
50
|
-
const dictionariesPath = (0, import_path.join)(mainDir, "dictionaries.mjs");
|
|
51
|
-
const relativeDictionariesPath = (0, import_path.relative)(baseDir, dictionariesPath);
|
|
52
|
-
config.resolve = {
|
|
53
|
-
...config.resolve,
|
|
54
|
-
alias: {
|
|
55
|
-
...config.resolve?.alias,
|
|
56
|
-
"@intlayer/dictionaries-entry": (0, import_path.resolve)(relativeDictionariesPath)
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
if (isWatchMode) {
|
|
60
|
-
config.optimizeDeps = {
|
|
61
|
-
...config.optimizeDeps,
|
|
62
|
-
exclude: [
|
|
63
|
-
...config.optimizeDeps?.exclude || [],
|
|
64
|
-
"@intlayer/dictionaries-entry"
|
|
65
|
-
]
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
const externals = config.build?.rollupOptions?.external ?? [];
|
|
69
|
-
config.build = {
|
|
70
|
-
...config.build,
|
|
71
|
-
rollupOptions: {
|
|
72
|
-
...config.build?.rollupOptions,
|
|
73
|
-
external: [...externals, "module"]
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
return config;
|
|
77
|
-
},
|
|
78
|
-
buildStart: () => {
|
|
79
|
-
(0, import_chokidar.watch)();
|
|
80
|
-
},
|
|
81
|
-
configureServer: () => {
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
-
0 && (module.exports = {
|
|
86
|
-
intlayerPlugin
|
|
87
|
-
});
|
|
88
|
-
//# sourceMappingURL=intlayerPlugin.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/vite/intlayerPlugin.ts"],"sourcesContent":["import { join, relative, resolve } from 'path';\nimport process from 'process';\nimport { watch } from '@intlayer/chokidar';\nimport { getConfiguration, formatEnvVariable } from '@intlayer/config';\n// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport { loadEnv, type Plugin } from 'vite';\n\n// Plugin options type definition\ntype PluginOptions = {\n // Custom options for your plugin, if any\n};\n\n/**\n *\n * A Vite plugin that integrates IntLayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayerPlugin() ],\n * });\n * ```\n * */\nexport const intlayerPlugin = (_pluginOptions: PluginOptions = {}): Plugin => ({\n name: 'vite-intlayer-plugin',\n\n config: (config, { mode }) => {\n const intlayerConfig = getConfiguration();\n const { mainDir, baseDir, watch: isWatchMode } = intlayerConfig.content;\n\n // Set all configuration values as environment variables\n const env = formatEnvVariable('vite');\n\n process.env = {\n ...process.env,\n ...loadEnv(mode, process.cwd()),\n ...env,\n };\n\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n // Update Vite's resolve alias\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve?.alias,\n '@intlayer/dictionaries-entry': resolve(relativeDictionariesPath),\n },\n };\n\n if (isWatchMode) {\n // Ajout de l'option optimizeDeps.exclude\n config.optimizeDeps = {\n ...config.optimizeDeps,\n exclude: [\n ...(config.optimizeDeps?.exclude || []),\n '@intlayer/dictionaries-entry',\n ],\n };\n }\n\n const externals: string[] = (config.build?.rollupOptions?.external ??\n []) as string[];\n\n config.build = {\n ...config.build,\n rollupOptions: {\n ...config.build?.rollupOptions,\n external: [...externals, 'module'],\n },\n };\n\n return config;\n },\n\n buildStart: () => {\n // Code to run when Vite build starts\n watch();\n },\n configureServer: () => {\n // Custom server configuration, if needed\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwC;AACxC,qBAAoB;AACpB,sBAAsB;AACtB,oBAAoD;AAEpD,kBAAqC;AAkB9B,MAAM,iBAAiB,CAAC,iBAAgC,CAAC,OAAe;AAAA,EAC7E,MAAM;AAAA,EAEN,QAAQ,CAAC,QAAQ,EAAE,KAAK,MAAM;AAC5B,UAAM,qBAAiB,gCAAiB;AACxC,UAAM,EAAE,SAAS,SAAS,OAAO,YAAY,IAAI,eAAe;AAGhE,UAAM,UAAM,iCAAkB,MAAM;AAEpC,mBAAAA,QAAQ,MAAM;AAAA,MACZ,GAAG,eAAAA,QAAQ;AAAA,MACX,OAAG,qBAAQ,MAAM,eAAAA,QAAQ,IAAI,CAAC;AAAA,MAC9B,GAAG;AAAA,IACL;AAEA,UAAM,uBAAmB,kBAAK,SAAS,kBAAkB;AACzD,UAAM,+BAA2B,sBAAS,SAAS,gBAAgB;AAGnE,WAAO,UAAU;AAAA,MACf,GAAG,OAAO;AAAA,MACV,OAAO;AAAA,QACL,GAAG,OAAO,SAAS;AAAA,QACnB,oCAAgC,qBAAQ,wBAAwB;AAAA,MAClE;AAAA,IACF;AAEA,QAAI,aAAa;AAEf,aAAO,eAAe;AAAA,QACpB,GAAG,OAAO;AAAA,QACV,SAAS;AAAA,UACP,GAAI,OAAO,cAAc,WAAW,CAAC;AAAA,UACrC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,YAAuB,OAAO,OAAO,eAAe,YACxD,CAAC;AAEH,WAAO,QAAQ;AAAA,MACb,GAAG,OAAO;AAAA,MACV,eAAe;AAAA,QACb,GAAG,OAAO,OAAO;AAAA,QACjB,UAAU,CAAC,GAAG,WAAW,QAAQ;AAAA,MACnC;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,MAAM;AAEhB,+BAAM;AAAA,EACR;AAAA,EACA,iBAAiB,MAAM;AAAA,EAEvB;AACF;","names":["process"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
__commonJS
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=chunk-ZD7AOCMD.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { ESMxCJSRequire, appLogger } from "@intlayer/config";
|
|
3
|
-
import spawn from "cross-spawn";
|
|
4
|
-
const args = process.argv.slice(2);
|
|
5
|
-
const scriptIndex = args.findIndex(
|
|
6
|
-
(x) => x === "build" || x === "start" || x === "test"
|
|
7
|
-
);
|
|
8
|
-
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
|
|
9
|
-
switch (script) {
|
|
10
|
-
case "build":
|
|
11
|
-
case "start":
|
|
12
|
-
case "test": {
|
|
13
|
-
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
|
|
14
|
-
const scriptPath = ESMxCJSRequire.resolve(
|
|
15
|
-
`@craco/craco/dist/scripts/${script}`
|
|
16
|
-
);
|
|
17
|
-
const scriptArgs = args.slice(scriptIndex + 1);
|
|
18
|
-
const processArgs = nodeArgs.concat(scriptPath).concat([
|
|
19
|
-
...scriptArgs,
|
|
20
|
-
"--config",
|
|
21
|
-
"./node_modules/react-intlayer/dist/cjs/craco/craco.config.cjs"
|
|
22
|
-
]);
|
|
23
|
-
const child = spawn.sync("node", processArgs, {
|
|
24
|
-
stdio: "inherit"
|
|
25
|
-
});
|
|
26
|
-
if (child.signal) {
|
|
27
|
-
if (child.signal === "SIGKILL") {
|
|
28
|
-
appLogger(`
|
|
29
|
-
The build failed because the process exited too early.
|
|
30
|
-
This probably means the system ran out of memory or someone called
|
|
31
|
-
\`kill -9\` on the process.
|
|
32
|
-
`);
|
|
33
|
-
} else if (child.signal === "SIGTERM") {
|
|
34
|
-
appLogger(`
|
|
35
|
-
The build failed because the process exited too early.
|
|
36
|
-
Someone might have called \`kill\` or \`killall\`, or the system could
|
|
37
|
-
be shutting down.
|
|
38
|
-
`);
|
|
39
|
-
}
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
process.exit(child.status ?? void 0);
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
default:
|
|
46
|
-
appLogger(`Unknown script "${script}".`);
|
|
47
|
-
appLogger("Perhaps you need to update craco?");
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=react-intlayer.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/cli/react-intlayer.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * To make the setup easier, we are using craco to override the webpack configuration.\n * This script is used to run the craco scripts with the custom configuration.\n *\n * The script is based on the original craco script from create-react-app.\n */\n\nimport { ESMxCJSRequire, appLogger } from '@intlayer/config';\nimport spawn from 'cross-spawn';\n\nconst args = process.argv.slice(2);\nconst scriptIndex = args.findIndex(\n (x) => x === 'build' || x === 'start' || x === 'test'\n);\nconst script = scriptIndex === -1 ? args[0] : args[scriptIndex];\n\nswitch (script) {\n case 'build':\n case 'start':\n case 'test': {\n const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];\n const scriptPath = ESMxCJSRequire.resolve(\n `@craco/craco/dist/scripts/${script}`\n );\n\n const scriptArgs = args.slice(scriptIndex + 1);\n const processArgs = nodeArgs\n .concat(scriptPath)\n .concat([\n ...scriptArgs,\n '--config',\n './node_modules/react-intlayer/dist/cjs/craco/craco.config.cjs',\n ]);\n\n const child = spawn.sync('node', processArgs, {\n stdio: 'inherit',\n });\n\n if (child.signal) {\n if (child.signal === 'SIGKILL') {\n appLogger(`\n The build failed because the process exited too early.\n This probably means the system ran out of memory or someone called\n \\`kill -9\\` on the process.\n `);\n } else if (child.signal === 'SIGTERM') {\n appLogger(`\n The build failed because the process exited too early.\n Someone might have called \\`kill\\` or \\`killall\\`, or the system could\n be shutting down.\n `);\n }\n\n process.exit(1);\n }\n\n process.exit(child.status ?? undefined);\n break;\n }\n default:\n appLogger(`Unknown script \"${script}\".`);\n appLogger('Perhaps you need to update craco?');\n break;\n}\n"],"mappings":";AASA,SAAS,gBAAgB,iBAAiB;AAC1C,OAAO,WAAW;AAElB,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,MAAM,cAAc,KAAK;AAAA,EACvB,CAAC,MAAM,MAAM,WAAW,MAAM,WAAW,MAAM;AACjD;AACA,MAAM,SAAS,gBAAgB,KAAK,KAAK,CAAC,IAAI,KAAK,WAAW;AAE9D,QAAQ,QAAQ;AAAA,EACd,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK,QAAQ;AACX,UAAM,WAAW,cAAc,IAAI,KAAK,MAAM,GAAG,WAAW,IAAI,CAAC;AACjE,UAAM,aAAa,eAAe;AAAA,MAChC,6BAA6B,MAAM;AAAA,IACrC;AAEA,UAAM,aAAa,KAAK,MAAM,cAAc,CAAC;AAC7C,UAAM,cAAc,SACjB,OAAO,UAAU,EACjB,OAAO;AAAA,MACN,GAAG;AAAA,MACH;AAAA,MACA;AAAA,IACF,CAAC;AAEH,UAAM,QAAQ,MAAM,KAAK,QAAQ,aAAa;AAAA,MAC5C,OAAO;AAAA,IACT,CAAC;AAED,QAAI,MAAM,QAAQ;AAChB,UAAI,MAAM,WAAW,WAAW;AAC9B,kBAAU;AAAA;AAAA;AAAA;AAAA,aAIL;AAAA,MACP,WAAW,MAAM,WAAW,WAAW;AACrC,kBAAU;AAAA;AAAA;AAAA;AAAA,aAIL;AAAA,MACP;AAEA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAEA,YAAQ,KAAK,MAAM,UAAU,MAAS;AACtC;AAAA,EACF;AAAA,EACA;AACE,cAAU,mBAAmB,MAAM,IAAI;AACvC,cAAU,mCAAmC;AAC7C;AACJ;","names":[]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__commonJS
|
|
3
|
-
} from '../chunk-ZD7AOCMD.mjs';
|
|
4
|
-
import * as intlayerPlugin from './intlayerCracoPlugin.mjs';
|
|
5
|
-
var require_craco_config = __commonJS({
|
|
6
|
-
"src/craco/craco.config.ts"(exports, module) {
|
|
7
|
-
module.exports = {
|
|
8
|
-
plugins: [
|
|
9
|
-
{
|
|
10
|
-
plugin: intlayerPlugin
|
|
11
|
-
}
|
|
12
|
-
]
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
export default require_craco_config();
|
|
17
|
-
//# sourceMappingURL=craco.config.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/craco/craco.config.ts"],"sourcesContent":["import type { CracoConfig, CracoPlugin } from '@craco/types';\nimport * as intlayerPlugin from './intlayerCracoPlugin';\n\n// Usage Example\nmodule.exports = {\n plugins: [\n {\n plugin: intlayerPlugin as CracoPlugin,\n },\n ],\n} satisfies CracoConfig;\n"],"mappings":";;;AACA,YAAY,oBAAoB;AADhC;AAAA;AAIA,WAAO,UAAU;AAAA,MACf,SAAS;AAAA,QACP;AAAA,UACE,QAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAAA;AAAA;","names":[]}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import "../chunk-ZD7AOCMD.mjs";
|
|
2
|
-
import { resolve, relative, join } from "path";
|
|
3
|
-
import {
|
|
4
|
-
getConfiguration,
|
|
5
|
-
formatEnvVariable,
|
|
6
|
-
ESMxCJSRequire
|
|
7
|
-
} from "@intlayer/config";
|
|
8
|
-
import { IntLayerPlugin as IntLayerWebpackPlugin } from "@intlayer/webpack";
|
|
9
|
-
import {
|
|
10
|
-
EnvironmentPlugin
|
|
11
|
-
} from "webpack";
|
|
12
|
-
import { removeUndefinedValueObject } from '../utils/removeUndefinedValueObject.mjs';
|
|
13
|
-
const intlayerConfig = getConfiguration();
|
|
14
|
-
const env = formatEnvVariable("react_app");
|
|
15
|
-
const overrideWebpackConfig = ({
|
|
16
|
-
webpackConfig
|
|
17
|
-
}) => {
|
|
18
|
-
webpackConfig.externals = {
|
|
19
|
-
...typeof webpackConfig.externals === "object" ? webpackConfig.externals : {},
|
|
20
|
-
esbuild: "esbuild",
|
|
21
|
-
module: "module",
|
|
22
|
-
fs: "fs",
|
|
23
|
-
vm: "vm"
|
|
24
|
-
};
|
|
25
|
-
(webpackConfig.module?.rules ?? []).push({
|
|
26
|
-
test: /\.node$/,
|
|
27
|
-
use: "node-loader"
|
|
28
|
-
});
|
|
29
|
-
return webpackConfig;
|
|
30
|
-
};
|
|
31
|
-
const overrideCracoConfig = ({
|
|
32
|
-
cracoConfig
|
|
33
|
-
}) => {
|
|
34
|
-
const { mainDir, baseDir } = intlayerConfig.content;
|
|
35
|
-
const dictionariesPath = join(mainDir, "dictionaries.mjs");
|
|
36
|
-
const relativeDictionariesPath = relative(baseDir, dictionariesPath);
|
|
37
|
-
return {
|
|
38
|
-
...cracoConfig,
|
|
39
|
-
webpack: {
|
|
40
|
-
...cracoConfig.webpack,
|
|
41
|
-
plugins: {
|
|
42
|
-
...cracoConfig.webpack?.plugins,
|
|
43
|
-
add: [
|
|
44
|
-
new EnvironmentPlugin(removeUndefinedValueObject(env)),
|
|
45
|
-
new IntLayerWebpackPlugin()
|
|
46
|
-
]
|
|
47
|
-
},
|
|
48
|
-
configure: {
|
|
49
|
-
...cracoConfig.webpack?.configure ?? {},
|
|
50
|
-
resolve: {
|
|
51
|
-
...cracoConfig.webpack?.configure?.resolve ?? {},
|
|
52
|
-
fallback: {
|
|
53
|
-
...cracoConfig.webpack?.configure?.resolve?.fallback ?? {},
|
|
54
|
-
process: ESMxCJSRequire.resolve("process/browser")
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
alias: {
|
|
59
|
-
...cracoConfig.webpack?.alias,
|
|
60
|
-
"@intlayer/dictionaries-entry": resolve("./", relativeDictionariesPath)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
const plugin = {
|
|
66
|
-
overrideCracoConfig,
|
|
67
|
-
overrideWebpackConfig
|
|
68
|
-
};
|
|
69
|
-
export {
|
|
70
|
-
overrideCracoConfig,
|
|
71
|
-
overrideWebpackConfig,
|
|
72
|
-
plugin
|
|
73
|
-
};
|
|
74
|
-
//# sourceMappingURL=intlayerCracoPlugin.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/craco/intlayerCracoPlugin.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\n// @ts-nocheck\n\nimport { resolve, relative, join } from 'path';\nimport type {\n CracoConfig,\n CracoConfigOverride,\n CracoPlugin,\n WebpackConfigOverride,\n} from '@craco/types';\nimport {\n getConfiguration,\n formatEnvVariable,\n ESMxCJSRequire,\n} from '@intlayer/config';\nimport { IntLayerPlugin as IntLayerWebpackPlugin } from '@intlayer/webpack';\nimport {\n type Configuration as WebpackConfig,\n EnvironmentPlugin,\n} from 'webpack';\nimport { removeUndefinedValueObject } from '../utils/removeUndefinedValueObject';\n\n// Get IntLayer configuration\nconst intlayerConfig = getConfiguration();\n\n// Format environment variables\nconst env: Record<string, string> = formatEnvVariable('react_app');\n\n// Custom CRACO plugin function to override webpack configuration\nexport const overrideWebpackConfig = ({\n webpackConfig,\n}: WebpackConfigOverride): WebpackConfig => {\n webpackConfig.externals = {\n ...(typeof webpackConfig.externals === 'object'\n ? webpackConfig.externals\n : {}),\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n vm: 'vm',\n };\n\n (webpackConfig.module?.rules ?? []).push({\n test: /\\.node$/,\n use: 'node-loader',\n });\n\n // You can add any custom CRACO plugins here if needed\n // config.plugins.push(new CustomCracoPlugin());\n\n return webpackConfig;\n};\n\n// Return a CRACO configuration object\nexport const overrideCracoConfig = ({\n cracoConfig,\n}: CracoConfigOverride): CracoConfig => {\n const { mainDir, baseDir } = intlayerConfig.content;\n\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n return {\n ...cracoConfig,\n webpack: {\n ...cracoConfig.webpack,\n plugins: {\n ...cracoConfig.webpack?.plugins,\n add: [\n new EnvironmentPlugin(removeUndefinedValueObject(env)),\n new IntLayerWebpackPlugin(),\n ],\n },\n configure: {\n ...(cracoConfig.webpack?.configure ?? {}),\n resolve: {\n ...(cracoConfig.webpack?.configure?.resolve ?? {}),\n fallback: {\n ...(cracoConfig.webpack?.configure?.resolve?.fallback ?? {}),\n process: ESMxCJSRequire.resolve('process/browser'),\n },\n },\n },\n\n alias: {\n ...cracoConfig.webpack?.alias,\n '@intlayer/dictionaries-entry': resolve('./', relativeDictionariesPath),\n },\n },\n };\n};\n\n/**\n * A CRACO plugin that adds the IntLayer configuration to the webpack configuration and sets the environment variables.\n *\n * Usage:\n *\n * ```ts\n * const cracoConfig: CracoConfig = {\n * plugins: [\n * {\n * plugin: intlayerCracoPlugin(),\n * },\n * ],\n * };\n *\n * export default cracoConfig;\n * ```\n *\n */\nexport const plugin: CracoPlugin = {\n overrideCracoConfig,\n overrideWebpackConfig,\n};\n"],"mappings":";AAGA,SAAS,SAAS,UAAU,YAAY;AAOxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB,6BAA6B;AACxD;AAAA,EAEE;AAAA,OACK;AACP,SAAS,kCAAkC;AAG3C,MAAM,iBAAiB,iBAAiB;AAGxC,MAAM,MAA8B,kBAAkB,WAAW;AAG1D,MAAM,wBAAwB,CAAC;AAAA,EACpC;AACF,MAA4C;AAC1C,gBAAc,YAAY;AAAA,IACxB,GAAI,OAAO,cAAc,cAAc,WACnC,cAAc,YACd,CAAC;AAAA,IACL,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,IAAI;AAAA,IACJ,IAAI;AAAA,EACN;AAEA,GAAC,cAAc,QAAQ,SAAS,CAAC,GAAG,KAAK;AAAA,IACvC,MAAM;AAAA,IACN,KAAK;AAAA,EACP,CAAC;AAKD,SAAO;AACT;AAGO,MAAM,sBAAsB,CAAC;AAAA,EAClC;AACF,MAAwC;AACtC,QAAM,EAAE,SAAS,QAAQ,IAAI,eAAe;AAE5C,QAAM,mBAAmB,KAAK,SAAS,kBAAkB;AACzD,QAAM,2BAA2B,SAAS,SAAS,gBAAgB;AAEnE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,SAAS;AAAA,MACP,GAAG,YAAY;AAAA,MACf,SAAS;AAAA,QACP,GAAG,YAAY,SAAS;AAAA,QACxB,KAAK;AAAA,UACH,IAAI,kBAAkB,2BAA2B,GAAG,CAAC;AAAA,UACrD,IAAI,sBAAsB;AAAA,QAC5B;AAAA,MACF;AAAA,MACA,WAAW;AAAA,QACT,GAAI,YAAY,SAAS,aAAa,CAAC;AAAA,QACvC,SAAS;AAAA,UACP,GAAI,YAAY,SAAS,WAAW,WAAW,CAAC;AAAA,UAChD,UAAU;AAAA,YACR,GAAI,YAAY,SAAS,WAAW,SAAS,YAAY,CAAC;AAAA,YAC1D,SAAS,eAAe,QAAQ,iBAAiB;AAAA,UACnD;AAAA,QACF;AAAA,MACF;AAAA,MAEA,OAAO;AAAA,QACL,GAAG,YAAY,SAAS;AAAA,QACxB,gCAAgC,QAAQ,MAAM,wBAAwB;AAAA,MACxE;AAAA,IACF;AAAA,EACF;AACF;AAoBO,MAAM,SAAsB;AAAA,EACjC;AAAA,EACA;AACF;","names":[]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import "../chunk-ZD7AOCMD.mjs";
|
|
2
|
-
const removeUndefinedValueObject = (obj) => {
|
|
3
|
-
const newObj = {};
|
|
4
|
-
for (const key in obj) {
|
|
5
|
-
if (obj[key] !== void 0) {
|
|
6
|
-
newObj[key] = obj[key];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
Object.freeze(newObj);
|
|
10
|
-
return newObj;
|
|
11
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
removeUndefinedValueObject
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=removeUndefinedValueObject.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/removeUndefinedValueObject.ts"],"sourcesContent":["export const removeUndefinedValueObject = <T extends Record<string, unknown>>(\n obj: T\n): T => {\n const newObj: T = {} as T;\n\n for (const key in obj) {\n if (obj[key] !== undefined) {\n newObj[key] = obj[key];\n }\n }\n\n Object.freeze(newObj);\n\n return newObj;\n};\n"],"mappings":";AAAO,MAAM,6BAA6B,CACxC,QACM;AACN,QAAM,SAAY,CAAC;AAEnB,aAAW,OAAO,KAAK;AACrB,QAAI,IAAI,GAAG,MAAM,QAAW;AAC1B,aAAO,GAAG,IAAI,IAAI,GAAG;AAAA,IACvB;AAAA,EACF;AAEA,SAAO,OAAO,MAAM;AAEpB,SAAO;AACT;","names":[]}
|
package/dist/esm/vite/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/vite/index.ts"],"sourcesContent":["export * from './intlayerPlugin';\nexport * from './intlayerMiddlewarePlugin';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|