@uni_toolkit/unplugin-json-optimization 0.0.19 → 0.0.21-alpha.1776521649215
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 +5 -0
- package/dist/index.cjs +7 -105
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +51 -9
- package/dist/src-csOFk3Wd.cjs +92 -0
- package/dist/types.cjs +0 -18
- package/dist/types.d.cts +6 -5
- package/dist/types.d.ts +6 -5
- package/dist/types.js +1 -0
- package/dist/vite.cjs +5 -103
- package/dist/vite.d.cts +5 -6
- package/dist/vite.d.ts +6 -6
- package/dist/vite.js +4 -8
- package/dist/webpack.cjs +5 -103
- package/dist/webpack.d.cts +5 -6
- package/dist/webpack.d.ts +6 -6
- package/dist/webpack.js +4 -8
- package/package.json +4 -4
- package/dist/chunk-JXHP6A5L.js +0 -71
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,106 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
33
|
-
default: () => src_default,
|
|
34
|
-
unplugin: () => unplugin,
|
|
35
|
-
unpluginFactory: () => unpluginFactory
|
|
36
|
-
});
|
|
37
|
-
module.exports = __toCommonJS(src_exports);
|
|
38
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
39
|
-
var import_pluginutils = require("@rollup/pluginutils");
|
|
40
|
-
var import_unplugin = require("unplugin");
|
|
41
|
-
function replaceRequirePaths(code, pathMapper) {
|
|
42
|
-
return code.replace(/require\s*\(\s*(["'])([^"']+)\1\s*\)/g, (match, quote, path2) => {
|
|
43
|
-
const newPath = pathMapper(path2);
|
|
44
|
-
if (newPath && newPath !== path2) {
|
|
45
|
-
return `require(${quote}${newPath}${quote})`;
|
|
46
|
-
}
|
|
47
|
-
return match;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
var unpluginFactory = (options = {
|
|
51
|
-
includes: ["**/*.json"],
|
|
52
|
-
excludes: ["pages.json", "**/uni_modules/**/*.json"]
|
|
53
|
-
}) => {
|
|
54
|
-
const jsonFiles = /* @__PURE__ */ new Set();
|
|
55
|
-
const pathMap = /* @__PURE__ */ new Map();
|
|
56
|
-
const inputDir = process.env.UNI_INPUT_DIR;
|
|
57
|
-
return {
|
|
58
|
-
name: "unplugin-json-optimization",
|
|
59
|
-
enforce: "post",
|
|
60
|
-
load(id) {
|
|
61
|
-
if (!id.endsWith(".json") || !(0, import_pluginutils.createFilter)(options.includes, options.excludes)(id)) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
if (!jsonFiles.has(id)) {
|
|
65
|
-
jsonFiles.add(id);
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
generateBundle(_, bundle) {
|
|
69
|
-
const bundleEntries = Object.entries(bundle);
|
|
70
|
-
for (const [fileName, chunk] of bundleEntries) {
|
|
71
|
-
if (chunk.type !== "chunk" || !chunk.moduleIds || !chunk.moduleIds.length || fileName.includes("/")) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
const id = chunk.moduleIds.find((id2) => jsonFiles.has(id2));
|
|
75
|
-
if (id) {
|
|
76
|
-
const relativePath = import_node_path.default.relative(inputDir, id);
|
|
77
|
-
const { dir, name } = import_node_path.default.parse(relativePath);
|
|
78
|
-
chunk.fileName = `${import_node_path.default.join(dir, name)}.js`;
|
|
79
|
-
pathMap.set(fileName, chunk.fileName);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const keys = Array.from(pathMap.keys());
|
|
83
|
-
for (const [fileName, chunk] of bundleEntries) {
|
|
84
|
-
if (chunk.type !== "chunk") {
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
if (keys.some((key) => chunk.code.includes(key))) {
|
|
88
|
-
chunk.code = replaceRequirePaths(chunk.code, (originalPath) => {
|
|
89
|
-
const name = import_node_path.default.relative(process.cwd(), import_node_path.default.resolve(import_node_path.default.dirname(fileName), originalPath));
|
|
90
|
-
if (keys.includes(name)) {
|
|
91
|
-
return import_node_path.default.relative(import_node_path.default.dirname(fileName), pathMap.get(name));
|
|
92
|
-
}
|
|
93
|
-
return originalPath;
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
var unplugin = /* @__PURE__ */ (0, import_unplugin.createUnplugin)(unpluginFactory);
|
|
101
|
-
var src_default = unplugin;
|
|
102
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
-
0 && (module.exports = {
|
|
104
|
-
unplugin,
|
|
105
|
-
unpluginFactory
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
106
4
|
});
|
|
5
|
+
const require_src = require("./src-csOFk3Wd.cjs");
|
|
6
|
+
exports.default = require_src.unplugin;
|
|
7
|
+
exports.unplugin = require_src.unplugin;
|
|
8
|
+
exports.unpluginFactory = require_src.unpluginFactory;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import '@rollup/pluginutils';
|
|
1
|
+
import { Options } from "./types.cjs";
|
|
2
|
+
import * as _$unplugin from "unplugin";
|
|
3
|
+
import { UnpluginFactory } from "unplugin";
|
|
5
4
|
|
|
5
|
+
//#region src/index.d.ts
|
|
6
6
|
declare const unpluginFactory: UnpluginFactory<Options | undefined>;
|
|
7
|
-
declare const unplugin:
|
|
8
|
-
|
|
9
|
-
export { unplugin as default, unplugin, unpluginFactory };
|
|
7
|
+
declare const unplugin: _$unplugin.UnpluginInstance<Options | undefined, boolean>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { unplugin as default, unplugin, unpluginFactory };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import '@rollup/pluginutils';
|
|
1
|
+
import { Options } from "./types.js";
|
|
2
|
+
import * as _$unplugin from "unplugin";
|
|
3
|
+
import { UnpluginFactory } from "unplugin";
|
|
5
4
|
|
|
5
|
+
//#region src/index.d.ts
|
|
6
6
|
declare const unpluginFactory: UnpluginFactory<Options | undefined>;
|
|
7
|
-
declare const unplugin:
|
|
8
|
-
|
|
9
|
-
export { unplugin as default, unplugin, unpluginFactory };
|
|
7
|
+
declare const unplugin: _$unplugin.UnpluginInstance<Options | undefined, boolean>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { unplugin as default, unplugin, unpluginFactory };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,52 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
3
|
+
import { createUnplugin } from "unplugin";
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
function replaceRequirePaths(code, pathMapper) {
|
|
6
|
+
return code.replace(/require\s*\(\s*(["'])([^"']+)\1\s*\)/g, (match, quote, path) => {
|
|
7
|
+
const newPath = pathMapper(path);
|
|
8
|
+
if (newPath && newPath !== path) return `require(${quote}${newPath}${quote})`;
|
|
9
|
+
return match;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
const unpluginFactory = (options = {
|
|
13
|
+
includes: ["**/*.json"],
|
|
14
|
+
excludes: ["pages.json", "**/uni_modules/**/*.json"]
|
|
15
|
+
}) => {
|
|
16
|
+
const jsonFiles = /* @__PURE__ */ new Set();
|
|
17
|
+
const pathMap = /* @__PURE__ */ new Map();
|
|
18
|
+
const inputDir = process.env.UNI_INPUT_DIR;
|
|
19
|
+
return {
|
|
20
|
+
name: "unplugin-json-optimization",
|
|
21
|
+
enforce: "post",
|
|
22
|
+
load(id) {
|
|
23
|
+
if (!id.endsWith(".json") || !createFilter(options.includes, options.excludes)(id)) return null;
|
|
24
|
+
if (!jsonFiles.has(id)) jsonFiles.add(id);
|
|
25
|
+
},
|
|
26
|
+
generateBundle(_, bundle) {
|
|
27
|
+
const bundleEntries = Object.entries(bundle);
|
|
28
|
+
for (const [fileName, chunk] of bundleEntries) {
|
|
29
|
+
if (chunk.type !== "chunk" || !chunk.moduleIds || !chunk.moduleIds.length || fileName.includes("/")) continue;
|
|
30
|
+
const id = chunk.moduleIds.find((id) => jsonFiles.has(id));
|
|
31
|
+
if (id) {
|
|
32
|
+
const relativePath = path.relative(inputDir, id);
|
|
33
|
+
const { dir, name } = path.parse(relativePath);
|
|
34
|
+
chunk.fileName = `${path.join(dir, name)}.js`;
|
|
35
|
+
pathMap.set(fileName, chunk.fileName);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const keys = Array.from(pathMap.keys());
|
|
39
|
+
for (const [fileName, chunk] of bundleEntries) {
|
|
40
|
+
if (chunk.type !== "chunk") continue;
|
|
41
|
+
if (keys.some((key) => chunk.code.includes(key))) chunk.code = replaceRequirePaths(chunk.code, (originalPath) => {
|
|
42
|
+
const name = path.relative(process.cwd(), path.resolve(path.dirname(fileName), originalPath));
|
|
43
|
+
if (keys.includes(name)) return path.relative(path.dirname(fileName), pathMap.get(name));
|
|
44
|
+
return originalPath;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
10
49
|
};
|
|
50
|
+
const unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
51
|
+
//#endregion
|
|
52
|
+
export { unplugin as default, unplugin, unpluginFactory };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
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
|
+
//#endregion
|
|
23
|
+
let node_path = require("node:path");
|
|
24
|
+
node_path = __toESM(node_path, 1);
|
|
25
|
+
let _rollup_pluginutils = require("@rollup/pluginutils");
|
|
26
|
+
let unplugin = require("unplugin");
|
|
27
|
+
//#region src/index.ts
|
|
28
|
+
function replaceRequirePaths(code, pathMapper) {
|
|
29
|
+
return code.replace(/require\s*\(\s*(["'])([^"']+)\1\s*\)/g, (match, quote, path) => {
|
|
30
|
+
const newPath = pathMapper(path);
|
|
31
|
+
if (newPath && newPath !== path) return `require(${quote}${newPath}${quote})`;
|
|
32
|
+
return match;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const unpluginFactory = (options = {
|
|
36
|
+
includes: ["**/*.json"],
|
|
37
|
+
excludes: ["pages.json", "**/uni_modules/**/*.json"]
|
|
38
|
+
}) => {
|
|
39
|
+
const jsonFiles = /* @__PURE__ */ new Set();
|
|
40
|
+
const pathMap = /* @__PURE__ */ new Map();
|
|
41
|
+
const inputDir = process.env.UNI_INPUT_DIR;
|
|
42
|
+
return {
|
|
43
|
+
name: "unplugin-json-optimization",
|
|
44
|
+
enforce: "post",
|
|
45
|
+
load(id) {
|
|
46
|
+
if (!id.endsWith(".json") || !(0, _rollup_pluginutils.createFilter)(options.includes, options.excludes)(id)) return null;
|
|
47
|
+
if (!jsonFiles.has(id)) jsonFiles.add(id);
|
|
48
|
+
},
|
|
49
|
+
generateBundle(_, bundle) {
|
|
50
|
+
const bundleEntries = Object.entries(bundle);
|
|
51
|
+
for (const [fileName, chunk] of bundleEntries) {
|
|
52
|
+
if (chunk.type !== "chunk" || !chunk.moduleIds || !chunk.moduleIds.length || fileName.includes("/")) continue;
|
|
53
|
+
const id = chunk.moduleIds.find((id) => jsonFiles.has(id));
|
|
54
|
+
if (id) {
|
|
55
|
+
const relativePath = node_path.default.relative(inputDir, id);
|
|
56
|
+
const { dir, name } = node_path.default.parse(relativePath);
|
|
57
|
+
chunk.fileName = `${node_path.default.join(dir, name)}.js`;
|
|
58
|
+
pathMap.set(fileName, chunk.fileName);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const keys = Array.from(pathMap.keys());
|
|
62
|
+
for (const [fileName, chunk] of bundleEntries) {
|
|
63
|
+
if (chunk.type !== "chunk") continue;
|
|
64
|
+
if (keys.some((key) => chunk.code.includes(key))) chunk.code = replaceRequirePaths(chunk.code, (originalPath) => {
|
|
65
|
+
const name = node_path.default.relative(process.cwd(), node_path.default.resolve(node_path.default.dirname(fileName), originalPath));
|
|
66
|
+
if (keys.includes(name)) return node_path.default.relative(node_path.default.dirname(fileName), pathMap.get(name));
|
|
67
|
+
return originalPath;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
const unplugin$1 = /* @__PURE__ */ (0, unplugin.createUnplugin)(unpluginFactory);
|
|
74
|
+
//#endregion
|
|
75
|
+
Object.defineProperty(exports, "__toESM", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function() {
|
|
78
|
+
return __toESM;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(exports, "unplugin", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function() {
|
|
84
|
+
return unplugin$1;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(exports, "unpluginFactory", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function() {
|
|
90
|
+
return unpluginFactory;
|
|
91
|
+
}
|
|
92
|
+
});
|
package/dist/types.cjs
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
|
|
16
|
-
// src/types.ts
|
|
17
|
-
var types_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(types_exports);
|
package/dist/types.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { FilterPattern } from
|
|
1
|
+
import { FilterPattern } from "@rollup/pluginutils";
|
|
2
2
|
|
|
3
|
+
//#region src/types.d.ts
|
|
3
4
|
interface Options {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
includes?: FilterPattern;
|
|
6
|
+
excludes?: FilterPattern;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
export { Options };
|
|
8
|
+
//#endregion
|
|
9
|
+
export { Options };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { FilterPattern } from
|
|
1
|
+
import { FilterPattern } from "@rollup/pluginutils";
|
|
2
2
|
|
|
3
|
+
//#region src/types.d.ts
|
|
3
4
|
interface Options {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
includes?: FilterPattern;
|
|
6
|
+
excludes?: FilterPattern;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
export { Options };
|
|
8
|
+
//#endregion
|
|
9
|
+
export { Options };
|
package/dist/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/vite.cjs
CHANGED
|
@@ -1,103 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/vite.ts
|
|
31
|
-
var vite_exports = {};
|
|
32
|
-
__export(vite_exports, {
|
|
33
|
-
default: () => vite_default
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(vite_exports);
|
|
36
|
-
var import_unplugin2 = require("unplugin");
|
|
37
|
-
|
|
38
|
-
// src/index.ts
|
|
39
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
40
|
-
var import_pluginutils = require("@rollup/pluginutils");
|
|
41
|
-
var import_unplugin = require("unplugin");
|
|
42
|
-
function replaceRequirePaths(code, pathMapper) {
|
|
43
|
-
return code.replace(/require\s*\(\s*(["'])([^"']+)\1\s*\)/g, (match, quote, path2) => {
|
|
44
|
-
const newPath = pathMapper(path2);
|
|
45
|
-
if (newPath && newPath !== path2) {
|
|
46
|
-
return `require(${quote}${newPath}${quote})`;
|
|
47
|
-
}
|
|
48
|
-
return match;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
var unpluginFactory = (options = {
|
|
52
|
-
includes: ["**/*.json"],
|
|
53
|
-
excludes: ["pages.json", "**/uni_modules/**/*.json"]
|
|
54
|
-
}) => {
|
|
55
|
-
const jsonFiles = /* @__PURE__ */ new Set();
|
|
56
|
-
const pathMap = /* @__PURE__ */ new Map();
|
|
57
|
-
const inputDir = process.env.UNI_INPUT_DIR;
|
|
58
|
-
return {
|
|
59
|
-
name: "unplugin-json-optimization",
|
|
60
|
-
enforce: "post",
|
|
61
|
-
load(id) {
|
|
62
|
-
if (!id.endsWith(".json") || !(0, import_pluginutils.createFilter)(options.includes, options.excludes)(id)) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
if (!jsonFiles.has(id)) {
|
|
66
|
-
jsonFiles.add(id);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
generateBundle(_, bundle) {
|
|
70
|
-
const bundleEntries = Object.entries(bundle);
|
|
71
|
-
for (const [fileName, chunk] of bundleEntries) {
|
|
72
|
-
if (chunk.type !== "chunk" || !chunk.moduleIds || !chunk.moduleIds.length || fileName.includes("/")) {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const id = chunk.moduleIds.find((id2) => jsonFiles.has(id2));
|
|
76
|
-
if (id) {
|
|
77
|
-
const relativePath = import_node_path.default.relative(inputDir, id);
|
|
78
|
-
const { dir, name } = import_node_path.default.parse(relativePath);
|
|
79
|
-
chunk.fileName = `${import_node_path.default.join(dir, name)}.js`;
|
|
80
|
-
pathMap.set(fileName, chunk.fileName);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const keys = Array.from(pathMap.keys());
|
|
84
|
-
for (const [fileName, chunk] of bundleEntries) {
|
|
85
|
-
if (chunk.type !== "chunk") {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
if (keys.some((key) => chunk.code.includes(key))) {
|
|
89
|
-
chunk.code = replaceRequirePaths(chunk.code, (originalPath) => {
|
|
90
|
-
const name = import_node_path.default.relative(process.cwd(), import_node_path.default.resolve(import_node_path.default.dirname(fileName), originalPath));
|
|
91
|
-
if (keys.includes(name)) {
|
|
92
|
-
return import_node_path.default.relative(import_node_path.default.dirname(fileName), pathMap.get(name));
|
|
93
|
-
}
|
|
94
|
-
return originalPath;
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
// src/vite.ts
|
|
103
|
-
var vite_default = (0, import_unplugin2.createVitePlugin)(unpluginFactory);
|
|
1
|
+
const require_src = require("./src-csOFk3Wd.cjs");
|
|
2
|
+
//#region src/vite.ts
|
|
3
|
+
var vite_default = (0, require("unplugin").createVitePlugin)(require_src.unpluginFactory);
|
|
4
|
+
//#endregion
|
|
5
|
+
module.exports = vite_default;
|
package/dist/vite.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import '@rollup/pluginutils';
|
|
1
|
+
import { Options } from "./types.cjs";
|
|
2
|
+
import * as _$vite from "vite";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
4
|
+
//#region src/vite.d.ts
|
|
5
|
+
declare const _default: (options?: Options | undefined) => _$vite.Plugin<any> | _$vite.Plugin<any>[];
|
|
6
|
+
export = _default;
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import '@rollup/pluginutils';
|
|
1
|
+
import { Options } from "./types.js";
|
|
2
|
+
import * as _$vite from "vite";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
//#region src/vite.d.ts
|
|
5
|
+
declare const _default: (options?: Options | undefined) => _$vite.Plugin<any> | _$vite.Plugin<any>[];
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default as default };
|
package/dist/vite.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
unpluginFactory
|
|
3
|
-
} from "./chunk-JXHP6A5L.js";
|
|
4
|
-
|
|
5
|
-
// src/vite.ts
|
|
1
|
+
import { unpluginFactory } from "./index.js";
|
|
6
2
|
import { createVitePlugin } from "unplugin";
|
|
3
|
+
//#region src/vite.ts
|
|
7
4
|
var vite_default = createVitePlugin(unpluginFactory);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
5
|
+
//#endregion
|
|
6
|
+
export { vite_default as default };
|
package/dist/webpack.cjs
CHANGED
|
@@ -1,103 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/webpack.ts
|
|
31
|
-
var webpack_exports = {};
|
|
32
|
-
__export(webpack_exports, {
|
|
33
|
-
default: () => webpack_default
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(webpack_exports);
|
|
36
|
-
var import_unplugin2 = require("unplugin");
|
|
37
|
-
|
|
38
|
-
// src/index.ts
|
|
39
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
40
|
-
var import_pluginutils = require("@rollup/pluginutils");
|
|
41
|
-
var import_unplugin = require("unplugin");
|
|
42
|
-
function replaceRequirePaths(code, pathMapper) {
|
|
43
|
-
return code.replace(/require\s*\(\s*(["'])([^"']+)\1\s*\)/g, (match, quote, path2) => {
|
|
44
|
-
const newPath = pathMapper(path2);
|
|
45
|
-
if (newPath && newPath !== path2) {
|
|
46
|
-
return `require(${quote}${newPath}${quote})`;
|
|
47
|
-
}
|
|
48
|
-
return match;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
var unpluginFactory = (options = {
|
|
52
|
-
includes: ["**/*.json"],
|
|
53
|
-
excludes: ["pages.json", "**/uni_modules/**/*.json"]
|
|
54
|
-
}) => {
|
|
55
|
-
const jsonFiles = /* @__PURE__ */ new Set();
|
|
56
|
-
const pathMap = /* @__PURE__ */ new Map();
|
|
57
|
-
const inputDir = process.env.UNI_INPUT_DIR;
|
|
58
|
-
return {
|
|
59
|
-
name: "unplugin-json-optimization",
|
|
60
|
-
enforce: "post",
|
|
61
|
-
load(id) {
|
|
62
|
-
if (!id.endsWith(".json") || !(0, import_pluginutils.createFilter)(options.includes, options.excludes)(id)) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
if (!jsonFiles.has(id)) {
|
|
66
|
-
jsonFiles.add(id);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
generateBundle(_, bundle) {
|
|
70
|
-
const bundleEntries = Object.entries(bundle);
|
|
71
|
-
for (const [fileName, chunk] of bundleEntries) {
|
|
72
|
-
if (chunk.type !== "chunk" || !chunk.moduleIds || !chunk.moduleIds.length || fileName.includes("/")) {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const id = chunk.moduleIds.find((id2) => jsonFiles.has(id2));
|
|
76
|
-
if (id) {
|
|
77
|
-
const relativePath = import_node_path.default.relative(inputDir, id);
|
|
78
|
-
const { dir, name } = import_node_path.default.parse(relativePath);
|
|
79
|
-
chunk.fileName = `${import_node_path.default.join(dir, name)}.js`;
|
|
80
|
-
pathMap.set(fileName, chunk.fileName);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const keys = Array.from(pathMap.keys());
|
|
84
|
-
for (const [fileName, chunk] of bundleEntries) {
|
|
85
|
-
if (chunk.type !== "chunk") {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
if (keys.some((key) => chunk.code.includes(key))) {
|
|
89
|
-
chunk.code = replaceRequirePaths(chunk.code, (originalPath) => {
|
|
90
|
-
const name = import_node_path.default.relative(process.cwd(), import_node_path.default.resolve(import_node_path.default.dirname(fileName), originalPath));
|
|
91
|
-
if (keys.includes(name)) {
|
|
92
|
-
return import_node_path.default.relative(import_node_path.default.dirname(fileName), pathMap.get(name));
|
|
93
|
-
}
|
|
94
|
-
return originalPath;
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
// src/webpack.ts
|
|
103
|
-
var webpack_default = (0, import_unplugin2.createWebpackPlugin)(unpluginFactory);
|
|
1
|
+
const require_src = require("./src-csOFk3Wd.cjs");
|
|
2
|
+
//#region src/webpack.ts
|
|
3
|
+
var webpack_default = (0, require("unplugin").createWebpackPlugin)(require_src.unpluginFactory);
|
|
4
|
+
//#endregion
|
|
5
|
+
module.exports = webpack_default;
|
package/dist/webpack.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import '@rollup/pluginutils';
|
|
1
|
+
import { Options } from "./types.cjs";
|
|
2
|
+
import * as _$webpack from "webpack";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
4
|
+
//#region src/webpack.d.ts
|
|
5
|
+
declare const _default: (options?: Options | undefined) => _$webpack.WebpackPluginInstance;
|
|
6
|
+
export = _default;
|
package/dist/webpack.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import '@rollup/pluginutils';
|
|
1
|
+
import { Options } from "./types.js";
|
|
2
|
+
import * as _$webpack from "webpack";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
//#region src/webpack.d.ts
|
|
5
|
+
declare const _default: (options?: Options | undefined) => _$webpack.WebpackPluginInstance;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default as default };
|
package/dist/webpack.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
unpluginFactory
|
|
3
|
-
} from "./chunk-JXHP6A5L.js";
|
|
4
|
-
|
|
5
|
-
// src/webpack.ts
|
|
1
|
+
import { unpluginFactory } from "./index.js";
|
|
6
2
|
import { createWebpackPlugin } from "unplugin";
|
|
3
|
+
//#region src/webpack.ts
|
|
7
4
|
var webpack_default = createWebpackPlugin(unpluginFactory);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
5
|
+
//#endregion
|
|
6
|
+
export { webpack_default as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uni_toolkit/unplugin-json-optimization",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.21-alpha.1776521649215",
|
|
5
5
|
"description": "A plugin to optimize json files generation",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/uni-toolkit/uni-toolkit/tree/main/packages/unplugin-json-optimization",
|
|
@@ -78,15 +78,15 @@
|
|
|
78
78
|
"@types/node": "^22.15.21",
|
|
79
79
|
"nodemon": "^3.1.10",
|
|
80
80
|
"rollup": "^4.41.0",
|
|
81
|
-
"
|
|
81
|
+
"tsdown": "^0.21.8",
|
|
82
82
|
"tsx": "^4.19.4",
|
|
83
83
|
"typescript": "^5.8.3",
|
|
84
84
|
"vite": "^6.3.5",
|
|
85
85
|
"webpack": "^5.99.9"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
|
-
"build": "
|
|
89
|
-
"dev": "
|
|
88
|
+
"build": "tsdown",
|
|
89
|
+
"dev": "tsdown --watch",
|
|
90
90
|
"start": "tsx src/index.ts"
|
|
91
91
|
}
|
|
92
92
|
}
|
package/dist/chunk-JXHP6A5L.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { createFilter } from "@rollup/pluginutils";
|
|
4
|
-
import { createUnplugin } from "unplugin";
|
|
5
|
-
function replaceRequirePaths(code, pathMapper) {
|
|
6
|
-
return code.replace(/require\s*\(\s*(["'])([^"']+)\1\s*\)/g, (match, quote, path2) => {
|
|
7
|
-
const newPath = pathMapper(path2);
|
|
8
|
-
if (newPath && newPath !== path2) {
|
|
9
|
-
return `require(${quote}${newPath}${quote})`;
|
|
10
|
-
}
|
|
11
|
-
return match;
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
var unpluginFactory = (options = {
|
|
15
|
-
includes: ["**/*.json"],
|
|
16
|
-
excludes: ["pages.json", "**/uni_modules/**/*.json"]
|
|
17
|
-
}) => {
|
|
18
|
-
const jsonFiles = /* @__PURE__ */ new Set();
|
|
19
|
-
const pathMap = /* @__PURE__ */ new Map();
|
|
20
|
-
const inputDir = process.env.UNI_INPUT_DIR;
|
|
21
|
-
return {
|
|
22
|
-
name: "unplugin-json-optimization",
|
|
23
|
-
enforce: "post",
|
|
24
|
-
load(id) {
|
|
25
|
-
if (!id.endsWith(".json") || !createFilter(options.includes, options.excludes)(id)) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
if (!jsonFiles.has(id)) {
|
|
29
|
-
jsonFiles.add(id);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
generateBundle(_, bundle) {
|
|
33
|
-
const bundleEntries = Object.entries(bundle);
|
|
34
|
-
for (const [fileName, chunk] of bundleEntries) {
|
|
35
|
-
if (chunk.type !== "chunk" || !chunk.moduleIds || !chunk.moduleIds.length || fileName.includes("/")) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
const id = chunk.moduleIds.find((id2) => jsonFiles.has(id2));
|
|
39
|
-
if (id) {
|
|
40
|
-
const relativePath = path.relative(inputDir, id);
|
|
41
|
-
const { dir, name } = path.parse(relativePath);
|
|
42
|
-
chunk.fileName = `${path.join(dir, name)}.js`;
|
|
43
|
-
pathMap.set(fileName, chunk.fileName);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const keys = Array.from(pathMap.keys());
|
|
47
|
-
for (const [fileName, chunk] of bundleEntries) {
|
|
48
|
-
if (chunk.type !== "chunk") {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (keys.some((key) => chunk.code.includes(key))) {
|
|
52
|
-
chunk.code = replaceRequirePaths(chunk.code, (originalPath) => {
|
|
53
|
-
const name = path.relative(process.cwd(), path.resolve(path.dirname(fileName), originalPath));
|
|
54
|
-
if (keys.includes(name)) {
|
|
55
|
-
return path.relative(path.dirname(fileName), pathMap.get(name));
|
|
56
|
-
}
|
|
57
|
-
return originalPath;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
var unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
65
|
-
var src_default = unplugin;
|
|
66
|
-
|
|
67
|
-
export {
|
|
68
|
-
unpluginFactory,
|
|
69
|
-
unplugin,
|
|
70
|
-
src_default
|
|
71
|
-
};
|