@abcnews/dev-proxy
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -54,3 +54,3 @@ "use strict"; | ||
} | ||
if (url.hostname.match(domainMatcher) === null) { | ||
if (url.hostname.match(/abc\.net\.au$/) === null) { | ||
return resolve(2 /* NON_ABC_SCRIPT */); | ||
@@ -123,3 +123,3 @@ } | ||
domainMatcher = /^(www|newsapp)\.abc\.net\.au$/; | ||
proxy = (project) => new Promise((resolve) => { | ||
proxy = (project) => new Promise((resolve, reject) => { | ||
if (document.location.host.match(domainMatcher) && !document.location.pathname.match(/news-projects/)) { | ||
@@ -130,3 +130,3 @@ return resolve(1 /* IN_PRODUCTION */); | ||
manager2(); | ||
resolve(init2(project)); | ||
init2(project).then(resolve).catch(reject); | ||
}); | ||
@@ -133,0 +133,0 @@ }); |
{ | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -22,2 +22,3 @@ # Dev script proxy | ||
The `proxy` function returns a promise that will either: | ||
- **resolve successfully**, indicating that the script initialisation should go ahead (i.e. the `.then(init)` part of the above implementation example), or | ||
@@ -27,2 +28,3 @@ - **be rejected**, indicating that an alternative script has been successfully identified and added to the document and the init function should not be run. | ||
For the `proxy` function to successfully identify a script to run instead a few criteria need to be met: | ||
- The script importing the `proxy` function should not have a `NODE_ENV` of 'development' (this prevents infinite loops when this `proxy` function is used on a dev server. | ||
@@ -32,4 +34,4 @@ - The script should not be running on a production URL. | ||
## Bookmarklet | ||
## Usage | ||
You can use [this bookmarklet](<https://bookmarklet-topaz.vercel.app/?name=Proxy%20news-project&source=!function()%7Bconst%20t%3Dprompt(%22Project%22%2CArray.from(document.querySelectorAll(%22script%5Bsrc%5D%22)).map((t%3D%3E%7Bconst%20r%3Dt.getAttribute(%22src%22).match(%2Fnews-projects%5C%2F(%5B%5Cw-%5D%2B)%2F)%3Breturn!!r%26%26r%5B1%5D%7D)).filter((t%3D%3E!!t)).join(%22%2C%22))%3Bt%26%26t.split(%22%2C%22).forEach((t%3D%3E%7Bconst%20r%3Dprompt(%22Replacement%20for%20%22%2Bt)%3Br%26%26(localStorage%5B%22proxy_%22%2Bt%5D%3Dr)%7D))%7D()%3B>) to help setup the config. | ||
As of version 1.2.0 pressing the key combination `Alt-M` when you're in an approprate dev or preview environment offers an easy way to set the appropriate localStorage values to proxy relevant scripts on the page. |
@@ -15,3 +15,3 @@ export enum RESOLUTION_REASONS { | ||
export const proxy = (project: string) => | ||
new Promise<number>((resolve) => { | ||
new Promise<number>((resolve, reject) => { | ||
// Never run on live/production. | ||
@@ -28,4 +28,4 @@ if ( | ||
manager(); | ||
resolve(init(project)); | ||
init(project).then(resolve).catch(reject); | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
import { RESOLUTION_REASONS, domainMatcher } from '.'; | ||
import { RESOLUTION_REASONS } from '.'; | ||
@@ -40,3 +40,3 @@ declare global { | ||
// Don't allow proxying of scripts that aren't loaded from the ABC domain. | ||
if (url.hostname.match(domainMatcher) === null) { | ||
if (url.hostname.match(/abc\.net\.au$/) === null) { | ||
return resolve(RESOLUTION_REASONS.NON_ABC_SCRIPT); | ||
@@ -43,0 +43,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
119391
64
1454
35
0
11