unplugin-raw 0.6.3 → 0.6.4

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/api.d.mts ADDED
@@ -0,0 +1,9 @@
1
+ import { i as resolveOptions, n as OptionsResolved, r as TransformOptions, t as Options } from "./options-DSAzFv_P.mjs";
2
+ import * as esbuild0 from "esbuild";
3
+ import { TransformOptions as TransformOptions$1 } from "esbuild";
4
+ import { Buffer } from "node:buffer";
5
+
6
+ //#region src/core/transform.d.ts
7
+ declare function transformRaw(file: string, type: "text" | "bytes", transform?: typeof esbuild0.transform, transformFilter?: (id: string | unknown) => boolean, options?: TransformOptions$1): Promise<string | Buffer>;
8
+ //#endregion
9
+ export { type Options, type OptionsResolved, type TransformOptions, resolveOptions, transformRaw };
package/dist/api.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { n as resolveOptions, t as transformRaw } from "./transform-DF3vB7QY.mjs";
2
+
3
+ export { resolveOptions, transformRaw };
@@ -1,5 +1,5 @@
1
- import "./options-DupdgTT1.js";
2
- import { unplugin } from "./index-BMXQlGcW.js";
1
+ import "./options-DSAzFv_P.mjs";
2
+ import unplugin from "./index.mjs";
3
3
 
4
4
  //#region src/esbuild.d.ts
5
5
 
@@ -1,8 +1,13 @@
1
- import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-CKGRYIxm.js";
1
+ import "./transform-DF3vB7QY.mjs";
2
+ import src_default from "./index.mjs";
3
3
 
4
4
  //#region src/esbuild.ts
