@fluentic/i18n-compiler 0.0.0-stage → 0.1.0-beta.2
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/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +10 -2
- package/dist/analyze.d.ts +25 -0
- package/dist/babel.d.ts +9 -0
- package/dist/babel.mjs +31 -0
- package/dist/babel.mjs.map +1 -0
- package/dist/esbuild.d.ts +5 -0
- package/dist/esbuild.mjs +32 -0
- package/dist/esbuild.mjs.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.mjs +1 -0
- package/dist/message.d.ts +12 -0
- package/dist/nextjs.d.ts +9 -0
- package/dist/nextjs.mjs +53 -0
- package/dist/nextjs.mjs.map +1 -0
- package/dist/options-WZfxnYkT.mjs +22 -0
- package/dist/options-WZfxnYkT.mjs.map +1 -0
- package/dist/options.d.ts +13 -0
- package/dist/rollup.d.ts +21 -0
- package/dist/rollup.mjs +25 -0
- package/dist/rollup.mjs.map +1 -0
- package/dist/src-ZYntx97W.mjs +419 -0
- package/dist/src-ZYntx97W.mjs.map +1 -0
- package/dist/vite.d.ts +22 -0
- package/dist/vite.mjs +11 -0
- package/dist/vite.mjs.map +1 -0
- package/dist/webpack-loader.d.ts +1 -0
- package/dist/webpack-loader.mjs +17 -0
- package/dist/webpack-loader.mjs.map +1 -0
- package/dist/webpack.d.ts +6 -0
- package/dist/webpack.mjs +22 -0
- package/dist/webpack.mjs.map +1 -0
- package/dist-cjs/babel.cjs +432 -0
- package/dist-cjs/babel.cjs.map +1 -0
- package/package.json +83 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @fluentic/i18n-compiler
|
|
2
|
+
|
|
3
|
+
## 0.1.0-beta.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Preserve `t.jsx()` reactive element callbacks while extracting and compiling their nested message calls normally.
|
|
8
|
+
- Move all source transforms and Babel, Vite, Rollup, esbuild, webpack, and Next.js integrations into the standalone compiler package.
|
|
9
|
+
- Share compiled hash options consistently across CLI and bundler integrations.
|
|
10
|
+
- Generate package declarations directly with TypeScript 7.
|
|
11
|
+
|
|
12
|
+
## 0.1.0-beta.1
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- Publish the build-time compiler and Babel, Vite, Rollup, esbuild, webpack, and Next.js integrations.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fluentic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @fluentic/i18n-compiler
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Node build-time compiler and integrations for Fluentic i18n.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import fluentic from '@fluentic/i18n-compiler/vite';
|
|
7
|
+
|
|
8
|
+
export default { plugins: [fluentic({ config: './i18n.config.ts' })] };
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The compiler always compiles matching source. Config location is never assumed. Both settings are optional: pass `{config: './any/path/i18n.config.ts'}` to reuse its `compiled.hashLength`, `{hashLength: 6}` to set the value directly, or neither to use the compiler default. A direct value overrides the selected config.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as traverseModule from '@babel/traverse';
|
|
2
|
+
import type { Binding, NodePath } from '@babel/traverse';
|
|
3
|
+
import * as b from '@babel/types';
|
|
4
|
+
declare const traverse: typeof traverseModule.default;
|
|
5
|
+
export { traverse };
|
|
6
|
+
export declare const importMap: Record<string, string>;
|
|
7
|
+
export type Scope = {
|
|
8
|
+
context: string | null;
|
|
9
|
+
notes: string[];
|
|
10
|
+
meta?: unknown;
|
|
11
|
+
};
|
|
12
|
+
export type ExtractedMessage = Scope & {
|
|
13
|
+
id: string;
|
|
14
|
+
source: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function parseSource(code: string, filename: string): import("@babel/parser").ParseResult<b.File>;
|
|
17
|
+
export declare function unwrap(path: NodePath): NodePath;
|
|
18
|
+
export declare function literal(path: NodePath, seen?: Set<Binding>): string | null;
|
|
19
|
+
export declare function memberName(path: NodePath): string | null;
|
|
20
|
+
export declare function analyzer(imports?: string[]): {
|
|
21
|
+
resolve: (path: NodePath, visiting?: Set<Binding>) => Scope | null;
|
|
22
|
+
scopedBindings: Set<Binding>;
|
|
23
|
+
scopeCalls: Set<NodePath<traverseModule.Node>>;
|
|
24
|
+
};
|
|
25
|
+
export declare function collectMessages(code: string, filename: string, imports?: string[]): ExtractedMessage[];
|
package/dist/babel.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type PluginOptions } from './options';
|
|
2
|
+
/** Owns parsing even when a host (e.g. Metro) passes an already parsed AST. */
|
|
3
|
+
export default function fluenticBabel(_api: unknown, options?: PluginOptions): {
|
|
4
|
+
name: string;
|
|
5
|
+
parserOverride(code: string, parserOptions: {
|
|
6
|
+
sourceFilename?: string;
|
|
7
|
+
}): import("@babel/parser").ParseResult<import("@babel/types").File> | undefined;
|
|
8
|
+
pre(file: any): void;
|
|
9
|
+
};
|
package/dist/babel.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { l as traverse, t as compileProgram } from "./src-ZYntx97W.mjs";
|
|
2
|
+
import { n as loadOptions } from "./options-WZfxnYkT.mjs";
|
|
3
|
+
// src/babel.ts
|
|
4
|
+
/** Owns parsing even when a host (e.g. Metro) passes an already parsed AST. */
|
|
5
|
+
function fluenticBabel(_api, options = {}) {
|
|
6
|
+
const config = loadOptions(options);
|
|
7
|
+
const handled = /* @__PURE__ */ new WeakSet();
|
|
8
|
+
const enabled = (code) => code.includes("@fluentic/i18n");
|
|
9
|
+
const compile = (code, filename) => {
|
|
10
|
+
const { ast } = compileProgram(code, filename, config);
|
|
11
|
+
traverse.cache.clear();
|
|
12
|
+
handled.add(ast.program);
|
|
13
|
+
return ast;
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
name: "fluentic-i18n",
|
|
17
|
+
parserOverride(code, parserOptions) {
|
|
18
|
+
if (!enabled(code)) return void 0;
|
|
19
|
+
return compile(code, parserOptions.sourceFilename ?? "source.tsx");
|
|
20
|
+
},
|
|
21
|
+
pre(file) {
|
|
22
|
+
if (!enabled(file.code) || handled.has(file.path.node)) return;
|
|
23
|
+
const ast = compile(file.code, file.opts.filename ?? "source.tsx");
|
|
24
|
+
file.path.replaceWith(ast.program);
|
|
25
|
+
file.scope.crawl();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export { fluenticBabel as default };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=babel.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"babel.mjs","names":[],"sources":["../src/babel.ts"],"sourcesContent":["import { traverse } from './analyze';\nimport { compileProgram } from './index';\nimport { loadOptions, type PluginOptions } from './options';\n/** Owns parsing even when a host (e.g. Metro) passes an already parsed AST. */\nexport default function fluenticBabel(_api: unknown, options: PluginOptions = {}) {\n const config = loadOptions(options);\n const handled = new WeakSet<object>();\n const enabled = (code: string) => code.includes('@fluentic/i18n');\n\n const compile = (code: string, filename: string) => {\n const { ast } = compileProgram(code, filename, config);\n // Standalone paths have a default Hub. Babel must create its own paths for presets.\n traverse.cache.clear();\n handled.add(ast.program);\n\n return ast;\n };\n\n return {\n name: 'fluentic-i18n',\n parserOverride(code: string, parserOptions: { sourceFilename?: string; }) {\n if (!enabled(code)) return undefined;\n\n return compile(code, parserOptions.sourceFilename ?? 'source.tsx');\n },\n pre(file: any) {\n if (!enabled(file.code) || handled.has(file.path.node)) return;\n\n const ast = compile(file.code, file.opts.filename ?? 'source.tsx');\n file.path.replaceWith(ast.program);\n file.scope.crawl();\n },\n };\n}\n"],"mappings":";;;;AAIA,SAAwB,cAAc,MAAe,UAAyB,CAAC,GAAG;CAChF,MAAM,SAAS,YAAY,OAAO;CAClC,MAAM,0BAAU,IAAI,QAAgB;CACpC,MAAM,WAAW,SAAiB,KAAK,SAAS,gBAAgB;CAEhE,MAAM,WAAW,MAAc,aAAqB;EAClD,MAAM,EAAE,QAAQ,eAAe,MAAM,UAAU,MAAM;EAErD,SAAS,MAAM,MAAM;EACrB,QAAQ,IAAI,IAAI,OAAO;EAEvB,OAAO;CACT;CAEA,OAAO;EACL,MAAM;EACN,eAAe,MAAc,eAA6C;GACxE,IAAI,CAAC,QAAQ,IAAI,GAAG,OAAO,KAAA;GAE3B,OAAO,QAAQ,MAAM,cAAc,kBAAkB,YAAY;EACnE;EACA,IAAI,MAAW;GACb,IAAI,CAAC,QAAQ,KAAK,IAAI,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,GAAG;GAExD,MAAM,MAAM,QAAQ,KAAK,MAAM,KAAK,KAAK,YAAY,YAAY;GACjE,KAAK,KAAK,YAAY,IAAI,OAAO;GACjC,KAAK,MAAM,MAAM;EACnB;CACF;AACF"}
|
package/dist/esbuild.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { n as transform } from "./src-ZYntx97W.mjs";
|
|
2
|
+
import { n as loadOptions, t as accepts } from "./options-WZfxnYkT.mjs";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
// src/esbuild.ts
|
|
5
|
+
function fluentic(options = {}) {
|
|
6
|
+
return {
|
|
7
|
+
name: "fluentic-i18n",
|
|
8
|
+
setup(build) {
|
|
9
|
+
let config = loadOptions(options, build.initialOptions.absWorkingDir);
|
|
10
|
+
build.onStart(() => {
|
|
11
|
+
config = loadOptions(options, build.initialOptions.absWorkingDir);
|
|
12
|
+
});
|
|
13
|
+
build.onLoad({ filter: /\.[cm]?[jt]sx?$/ }, async ({ path }) => {
|
|
14
|
+
if (!accepts(path, config)) return;
|
|
15
|
+
const result = transform(await readFile(path, "utf8"), {
|
|
16
|
+
...config,
|
|
17
|
+
filename: path
|
|
18
|
+
});
|
|
19
|
+
if (!result) return;
|
|
20
|
+
const loader = /\.tsx$/.test(path) ? "tsx" : /\.[cm]?ts$/.test(path) ? "ts" : /\.jsx$/.test(path) ? "jsx" : "js";
|
|
21
|
+
return {
|
|
22
|
+
contents: result.code + "\n//# sourceMappingURL=data:application/json;base64," + Buffer.from(JSON.stringify(result.map)).toString("base64"),
|
|
23
|
+
loader,
|
|
24
|
+
watchFiles: [path, ...config.configFile ? [config.configFile] : []]
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export { fluentic as default };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=esbuild.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild.mjs","names":[],"sources":["../src/esbuild.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { transform } from './index';\nimport { accepts, loadOptions, type PluginOptions } from './options';\n\nexport default function fluentic(options: PluginOptions = {}) {\n return {\n name: 'fluentic-i18n',\n setup(build: any) {\n let config = loadOptions(options, build.initialOptions.absWorkingDir);\n build.onStart(() => {\n config = loadOptions(options, build.initialOptions.absWorkingDir);\n });\n build.onLoad({ filter: /\\.[cm]?[jt]sx?$/ }, async ({ path }: { path: string; }) => {\n if (!accepts(path, config)) return;\n\n const result = transform(await readFile(path, 'utf8'), { ...config, filename: path });\n\n if (!result) return;\n\n const loader = /\\.tsx$/.test(path)\n ? 'tsx'\n : /\\.[cm]?ts$/.test(path)\n ? 'ts'\n : /\\.jsx$/.test(path)\n ? 'jsx'\n : 'js';\n\n return {\n contents: result.code + '\\n//# sourceMappingURL=data:application/json;base64,' +\n Buffer.from(JSON.stringify(result.map)).toString('base64'),\n loader,\n watchFiles: [path, ...(config.configFile ? [config.configFile] : [])],\n };\n });\n },\n };\n}\n"],"mappings":";;;;AAIA,SAAwB,SAAS,UAAyB,CAAC,GAAG;CAC5D,OAAO;EACL,MAAM;EACN,MAAM,OAAY;GAChB,IAAI,SAAS,YAAY,SAAS,MAAM,eAAe,aAAa;GACpE,MAAM,cAAc;IAClB,SAAS,YAAY,SAAS,MAAM,eAAe,aAAa;GAClE,CAAC;GACD,MAAM,OAAO,EAAE,QAAQ,kBAAkB,GAAG,OAAO,EAAE,WAA8B;IACjF,IAAI,CAAC,QAAQ,MAAM,MAAM,GAAG;IAE5B,MAAM,SAAS,UAAU,MAAM,SAAS,MAAM,MAAM,GAAG;KAAE,GAAG;KAAQ,UAAU;IAAK,CAAC;IAEpF,IAAI,CAAC,QAAQ;IAEb,MAAM,SAAS,SAAS,KAAK,IAAI,IAC7B,QACA,aAAa,KAAK,IAAI,IACtB,OACA,SAAS,KAAK,IAAI,IAClB,QACA;IAEJ,OAAO;KACL,UAAU,OAAO,OAAO,yDACtB,OAAO,KAAK,KAAK,UAAU,OAAO,GAAG,CAAC,CAAC,CAAC,SAAS,QAAQ;KAC3D;KACA,YAAY,CAAC,MAAM,GAAI,OAAO,aAAa,CAAC,OAAO,UAAU,IAAI,CAAC,CAAE;IACtE;GACF,CAAC;EACH;CACF;AACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as b from '@babel/types';
|
|
2
|
+
import { type ExtractedMessage } from './analyze';
|
|
3
|
+
export { collectMessages } from './analyze';
|
|
4
|
+
export * from './message';
|
|
5
|
+
export type CompiledOptions = {
|
|
6
|
+
hashLength?: number;
|
|
7
|
+
};
|
|
8
|
+
export type CompilerOptions = CompiledOptions & {
|
|
9
|
+
filename?: string;
|
|
10
|
+
bindReactText?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function compileProgram(code: string, filename: string, options?: CompilerOptions): {
|
|
13
|
+
ast: import("@babel/parser").ParseResult<b.File>;
|
|
14
|
+
messages: ExtractedMessage[];
|
|
15
|
+
changed: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare function transform(code: string, options?: CompilerOptions): {
|
|
18
|
+
code: string;
|
|
19
|
+
map: {
|
|
20
|
+
version: number;
|
|
21
|
+
sources: string[];
|
|
22
|
+
names: string[];
|
|
23
|
+
sourceRoot?: string | undefined;
|
|
24
|
+
sourcesContent?: string[] | undefined;
|
|
25
|
+
mappings: string;
|
|
26
|
+
file: string;
|
|
27
|
+
} | null;
|
|
28
|
+
messages: ExtractedMessage[];
|
|
29
|
+
} | null;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { r as COMPACT_VERSION, c as collectMessages, i as compileCatalog, a as compileMessage, t as compileProgram, o as messageId, s as messageIdentity, n as transform } from "./src-ZYntx97W.mjs";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type CompactMessage } from '@fluentic/i18n/compiler-support';
|
|
2
|
+
export { COMPACT_VERSION } from '@fluentic/i18n/compiler-support';
|
|
3
|
+
export declare function messageIdentity(context: string | null, source: string): string;
|
|
4
|
+
export declare function messageId(context: string | null, source: string, hashLength?: number): string;
|
|
5
|
+
export declare function compileMessage(source: string): CompactMessage;
|
|
6
|
+
export declare function compileCatalog(records: Array<{
|
|
7
|
+
source: string;
|
|
8
|
+
context: string | null;
|
|
9
|
+
translation: string;
|
|
10
|
+
}>, options?: {
|
|
11
|
+
hashLength?: number;
|
|
12
|
+
}): Array<[string, CompactMessage]>;
|
package/dist/nextjs.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type NextPluginOptions = {
|
|
2
|
+
requestConfig: string;
|
|
3
|
+
/** Optional i18n config path, resolved from the application working directory. */
|
|
4
|
+
config?: string;
|
|
5
|
+
/** Direct override; otherwise reuse compiled.hashLength from an explicitly selected config or the default. */
|
|
6
|
+
hashLength?: number;
|
|
7
|
+
};
|
|
8
|
+
/** One Next integration; preserves the application's existing webpack hook/rules. */
|
|
9
|
+
export default function withFluentic(options: NextPluginOptions): (nextConfig?: any) => any;
|
package/dist/nextjs.mjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import FluenticI18nPlugin from "./webpack.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { relative, resolve } from "node:path";
|
|
4
|
+
// src/nextjs.ts
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
/** One Next integration; preserves the application's existing webpack hook/rules. */
|
|
7
|
+
function withFluentic(options) {
|
|
8
|
+
const request = resolve(options.requestConfig);
|
|
9
|
+
const loader = require.resolve("@fluentic/i18n-compiler/webpack-loader");
|
|
10
|
+
const compilerOptions = {
|
|
11
|
+
bindReactText: true,
|
|
12
|
+
...options.config ? { config: resolve(options.config) } : {},
|
|
13
|
+
...options.hashLength !== void 0 ? { hashLength: options.hashLength } : {}
|
|
14
|
+
};
|
|
15
|
+
return (nextConfig = {}) => ({
|
|
16
|
+
...nextConfig,
|
|
17
|
+
turbopack: {
|
|
18
|
+
...nextConfig.turbopack,
|
|
19
|
+
resolveAlias: {
|
|
20
|
+
...nextConfig.turbopack?.resolveAlias,
|
|
21
|
+
"@fluentic/i18n-nextjs/request": "./" + relative(process.cwd(), request).replace(/\\/g, "/")
|
|
22
|
+
},
|
|
23
|
+
rules: {
|
|
24
|
+
...nextConfig.turbopack?.rules,
|
|
25
|
+
...Object.fromEntries([
|
|
26
|
+
"*.js",
|
|
27
|
+
"*.jsx",
|
|
28
|
+
"*.ts",
|
|
29
|
+
"*.tsx",
|
|
30
|
+
"*.mjs",
|
|
31
|
+
"*.mts"
|
|
32
|
+
].map((pattern) => [pattern, [...nextConfig.turbopack?.rules?.[pattern] ? [nextConfig.turbopack.rules[pattern]].flat() : [], {
|
|
33
|
+
condition: { not: "foreign" },
|
|
34
|
+
loaders: [{
|
|
35
|
+
loader,
|
|
36
|
+
options: compilerOptions
|
|
37
|
+
}]
|
|
38
|
+
}]]))
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
webpack(config, context) {
|
|
42
|
+
config.resolve ??= {};
|
|
43
|
+
config.resolve.alias ??= {};
|
|
44
|
+
config.resolve.alias["@fluentic/i18n-nextjs/request$"] = request;
|
|
45
|
+
config.plugins ??= [];
|
|
46
|
+
config.plugins.push(new FluenticI18nPlugin(compilerOptions));
|
|
47
|
+
return nextConfig.webpack ? nextConfig.webpack(config, context) : config;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export { withFluentic as default };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=nextjs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nextjs.mjs","names":["FluenticPlugin"],"sources":["../src/nextjs.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { relative, resolve } from 'node:path';\nimport FluenticPlugin from './webpack';\nconst require = createRequire(import.meta.url);\nexport type NextPluginOptions = {\n requestConfig: string;\n /** Optional i18n config path, resolved from the application working directory. */\n config?: string;\n /** Direct override; otherwise reuse compiled.hashLength from an explicitly selected config or the default. */\n hashLength?: number;\n};\n/** One Next integration; preserves the application's existing webpack hook/rules. */\nexport default function withFluentic(options: NextPluginOptions) {\n const request = resolve(options.requestConfig);\n const loader = require.resolve('@fluentic/i18n-compiler/webpack-loader');\n const compilerOptions = {\n bindReactText: true,\n ...(options.config ? { config: resolve(options.config) } : {}),\n ...(options.hashLength !== undefined ? { hashLength: options.hashLength } : {}),\n };\n return (nextConfig: any = {}) => ({\n ...nextConfig,\n turbopack: {\n ...nextConfig.turbopack,\n resolveAlias: {\n ...nextConfig.turbopack?.resolveAlias,\n '@fluentic/i18n-nextjs/request': './' + relative(process.cwd(), request).replace(/\\\\/g, '/'),\n },\n rules: {\n ...nextConfig.turbopack?.rules,\n ...Object.fromEntries(['*.js', '*.jsx', '*.ts', '*.tsx', '*.mjs', '*.mts'].map((pattern) => [pattern, [\n ...(nextConfig.turbopack?.rules?.[pattern] ? [nextConfig.turbopack.rules[pattern]].flat() : []),\n { condition: { not: 'foreign' }, loaders: [{ loader, options: compilerOptions }] },\n ]])),\n },\n },\n webpack(config: any, context: any) {\n config.resolve ??= {};\n config.resolve.alias ??= {};\n config.resolve.alias['@fluentic/i18n-nextjs/request$'] = request;\n config.plugins ??= [];\n config.plugins.push(new FluenticPlugin(compilerOptions));\n return nextConfig.webpack ? nextConfig.webpack(config, context) : config;\n },\n });\n}\n"],"mappings":";;;;AAGA,MAAM,UAAU,cAAc,YAAY,GAAG;;AAS7C,SAAwB,aAAa,SAA4B;CAC/D,MAAM,UAAU,QAAQ,QAAQ,aAAa;CAC7C,MAAM,SAAS,QAAQ,QAAQ,wCAAwC;CACvE,MAAM,kBAAkB;EACtB,eAAe;EACf,GAAI,QAAQ,SAAS,EAAE,QAAQ,QAAQ,QAAQ,MAAM,EAAE,IAAI,CAAC;EAC5D,GAAI,QAAQ,eAAe,KAAA,IAAY,EAAE,YAAY,QAAQ,WAAW,IAAI,CAAC;CAC/E;CACA,QAAQ,aAAkB,CAAC,OAAO;EAChC,GAAG;EACH,WAAW;GACT,GAAG,WAAW;GACd,cAAc;IACZ,GAAG,WAAW,WAAW;IACzB,iCAAiC,OAAO,SAAS,QAAQ,IAAI,GAAG,OAAO,CAAC,CAAC,QAAQ,OAAO,GAAG;GAC7F;GACA,OAAO;IACL,GAAG,WAAW,WAAW;IACzB,GAAG,OAAO,YAAY;KAAC;KAAQ;KAAS;KAAQ;KAAS;KAAS;IAAO,CAAC,CAAC,KAAK,YAAY,CAAC,SAAS,CACpG,GAAI,WAAW,WAAW,QAAQ,WAAW,CAAC,WAAW,UAAU,MAAM,QAAQ,CAAC,CAAC,KAAK,IAAI,CAAC,GAC7F;KAAE,WAAW,EAAE,KAAK,UAAU;KAAG,SAAS,CAAC;MAAE;MAAQ,SAAS;KAAgB,CAAC;IAAE,CACnF,CAAC,CAAC,CAAC;GACL;EACF;EACA,QAAQ,QAAa,SAAc;GACjC,OAAO,YAAY,CAAC;GACpB,OAAO,QAAQ,UAAU,CAAC;GAC1B,OAAO,QAAQ,MAAM,oCAAoC;GACzD,OAAO,YAAY,CAAC;GACpB,OAAO,QAAQ,KAAK,IAAIA,mBAAe,eAAe,CAAC;GACvD,OAAO,WAAW,UAAU,WAAW,QAAQ,QAAQ,OAAO,IAAI;EACpE;CACF;AACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createJiti } from "jiti";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
// src/options.ts
|
|
4
|
+
function loadOptions(options = {}, root = process.cwd()) {
|
|
5
|
+
if ("compiled" in options) throw new TypeError("[i18n] compiler plugins always compile; use hashLength instead of compiled");
|
|
6
|
+
const file = options.config ? resolve(root, options.config) : void 0;
|
|
7
|
+
const config = file ? createJiti(import.meta.url, { moduleCache: false })(file) : {};
|
|
8
|
+
const { compiled, ...configOptions } = config.default ?? config;
|
|
9
|
+
const sharedHashLength = typeof compiled === "object" ? compiled.hashLength : void 0;
|
|
10
|
+
return {
|
|
11
|
+
...configOptions,
|
|
12
|
+
...sharedHashLength === void 0 ? {} : { hashLength: sharedHashLength },
|
|
13
|
+
...options,
|
|
14
|
+
configFile: file
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function accepts(id, options) {
|
|
18
|
+
return /\.[cm]?[jt]sx?$/.test(id.split("?")[0]) && (options.includeDependencies || !id.includes("/node_modules/"));
|
|
19
|
+
}
|
|
20
|
+
export { loadOptions as n, accepts as t };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=options-WZfxnYkT.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options-WZfxnYkT.mjs","names":[],"sources":["../src/options.ts"],"sourcesContent":["import { createJiti } from 'jiti';\nimport { resolve } from 'node:path';\n\nimport type { CompiledOptions } from './index';\n\nexport type PluginOptions = {\n /** Direct override; otherwise reuse compiled.hashLength from an explicitly selected config or the default. */\n hashLength?: number;\n /** Optional i18n config path, resolved from the plugin's working directory. */\n config?: string;\n includeDependencies?: boolean;\n /** Next.js client modules: bind synchronous text calls to the hydration boundary. */\n bindReactText?: boolean;\n};\n\nexport function loadOptions(\n options: PluginOptions = {},\n root = process.cwd(),\n): PluginOptions & { configFile?: string; } {\n if ('compiled' in options) {\n throw new TypeError('[i18n] compiler plugins always compile; use hashLength instead of compiled');\n }\n const file = options.config ? resolve(root, options.config) : undefined;\n\n const config = file\n ? createJiti(import.meta.url, { moduleCache: false })(file) as\n & { default?: PluginOptions & { compiled?: true | CompiledOptions; }; }\n & PluginOptions\n & { compiled?: true | CompiledOptions; }\n : {};\n const loaded = (config.default ?? config) as PluginOptions & { compiled?: true | CompiledOptions; };\n const { compiled, ...configOptions } = loaded;\n const sharedHashLength = typeof compiled === 'object' ? compiled.hashLength : undefined;\n\n return {\n ...configOptions,\n ...(sharedHashLength === undefined ? {} : { hashLength: sharedHashLength }),\n ...options,\n configFile: file,\n };\n}\n\nexport function accepts(id: string, options: PluginOptions) {\n return /\\.[cm]?[jt]sx?$/.test(id.split('?')[0]) && (options.includeDependencies || !id.includes('/node_modules/'));\n}\n"],"mappings":";;;AAeA,SAAgB,YACd,UAAyB,CAAC,GAC1B,OAAO,QAAQ,IAAI,GACuB;CAC1C,IAAI,cAAc,SAChB,MAAM,IAAI,UAAU,4EAA4E;CAElG,MAAM,OAAO,QAAQ,SAAS,QAAQ,MAAM,QAAQ,MAAM,IAAI,KAAA;CAE9D,MAAM,SAAS,OACX,WAAW,YAAY,KAAK,EAAE,aAAa,MAAM,CAAC,CAAC,CAAC,IAAI,IAIxD,CAAC;CAEL,MAAM,EAAE,UAAU,GAAG,kBADL,OAAO,WAAW;CAElC,MAAM,mBAAmB,OAAO,aAAa,WAAW,SAAS,aAAa,KAAA;CAE9E,OAAO;EACL,GAAG;EACH,GAAI,qBAAqB,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY,iBAAiB;EACzE,GAAG;EACH,YAAY;CACd;AACF;AAEA,SAAgB,QAAQ,IAAY,SAAwB;CAC1D,OAAO,kBAAkB,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM,QAAQ,uBAAuB,CAAC,GAAG,SAAS,gBAAgB;AAClH"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type PluginOptions = {
|
|
2
|
+
/** Direct override; otherwise reuse compiled.hashLength from an explicitly selected config or the default. */
|
|
3
|
+
hashLength?: number;
|
|
4
|
+
/** Optional i18n config path, resolved from the plugin's working directory. */
|
|
5
|
+
config?: string;
|
|
6
|
+
includeDependencies?: boolean;
|
|
7
|
+
/** Next.js client modules: bind synchronous text calls to the hydration boundary. */
|
|
8
|
+
bindReactText?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function loadOptions(options?: PluginOptions, root?: string): PluginOptions & {
|
|
11
|
+
configFile?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function accepts(id: string, options: PluginOptions): boolean;
|
package/dist/rollup.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type PluginOptions } from './options';
|
|
2
|
+
export default function fluentic(options?: PluginOptions): {
|
|
3
|
+
name: string;
|
|
4
|
+
buildStart(this: {
|
|
5
|
+
addWatchFile(file: string): void;
|
|
6
|
+
}): void;
|
|
7
|
+
watchChange(id: string): void;
|
|
8
|
+
transform(code: string, id: string): {
|
|
9
|
+
code: string;
|
|
10
|
+
map: {
|
|
11
|
+
version: number;
|
|
12
|
+
sources: string[];
|
|
13
|
+
names: string[];
|
|
14
|
+
sourceRoot?: string | undefined;
|
|
15
|
+
sourcesContent?: string[] | undefined;
|
|
16
|
+
mappings: string;
|
|
17
|
+
file: string;
|
|
18
|
+
} | null;
|
|
19
|
+
messages: import("./analyze").ExtractedMessage[];
|
|
20
|
+
} | null;
|
|
21
|
+
};
|
package/dist/rollup.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { n as transform } from "./src-ZYntx97W.mjs";
|
|
2
|
+
import { n as loadOptions, t as accepts } from "./options-WZfxnYkT.mjs";
|
|
3
|
+
// src/rollup.ts
|
|
4
|
+
function fluentic(options = {}) {
|
|
5
|
+
let config = loadOptions(options);
|
|
6
|
+
return {
|
|
7
|
+
name: "fluentic-i18n",
|
|
8
|
+
buildStart() {
|
|
9
|
+
if (config.configFile) this.addWatchFile(config.configFile);
|
|
10
|
+
},
|
|
11
|
+
watchChange(id) {
|
|
12
|
+
if (id === config.configFile) config = loadOptions(options);
|
|
13
|
+
},
|
|
14
|
+
transform(code, id) {
|
|
15
|
+
if (!accepts(id, config)) return null;
|
|
16
|
+
return transform(code, {
|
|
17
|
+
...config,
|
|
18
|
+
filename: id.split("?")[0]
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export { fluentic as default };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=rollup.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup.mjs","names":[],"sources":["../src/rollup.ts"],"sourcesContent":["import { transform } from './index';\nimport { accepts, loadOptions, type PluginOptions } from './options';\n\nexport default function fluentic(options: PluginOptions = {}) {\n let config = loadOptions(options);\n\n return {\n name: 'fluentic-i18n',\n buildStart(this: { addWatchFile(file: string): void; }) {\n if (config.configFile) this.addWatchFile(config.configFile);\n },\n watchChange(id: string) {\n if (id === config.configFile) config = loadOptions(options);\n },\n transform(code: string, id: string) {\n if (!accepts(id, config)) return null;\n\n return transform(code, { ...config, filename: id.split('?')[0] });\n },\n };\n}\n"],"mappings":";;;AAGA,SAAwB,SAAS,UAAyB,CAAC,GAAG;CAC5D,IAAI,SAAS,YAAY,OAAO;CAEhC,OAAO;EACL,MAAM;EACN,aAAwD;GACtD,IAAI,OAAO,YAAY,KAAK,aAAa,OAAO,UAAU;EAC5D;EACA,YAAY,IAAY;GACtB,IAAI,OAAO,OAAO,YAAY,SAAS,YAAY,OAAO;EAC5D;EACA,UAAU,MAAc,IAAY;GAClC,IAAI,CAAC,QAAQ,IAAI,MAAM,GAAG,OAAO;GAEjC,OAAO,UAAU,MAAM;IAAE,GAAG;IAAQ,UAAU,GAAG,MAAM,GAAG,CAAC,CAAC;GAAG,CAAC;EAClE;CACF;AACF"}
|