@vocab/vite 0.2.4 → 0.2.5-tsdown-20250922064614
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/chunk-nOFOJqeH.js +30 -0
- package/dist/chunks.d.mts +13 -0
- package/dist/chunks.d.ts +13 -0
- package/dist/chunks.js +36 -0
- package/dist/chunks.js.map +1 -0
- package/dist/chunks.mjs +35 -0
- package/dist/chunks.mjs.map +1 -0
- package/dist/get-chunk-name-BXaBbR1f.js +14 -0
- package/dist/get-chunk-name-BXaBbR1f.js.map +1 -0
- package/dist/get-chunk-name-C-VEd843.mjs +8 -0
- package/dist/get-chunk-name-C-VEd843.mjs.map +1 -0
- package/dist/get-chunk-name-CLQqsYYm.d.ts +5 -0
- package/dist/get-chunk-name-CogJ8I9H.d.mts +5 -0
- package/dist/get-chunk-name.d.mts +2 -0
- package/dist/get-chunk-name.d.ts +2 -0
- package/dist/get-chunk-name.js +3 -0
- package/dist/get-chunk-name.mjs +3 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +111 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +107 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger-BBoxZFcH.js +16 -0
- package/dist/logger-BBoxZFcH.js.map +1 -0
- package/dist/logger-OmOg8OXO.mjs +9 -0
- package/dist/logger-OmOg8OXO.mjs.map +1 -0
- package/dist/runtime.d.mts +8 -0
- package/dist/runtime.d.ts +8 -0
- package/dist/runtime.js +36 -0
- package/dist/runtime.js.map +1 -0
- package/dist/runtime.mjs +27 -0
- package/dist/runtime.mjs.map +1 -0
- package/package.json +19 -23
- package/README.md +0 -827
- package/chunks/dist/vocab-vite-chunks.cjs.d.ts +0 -2
- package/chunks/dist/vocab-vite-chunks.cjs.dev.js +0 -57
- package/chunks/dist/vocab-vite-chunks.cjs.js +0 -7
- package/chunks/dist/vocab-vite-chunks.cjs.prod.js +0 -57
- package/chunks/dist/vocab-vite-chunks.esm.js +0 -52
- package/chunks/package.json +0 -4
- package/dist/declarations/src/chunks.d.ts +0 -2
- package/dist/declarations/src/create-language.d.ts +0 -2
- package/dist/declarations/src/create-vocab-chunks.d.ts +0 -5
- package/dist/declarations/src/get-chunk-name.d.ts +0 -1
- package/dist/declarations/src/index.d.ts +0 -6
- package/dist/declarations/src/runtime.d.ts +0 -2
- package/dist/logger-0d92b2c5.cjs.prod.js +0 -12
- package/dist/logger-3e3dccee.cjs.dev.js +0 -12
- package/dist/logger-e3a4b043.esm.js +0 -6
- package/dist/vocab-vite.cjs.d.ts +0 -3
- package/dist/vocab-vite.cjs.dev.js +0 -148
- package/dist/vocab-vite.cjs.js +0 -7
- package/dist/vocab-vite.cjs.prod.js +0 -148
- package/dist/vocab-vite.esm.js +0 -123
- package/runtime/dist/vocab-vite-runtime.cjs.d.ts +0 -2
- package/runtime/dist/vocab-vite-runtime.cjs.dev.js +0 -34
- package/runtime/dist/vocab-vite-runtime.cjs.js +0 -7
- package/runtime/dist/vocab-vite-runtime.cjs.prod.js +0 -34
- package/runtime/dist/vocab-vite-runtime.esm.js +0 -26
- package/runtime/package.json +0 -4
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(exports, '__toESM', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return __toESM;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getChunkName } from "./get-chunk-name-CogJ8I9H.mjs";
|
|
2
|
+
import { Rollup } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/create-vocab-chunks.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Gets vocab virtual module details and creates chunks for each language
|
|
7
|
+
*/
|
|
8
|
+
declare const createVocabChunks: (id: string, {
|
|
9
|
+
getModuleInfo
|
|
10
|
+
}: Rollup.ManualChunkMeta) => string | undefined;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { createVocabChunks, getChunkName };
|
|
13
|
+
//# sourceMappingURL=chunks.d.mts.map
|
package/dist/chunks.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getChunkName } from "./get-chunk-name-CLQqsYYm.js";
|
|
2
|
+
import { Rollup } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/create-vocab-chunks.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Gets vocab virtual module details and creates chunks for each language
|
|
7
|
+
*/
|
|
8
|
+
declare const createVocabChunks: (id: string, {
|
|
9
|
+
getModuleInfo
|
|
10
|
+
}: Rollup.ManualChunkMeta) => string | undefined;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { createVocabChunks, getChunkName };
|
|
13
|
+
//# sourceMappingURL=chunks.d.ts.map
|
package/dist/chunks.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const require_logger = require('./logger-BBoxZFcH.js');
|
|
2
|
+
const require_get_chunk_name = require('./get-chunk-name-BXaBbR1f.js');
|
|
3
|
+
|
|
4
|
+
//#region src/create-vocab-chunks.ts
|
|
5
|
+
const trace$1 = require_logger.trace.extend("create-vocab-chunks");
|
|
6
|
+
/**
|
|
7
|
+
* Gets vocab virtual module details and creates chunks for each language
|
|
8
|
+
*/
|
|
9
|
+
const createVocabChunks = (id, { getModuleInfo }) => {
|
|
10
|
+
const match = /virtual:vocab-(\w+)/.exec(id);
|
|
11
|
+
if (!match) return;
|
|
12
|
+
const language = match[1];
|
|
13
|
+
const dependentEntryPoints = [];
|
|
14
|
+
const rootModuleInfo = getModuleInfo(id);
|
|
15
|
+
if (!rootModuleInfo) {
|
|
16
|
+
trace$1(`No module info found for ${id}`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const idsToHandle = new Set(rootModuleInfo.dynamicImporters);
|
|
20
|
+
for (const moduleId of idsToHandle) {
|
|
21
|
+
const moduleInfo = getModuleInfo(moduleId);
|
|
22
|
+
if (!moduleInfo) {
|
|
23
|
+
trace$1(`No module info found for ${moduleId}`);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const { isEntry, dynamicImporters, importers } = moduleInfo;
|
|
27
|
+
if (isEntry || dynamicImporters.length > 0) dependentEntryPoints.push(moduleId);
|
|
28
|
+
for (const importerId of importers) idsToHandle.add(importerId);
|
|
29
|
+
}
|
|
30
|
+
if (dependentEntryPoints.length > 0) return require_get_chunk_name.getChunkName(language);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.createVocabChunks = createVocabChunks;
|
|
35
|
+
exports.getChunkName = require_get_chunk_name.getChunkName;
|
|
36
|
+
//# sourceMappingURL=chunks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunks.js","names":["trace","_trace","dependentEntryPoints: string[]","getChunkName"],"sources":["../src/create-vocab-chunks.ts"],"sourcesContent":["import type { Rollup } from 'vite';\nimport { trace as _trace } from './logger';\nimport { getChunkName } from './get-chunk-name';\n\nconst trace = _trace.extend('create-vocab-chunks');\n\n/**\n * Gets vocab virtual module details and creates chunks for each language\n */\nexport const createVocabChunks = (\n id: string,\n { getModuleInfo }: Rollup.ManualChunkMeta,\n) => {\n const match = /virtual:vocab-(\\w+)/.exec(id);\n if (!match) {\n return;\n }\n\n const language = match[1];\n const dependentEntryPoints: string[] = [];\n\n const rootModuleInfo = getModuleInfo(id);\n\n if (!rootModuleInfo) {\n trace(`No module info found for ${id}`);\n return;\n }\n\n const idsToHandle = new Set<string>(rootModuleInfo.dynamicImporters);\n\n for (const moduleId of idsToHandle) {\n const moduleInfo = getModuleInfo(moduleId);\n if (!moduleInfo) {\n trace(`No module info found for ${moduleId}`);\n continue;\n }\n\n const { isEntry, dynamicImporters, importers } = moduleInfo;\n\n if (isEntry || dynamicImporters.length > 0) {\n dependentEntryPoints.push(moduleId);\n }\n\n for (const importerId of importers) {\n idsToHandle.add(importerId);\n }\n }\n\n if (dependentEntryPoints.length > 0) {\n return getChunkName(language);\n }\n};\n"],"mappings":";;;;AAIA,MAAMA,UAAQC,qBAAO,OAAO,sBAAsB;;;;AAKlD,MAAa,qBACX,IACA,EAAE,oBACC;CACH,MAAM,QAAQ,sBAAsB,KAAK,GAAG;AAC5C,KAAI,CAAC,MACH;CAGF,MAAM,WAAW,MAAM;CACvB,MAAMC,uBAAiC,EAAE;CAEzC,MAAM,iBAAiB,cAAc,GAAG;AAExC,KAAI,CAAC,gBAAgB;AACnB,UAAM,4BAA4B,KAAK;AACvC;;CAGF,MAAM,cAAc,IAAI,IAAY,eAAe,iBAAiB;AAEpE,MAAK,MAAM,YAAY,aAAa;EAClC,MAAM,aAAa,cAAc,SAAS;AAC1C,MAAI,CAAC,YAAY;AACf,WAAM,4BAA4B,WAAW;AAC7C;;EAGF,MAAM,EAAE,SAAS,kBAAkB,cAAc;AAEjD,MAAI,WAAW,iBAAiB,SAAS,EACvC,sBAAqB,KAAK,SAAS;AAGrC,OAAK,MAAM,cAAc,UACvB,aAAY,IAAI,WAAW;;AAI/B,KAAI,qBAAqB,SAAS,EAChC,QAAOC,oCAAa,SAAS"}
|
package/dist/chunks.mjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { trace } from "./logger-OmOg8OXO.mjs";
|
|
2
|
+
import { getChunkName } from "./get-chunk-name-C-VEd843.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/create-vocab-chunks.ts
|
|
5
|
+
const trace$1 = trace.extend("create-vocab-chunks");
|
|
6
|
+
/**
|
|
7
|
+
* Gets vocab virtual module details and creates chunks for each language
|
|
8
|
+
*/
|
|
9
|
+
const createVocabChunks = (id, { getModuleInfo }) => {
|
|
10
|
+
const match = /virtual:vocab-(\w+)/.exec(id);
|
|
11
|
+
if (!match) return;
|
|
12
|
+
const language = match[1];
|
|
13
|
+
const dependentEntryPoints = [];
|
|
14
|
+
const rootModuleInfo = getModuleInfo(id);
|
|
15
|
+
if (!rootModuleInfo) {
|
|
16
|
+
trace$1(`No module info found for ${id}`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const idsToHandle = new Set(rootModuleInfo.dynamicImporters);
|
|
20
|
+
for (const moduleId of idsToHandle) {
|
|
21
|
+
const moduleInfo = getModuleInfo(moduleId);
|
|
22
|
+
if (!moduleInfo) {
|
|
23
|
+
trace$1(`No module info found for ${moduleId}`);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const { isEntry, dynamicImporters, importers } = moduleInfo;
|
|
27
|
+
if (isEntry || dynamicImporters.length > 0) dependentEntryPoints.push(moduleId);
|
|
28
|
+
for (const importerId of importers) idsToHandle.add(importerId);
|
|
29
|
+
}
|
|
30
|
+
if (dependentEntryPoints.length > 0) return getChunkName(language);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { createVocabChunks, getChunkName };
|
|
35
|
+
//# sourceMappingURL=chunks.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunks.mjs","names":["trace","_trace","dependentEntryPoints: string[]"],"sources":["../src/create-vocab-chunks.ts"],"sourcesContent":["import type { Rollup } from 'vite';\nimport { trace as _trace } from './logger';\nimport { getChunkName } from './get-chunk-name';\n\nconst trace = _trace.extend('create-vocab-chunks');\n\n/**\n * Gets vocab virtual module details and creates chunks for each language\n */\nexport const createVocabChunks = (\n id: string,\n { getModuleInfo }: Rollup.ManualChunkMeta,\n) => {\n const match = /virtual:vocab-(\\w+)/.exec(id);\n if (!match) {\n return;\n }\n\n const language = match[1];\n const dependentEntryPoints: string[] = [];\n\n const rootModuleInfo = getModuleInfo(id);\n\n if (!rootModuleInfo) {\n trace(`No module info found for ${id}`);\n return;\n }\n\n const idsToHandle = new Set<string>(rootModuleInfo.dynamicImporters);\n\n for (const moduleId of idsToHandle) {\n const moduleInfo = getModuleInfo(moduleId);\n if (!moduleInfo) {\n trace(`No module info found for ${moduleId}`);\n continue;\n }\n\n const { isEntry, dynamicImporters, importers } = moduleInfo;\n\n if (isEntry || dynamicImporters.length > 0) {\n dependentEntryPoints.push(moduleId);\n }\n\n for (const importerId of importers) {\n idsToHandle.add(importerId);\n }\n }\n\n if (dependentEntryPoints.length > 0) {\n return getChunkName(language);\n }\n};\n"],"mappings":";;;;AAIA,MAAMA,UAAQC,MAAO,OAAO,sBAAsB;;;;AAKlD,MAAa,qBACX,IACA,EAAE,oBACC;CACH,MAAM,QAAQ,sBAAsB,KAAK,GAAG;AAC5C,KAAI,CAAC,MACH;CAGF,MAAM,WAAW,MAAM;CACvB,MAAMC,uBAAiC,EAAE;CAEzC,MAAM,iBAAiB,cAAc,GAAG;AAExC,KAAI,CAAC,gBAAgB;AACnB,UAAM,4BAA4B,KAAK;AACvC;;CAGF,MAAM,cAAc,IAAI,IAAY,eAAe,iBAAiB;AAEpE,MAAK,MAAM,YAAY,aAAa;EAClC,MAAM,aAAa,cAAc,SAAS;AAC1C,MAAI,CAAC,YAAY;AACf,WAAM,4BAA4B,WAAW;AAC7C;;EAGF,MAAM,EAAE,SAAS,kBAAkB,cAAc;AAEjD,MAAI,WAAW,iBAAiB,SAAS,EACvC,sBAAqB,KAAK,SAAS;AAGrC,OAAK,MAAM,cAAc,UACvB,aAAY,IAAI,WAAW;;AAI/B,KAAI,qBAAqB,SAAS,EAChC,QAAO,aAAa,SAAS"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/get-chunk-name.ts
|
|
3
|
+
function getChunkName(lang) {
|
|
4
|
+
return `${lang}-translations`;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
Object.defineProperty(exports, 'getChunkName', {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return getChunkName;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=get-chunk-name-BXaBbR1f.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-chunk-name-BXaBbR1f.js","names":[],"sources":["../src/get-chunk-name.ts"],"sourcesContent":["export function getChunkName(lang: string) {\n return `${lang}-translations`;\n}\n"],"mappings":";;AAAA,SAAgB,aAAa,MAAc;AACzC,QAAO,GAAG,KAAK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-chunk-name-C-VEd843.mjs","names":[],"sources":["../src/get-chunk-name.ts"],"sourcesContent":["export function getChunkName(lang: string) {\n return `${lang}-translations`;\n}\n"],"mappings":";AAAA,SAAgB,aAAa,MAAc;AACzC,QAAO,GAAG,KAAK"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UserConfig } from "@vocab/core";
|
|
2
|
+
import { Plugin } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
type VocabPluginOptions = {
|
|
6
|
+
vocabConfig: UserConfig;
|
|
7
|
+
};
|
|
8
|
+
declare function vitePluginVocab({
|
|
9
|
+
vocabConfig
|
|
10
|
+
}: VocabPluginOptions): Plugin;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { VocabPluginOptions, vitePluginVocab as default };
|
|
13
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
import { UserConfig } from "@vocab/core";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
type VocabPluginOptions = {
|
|
6
|
+
vocabConfig: UserConfig;
|
|
7
|
+
};
|
|
8
|
+
declare function vitePluginVocab({
|
|
9
|
+
vocabConfig
|
|
10
|
+
}: VocabPluginOptions): Plugin;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { VocabPluginOptions, vitePluginVocab as default };
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-nOFOJqeH.js');
|
|
2
|
+
const require_logger = require('./logger-BBoxZFcH.js');
|
|
3
|
+
let __vocab_core = require("@vocab/core");
|
|
4
|
+
__vocab_core = require_chunk.__toESM(__vocab_core);
|
|
5
|
+
let es_module_lexer = require("es-module-lexer");
|
|
6
|
+
es_module_lexer = require_chunk.__toESM(es_module_lexer);
|
|
7
|
+
let cjs_module_lexer = require("cjs-module-lexer");
|
|
8
|
+
cjs_module_lexer = require_chunk.__toESM(cjs_module_lexer);
|
|
9
|
+
|
|
10
|
+
//#region src/consts.ts
|
|
11
|
+
const compiledVocabFileFilter = /\.vocab[\\/]index\.(?:ts|js|cjs|mjs)$/;
|
|
12
|
+
const virtualModuleId = "virtual:vocab";
|
|
13
|
+
const sourceQueryKey = "?source=";
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/transform-vocab-file.ts
|
|
17
|
+
const trace$1 = require_logger.trace.extend("transform");
|
|
18
|
+
function findExportNames(source, mode) {
|
|
19
|
+
if (mode === "esm") {
|
|
20
|
+
const [, exports$2] = es_module_lexer.parse(source);
|
|
21
|
+
return exports$2;
|
|
22
|
+
}
|
|
23
|
+
const { exports: exports$1 } = cjs_module_lexer.parse(source);
|
|
24
|
+
return exports$1;
|
|
25
|
+
}
|
|
26
|
+
const transformVocabFile = async (code, id, config) => {
|
|
27
|
+
trace$1("Transforming vocab file", id);
|
|
28
|
+
let result = code;
|
|
29
|
+
const devJsonFilePath = (0, __vocab_core.getDevLanguageFileFromTsFile)(id);
|
|
30
|
+
const loadedTranslation = (0, __vocab_core.loadTranslation)({
|
|
31
|
+
filePath: devJsonFilePath,
|
|
32
|
+
fallbacks: "all"
|
|
33
|
+
}, config);
|
|
34
|
+
const renderLanguageLoader = renderLanguageLoaderAsync(loadedTranslation);
|
|
35
|
+
const translations = `
|
|
36
|
+
const translations = createTranslationFile({
|
|
37
|
+
${Object.keys(loadedTranslation.languages).map((lang) => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(",\n")}
|
|
38
|
+
});
|
|
39
|
+
`;
|
|
40
|
+
await es_module_lexer.init;
|
|
41
|
+
const esmExports = findExportNames(code, "esm");
|
|
42
|
+
if (esmExports.length > 0) {
|
|
43
|
+
const exportName = esmExports[0];
|
|
44
|
+
trace$1(`Found ESM export '${exportName.n}' in ${id}`);
|
|
45
|
+
result = `
|
|
46
|
+
import { createLanguage, createTranslationFile } from '@vocab/vite/runtime';
|
|
47
|
+
${translations}
|
|
48
|
+
export { translations as ${exportName.n} };
|
|
49
|
+
`;
|
|
50
|
+
} else {
|
|
51
|
+
await cjs_module_lexer.init();
|
|
52
|
+
const exportName = findExportNames(code, "cjs")[0];
|
|
53
|
+
trace$1(`Found CJS export '${exportName}' in ${id}`);
|
|
54
|
+
result = `
|
|
55
|
+
import { createLanguage, createTranslationFile } from '@vocab/vite/runtime';
|
|
56
|
+
${translations}
|
|
57
|
+
exports.${exportName} = translations;
|
|
58
|
+
`;
|
|
59
|
+
}
|
|
60
|
+
trace$1("Created translation file", result);
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
const renderLanguageLoaderAsync = (loadedTranslation) => (lang) => {
|
|
64
|
+
return `createLanguage(() => import(${JSON.stringify(createIdentifier(lang, loadedTranslation))}))`.trim();
|
|
65
|
+
};
|
|
66
|
+
const createIdentifier = (lang, loadedTranslation) => {
|
|
67
|
+
const languageTranslations = loadedTranslation.languages[lang] ?? {};
|
|
68
|
+
const langJson = {};
|
|
69
|
+
for (const key of loadedTranslation.keys) langJson[key] = languageTranslations[key].message;
|
|
70
|
+
const base64 = Buffer.from(JSON.stringify(langJson), "utf-8").toString("base64");
|
|
71
|
+
const encodedResource = `${sourceQueryKey}${base64}`;
|
|
72
|
+
return `${virtualModuleId}-${lang}.json${encodedResource}`;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/virtual-resource-loader.ts
|
|
77
|
+
const virtualResourceLoader = (path) => Buffer.from(path.split(sourceQueryKey)[1], "base64").toString("utf-8");
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/index.ts
|
|
81
|
+
function vitePluginVocab({ vocabConfig }) {
|
|
82
|
+
let isSSR = false;
|
|
83
|
+
require_logger.trace(`Creating Vocab plugin${vocabConfig ? ` with config file ${vocabConfig}` : ""}`);
|
|
84
|
+
return {
|
|
85
|
+
name: "vite-plugin-vocab",
|
|
86
|
+
apply: "build",
|
|
87
|
+
enforce: "pre",
|
|
88
|
+
configResolved(config) {
|
|
89
|
+
isSSR = Boolean(config.build.ssr);
|
|
90
|
+
},
|
|
91
|
+
resolveId(id) {
|
|
92
|
+
if (isSSR) return null;
|
|
93
|
+
if (id.includes(virtualModuleId)) return `\0${id}`;
|
|
94
|
+
},
|
|
95
|
+
load(id) {
|
|
96
|
+
if (isSSR) return null;
|
|
97
|
+
if (id.includes(`\0${virtualModuleId}`)) return virtualResourceLoader(id);
|
|
98
|
+
},
|
|
99
|
+
async transform(code, id) {
|
|
100
|
+
if (isSSR) return null;
|
|
101
|
+
if (compiledVocabFileFilter.test(id)) return {
|
|
102
|
+
code: await transformVocabFile(code, id, vocabConfig),
|
|
103
|
+
map: null
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
module.exports = vitePluginVocab;
|
|
111
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["trace","_trace","exports","esModuleLexer","cjsModuleLexer","langJson: TranslationMessagesByKey"],"sources":["../src/consts.ts","../src/transform-vocab-file.ts","../src/virtual-resource-loader.ts","../src/index.ts"],"sourcesContent":["export const compiledVocabFileFilter = /\\.vocab[\\\\/]index\\.(?:ts|js|cjs|mjs)$/;\nexport const virtualModuleId = 'virtual:vocab';\nexport const sourceQueryKey = '?source=';\n","import {\n getDevLanguageFileFromTsFile,\n type LoadedTranslation,\n loadTranslation,\n type TranslationMessagesByKey,\n type UserConfig,\n} from '@vocab/core';\n\nimport * as esModuleLexer from 'es-module-lexer';\nimport * as cjsModuleLexer from 'cjs-module-lexer';\n\nimport { sourceQueryKey, virtualModuleId } from './consts';\n\nimport { trace as _trace } from './logger';\n\nconst trace = _trace.extend('transform');\n\nfunction findExportNames(source: string, mode: 'cjs'): string[];\nfunction findExportNames(\n source: string,\n mode: 'esm',\n): esModuleLexer.ExportSpecifier[];\nfunction findExportNames(source: string, mode: 'cjs' | 'esm') {\n if (mode === 'esm') {\n const [, exports] = esModuleLexer.parse(source);\n return exports;\n }\n const { exports } = cjsModuleLexer.parse(source);\n return exports;\n}\n\nexport const transformVocabFile = async (\n code: string,\n id: string,\n config: UserConfig,\n) => {\n trace('Transforming vocab file', id);\n\n let result = code;\n\n const devJsonFilePath = getDevLanguageFileFromTsFile(id);\n\n const loadedTranslation = loadTranslation(\n { filePath: devJsonFilePath, fallbacks: 'all' },\n config,\n );\n\n const renderLanguageLoader = renderLanguageLoaderAsync(loadedTranslation);\n\n const translations = /* ts */ `\n const translations = createTranslationFile({\n ${Object.keys(loadedTranslation.languages)\n .map((lang) => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`)\n .join(',\\n')}\n });\n `;\n\n await esModuleLexer.init;\n const esmExports = findExportNames(code, 'esm');\n if (esmExports.length > 0) {\n const exportName = esmExports[0];\n trace(`Found ESM export '${exportName.n}' in ${id}`);\n\n result = /* ts */ `\n import { createLanguage, createTranslationFile } from '@vocab/vite/runtime';\n ${translations}\n export { translations as ${exportName.n} };\n `;\n } else {\n // init needs to be called and waited upon\n await cjsModuleLexer.init();\n\n const exportName = findExportNames(code, 'cjs')[0];\n trace(`Found CJS export '${exportName}' in ${id}`);\n\n result = /* ts */ `\n import { createLanguage, createTranslationFile } from '@vocab/vite/runtime';\n ${translations}\n exports.${exportName} = translations;\n `;\n }\n trace('Created translation file', result);\n\n return result;\n};\n\nconst renderLanguageLoaderAsync =\n (loadedTranslation: LoadedTranslation) => (lang: string) => {\n const identifier = JSON.stringify(\n createIdentifier(lang, loadedTranslation),\n );\n\n return /* ts */ `createLanguage(() => import(${identifier}))`.trim();\n };\n\nconst createIdentifier = (\n lang: string,\n loadedTranslation: LoadedTranslation,\n) => {\n const languageTranslations = loadedTranslation.languages[lang] ?? {};\n\n const langJson: TranslationMessagesByKey = {};\n\n for (const key of loadedTranslation.keys) {\n langJson[key] = languageTranslations[key].message;\n }\n\n const base64 = Buffer.from(JSON.stringify(langJson), 'utf-8').toString(\n 'base64',\n );\n\n const encodedResource = `${sourceQueryKey}${base64}`;\n\n return `${virtualModuleId}-${lang}.json${encodedResource}`;\n};\n","import { sourceQueryKey } from './consts';\n\nexport const virtualResourceLoader = (path: string) =>\n Buffer.from(path.split(sourceQueryKey)[1] as string, 'base64').toString(\n 'utf-8',\n );\n","import type { Plugin as VitePlugin } from 'vite';\nimport type { UserConfig } from '@vocab/core';\n\nimport { transformVocabFile } from './transform-vocab-file';\nimport { virtualResourceLoader } from './virtual-resource-loader';\n\nimport { trace } from './logger';\n\nimport { compiledVocabFileFilter, virtualModuleId } from './consts';\n\nexport type VocabPluginOptions = {\n vocabConfig: UserConfig;\n};\n\nexport default function vitePluginVocab({\n vocabConfig,\n}: VocabPluginOptions): VitePlugin {\n let isSSR = false;\n\n trace(\n `Creating Vocab plugin${\n vocabConfig ? ` with config file ${vocabConfig}` : ''\n }`,\n );\n\n return {\n name: 'vite-plugin-vocab',\n apply: 'build',\n enforce: 'pre',\n configResolved(config) {\n // Check if the build is for SSR. This plugin should not run for SSR builds.\n isSSR = Boolean(config.build.ssr);\n },\n resolveId(id) {\n if (isSSR) {\n return null;\n }\n\n if (id.includes(virtualModuleId)) {\n return `\\0${id}`;\n }\n },\n load(id) {\n if (isSSR) {\n return null;\n }\n\n if (id.includes(`\\0${virtualModuleId}`)) {\n return virtualResourceLoader(id);\n }\n },\n async transform(code, id) {\n if (isSSR) {\n return null;\n }\n\n if (compiledVocabFileFilter.test(id)) {\n const transformedCode = await transformVocabFile(code, id, vocabConfig);\n\n return {\n code: transformedCode,\n map: null, // provide source map if available\n };\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;AAAA,MAAa,0BAA0B;AACvC,MAAa,kBAAkB;AAC/B,MAAa,iBAAiB;;;;ACa9B,MAAMA,UAAQC,qBAAO,OAAO,YAAY;AAOxC,SAAS,gBAAgB,QAAgB,MAAqB;AAC5D,KAAI,SAAS,OAAO;EAClB,MAAM,GAAGC,aAAWC,gBAAc,MAAM,OAAO;AAC/C,SAAOD;;CAET,MAAM,EAAE,uBAAYE,iBAAe,MAAM,OAAO;AAChD,QAAOF;;AAGT,MAAa,qBAAqB,OAChC,MACA,IACA,WACG;AACH,SAAM,2BAA2B,GAAG;CAEpC,IAAI,SAAS;CAEb,MAAM,iEAA+C,GAAG;CAExD,MAAM,sDACJ;EAAE,UAAU;EAAiB,WAAW;EAAO,EAC/C,OACD;CAED,MAAM,uBAAuB,0BAA0B,kBAAkB;CAEzE,MAAM,eAAwB;;QAExB,OAAO,KAAK,kBAAkB,UAAU,CACvC,KAAK,SAAS,GAAG,KAAK,UAAU,KAAK,CAAC,IAAI,qBAAqB,KAAK,GAAG,CACvE,KAAK,MAAM,CAAC;;;AAInB,OAAMC,gBAAc;CACpB,MAAM,aAAa,gBAAgB,MAAM,MAAM;AAC/C,KAAI,WAAW,SAAS,GAAG;EACzB,MAAM,aAAa,WAAW;AAC9B,UAAM,qBAAqB,WAAW,EAAE,OAAO,KAAK;AAEpD,WAAkB;;QAEd,aAAa;iCACY,WAAW,EAAE;;QAErC;AAEL,QAAMC,iBAAe,MAAM;EAE3B,MAAM,aAAa,gBAAgB,MAAM,MAAM,CAAC;AAChD,UAAM,qBAAqB,WAAW,OAAO,KAAK;AAElD,WAAkB;;QAEd,aAAa;gBACL,WAAW;;;AAGzB,SAAM,4BAA4B,OAAO;AAEzC,QAAO;;AAGT,MAAM,6BACH,uBAA0C,SAAiB;AAK1D,QAAgB,+BAJG,KAAK,UACtB,iBAAiB,MAAM,kBAAkB,CAC1C,CAEyD,IAAI,MAAM;;AAGxE,MAAM,oBACJ,MACA,sBACG;CACH,MAAM,uBAAuB,kBAAkB,UAAU,SAAS,EAAE;CAEpE,MAAMC,WAAqC,EAAE;AAE7C,MAAK,MAAM,OAAO,kBAAkB,KAClC,UAAS,OAAO,qBAAqB,KAAK;CAG5C,MAAM,SAAS,OAAO,KAAK,KAAK,UAAU,SAAS,EAAE,QAAQ,CAAC,SAC5D,SACD;CAED,MAAM,kBAAkB,GAAG,iBAAiB;AAE5C,QAAO,GAAG,gBAAgB,GAAG,KAAK,OAAO;;;;;AC/G3C,MAAa,yBAAyB,SACpC,OAAO,KAAK,KAAK,MAAM,eAAe,CAAC,IAAc,SAAS,CAAC,SAC7D,QACD;;;;ACSH,SAAwB,gBAAgB,EACtC,eACiC;CACjC,IAAI,QAAQ;AAEZ,sBACE,wBACE,cAAc,qBAAqB,gBAAgB,KAEtD;AAED,QAAO;EACL,MAAM;EACN,OAAO;EACP,SAAS;EACT,eAAe,QAAQ;AAErB,WAAQ,QAAQ,OAAO,MAAM,IAAI;;EAEnC,UAAU,IAAI;AACZ,OAAI,MACF,QAAO;AAGT,OAAI,GAAG,SAAS,gBAAgB,CAC9B,QAAO,KAAK;;EAGhB,KAAK,IAAI;AACP,OAAI,MACF,QAAO;AAGT,OAAI,GAAG,SAAS,KAAK,kBAAkB,CACrC,QAAO,sBAAsB,GAAG;;EAGpC,MAAM,UAAU,MAAM,IAAI;AACxB,OAAI,MACF,QAAO;AAGT,OAAI,wBAAwB,KAAK,GAAG,CAGlC,QAAO;IACL,MAHsB,MAAM,mBAAmB,MAAM,IAAI,YAAY;IAIrE,KAAK;IACN;;EAGN"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { trace } from "./logger-OmOg8OXO.mjs";
|
|
2
|
+
import { getDevLanguageFileFromTsFile, loadTranslation } from "@vocab/core";
|
|
3
|
+
import * as esModuleLexer from "es-module-lexer";
|
|
4
|
+
import * as cjsModuleLexer from "cjs-module-lexer";
|
|
5
|
+
|
|
6
|
+
//#region src/consts.ts
|
|
7
|
+
const compiledVocabFileFilter = /\.vocab[\\/]index\.(?:ts|js|cjs|mjs)$/;
|
|
8
|
+
const virtualModuleId = "virtual:vocab";
|
|
9
|
+
const sourceQueryKey = "?source=";
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/transform-vocab-file.ts
|
|
13
|
+
const trace$1 = trace.extend("transform");
|
|
14
|
+
function findExportNames(source, mode) {
|
|
15
|
+
if (mode === "esm") {
|
|
16
|
+
const [, exports$1] = esModuleLexer.parse(source);
|
|
17
|
+
return exports$1;
|
|
18
|
+
}
|
|
19
|
+
const { exports } = cjsModuleLexer.parse(source);
|
|
20
|
+
return exports;
|
|
21
|
+
}
|
|
22
|
+
const transformVocabFile = async (code, id, config) => {
|
|
23
|
+
trace$1("Transforming vocab file", id);
|
|
24
|
+
let result = code;
|
|
25
|
+
const devJsonFilePath = getDevLanguageFileFromTsFile(id);
|
|
26
|
+
const loadedTranslation = loadTranslation({
|
|
27
|
+
filePath: devJsonFilePath,
|
|
28
|
+
fallbacks: "all"
|
|
29
|
+
}, config);
|
|
30
|
+
const renderLanguageLoader = renderLanguageLoaderAsync(loadedTranslation);
|
|
31
|
+
const translations = `
|
|
32
|
+
const translations = createTranslationFile({
|
|
33
|
+
${Object.keys(loadedTranslation.languages).map((lang) => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`).join(",\n")}
|
|
34
|
+
});
|
|
35
|
+
`;
|
|
36
|
+
await esModuleLexer.init;
|
|
37
|
+
const esmExports = findExportNames(code, "esm");
|
|
38
|
+
if (esmExports.length > 0) {
|
|
39
|
+
const exportName = esmExports[0];
|
|
40
|
+
trace$1(`Found ESM export '${exportName.n}' in ${id}`);
|
|
41
|
+
result = `
|
|
42
|
+
import { createLanguage, createTranslationFile } from '@vocab/vite/runtime';
|
|
43
|
+
${translations}
|
|
44
|
+
export { translations as ${exportName.n} };
|
|
45
|
+
`;
|
|
46
|
+
} else {
|
|
47
|
+
await cjsModuleLexer.init();
|
|
48
|
+
const exportName = findExportNames(code, "cjs")[0];
|
|
49
|
+
trace$1(`Found CJS export '${exportName}' in ${id}`);
|
|
50
|
+
result = `
|
|
51
|
+
import { createLanguage, createTranslationFile } from '@vocab/vite/runtime';
|
|
52
|
+
${translations}
|
|
53
|
+
exports.${exportName} = translations;
|
|
54
|
+
`;
|
|
55
|
+
}
|
|
56
|
+
trace$1("Created translation file", result);
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
const renderLanguageLoaderAsync = (loadedTranslation) => (lang) => {
|
|
60
|
+
return `createLanguage(() => import(${JSON.stringify(createIdentifier(lang, loadedTranslation))}))`.trim();
|
|
61
|
+
};
|
|
62
|
+
const createIdentifier = (lang, loadedTranslation) => {
|
|
63
|
+
const languageTranslations = loadedTranslation.languages[lang] ?? {};
|
|
64
|
+
const langJson = {};
|
|
65
|
+
for (const key of loadedTranslation.keys) langJson[key] = languageTranslations[key].message;
|
|
66
|
+
const base64 = Buffer.from(JSON.stringify(langJson), "utf-8").toString("base64");
|
|
67
|
+
const encodedResource = `${sourceQueryKey}${base64}`;
|
|
68
|
+
return `${virtualModuleId}-${lang}.json${encodedResource}`;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/virtual-resource-loader.ts
|
|
73
|
+
const virtualResourceLoader = (path) => Buffer.from(path.split(sourceQueryKey)[1], "base64").toString("utf-8");
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/index.ts
|
|
77
|
+
function vitePluginVocab({ vocabConfig }) {
|
|
78
|
+
let isSSR = false;
|
|
79
|
+
trace(`Creating Vocab plugin${vocabConfig ? ` with config file ${vocabConfig}` : ""}`);
|
|
80
|
+
return {
|
|
81
|
+
name: "vite-plugin-vocab",
|
|
82
|
+
apply: "build",
|
|
83
|
+
enforce: "pre",
|
|
84
|
+
configResolved(config) {
|
|
85
|
+
isSSR = Boolean(config.build.ssr);
|
|
86
|
+
},
|
|
87
|
+
resolveId(id) {
|
|
88
|
+
if (isSSR) return null;
|
|
89
|
+
if (id.includes(virtualModuleId)) return `\0${id}`;
|
|
90
|
+
},
|
|
91
|
+
load(id) {
|
|
92
|
+
if (isSSR) return null;
|
|
93
|
+
if (id.includes(`\0${virtualModuleId}`)) return virtualResourceLoader(id);
|
|
94
|
+
},
|
|
95
|
+
async transform(code, id) {
|
|
96
|
+
if (isSSR) return null;
|
|
97
|
+
if (compiledVocabFileFilter.test(id)) return {
|
|
98
|
+
code: await transformVocabFile(code, id, vocabConfig),
|
|
99
|
+
map: null
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { vitePluginVocab as default };
|
|
107
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["trace","_trace","exports","langJson: TranslationMessagesByKey"],"sources":["../src/consts.ts","../src/transform-vocab-file.ts","../src/virtual-resource-loader.ts","../src/index.ts"],"sourcesContent":["export const compiledVocabFileFilter = /\\.vocab[\\\\/]index\\.(?:ts|js|cjs|mjs)$/;\nexport const virtualModuleId = 'virtual:vocab';\nexport const sourceQueryKey = '?source=';\n","import {\n getDevLanguageFileFromTsFile,\n type LoadedTranslation,\n loadTranslation,\n type TranslationMessagesByKey,\n type UserConfig,\n} from '@vocab/core';\n\nimport * as esModuleLexer from 'es-module-lexer';\nimport * as cjsModuleLexer from 'cjs-module-lexer';\n\nimport { sourceQueryKey, virtualModuleId } from './consts';\n\nimport { trace as _trace } from './logger';\n\nconst trace = _trace.extend('transform');\n\nfunction findExportNames(source: string, mode: 'cjs'): string[];\nfunction findExportNames(\n source: string,\n mode: 'esm',\n): esModuleLexer.ExportSpecifier[];\nfunction findExportNames(source: string, mode: 'cjs' | 'esm') {\n if (mode === 'esm') {\n const [, exports] = esModuleLexer.parse(source);\n return exports;\n }\n const { exports } = cjsModuleLexer.parse(source);\n return exports;\n}\n\nexport const transformVocabFile = async (\n code: string,\n id: string,\n config: UserConfig,\n) => {\n trace('Transforming vocab file', id);\n\n let result = code;\n\n const devJsonFilePath = getDevLanguageFileFromTsFile(id);\n\n const loadedTranslation = loadTranslation(\n { filePath: devJsonFilePath, fallbacks: 'all' },\n config,\n );\n\n const renderLanguageLoader = renderLanguageLoaderAsync(loadedTranslation);\n\n const translations = /* ts */ `\n const translations = createTranslationFile({\n ${Object.keys(loadedTranslation.languages)\n .map((lang) => `${JSON.stringify(lang)}: ${renderLanguageLoader(lang)}`)\n .join(',\\n')}\n });\n `;\n\n await esModuleLexer.init;\n const esmExports = findExportNames(code, 'esm');\n if (esmExports.length > 0) {\n const exportName = esmExports[0];\n trace(`Found ESM export '${exportName.n}' in ${id}`);\n\n result = /* ts */ `\n import { createLanguage, createTranslationFile } from '@vocab/vite/runtime';\n ${translations}\n export { translations as ${exportName.n} };\n `;\n } else {\n // init needs to be called and waited upon\n await cjsModuleLexer.init();\n\n const exportName = findExportNames(code, 'cjs')[0];\n trace(`Found CJS export '${exportName}' in ${id}`);\n\n result = /* ts */ `\n import { createLanguage, createTranslationFile } from '@vocab/vite/runtime';\n ${translations}\n exports.${exportName} = translations;\n `;\n }\n trace('Created translation file', result);\n\n return result;\n};\n\nconst renderLanguageLoaderAsync =\n (loadedTranslation: LoadedTranslation) => (lang: string) => {\n const identifier = JSON.stringify(\n createIdentifier(lang, loadedTranslation),\n );\n\n return /* ts */ `createLanguage(() => import(${identifier}))`.trim();\n };\n\nconst createIdentifier = (\n lang: string,\n loadedTranslation: LoadedTranslation,\n) => {\n const languageTranslations = loadedTranslation.languages[lang] ?? {};\n\n const langJson: TranslationMessagesByKey = {};\n\n for (const key of loadedTranslation.keys) {\n langJson[key] = languageTranslations[key].message;\n }\n\n const base64 = Buffer.from(JSON.stringify(langJson), 'utf-8').toString(\n 'base64',\n );\n\n const encodedResource = `${sourceQueryKey}${base64}`;\n\n return `${virtualModuleId}-${lang}.json${encodedResource}`;\n};\n","import { sourceQueryKey } from './consts';\n\nexport const virtualResourceLoader = (path: string) =>\n Buffer.from(path.split(sourceQueryKey)[1] as string, 'base64').toString(\n 'utf-8',\n );\n","import type { Plugin as VitePlugin } from 'vite';\nimport type { UserConfig } from '@vocab/core';\n\nimport { transformVocabFile } from './transform-vocab-file';\nimport { virtualResourceLoader } from './virtual-resource-loader';\n\nimport { trace } from './logger';\n\nimport { compiledVocabFileFilter, virtualModuleId } from './consts';\n\nexport type VocabPluginOptions = {\n vocabConfig: UserConfig;\n};\n\nexport default function vitePluginVocab({\n vocabConfig,\n}: VocabPluginOptions): VitePlugin {\n let isSSR = false;\n\n trace(\n `Creating Vocab plugin${\n vocabConfig ? ` with config file ${vocabConfig}` : ''\n }`,\n );\n\n return {\n name: 'vite-plugin-vocab',\n apply: 'build',\n enforce: 'pre',\n configResolved(config) {\n // Check if the build is for SSR. This plugin should not run for SSR builds.\n isSSR = Boolean(config.build.ssr);\n },\n resolveId(id) {\n if (isSSR) {\n return null;\n }\n\n if (id.includes(virtualModuleId)) {\n return `\\0${id}`;\n }\n },\n load(id) {\n if (isSSR) {\n return null;\n }\n\n if (id.includes(`\\0${virtualModuleId}`)) {\n return virtualResourceLoader(id);\n }\n },\n async transform(code, id) {\n if (isSSR) {\n return null;\n }\n\n if (compiledVocabFileFilter.test(id)) {\n const transformedCode = await transformVocabFile(code, id, vocabConfig);\n\n return {\n code: transformedCode,\n map: null, // provide source map if available\n };\n }\n },\n };\n}\n"],"mappings":";;;;;;AAAA,MAAa,0BAA0B;AACvC,MAAa,kBAAkB;AAC/B,MAAa,iBAAiB;;;;ACa9B,MAAMA,UAAQC,MAAO,OAAO,YAAY;AAOxC,SAAS,gBAAgB,QAAgB,MAAqB;AAC5D,KAAI,SAAS,OAAO;EAClB,MAAM,GAAGC,aAAW,cAAc,MAAM,OAAO;AAC/C,SAAOA;;CAET,MAAM,EAAE,YAAY,eAAe,MAAM,OAAO;AAChD,QAAO;;AAGT,MAAa,qBAAqB,OAChC,MACA,IACA,WACG;AACH,SAAM,2BAA2B,GAAG;CAEpC,IAAI,SAAS;CAEb,MAAM,kBAAkB,6BAA6B,GAAG;CAExD,MAAM,oBAAoB,gBACxB;EAAE,UAAU;EAAiB,WAAW;EAAO,EAC/C,OACD;CAED,MAAM,uBAAuB,0BAA0B,kBAAkB;CAEzE,MAAM,eAAwB;;QAExB,OAAO,KAAK,kBAAkB,UAAU,CACvC,KAAK,SAAS,GAAG,KAAK,UAAU,KAAK,CAAC,IAAI,qBAAqB,KAAK,GAAG,CACvE,KAAK,MAAM,CAAC;;;AAInB,OAAM,cAAc;CACpB,MAAM,aAAa,gBAAgB,MAAM,MAAM;AAC/C,KAAI,WAAW,SAAS,GAAG;EACzB,MAAM,aAAa,WAAW;AAC9B,UAAM,qBAAqB,WAAW,EAAE,OAAO,KAAK;AAEpD,WAAkB;;QAEd,aAAa;iCACY,WAAW,EAAE;;QAErC;AAEL,QAAM,eAAe,MAAM;EAE3B,MAAM,aAAa,gBAAgB,MAAM,MAAM,CAAC;AAChD,UAAM,qBAAqB,WAAW,OAAO,KAAK;AAElD,WAAkB;;QAEd,aAAa;gBACL,WAAW;;;AAGzB,SAAM,4BAA4B,OAAO;AAEzC,QAAO;;AAGT,MAAM,6BACH,uBAA0C,SAAiB;AAK1D,QAAgB,+BAJG,KAAK,UACtB,iBAAiB,MAAM,kBAAkB,CAC1C,CAEyD,IAAI,MAAM;;AAGxE,MAAM,oBACJ,MACA,sBACG;CACH,MAAM,uBAAuB,kBAAkB,UAAU,SAAS,EAAE;CAEpE,MAAMC,WAAqC,EAAE;AAE7C,MAAK,MAAM,OAAO,kBAAkB,KAClC,UAAS,OAAO,qBAAqB,KAAK;CAG5C,MAAM,SAAS,OAAO,KAAK,KAAK,UAAU,SAAS,EAAE,QAAQ,CAAC,SAC5D,SACD;CAED,MAAM,kBAAkB,GAAG,iBAAiB;AAE5C,QAAO,GAAG,gBAAgB,GAAG,KAAK,OAAO;;;;;AC/G3C,MAAa,yBAAyB,SACpC,OAAO,KAAK,KAAK,MAAM,eAAe,CAAC,IAAc,SAAS,CAAC,SAC7D,QACD;;;;ACSH,SAAwB,gBAAgB,EACtC,eACiC;CACjC,IAAI,QAAQ;AAEZ,OACE,wBACE,cAAc,qBAAqB,gBAAgB,KAEtD;AAED,QAAO;EACL,MAAM;EACN,OAAO;EACP,SAAS;EACT,eAAe,QAAQ;AAErB,WAAQ,QAAQ,OAAO,MAAM,IAAI;;EAEnC,UAAU,IAAI;AACZ,OAAI,MACF,QAAO;AAGT,OAAI,GAAG,SAAS,gBAAgB,CAC9B,QAAO,KAAK;;EAGhB,KAAK,IAAI;AACP,OAAI,MACF,QAAO;AAGT,OAAI,GAAG,SAAS,KAAK,kBAAkB,CACrC,QAAO,sBAAsB,GAAG;;EAGpC,MAAM,UAAU,MAAM,IAAI;AACxB,OAAI,MACF,QAAO;AAGT,OAAI,wBAAwB,KAAK,GAAG,CAGlC,QAAO;IACL,MAHsB,MAAM,mBAAmB,MAAM,IAAI,YAAY;IAIrE,KAAK;IACN;;EAGN"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-nOFOJqeH.js');
|
|
2
|
+
require("picocolors");
|
|
3
|
+
let debug = require("debug");
|
|
4
|
+
debug = require_chunk.__toESM(debug);
|
|
5
|
+
|
|
6
|
+
//#region src/logger.ts
|
|
7
|
+
const trace = (0, debug.default)(`vocab:vite`);
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
Object.defineProperty(exports, 'trace', {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return trace;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=logger-BBoxZFcH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-BBoxZFcH.js","names":[],"sources":["../src/logger.ts"],"sourcesContent":["import pc from 'picocolors';\nimport debug from 'debug';\n\nexport const trace = debug(`vocab:vite`);\n\nexport const log = (...params: unknown[]) => {\n // eslint-disable-next-line no-console\n console.log(pc.yellow('Vocab'), ...params);\n};\n"],"mappings":";;;;;;AAGA,MAAa,2BAAc,aAAa"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-OmOg8OXO.mjs","names":[],"sources":["../src/logger.ts"],"sourcesContent":["import pc from 'picocolors';\nimport debug from 'debug';\n\nexport const trace = debug(`vocab:vite`);\n\nexport const log = (...params: unknown[]) => {\n // eslint-disable-next-line no-console\n console.log(pc.yellow('Vocab'), ...params);\n};\n"],"mappings":";;;;AAGA,MAAa,QAAQ,MAAM,aAAa"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TranslationModule } from "@vocab/core";
|
|
2
|
+
import { createTranslationFile } from "@vocab/core/translation-file";
|
|
3
|
+
|
|
4
|
+
//#region src/create-language.d.ts
|
|
5
|
+
declare const createLanguage: (loadImport: () => Promise<any>) => TranslationModule<any>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createLanguage, createTranslationFile };
|
|
8
|
+
//# sourceMappingURL=runtime.d.mts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TranslationModule } from "@vocab/core";
|
|
2
|
+
import { createTranslationFile } from "@vocab/core/translation-file";
|
|
3
|
+
|
|
4
|
+
//#region src/create-language.d.ts
|
|
5
|
+
declare const createLanguage: (loadImport: () => Promise<any>) => TranslationModule<any>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createLanguage, createTranslationFile };
|
|
8
|
+
//# sourceMappingURL=runtime.d.ts.map
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-nOFOJqeH.js');
|
|
2
|
+
let __vocab_core_translation_file = require("@vocab/core/translation-file");
|
|
3
|
+
__vocab_core_translation_file = require_chunk.__toESM(__vocab_core_translation_file);
|
|
4
|
+
let __vocab_core_icu_handler = require("@vocab/core/icu-handler");
|
|
5
|
+
__vocab_core_icu_handler = require_chunk.__toESM(__vocab_core_icu_handler);
|
|
6
|
+
|
|
7
|
+
//#region src/create-language.ts
|
|
8
|
+
const createLanguage = (loadImport) => {
|
|
9
|
+
let promiseValue;
|
|
10
|
+
let resolvedValue;
|
|
11
|
+
return {
|
|
12
|
+
getValue: (locale) => {
|
|
13
|
+
if (!resolvedValue) return;
|
|
14
|
+
return (0, __vocab_core_icu_handler.getParsedICUMessages)(resolvedValue, locale);
|
|
15
|
+
},
|
|
16
|
+
load: () => {
|
|
17
|
+
if (!promiseValue) {
|
|
18
|
+
promiseValue = loadImport();
|
|
19
|
+
promiseValue.then((value) => {
|
|
20
|
+
resolvedValue = value.default;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return promiseValue;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.createLanguage = createLanguage;
|
|
30
|
+
Object.defineProperty(exports, 'createTranslationFile', {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return __vocab_core_translation_file.createTranslationFile;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","names":["promiseValue: Promise<any>","resolvedValue: any"],"sources":["../src/create-language.ts"],"sourcesContent":["import type { TranslationModule } from '@vocab/core';\nimport { getParsedICUMessages } from '@vocab/core/icu-handler';\n\nexport const createLanguage = (\n loadImport: () => Promise<any>,\n): TranslationModule<any> => {\n let promiseValue: Promise<any>;\n let resolvedValue: any;\n\n return {\n getValue: (locale) => {\n if (!resolvedValue) {\n return undefined;\n }\n return getParsedICUMessages(resolvedValue, locale);\n },\n load: () => {\n if (!promiseValue) {\n promiseValue = loadImport();\n promiseValue.then((value) => {\n resolvedValue = value.default;\n });\n }\n return promiseValue;\n },\n };\n};\n"],"mappings":";;;;;;;AAGA,MAAa,kBACX,eAC2B;CAC3B,IAAIA;CACJ,IAAIC;AAEJ,QAAO;EACL,WAAW,WAAW;AACpB,OAAI,CAAC,cACH;AAEF,6DAA4B,eAAe,OAAO;;EAEpD,YAAY;AACV,OAAI,CAAC,cAAc;AACjB,mBAAe,YAAY;AAC3B,iBAAa,MAAM,UAAU;AAC3B,qBAAgB,MAAM;MACtB;;AAEJ,UAAO;;EAEV"}
|
package/dist/runtime.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createTranslationFile } from "@vocab/core/translation-file";
|
|
2
|
+
import { getParsedICUMessages } from "@vocab/core/icu-handler";
|
|
3
|
+
|
|
4
|
+
//#region src/create-language.ts
|
|
5
|
+
const createLanguage = (loadImport) => {
|
|
6
|
+
let promiseValue;
|
|
7
|
+
let resolvedValue;
|
|
8
|
+
return {
|
|
9
|
+
getValue: (locale) => {
|
|
10
|
+
if (!resolvedValue) return;
|
|
11
|
+
return getParsedICUMessages(resolvedValue, locale);
|
|
12
|
+
},
|
|
13
|
+
load: () => {
|
|
14
|
+
if (!promiseValue) {
|
|
15
|
+
promiseValue = loadImport();
|
|
16
|
+
promiseValue.then((value) => {
|
|
17
|
+
resolvedValue = value.default;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return promiseValue;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { createLanguage, createTranslationFile };
|
|
27
|
+
//# sourceMappingURL=runtime.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":["promiseValue: Promise<any>","resolvedValue: any"],"sources":["../src/create-language.ts"],"sourcesContent":["import type { TranslationModule } from '@vocab/core';\nimport { getParsedICUMessages } from '@vocab/core/icu-handler';\n\nexport const createLanguage = (\n loadImport: () => Promise<any>,\n): TranslationModule<any> => {\n let promiseValue: Promise<any>;\n let resolvedValue: any;\n\n return {\n getValue: (locale) => {\n if (!resolvedValue) {\n return undefined;\n }\n return getParsedICUMessages(resolvedValue, locale);\n },\n load: () => {\n if (!promiseValue) {\n promiseValue = loadImport();\n promiseValue.then((value) => {\n resolvedValue = value.default;\n });\n }\n return promiseValue;\n },\n };\n};\n"],"mappings":";;;;AAGA,MAAa,kBACX,eAC2B;CAC3B,IAAIA;CACJ,IAAIC;AAEJ,QAAO;EACL,WAAW,WAAW;AACpB,OAAI,CAAC,cACH;AAEF,UAAO,qBAAqB,eAAe,OAAO;;EAEpD,YAAY;AACV,OAAI,CAAC,cAAc;AACjB,mBAAe,YAAY;AAC3B,iBAAa,MAAM,UAAU;AAC3B,qBAAgB,MAAM;MACtB;;AAEJ,UAAO;;EAEV"}
|