mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Merge pull request #4451 from node-red/4446-allow-import-of-subpath-modules
Allow import of modules with subpath in specifier
This commit is contained in:
		| @@ -98,7 +98,7 @@ function requireModule(module) { | ||||
|     const parsedModule = parseModuleName(module); | ||||
|  | ||||
|     if (BUILTIN_MODULES.indexOf(parsedModule.module) !== -1) { | ||||
|         return require(parsedModule.module); | ||||
|         return require(parsedModule.module + parsedModule.subpath); | ||||
|     } | ||||
|     if (!knownExternalModules[parsedModule.module]) { | ||||
|         const e = new Error("Module not allowed"); | ||||
| @@ -131,7 +131,7 @@ function importModule(module) { | ||||
|     const parsedModule = parseModuleName(module); | ||||
|  | ||||
|     if (BUILTIN_MODULES.indexOf(parsedModule.module) !== -1) { | ||||
|         return import(parsedModule.module); | ||||
|         return import(parsedModule.module + parsedModule.subpath); | ||||
|     } | ||||
|     if (!knownExternalModules[parsedModule.module]) { | ||||
|         const e = new Error("Module not allowed"); | ||||
| @@ -152,12 +152,13 @@ function importModule(module) { | ||||
| } | ||||
|  | ||||
| function parseModuleName(module) { | ||||
|     var match = /((?:@[^/]+\/)?[^/@]+)(?:@([\s\S]+))?/.exec(module); | ||||
|     var match = /((?:@[^/]+\/)?[^/@]+)(\/[^/@]+)?(?:@([\s\S]+))?/.exec(module); | ||||
|     if (match) { | ||||
|         return { | ||||
|             spec: module, | ||||
|             module: match[1], | ||||
|             version: match[2], | ||||
|             subpath: match[2] || '', | ||||
|             version: match[3], | ||||
|             builtin: BUILTIN_MODULES.indexOf(match[1]) !== -1, | ||||
|             known: !!knownExternalModules[match[1]] | ||||
|         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user