@inlang/paraglide-js 2.7.2 → 2.8.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/README.md +42 -47
- package/dist/bundler-plugins/unplugin.d.ts.map +1 -1
- package/dist/bundler-plugins/unplugin.js +30 -36
- package/dist/bundler-plugins/unplugin.js.map +1 -1
- package/dist/cli/commands/compile/command.d.ts.map +1 -1
- package/dist/cli/commands/compile/command.js +160 -17
- package/dist/cli/commands/compile/command.js.map +1 -1
- package/dist/cli/commands/init/command.d.ts.map +1 -1
- package/dist/cli/commands/init/command.js +7 -11
- package/dist/cli/commands/init/command.js.map +1 -1
- package/dist/cli/steps/check-for-uncomitted-changes.d.ts.map +1 -1
- package/dist/cli/steps/check-for-uncomitted-changes.js +2 -2
- package/dist/cli/steps/check-for-uncomitted-changes.js.map +1 -1
- package/dist/cli/steps/maybe-add-sherlock.d.ts.map +1 -1
- package/dist/cli/steps/maybe-add-sherlock.js +9 -3
- package/dist/cli/steps/maybe-add-sherlock.js.map +1 -1
- package/dist/cli/steps/prompt-for-outdir.js +1 -1
- package/dist/cli/steps/prompt-for-outdir.js.map +1 -1
- package/dist/compiler/compile-message.test.js +22 -0
- package/dist/compiler/compile-message.test.js.map +1 -1
- package/dist/compiler/compile-project.d.ts +2 -1
- package/dist/compiler/compile-project.d.ts.map +1 -1
- package/dist/compiler/compile-project.js +5 -1
- package/dist/compiler/compile-project.js.map +1 -1
- package/dist/compiler/compile-project.test.js +53 -0
- package/dist/compiler/compile-project.test.js.map +1 -1
- package/dist/compiler/compile.d.ts.map +1 -1
- package/dist/compiler/compile.js +1 -0
- package/dist/compiler/compile.js.map +1 -1
- package/dist/compiler/compile.test.js +26 -0
- package/dist/compiler/compile.test.js.map +1 -1
- package/dist/compiler/compiler-options.d.ts +18 -0
- package/dist/compiler/compiler-options.d.ts.map +1 -1
- package/dist/compiler/compiler-options.js +1 -0
- package/dist/compiler/compiler-options.js.map +1 -1
- package/dist/compiler/create-readme.d.ts +10 -0
- package/dist/compiler/create-readme.d.ts.map +1 -0
- package/dist/compiler/create-readme.js +104 -0
- package/dist/compiler/create-readme.js.map +1 -0
- package/dist/compiler/runtime/create-runtime.js +7 -1
- package/dist/compiler/runtime/create-runtime.js.map +1 -1
- package/dist/compiler/server/create-server-file.js +7 -1
- package/dist/compiler/server/create-server-file.js.map +1 -1
- package/dist/compiler/server/middleware.d.ts +40 -4
- package/dist/compiler/server/middleware.d.ts.map +1 -1
- package/dist/compiler/server/middleware.js +40 -4
- package/dist/compiler/server/middleware.js.map +1 -1
- package/dist/services/env-variables/index.js +1 -1
- package/dist/services/file-watching/tracked-fs.d.ts +26 -0
- package/dist/services/file-watching/tracked-fs.d.ts.map +1 -0
- package/dist/services/file-watching/tracked-fs.js +92 -0
- package/dist/services/file-watching/tracked-fs.js.map +1 -0
- package/dist/services/file-watching/tracked-fs.test.d.ts +2 -0
- package/dist/services/file-watching/tracked-fs.test.d.ts.map +1 -0
- package/dist/services/file-watching/tracked-fs.test.js +90 -0
- package/dist/services/file-watching/tracked-fs.test.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the README.md content for the compiled output.
|
|
3
|
+
*
|
|
4
|
+
* This helps LLMs understand the compiled Paraglide JS output.
|
|
5
|
+
* See https://llmstxt.org/ for the format guidelines.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createReadme(args: {
|
|
8
|
+
projectPath?: string;
|
|
9
|
+
}): string;
|
|
10
|
+
//# sourceMappingURL=create-readme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-readme.d.ts","sourceRoot":"","sources":["../../src/compiler/create-readme.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAiGnE"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the README.md content for the compiled output.
|
|
3
|
+
*
|
|
4
|
+
* This helps LLMs understand the compiled Paraglide JS output.
|
|
5
|
+
* See https://llmstxt.org/ for the format guidelines.
|
|
6
|
+
*/
|
|
7
|
+
export function createReadme(args) {
|
|
8
|
+
const compiledFromLine = args.projectPath
|
|
9
|
+
? `\nCompiled from: \`${args.projectPath}\`\n`
|
|
10
|
+
: "";
|
|
11
|
+
return `# Paraglide JS Compiled Output
|
|
12
|
+
|
|
13
|
+
> Auto-generated i18n message functions. Import \`messages.js\` to use translated strings.
|
|
14
|
+
${compiledFromLine}
|
|
15
|
+
|
|
16
|
+
## What is this folder?
|
|
17
|
+
|
|
18
|
+
This folder contains compiled [Paraglide JS](https://github.com/opral/paraglide-js) output. Paraglide JS compiles your translation messages into tree-shakeable JavaScript functions.
|
|
19
|
+
|
|
20
|
+
## At a glance
|
|
21
|
+
|
|
22
|
+
Purpose:
|
|
23
|
+
- This folder stores compiled i18n message functions.
|
|
24
|
+
- Source translations live outside this folder in your inlang project.
|
|
25
|
+
|
|
26
|
+
Safe to import:
|
|
27
|
+
- \`messages.js\` — all message functions
|
|
28
|
+
- \`runtime.js\` — locale utilities
|
|
29
|
+
- \`server.js\` — server-side middleware
|
|
30
|
+
|
|
31
|
+
Do not edit:
|
|
32
|
+
- All files in this folder are auto-generated.
|
|
33
|
+
- Changes will be overwritten on next compilation.
|
|
34
|
+
|
|
35
|
+
\`\`\`
|
|
36
|
+
paraglide/
|
|
37
|
+
├── messages.js # Message exports (import this)
|
|
38
|
+
├── messages/ # Individual message functions
|
|
39
|
+
├── runtime.js # Locale detection & configuration
|
|
40
|
+
├── registry.js # Formatting utilities (plural, number, datetime)
|
|
41
|
+
├── server.js # Server-side middleware
|
|
42
|
+
└── .gitignore # Marks folder as generated
|
|
43
|
+
\`\`\`
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
\`\`\`js
|
|
48
|
+
import * as m from "./paraglide/messages.js";
|
|
49
|
+
|
|
50
|
+
// Messages are functions that return localized strings
|
|
51
|
+
m.hello_world(); // "Hello, World!" (in current locale)
|
|
52
|
+
m.greeting({ name: "Sam" }); // "Hello, Sam!"
|
|
53
|
+
|
|
54
|
+
// Override locale per-call
|
|
55
|
+
m.hello_world({}, { locale: "de" }); // "Hallo, Welt!"
|
|
56
|
+
m.greeting({ name: "Sam" }, { locale: "de" }); // "Hallo, Sam!"
|
|
57
|
+
\`\`\`
|
|
58
|
+
|
|
59
|
+
## Runtime API
|
|
60
|
+
|
|
61
|
+
\`\`\`js
|
|
62
|
+
import { getLocale, setLocale, locales, baseLocale } from "./paraglide/runtime.js";
|
|
63
|
+
|
|
64
|
+
getLocale(); // Current locale, e.g., "en"
|
|
65
|
+
setLocale("de"); // Set locale
|
|
66
|
+
locales; // Available locales, e.g., ["en", "de", "fr"]
|
|
67
|
+
baseLocale; // Default locale, e.g., "en"
|
|
68
|
+
\`\`\`
|
|
69
|
+
|
|
70
|
+
## Strategy
|
|
71
|
+
|
|
72
|
+
The strategy determines how the current locale is detected and persisted:
|
|
73
|
+
|
|
74
|
+
- **Cookie**: Stores locale preference in a cookie.
|
|
75
|
+
- **URL**: Derives locale from URL patterns (e.g., \`/en/about\`, \`en.example.com\`).
|
|
76
|
+
- **GlobalVariable**: Uses a global variable (client-side only).
|
|
77
|
+
- **BaseLocale**: Always returns the base locale.
|
|
78
|
+
|
|
79
|
+
Strategies can be combined. The order defines precedence:
|
|
80
|
+
|
|
81
|
+
\`\`\`js
|
|
82
|
+
await compile({
|
|
83
|
+
project: "./project.inlang",
|
|
84
|
+
outdir: "./src/paraglide",
|
|
85
|
+
strategy: ["url", "cookie", "baseLocale"],
|
|
86
|
+
});
|
|
87
|
+
\`\`\`
|
|
88
|
+
|
|
89
|
+
See the [strategy documentation](https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy) for details.
|
|
90
|
+
|
|
91
|
+
## Key concepts
|
|
92
|
+
|
|
93
|
+
- **Tree-shakeable**: Each message is a function, enabling [up to 70% smaller bundles](https://inlang.com/m/gerre34r/library-inlang-paraglideJs/benchmark) than traditional i18n libraries.
|
|
94
|
+
- **Typesafe**: Full TypeScript/JSDoc support with autocomplete.
|
|
95
|
+
- **Variants**: Messages can have variants for pluralization, gender, etc.
|
|
96
|
+
- **Fallbacks**: Missing translations fall back to the base locale.
|
|
97
|
+
|
|
98
|
+
## Links
|
|
99
|
+
|
|
100
|
+
- [Paraglide JS Documentation](https://inlang.com/m/gerre34r/library-inlang-paraglideJs)
|
|
101
|
+
- [Source Repository](https://github.com/opral/paraglide-js)
|
|
102
|
+
`;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=create-readme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-readme.js","sourceRoot":"","sources":["../../src/compiler/create-readme.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAA8B;IAC1D,MAAM,gBAAgB,GAAG,IAAI,CAAC,WAAW;QACxC,CAAC,CAAC,sBAAsB,IAAI,CAAC,WAAW,MAAM;QAC9C,CAAC,CAAC,EAAE,CAAC;IAEN,OAAO;;;EAGN,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwFjB,CAAC;AACF,CAAC"}
|
|
@@ -153,6 +153,12 @@ function injectCode(path) {
|
|
|
153
153
|
const code = fs.readFileSync(new URL(path, import.meta.url), "utf-8");
|
|
154
154
|
// Regex to match single-line and multi-line imports
|
|
155
155
|
const importRegex = /import\s+[\s\S]*?from\s+['"][^'"]+['"]\s*;?/g;
|
|
156
|
-
|
|
156
|
+
const sourceMapRegex = /\/\/# sourceMappingURL=.*$/gm;
|
|
157
|
+
const blockSourceMapRegex = /\/\*# sourceMappingURL=.*?\*\//g;
|
|
158
|
+
return code
|
|
159
|
+
.replace(importRegex, "")
|
|
160
|
+
.replace(sourceMapRegex, "")
|
|
161
|
+
.replace(blockSourceMapRegex, "")
|
|
162
|
+
.trim();
|
|
157
163
|
}
|
|
158
164
|
//# sourceMappingURL=create-runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-runtime.js","sourceRoot":"","sources":["../../../src/compiler/runtime/create-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzB;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAgBjC;IACA,MAAM,WAAW,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,IAAI,EAAE,CAAC;IAE3D,IAAI,qBAAqB,GAAG,KAAK,CAAC;IAElC,+DAA+D;IAC/D,IAAI,IAAI,CAAC,eAAe,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACpD,qBAAqB,GAAG,IAAI,CAAC;QAC7B,WAAW,CAAC,IAAI,CAAC;YAChB,OAAO,EAAE,2CAA2C;YACpD,SAAS,EAAE,EAAE;SACb,CAAC,CAAC;QACH,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACnC,IAAI,MAAM,KAAK,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChC,SAAS;YACV,CAAC;YACD,WAAW,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,IAAI,CAAC;gBAC9B,MAAM;gBACN,kCAAkC,MAAM,aAAa;aACrD,CAAC,CAAC;QACJ,CAAC;QACD,WAAW,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,IAAI,CAAC;YAC9B,IAAI,CAAC,UAAU;YACf,2CAA2C;SAC3C,CAAC,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,GAAG;EACZ,qBAAqB,CAAC,CAAC,CAAC,2CAA2C,CAAC,CAAC,CAAC,oDAAoD;;EAE1H,UAAU,CAAC,gBAAgB,CAAC;SAC5B,OAAO,CACP,i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,WAAW,GAAG,8CAA8C,CAAC;IACnE,MAAM,cAAc,GAAG,8BAA8B,CAAC;IACtD,MAAM,mBAAmB,GAAG,iCAAiC,CAAC;IAC9D,OAAO,IAAI;SACT,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;SACxB,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;SAC3B,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;SAChC,IAAI,EAAE,CAAC;AACV,CAAC"}
|
|
@@ -43,6 +43,12 @@ function injectCode(path) {
|
|
|
43
43
|
const code = fs.readFileSync(new URL(path, import.meta.url), "utf-8");
|
|
44
44
|
// Regex to match single-line and multi-line imports
|
|
45
45
|
const importRegex = /import\s+[\s\S]*?from\s+['"][^'"]+['"]\s*;?/g;
|
|
46
|
-
|
|
46
|
+
const sourceMapRegex = /\/\/# sourceMappingURL=.*$/gm;
|
|
47
|
+
const blockSourceMapRegex = /\/\*# sourceMappingURL=.*?\*\//g;
|
|
48
|
+
return code
|
|
49
|
+
.replace(importRegex, "")
|
|
50
|
+
.replace(sourceMapRegex, "")
|
|
51
|
+
.replace(blockSourceMapRegex, "")
|
|
52
|
+
.trim();
|
|
47
53
|
}
|
|
48
54
|
//# sourceMappingURL=create-server-file.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-server-file.js","sourceRoot":"","sources":["../../../src/compiler/server/create-server-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAOhC;IACA,IAAI,IAAI,GAAG;;;EAGV,UAAU,CAAC,iBAAiB,CAAC;CAC9B,CAAC;IAED,IAAI,IAAI,CAAC,eAAe,CAAC,qCAAqC,EAAE,CAAC;QAChE,IAAI,GAAG,IAAI,CAAC,OAAO,CAClB,6BAA6B,EAC7B,2BAA2B,IAAI,CAAC,SA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IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;IACtE,oDAAoD;IACpD,MAAM,WAAW,GAAG,8CAA8C,CAAC;IACnE,MAAM,cAAc,GAAG,8BAA8B,CAAC;IACtD,MAAM,mBAAmB,GAAG,iCAAiC,CAAC;IAC9D,OAAO,IAAI;SACT,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;SACxB,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;SAC3B,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;SAChC,IAAI,EAAE,CAAC;AACV,CAAC"}
|
|
@@ -16,7 +16,11 @@
|
|
|
16
16
|
* @template T - The return type of the resolve function
|
|
17
17
|
*
|
|
18
18
|
* @param {Request} request - The incoming request object
|
|
19
|
-
* @param {(args: { request: Request, locale: import("./runtime.js").Locale }) => T | Promise<T>} resolve - Function to handle the request
|
|
19
|
+
* @param {(args: { request: Request, locale: import("./runtime.js").Locale }) => T | Promise<T>} resolve - Function to handle the request. The callback receives:
|
|
20
|
+
* - `request`: A modified request with a delocalized URL when the URL strategy is used (e.g., `/fr/about` → `/about`).
|
|
21
|
+
* If your framework handles URL localization itself (e.g., TanStack Router's `rewrite` option), use the original
|
|
22
|
+
* request instead to avoid redirect loops.
|
|
23
|
+
* - `locale`: The determined locale for this request.
|
|
20
24
|
* @param {{ onRedirect:(response: Response) => void }} [callbacks] - Callbacks to handle events from middleware
|
|
21
25
|
* @returns {Promise<Response>}
|
|
22
26
|
*
|
|
@@ -24,7 +28,7 @@
|
|
|
24
28
|
* ```typescript
|
|
25
29
|
* // Basic usage in metaframeworks like NextJS, SvelteKit, Astro, Nuxt, etc.
|
|
26
30
|
* export const handle = async ({ event, resolve }) => {
|
|
27
|
-
* return
|
|
31
|
+
* return paraglideMiddleware(event.request, ({ request, locale }) => {
|
|
28
32
|
* // let the framework further resolve the request
|
|
29
33
|
* return resolve(request);
|
|
30
34
|
* });
|
|
@@ -35,7 +39,7 @@
|
|
|
35
39
|
* ```typescript
|
|
36
40
|
* // Usage in a framework like Express JS or Hono
|
|
37
41
|
* app.use(async (req, res, next) => {
|
|
38
|
-
* const result = await
|
|
42
|
+
* const result = await paraglideMiddleware(req, ({ request, locale }) => {
|
|
39
43
|
* // If a redirect happens this won't be called
|
|
40
44
|
* return next(request);
|
|
41
45
|
* });
|
|
@@ -50,7 +54,7 @@
|
|
|
50
54
|
* // one request could leak into another concurrent request.
|
|
51
55
|
* export default {
|
|
52
56
|
* fetch: async (request) => {
|
|
53
|
-
* return
|
|
57
|
+
* return paraglideMiddleware(
|
|
54
58
|
* request,
|
|
55
59
|
* ({ request, locale }) => handleRequest(request, locale),
|
|
56
60
|
* { disableAsyncLocalStorage: true }
|
|
@@ -58,6 +62,38 @@
|
|
|
58
62
|
* }
|
|
59
63
|
* };
|
|
60
64
|
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // Usage with frameworks that handle URL localization/delocalization themselves
|
|
69
|
+
* //
|
|
70
|
+
* // Some frameworks like TanStack Router handle URL localization and delocalization
|
|
71
|
+
* // themselves via their own rewrite APIs (e.g., `rewrite.input`/`rewrite.output`).
|
|
72
|
+
* //
|
|
73
|
+
* // When the framework handles this, the middleware's URL delocalization is not needed.
|
|
74
|
+
* // Using the modified `request` from the callback would cause a redirect loop because
|
|
75
|
+
* // both the middleware and the framework would attempt to delocalize the URL.
|
|
76
|
+
* //
|
|
77
|
+
* // Solution: Pass the original request to the handler instead of the modified one.
|
|
78
|
+
* // The middleware still handles locale detection, cookies, and AsyncLocalStorage context.
|
|
79
|
+
* //
|
|
80
|
+
* // ❌ WRONG - causes redirect loop when framework handles URL rewriting:
|
|
81
|
+
* // paraglideMiddleware(req, ({ request }) => handler.fetch(request))
|
|
82
|
+
* //
|
|
83
|
+
* // ✅ CORRECT - use original request when framework handles URL localization:
|
|
84
|
+
* // paraglideMiddleware(req, () => handler.fetch(req))
|
|
85
|
+
*
|
|
86
|
+
* import { paraglideMiddleware } from './paraglide/server.js'
|
|
87
|
+
* import handler from '@tanstack/react-start/server-entry'
|
|
88
|
+
*
|
|
89
|
+
* export default {
|
|
90
|
+
* fetch(req: Request): Promise<Response> {
|
|
91
|
+
* // TanStack Router handles URL rewriting via deLocalizeUrl/localizeUrl
|
|
92
|
+
* // so we pass the original `req` instead of the modified `request`
|
|
93
|
+
* return paraglideMiddleware(req, () => handler.fetch(req))
|
|
94
|
+
* },
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
61
97
|
*/
|
|
62
98
|
export function paraglideMiddleware<T>(request: Request, resolve: (args: {
|
|
63
99
|
request: Request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/compiler/server/middleware.js"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/compiler/server/middleware.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgGG;AACH,oCAlFa,CAAC,WAEH,OAAO,WACP,CAAC,IAAI,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,cAAc,EAAE,MAAM,CAAA;CAAE,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,cAKrF;IAAE,UAAU,EAAC,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAA;CAAE,GACzC,OAAO,CAAC,QAAQ,CAAC,CAoL7B"}
|
|
@@ -17,7 +17,11 @@ import * as runtime from "./runtime.js";
|
|
|
17
17
|
* @template T - The return type of the resolve function
|
|
18
18
|
*
|
|
19
19
|
* @param {Request} request - The incoming request object
|
|
20
|
-
* @param {(args: { request: Request, locale: import("./runtime.js").Locale }) => T | Promise<T>} resolve - Function to handle the request
|
|
20
|
+
* @param {(args: { request: Request, locale: import("./runtime.js").Locale }) => T | Promise<T>} resolve - Function to handle the request. The callback receives:
|
|
21
|
+
* - `request`: A modified request with a delocalized URL when the URL strategy is used (e.g., `/fr/about` → `/about`).
|
|
22
|
+
* If your framework handles URL localization itself (e.g., TanStack Router's `rewrite` option), use the original
|
|
23
|
+
* request instead to avoid redirect loops.
|
|
24
|
+
* - `locale`: The determined locale for this request.
|
|
21
25
|
* @param {{ onRedirect:(response: Response) => void }} [callbacks] - Callbacks to handle events from middleware
|
|
22
26
|
* @returns {Promise<Response>}
|
|
23
27
|
*
|
|
@@ -25,7 +29,7 @@ import * as runtime from "./runtime.js";
|
|
|
25
29
|
* ```typescript
|
|
26
30
|
* // Basic usage in metaframeworks like NextJS, SvelteKit, Astro, Nuxt, etc.
|
|
27
31
|
* export const handle = async ({ event, resolve }) => {
|
|
28
|
-
* return
|
|
32
|
+
* return paraglideMiddleware(event.request, ({ request, locale }) => {
|
|
29
33
|
* // let the framework further resolve the request
|
|
30
34
|
* return resolve(request);
|
|
31
35
|
* });
|
|
@@ -36,7 +40,7 @@ import * as runtime from "./runtime.js";
|
|
|
36
40
|
* ```typescript
|
|
37
41
|
* // Usage in a framework like Express JS or Hono
|
|
38
42
|
* app.use(async (req, res, next) => {
|
|
39
|
-
* const result = await
|
|
43
|
+
* const result = await paraglideMiddleware(req, ({ request, locale }) => {
|
|
40
44
|
* // If a redirect happens this won't be called
|
|
41
45
|
* return next(request);
|
|
42
46
|
* });
|
|
@@ -51,7 +55,7 @@ import * as runtime from "./runtime.js";
|
|
|
51
55
|
* // one request could leak into another concurrent request.
|
|
52
56
|
* export default {
|
|
53
57
|
* fetch: async (request) => {
|
|
54
|
-
* return
|
|
58
|
+
* return paraglideMiddleware(
|
|
55
59
|
* request,
|
|
56
60
|
* ({ request, locale }) => handleRequest(request, locale),
|
|
57
61
|
* { disableAsyncLocalStorage: true }
|
|
@@ -59,6 +63,38 @@ import * as runtime from "./runtime.js";
|
|
|
59
63
|
* }
|
|
60
64
|
* };
|
|
61
65
|
* ```
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* // Usage with frameworks that handle URL localization/delocalization themselves
|
|
70
|
+
* //
|
|
71
|
+
* // Some frameworks like TanStack Router handle URL localization and delocalization
|
|
72
|
+
* // themselves via their own rewrite APIs (e.g., `rewrite.input`/`rewrite.output`).
|
|
73
|
+
* //
|
|
74
|
+
* // When the framework handles this, the middleware's URL delocalization is not needed.
|
|
75
|
+
* // Using the modified `request` from the callback would cause a redirect loop because
|
|
76
|
+
* // both the middleware and the framework would attempt to delocalize the URL.
|
|
77
|
+
* //
|
|
78
|
+
* // Solution: Pass the original request to the handler instead of the modified one.
|
|
79
|
+
* // The middleware still handles locale detection, cookies, and AsyncLocalStorage context.
|
|
80
|
+
* //
|
|
81
|
+
* // ❌ WRONG - causes redirect loop when framework handles URL rewriting:
|
|
82
|
+
* // paraglideMiddleware(req, ({ request }) => handler.fetch(request))
|
|
83
|
+
* //
|
|
84
|
+
* // ✅ CORRECT - use original request when framework handles URL localization:
|
|
85
|
+
* // paraglideMiddleware(req, () => handler.fetch(req))
|
|
86
|
+
*
|
|
87
|
+
* import { paraglideMiddleware } from './paraglide/server.js'
|
|
88
|
+
* import handler from '@tanstack/react-start/server-entry'
|
|
89
|
+
*
|
|
90
|
+
* export default {
|
|
91
|
+
* fetch(req: Request): Promise<Response> {
|
|
92
|
+
* // TanStack Router handles URL rewriting via deLocalizeUrl/localizeUrl
|
|
93
|
+
* // so we pass the original `req` instead of the modified `request`
|
|
94
|
+
* return paraglideMiddleware(req, () => handler.fetch(req))
|
|
95
|
+
* },
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
62
98
|
*/
|
|
63
99
|
export async function paraglideMiddleware(request, resolve, callbacks) {
|
|
64
100
|
if (!runtime.disableAsyncLocalStorage && !runtime.serverAsyncLocalStorage) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/compiler/server/middleware.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/compiler/server/middleware.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS;IACpE,IAAI,CAAC,OAAO,CAAC,wBAAwB,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC;QAC3E,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;QAC1D,OAAO,CAAC,gCAAgC,CAAC,IAAI,iBAAiB,EAAE,CAAC,CAAC;IACnE,CAAC;SAAM,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC;QAC7C,OAAO,CAAC,gCAAgC,CAAC,2BAA2B,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC/B,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IAE3C,4DAA4D;IAC5D,6DAA6D;IAC7D,IACC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,KAAK,UAAU;QACpD,QAAQ,CAAC,cAAc;QACvB,QAAQ,CAAC,WA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ACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,2BAA2B;IACnC,kBAAkB;IAClB,IAAI,YAAY,GAAG,SAAS,CAAC;IAC7B,OAAO;QACN,QAAQ;YACP,OAAO,YAAY,CAAC;QACrB,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ;YACxB,YAAY,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC;gBACJ,OAAO,MAAM,QAAQ,EAAE,CAAC;YACzB,CAAC;oBAAS,CAAC;gBACV,YAAY,GAAG,SAAS,CAAC;YAC1B,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type TrackedFs = {
|
|
2
|
+
fs: typeof import("node:fs");
|
|
3
|
+
readFiles: Set<string>;
|
|
4
|
+
clearReadFiles: () => void;
|
|
5
|
+
};
|
|
6
|
+
type TrackedFsOptions = {
|
|
7
|
+
baseDir?: string;
|
|
8
|
+
fs?: typeof import("node:fs");
|
|
9
|
+
};
|
|
10
|
+
type WatchTargetOptions = {
|
|
11
|
+
baseDir?: string;
|
|
12
|
+
outdir?: string;
|
|
13
|
+
ignoreCache?: boolean;
|
|
14
|
+
includeDirectories?: boolean;
|
|
15
|
+
ignorePath?: (path: string) => boolean;
|
|
16
|
+
};
|
|
17
|
+
type WatchTargets = {
|
|
18
|
+
files: Set<string>;
|
|
19
|
+
directories: Set<string>;
|
|
20
|
+
isIgnoredPath: (path: string) => boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare function isPathWithinDirectories(path: string, directories: Iterable<string>): boolean;
|
|
23
|
+
export declare function getWatchTargets(files: Iterable<string>, options?: WatchTargetOptions): WatchTargets;
|
|
24
|
+
export declare function createTrackedFs(options?: TrackedFsOptions): TrackedFs;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=tracked-fs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracked-fs.d.ts","sourceRoot":"","sources":["../../../src/services/file-watching/tracked-fs.ts"],"names":[],"mappings":"AAIA,KAAK,SAAS,GAAG;IAChB,EAAE,EAAE,cAAc,SAAS,CAAC,CAAC;IAC7B,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACvB,cAAc,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,cAAc,SAAS,CAAC,CAAC;CAC9B,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACvC,CAAC;AAEF,KAAK,YAAY,GAAG;IACnB,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACnB,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACzC,CAAC;AAEF,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,GAC3B,OAAO,CAYT;AAED,wBAAgB,eAAe,CAC9B,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EACvB,OAAO,GAAE,kBAAuB,GAC9B,YAAY,CA8Cd;AAED,wBAAgB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,SAAS,CAkDzE"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { nodeNormalizePath } from "../../utilities/node-normalize-path.js";
|
|
4
|
+
export function isPathWithinDirectories(path, directories) {
|
|
5
|
+
const normalizedPath = nodeNormalizePath(path);
|
|
6
|
+
for (const directory of directories) {
|
|
7
|
+
const normalizedDirectory = nodeNormalizePath(directory);
|
|
8
|
+
if (normalizedPath === normalizedDirectory ||
|
|
9
|
+
normalizedPath.startsWith(`${normalizedDirectory}/`)) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
export function getWatchTargets(files, options = {}) {
|
|
16
|
+
const baseDir = options.baseDir ?? process.cwd();
|
|
17
|
+
const outdirPath = options.outdir
|
|
18
|
+
? nodeNormalizePath(resolve(baseDir, options.outdir))
|
|
19
|
+
: undefined;
|
|
20
|
+
const ignoreCache = options.ignoreCache ?? true;
|
|
21
|
+
const includeDirectories = options.includeDirectories ?? true;
|
|
22
|
+
const ignorePath = options.ignorePath;
|
|
23
|
+
const isIgnoredPath = (path) => {
|
|
24
|
+
const normalizedPath = nodeNormalizePath(path);
|
|
25
|
+
if (ignoreCache && normalizedPath.includes("cache")) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (outdirPath &&
|
|
29
|
+
(normalizedPath === outdirPath ||
|
|
30
|
+
normalizedPath.startsWith(`${outdirPath}/`))) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return ignorePath ? ignorePath(normalizedPath) : false;
|
|
34
|
+
};
|
|
35
|
+
const nextFiles = new Set();
|
|
36
|
+
const nextDirectories = new Set();
|
|
37
|
+
for (const filePath of files) {
|
|
38
|
+
const normalizedPath = nodeNormalizePath(filePath);
|
|
39
|
+
if (isIgnoredPath(normalizedPath)) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
nextFiles.add(normalizedPath);
|
|
43
|
+
if (includeDirectories) {
|
|
44
|
+
const directoryPath = dirname(normalizedPath);
|
|
45
|
+
if (!isIgnoredPath(directoryPath)) {
|
|
46
|
+
nextDirectories.add(directoryPath);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
files: nextFiles,
|
|
52
|
+
directories: nextDirectories,
|
|
53
|
+
isIgnoredPath,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export function createTrackedFs(options = {}) {
|
|
57
|
+
const baseDir = options.baseDir ?? process.cwd();
|
|
58
|
+
const baseFs = options.fs ?? fs;
|
|
59
|
+
const readFiles = new Set();
|
|
60
|
+
const trackRead = (path) => {
|
|
61
|
+
readFiles.add(nodeNormalizePath(resolve(baseDir, path.toString())));
|
|
62
|
+
};
|
|
63
|
+
const wrappedFs = {
|
|
64
|
+
...baseFs,
|
|
65
|
+
// @ts-expect-error - Node's fs has too many overloads
|
|
66
|
+
readFile: (path, options, callback) => {
|
|
67
|
+
trackRead(path);
|
|
68
|
+
return baseFs.readFile(path, options, callback);
|
|
69
|
+
},
|
|
70
|
+
// @ts-expect-error - Node's fs has too many overloads
|
|
71
|
+
readFileSync: (path, options) => {
|
|
72
|
+
trackRead(path);
|
|
73
|
+
return baseFs.readFileSync(path, options);
|
|
74
|
+
},
|
|
75
|
+
promises: {
|
|
76
|
+
...baseFs.promises,
|
|
77
|
+
// @ts-expect-error - Node's fs.promises has too many overloads
|
|
78
|
+
readFile: async (path, options) => {
|
|
79
|
+
trackRead(path);
|
|
80
|
+
return baseFs.promises.readFile(path, options);
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
fs: wrappedFs,
|
|
86
|
+
readFiles,
|
|
87
|
+
clearReadFiles: () => {
|
|
88
|
+
readFiles.clear();
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=tracked-fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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C,IAA0B,EAAE,EAAE;QAChD,SAAS,CAAC,GAAG,CACZ,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CACpD,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,SAAS,GAA6B;QAC3C,GAAG,MAAM;QACT,sDAAsD;QACtD,QAAQ,EAAE,CACT,IAA0B,EAC1B,OAA8D,EAC9D,QAAmE,EAClE,EAAE;YACH,SAAS,CAAC,IAAI,CAAC,CAAC;YAChB,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QACjD,CAAC;QACD,sDAAsD;QACtD,YAAY,EAAE,CACb,IAA0B,EAC1B,OAA+D,EAC9D,EAAE;YACH,SAAS,CAAC,IAAI,CAAC,CAAC;YAChB,OAAO,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3C,CAAC;QACD,QAAQ,EAAE;YACT,GAAG,MAAM,CAAC,QAAQ;YAClB,+DAA+D;YAC/D,QAAQ,EAAE,KAAK,EACd,IAAiB,EACjB,OAAmD,EACjC,EAAE;gBACpB,SAAS,CAAC,IAAI,CAAC,CAAC;gBAChB,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAChD,CAAC;SACD;KACD,CAAC;IAEF,OAAO;QACN,EAAE,EAAE,SAAS;QACb,SAAS;QACT,cAAc,EAAE,GAAG,EAAE;YACpB,SAAS,CAAC,KAAK,EAAE,CAAC;QACnB,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracked-fs.test.d.ts","sourceRoot":"","sources":["../../../src/services/file-watching/tracked-fs.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import memfs from "memfs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { expect, test } from "vitest";
|
|
4
|
+
import { createTrackedFs, getWatchTargets, isPathWithinDirectories, } from "./tracked-fs.js";
|
|
5
|
+
import { nodeNormalizePath } from "../../utilities/node-normalize-path.js";
|
|
6
|
+
test("tracks readFile and promises.readFile calls", async () => {
|
|
7
|
+
const baseDir = "/";
|
|
8
|
+
const memFs = memfs.createFsFromVolume(memfs.Volume.fromJSON({
|
|
9
|
+
"/messages.json": "test",
|
|
10
|
+
}));
|
|
11
|
+
const tracked = createTrackedFs({ baseDir, fs: memFs });
|
|
12
|
+
await new Promise((resolvePromise, rejectPromise) => {
|
|
13
|
+
tracked.fs.readFile("/messages.json", null, (error, data) => {
|
|
14
|
+
if (error) {
|
|
15
|
+
rejectPromise(error);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
expect(data.toString()).toBe("test");
|
|
19
|
+
resolvePromise();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
await tracked.fs.promises.readFile("/messages.json");
|
|
23
|
+
const normalizedPath = nodeNormalizePath(path.resolve(baseDir, "messages.json"));
|
|
24
|
+
expect(tracked.readFiles.has(normalizedPath)).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
test("tracks readFileSync and clears tracked files", async () => {
|
|
27
|
+
const baseDir = "/";
|
|
28
|
+
const memFs = memfs.createFsFromVolume(memfs.Volume.fromJSON({
|
|
29
|
+
"/sync.json": "sync",
|
|
30
|
+
}));
|
|
31
|
+
const tracked = createTrackedFs({ baseDir, fs: memFs });
|
|
32
|
+
const contents = tracked.fs.readFileSync("/sync.json");
|
|
33
|
+
expect(contents.toString()).toBe("sync");
|
|
34
|
+
expect(tracked.readFiles.size).toBe(1);
|
|
35
|
+
tracked.clearReadFiles();
|
|
36
|
+
expect(tracked.readFiles.size).toBe(0);
|
|
37
|
+
});
|
|
38
|
+
test("getWatchTargets filters cache files and collects directories", () => {
|
|
39
|
+
const files = new Set([
|
|
40
|
+
"/project/messages/en.json",
|
|
41
|
+
"/project/cache/tmp.json",
|
|
42
|
+
]);
|
|
43
|
+
const targets = getWatchTargets(files);
|
|
44
|
+
expect(targets.files).toEqual(new Set([nodeNormalizePath("/project/messages/en.json")]));
|
|
45
|
+
expect(targets.directories).toEqual(new Set([nodeNormalizePath("/project/messages")]));
|
|
46
|
+
});
|
|
47
|
+
test("getWatchTargets ignores outdir and descendants", () => {
|
|
48
|
+
const files = new Set([
|
|
49
|
+
"/project/src/paraglide/index.js",
|
|
50
|
+
"/project/messages/en.json",
|
|
51
|
+
]);
|
|
52
|
+
const targets = getWatchTargets(files, {
|
|
53
|
+
baseDir: "/project",
|
|
54
|
+
outdir: "src/paraglide",
|
|
55
|
+
});
|
|
56
|
+
expect(targets.files.has(nodeNormalizePath("/project/src/paraglide/index.js"))).toBe(false);
|
|
57
|
+
expect(targets.files.has(nodeNormalizePath("/project/messages/en.json"))).toBe(true);
|
|
58
|
+
expect(targets.isIgnoredPath("/project/src/paraglide/new.js")).toBe(true);
|
|
59
|
+
expect(targets.directories).toEqual(new Set([nodeNormalizePath("/project/messages")]));
|
|
60
|
+
});
|
|
61
|
+
test("getWatchTargets can keep cache files when ignoreCache is false", () => {
|
|
62
|
+
const files = new Set(["/project/cache/keep.json"]);
|
|
63
|
+
const targets = getWatchTargets(files, { ignoreCache: false });
|
|
64
|
+
expect(targets.files.has(nodeNormalizePath("/project/cache/keep.json"))).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
test("getWatchTargets respects ignorePath predicate", () => {
|
|
67
|
+
const files = new Set([
|
|
68
|
+
"/project/messages/en.json",
|
|
69
|
+
"/project/extra.txt",
|
|
70
|
+
]);
|
|
71
|
+
const targets = getWatchTargets(files, {
|
|
72
|
+
ignorePath: (path) => path.endsWith("extra.txt"),
|
|
73
|
+
});
|
|
74
|
+
expect(targets.files.has(nodeNormalizePath("/project/extra.txt"))).toBe(false);
|
|
75
|
+
expect(targets.directories).toEqual(new Set([nodeNormalizePath("/project/messages")]));
|
|
76
|
+
});
|
|
77
|
+
test("getWatchTargets can omit directories", () => {
|
|
78
|
+
const files = new Set(["/project/messages/en.json"]);
|
|
79
|
+
const targets = getWatchTargets(files, { includeDirectories: false });
|
|
80
|
+
expect(targets.directories.size).toBe(0);
|
|
81
|
+
});
|
|
82
|
+
test("isPathWithinDirectories matches nested paths", () => {
|
|
83
|
+
const directories = new Set([
|
|
84
|
+
"/project/messages",
|
|
85
|
+
"/project/other",
|
|
86
|
+
]);
|
|
87
|
+
expect(isPathWithinDirectories("/project/messages/nested/file.json", directories)).toBe(true);
|
|
88
|
+
expect(isPathWithinDirectories("/project/unknown/file.json", directories)).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=tracked-fs.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracked-fs.test.js","sourceRoot":"","sources":["../../../src/services/file-watching/tracked-fs.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EACN,eAAe,EACf,eAAe,EACf,uBAAuB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAE3E,IAAI,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;IAC9D,MAAM,OAAO,GAAG,GAAG,CAAC;IACpB,MAAM,KAAK,GAAG,KAAK,CAAC,kBAAkB,CACrC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;QACrB,gBAAgB,EAAE,MAAM;KACxB,CAAC,CACsB,CAAC;IAC1B,MAAM,OAAO,GAAG,eAAe,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAExD,MAAM,IAAI,OAAO,CAAO,CAAC,cAAc,EAAE,aAAa,EAAE,EAAE;QACzD,OAAO,CAAC,EAAE,CAAC,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AAO,GAAG,eAAe,CAAC,KAAK,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC,CAAC;IAEtE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,8CAA8C,EAAE,GAAG,EAAE;IACzD,MAAM,WAAW,GAAG,IAAI,GAAG,CAAS;QACnC,mBAAmB;QACnB,gBAAgB;KAChB,CAAC,CAAC;IAEH,MAAM,CACL,uBAAuB,CACtB,oCAAoC,EACpC,WAAW,CACX,CACD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACb,MAAM,CAAC,uBAAuB,CAAC,4BAA4B,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAC9E,KAAK,CACL,CAAC;AACH,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inlang/paraglide-js",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.8.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@inlang/recommend-sherlock": "^0.2.1",
|
|
30
|
-
"@inlang/sdk": "2.
|
|
30
|
+
"@inlang/sdk": "2.6.0",
|
|
31
31
|
"commander": "11.1.0",
|
|
32
32
|
"consola": "3.4.0",
|
|
33
33
|
"json5": "2.2.3",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"scripts": {
|
|
83
83
|
"dev": "tsc --watch",
|
|
84
84
|
"bench": "vitest bench --run",
|
|
85
|
-
"build:examples": "pnpm -r --filter \"./examples/**\" --if-present build",
|
|
85
|
+
"build:examples": "pnpm -r --filter \"./examples/**\" --if-present --workspace-concurrency=1 build",
|
|
86
86
|
"build": "npm run env-variables && tsc --build && npm run generate-api-docs",
|
|
87
87
|
"changeset": "changeset",
|
|
88
88
|
"version-packages": "changeset version",
|