@typeup/rollup-plugin 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/index.node.js +2 -0
- package/dist/index.node.js.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.node.d.ts +3 -0
- package/dist/types/index.node.d.ts.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TypeUp
|
|
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
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { parser } from "@typeup/parser";
|
|
2
|
+
import { mendly } from "mendly/node";
|
|
3
|
+
export function typeup(options = {}) {
|
|
4
|
+
const extensions = options.extensions ?? ["tup", "typeup"];
|
|
5
|
+
return {
|
|
6
|
+
name: "@typeup/rollup-plugin",
|
|
7
|
+
async transform(source, id) {
|
|
8
|
+
const imports = {};
|
|
9
|
+
function getName(uri, prefix) {
|
|
10
|
+
const result = (prefix ? prefix + "_" : "") + uri.path[uri.path.length - 1];
|
|
11
|
+
const current = imports[result];
|
|
12
|
+
return current != undefined && current.toString() != uri.toString() ? getName(uri, result) : result;
|
|
13
|
+
}
|
|
14
|
+
const url = mendly.Uri.parse(id);
|
|
15
|
+
let result = null;
|
|
16
|
+
if (url && extensions.some(extension => url.path[url.path.length - 1]?.endsWith("." + extension))) {
|
|
17
|
+
let serialized;
|
|
18
|
+
try {
|
|
19
|
+
serialized = JSON.stringify(await parser.parse(source, undefined, (locator) => getName(locator)));
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
throw new TypeError(`Parser result for "${id}" is not JSON-serializable: ${error instanceof Error ? error.message : String(error)}`);
|
|
23
|
+
}
|
|
24
|
+
result = {
|
|
25
|
+
code: `${Object.entries(imports)
|
|
26
|
+
.map(([key, value]) => `import ${key} from "${value}";`)
|
|
27
|
+
.join("\n")}\nexport default ${serialized};`
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;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AAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;gBAC9G,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAChB,MAAM,IAAI,SAAS,CAClB,sBAAsB,EAAE,+BAA+B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC/G,CAAA;gBACF,CAAC;gBACD,MAAM,GAAG;oBACR,IAAI,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;yBAC9B,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,UAAU,GAAG,UAAU,KAAK,IAAI,CAAC;yBACvD,IAAI,CAAC,IAAI,CAAC,oBAAoB,UAAU,GAAG;iBAC7C,CAAA;YACF,CAAC;YACD,OAAO,MAAM,CAAA;QACd,CAAC;KAC4B,CAAA;AAC/B,CAAC","sourcesContent":["import { parser } from \"@typeup/parser\"\nimport { mendly } from \"mendly/node\"\n\nexport interface TypeupRollupPluginOptions {\n\textensions?: string[]\n}\nexport interface TypeupTransformResult {\n\tcode: string\n}\nexport interface TypeupRollupPlugin {\n\tname: string\n\ttransform(source: string, id: string): Promise<TypeupTransformResult | null>\n}\nexport function typeup(options: TypeupRollupPluginOptions = {}): TypeupRollupPlugin {\n\tconst extensions = options.extensions ?? [\"tup\", \"typeup\"]\n\treturn {\n\t\tname: \"@typeup/rollup-plugin\",\n\t\tasync transform(source, id) {\n\t\t\tconst imports: Record<string, mendly.Uri> = {}\n\t\t\tfunction getName(uri: mendly.Uri, prefix?: string): string {\n\t\t\t\tconst result = (prefix ? prefix + \"_\" : \"\") + uri.path[uri.path.length - 1]\n\t\t\t\tconst current = imports[result]\n\t\t\t\treturn current != undefined && current.toString() != uri.toString() ? getName(uri, result) : result\n\t\t\t}\n\t\t\tconst url = mendly.Uri.parse(id)\n\t\t\tlet result: TypeupTransformResult | null = null\n\t\t\tif (url && extensions.some(extension => url.path[url.path.length - 1]?.endsWith(\".\" + extension))) {\n\t\t\t\tlet serialized: string\n\t\t\t\ttry {\n\t\t\t\t\tserialized = JSON.stringify(await parser.parse(source, undefined, (locator: mendly.Uri) => getName(locator)))\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthrow new TypeError(\n\t\t\t\t\t\t`Parser result for \"${id}\" is not JSON-serializable: ${error instanceof Error ? error.message : String(error)}`\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tresult = {\n\t\t\t\t\tcode: `${Object.entries(imports)\n\t\t\t\t\t\t.map(([key, value]) => `import ${key} from \"${value}\";`)\n\t\t\t\t\t\t.join(\"\\n\")}\\nexport default ${serialized};`\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result\n\t\t}\n\t} satisfies TypeupRollupPlugin\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.node.js","sourceRoot":"","sources":["../index.node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { default } from './index.js';\nexport type {\n\tParser,\n\tRollupLikePlugin,\n\tRollupPluginOptions,\n\tTransformResult\n} from './index.js';"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface TypeupRollupPluginOptions {
|
|
2
|
+
extensions?: string[];
|
|
3
|
+
}
|
|
4
|
+
export interface TypeupTransformResult {
|
|
5
|
+
code: string;
|
|
6
|
+
}
|
|
7
|
+
export interface TypeupRollupPlugin {
|
|
8
|
+
name: string;
|
|
9
|
+
transform(source: string, id: string): Promise<TypeupTransformResult | null>;
|
|
10
|
+
}
|
|
11
|
+
export declare function typeup(options?: TypeupRollupPluginOptions): TypeupRollupPlugin;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,yBAAyB;IACzC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB;AACD,MAAM,WAAW,qBAAqB;IACrC,IAAI,EAAE,MAAM,CAAA;CACZ;AACD,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAAA;CAC5E;AACD,wBAAgB,MAAM,CAAC,OAAO,GAAE,yBAA8B,GAAG,kBAAkB,CA+BlF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.node.d.ts","sourceRoot":"","sources":["../../index.node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,YAAY,EACX,MAAM,EACN,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,MAAM,YAAY,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typeup/rollup-plugin",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "Rollup plugin to import TypeUp files and parse them into a Binotype site.",
|
|
5
|
+
"author": "binotype",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"private": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/binotype/rollup-plugin.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/binotype/rollup-plugin/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/binotype/rollup-plugin",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"types": "./dist/types/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/types/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"git": {
|
|
31
|
+
"tagName": "release-${version}"
|
|
32
|
+
},
|
|
33
|
+
"github": {
|
|
34
|
+
"release": true
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.build.json",
|
|
38
|
+
"clean": "rimraf dist node_modules coverage",
|
|
39
|
+
"lint": "biome format .",
|
|
40
|
+
"format": "biome format --write .",
|
|
41
|
+
"test": "vitest --run",
|
|
42
|
+
"coverage": "vitest --coverage",
|
|
43
|
+
"verify": "npm run build && npm audit --omit=dev"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@biomejs/biome": "^2.4.16",
|
|
47
|
+
"@types/node": "^25.9.1",
|
|
48
|
+
"@vitest/coverage-v8": "^4.1.7",
|
|
49
|
+
"rimraf": "^6.1.3",
|
|
50
|
+
"typescript": "^6.0.3",
|
|
51
|
+
"vite": "^8.0.14",
|
|
52
|
+
"vitest": "^4.1.7"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@typeup/dom": "1.0.11-beta.14",
|
|
56
|
+
"@typeup/parser": "1.2.5-beta.18",
|
|
57
|
+
"mendly": "^3.1.1-beta.18"
|
|
58
|
+
}
|
|
59
|
+
}
|