5
5
  /**
6
+ * This entry file is for esbuild plugin. Requires esbuild >= 0.15
7
+ *
8
+ * @module
9
+ */
10
+ /**
6
11
  * Esbuild plugin
7
12
  *
8
13
  * @example
@@ -1,7 +1,7 @@
1
- import { Options } from "./options-DupdgTT1.js";
1
+ import { t as Options } from "./options-DSAzFv_P.mjs";
2
2
  import { UnpluginInstance } from "unplugin";
3
3
 
4
4
  //#region src/index.d.ts
5
5
  declare const unplugin: UnpluginInstance<Options | undefined, false>;
6
6
  //#endregion
7
- export { unplugin };
7
+ export { unplugin as default };
@@ -1,5 +1,4 @@
1
- import { resolveOptions, transformRaw } from "./options-BTT0I76V.js";
2
- import { Buffer } from "node:buffer";
1
+ import { n as resolveOptions, t as transformRaw } from "./transform-DF3vB7QY.mjs";
3
2
  import { createUnplugin } from "unplugin";
4
3
  import { createFilter } from "unplugin-utils";
5
4
 
@@ -33,20 +32,19 @@ const unplugin = createUnplugin((rawOptions = {}, meta) => {
33
32
  load: {
34
33
  filter: { id: { include: [rawRE, bytesRE] } },
35
34
  async handler(id) {
36
- const isBytes = bytesRE.test(id);
37
35
  const file = cleanUrl(id);
38
36
  const context = this.getNativeBuildContext?.();
39
37
  const transform = context?.framework === "esbuild" ? context.build.esbuild.transform : void 0;
40
- let contents = await transformRaw(file, isBytes, transform, transformFilter, options.transform ? options.transform.options : void 0);
41
- if (Buffer.isBuffer(contents)) contents = `export default new Uint8Array([${contents.join(", ")}])`;
38
+ let contents = await transformRaw(file, bytesRE.test(id) ? "bytes" : "text", transform, transformFilter, options.transform ? options.transform.options : void 0);
39
+ if (typeof contents !== "string") contents = `export default new Uint8Array([${contents.join(", ")}])`;
42
40
  return contents;
43
41
  }
44
42
  },
45
43
  esbuild: { setup(build) {
46
44
  build.onLoad({ filter: /.*/ }, async (args) => {
47
- const isBytes = args.with.type === "bytes";
48
- if (args.with.type === "text" || isBytes) {
49
- const contents = await transformRaw(args.path, isBytes, build.esbuild.transform, transformFilter, options.transform ? options.transform.options : void 0);
45
+ const type = args.with.type;
46
+ if (type === "text" || type === "bytes") {
47
+ const contents = await transformRaw(args.path, type, build.esbuild.transform, transformFilter, options.transform ? options.transform.options : void 0);
50
48
  return {
51
49
  contents,
52
50
  loader: typeof contents === "string" ? "js" : "binary"
@@ -59,4 +57,4 @@ const unplugin = createUnplugin((rawOptions = {}, meta) => {
59
57
  var src_default = unplugin;
60
58
 
61
59
  //#endregion
62
- export { src_default };
60
+ export { src_default as default };
@@ -24,4 +24,4 @@ type OptionsResolved = Pick<Options, "enforce"> & {
24
24
  };
25
25
  declare function resolveOptions(options: Options): OptionsResolved;
26
26
  //#endregion
27
- export { Options, OptionsResolved, TransformOptions$1 as TransformOptions, resolveOptions };
27
+ export { resolveOptions as i, OptionsResolved as n, TransformOptions$1 as r, Options as t };
@@ -1,5 +1,5 @@
1
- import "./options-DupdgTT1.js";
2
- import { unplugin } from "./index-BMXQlGcW.js";
1
+ import "./options-DSAzFv_P.mjs";
2
+ import unplugin from "./index.mjs";
3
3
 
4
4
  //#region src/rolldown.d.ts
5
5
 
@@ -1,8 +1,13 @@
1
- import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-CKGRYIxm.js";
1
+ import "./transform-DF3vB7QY.mjs";
2
+ import src_default from "./index.mjs";
3
3
 
4
4
  //#region src/rolldown.ts
5
5
  /**
6
+ * This entry file is for Rolldown plugin.
7
+ *
8
+ * @module
9
+ */
10
+ /**
6
11
  * Rolldown plugin
7
12
  *
8
13
  * @example
@@ -1,5 +1,5 @@
1
- import "./options-DupdgTT1.js";
2
- import { unplugin } from "./index-BMXQlGcW.js";
1
+ import "./options-DSAzFv_P.mjs";
2
+ import unplugin from "./index.mjs";
3
3
 
4
4
  //#region src/rollup.d.ts
5
5
 
@@ -1,8 +1,13 @@
1
- import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-CKGRYIxm.js";
1
+ import "./transform-DF3vB7QY.mjs";
2
+ import src_default from "./index.mjs";
3
3
 
4
4
  //#region src/rollup.ts
5
5
  /**
6
+ * This entry file is for Rollup plugin.
7
+ *
8
+ * @module
9
+ */
10
+ /**
6
11
  * Rollup plugin
7
12
  *
8
13
  * @example
@@ -1,5 +1,5 @@
1
- import "./options-DupdgTT1.js";
2
- import { unplugin } from "./index-BMXQlGcW.js";
1
+ import "./options-DSAzFv_P.mjs";
2
+ import unplugin from "./index.mjs";
3
3
 
4
4
  //#region src/rspack.d.ts
5
5
 
@@ -1,8 +1,13 @@
1
- import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-CKGRYIxm.js";
1
+ import "./transform-DF3vB7QY.mjs";
2
+ import src_default from "./index.mjs";
3
3
 
4
4
  //#region src/rspack.ts
5
5
  /**
6
+ * This entry file is for rspack plugin.
7
+ *
8
+ * @module
9
+ */
10
+ /**
6
11
  * Rspack plugin
7
12
  *
8
13
  * @example
@@ -1,17 +1,34 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
 
4
+ //#region src/core/options.ts
5
+ function resolveOptions(options) {
6
+ let { transform = false } = options;
7
+ if (transform === true) transform = {};
8
+ return {
9
+ ...options,
10
+ enforce: "enforce" in options ? options.enforce : "pre",
11
+ transform: transform ? {
12
+ ...transform,
13
+ include: transform.include || [/\.[cm]?[jt]sx?$/],
14
+ exclude: transform.exclude || [/node_modules/],
15
+ options: transform.options || {}
16
+ } : false
17
+ };
18
+ }
19
+
20
+ //#endregion
4
21
  //#region src/core/transform.ts
5
- async function transformRaw(file, isBytes, transform, transformFilter, options) {
6
- let contents = await readFile(file, isBytes ? void 0 : "utf8");
7
- if (!isBytes && transformFilter?.(file)) {
22
+ async function transformRaw(file, type, transform, transformFilter, options) {
23
+ let contents = await readFile(file, type === "text" ? "utf8" : void 0);
24
+ if (type === "text" && transformFilter?.(file)) {
8
25
  transform ||= (await import("esbuild")).transform;
9
26
  contents = (await transform(contents, {
10
27
  loader: guessLoader(file),
11
28
  ...options
12
29
  })).code;
13
30
  }
14
- return isBytes ? contents : `export default ${JSON.stringify(contents)}`;
31
+ return type === "bytes" ? contents : `export default ${JSON.stringify(contents)}`;
15
32
  }
16
33
  const ExtToLoader = {
17
34
  ".js": "js",
@@ -35,21 +52,4 @@ function guessLoader(id) {
35
52
  }
36
53
 
37
54
  //#endregion
38
- //#region src/core/options.ts
39
- function resolveOptions(options) {
40
- let { transform = false } = options;
41
- if (transform === true) transform = {};
42
- return {
43
- ...options,
44
- enforce: "enforce" in options ? options.enforce : "pre",
45
- transform: transform ? {
46
- ...transform,
47
- include: transform.include || [/\.[cm]?[jt]sx?$/],
48
- exclude: transform.exclude || [/node_modules/],
49
- options: transform.options || {}
50
- } : false
51
- };
52
- }
53
-
54
- //#endregion
55
- export { resolveOptions, transformRaw };
55
+ export { resolveOptions as n, transformRaw as t };
@@ -1,5 +1,5 @@
1
- import "./options-DupdgTT1.js";
2
- import { unplugin } from "./index-BMXQlGcW.js";
1
+ import "./options-DSAzFv_P.mjs";
2
+ import unplugin from "./index.mjs";
3
3
 
4
4
  //#region src/vite.d.ts
5
5
 
@@ -1,8 +1,13 @@
1
- import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-CKGRYIxm.js";
1
+ import "./transform-DF3vB7QY.mjs";
2
+ import src_default from "./index.mjs";
3
3
 
4
4
  //#region src/vite.ts
5
5
  /**
6
+ * This entry file is for Vite plugin.
7
+ *
8
+ * @module
9
+ */
10
+ /**
6
11
  * Vite plugin
7
12
  *
8
13
  * @example
@@ -1,5 +1,5 @@
1
- import "./options-DupdgTT1.js";
2
- import { unplugin } from "./index-BMXQlGcW.js";
1
+ import "./options-DSAzFv_P.mjs";
2
+ import unplugin from "./index.mjs";
3
3
 
4
4
  //#region src/webpack.d.ts
5
5
 
@@ -1,8 +1,13 @@
1
- import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-CKGRYIxm.js";
1
+ import "./transform-DF3vB7QY.mjs";
2
+ import src_default from "./index.mjs";
3
3
 
4
4
  //#region src/webpack.ts
5
5
  /**
6
+ * This entry file is for webpack plugin.
7
+ *
8
+ * @module
9
+ */
10
+ /**
6
11
  * Webpack plugin
7
12
  *
8
13
  * @example
package/package.json CHANGED
@@ -1,54 +1,55 @@
1
1
  {
2
2
  "name": "unplugin-raw",
3
- "version": "0.6.3",
4
- "description": "Transform file to a default-export string.",
5
3
  "type": "module",
6
- "keywords": [
7
- "unplugin",
8
- "rollup",
9
- "vite",
10
- "esbuild",
11
- "webpack"
12
- ],
4
+ "version": "0.6.4",
5
+ "description": "Transform file to a default-export string.",
6
+ "author": "Kevin Deng <sxzz@sxzz.moe>",
13
7
  "license": "MIT",
8
+ "funding": "https://github.com/sponsors/sxzz",
14
9
  "homepage": "https://github.com/unplugin/unplugin-raw#readme",
15
- "bugs": {
16
- "url": "https://github.com/unplugin/unplugin-raw/issues"
17
- },
18
10
  "repository": {
19
11
  "type": "git",
20
12
  "url": "git+https://github.com/unplugin/unplugin-raw.git"
21
13
  },
22
- "author": "Kevin Deng <sxzz@sxzz.moe>",
23
- "funding": "https://github.com/sponsors/sxzz",
24
- "files": [
25
- "dist"
14
+ "bugs": {
15
+ "url": "https://github.com/unplugin/unplugin-raw/issues"
16
+ },
17
+ "keywords": [
18
+ "unplugin",
19
+ "rollup",
20
+ "vite",
21
+ "esbuild",
22
+ "webpack"
26
23
  ],
27
- "main": "./dist/index.js",
28
- "module": "./dist/index.js",
29
- "types": "./dist/index.d.ts",
30
24
  "exports": {
31
- ".": "./dist/index.js",
32
- "./api": "./dist/api.js",
33
- "./esbuild": "./dist/esbuild.js",
34
- "./rolldown": "./dist/rolldown.js",
35
- "./rollup": "./dist/rollup.js",
36
- "./rspack": "./dist/rspack.js",
37
- "./vite": "./dist/vite.js",
38
- "./webpack": "./dist/webpack.js",
25
+ ".": "./dist/index.mjs",
26
+ "./api": "./dist/api.mjs",
27
+ "./esbuild": "./dist/esbuild.mjs",
28
+ "./rolldown": "./dist/rolldown.mjs",
29
+ "./rollup": "./dist/rollup.mjs",
30
+ "./rspack": "./dist/rspack.mjs",
31
+ "./vite": "./dist/vite.mjs",
32
+ "./webpack": "./dist/webpack.mjs",
39
33
  "./package.json": "./package.json"
40
34
  },
35
+ "types": "./dist/index.d.mts",
41
36
  "typesVersions": {
42
37
  "*": {
43
38
  "*": [
44
- "./dist/*",
39
+ "./dist/*.d.mts",
45
40
  "./*"
46
41
  ]
47
42
  }
48
43
  },
44
+ "files": [
45
+ "dist"
46
+ ],
49
47
  "publishConfig": {
50
48
  "access": "public"
51
49
  },
50
+ "engines": {
51
+ "node": ">=20.19.0"
52
+ },
52
53
  "peerDependencies": {
53
54
  "esbuild": ">=0.25.0"
54
55
  },
@@ -58,26 +59,24 @@
58
59
  }
59
60
  },
60
61
  "dependencies": {
61
- "unplugin": "^2.3.10",
62
- "unplugin-utils": "^0.3.0"
62
+ "unplugin": "^2.3.11",
63
+ "unplugin-utils": "^0.3.1"
63
64
  },
64
65
  "devDependencies": {
65
- "@sxzz/eslint-config": "^7.1.4",
66
- "@sxzz/prettier-config": "^2.2.4",
67
- "@types/node": "^24.5.2",
68
- "bumpp": "^10.2.3",
69
- "esbuild": "^0.25.10",
70
- "eslint": "^9.36.0",
71
- "prettier": "^3.6.2",
72
- "rolldown": "^1.0.0-beta.38",
73
- "rollup": "^4.52.0",
74
- "tsdown": "^0.15.4",
75
- "typescript": "^5.9.2",
76
- "vite": "^7.1.6",
77
- "vitest": "^3.2.4"
78
- },
79
- "engines": {
80
- "node": ">=20.18.0"
66
+ "@sxzz/eslint-config": "^7.4.4",
67
+ "@sxzz/prettier-config": "^2.2.6",
68
+ "@types/node": "^25.0.3",
69
+ "bumpp": "^10.3.2",
70
+ "esbuild": "^0.27.2",
71
+ "eslint": "^9.39.2",
72
+ "prettier": "^3.7.4",
73
+ "rolldown": "^1.0.0-beta.58",
74
+ "rollup": "^4.54.0",
75
+ "tsdown": "^0.19.0-beta.2",
76
+ "tsdown-preset-sxzz": "^0.2.0",
77
+ "typescript": "^5.9.3",
78
+ "vite": "^7.3.0",
79
+ "vitest": "^4.0.16"
81
80
  },
82
81
  "prettier": "@sxzz/prettier-config",
83
82
  "scripts": {
package/dist/api.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { Options, OptionsResolved, TransformOptions, resolveOptions } from "./options-DupdgTT1.js";
2
- import { Buffer } from "node:buffer";
3
- import * as esbuild0 from "esbuild";
4
- import { TransformOptions as TransformOptions$1 } from "esbuild";
5
-
6
- //#region src/core/transform.d.ts
7
- declare function transformRaw(file: string, isBytes: boolean, transform?: typeof esbuild0.transform, transformFilter?: (id: string | unknown) => boolean, options?: TransformOptions$1): Promise<string | Buffer>;
8
- //#endregion
9
- export { type Options, type OptionsResolved, type TransformOptions, resolveOptions, transformRaw };
package/dist/api.js DELETED
@@ -1,3 +0,0 @@
1
- import { resolveOptions, transformRaw } from "./options-BTT0I76V.js";
2
-
3
- export { resolveOptions, transformRaw };
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import "./options-DupdgTT1.js";
2
- import { unplugin } from "./index-BMXQlGcW.js";
3
- export { unplugin as default };
package/dist/index.js DELETED
@@ -1,4 +0,0 @@
1
- import "./options-BTT0I76V.js";
2
- import { src_default } from "./src-CKGRYIxm.js";
3
-
4
- export { src_default as default };