Skip to content

Commit b8913d2

Browse files
Update domain-task to export baseUrl from 'main' instead of only 'fetch'. Goal is to avoid Webpack detecting dependency on isomorphic-fetch unless you're actually using it.
1 parent 5e669d6 commit b8913d2

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

‎src/Microsoft.AspNetCore.SpaServices/npm/domain-task/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "domain-task",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "Tracks outstanding operations for a logical thread of execution",
55
"main": "index.js",
66
"scripts":{

‎src/Microsoft.AspNetCore.SpaServices/npm/domain-task/src/fetch.ts‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import*asurlfrom'url';
22
import*asdomainfrom'domain';
33
import*asdomainContextfrom'domain-context';
4+
import{baseUrl}from'./main';
45
constisomorphicFetch=require('isomorphic-fetch');
56
constisNode=typeofprocess==='object'&&process.versions&&!!process.versions.node;
67

7-
// Not using a symbol, because this may need to run in a version of Node.js that doesn't support them
8-
constdomainTaskStateKey='__DOMAIN_TASK_INTERNAL_FETCH_BASEURL__DO_NOT_REFERENCE_THIS__';
9-
letnoDomainBaseUrl: string;
10-
118
functionissueRequest(baseUrl: string,req: string|Request,init?: RequestInit): Promise<any>{
129
// Resolve relative URLs
1310
if(baseUrl){
@@ -70,16 +67,6 @@ export function fetch(url: string | Request, init?: RequestInit): Promise<any>{
7067
returnissueRequest(baseUrl(),url,init);
7168
}
7269

73-
exportfunctionbaseUrl(url?: string): string{
74-
if(url){
75-
if(domain.active){
76-
// There's an active domain (e.g., in Node.js), so associate the base URL with it
77-
domainContext.set(domainTaskStateKey,url);
78-
}else{
79-
// There's no active domain (e.g., in browser), so there's just one shared base URL
80-
noDomainBaseUrl=url;
81-
}
82-
}
83-
84-
returndomain.active ? domainContext.get(domainTaskStateKey) : noDomainBaseUrl;
85-
}
70+
// Re-exporting baseUrl from this module for back-compatibility only
71+
// Newer code that wants to access baseUrl should use the version exported from the root of this package
72+
export{baseUrl}from'./main';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This file determines the top-level package exports
2-
export{addTask,run}from'./main';
2+
export{addTask,run,baseUrl}from'./main';
33
export{fetch}from'./fetch';

‎src/Microsoft.AspNetCore.SpaServices/npm/domain-task/src/main.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import*asdomainfrom'domain';
22
import*asdomainContextfrom'domain-context';
3+
4+
// Not using symbols, because this may need to run in a version of Node.js that doesn't support them
35
constdomainTasksStateKey='__DOMAIN_TASKS';
6+
constdomainTaskBaseUrlStateKey='__DOMAIN_TASK_INTERNAL_FETCH_BASEURL__DO_NOT_REFERENCE_THIS__';
7+
8+
letnoDomainBaseUrl: string;
49

510
exportfunctionaddTask(task: PromiseLike<any>){
611
if(task&&domain.active){
@@ -57,6 +62,20 @@ export function run<T>(codeToRun: () => T, completionCallback: (error: any) => v
5762
returnsynchronousResult;
5863
}
5964

65+
exportfunctionbaseUrl(url?: string): string{
66+
if(url){
67+
if(domain.active){
68+
// There's an active domain (e.g., in Node.js), so associate the base URL with it
69+
domainContext.set(domainTaskBaseUrlStateKey,url);
70+
}else{
71+
// There's no active domain (e.g., in browser), so there's just one shared base URL
72+
noDomainBaseUrl=url;
73+
}
74+
}
75+
76+
returndomain.active ? domainContext.get(domainTaskBaseUrlStateKey) : noDomainBaseUrl;
77+
}
78+
6079
interfaceDomainTasksState{
6180
numRemainingTasks: number;
6281
hasIssuedSuccessCallback: boolean;

0 commit comments

Comments
(0)