@mpxjs/webpack-plugin 2.6.114-alpha.8 → 2.6.114-alpha.9
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/lib/tenon/processJSON.js
CHANGED
|
@@ -3,7 +3,7 @@ const path = require('path')
|
|
|
3
3
|
const JSON5 = require('json5')
|
|
4
4
|
const loaderUtils = require('loader-utils')
|
|
5
5
|
const parseRequest = require('../utils/parse-request')
|
|
6
|
-
const toPosix = require('../utils/to-posix')
|
|
6
|
+
// const toPosix = require('../utils/to-posix')
|
|
7
7
|
const addQuery = require('../utils/add-query')
|
|
8
8
|
const parseComponent = require('../parser')
|
|
9
9
|
const getJSONContent = require('../utils/get-json-content')
|
|
@@ -15,7 +15,7 @@ module.exports = function (json, options, rawCallback) {
|
|
|
15
15
|
const defs = options.defs
|
|
16
16
|
const loaderContext = options.loaderContext
|
|
17
17
|
const resolveMode = options.resolveMode
|
|
18
|
-
const pagesMap = options.pagesMap
|
|
18
|
+
// const pagesMap = options.pagesMap
|
|
19
19
|
const componentsMap = options.componentsMap
|
|
20
20
|
const projectRoot = options.projectRoot
|
|
21
21
|
const pathHash = options.pathHash
|
|
@@ -29,17 +29,17 @@ module.exports = function (json, options, rawCallback) {
|
|
|
29
29
|
let tabBarStr
|
|
30
30
|
const context = loaderContext.context
|
|
31
31
|
|
|
32
|
-
const emitWarning = (msg) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
32
|
+
// const emitWarning = (msg) => {
|
|
33
|
+
// loaderContext.emitWarning(
|
|
34
|
+
// new Error('[json processor][' + loaderContext.resource + ']: ' + msg)
|
|
35
|
+
// )
|
|
36
|
+
// }
|
|
37
37
|
|
|
38
|
-
const emitError = (msg) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
38
|
+
// const emitError = (msg) => {
|
|
39
|
+
// this.emitError(
|
|
40
|
+
// new Error('[json compiler][' + this.resource + ']: ' + msg)
|
|
41
|
+
// )
|
|
42
|
+
// }
|
|
43
43
|
|
|
44
44
|
// const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
|
|
45
45
|
|
|
@@ -186,73 +186,69 @@ module.exports = function (json, options, rawCallback) {
|
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
const getPageName = (resourcePath, ext) => {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
189
|
+
// const getPageName = (resourcePath, ext) => {
|
|
190
|
+
// const baseName = path.basename(resourcePath, ext)
|
|
191
|
+
// return path.join('pages', baseName + pathHash(resourcePath), baseName)
|
|
192
|
+
// }
|
|
193
193
|
|
|
194
194
|
const processPages = (pages, srcRoot = '', tarRoot = '', context, callback) => {
|
|
195
195
|
if (pages) {
|
|
196
196
|
context = path.join(context, srcRoot)
|
|
197
197
|
async.forEach(pages, (page, callback) => {
|
|
198
|
-
let
|
|
198
|
+
let pagePath = page
|
|
199
199
|
if (typeof page !== 'string') {
|
|
200
|
-
|
|
201
|
-
page = page.src
|
|
200
|
+
pagePath = page.src
|
|
202
201
|
}
|
|
203
|
-
if (!isUrlRequest(page, projectRoot)) return callback()
|
|
204
|
-
if (resolveMode === 'native') {
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
resolve(context, page, (err, resource) => {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
callback()
|
|
255
|
-
})
|
|
202
|
+
// if (!isUrlRequest(page, projectRoot)) return callback()
|
|
203
|
+
// if (resolveMode === 'native') {
|
|
204
|
+
// page = loaderUtils.urlToRequest(page, projectRoot)
|
|
205
|
+
// }
|
|
206
|
+
// resolve(context, page, (err, resource) => {
|
|
207
|
+
// if (err) return callback(err)
|
|
208
|
+
// const { resourcePath, queryObj } = parseRequest(resource)
|
|
209
|
+
// const ext = path.extname(resourcePath)
|
|
210
|
+
// // 获取pageName
|
|
211
|
+
// let pageName
|
|
212
|
+
// if (aliasPath) {
|
|
213
|
+
// pageName = toPosix(path.join(tarRoot, aliasPath))
|
|
214
|
+
// // 判断 key 存在重复情况直接报错
|
|
215
|
+
// for (let key in pagesMap) {
|
|
216
|
+
// if (pagesMap[key] === pageName && key !== resourcePath) {
|
|
217
|
+
// emitError(`Current page [${resourcePath}] registers a conflict page path [${pageName}] with existed page [${key}], which is not allowed, please rename it!`)
|
|
218
|
+
// return callback()
|
|
219
|
+
// }
|
|
220
|
+
// }
|
|
221
|
+
// } else {
|
|
222
|
+
// const relative = path.relative(context, resourcePath)
|
|
223
|
+
// if (/^\./.test(relative)) {
|
|
224
|
+
// // 如果当前page不存在于context中,对其进行重命名
|
|
225
|
+
// pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
|
|
226
|
+
// emitWarning(`Current page [${resourcePath}] is not in current pages directory [${context}], the page path will be replaced with [${pageName}], use ?resolve to get the page path and navigate to it!`)
|
|
227
|
+
// } else {
|
|
228
|
+
// pageName = toPosix(path.join(tarRoot, /^(.*?)(\.[^.]*)?$/.exec(relative)[1]))
|
|
229
|
+
// // 如果当前page与已有page存在命名冲突,也进行重命名
|
|
230
|
+
// for (let key in pagesMap) {
|
|
231
|
+
// // 此处引入pagesMap确保相同entry下路由路径重复注册才报错,不同entry下的路由路径重复则无影响
|
|
232
|
+
// if (pagesMap[key] === pageName && key !== resourcePath && pagesMap[key] === loaderContext.resourcePath) {
|
|
233
|
+
// const pageNameRaw = pageName
|
|
234
|
+
// pageName = toPosix(path.join(tarRoot, getPageName(resourcePath, ext)))
|
|
235
|
+
// emitWarning(`Current page [${resourcePath}] is registered with a conflict page path [${pageNameRaw}] which is already existed in system, the page path will be replaced with [${pageName}], use ?resolve to get the page path and navigate to it!`)
|
|
236
|
+
// break
|
|
237
|
+
// }
|
|
238
|
+
// }
|
|
239
|
+
// }
|
|
240
|
+
// }
|
|
241
|
+
// if (pagesMap[resourcePath]) {
|
|
242
|
+
// emitWarning(`Current page [${resourcePath}] which is imported from [${loaderContext.resourcePath}] has been registered in pagesMap already, it will be ignored, please check it and remove the redundant page declaration!`)
|
|
243
|
+
// return callback()
|
|
244
|
+
// }
|
|
245
|
+
// buildInfo.pagesMap = buildInfo.pagesMap || {}
|
|
246
|
+
// buildInfo.pagesMap[resourcePath] = pagesMap[resourcePath] = pageName
|
|
247
|
+
// pagesMap[resourcePath] = loaderContext.resourcePath
|
|
248
|
+
localPagesMap[pagePath] = page
|
|
249
|
+
// callback()
|
|
250
|
+
// })
|
|
251
|
+
callback()
|
|
256
252
|
}, callback)
|
|
257
253
|
} else {
|
|
258
254
|
callback()
|
|
@@ -244,7 +244,8 @@ module.exports = function (script, options, callback) {
|
|
|
244
244
|
const pageSet = new Set()
|
|
245
245
|
let dynamicPageStr = ''
|
|
246
246
|
async.each(localPagesMap, (pageCfg, callback) => {
|
|
247
|
-
|
|
247
|
+
if (typeof pageCfg !== 'string') pageCfg.src = addQuery(pageCfg.src, { tenon: true })
|
|
248
|
+
processPage(pageCfg, loaderContext.context, '', (err, entry, { key }) => {
|
|
248
249
|
if (err) return callback()
|
|
249
250
|
if (pageSet.has(key)) return callback()
|
|
250
251
|
pageSet.add(key)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
function getRelativePath (source, target) {
|
|
2
|
-
source = source && source.replace(/\/[^/]*$/, ''); // get dirname
|
|
3
2
|
// make sure source and target are absolute path
|
|
4
3
|
/^\//.test(source) || (source = '/' + source);
|
|
5
4
|
/^\//.test(target) || (target = '/' + target)
|
|
5
|
+
|
|
6
|
+
source = source && source.replace(/\/[^/]*$/, '') // get dirname
|
|
6
7
|
// check if source or target is root path
|
|
7
8
|
let sourceArr = source.split('/').filter((item, index) => index !== 0 && !!item)
|
|
8
9
|
let targetArr = target.split('/').filter((item, index) => index !== 0 && !!item)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.6.114-alpha.
|
|
3
|
+
"version": "2.6.114-alpha.9",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"engines": {
|
|
84
84
|
"node": ">=14.14.0"
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "0db2ebdd83d4676e043a68415345dcaa8ae91a54"
|
|
87
87
|
}
|