From 450d34aa35eb28ea0d718e6ad1dc013ebcd0d494 Mon Sep 17 00:00:00 2001 From: "elvira.zy" Date: Wed, 8 Apr 2020 21:17:47 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20Cube.use=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=8F=82=E6=95=B0=20=3Fm=3D1&env=3D2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- runtime/cube.js | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9416b6e..1380d62 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "fish (https://github.com/fishbar)", "name": "node-cube", "description": "a new way to write js in browser", - "version": "3.1.17-beta.2", + "version": "3.1.18", "homepage": "https://github.com/fishbar/cube", "repository": { "type": "git", diff --git a/runtime/cube.js b/runtime/cube.js index b68c04c..abb310d 100644 --- a/runtime/cube.js +++ b/runtime/cube.js @@ -131,7 +131,7 @@ * @param requires * @param referer */ - function load(requires, referer) { + function load(requires, referer, customArgs) { if (typeof requires === 'string') { requires = [requires]; } @@ -165,6 +165,11 @@ q.push('m'); q.push('ref=' + referer); } + if (customArgs) { + Array.prototype.push.apply(q, Object.keys(customArgs).map(c => { + return `${c}=${customArgs[c]}` + })); + } if (q.length) { script.src = srcPath + '?' + q.join('&'); @@ -335,8 +340,11 @@ } cb = cb || noop; + let customArgs; if (typeof mods === 'string') { - mods = [mods]; + const arr = mods.split('?'); + mods = [arr[0]]; + customArgs = parseQueryString(arr[1]); } if (!noFix) { mods = fixUseModPath(mods); @@ -363,7 +371,7 @@ }; }()); - load(mods, referer); + load(mods, referer, customArgs); return this; }; /** @@ -477,4 +485,14 @@ Cube.use(cfg.main || 'index.js', function(app){app.run&& app.run();}); } } + + function parseQueryString(param) { + var regExp = /([^&=]+)=([\w\W]*?)(&|$)/g; + var ret = {}; + + while ((result = regExp.exec(param)) != null) { + ret[result[1]] = result[2]; + } + return ret; + } })(window, null); From cfdd8fcf6ecdc604f483635c2a4aaf99ca25e1ea Mon Sep 17 00:00:00 2001 From: "elvira.zy" Date: Thu, 9 Apr 2020 11:37:05 +0800 Subject: [PATCH 2/8] =?UTF-8?q?fix:=20=E6=8A=8A=E5=85=A5=E5=8F=82=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E7=A7=BB=E5=85=A5=20load=20=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/cube.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/runtime/cube.js b/runtime/cube.js index abb310d..a0517bf 100644 --- a/runtime/cube.js +++ b/runtime/cube.js @@ -131,7 +131,7 @@ * @param requires * @param referer */ - function load(requires, referer, customArgs) { + function load(requires, referer) { if (typeof requires === 'string') { requires = [requires]; } @@ -157,6 +157,12 @@ var rebaseName = reBase(require); var srcPath = rebaseName || (base + require); + + // 解析入参 + const urlArr = srcPath.split('?'); + srcPath = urlArr[0]; + const customArgs = parseQueryString(urlArr[1]); + var q = []; if (version) { q.push(version); @@ -165,7 +171,7 @@ q.push('m'); q.push('ref=' + referer); } - if (customArgs) { + if (!!urlArr[1] && customArgs) { Array.prototype.push.apply(q, Object.keys(customArgs).map(c => { return `${c}=${customArgs[c]}` })); @@ -340,12 +346,10 @@ } cb = cb || noop; - let customArgs; if (typeof mods === 'string') { - const arr = mods.split('?'); - mods = [arr[0]]; - customArgs = parseQueryString(arr[1]); + mods = [mods]; } + if (!noFix) { mods = fixUseModPath(mods); } @@ -371,7 +375,7 @@ }; }()); - load(mods, referer, customArgs); + load(mods, referer); return this; }; /** From b7293a17d09d0a38675e52a9b9b1d248b275c32a Mon Sep 17 00:00:00 2001 From: "elvira.zy" Date: Thu, 9 Apr 2020 12:15:48 +0800 Subject: [PATCH 3/8] =?UTF-8?q?fix:=20=E8=A7=A3=E6=9E=90=E5=85=A5=E5=8F=82?= =?UTF-8?q?=E7=A7=BB=E5=88=B0=20Cube.use=20=E4=B8=AD=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=20fireModule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/cube.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/runtime/cube.js b/runtime/cube.js index a0517bf..fedf34c 100644 --- a/runtime/cube.js +++ b/runtime/cube.js @@ -131,7 +131,7 @@ * @param requires * @param referer */ - function load(requires, referer) { + function load(requires, referer, customArgs = {}) { if (typeof requires === 'string') { requires = [requires]; } @@ -158,11 +158,6 @@ var rebaseName = reBase(require); var srcPath = rebaseName || (base + require); - // 解析入参 - const urlArr = srcPath.split('?'); - srcPath = urlArr[0]; - const customArgs = parseQueryString(urlArr[1]); - var q = []; if (version) { q.push(version); @@ -171,9 +166,9 @@ q.push('m'); q.push('ref=' + referer); } - if (!!urlArr[1] && customArgs) { - Array.prototype.push.apply(q, Object.keys(customArgs).map(c => { - return `${c}=${customArgs[c]}` + if (customArgs[require]) { + Array.prototype.push.apply(q, Object.keys(customArgs[require]).map(c => { + return `${c}=${customArgs[require][c]}` })); } @@ -350,6 +345,13 @@ mods = [mods]; } + let customArgs = {}; + mods = mods.map(m => { + const [ mod, custom ] = m.split('?'); + customArgs[mod] = parseQueryString(custom); + return mod; + }); + if (!noFix) { mods = fixUseModPath(mods); } @@ -375,7 +377,7 @@ }; }()); - load(mods, referer); + load(mods, referer, customArgs); return this; }; /** From 07fbad1adcce5848691109d489e2c809b1eccaef Mon Sep 17 00:00:00 2001 From: "elvira.zy" Date: Mon, 13 Apr 2020 17:02:06 +0800 Subject: [PATCH 4/8] =?UTF-8?q?fix:=20=E7=94=A8=E8=80=81=E5=86=99=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E4=BF=9D=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- runtime/cube.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 1380d62..9416b6e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "fish (https://github.com/fishbar)", "name": "node-cube", "description": "a new way to write js in browser", - "version": "3.1.18", + "version": "3.1.17-beta.2", "homepage": "https://github.com/fishbar/cube", "repository": { "type": "git", diff --git a/runtime/cube.js b/runtime/cube.js index fedf34c..7cd5d02 100644 --- a/runtime/cube.js +++ b/runtime/cube.js @@ -131,7 +131,8 @@ * @param requires * @param referer */ - function load(requires, referer, customArgs = {}) { + function load(requires, referer, customArgs) { + customArgs = customArgs || {}; if (typeof requires === 'string') { requires = [requires]; } @@ -347,7 +348,9 @@ let customArgs = {}; mods = mods.map(m => { - const [ mod, custom ] = m.split('?'); + const tmpArr = m.split('?'); + const mod = tmpArr[0]; + const custom = tmpArr[1]; customArgs[mod] = parseQueryString(custom); return mod; }); From 5b8f7c433b63972d6f64747f49c695c75946e74c Mon Sep 17 00:00:00 2001 From: "elvira.zy" Date: Mon, 13 Apr 2020 20:27:16 +0800 Subject: [PATCH 5/8] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=20parse=20=E7=9A=84=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/cube.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/cube.js b/runtime/cube.js index 7cd5d02..28a2cfd 100644 --- a/runtime/cube.js +++ b/runtime/cube.js @@ -351,7 +351,8 @@ const tmpArr = m.split('?'); const mod = tmpArr[0]; const custom = tmpArr[1]; - customArgs[mod] = parseQueryString(custom); + + if (!!custom) customArgs[mod] = parseQueryString(custom); return mod; }); From 8df182323383a1cfce523686eb7921e116a9ba25 Mon Sep 17 00:00:00 2001 From: "elvira.zy" Date: Mon, 13 Apr 2020 20:35:56 +0800 Subject: [PATCH 6/8] =?UTF-8?q?fix:=20=E4=B8=8D=E4=B8=A5=E8=B0=A8=E7=9A=84?= =?UTF-8?q?=E6=AD=A3=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/cube.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/runtime/cube.js b/runtime/cube.js index 28a2cfd..4262955 100644 --- a/runtime/cube.js +++ b/runtime/cube.js @@ -497,12 +497,12 @@ } function parseQueryString(param) { - var regExp = /([^&=]+)=([\w\W]*?)(&|$)/g; - var ret = {}; - - while ((result = regExp.exec(param)) != null) { - ret[result[1]] = result[2]; - } - return ret; + let kvs = param.split('&'); + let obj = {}; + kvs.forEach((kv) => { + let tmp = kv.split('='); + obj[tmp[0]] = obj[tmp[1]]; + }); + return obj; } })(window, null); From 654fb64413ad8bdc68a4726d2fcf1307f273a038 Mon Sep 17 00:00:00 2001 From: "elvira.zy" Date: Tue, 14 Apr 2020 10:29:15 +0800 Subject: [PATCH 7/8] =?UTF-8?q?fix:=20=E7=BC=A9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/cube.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/cube.js b/runtime/cube.js index 4262955..bf3cbdb 100644 --- a/runtime/cube.js +++ b/runtime/cube.js @@ -502,7 +502,7 @@ kvs.forEach((kv) => { let tmp = kv.split('='); obj[tmp[0]] = obj[tmp[1]]; - }); + }); return obj; } })(window, null); From f1153e19bdc11ba8e7a131fcd2c00a5ac8247a0f Mon Sep 17 00:00:00 2001 From: "elvira.zy" Date: Tue, 14 Apr 2020 11:39:55 +0800 Subject: [PATCH 8/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20querystring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/cube.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/cube.js b/runtime/cube.js index bf3cbdb..b89f12e 100644 --- a/runtime/cube.js +++ b/runtime/cube.js @@ -501,7 +501,7 @@ let obj = {}; kvs.forEach((kv) => { let tmp = kv.split('='); - obj[tmp[0]] = obj[tmp[1]]; + obj[tmp[0]] = tmp[1]; }); return obj; }