@vocab/rollup-plugin 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,85 @@
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
+ let fs_promises = require("fs/promises");
25
+ fs_promises = __toESM(fs_promises);
26
+ let path = require("path");
27
+ path = __toESM(path);
28
+ let process = require("process");
29
+ let __vocab_core = require("@vocab/core");
30
+
31
+ //#region src/index.ts
32
+ const isVocabFile = (id) => __vocab_core.compiledVocabFileFilter.test(id);
33
+ const promiseMap = async (items, fn) => Promise.all(items.map(fn));
34
+ const vocabTranslations = async ({ root } = { root: (0, process.cwd)() }) => {
35
+ const { default: memoize } = await import("memoize");
36
+ const handleVocabTranslations = memoize(async function(vocabDir) {
37
+ await promiseMap(await fs_promises.default.readdir(vocabDir), async (name) => {
38
+ if (name.endsWith("translations.json")) {
39
+ const json = await fs_promises.default.readFile(path.default.join(vocabDir, name), "utf-8");
40
+ const originalFileName = path.default.join(vocabDir, name);
41
+ this.info(`root: ${root}`);
42
+ this.info(`name: ${name}`);
43
+ this.info(`vocabDir: ${vocabDir}`);
44
+ this.info(`og file name: ${originalFileName}`);
45
+ this.emitFile({
46
+ type: "asset",
47
+ fileName: path.default.relative(root, originalFileName),
48
+ source: json
49
+ });
50
+ }
51
+ });
52
+ return null;
53
+ });
54
+ return {
55
+ name: "vocab:translations-files",
56
+ resolveId: {
57
+ order: "pre",
58
+ async handler(id, importer, options) {
59
+ const resolved = await this.resolve(id, importer, {
60
+ skipSelf: true,
61
+ ...options
62
+ });
63
+ this.info(`Resolved ${id} to ${resolved?.id} from importer ${importer}`);
64
+ if (resolved && isVocabFile(resolved.id)) {
65
+ const vocabDir = path.default.dirname(resolved.id);
66
+ await handleVocabTranslations.call(this, vocabDir);
67
+ }
68
+ }
69
+ },
70
+ async renderChunk(_code, chunk, outputOptions) {
71
+ if (!outputOptions.preserveModules) this.warn("@vocab/rollup-plugin can only bundle translations.json files if `preserveModules` is enabled");
72
+ const outDir = outputOptions.dir;
73
+ this.info(`outdir: ${outDir}`);
74
+ if (!outDir) this.error("Output directory not specified. Please set the `dir` option in your Rollup configuration.");
75
+ for (const moduleId of chunk.moduleIds) if (isVocabFile(moduleId)) {
76
+ const vocabDir = path.default.dirname(moduleId);
77
+ if (outDir) await handleVocabTranslations.call(this, vocabDir);
78
+ }
79
+ }
80
+ };
81
+ };
82
+
83
+ //#endregion
84
+ exports.vocabTranslations = vocabTranslations;
85
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["compiledVocabFileFilter","fs"],"sources":["../src/index.ts"],"sourcesContent":["import fs from 'fs/promises';\nimport path from 'path';\nimport { cwd } from 'process';\n\nimport { compiledVocabFileFilter } from '@vocab/core';\nimport type { Plugin, PluginContext } from 'rollup';\n\nconst isVocabFile = (id: string) => compiledVocabFileFilter.test(id);\n\nconst promiseMap = async <T, K>(\n items: T[],\n fn: (item: T) => Promise<K>,\n): Promise<K[]> => Promise.all(items.map(fn));\n\ntype PluginOptions = {\n /**\n * The root of the library that all paths are resolved relative to\n *\n * @default process.cwd()\n */\n root: string;\n};\n\nexport const vocabTranslations = async (\n { root }: PluginOptions = { root: cwd() },\n): Promise<Plugin> => {\n const { default: memoize } = await import('memoize');\n\n // Because this is called for every generated Vocab translation file, we don't want to emit assets\n // multiple times. The function is memoized so that it only emits assets once per `vocab` directory,\n // because the translation file can be imported from multiple places.\n const handleVocabTranslations = memoize(async function (\n this: PluginContext,\n vocabDir: string,\n // distDir: string,\n ) {\n // const distDir = toDistPath(vocabDir);\n await promiseMap(await fs.readdir(vocabDir), async (name) => {\n if (name.endsWith('translations.json')) {\n const json = await fs.readFile(path.join(vocabDir, name), 'utf-8');\n const originalFileName = path.join(vocabDir, name);\n this.info(`root: ${root}`);\n this.info(`name: ${name}`);\n this.info(`vocabDir: ${vocabDir}`);\n this.info(`og file name: ${originalFileName}`);\n\n this.emitFile({\n type: 'asset',\n // originalFileName,\n fileName: path.relative(root, originalFileName),\n source: json,\n });\n }\n });\n\n // return value is important for memoize\n return null;\n });\n\n return {\n name: 'vocab:translations-files',\n\n resolveId: {\n order: 'pre',\n async handler(id, importer, options) {\n const resolved = await this.resolve(id, importer, {\n skipSelf: true,\n ...options,\n });\n this.info(\n `Resolved ${id} to ${resolved?.id} from importer ${importer}`,\n );\n\n if (resolved && isVocabFile(resolved.id)) {\n const vocabDir = path.dirname(resolved.id);\n await handleVocabTranslations.call(this, vocabDir);\n }\n },\n },\n async renderChunk(_code, chunk, outputOptions) {\n if (!outputOptions.preserveModules) {\n this.warn(\n '@vocab/rollup-plugin can only bundle translations.json files if `preserveModules` is enabled',\n );\n }\n const outDir = outputOptions.dir;\n this.info(`outdir: ${outDir}`);\n if (!outDir) {\n // Should never happen as rollup validates that `dir` is provided if `preserveModules` is\n // true\n this.error(\n 'Output directory not specified. Please set the `dir` option in your Rollup configuration.',\n );\n }\n\n for (const moduleId of chunk.moduleIds) {\n if (isVocabFile(moduleId)) {\n const vocabDir = path.dirname(moduleId);\n if (outDir) {\n await handleVocabTranslations.call(this, vocabDir);\n }\n }\n }\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAM,eAAe,OAAeA,qCAAwB,KAAK,GAAG;AAEpE,MAAM,aAAa,OACjB,OACA,OACiB,QAAQ,IAAI,MAAM,IAAI,GAAG,CAAC;AAW7C,MAAa,oBAAoB,OAC/B,EAAE,SAAwB,EAAE,wBAAW,EAAE,KACrB;CACpB,MAAM,EAAE,SAAS,YAAY,MAAM,OAAO;CAK1C,MAAM,0BAA0B,QAAQ,eAEtC,UAEA;AAEA,QAAM,WAAW,MAAMC,oBAAG,QAAQ,SAAS,EAAE,OAAO,SAAS;AAC3D,OAAI,KAAK,SAAS,oBAAoB,EAAE;IACtC,MAAM,OAAO,MAAMA,oBAAG,SAAS,aAAK,KAAK,UAAU,KAAK,EAAE,QAAQ;IAClE,MAAM,mBAAmB,aAAK,KAAK,UAAU,KAAK;AAClD,SAAK,KAAK,SAAS,OAAO;AAC1B,SAAK,KAAK,SAAS,OAAO;AAC1B,SAAK,KAAK,aAAa,WAAW;AAClC,SAAK,KAAK,iBAAiB,mBAAmB;AAE9C,SAAK,SAAS;KACZ,MAAM;KAEN,UAAU,aAAK,SAAS,MAAM,iBAAiB;KAC/C,QAAQ;KACT,CAAC;;IAEJ;AAGF,SAAO;GACP;AAEF,QAAO;EACL,MAAM;EAEN,WAAW;GACT,OAAO;GACP,MAAM,QAAQ,IAAI,UAAU,SAAS;IACnC,MAAM,WAAW,MAAM,KAAK,QAAQ,IAAI,UAAU;KAChD,UAAU;KACV,GAAG;KACJ,CAAC;AACF,SAAK,KACH,YAAY,GAAG,MAAM,UAAU,GAAG,iBAAiB,WACpD;AAED,QAAI,YAAY,YAAY,SAAS,GAAG,EAAE;KACxC,MAAM,WAAW,aAAK,QAAQ,SAAS,GAAG;AAC1C,WAAM,wBAAwB,KAAK,MAAM,SAAS;;;GAGvD;EACD,MAAM,YAAY,OAAO,OAAO,eAAe;AAC7C,OAAI,CAAC,cAAc,gBACjB,MAAK,KACH,+FACD;GAEH,MAAM,SAAS,cAAc;AAC7B,QAAK,KAAK,WAAW,SAAS;AAC9B,OAAI,CAAC,OAGH,MAAK,MACH,4FACD;AAGH,QAAK,MAAM,YAAY,MAAM,UAC3B,KAAI,YAAY,SAAS,EAAE;IACzB,MAAM,WAAW,aAAK,QAAQ,SAAS;AACvC,QAAI,OACF,OAAM,wBAAwB,KAAK,MAAM,SAAS;;;EAK3D"}
@@ -0,0 +1,17 @@
1
+ import { Plugin } from "rollup";
2
+
3
+ //#region src/index.d.ts
4
+ type PluginOptions = {
5
+ /**
6
+ * The root of the library that all paths are resolved relative to
7
+ *
8
+ * @default process.cwd()
9
+ */
10
+ root: string;
11
+ };
12
+ declare const vocabTranslations: ({
13
+ root
14
+ }?: PluginOptions) => Promise<Plugin>;
15
+ //#endregion
16
+ export { vocabTranslations };
17
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1,17 @@
1
+ import { Plugin } from "rollup";
2
+
3
+ //#region src/index.d.ts
4
+ type PluginOptions = {
5
+ /**
6
+ * The root of the library that all paths are resolved relative to
7
+ *
8
+ * @default process.cwd()
9
+ */
10
+ root: string;
11
+ };
12
+ declare const vocabTranslations: ({
13
+ root
14
+ }?: PluginOptions) => Promise<Plugin>;
15
+ //#endregion
16
+ export { vocabTranslations };
17
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,60 @@
1
+ import fs from "fs/promises";
2
+ import path from "path";
3
+ import { cwd } from "process";
4
+ import { compiledVocabFileFilter } from "@vocab/core";
5
+
6
+ //#region src/index.ts
7
+ const isVocabFile = (id) => compiledVocabFileFilter.test(id);
8
+ const promiseMap = async (items, fn) => Promise.all(items.map(fn));
9
+ const vocabTranslations = async ({ root } = { root: cwd() }) => {
10
+ const { default: memoize } = await import("memoize");
11
+ const handleVocabTranslations = memoize(async function(vocabDir) {
12
+ await promiseMap(await fs.readdir(vocabDir), async (name) => {
13
+ if (name.endsWith("translations.json")) {
14
+ const json = await fs.readFile(path.join(vocabDir, name), "utf-8");
15
+ const originalFileName = path.join(vocabDir, name);
16
+ this.info(`root: ${root}`);
17
+ this.info(`name: ${name}`);
18
+ this.info(`vocabDir: ${vocabDir}`);
19
+ this.info(`og file name: ${originalFileName}`);
20
+ this.emitFile({
21
+ type: "asset",
22
+ fileName: path.relative(root, originalFileName),
23
+ source: json
24
+ });
25
+ }
26
+ });
27
+ return null;
28
+ });
29
+ return {
30
+ name: "vocab:translations-files",
31
+ resolveId: {
32
+ order: "pre",
33
+ async handler(id, importer, options) {
34
+ const resolved = await this.resolve(id, importer, {
35
+ skipSelf: true,
36
+ ...options
37
+ });
38
+ this.info(`Resolved ${id} to ${resolved?.id} from importer ${importer}`);
39
+ if (resolved && isVocabFile(resolved.id)) {
40
+ const vocabDir = path.dirname(resolved.id);
41
+ await handleVocabTranslations.call(this, vocabDir);
42
+ }
43
+ }
44
+ },
45
+ async renderChunk(_code, chunk, outputOptions) {
46
+ if (!outputOptions.preserveModules) this.warn("@vocab/rollup-plugin can only bundle translations.json files if `preserveModules` is enabled");
47
+ const outDir = outputOptions.dir;
48
+ this.info(`outdir: ${outDir}`);
49
+ if (!outDir) this.error("Output directory not specified. Please set the `dir` option in your Rollup configuration.");
50
+ for (const moduleId of chunk.moduleIds) if (isVocabFile(moduleId)) {
51
+ const vocabDir = path.dirname(moduleId);
52
+ if (outDir) await handleVocabTranslations.call(this, vocabDir);
53
+ }
54
+ }
55
+ };
56
+ };
57
+
58
+ //#endregion
59
+ export { vocabTranslations };
60
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import fs from 'fs/promises';\nimport path from 'path';\nimport { cwd } from 'process';\n\nimport { compiledVocabFileFilter } from '@vocab/core';\nimport type { Plugin, PluginContext } from 'rollup';\n\nconst isVocabFile = (id: string) => compiledVocabFileFilter.test(id);\n\nconst promiseMap = async <T, K>(\n items: T[],\n fn: (item: T) => Promise<K>,\n): Promise<K[]> => Promise.all(items.map(fn));\n\ntype PluginOptions = {\n /**\n * The root of the library that all paths are resolved relative to\n *\n * @default process.cwd()\n */\n root: string;\n};\n\nexport const vocabTranslations = async (\n { root }: PluginOptions = { root: cwd() },\n): Promise<Plugin> => {\n const { default: memoize } = await import('memoize');\n\n // Because this is called for every generated Vocab translation file, we don't want to emit assets\n // multiple times. The function is memoized so that it only emits assets once per `vocab` directory,\n // because the translation file can be imported from multiple places.\n const handleVocabTranslations = memoize(async function (\n this: PluginContext,\n vocabDir: string,\n // distDir: string,\n ) {\n // const distDir = toDistPath(vocabDir);\n await promiseMap(await fs.readdir(vocabDir), async (name) => {\n if (name.endsWith('translations.json')) {\n const json = await fs.readFile(path.join(vocabDir, name), 'utf-8');\n const originalFileName = path.join(vocabDir, name);\n this.info(`root: ${root}`);\n this.info(`name: ${name}`);\n this.info(`vocabDir: ${vocabDir}`);\n this.info(`og file name: ${originalFileName}`);\n\n this.emitFile({\n type: 'asset',\n // originalFileName,\n fileName: path.relative(root, originalFileName),\n source: json,\n });\n }\n });\n\n // return value is important for memoize\n return null;\n });\n\n return {\n name: 'vocab:translations-files',\n\n resolveId: {\n order: 'pre',\n async handler(id, importer, options) {\n const resolved = await this.resolve(id, importer, {\n skipSelf: true,\n ...options,\n });\n this.info(\n `Resolved ${id} to ${resolved?.id} from importer ${importer}`,\n );\n\n if (resolved && isVocabFile(resolved.id)) {\n const vocabDir = path.dirname(resolved.id);\n await handleVocabTranslations.call(this, vocabDir);\n }\n },\n },\n async renderChunk(_code, chunk, outputOptions) {\n if (!outputOptions.preserveModules) {\n this.warn(\n '@vocab/rollup-plugin can only bundle translations.json files if `preserveModules` is enabled',\n );\n }\n const outDir = outputOptions.dir;\n this.info(`outdir: ${outDir}`);\n if (!outDir) {\n // Should never happen as rollup validates that `dir` is provided if `preserveModules` is\n // true\n this.error(\n 'Output directory not specified. Please set the `dir` option in your Rollup configuration.',\n );\n }\n\n for (const moduleId of chunk.moduleIds) {\n if (isVocabFile(moduleId)) {\n const vocabDir = path.dirname(moduleId);\n if (outDir) {\n await handleVocabTranslations.call(this, vocabDir);\n }\n }\n }\n },\n };\n};\n"],"mappings":";;;;;;AAOA,MAAM,eAAe,OAAe,wBAAwB,KAAK,GAAG;AAEpE,MAAM,aAAa,OACjB,OACA,OACiB,QAAQ,IAAI,MAAM,IAAI,GAAG,CAAC;AAW7C,MAAa,oBAAoB,OAC/B,EAAE,SAAwB,EAAE,MAAM,KAAK,EAAE,KACrB;CACpB,MAAM,EAAE,SAAS,YAAY,MAAM,OAAO;CAK1C,MAAM,0BAA0B,QAAQ,eAEtC,UAEA;AAEA,QAAM,WAAW,MAAM,GAAG,QAAQ,SAAS,EAAE,OAAO,SAAS;AAC3D,OAAI,KAAK,SAAS,oBAAoB,EAAE;IACtC,MAAM,OAAO,MAAM,GAAG,SAAS,KAAK,KAAK,UAAU,KAAK,EAAE,QAAQ;IAClE,MAAM,mBAAmB,KAAK,KAAK,UAAU,KAAK;AAClD,SAAK,KAAK,SAAS,OAAO;AAC1B,SAAK,KAAK,SAAS,OAAO;AAC1B,SAAK,KAAK,aAAa,WAAW;AAClC,SAAK,KAAK,iBAAiB,mBAAmB;AAE9C,SAAK,SAAS;KACZ,MAAM;KAEN,UAAU,KAAK,SAAS,MAAM,iBAAiB;KAC/C,QAAQ;KACT,CAAC;;IAEJ;AAGF,SAAO;GACP;AAEF,QAAO;EACL,MAAM;EAEN,WAAW;GACT,OAAO;GACP,MAAM,QAAQ,IAAI,UAAU,SAAS;IACnC,MAAM,WAAW,MAAM,KAAK,QAAQ,IAAI,UAAU;KAChD,UAAU;KACV,GAAG;KACJ,CAAC;AACF,SAAK,KACH,YAAY,GAAG,MAAM,UAAU,GAAG,iBAAiB,WACpD;AAED,QAAI,YAAY,YAAY,SAAS,GAAG,EAAE;KACxC,MAAM,WAAW,KAAK,QAAQ,SAAS,GAAG;AAC1C,WAAM,wBAAwB,KAAK,MAAM,SAAS;;;GAGvD;EACD,MAAM,YAAY,OAAO,OAAO,eAAe;AAC7C,OAAI,CAAC,cAAc,gBACjB,MAAK,KACH,+FACD;GAEH,MAAM,SAAS,cAAc;AAC7B,QAAK,KAAK,WAAW,SAAS;AAC9B,OAAI,CAAC,OAGH,MAAK,MACH,4FACD;AAGH,QAAK,MAAM,YAAY,MAAM,UAC3B,KAAI,YAAY,SAAS,EAAE;IACzB,MAAM,WAAW,KAAK,QAAQ,SAAS;AACvC,QAAI,OACF,OAAM,wBAAwB,KAAK,MAAM,SAAS;;;EAK3D"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@vocab/rollup-plugin",
3
+ "version": "0.0.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/seek-oss/vocab.git",
7
+ "directory": "packages/rollup-plugin"
8
+ },
9
+ "main": "./dist/index.cjs",
10
+ "module": "./dist/index.mjs",
11
+ "types": "./dist/index.d.cts",
12
+ "exports": {
13
+ ".": {
14
+ "@vocab-private/monorepo": "./src/index.ts",
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.cjs"
17
+ },
18
+ "./package.json": "./package.json"
19
+ },
20
+ "author": "SEEK",
21
+ "license": "MIT",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "dependencies": {
26
+ "@vocab/core": "workspace:^",
27
+ "memoize": "^10.1.0"
28
+ },
29
+ "devDependencies": {
30
+ "tsdown": "^0.16.0"
31
+ },
32
+ "peerDependencies": {
33
+ "rolldown": "*",
34
+ "rollup": "^4.0.0"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "rollup": {
38
+ "optional": true
39
+ },
40
+ "rolldown": {
41
+ "optional": true
42
+ }
43
+ },
44
+ "publishConfig": {
45
+ "exports": {
46
+ ".": {
47
+ "import": "./dist/index.mjs",
48
+ "require": "./dist/index.cjs"
49
+ },
50
+ "./package.json": "./package.json"
51
+ }
52
+ }
53
+ }