piral-core 1.6.1 → 1.6.2-beta.7393
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/codegen.js +170 -112
- package/lib/utils/routes.js +100 -2
- package/lib/utils/routes.js.map +1 -1
- package/package.json +4 -5
- package/src/utils/routes.ts +132 -2
package/lib/codegen.js
CHANGED
|
@@ -865,13 +865,13 @@ var require_CachedInputFileSystem = __commonJS({
|
|
|
865
865
|
callback = options;
|
|
866
866
|
options = void 0;
|
|
867
867
|
}
|
|
868
|
+
if (typeof path !== "string" && !Buffer.isBuffer(path) && !(path instanceof URL) && typeof path !== "number") {
|
|
869
|
+
callback(new TypeError("path must be a string, Buffer, URL or number"));
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
868
872
|
if (options) {
|
|
869
873
|
return this._provider.call(this._providerContext, path, options, callback);
|
|
870
874
|
}
|
|
871
|
-
if (typeof path !== "string") {
|
|
872
|
-
callback(new TypeError("path must be a string"));
|
|
873
|
-
return;
|
|
874
|
-
}
|
|
875
875
|
let callbacks = this._activeAsyncOperations.get(path);
|
|
876
876
|
if (callbacks) {
|
|
877
877
|
callbacks.push(callback);
|
|
@@ -921,68 +921,70 @@ var require_CachedInputFileSystem = __commonJS({
|
|
|
921
921
|
callback = options;
|
|
922
922
|
options = void 0;
|
|
923
923
|
}
|
|
924
|
-
if (typeof path !== "string") {
|
|
925
|
-
callback(new TypeError("path must be a string"));
|
|
924
|
+
if (typeof path !== "string" && !Buffer.isBuffer(path) && !(path instanceof URL) && typeof path !== "number") {
|
|
925
|
+
callback(new TypeError("path must be a string, Buffer, URL or number"));
|
|
926
926
|
return;
|
|
927
927
|
}
|
|
928
|
+
const strPath = typeof path !== "string" ? path.toString() : path;
|
|
928
929
|
if (options) {
|
|
929
930
|
return this._provider.call(this._providerContext, path, options, callback);
|
|
930
931
|
}
|
|
931
932
|
if (this._mode === STORAGE_MODE_SYNC) {
|
|
932
933
|
this._enterAsyncMode();
|
|
933
934
|
}
|
|
934
|
-
let cacheEntry = this._data.get(
|
|
935
|
+
let cacheEntry = this._data.get(strPath);
|
|
935
936
|
if (cacheEntry !== void 0) {
|
|
936
937
|
if (cacheEntry.err)
|
|
937
938
|
return nextTick(callback, cacheEntry.err);
|
|
938
939
|
return nextTick(callback, null, cacheEntry.result);
|
|
939
940
|
}
|
|
940
|
-
let callbacks = this._activeAsyncOperations.get(
|
|
941
|
+
let callbacks = this._activeAsyncOperations.get(strPath);
|
|
941
942
|
if (callbacks !== void 0) {
|
|
942
943
|
callbacks.push(callback);
|
|
943
944
|
return;
|
|
944
945
|
}
|
|
945
|
-
this._activeAsyncOperations.set(
|
|
946
|
+
this._activeAsyncOperations.set(strPath, callbacks = [callback]);
|
|
946
947
|
this._provider.call(this._providerContext, path, (err, result) => {
|
|
947
|
-
this._activeAsyncOperations.delete(
|
|
948
|
-
this._storeResult(
|
|
948
|
+
this._activeAsyncOperations.delete(strPath);
|
|
949
|
+
this._storeResult(strPath, err, result);
|
|
949
950
|
this._enterAsyncMode();
|
|
950
951
|
runCallbacks(callbacks, err, result);
|
|
951
952
|
});
|
|
952
953
|
}
|
|
953
954
|
provideSync(path, options) {
|
|
954
|
-
if (typeof path !== "string") {
|
|
955
|
+
if (typeof path !== "string" && !Buffer.isBuffer(path) && !(path instanceof URL) && typeof path !== "number") {
|
|
955
956
|
throw new TypeError("path must be a string");
|
|
956
957
|
}
|
|
958
|
+
const strPath = typeof path !== "string" ? path.toString() : path;
|
|
957
959
|
if (options) {
|
|
958
960
|
return this._syncProvider.call(this._providerContext, path, options);
|
|
959
961
|
}
|
|
960
962
|
if (this._mode === STORAGE_MODE_SYNC) {
|
|
961
963
|
this._runDecays();
|
|
962
964
|
}
|
|
963
|
-
let cacheEntry = this._data.get(
|
|
965
|
+
let cacheEntry = this._data.get(strPath);
|
|
964
966
|
if (cacheEntry !== void 0) {
|
|
965
967
|
if (cacheEntry.err)
|
|
966
968
|
throw cacheEntry.err;
|
|
967
969
|
return cacheEntry.result;
|
|
968
970
|
}
|
|
969
|
-
const callbacks = this._activeAsyncOperations.get(
|
|
970
|
-
this._activeAsyncOperations.delete(
|
|
971
|
+
const callbacks = this._activeAsyncOperations.get(strPath);
|
|
972
|
+
this._activeAsyncOperations.delete(strPath);
|
|
971
973
|
let result;
|
|
972
974
|
try {
|
|
973
975
|
result = this._syncProvider.call(this._providerContext, path);
|
|
974
976
|
} catch (err) {
|
|
975
|
-
this._storeResult(
|
|
977
|
+
this._storeResult(strPath, err, void 0);
|
|
976
978
|
this._enterSyncModeWhenIdle();
|
|
977
979
|
if (callbacks) {
|
|
978
980
|
runCallbacks(callbacks, err, void 0);
|
|
979
981
|
}
|
|
980
982
|
throw err;
|
|
981
983
|
}
|
|
982
|
-
this._storeResult(
|
|
984
|
+
this._storeResult(strPath, null, result);
|
|
983
985
|
this._enterSyncModeWhenIdle();
|
|
984
986
|
if (callbacks) {
|
|
985
|
-
runCallbacks(callbacks,
|
|
987
|
+
runCallbacks(callbacks, null, result);
|
|
986
988
|
}
|
|
987
989
|
return result;
|
|
988
990
|
}
|
|
@@ -995,9 +997,10 @@ var require_CachedInputFileSystem = __commonJS({
|
|
|
995
997
|
}
|
|
996
998
|
this._enterIdleMode();
|
|
997
999
|
}
|
|
998
|
-
} else if (typeof what === "string") {
|
|
1000
|
+
} else if (typeof what === "string" || Buffer.isBuffer(what) || what instanceof URL || typeof what === "number") {
|
|
1001
|
+
const strWhat = typeof what !== "string" ? what.toString() : what;
|
|
999
1002
|
for (let [key, data] of this._data) {
|
|
1000
|
-
if (key.startsWith(
|
|
1003
|
+
if (key.startsWith(strWhat)) {
|
|
1001
1004
|
this._data.delete(key);
|
|
1002
1005
|
data.level.delete(key);
|
|
1003
1006
|
}
|
|
@@ -1008,7 +1011,8 @@ var require_CachedInputFileSystem = __commonJS({
|
|
|
1008
1011
|
} else {
|
|
1009
1012
|
for (let [key, data] of this._data) {
|
|
1010
1013
|
for (const item of what) {
|
|
1011
|
-
|
|
1014
|
+
const strItem = typeof item !== "string" ? item.toString() : item;
|
|
1015
|
+
if (key.startsWith(strItem)) {
|
|
1012
1016
|
this._data.delete(key);
|
|
1013
1017
|
data.level.delete(key);
|
|
1014
1018
|
break;
|
|
@@ -1023,12 +1027,14 @@ var require_CachedInputFileSystem = __commonJS({
|
|
|
1023
1027
|
purgeParent(what) {
|
|
1024
1028
|
if (!what) {
|
|
1025
1029
|
this.purge();
|
|
1026
|
-
} else if (typeof what === "string") {
|
|
1027
|
-
|
|
1030
|
+
} else if (typeof what === "string" || Buffer.isBuffer(what) || what instanceof URL || typeof what === "number") {
|
|
1031
|
+
const strWhat = typeof what !== "string" ? what.toString() : what;
|
|
1032
|
+
this.purge(dirname2(strWhat));
|
|
1028
1033
|
} else {
|
|
1029
1034
|
const set = new Set();
|
|
1030
1035
|
for (const item of what) {
|
|
1031
|
-
|
|
1036
|
+
const strItem = typeof item !== "string" ? item.toString() : item;
|
|
1037
|
+
set.add(dirname2(strItem));
|
|
1032
1038
|
}
|
|
1033
1039
|
this.purge(set);
|
|
1034
1040
|
}
|
|
@@ -1154,6 +1160,11 @@ var require_CachedInputFileSystem = __commonJS({
|
|
|
1154
1160
|
this.readlink = readlink;
|
|
1155
1161
|
const readlinkSync = this._readlinkBackend.provideSync;
|
|
1156
1162
|
this.readlinkSync = readlinkSync;
|
|
1163
|
+
this._realpathBackend = createBackend(duration, this.fileSystem.realpath, this.fileSystem.realpathSync, this.fileSystem);
|
|
1164
|
+
const realpath = this._realpathBackend.provide;
|
|
1165
|
+
this.realpath = realpath;
|
|
1166
|
+
const realpathSync = this._realpathBackend.provideSync;
|
|
1167
|
+
this.realpathSync = realpathSync;
|
|
1157
1168
|
}
|
|
1158
1169
|
purge(what) {
|
|
1159
1170
|
this._statBackend.purge(what);
|
|
@@ -1162,6 +1173,7 @@ var require_CachedInputFileSystem = __commonJS({
|
|
|
1162
1173
|
this._readFileBackend.purge(what);
|
|
1163
1174
|
this._readlinkBackend.purge(what);
|
|
1164
1175
|
this._readJsonBackend.purge(what);
|
|
1176
|
+
this._realpathBackend.purge(what);
|
|
1165
1177
|
}
|
|
1166
1178
|
};
|
|
1167
1179
|
}
|
|
@@ -2413,6 +2425,10 @@ var require_path = __commonJS({
|
|
|
2413
2425
|
Internal: 5
|
|
2414
2426
|
});
|
|
2415
2427
|
exports.PathType = PathType;
|
|
2428
|
+
var invalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i;
|
|
2429
|
+
exports.invalidSegmentRegEx = invalidSegmentRegEx;
|
|
2430
|
+
var deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i;
|
|
2431
|
+
exports.deprecatedInvalidSegmentRegEx = deprecatedInvalidSegmentRegEx;
|
|
2416
2432
|
var getType = (p) => {
|
|
2417
2433
|
switch (p.length) {
|
|
2418
2434
|
case 0:
|
|
@@ -2545,30 +2561,6 @@ var require_path = __commonJS({
|
|
|
2545
2561
|
return cacheEntry;
|
|
2546
2562
|
};
|
|
2547
2563
|
exports.cachedJoin = cachedJoin;
|
|
2548
|
-
var checkImportsExportsFieldTarget = (relativePath) => {
|
|
2549
|
-
let lastNonSlashIndex = 0;
|
|
2550
|
-
let slashIndex = relativePath.indexOf("/", 1);
|
|
2551
|
-
let cd = 0;
|
|
2552
|
-
while (slashIndex !== -1) {
|
|
2553
|
-
const folder = relativePath.slice(lastNonSlashIndex, slashIndex);
|
|
2554
|
-
switch (folder) {
|
|
2555
|
-
case "..": {
|
|
2556
|
-
cd--;
|
|
2557
|
-
if (cd < 0)
|
|
2558
|
-
return new Error(`Trying to access out of package scope. Requesting ${relativePath}`);
|
|
2559
|
-
break;
|
|
2560
|
-
}
|
|
2561
|
-
case ".":
|
|
2562
|
-
break;
|
|
2563
|
-
default:
|
|
2564
|
-
cd++;
|
|
2565
|
-
break;
|
|
2566
|
-
}
|
|
2567
|
-
lastNonSlashIndex = slashIndex + 1;
|
|
2568
|
-
slashIndex = relativePath.indexOf("/", lastNonSlashIndex);
|
|
2569
|
-
}
|
|
2570
|
-
};
|
|
2571
|
-
exports.checkImportsExportsFieldTarget = checkImportsExportsFieldTarget;
|
|
2572
2564
|
}
|
|
2573
2565
|
});
|
|
2574
2566
|
|
|
@@ -2772,7 +2764,8 @@ var require_Resolver = __commonJS({
|
|
|
2772
2764
|
}
|
|
2773
2765
|
newStack.add(stackEntry);
|
|
2774
2766
|
} else {
|
|
2775
|
-
newStack = new Set(
|
|
2767
|
+
newStack = new Set();
|
|
2768
|
+
newStack.add(stackEntry);
|
|
2776
2769
|
}
|
|
2777
2770
|
this.hooks.resolveStep.call(hook, request);
|
|
2778
2771
|
if (hook.isUsed()) {
|
|
@@ -2852,7 +2845,7 @@ var require_SyncAsyncFileSystemDecorator = __commonJS({
|
|
|
2852
2845
|
this.lstat = (arg, options, callback) => {
|
|
2853
2846
|
let result;
|
|
2854
2847
|
try {
|
|
2855
|
-
result = lstatSync.call(fs2, arg);
|
|
2848
|
+
result = callback ? lstatSync.call(fs2, arg, options) : lstatSync.call(fs2, arg);
|
|
2856
2849
|
} catch (e) {
|
|
2857
2850
|
return (callback || options)(e);
|
|
2858
2851
|
}
|
|
@@ -2873,7 +2866,7 @@ var require_SyncAsyncFileSystemDecorator = __commonJS({
|
|
|
2873
2866
|
this.readdir = (arg, options, callback) => {
|
|
2874
2867
|
let result;
|
|
2875
2868
|
try {
|
|
2876
|
-
result = fs2.readdirSync(arg);
|
|
2869
|
+
result = callback ? fs2.readdirSync(arg, options) : fs2.readdirSync(arg);
|
|
2877
2870
|
} catch (e) {
|
|
2878
2871
|
return (callback || options)(e);
|
|
2879
2872
|
}
|
|
@@ -2883,7 +2876,7 @@ var require_SyncAsyncFileSystemDecorator = __commonJS({
|
|
|
2883
2876
|
this.readFile = (arg, options, callback) => {
|
|
2884
2877
|
let result;
|
|
2885
2878
|
try {
|
|
2886
|
-
result = fs2.readFileSync(arg);
|
|
2879
|
+
result = callback ? fs2.readFileSync(arg, options) : fs2.readFileSync(arg);
|
|
2887
2880
|
} catch (e) {
|
|
2888
2881
|
return (callback || options)(e);
|
|
2889
2882
|
}
|
|
@@ -2893,7 +2886,7 @@ var require_SyncAsyncFileSystemDecorator = __commonJS({
|
|
|
2893
2886
|
this.readlink = (arg, options, callback) => {
|
|
2894
2887
|
let result;
|
|
2895
2888
|
try {
|
|
2896
|
-
result = fs2.readlinkSync(arg);
|
|
2889
|
+
result = callback ? fs2.readlinkSync(arg, options) : fs2.readlinkSync(arg);
|
|
2897
2890
|
} catch (e) {
|
|
2898
2891
|
return (callback || options)(e);
|
|
2899
2892
|
}
|
|
@@ -2904,16 +2897,31 @@ var require_SyncAsyncFileSystemDecorator = __commonJS({
|
|
|
2904
2897
|
this.readJsonSync = void 0;
|
|
2905
2898
|
const readJsonSync = fs2.readJsonSync;
|
|
2906
2899
|
if (readJsonSync) {
|
|
2907
|
-
this.readJson = (arg,
|
|
2900
|
+
this.readJson = (arg, callback) => {
|
|
2908
2901
|
let result;
|
|
2909
2902
|
try {
|
|
2910
2903
|
result = readJsonSync.call(fs2, arg);
|
|
2904
|
+
} catch (e) {
|
|
2905
|
+
return callback(e);
|
|
2906
|
+
}
|
|
2907
|
+
callback(null, result);
|
|
2908
|
+
};
|
|
2909
|
+
this.readJsonSync = (arg) => readJsonSync.call(fs2, arg);
|
|
2910
|
+
}
|
|
2911
|
+
this.realpath = void 0;
|
|
2912
|
+
this.realpathSync = void 0;
|
|
2913
|
+
const realpathSync = fs2.realpathSync;
|
|
2914
|
+
if (realpathSync) {
|
|
2915
|
+
this.realpath = (arg, options, callback) => {
|
|
2916
|
+
let result;
|
|
2917
|
+
try {
|
|
2918
|
+
result = callback ? realpathSync.call(fs2, arg, options) : realpathSync.call(fs2, arg);
|
|
2911
2919
|
} catch (e) {
|
|
2912
2920
|
return (callback || options)(e);
|
|
2913
2921
|
}
|
|
2914
2922
|
(callback || options)(null, result);
|
|
2915
2923
|
};
|
|
2916
|
-
this.
|
|
2924
|
+
this.realpathSync = (arg, options) => realpathSync.call(fs2, arg, options);
|
|
2917
2925
|
}
|
|
2918
2926
|
}
|
|
2919
2927
|
module2.exports = SyncAsyncFileSystemDecorator;
|
|
@@ -2932,7 +2940,7 @@ var require_forEachBail = __commonJS({
|
|
|
2932
2940
|
let loop = void 0;
|
|
2933
2941
|
iterator(array[i++], (err, result) => {
|
|
2934
2942
|
if (err || result !== void 0 || i >= array.length) {
|
|
2935
|
-
return callback(err, result);
|
|
2943
|
+
return callback(err, result, i);
|
|
2936
2944
|
}
|
|
2937
2945
|
if (loop === false)
|
|
2938
2946
|
while (next())
|
|
@@ -3398,6 +3406,7 @@ var require_DirectoryExistsPlugin = __commonJS({
|
|
|
3398
3406
|
var require_entrypoints = __commonJS({
|
|
3399
3407
|
"../../../node_modules/enhanced-resolve/lib/util/entrypoints.js"(exports, module2) {
|
|
3400
3408
|
"use strict";
|
|
3409
|
+
var { parseIdentifier } = require_identifier();
|
|
3401
3410
|
var slashCode = "/".charCodeAt(0);
|
|
3402
3411
|
var dotCode = ".".charCodeAt(0);
|
|
3403
3412
|
var hashCode = "#".charCodeAt(0);
|
|
@@ -3406,24 +3415,27 @@ var require_entrypoints = __commonJS({
|
|
|
3406
3415
|
return createFieldProcessor(buildExportsField(exportsField), (request) => request.length === 0 ? "." : "./" + request, assertExportsFieldRequest, assertExportTarget);
|
|
3407
3416
|
};
|
|
3408
3417
|
module2.exports.processImportsField = function processImportsField(importsField) {
|
|
3409
|
-
return createFieldProcessor(
|
|
3418
|
+
return createFieldProcessor(importsField, (request) => "#" + request, assertImportsFieldRequest, assertImportTarget);
|
|
3410
3419
|
};
|
|
3411
3420
|
function createFieldProcessor(field, normalizeRequest, assertRequest, assertTarget) {
|
|
3412
3421
|
return function fieldProcessor(request, conditionNames) {
|
|
3413
3422
|
request = assertRequest(request);
|
|
3414
3423
|
const match = findMatch(normalizeRequest(request), field);
|
|
3415
3424
|
if (match === null)
|
|
3416
|
-
return [];
|
|
3417
|
-
const [mapping, remainingRequest, isSubpathMapping, isPattern] = match;
|
|
3425
|
+
return [[], null];
|
|
3426
|
+
const [mapping, remainingRequest, isSubpathMapping, isPattern, usedField] = match;
|
|
3418
3427
|
let direct = null;
|
|
3419
3428
|
if (isConditionalMapping(mapping)) {
|
|
3420
3429
|
direct = conditionalMapping(mapping, conditionNames);
|
|
3421
3430
|
if (direct === null)
|
|
3422
|
-
return [];
|
|
3431
|
+
return [[], null];
|
|
3423
3432
|
} else {
|
|
3424
3433
|
direct = mapping;
|
|
3425
3434
|
}
|
|
3426
|
-
return
|
|
3435
|
+
return [
|
|
3436
|
+
directMapping(remainingRequest, isPattern, isSubpathMapping, direct, conditionNames, assertTarget),
|
|
3437
|
+
usedField
|
|
3438
|
+
];
|
|
3427
3439
|
};
|
|
3428
3440
|
}
|
|
3429
3441
|
function assertExportsFieldRequest(request) {
|
|
@@ -3456,16 +3468,23 @@ var require_entrypoints = __commonJS({
|
|
|
3456
3468
|
return request.slice(1);
|
|
3457
3469
|
}
|
|
3458
3470
|
function assertExportTarget(exp, expectFolder) {
|
|
3459
|
-
|
|
3460
|
-
|
|
3471
|
+
const parsedIdentifier = parseIdentifier(exp);
|
|
3472
|
+
if (!parsedIdentifier) {
|
|
3473
|
+
return;
|
|
3461
3474
|
}
|
|
3462
|
-
const
|
|
3475
|
+
const [relativePath] = parsedIdentifier;
|
|
3476
|
+
const isFolder = relativePath.charCodeAt(relativePath.length - 1) === slashCode;
|
|
3463
3477
|
if (isFolder !== expectFolder) {
|
|
3464
3478
|
throw new Error(expectFolder ? `Expecting folder to folder mapping. ${JSON.stringify(exp)} should end with "/"` : `Expecting file to file mapping. ${JSON.stringify(exp)} should not end with "/"`);
|
|
3465
3479
|
}
|
|
3466
3480
|
}
|
|
3467
3481
|
function assertImportTarget(imp, expectFolder) {
|
|
3468
|
-
const
|
|
3482
|
+
const parsedIdentifier = parseIdentifier(imp);
|
|
3483
|
+
if (!parsedIdentifier) {
|
|
3484
|
+
return;
|
|
3485
|
+
}
|
|
3486
|
+
const [relativePath] = parsedIdentifier;
|
|
3487
|
+
const isFolder = relativePath.charCodeAt(relativePath.length - 1) === slashCode;
|
|
3469
3488
|
if (isFolder !== expectFolder) {
|
|
3470
3489
|
throw new Error(expectFolder ? `Expecting folder to folder mapping. ${JSON.stringify(imp)} should end with "/"` : `Expecting file to file mapping. ${JSON.stringify(imp)} should not end with "/"`);
|
|
3471
3490
|
}
|
|
@@ -3492,7 +3511,7 @@ var require_entrypoints = __commonJS({
|
|
|
3492
3511
|
function findMatch(request, field) {
|
|
3493
3512
|
if (Object.prototype.hasOwnProperty.call(field, request) && !request.includes("*") && !request.endsWith("/")) {
|
|
3494
3513
|
const target2 = field[request];
|
|
3495
|
-
return [target2, "", false, false];
|
|
3514
|
+
return [target2, "", false, false, request];
|
|
3496
3515
|
}
|
|
3497
3516
|
let bestMatch = "";
|
|
3498
3517
|
let bestMatchSubpath;
|
|
@@ -3520,7 +3539,8 @@ var require_entrypoints = __commonJS({
|
|
|
3520
3539
|
target,
|
|
3521
3540
|
bestMatchSubpath,
|
|
3522
3541
|
isSubpathMapping,
|
|
3523
|
-
isPattern
|
|
3542
|
+
isPattern,
|
|
3543
|
+
bestMatch
|
|
3524
3544
|
];
|
|
3525
3545
|
}
|
|
3526
3546
|
function isConditionalMapping(mapping) {
|
|
@@ -3571,14 +3591,9 @@ var require_entrypoints = __commonJS({
|
|
|
3571
3591
|
loop:
|
|
3572
3592
|
while (lookup.length > 0) {
|
|
3573
3593
|
const [mapping, conditions, j] = lookup[lookup.length - 1];
|
|
3574
|
-
const last = conditions.length - 1;
|
|
3575
3594
|
for (let i = j; i < conditions.length; i++) {
|
|
3576
3595
|
const condition = conditions[i];
|
|
3577
|
-
if (
|
|
3578
|
-
if (condition === "default") {
|
|
3579
|
-
throw new Error("Default condition should be last one");
|
|
3580
|
-
}
|
|
3581
|
-
} else if (condition === "default") {
|
|
3596
|
+
if (condition === "default") {
|
|
3582
3597
|
const innerMapping = mapping[condition];
|
|
3583
3598
|
if (isConditionalMapping(innerMapping)) {
|
|
3584
3599
|
const conditionalMapping2 = innerMapping;
|
|
@@ -3632,22 +3647,6 @@ var require_entrypoints = __commonJS({
|
|
|
3632
3647
|
}
|
|
3633
3648
|
return field;
|
|
3634
3649
|
}
|
|
3635
|
-
function buildImportsField(field) {
|
|
3636
|
-
const keys = Object.keys(field);
|
|
3637
|
-
for (let i = 0; i < keys.length; i++) {
|
|
3638
|
-
const key = keys[i];
|
|
3639
|
-
if (key.charCodeAt(0) !== hashCode) {
|
|
3640
|
-
throw new Error(`Imports field key should start with "#" (key: ${JSON.stringify(key)})`);
|
|
3641
|
-
}
|
|
3642
|
-
if (key.length === 1) {
|
|
3643
|
-
throw new Error(`Imports field key should have at least 2 characters (key: ${JSON.stringify(key)})`);
|
|
3644
|
-
}
|
|
3645
|
-
if (key.charCodeAt(1) === slashCode) {
|
|
3646
|
-
throw new Error(`Imports field key should not start with "#/" (key: ${JSON.stringify(key)})`);
|
|
3647
|
-
}
|
|
3648
|
-
}
|
|
3649
|
-
return field;
|
|
3650
|
-
}
|
|
3651
3650
|
}
|
|
3652
3651
|
});
|
|
3653
3652
|
|
|
@@ -3655,12 +3654,14 @@ var require_entrypoints = __commonJS({
|
|
|
3655
3654
|
var require_ExportsFieldPlugin = __commonJS({
|
|
3656
3655
|
"../../../node_modules/enhanced-resolve/lib/ExportsFieldPlugin.js"(exports, module2) {
|
|
3657
3656
|
"use strict";
|
|
3658
|
-
var path = require("path");
|
|
3659
3657
|
var DescriptionFileUtils = require_DescriptionFileUtils();
|
|
3660
3658
|
var forEachBail = require_forEachBail();
|
|
3661
3659
|
var { processExportsField } = require_entrypoints();
|
|
3662
3660
|
var { parseIdentifier } = require_identifier();
|
|
3663
|
-
var {
|
|
3661
|
+
var {
|
|
3662
|
+
invalidSegmentRegEx,
|
|
3663
|
+
deprecatedInvalidSegmentRegEx
|
|
3664
|
+
} = require_path();
|
|
3664
3665
|
module2.exports = class ExportsFieldPlugin {
|
|
3665
3666
|
constructor(source, conditionNames, fieldNamePath, target) {
|
|
3666
3667
|
this.source = source;
|
|
@@ -3684,13 +3685,14 @@ var require_ExportsFieldPlugin = __commonJS({
|
|
|
3684
3685
|
return callback(new Error(`Resolving to directories is not possible with the exports field (request was ${remainingRequest}/)`));
|
|
3685
3686
|
}
|
|
3686
3687
|
let paths;
|
|
3688
|
+
let usedField;
|
|
3687
3689
|
try {
|
|
3688
3690
|
let fieldProcessor = this.fieldProcessorCache.get(request.descriptionFileData);
|
|
3689
3691
|
if (fieldProcessor === void 0) {
|
|
3690
3692
|
fieldProcessor = processExportsField(exportsField);
|
|
3691
3693
|
this.fieldProcessorCache.set(request.descriptionFileData, fieldProcessor);
|
|
3692
3694
|
}
|
|
3693
|
-
paths = fieldProcessor(remainingRequest, this.conditionNames);
|
|
3695
|
+
[paths, usedField] = fieldProcessor(remainingRequest, this.conditionNames);
|
|
3694
3696
|
} catch (err) {
|
|
3695
3697
|
if (resolveContext.log) {
|
|
3696
3698
|
resolveContext.log(`Exports field in ${request.descriptionFilePath} can't be processed: ${err}`);
|
|
@@ -3700,24 +3702,38 @@ var require_ExportsFieldPlugin = __commonJS({
|
|
|
3700
3702
|
if (paths.length === 0) {
|
|
3701
3703
|
return callback(new Error(`Package path ${remainingRequest} is not exported from package ${request.descriptionFileRoot} (see exports field in ${request.descriptionFilePath})`));
|
|
3702
3704
|
}
|
|
3703
|
-
forEachBail(paths, (p, callback2) => {
|
|
3705
|
+
forEachBail(paths, (p, callback2, i) => {
|
|
3704
3706
|
const parsedIdentifier = parseIdentifier(p);
|
|
3705
3707
|
if (!parsedIdentifier)
|
|
3706
3708
|
return callback2();
|
|
3707
3709
|
const [relativePath, query, fragment] = parsedIdentifier;
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3710
|
+
if (relativePath.length === 0 || !relativePath.startsWith("./")) {
|
|
3711
|
+
if (paths.length === i) {
|
|
3712
|
+
return callback2(new Error(`Invalid "exports" target "${p}" defined for "${usedField}" in the package config ${request.descriptionFilePath}, targets must start with "./"`));
|
|
3713
|
+
}
|
|
3714
|
+
return callback2();
|
|
3715
|
+
}
|
|
3716
|
+
if (invalidSegmentRegEx.exec(relativePath.slice(2)) !== null && deprecatedInvalidSegmentRegEx.test(relativePath.slice(2)) !== null) {
|
|
3717
|
+
if (paths.length === i) {
|
|
3718
|
+
return callback2(new Error(`Invalid "exports" target "${p}" defined for "${usedField}" in the package config ${request.descriptionFilePath}, targets must start with "./"`));
|
|
3719
|
+
}
|
|
3720
|
+
return callback2();
|
|
3711
3721
|
}
|
|
3712
3722
|
const obj = {
|
|
3713
3723
|
...request,
|
|
3714
3724
|
request: void 0,
|
|
3715
|
-
path:
|
|
3725
|
+
path: resolver.join(request.descriptionFileRoot, relativePath),
|
|
3716
3726
|
relativePath,
|
|
3717
3727
|
query,
|
|
3718
3728
|
fragment
|
|
3719
3729
|
};
|
|
3720
|
-
resolver.doResolve(target, obj, "using exports field: " + p, resolveContext,
|
|
3730
|
+
resolver.doResolve(target, obj, "using exports field: " + p, resolveContext, (err, result) => {
|
|
3731
|
+
if (err)
|
|
3732
|
+
return callback2(err);
|
|
3733
|
+
if (result === void 0)
|
|
3734
|
+
return callback2(null, null);
|
|
3735
|
+
callback2(null, result);
|
|
3736
|
+
});
|
|
3721
3737
|
}, (err, result) => callback(err, result || null));
|
|
3722
3738
|
});
|
|
3723
3739
|
}
|
|
@@ -3829,12 +3845,14 @@ var require_FileExistsPlugin = __commonJS({
|
|
|
3829
3845
|
var require_ImportsFieldPlugin = __commonJS({
|
|
3830
3846
|
"../../../node_modules/enhanced-resolve/lib/ImportsFieldPlugin.js"(exports, module2) {
|
|
3831
3847
|
"use strict";
|
|
3832
|
-
var path = require("path");
|
|
3833
3848
|
var DescriptionFileUtils = require_DescriptionFileUtils();
|
|
3834
3849
|
var forEachBail = require_forEachBail();
|
|
3835
3850
|
var { processImportsField } = require_entrypoints();
|
|
3836
3851
|
var { parseIdentifier } = require_identifier();
|
|
3837
|
-
var {
|
|
3852
|
+
var {
|
|
3853
|
+
invalidSegmentRegEx,
|
|
3854
|
+
deprecatedInvalidSegmentRegEx
|
|
3855
|
+
} = require_path();
|
|
3838
3856
|
var dotCode = ".".charCodeAt(0);
|
|
3839
3857
|
module2.exports = class ImportsFieldPlugin {
|
|
3840
3858
|
constructor(source, conditionNames, fieldNamePath, targetFile, targetPackage) {
|
|
@@ -3860,13 +3878,14 @@ var require_ImportsFieldPlugin = __commonJS({
|
|
|
3860
3878
|
return callback(new Error(`Resolving to directories is not possible with the imports field (request was ${remainingRequest}/)`));
|
|
3861
3879
|
}
|
|
3862
3880
|
let paths;
|
|
3881
|
+
let usedField;
|
|
3863
3882
|
try {
|
|
3864
3883
|
let fieldProcessor = this.fieldProcessorCache.get(request.descriptionFileData);
|
|
3865
3884
|
if (fieldProcessor === void 0) {
|
|
3866
3885
|
fieldProcessor = processImportsField(importsField);
|
|
3867
3886
|
this.fieldProcessorCache.set(request.descriptionFileData, fieldProcessor);
|
|
3868
3887
|
}
|
|
3869
|
-
paths = fieldProcessor(remainingRequest, this.conditionNames);
|
|
3888
|
+
[paths, usedField] = fieldProcessor(remainingRequest, this.conditionNames);
|
|
3870
3889
|
} catch (err) {
|
|
3871
3890
|
if (resolveContext.log) {
|
|
3872
3891
|
resolveContext.log(`Imports field in ${request.descriptionFilePath} can't be processed: ${err}`);
|
|
@@ -3876,26 +3895,34 @@ var require_ImportsFieldPlugin = __commonJS({
|
|
|
3876
3895
|
if (paths.length === 0) {
|
|
3877
3896
|
return callback(new Error(`Package import ${remainingRequest} is not imported from package ${request.descriptionFileRoot} (see imports field in ${request.descriptionFilePath})`));
|
|
3878
3897
|
}
|
|
3879
|
-
forEachBail(paths, (p, callback2) => {
|
|
3898
|
+
forEachBail(paths, (p, callback2, i) => {
|
|
3880
3899
|
const parsedIdentifier = parseIdentifier(p);
|
|
3881
3900
|
if (!parsedIdentifier)
|
|
3882
3901
|
return callback2();
|
|
3883
3902
|
const [path_, query, fragment] = parsedIdentifier;
|
|
3884
|
-
const error = checkImportsExportsFieldTarget(path_);
|
|
3885
|
-
if (error) {
|
|
3886
|
-
return callback2(error);
|
|
3887
|
-
}
|
|
3888
3903
|
switch (path_.charCodeAt(0)) {
|
|
3889
3904
|
case dotCode: {
|
|
3905
|
+
if (invalidSegmentRegEx.exec(path_.slice(2)) !== null && deprecatedInvalidSegmentRegEx.test(path_.slice(2)) !== null) {
|
|
3906
|
+
if (paths.length === i) {
|
|
3907
|
+
return callback2(new Error(`Invalid "imports" target "${p}" defined for "${usedField}" in the package config ${request.descriptionFilePath}, targets must start with "./"`));
|
|
3908
|
+
}
|
|
3909
|
+
return callback2();
|
|
3910
|
+
}
|
|
3890
3911
|
const obj = {
|
|
3891
3912
|
...request,
|
|
3892
3913
|
request: void 0,
|
|
3893
|
-
path:
|
|
3914
|
+
path: resolver.join(request.descriptionFileRoot, path_),
|
|
3894
3915
|
relativePath: path_,
|
|
3895
3916
|
query,
|
|
3896
3917
|
fragment
|
|
3897
3918
|
};
|
|
3898
|
-
resolver.doResolve(targetFile, obj, "using imports field: " + p, resolveContext,
|
|
3919
|
+
resolver.doResolve(targetFile, obj, "using imports field: " + p, resolveContext, (err, result) => {
|
|
3920
|
+
if (err)
|
|
3921
|
+
return callback2(err);
|
|
3922
|
+
if (result === void 0)
|
|
3923
|
+
return callback2(null, null);
|
|
3924
|
+
callback2(null, result);
|
|
3925
|
+
});
|
|
3899
3926
|
break;
|
|
3900
3927
|
}
|
|
3901
3928
|
default: {
|
|
@@ -3907,7 +3934,13 @@ var require_ImportsFieldPlugin = __commonJS({
|
|
|
3907
3934
|
query,
|
|
3908
3935
|
fragment
|
|
3909
3936
|
};
|
|
3910
|
-
resolver.doResolve(targetPackage, obj, "using imports field: " + p, resolveContext,
|
|
3937
|
+
resolver.doResolve(targetPackage, obj, "using imports field: " + p, resolveContext, (err, result) => {
|
|
3938
|
+
if (err)
|
|
3939
|
+
return callback2(err);
|
|
3940
|
+
if (result === void 0)
|
|
3941
|
+
return callback2(null, null);
|
|
3942
|
+
callback2(null, result);
|
|
3943
|
+
});
|
|
3911
3944
|
}
|
|
3912
3945
|
}
|
|
3913
3946
|
}, (err, result) => callback(err, result || null));
|
|
@@ -4212,13 +4245,15 @@ var require_PnpPlugin = __commonJS({
|
|
|
4212
4245
|
"../../../node_modules/enhanced-resolve/lib/PnpPlugin.js"(exports, module2) {
|
|
4213
4246
|
"use strict";
|
|
4214
4247
|
module2.exports = class PnpPlugin {
|
|
4215
|
-
constructor(source, pnpApi, target) {
|
|
4248
|
+
constructor(source, pnpApi, target, alternateTarget) {
|
|
4216
4249
|
this.source = source;
|
|
4217
4250
|
this.pnpApi = pnpApi;
|
|
4218
4251
|
this.target = target;
|
|
4252
|
+
this.alternateTarget = alternateTarget;
|
|
4219
4253
|
}
|
|
4220
4254
|
apply(resolver) {
|
|
4221
4255
|
const target = resolver.ensureHook(this.target);
|
|
4256
|
+
const alternateTarget = resolver.ensureHook(this.alternateTarget);
|
|
4222
4257
|
resolver.getHook(this.source).tapAsync("PnpPlugin", (request, resolveContext, callback) => {
|
|
4223
4258
|
const req = request.request;
|
|
4224
4259
|
if (!req)
|
|
@@ -4235,6 +4270,16 @@ var require_PnpPlugin = __commonJS({
|
|
|
4235
4270
|
resolution = this.pnpApi.resolveToUnqualified(packageName, issuer, {
|
|
4236
4271
|
considerBuiltins: false
|
|
4237
4272
|
});
|
|
4273
|
+
if (resolution === null) {
|
|
4274
|
+
resolver.doResolve(alternateTarget, request, "issuer is not managed by a pnpapi", resolveContext, (err, result) => {
|
|
4275
|
+
if (err)
|
|
4276
|
+
return callback(err);
|
|
4277
|
+
if (result)
|
|
4278
|
+
return callback(null, result);
|
|
4279
|
+
return callback(null, null);
|
|
4280
|
+
});
|
|
4281
|
+
return;
|
|
4282
|
+
}
|
|
4238
4283
|
if (resolveContext.fileDependencies) {
|
|
4239
4284
|
apiResolution = this.pnpApi.resolveToUnqualified("pnpapi", issuer, {
|
|
4240
4285
|
considerBuiltins: false
|
|
@@ -4643,7 +4688,18 @@ var require_ResolverFactory = __commonJS({
|
|
|
4643
4688
|
var UseFilePlugin = require_UseFilePlugin();
|
|
4644
4689
|
function processPnpApiOption(option) {
|
|
4645
4690
|
if (option === void 0 && versions.pnp) {
|
|
4646
|
-
|
|
4691
|
+
const _findPnpApi = require("module").findPnpApi;
|
|
4692
|
+
if (_findPnpApi) {
|
|
4693
|
+
return {
|
|
4694
|
+
resolveToUnqualified(request, issuer, opts) {
|
|
4695
|
+
const pnpapi = _findPnpApi(issuer);
|
|
4696
|
+
if (!pnpapi) {
|
|
4697
|
+
return null;
|
|
4698
|
+
}
|
|
4699
|
+
return pnpapi.resolveToUnqualified(request, issuer, opts);
|
|
4700
|
+
}
|
|
4701
|
+
};
|
|
4702
|
+
}
|
|
4647
4703
|
}
|
|
4648
4704
|
return option || null;
|
|
4649
4705
|
}
|
|
@@ -4758,6 +4814,7 @@ var require_ResolverFactory = __commonJS({
|
|
|
4758
4814
|
resolver.ensureHook("normalResolve");
|
|
4759
4815
|
resolver.ensureHook("internal");
|
|
4760
4816
|
resolver.ensureHook("rawModule");
|
|
4817
|
+
resolver.ensureHook("alternateRawModule");
|
|
4761
4818
|
resolver.ensureHook("module");
|
|
4762
4819
|
resolver.ensureHook("resolveAsModule");
|
|
4763
4820
|
resolver.ensureHook("undescribedResolveInPackage");
|
|
@@ -4824,7 +4881,8 @@ var require_ResolverFactory = __commonJS({
|
|
|
4824
4881
|
if (Array.isArray(item)) {
|
|
4825
4882
|
if (item.includes("node_modules") && pnpApi) {
|
|
4826
4883
|
plugins.push(new ModulesInHierarchicalDirectoriesPlugin("raw-module", item.filter((i) => i !== "node_modules"), "module"));
|
|
4827
|
-
plugins.push(new PnpPlugin("raw-module", pnpApi, "undescribed-resolve-in-package"));
|
|
4884
|
+
plugins.push(new PnpPlugin("raw-module", pnpApi, "undescribed-resolve-in-package", "alternate-raw-module"));
|
|
4885
|
+
plugins.push(new ModulesInHierarchicalDirectoriesPlugin("alternate-raw-module", ["node_modules"], "module"));
|
|
4828
4886
|
} else {
|
|
4829
4887
|
plugins.push(new ModulesInHierarchicalDirectoriesPlugin("raw-module", item, "module"));
|
|
4830
4888
|
}
|
package/lib/utils/routes.js
CHANGED
|
@@ -1,5 +1,103 @@
|
|
|
1
|
-
|
|
1
|
+
const defaultDelimiter = escapeString('/');
|
|
2
|
+
const pathExpr = new RegExp([
|
|
3
|
+
'(\\\\.)',
|
|
4
|
+
'([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))',
|
|
5
|
+
].join('|'), 'g');
|
|
6
|
+
function escapeString(str) {
|
|
7
|
+
return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1');
|
|
8
|
+
}
|
|
9
|
+
function escapeGroup(group) {
|
|
10
|
+
return group.replace(/([=!:$\/()])/g, '\\$1');
|
|
11
|
+
}
|
|
12
|
+
function parse(str) {
|
|
13
|
+
const tokens = [];
|
|
14
|
+
let key = 0;
|
|
15
|
+
let index = 0;
|
|
16
|
+
let path = '';
|
|
17
|
+
let res;
|
|
18
|
+
while ((res = pathExpr.exec(str)) !== null) {
|
|
19
|
+
const m = res[0];
|
|
20
|
+
const escaped = res[1];
|
|
21
|
+
const offset = res.index;
|
|
22
|
+
path += str.slice(index, offset);
|
|
23
|
+
index = offset + m.length;
|
|
24
|
+
// Ignore already escaped sequences.
|
|
25
|
+
if (escaped) {
|
|
26
|
+
path += escaped[1];
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const next = str[index];
|
|
30
|
+
const prefix = res[2];
|
|
31
|
+
const name = res[3];
|
|
32
|
+
const capture = res[4];
|
|
33
|
+
const group = res[5];
|
|
34
|
+
const modifier = res[6];
|
|
35
|
+
const asterisk = res[7];
|
|
36
|
+
// Push the current path onto the tokens.
|
|
37
|
+
if (path) {
|
|
38
|
+
tokens.push(path);
|
|
39
|
+
path = '';
|
|
40
|
+
}
|
|
41
|
+
const partial = prefix != null && next != null && next !== prefix;
|
|
42
|
+
const repeat = modifier === '+' || modifier === '*';
|
|
43
|
+
const optional = modifier === '?' || modifier === '*';
|
|
44
|
+
const delimiter = res[2] || '/';
|
|
45
|
+
const pattern = capture || group;
|
|
46
|
+
tokens.push({
|
|
47
|
+
name: name || `${key++}`,
|
|
48
|
+
prefix: prefix || '',
|
|
49
|
+
delimiter,
|
|
50
|
+
optional,
|
|
51
|
+
repeat,
|
|
52
|
+
partial,
|
|
53
|
+
asterisk: !!asterisk,
|
|
54
|
+
pattern: pattern ? escapeGroup(pattern) : asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// Match any characters still remaining.
|
|
58
|
+
if (index < str.length) {
|
|
59
|
+
path += str.substring(index);
|
|
60
|
+
}
|
|
61
|
+
// If the path exists, push it onto the end.
|
|
62
|
+
if (path) {
|
|
63
|
+
tokens.push(path);
|
|
64
|
+
}
|
|
65
|
+
return tokens;
|
|
66
|
+
}
|
|
67
|
+
function tokensToRegExp(tokens) {
|
|
68
|
+
let route = '';
|
|
69
|
+
for (const token of tokens) {
|
|
70
|
+
if (typeof token === 'string') {
|
|
71
|
+
route += escapeString(token);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const prefix = escapeString(token.prefix);
|
|
75
|
+
let capture = '(?:' + token.pattern + ')';
|
|
76
|
+
if (token.repeat) {
|
|
77
|
+
capture += '(?:' + prefix + capture + ')*';
|
|
78
|
+
}
|
|
79
|
+
if (token.optional) {
|
|
80
|
+
if (!token.partial) {
|
|
81
|
+
capture = '(?:' + prefix + '(' + capture + '))?';
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
capture = prefix + '(' + capture + ')?';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
capture = prefix + '(' + capture + ')';
|
|
89
|
+
}
|
|
90
|
+
route += capture;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const endsWithDelimiter = route.slice(-defaultDelimiter.length) === defaultDelimiter;
|
|
94
|
+
const path = endsWithDelimiter ? route.slice(0, -defaultDelimiter.length) : route;
|
|
95
|
+
return new RegExp(`^${path}(?:${defaultDelimiter}(?=$))?$`, 'i');
|
|
96
|
+
}
|
|
97
|
+
function stringToRegexp(path) {
|
|
98
|
+
return tokensToRegExp(parse(path));
|
|
99
|
+
}
|
|
2
100
|
export function createRouteMatcher(path) {
|
|
3
|
-
return
|
|
101
|
+
return stringToRegexp(path);
|
|
4
102
|
}
|
|
5
103
|
//# sourceMappingURL=routes.js.map
|
package/lib/utils/routes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/utils/routes.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/utils/routes.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3C,MAAM,QAAQ,GAAG,IAAI,MAAM,CACzB;IACE,SAAS;IACT,wGAAwG;CACzG,CAAC,IAAI,CAAC,GAAG,CAAC,EACX,GAAG,CACJ,CAAC;AAEF,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,4BAA4B,EAAE,MAAM,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C,CAAC;AAC9B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-core",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2-beta.7393",
|
|
4
4
|
"description": "The core library for creating a Piral instance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -61,9 +61,8 @@
|
|
|
61
61
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"
|
|
65
|
-
"piral-
|
|
66
|
-
"piral-debug-utils": "^1.6.1",
|
|
64
|
+
"piral-base": "1.6.2-beta.7393",
|
|
65
|
+
"piral-debug-utils": "1.6.2-beta.7393",
|
|
67
66
|
"zustand": "^3.0.0"
|
|
68
67
|
},
|
|
69
68
|
"devDependencies": {
|
|
@@ -83,5 +82,5 @@
|
|
|
83
82
|
"react-router-dom",
|
|
84
83
|
"tslib"
|
|
85
84
|
],
|
|
86
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "75d596d714a582f54071e1799e0ce183dbacbb09"
|
|
87
86
|
}
|
package/src/utils/routes.ts
CHANGED
|
@@ -1,5 +1,135 @@
|
|
|
1
|
-
|
|
1
|
+
const defaultDelimiter = escapeString('/');
|
|
2
|
+
const pathExpr = new RegExp(
|
|
3
|
+
[
|
|
4
|
+
'(\\\\.)',
|
|
5
|
+
'([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))',
|
|
6
|
+
].join('|'),
|
|
7
|
+
'g',
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
function escapeString(str: string) {
|
|
11
|
+
return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function escapeGroup(group: string) {
|
|
15
|
+
return group.replace(/([=!:$\/()])/g, '\\$1');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type Token =
|
|
19
|
+
| string
|
|
20
|
+
| {
|
|
21
|
+
name: string;
|
|
22
|
+
prefix: string;
|
|
23
|
+
delimiter: string;
|
|
24
|
+
optional: boolean;
|
|
25
|
+
repeat: boolean;
|
|
26
|
+
partial: boolean;
|
|
27
|
+
asterisk: boolean;
|
|
28
|
+
pattern: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function parse(str: string) {
|
|
32
|
+
const tokens: Array<Token> = [];
|
|
33
|
+
let key = 0;
|
|
34
|
+
let index = 0;
|
|
35
|
+
let path = '';
|
|
36
|
+
let res: RegExpExecArray;
|
|
37
|
+
|
|
38
|
+
while ((res = pathExpr.exec(str)) !== null) {
|
|
39
|
+
const m = res[0];
|
|
40
|
+
const escaped = res[1];
|
|
41
|
+
const offset = res.index;
|
|
42
|
+
path += str.slice(index, offset);
|
|
43
|
+
index = offset + m.length;
|
|
44
|
+
|
|
45
|
+
// Ignore already escaped sequences.
|
|
46
|
+
if (escaped) {
|
|
47
|
+
path += escaped[1];
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const next = str[index];
|
|
52
|
+
const prefix = res[2];
|
|
53
|
+
const name = res[3];
|
|
54
|
+
const capture = res[4];
|
|
55
|
+
const group = res[5];
|
|
56
|
+
const modifier = res[6];
|
|
57
|
+
const asterisk = res[7];
|
|
58
|
+
|
|
59
|
+
// Push the current path onto the tokens.
|
|
60
|
+
if (path) {
|
|
61
|
+
tokens.push(path);
|
|
62
|
+
path = '';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const partial = prefix != null && next != null && next !== prefix;
|
|
66
|
+
const repeat = modifier === '+' || modifier === '*';
|
|
67
|
+
const optional = modifier === '?' || modifier === '*';
|
|
68
|
+
const delimiter = res[2] || '/';
|
|
69
|
+
const pattern = capture || group;
|
|
70
|
+
|
|
71
|
+
tokens.push({
|
|
72
|
+
name: name || `${key++}`,
|
|
73
|
+
prefix: prefix || '',
|
|
74
|
+
delimiter,
|
|
75
|
+
optional,
|
|
76
|
+
repeat,
|
|
77
|
+
partial,
|
|
78
|
+
asterisk: !!asterisk,
|
|
79
|
+
pattern: pattern ? escapeGroup(pattern) : asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Match any characters still remaining.
|
|
84
|
+
if (index < str.length) {
|
|
85
|
+
path += str.substring(index);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// If the path exists, push it onto the end.
|
|
89
|
+
if (path) {
|
|
90
|
+
tokens.push(path);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return tokens;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function tokensToRegExp(tokens: Array<Token>) {
|
|
97
|
+
let route = '';
|
|
98
|
+
|
|
99
|
+
for (const token of tokens) {
|
|
100
|
+
if (typeof token === 'string') {
|
|
101
|
+
route += escapeString(token);
|
|
102
|
+
} else {
|
|
103
|
+
const prefix = escapeString(token.prefix);
|
|
104
|
+
let capture = '(?:' + token.pattern + ')';
|
|
105
|
+
|
|
106
|
+
if (token.repeat) {
|
|
107
|
+
capture += '(?:' + prefix + capture + ')*';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (token.optional) {
|
|
111
|
+
if (!token.partial) {
|
|
112
|
+
capture = '(?:' + prefix + '(' + capture + '))?';
|
|
113
|
+
} else {
|
|
114
|
+
capture = prefix + '(' + capture + ')?';
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
capture = prefix + '(' + capture + ')';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
route += capture;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const endsWithDelimiter = route.slice(-defaultDelimiter.length) === defaultDelimiter;
|
|
125
|
+
const path = endsWithDelimiter ? route.slice(0, -defaultDelimiter.length) : route;
|
|
126
|
+
return new RegExp(`^${path}(?:${defaultDelimiter}(?=$))?$`, 'i');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function stringToRegexp(path: string) {
|
|
130
|
+
return tokensToRegExp(parse(path));
|
|
131
|
+
}
|
|
2
132
|
|
|
3
133
|
export function createRouteMatcher(path: string): RegExp {
|
|
4
|
-
return
|
|
134
|
+
return stringToRegexp(path);
|
|
5
135
|
}
|