rolldown-string 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2025-PRESENT Kevin Deng (https://github.com/sxzz)
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
@@ -0,0 +1,34 @@
1
+ # rolldown-string
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![Unit Test][unit-test-src]][unit-test-href]
6
+
7
+ undefined
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm i rolldown-string
13
+ ```
14
+
15
+ ## Sponsors
16
+
17
+ <p align="center">
18
+ <a href="https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg">
19
+ <img src='https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg'/>
20
+ </a>
21
+ </p>
22
+
23
+ ## License
24
+
25
+ [MIT](./LICENSE) License © 2025-PRESENT [Kevin Deng](https://github.com/sxzz)
26
+
27
+ <!-- Badges -->
28
+
29
+ [npm-version-src]: https://img.shields.io/npm/v/rolldown-string.svg
30
+ [npm-version-href]: https://npmjs.com/package/rolldown-string
31
+ [npm-downloads-src]: https://img.shields.io/npm/dm/rolldown-string
32
+ [npm-downloads-href]: https://www.npmcharts.com/compare/rolldown-string?interval=30
33
+ [unit-test-src]: https://github.com/sxzz/rolldown-string/actions/workflows/unit-test.yml/badge.svg
34
+ [unit-test-href]: https://github.com/sxzz/rolldown-string/actions/workflows/unit-test.yml
@@ -0,0 +1,20 @@
1
+ import MagicString from "magic-string";
2
+ import { BindingMagicString } from "rolldown";
3
+
4
+ //#region src/index.d.ts
5
+ type ObjectIntersection<A, B> = { [K in keyof A & keyof B]: A[K] };
6
+ type RolldownString = ObjectIntersection<MagicString, BindingMagicString>;
7
+ declare function rolldownString(code: string, id: string, meta?: any): RolldownString;
8
+ /**
9
+ * The result of code transformation.
10
+ */
11
+ interface CodeTransform {
12
+ code: any;
13
+ map?: any;
14
+ }
15
+ /**
16
+ * Generate an object of code and source map from MagicString.
17
+ */
18
+ declare function generateTransform(s: MagicString | BindingMagicString | RolldownString | undefined, id: string): CodeTransform | undefined;
19
+ //#endregion
20
+ export { CodeTransform, RolldownString, generateTransform, rolldownString };
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ import MagicString from "magic-string";
2
+
3
+ //#region src/index.ts
4
+ function rolldownString(code, id, meta) {
5
+ return meta?.magicString || new MagicString(code, { filename: id });
6
+ }
7
+ /**
8
+ * Generate an object of code and source map from MagicString.
9
+ */
10
+ function generateTransform(s, id) {
11
+ if (s?.constructor.name === "BindingMagicString") return { code: s };
12
+ if (s?.hasChanged()) return {
13
+ code: s.toString(),
14
+ get map() {
15
+ return s.generateMap({
16
+ source: id,
17
+ includeContent: true,
18
+ hires: "boundary"
19
+ });
20
+ }
21
+ };
22
+ }
23
+
24
+ //#endregion
25
+ export { generateTransform, rolldownString };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "rolldown-string",
3
+ "type": "module",
4
+ "version": "0.0.0",
5
+ "description": "undefined",
6
+ "author": "Kevin Deng <sxzz@sxzz.moe>",
7
+ "license": "MIT",
8
+ "funding": "https://github.com/sponsors/sxzz",
9
+ "homepage": "https://github.com/sxzz/rolldown-string#readme",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/sxzz/rolldown-string.git"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/sxzz/rolldown-string/issues"
16
+ },
17
+ "exports": {
18
+ ".": "./dist/index.js",
19
+ "./package.json": "./package.json"
20
+ },
21
+ "main": "./dist/index.js",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "engines": {
31
+ "node": ">=20.19.0"
32
+ },
33
+ "dependencies": {
34
+ "magic-string": "^0.30.21"
35
+ },
36
+ "devDependencies": {
37
+ "@sxzz/eslint-config": "^7.4.3",
38
+ "@sxzz/prettier-config": "^2.2.6",
39
+ "@types/node": "^24.10.4",
40
+ "@typescript/native-preview": "7.0.0-dev.20251214.1",
41
+ "bumpp": "^10.3.2",
42
+ "eslint": "^9.39.2",
43
+ "prettier": "^3.7.4",
44
+ "rolldown": "1.0.0-beta.54",
45
+ "tsdown": "^0.17.4",
46
+ "typescript": "^5.9.3",
47
+ "vitest": "^4.0.15"
48
+ },
49
+ "prettier": "@sxzz/prettier-config",
50
+ "scripts": {
51
+ "lint": "eslint --cache .",
52
+ "lint:fix": "pnpm run lint --fix",
53
+ "build": "tsdown",
54
+ "dev": "tsdown --watch",
55
+ "test": "vitest",
56
+ "typecheck": "tsgo --noEmit",
57
+ "format": "prettier --cache --write .",
58
+ "release": "bumpp"
59
+ }
60
+ }