@sepveneto/plugin-mp-router-view 0.4.4 → 0.5.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/dist/{chunk-UB2NVQE4.js → chunk-34IBKFGI.js} +58 -57
- package/dist/chunk-M3QQKYK3.js +44 -0
- package/dist/esbuild.cjs +54 -25
- package/dist/esbuild.js +2 -1
- package/dist/helper/index.cjs +45 -0
- package/dist/helper/index.d.ts +5 -0
- package/dist/helper/index.js +19 -0
- package/dist/index.cjs +54 -25
- package/dist/index.js +2 -1
- package/dist/loader.cjs +72 -41
- package/dist/loader.js +8 -3
- package/dist/rollup.cjs +54 -25
- package/dist/rollup.js +2 -1
- package/dist/type.d.d.ts +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/vite.cjs +54 -25
- package/dist/vite.js +2 -1
- package/dist/webpack.cjs +54 -25
- package/dist/webpack.js +2 -1
- package/package.json +6 -1
package/dist/index.cjs
CHANGED
|
@@ -67,7 +67,7 @@ __export(src_exports, {
|
|
|
67
67
|
unpluginFactory: () => unpluginFactory
|
|
68
68
|
});
|
|
69
69
|
module.exports = __toCommonJS(src_exports);
|
|
70
|
-
var
|
|
70
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
71
71
|
var import_unplugin = require("unplugin");
|
|
72
72
|
|
|
73
73
|
// src/util/parse.ts
|
|
@@ -5591,17 +5591,17 @@ function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
|
5591
5591
|
if (hasTrailingSlash(input, true)) {
|
|
5592
5592
|
return input || "/";
|
|
5593
5593
|
}
|
|
5594
|
-
let
|
|
5594
|
+
let path8 = input;
|
|
5595
5595
|
let fragment = "";
|
|
5596
5596
|
const fragmentIndex = input.indexOf("#");
|
|
5597
5597
|
if (fragmentIndex >= 0) {
|
|
5598
|
-
|
|
5598
|
+
path8 = input.slice(0, fragmentIndex);
|
|
5599
5599
|
fragment = input.slice(fragmentIndex);
|
|
5600
|
-
if (!
|
|
5600
|
+
if (!path8) {
|
|
5601
5601
|
return fragment;
|
|
5602
5602
|
}
|
|
5603
5603
|
}
|
|
5604
|
-
const [s0, ...s] =
|
|
5604
|
+
const [s0, ...s] = path8.split("?");
|
|
5605
5605
|
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
|
|
5606
5606
|
}
|
|
5607
5607
|
function isNonEmptyURL(url) {
|
|
@@ -5635,8 +5635,8 @@ var import_node_path = __toESM(require("path"), 1);
|
|
|
5635
5635
|
var import_node_v8 = __toESM(require("v8"), 1);
|
|
5636
5636
|
var import_node_util = require("util");
|
|
5637
5637
|
var BUILTIN_MODULES = new Set(import_node_module.builtinModules);
|
|
5638
|
-
function normalizeSlash(
|
|
5639
|
-
return
|
|
5638
|
+
function normalizeSlash(path8) {
|
|
5639
|
+
return path8.replace(/\\/g, "/");
|
|
5640
5640
|
}
|
|
5641
5641
|
var own$1 = {}.hasOwnProperty;
|
|
5642
5642
|
var classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
@@ -5752,8 +5752,8 @@ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
|
5752
5752
|
* @param {string} [base]
|
|
5753
5753
|
* @param {string} [message]
|
|
5754
5754
|
*/
|
|
5755
|
-
(
|
|
5756
|
-
return `Invalid package config ${
|
|
5755
|
+
(path8, base, message) => {
|
|
5756
|
+
return `Invalid package config ${path8}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
|
|
5757
5757
|
},
|
|
5758
5758
|
Error
|
|
5759
5759
|
);
|
|
@@ -5785,8 +5785,8 @@ codes.ERR_MODULE_NOT_FOUND = createError(
|
|
|
5785
5785
|
* @param {string} base
|
|
5786
5786
|
* @param {boolean} [exactUrl]
|
|
5787
5787
|
*/
|
|
5788
|
-
(
|
|
5789
|
-
return `Cannot find ${exactUrl ? "module" : "package"} '${
|
|
5788
|
+
(path8, base, exactUrl = false) => {
|
|
5789
|
+
return `Cannot find ${exactUrl ? "module" : "package"} '${path8}' imported from ${base}`;
|
|
5790
5790
|
},
|
|
5791
5791
|
Error
|
|
5792
5792
|
);
|
|
@@ -5837,8 +5837,8 @@ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
|
5837
5837
|
* @param {string} extension
|
|
5838
5838
|
* @param {string} path
|
|
5839
5839
|
*/
|
|
5840
|
-
(extension,
|
|
5841
|
-
return `Unknown file extension "${extension}" for ${
|
|
5840
|
+
(extension, path8) => {
|
|
5841
|
+
return `Unknown file extension "${extension}" for ${path8}`;
|
|
5842
5842
|
},
|
|
5843
5843
|
TypeError
|
|
5844
5844
|
);
|
|
@@ -6218,9 +6218,9 @@ Default "index" lookups for the main are deprecated for ES modules.`,
|
|
|
6218
6218
|
);
|
|
6219
6219
|
}
|
|
6220
6220
|
}
|
|
6221
|
-
function tryStatSync(
|
|
6221
|
+
function tryStatSync(path8) {
|
|
6222
6222
|
try {
|
|
6223
|
-
return (0, import_node_fs.statSync)(
|
|
6223
|
+
return (0, import_node_fs.statSync)(path8);
|
|
6224
6224
|
} catch (e) {
|
|
6225
6225
|
}
|
|
6226
6226
|
}
|
|
@@ -7075,10 +7075,10 @@ _head = new WeakMap();
|
|
|
7075
7075
|
_tail = new WeakMap();
|
|
7076
7076
|
_size = new WeakMap();
|
|
7077
7077
|
var findUpStop = Symbol("findUpStop");
|
|
7078
|
-
function _resolve2(
|
|
7078
|
+
function _resolve2(path8, options = {}) {
|
|
7079
7079
|
if (options.platform === "auto" || !options.platform)
|
|
7080
7080
|
options.platform = import_node_process2.default.platform === "win32" ? "win32" : "posix";
|
|
7081
|
-
const modulePath = resolvePathSync(
|
|
7081
|
+
const modulePath = resolvePathSync(path8, {
|
|
7082
7082
|
url: options.paths
|
|
7083
7083
|
});
|
|
7084
7084
|
if (options.platform === "win32")
|
|
@@ -7179,12 +7179,13 @@ function addToHeader(code, header2) {
|
|
|
7179
7179
|
function addToFooter(code, footer2) {
|
|
7180
7180
|
return code.replace(/(\s*)(<\/template>)(?!(([\s\S]*)(<\/template>)))/, (p) => footer2 + p);
|
|
7181
7181
|
}
|
|
7182
|
+
var pageMap = /* @__PURE__ */ new Map();
|
|
7182
7183
|
function getPages(collectMode) {
|
|
7183
7184
|
const jsonStr = import_node_fs3.default.readFileSync(import_node_path3.default.resolve(INPUT_DIR, "pages.json"), "utf-8");
|
|
7184
7185
|
const pagesJson = parseJson(jsonStr);
|
|
7185
7186
|
const { pages, subPackages = [] } = pagesJson;
|
|
7186
7187
|
const entryList = [...collectEntry(collectMode, pages), ...collectEntry(collectMode, subPackages)];
|
|
7187
|
-
return entryList;
|
|
7188
|
+
return { entryList, pageMap };
|
|
7188
7189
|
}
|
|
7189
7190
|
function collectEntry(collectMode, json, root = "") {
|
|
7190
7191
|
const entryList = [];
|
|
@@ -7197,6 +7198,7 @@ function collectEntry(collectMode, json, root = "") {
|
|
|
7197
7198
|
return;
|
|
7198
7199
|
}
|
|
7199
7200
|
const _path = import_node_path3.default.resolve(INPUT_DIR, `${root}${root ? "/" : ""}${item.path}`);
|
|
7201
|
+
pageMap.set(_path, item);
|
|
7200
7202
|
if (collectMode && typeof collectMode === "boolean" && !item["ROUTER_VIEW_EXCLUDE"]) {
|
|
7201
7203
|
entryList.push(_path);
|
|
7202
7204
|
} else if (typeof collectMode === "string" && item[collectMode]) {
|
|
@@ -7216,9 +7218,9 @@ function combineCode(code, header2, footer2) {
|
|
|
7216
7218
|
code = addToFooter(code, footer2);
|
|
7217
7219
|
return code;
|
|
7218
7220
|
}
|
|
7219
|
-
function transform(
|
|
7221
|
+
function transform(path8, code, entryPages, level) {
|
|
7220
7222
|
logLevel = level;
|
|
7221
|
-
if (isAppVue(
|
|
7223
|
+
if (isAppVue(path8)) {
|
|
7222
7224
|
log(`\u57FA\u4E8E\u5E73\u53F0${process.env.UNI_PLATFORM}, \u5904\u7406App.vue...`, logLevel);
|
|
7223
7225
|
const { origin, tpl } = getTemplate(code);
|
|
7224
7226
|
const { count, before, after } = countRouterView(tpl);
|
|
@@ -7230,28 +7232,55 @@ function transform(path7, code, entryPages, level) {
|
|
|
7230
7232
|
header = before;
|
|
7231
7233
|
footer = after;
|
|
7232
7234
|
return origin;
|
|
7233
|
-
} else if (isEntryPage(
|
|
7234
|
-
log(`\u5904\u7406 ${
|
|
7235
|
+
} else if (isEntryPage(path8, entryPages)) {
|
|
7236
|
+
log(`\u5904\u7406 ${path8} ...`, logLevel);
|
|
7235
7237
|
code = combineCode(code, header, footer);
|
|
7236
7238
|
}
|
|
7237
7239
|
return code;
|
|
7238
7240
|
}
|
|
7239
7241
|
|
|
7242
|
+
// src/util/pagemeta.ts
|
|
7243
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
7244
|
+
|
|
7245
|
+
// src/util/constant.ts
|
|
7246
|
+
var PAGE_META = "$$__PageMeta";
|
|
7247
|
+
|
|
7248
|
+
// src/util/pagemeta.ts
|
|
7249
|
+
var scriptRegex = /<script\b[^>]*>/;
|
|
7250
|
+
function injectPageMeta(code, id, pageMap2) {
|
|
7251
|
+
const ext = import_node_path4.default.extname(id);
|
|
7252
|
+
const key = id.replace(new RegExp(`${ext}$`), "");
|
|
7253
|
+
const injection = `
|
|
7254
|
+
var __g =
|
|
7255
|
+
typeof globalThis !== 'undefined' ? globalThis :
|
|
7256
|
+
typeof self !== 'undefined' ? self :
|
|
7257
|
+
typeof window !== 'undefined' ? window :
|
|
7258
|
+
typeof global !== 'undefined' ? global :
|
|
7259
|
+
Function('return this')();
|
|
7260
|
+
|
|
7261
|
+
__g[Symbol.for('${PAGE_META}')] = ${JSON.stringify(pageMap2.get(key))}
|
|
7262
|
+
`;
|
|
7263
|
+
return code.replace(scriptRegex, (match) => match + injection);
|
|
7264
|
+
}
|
|
7265
|
+
|
|
7240
7266
|
// src/index.ts
|
|
7241
7267
|
var NAME = "unplugin-mp-router-view";
|
|
7242
7268
|
var unpluginFactory = (options) => {
|
|
7243
7269
|
var _a2, _b2;
|
|
7244
7270
|
const log2 = (_a2 = options == null ? void 0 : options.log) != null ? _a2 : "error";
|
|
7245
|
-
const entryPages = getPages((_b2 = options == null ? void 0 : options.collect) != null ? _b2 : true);
|
|
7271
|
+
const { entryList: entryPages, pageMap: pageMap2 } = getPages((_b2 = options == null ? void 0 : options.collect) != null ? _b2 : true);
|
|
7246
7272
|
return {
|
|
7247
7273
|
name: NAME,
|
|
7248
7274
|
enforce: "pre",
|
|
7249
7275
|
transformInclude(id) {
|
|
7250
|
-
const _id =
|
|
7276
|
+
const _id = import_node_path5.default.resolve(id);
|
|
7251
7277
|
return isAppVue(_id) || isEntryPage(_id, entryPages);
|
|
7252
7278
|
},
|
|
7253
7279
|
transform(code, id) {
|
|
7254
|
-
|
|
7280
|
+
let res = transform(import_node_path5.default.resolve(id), code, entryPages, log2);
|
|
7281
|
+
if (options == null ? void 0 : options.inject) {
|
|
7282
|
+
res = injectPageMeta(code, id, pageMap2);
|
|
7283
|
+
}
|
|
7255
7284
|
return res;
|
|
7256
7285
|
}
|
|
7257
7286
|
};
|
package/dist/index.js
CHANGED
package/dist/loader.cjs
CHANGED
|
@@ -67,15 +67,41 @@ module.exports = __toCommonJS(loader_exports);
|
|
|
67
67
|
|
|
68
68
|
// src/util/parse.ts
|
|
69
69
|
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
70
|
-
var
|
|
70
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
71
71
|
var import_jsonc_parser = require("jsonc-parser");
|
|
72
72
|
|
|
73
73
|
// src/util/error.ts
|
|
74
74
|
var import_colors = __toESM(require("colors"), 1);
|
|
75
75
|
|
|
76
76
|
// src/index.ts
|
|
77
|
-
var
|
|
77
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
78
78
|
var import_unplugin = require("unplugin");
|
|
79
|
+
|
|
80
|
+
// src/util/pagemeta.ts
|
|
81
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
82
|
+
|
|
83
|
+
// src/util/constant.ts
|
|
84
|
+
var PAGE_META = "$$__PageMeta";
|
|
85
|
+
|
|
86
|
+
// src/util/pagemeta.ts
|
|
87
|
+
var scriptRegex = /<script\b[^>]*>/;
|
|
88
|
+
function injectPageMeta(code, id, pageMap2) {
|
|
89
|
+
const ext = import_node_path.default.extname(id);
|
|
90
|
+
const key = id.replace(new RegExp(`${ext}$`), "");
|
|
91
|
+
const injection = `
|
|
92
|
+
var __g =
|
|
93
|
+
typeof globalThis !== 'undefined' ? globalThis :
|
|
94
|
+
typeof self !== 'undefined' ? self :
|
|
95
|
+
typeof window !== 'undefined' ? window :
|
|
96
|
+
typeof global !== 'undefined' ? global :
|
|
97
|
+
Function('return this')();
|
|
98
|
+
|
|
99
|
+
__g[Symbol.for('${PAGE_META}')] = ${JSON.stringify(pageMap2.get(key))}
|
|
100
|
+
`;
|
|
101
|
+
return code.replace(scriptRegex, (match) => match + injection);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/index.ts
|
|
79
105
|
var NAME = "unplugin-mp-router-view";
|
|
80
106
|
|
|
81
107
|
// src/util/error.ts
|
|
@@ -100,9 +126,9 @@ function log(msg, level) {
|
|
|
100
126
|
|
|
101
127
|
// src/util/filter.ts
|
|
102
128
|
var import_compiler_sfc = require("@vue/compiler-sfc");
|
|
103
|
-
var
|
|
129
|
+
var path3 = __toESM(require("path"), 1);
|
|
104
130
|
function isAppVue(id) {
|
|
105
|
-
const target = process.env.UNI_INPUT_DIR ?
|
|
131
|
+
const target = process.env.UNI_INPUT_DIR ? path3.resolve(process.env.UNI_INPUT_DIR, "App.vue") : path3.resolve(process.cwd(), "src", "App.vue");
|
|
106
132
|
if (id === target) {
|
|
107
133
|
console.log("isAppVue", id, target);
|
|
108
134
|
}
|
|
@@ -151,7 +177,7 @@ function countRouterView(code) {
|
|
|
151
177
|
}
|
|
152
178
|
|
|
153
179
|
// ../../node_modules/.pnpm/local-pkg@0.5.0/node_modules/local-pkg/dist/index.mjs
|
|
154
|
-
var
|
|
180
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
155
181
|
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
156
182
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
157
183
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
@@ -5593,17 +5619,17 @@ function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
|
5593
5619
|
if (hasTrailingSlash(input, true)) {
|
|
5594
5620
|
return input || "/";
|
|
5595
5621
|
}
|
|
5596
|
-
let
|
|
5622
|
+
let path8 = input;
|
|
5597
5623
|
let fragment = "";
|
|
5598
5624
|
const fragmentIndex = input.indexOf("#");
|
|
5599
5625
|
if (fragmentIndex >= 0) {
|
|
5600
|
-
|
|
5626
|
+
path8 = input.slice(0, fragmentIndex);
|
|
5601
5627
|
fragment = input.slice(fragmentIndex);
|
|
5602
|
-
if (!
|
|
5628
|
+
if (!path8) {
|
|
5603
5629
|
return fragment;
|
|
5604
5630
|
}
|
|
5605
5631
|
}
|
|
5606
|
-
const [s0, ...s] =
|
|
5632
|
+
const [s0, ...s] = path8.split("?");
|
|
5607
5633
|
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
|
|
5608
5634
|
}
|
|
5609
5635
|
function isNonEmptyURL(url) {
|
|
@@ -5633,12 +5659,12 @@ var isAbsolute = function(p) {
|
|
|
5633
5659
|
var import_node_url = require("url");
|
|
5634
5660
|
var import_node_assert = __toESM(require("assert"), 1);
|
|
5635
5661
|
var import_node_process = __toESM(require("process"), 1);
|
|
5636
|
-
var
|
|
5662
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
5637
5663
|
var import_node_v8 = __toESM(require("v8"), 1);
|
|
5638
5664
|
var import_node_util = require("util");
|
|
5639
5665
|
var BUILTIN_MODULES = new Set(import_node_module.builtinModules);
|
|
5640
|
-
function normalizeSlash(
|
|
5641
|
-
return
|
|
5666
|
+
function normalizeSlash(path8) {
|
|
5667
|
+
return path8.replace(/\\/g, "/");
|
|
5642
5668
|
}
|
|
5643
5669
|
var own$1 = {}.hasOwnProperty;
|
|
5644
5670
|
var classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
@@ -5754,8 +5780,8 @@ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
|
5754
5780
|
* @param {string} [base]
|
|
5755
5781
|
* @param {string} [message]
|
|
5756
5782
|
*/
|
|
5757
|
-
(
|
|
5758
|
-
return `Invalid package config ${
|
|
5783
|
+
(path8, base, message) => {
|
|
5784
|
+
return `Invalid package config ${path8}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
|
|
5759
5785
|
},
|
|
5760
5786
|
Error
|
|
5761
5787
|
);
|
|
@@ -5787,8 +5813,8 @@ codes.ERR_MODULE_NOT_FOUND = createError(
|
|
|
5787
5813
|
* @param {string} base
|
|
5788
5814
|
* @param {boolean} [exactUrl]
|
|
5789
5815
|
*/
|
|
5790
|
-
(
|
|
5791
|
-
return `Cannot find ${exactUrl ? "module" : "package"} '${
|
|
5816
|
+
(path8, base, exactUrl = false) => {
|
|
5817
|
+
return `Cannot find ${exactUrl ? "module" : "package"} '${path8}' imported from ${base}`;
|
|
5792
5818
|
},
|
|
5793
5819
|
Error
|
|
5794
5820
|
);
|
|
@@ -5839,8 +5865,8 @@ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
|
5839
5865
|
* @param {string} extension
|
|
5840
5866
|
* @param {string} path
|
|
5841
5867
|
*/
|
|
5842
|
-
(extension,
|
|
5843
|
-
return `Unknown file extension "${extension}" for ${
|
|
5868
|
+
(extension, path8) => {
|
|
5869
|
+
return `Unknown file extension "${extension}" for ${path8}`;
|
|
5844
5870
|
},
|
|
5845
5871
|
TypeError
|
|
5846
5872
|
);
|
|
@@ -5990,7 +6016,7 @@ function read(jsonPath, { base, specifier }) {
|
|
|
5990
6016
|
}
|
|
5991
6017
|
let string;
|
|
5992
6018
|
try {
|
|
5993
|
-
string = import_node_fs.default.readFileSync(
|
|
6019
|
+
string = import_node_fs.default.readFileSync(import_node_path3.default.toNamespacedPath(jsonPath), "utf8");
|
|
5994
6020
|
} catch (error2) {
|
|
5995
6021
|
const exception = (
|
|
5996
6022
|
/** @type {ErrnoException} */
|
|
@@ -6209,7 +6235,7 @@ Default "index" lookups for the main are deprecated for ES modules.`,
|
|
|
6209
6235
|
"DeprecationWarning",
|
|
6210
6236
|
"DEP0151"
|
|
6211
6237
|
);
|
|
6212
|
-
} else if (
|
|
6238
|
+
} else if (import_node_path3.default.resolve(packagePath, main) !== urlPath) {
|
|
6213
6239
|
import_node_process.default.emitWarning(
|
|
6214
6240
|
`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(
|
|
6215
6241
|
packagePath.length
|
|
@@ -6220,9 +6246,9 @@ Default "index" lookups for the main are deprecated for ES modules.`,
|
|
|
6220
6246
|
);
|
|
6221
6247
|
}
|
|
6222
6248
|
}
|
|
6223
|
-
function tryStatSync(
|
|
6249
|
+
function tryStatSync(path8) {
|
|
6224
6250
|
try {
|
|
6225
|
-
return (0, import_node_fs.statSync)(
|
|
6251
|
+
return (0, import_node_fs.statSync)(path8);
|
|
6226
6252
|
} catch (e) {
|
|
6227
6253
|
}
|
|
6228
6254
|
}
|
|
@@ -6319,7 +6345,7 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
|
|
|
6319
6345
|
if (!preserveSymlinks) {
|
|
6320
6346
|
const real = (0, import_node_fs.realpathSync)(filePath);
|
|
6321
6347
|
const { search, hash } = resolved;
|
|
6322
|
-
resolved = (0, import_node_url.pathToFileURL)(real + (filePath.endsWith(
|
|
6348
|
+
resolved = (0, import_node_url.pathToFileURL)(real + (filePath.endsWith(import_node_path3.default.sep) ? "/" : ""));
|
|
6323
6349
|
resolved.search = search;
|
|
6324
6350
|
resolved.hash = hash;
|
|
6325
6351
|
}
|
|
@@ -7077,14 +7103,14 @@ _head = new WeakMap();
|
|
|
7077
7103
|
_tail = new WeakMap();
|
|
7078
7104
|
_size = new WeakMap();
|
|
7079
7105
|
var findUpStop = Symbol("findUpStop");
|
|
7080
|
-
function _resolve2(
|
|
7106
|
+
function _resolve2(path8, options = {}) {
|
|
7081
7107
|
if (options.platform === "auto" || !options.platform)
|
|
7082
7108
|
options.platform = import_node_process2.default.platform === "win32" ? "win32" : "posix";
|
|
7083
|
-
const modulePath = resolvePathSync(
|
|
7109
|
+
const modulePath = resolvePathSync(path8, {
|
|
7084
7110
|
url: options.paths
|
|
7085
7111
|
});
|
|
7086
7112
|
if (options.platform === "win32")
|
|
7087
|
-
return
|
|
7113
|
+
return import_node_path4.win32.normalize(modulePath);
|
|
7088
7114
|
return modulePath;
|
|
7089
7115
|
}
|
|
7090
7116
|
function getPackageJsonPath(name, options = {}) {
|
|
@@ -7101,7 +7127,7 @@ function getPackageInfoSync(name, options = {}) {
|
|
|
7101
7127
|
return {
|
|
7102
7128
|
name,
|
|
7103
7129
|
version: packageJson.version,
|
|
7104
|
-
rootPath: (0,
|
|
7130
|
+
rootPath: (0, import_node_path4.dirname)(packageJsonPath),
|
|
7105
7131
|
packageJsonPath,
|
|
7106
7132
|
packageJson
|
|
7107
7133
|
};
|
|
@@ -7124,11 +7150,11 @@ function searchPackageJSON(dir) {
|
|
|
7124
7150
|
while (true) {
|
|
7125
7151
|
if (!dir)
|
|
7126
7152
|
return;
|
|
7127
|
-
const newDir = (0,
|
|
7153
|
+
const newDir = (0, import_node_path4.dirname)(dir);
|
|
7128
7154
|
if (newDir === dir)
|
|
7129
7155
|
return;
|
|
7130
7156
|
dir = newDir;
|
|
7131
|
-
packageJsonPath = (0,
|
|
7157
|
+
packageJsonPath = (0, import_node_path4.join)(dir, "package.json");
|
|
7132
7158
|
if (import_node_fs2.default.existsSync(packageJsonPath))
|
|
7133
7159
|
break;
|
|
7134
7160
|
}
|
|
@@ -7181,12 +7207,13 @@ function addToHeader(code, header2) {
|
|
|
7181
7207
|
function addToFooter(code, footer2) {
|
|
7182
7208
|
return code.replace(/(\s*)(<\/template>)(?!(([\s\S]*)(<\/template>)))/, (p) => footer2 + p);
|
|
7183
7209
|
}
|
|
7210
|
+
var pageMap = /* @__PURE__ */ new Map();
|
|
7184
7211
|
function getPages(collectMode) {
|
|
7185
|
-
const jsonStr = import_node_fs3.default.readFileSync(
|
|
7212
|
+
const jsonStr = import_node_fs3.default.readFileSync(import_node_path5.default.resolve(INPUT_DIR, "pages.json"), "utf-8");
|
|
7186
7213
|
const pagesJson = parseJson(jsonStr);
|
|
7187
7214
|
const { pages, subPackages = [] } = pagesJson;
|
|
7188
7215
|
const entryList = [...collectEntry(collectMode, pages), ...collectEntry(collectMode, subPackages)];
|
|
7189
|
-
return entryList;
|
|
7216
|
+
return { entryList, pageMap };
|
|
7190
7217
|
}
|
|
7191
7218
|
function collectEntry(collectMode, json, root = "") {
|
|
7192
7219
|
const entryList = [];
|
|
@@ -7198,7 +7225,8 @@ function collectEntry(collectMode, json, root = "") {
|
|
|
7198
7225
|
if (!collectMode) {
|
|
7199
7226
|
return;
|
|
7200
7227
|
}
|
|
7201
|
-
const _path =
|
|
7228
|
+
const _path = import_node_path5.default.resolve(INPUT_DIR, `${root}${root ? "/" : ""}${item.path}`);
|
|
7229
|
+
pageMap.set(_path, item);
|
|
7202
7230
|
if (collectMode && typeof collectMode === "boolean" && !item["ROUTER_VIEW_EXCLUDE"]) {
|
|
7203
7231
|
entryList.push(_path);
|
|
7204
7232
|
} else if (typeof collectMode === "string" && item[collectMode]) {
|
|
@@ -7218,9 +7246,9 @@ function combineCode(code, header2, footer2) {
|
|
|
7218
7246
|
code = addToFooter(code, footer2);
|
|
7219
7247
|
return code;
|
|
7220
7248
|
}
|
|
7221
|
-
function transform(
|
|
7249
|
+
function transform(path8, code, entryPages, level) {
|
|
7222
7250
|
logLevel = level;
|
|
7223
|
-
if (isAppVue(
|
|
7251
|
+
if (isAppVue(path8)) {
|
|
7224
7252
|
log(`\u57FA\u4E8E\u5E73\u53F0${process.env.UNI_PLATFORM}, \u5904\u7406App.vue...`, logLevel);
|
|
7225
7253
|
const { origin, tpl } = getTemplate(code);
|
|
7226
7254
|
const { count, before, after } = countRouterView(tpl);
|
|
@@ -7232,8 +7260,8 @@ function transform(path7, code, entryPages, level) {
|
|
|
7232
7260
|
header = before;
|
|
7233
7261
|
footer = after;
|
|
7234
7262
|
return origin;
|
|
7235
|
-
} else if (isEntryPage(
|
|
7236
|
-
log(`\u5904\u7406 ${
|
|
7263
|
+
} else if (isEntryPage(path8, entryPages)) {
|
|
7264
|
+
log(`\u5904\u7406 ${path8} ...`, logLevel);
|
|
7237
7265
|
code = combineCode(code, header, footer);
|
|
7238
7266
|
}
|
|
7239
7267
|
return code;
|
|
@@ -7241,12 +7269,15 @@ function transform(path7, code, entryPages, level) {
|
|
|
7241
7269
|
|
|
7242
7270
|
// src/loader.ts
|
|
7243
7271
|
function loader_default(source) {
|
|
7244
|
-
const { log: logConfig, collect } = this.query || {};
|
|
7272
|
+
const { log: logConfig, collect, inject } = this.query || {};
|
|
7245
7273
|
const log2 = logConfig || "error";
|
|
7246
|
-
const entryPages = getPages(collect != null ? collect : true);
|
|
7247
|
-
const
|
|
7248
|
-
if (isAppVue(
|
|
7249
|
-
source = transform(
|
|
7274
|
+
const { entryList: entryPages, pageMap: pageMap2 } = getPages(collect != null ? collect : true);
|
|
7275
|
+
const path8 = this.resourcePath;
|
|
7276
|
+
if (isAppVue(path8) || isEntryPage(path8, entryPages)) {
|
|
7277
|
+
source = transform(path8, source, entryPages, log2);
|
|
7278
|
+
if (inject) {
|
|
7279
|
+
source = injectPageMeta(source, path8, pageMap2);
|
|
7280
|
+
}
|
|
7250
7281
|
}
|
|
7251
7282
|
return source;
|
|
7252
7283
|
}
|
package/dist/loader.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getPages,
|
|
3
|
+
injectPageMeta,
|
|
3
4
|
isAppVue,
|
|
4
5
|
isEntryPage,
|
|
5
6
|
transform
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-34IBKFGI.js";
|
|
8
|
+
import "./chunk-M3QQKYK3.js";
|
|
7
9
|
|
|
8
10
|
// src/loader.ts
|
|
9
11
|
function loader_default(source) {
|
|
10
|
-
const { log: logConfig, collect } = this.query || {};
|
|
12
|
+
const { log: logConfig, collect, inject } = this.query || {};
|
|
11
13
|
const log = logConfig || "error";
|
|
12
|
-
const entryPages = getPages(collect != null ? collect : true);
|
|
14
|
+
const { entryList: entryPages, pageMap } = getPages(collect != null ? collect : true);
|
|
13
15
|
const path = this.resourcePath;
|
|
14
16
|
if (isAppVue(path) || isEntryPage(path, entryPages)) {
|
|
15
17
|
source = transform(path, source, entryPages, log);
|
|
18
|
+
if (inject) {
|
|
19
|
+
source = injectPageMeta(source, path, pageMap);
|
|
20
|
+
}
|
|
16
21
|
}
|
|
17
22
|
return source;
|
|
18
23
|
}
|