unplugin-saykit 0.3.0 → 0.4.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/bun.mjs +1 -1
- package/dist/esbuild.mjs +1 -1
- package/dist/farm.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.test.mjs +21 -4
- package/dist/rolldown.mjs +1 -1
- package/dist/rollup.mjs +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/{src-B4Rsypvw.mjs → src-sSruAedT.mjs} +1 -0
- package/dist/unloader.mjs +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +2 -2
package/dist/bun.mjs
CHANGED
package/dist/esbuild.mjs
CHANGED
package/dist/farm.mjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as src_default } from "./src-
|
|
1
|
+
import { t as src_default } from "./src-sSruAedT.mjs";
|
|
2
2
|
export { src_default as default };
|
package/dist/index.test.mjs
CHANGED
|
@@ -13667,6 +13667,14 @@ const config = {
|
|
|
13667
13667
|
extension: ".json",
|
|
13668
13668
|
parse: (content) => JSON.parse(content)
|
|
13669
13669
|
}
|
|
13670
|
+
}, {
|
|
13671
|
+
match: (id) => id.endsWith(".ts"),
|
|
13672
|
+
output: Object.assign(join(dir, "{locale}", "messages.{extension}"), { match: (id) => id.endsWith("messages.po") }),
|
|
13673
|
+
transformer: { transform: (code) => code },
|
|
13674
|
+
formatter: {
|
|
13675
|
+
extension: ".po",
|
|
13676
|
+
parse: (content) => content ? JSON.parse(content) : []
|
|
13677
|
+
}
|
|
13670
13678
|
}]
|
|
13671
13679
|
};
|
|
13672
13680
|
vi.mock("@saykit/config/features/loader", () => ({ resolveConfig: () => config }));
|
|
@@ -13676,8 +13684,8 @@ afterAll(() => rmSync(dir, {
|
|
|
13676
13684
|
recursive: true,
|
|
13677
13685
|
force: true
|
|
13678
13686
|
}));
|
|
13679
|
-
const write = (locale, content) => {
|
|
13680
|
-
const file = join(dir, locale,
|
|
13687
|
+
const write = (locale, content, extension = "json") => {
|
|
13688
|
+
const file = join(dir, locale, `messages.${extension}`);
|
|
13681
13689
|
mkdirSync(dirname(file), { recursive: true });
|
|
13682
13690
|
writeFileSync(file, typeof content === "string" ? content : JSON.stringify(content));
|
|
13683
13691
|
return file;
|
|
@@ -13692,7 +13700,7 @@ describe("unplugin transform", () => {
|
|
|
13692
13700
|
});
|
|
13693
13701
|
});
|
|
13694
13702
|
describe("unplugin load", () => {
|
|
13695
|
-
it("loads the source locale into a
|
|
13703
|
+
it("loads the source locale into a record", async () => {
|
|
13696
13704
|
const file = write("en", [{
|
|
13697
13705
|
message: "Hello",
|
|
13698
13706
|
translation: "",
|
|
@@ -13702,7 +13710,7 @@ describe("unplugin load", () => {
|
|
|
13702
13710
|
translation: ""
|
|
13703
13711
|
}]);
|
|
13704
13712
|
const output = await plugin.load.handler(file);
|
|
13705
|
-
globalExpect(output).toContain("export default");
|
|
13713
|
+
globalExpect(output).not.toContain("export default");
|
|
13706
13714
|
const messages = record(output);
|
|
13707
13715
|
globalExpect(messages.greeting).toBe("Hello");
|
|
13708
13716
|
globalExpect(messages[generateHash("Bye", void 0)]).toBe("Bye");
|
|
@@ -13766,6 +13774,15 @@ describe("unplugin load", () => {
|
|
|
13766
13774
|
globalExpect(messages.b).toBe("B-GB");
|
|
13767
13775
|
globalExpect(messages.c).toBe("C-NZ");
|
|
13768
13776
|
});
|
|
13777
|
+
it("wraps a non-JSON catalogue in a default export", async () => {
|
|
13778
|
+
const file = write("en", [{
|
|
13779
|
+
message: "Hello",
|
|
13780
|
+
id: "greeting"
|
|
13781
|
+
}], "po");
|
|
13782
|
+
const output = await plugin.load.handler(file);
|
|
13783
|
+
globalExpect(output).toContain("export default");
|
|
13784
|
+
globalExpect(record(output).greeting).toBe("Hello");
|
|
13785
|
+
});
|
|
13769
13786
|
it("returns undefined when the id does not match a bucket output", async () => {
|
|
13770
13787
|
globalExpect(await plugin.load.handler(join(dir, "other.txt"))).toBeUndefined();
|
|
13771
13788
|
});
|
package/dist/rolldown.mjs
CHANGED
package/dist/rollup.mjs
CHANGED
package/dist/rspack.mjs
CHANGED
|
@@ -26,6 +26,7 @@ var src_default = createUnplugin((_options) => {
|
|
|
26
26
|
const contents = await Promise.all(sources.map((source) => readFile(source, "utf8").catch(() => "")));
|
|
27
27
|
for (const source of sources) this.addWatchFile?.(source);
|
|
28
28
|
const record = assembleCatalogueRecord(bucket, contents);
|
|
29
|
+
if (id.endsWith(".json")) return JSON.stringify(record);
|
|
29
30
|
return `export default ${JSON.stringify(record)}`;
|
|
30
31
|
}
|
|
31
32
|
}
|
package/dist/unloader.mjs
CHANGED
package/dist/vite.mjs
CHANGED
package/dist/webpack.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-saykit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Universal build tool plugin for saykit (Vite, Rollup, Webpack, esbuild)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"unplugin": "^3.3.0",
|
|
44
|
-
"@saykit/config": "^0.
|
|
44
|
+
"@saykit/config": "^0.4.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"check": "tsc --noEmit",
|