@@ -30,8 +30,6 @@ const { getOptionValue } = require('internal/options');
30
30
const { sep, posix : { relative : relativePosixPath } , resolve } = require ( 'path' ) ;
31
31
const preserveSymlinks = getOptionValue ( '--preserve-symlinks' ) ;
32
32
const preserveSymlinksMain = getOptionValue ( '--preserve-symlinks-main' ) ;
33
- const experimentalNetworkImports =
34
- getOptionValue ( '--experimental-network-imports' ) ;
35
33
const inputTypeFlag = getOptionValue ( '--input-type' ) ;
36
34
const { URL , pathToFileURL, fileURLToPath, isURL, URLParse } = require ( 'internal/url' ) ;
37
35
const { getCWDURL, setOwnProperty } = require ( 'internal/util' ) ;
@@ -48,7 +46,6 @@ const {
48
46
ERR_PACKAGE_PATH_NOT_EXPORTED ,
49
47
ERR_UNSUPPORTED_DIR_IMPORT ,
50
48
ERR_UNSUPPORTED_RESOLVE_REQUEST ,
51
- ERR_NETWORK_IMPORT_DISALLOWED ,
52
49
} = require ( 'internal/errors' ) . codes ;
53
50
54
51
const { Module : CJSModule } = require ( 'internal/modules/cjs/loader' ) ;
@@ -886,10 +883,6 @@ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
886
883
StringPrototypeSlice ( base , 0 , StringPrototypeIndexOf ( base , ':' ) + 1 ) :
887
884
base . protocol ;
888
885
const isData = protocol === 'data:' ;
889
- const isRemote =
890
- isData ||
891
- protocol === 'http:' ||
892
- protocol === 'https:' ;
893
886
// Order swapped from spec for minor perf gain.
894
887
// Ok since relative URLs cannot parse as URLs.
895
888
let resolved ;
@@ -907,7 +900,7 @@ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
907
900
try {
908
901
resolved = new URL ( specifier ) ;
909
902
} catch ( cause ) {
910
- if ( isRemote && ! BuiltinModule . canBeRequiredWithoutScheme ( specifier ) ) {
903
+ if ( isData && ! BuiltinModule . canBeRequiredWithoutScheme ( specifier ) ) {
911
904
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST ( specifier , base ) ;
912
905
setOwnProperty ( error , 'cause' , cause ) ;
913
906
throw error ;
@@ -976,57 +969,6 @@ function resolveAsCommonJS(specifier, parentURL) {
976
969
}
977
970
}
978
971
979
- /**
980
- * Throw an error if an import is not allowed.
981
- * TODO(@JakobJingleheimer): de-dupe `specifier` & `parsed`
982
- * @param {string } specifier - The import specifier.
983
- * @param {URL } parsed - The parsed URL of the import specifier.
984
- * @param {URL } parsedParentURL - The parsed URL of the parent module.
985
- * @throws {ERR_NETWORK_IMPORT_DISALLOWED } - If the import is disallowed.
986
- */
987
- function checkIfDisallowedImport ( specifier , parsed , parsedParentURL ) {
988
- if ( parsedParentURL ) {
989
- // Avoid accessing the `protocol` property due to the lazy getters.
990
- const parentProtocol = parsedParentURL . protocol ;
991
- if (
992
- parentProtocol === 'http:' ||
993
- parentProtocol === 'https:'
994
- ) {
995
- if ( shouldBeTreatedAsRelativeOrAbsolutePath ( specifier ) ) {
996
- // Avoid accessing the `protocol` property due to the lazy getters.
997
- const parsedProtocol = parsed ?. protocol ;
998
- // data: and blob: disallowed due to allowing file: access via
999
- // indirection
1000
- if ( parsedProtocol &&
1001
- parsedProtocol !== 'https:' &&
1002
- parsedProtocol !== 'http:'
1003
- ) {
1004
- throw new ERR_NETWORK_IMPORT_DISALLOWED (
1005
- specifier ,
1006
- parsedParentURL ,
1007
- 'remote imports cannot import from a local location.' ,
1008
- ) ;
1009
- }
1010
-
1011
- return { url : parsed . href } ;
1012
- }
1013
- if ( BuiltinModule . canBeRequiredWithoutScheme ( specifier ) ) {
1014
- throw new ERR_NETWORK_IMPORT_DISALLOWED (
1015
- specifier ,
1016
- parsedParentURL ,
1017
- 'remote imports cannot import from a local location.' ,
1018
- ) ;
1019
- }
1020
-
1021
- throw new ERR_NETWORK_IMPORT_DISALLOWED (
1022
- specifier ,
1023
- parsedParentURL ,
1024
- 'only relative and absolute specifiers are supported.' ,
1025
- ) ;
1026
- }
1027
- }
1028
- }
1029
-
1030
972
/**
1031
973
* Validate user-input in `context` supplied by a custom loader.
1032
974
* @param {string | URL | undefined } parentURL - The parent URL.
@@ -1068,36 +1010,10 @@ function defaultResolve(specifier, context = {}) {
1068
1010
// Avoid accessing the `protocol` property due to the lazy getters.
1069
1011
protocol = parsed . protocol ;
1070
1012
1071
- if ( protocol === 'data:' &&
1072
- parsedParentURL . protocol !== 'file:' &&
1073
- experimentalNetworkImports ) {
1074
- throw new ERR_NETWORK_IMPORT_DISALLOWED (
1075
- specifier ,
1076
- parsedParentURL ,
1077
- 'import data: from a non file: is not allowed' ,
1078
- ) ;
1079
- }
1080
- if ( protocol === 'data:' ||
1081
- ( experimentalNetworkImports &&
1082
- (
1083
- protocol === 'https:' ||
1084
- protocol === 'http:'
1085
- )
1086
- )
1087
- ) {
1013
+ if ( protocol === 'data:' ) {
1088
1014
return { __proto__ : null , url : parsed . href } ;
1089
1015
}
1090
1016
}
1091
- // There are multiple deep branches that can either throw or return; instead
1092
- // of duplicating that deeply nested logic for the possible returns, DRY and
1093
- // check for a return. This seems the least gnarly.
1094
- const maybeReturn = checkIfDisallowedImport (
1095
- specifier ,
1096
- parsed ,
1097
- parsedParentURL ,
1098
- ) ;
1099
-
1100
- if ( maybeReturn ) { return maybeReturn ; }
1101
1017
1102
1018
// This must come after checkIfDisallowedImport
1103
1019
protocol ??= parsed ?. protocol ;
0 commit comments