@vocab/rollup-plugin 0.1.0-rollup-plugin-20251128052954 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -0
- package/dist/index.cjs +1 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -3
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# `@vocab/rollup-plugin`
|
|
2
|
+
|
|
3
|
+
Copy `translations.json` files into your bundle, preserving directory structure.
|
|
4
|
+
|
|
5
|
+
## Why
|
|
6
|
+
|
|
7
|
+
`translations.json` files are never directly referenced by your code, so bundlers typically don't include them in a package bundle.
|
|
8
|
+
However, these files are critical for applications that use Vocab with a bundler plugin.
|
|
9
|
+
|
|
10
|
+
This plugin ensures that they are copied over while maintaining the same directory structure as your source code.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
pnpm install -D @vocab/rollup-plugin
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
> [!IMPORTANT]
|
|
21
|
+
> This plugin will only work if `preserveModules` (or `tsdown`'s `unbundle`) is set to `true`.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
// rollup.config.ts
|
|
25
|
+
import { vocabTranslations } from '@vocab/rollup-plugin';
|
|
26
|
+
|
|
27
|
+
export default {
|
|
28
|
+
input: './src/index.ts',
|
|
29
|
+
output: {
|
|
30
|
+
dir: 'dist',
|
|
31
|
+
format: 'es',
|
|
32
|
+
preserveModules: true
|
|
33
|
+
},
|
|
34
|
+
plugins: [vocabTranslations({ root: './src' })]
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
// tsdown.config.ts
|
|
40
|
+
import { defineConfig } from 'tsdown';
|
|
41
|
+
import { vocabTranslations } from '@vocab/rollup-plugin';
|
|
42
|
+
|
|
43
|
+
export default defineConfig({
|
|
44
|
+
entry: './src/index.ts',
|
|
45
|
+
unbundle: true,
|
|
46
|
+
format: 'esm',
|
|
47
|
+
plugins: [vocabTranslations({ root: './src' })]
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Options
|
|
52
|
+
|
|
53
|
+
### `root` (string, required)
|
|
54
|
+
|
|
55
|
+
The root of the library that all paths are resolved relative to.
|
|
56
|
+
Typically this should be the root of your source code, e.g. `"./src"`, _not_ the root of your library.
|
package/dist/index.cjs
CHANGED
|
@@ -25,13 +25,12 @@ let fs_promises = require("fs/promises");
|
|
|
25
25
|
fs_promises = __toESM(fs_promises);
|
|
26
26
|
let path = require("path");
|
|
27
27
|
path = __toESM(path);
|
|
28
|
-
let process = require("process");
|
|
29
28
|
let __vocab_core = require("@vocab/core");
|
|
30
29
|
|
|
31
30
|
//#region src/index.ts
|
|
32
31
|
const isVocabFile = (id) => __vocab_core.compiledVocabFileFilter.test(id);
|
|
33
32
|
const promiseMap = async (items, fn) => Promise.all(items.map(fn));
|
|
34
|
-
const vocabTranslations = async ({ root }
|
|
33
|
+
const vocabTranslations = async ({ root }) => {
|
|
35
34
|
const { default: memoize } = await import("memoize");
|
|
36
35
|
const handleVocabTranslations = memoize(async function(vocabDir) {
|
|
37
36
|
await promiseMap(await fs_promises.default.readdir(vocabDir), async (name) => {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["compiledVocabFileFilter","fs"],"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["compiledVocabFileFilter","fs"],"sources":["../src/index.ts"],"sourcesContent":["// Based off https://github.com/seek-oss/crackle/blob/ea226ae49853ca5531bb436334bc4e8d8ec1c49b/packages/core/src/plugins/rollup/vocab-translations.ts\nimport fs from 'fs/promises';\nimport path from 'path';\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 * Typically this should be the root of your source code, e.g. `\"./src\"`,\n * _not_ the root of your library.\n */\n root: string;\n};\n\nexport const vocabTranslations = async ({\n root,\n}: PluginOptions): 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 ) {\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\n this.emitFile({\n type: 'asset',\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\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 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,OAAO,EACtC,WACoC;CACpC,MAAM,EAAE,SAAS,YAAY,MAAM,OAAO;CAK1C,MAAM,0BAA0B,QAAQ,eAEtC,UACA;AACA,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;AAElD,SAAK,SAAS;KACZ,MAAM;KACN,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;AAEF,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,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"}
|
package/dist/index.d.cts
CHANGED
|
@@ -3,15 +3,15 @@ import { Plugin } from "rollup";
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
type PluginOptions = {
|
|
5
5
|
/**
|
|
6
|
-
* The root of the library that all paths are resolved relative to
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* The root of the library that all paths are resolved relative to.
|
|
7
|
+
* Typically this should be the root of your source code, e.g. `"./src"`,
|
|
8
|
+
* _not_ the root of your library.
|
|
9
9
|
*/
|
|
10
10
|
root: string;
|
|
11
11
|
};
|
|
12
12
|
declare const vocabTranslations: ({
|
|
13
13
|
root
|
|
14
|
-
}
|
|
14
|
+
}: PluginOptions) => Promise<Plugin>;
|
|
15
15
|
//#endregion
|
|
16
16
|
export { vocabTranslations };
|
|
17
17
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -3,15 +3,15 @@ import { Plugin } from "rollup";
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
type PluginOptions = {
|
|
5
5
|
/**
|
|
6
|
-
* The root of the library that all paths are resolved relative to
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* The root of the library that all paths are resolved relative to.
|
|
7
|
+
* Typically this should be the root of your source code, e.g. `"./src"`,
|
|
8
|
+
* _not_ the root of your library.
|
|
9
9
|
*/
|
|
10
10
|
root: string;
|
|
11
11
|
};
|
|
12
12
|
declare const vocabTranslations: ({
|
|
13
13
|
root
|
|
14
|
-
}
|
|
14
|
+
}: PluginOptions) => Promise<Plugin>;
|
|
15
15
|
//#endregion
|
|
16
16
|
export { vocabTranslations };
|
|
17
17
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import fs from "fs/promises";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { cwd } from "process";
|
|
4
3
|
import { compiledVocabFileFilter } from "@vocab/core";
|
|
5
4
|
|
|
6
5
|
//#region src/index.ts
|
|
7
6
|
const isVocabFile = (id) => compiledVocabFileFilter.test(id);
|
|
8
7
|
const promiseMap = async (items, fn) => Promise.all(items.map(fn));
|
|
9
|
-
const vocabTranslations = async ({ root }
|
|
8
|
+
const vocabTranslations = async ({ root }) => {
|
|
10
9
|
const { default: memoize } = await import("memoize");
|
|
11
10
|
const handleVocabTranslations = memoize(async function(vocabDir) {
|
|
12
11
|
await promiseMap(await fs.readdir(vocabDir), async (name) => {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["// Based off https://github.com/seek-oss/crackle/blob/ea226ae49853ca5531bb436334bc4e8d8ec1c49b/packages/core/src/plugins/rollup/vocab-translations.ts\nimport fs from 'fs/promises';\nimport path from 'path';\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 * Typically this should be the root of your source code, e.g. `\"./src\"`,\n * _not_ the root of your library.\n */\n root: string;\n};\n\nexport const vocabTranslations = async ({\n root,\n}: PluginOptions): 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 ) {\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\n this.emitFile({\n type: 'asset',\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\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 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,OAAO,EACtC,WACoC;CACpC,MAAM,EAAE,SAAS,YAAY,MAAM,OAAO;CAK1C,MAAM,0BAA0B,QAAQ,eAEtC,UACA;AACA,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;AAElD,SAAK,SAAS;KACZ,MAAM;KACN,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;AAEF,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,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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vocab/rollup-plugin",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/seek-oss/vocab.git",
|
|
@@ -23,10 +23,14 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"memoize": "^10.1.0",
|
|
26
|
-
"@vocab/core": "^1.7.0
|
|
26
|
+
"@vocab/core": "^1.7.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"rolldown": ">=1.0.0-beta.
|
|
29
|
+
"rolldown": ">=1.0.0-beta.47",
|
|
30
|
+
"rollup": "^4.0.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"rolldown": ">=1.0.0-beta.47",
|
|
30
34
|
"rollup": "^4.0.0"
|
|
31
35
|
},
|
|
32
36
|
"peerDependenciesMeta": {
|