Skip to content

Commit

Permalink
Revert "Migrate Photon to Typescript (Automattic#59033)" (Automattic#…
Browse files Browse the repository at this point in the history
…59268)

This reverts commit f0fc7b7.
  • Loading branch information
noahtallen authored Dec 15, 2021
1 parent 15bea25 commit 2da950f
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 70 deletions.
1 change: 0 additions & 1 deletion apps/editing-toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"@automattic/plans-grid": "workspace:^",
"@automattic/tour-kit": "workspace:^",
"@automattic/typography": "workspace:^",
"@automattic/viewport": "workspace:^",
"@automattic/whats-new": "workspace:^",
"@babel/core": "^7.16.5",
"@emotion/react": "^11.4.1",
Expand Down
15 changes: 4 additions & 11 deletions packages/photon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"description": "JavaScript library for the WordPress.com Photon image manipulation service",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"calypso:src": "src/index.ts",
"types": "dist/types/index.d.ts",
"calypso:src": "src/index.js",
"sideEffects": false,
"repository": {
"type": "git",
Expand All @@ -23,10 +22,6 @@
"api",
"library"
],
"files": [
"dist",
"src"
],
"author": "Automattic Inc.",
"contributors": [
"Nathan Rajlich <nathan@automattic.com>"
Expand All @@ -37,18 +32,16 @@
},
"homepage": "https://github.com/Automattic/wp-calypso",
"dependencies": {
"@types/seed-random": "^2.2.1",
"crc32": "^0.2.2",
"debug": "^4.0.0",
"seed-random": "^2.2.0"
},
"devDependencies": {
"@automattic/calypso-typescript-config": "workspace:^",
"typescript": "^4.5.3"
"@automattic/calypso-typescript-config": "workspace:^"
},
"scripts": {
"clean": "tsc --build ./tsconfig.json ./tsconfig-cjs.json --clean && rm -rf dist",
"build": "tsc --build ./tsconfig.json ./tsconfig-cjs.json",
"clean": "rm -rf dist",
"build": "transpile",
"prepack": "yarn run clean && yarn run build"
}
}
3 changes: 0 additions & 3 deletions packages/photon/src/decs.d.ts

This file was deleted.

43 changes: 17 additions & 26 deletions packages/photon/src/index.ts → packages/photon/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const debug = debugFactory( 'photon' );
/**
* Options argument to query string parameter mappings.
*/
const mappings: Record< string, string > = {
const mappings = {
width: 'w',
height: 'h',
letterboxing: 'lb',
Expand All @@ -18,19 +18,6 @@ const PARSE_BASE_HOST = '__domain__.invalid';
const PARSE_BASE_URL = `https://${ PARSE_BASE_HOST }`;
const PHOTON_BASE_URL = 'https://i0.wp.com';

type PhotonOpts = {
width?: number;
height?: number;
hostname?: string;
host?: string;
secure?: boolean;
zoom?: number;
resize?: string;
fit?: string;
letterboxing?: string;
removeLetterBoxing?: boolean;
};

/**
* Returns a "photon" URL from the given image URL.
*
Expand All @@ -39,11 +26,11 @@ type PhotonOpts = {
*
* Photon documentation: http://developer.wordpress.com/docs/photon/
*
* @param imageUrl - the URL of the image to run through Photon
* @param [opts] - optional options object with Photon options
* @returns The generated Photon URL string
* @param {string} imageUrl - the URL of the image to run through Photon
* @param {object} [opts] - optional options object with Photon options
* @returns {string} The generated Photon URL string
*/
export default function photon( imageUrl: string, opts?: PhotonOpts ): string | null {
export default function photon( imageUrl, opts ) {
let parsedUrl;
try {
parsedUrl = new URL( imageUrl, PARSE_BASE_URL );
Expand Down Expand Up @@ -77,21 +64,25 @@ export default function photon( imageUrl: string, opts?: PhotonOpts ): string |
photonUrl.pathname = formattedUrl;
photonUrl.hostname = serverFromUrlParts( formattedUrl, photonUrl.protocol === 'https:' );
if ( wasSecure ) {
photonUrl.searchParams.set( 'ssl', '1' );
photonUrl.searchParams.set( 'ssl', 1 );
}
}

if ( opts ) {
for ( const [ opt, value ] of Object.entries( opts ) ) {
if ( opt === 'host' || opt === 'hostname' ) {
photonUrl.hostname = value as string;
for ( const i in opts ) {
// allow configurable "hostname"
if ( i === 'host' || i === 'hostname' ) {
photonUrl.hostname = opts[ i ];
continue;
}
if ( opt === 'secure' && ! value ) {

// allow non-secure access
if ( i === 'secure' && ! opts[ i ] ) {
photonUrl.protocol = 'http:';
continue;
}
photonUrl.searchParams.set( mappings[ opt ] ?? opt, value.toString() );

photonUrl.searchParams.set( mappings[ i ] || i, opts[ i ] );
}
}

Expand All @@ -101,7 +92,7 @@ export default function photon( imageUrl: string, opts?: PhotonOpts ): string |
return photonUrl.href;
}

function isAlreadyPhotoned( host: string ) {
function isAlreadyPhotoned( host ) {
return /^i[0-2]\.wp\.com$/.test( host );
}

Expand All @@ -116,7 +107,7 @@ function isAlreadyPhotoned( host: string ) {
* @param {boolean} isSecure Whether we're constructing a HTTPS URL or a HTTP one
* @returns {string} The hostname for the pathname
*/
function serverFromUrlParts( pathname: string, isSecure: boolean ) {
function serverFromUrlParts( pathname, isSecure ) {
if ( isSecure ) {
return 'i0.wp.com';
}
Expand Down
7 changes: 0 additions & 7 deletions packages/photon/tsconfig-cjs.json

This file was deleted.

9 changes: 1 addition & 8 deletions packages/photon/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
{
"extends": "@automattic/calypso-typescript-config/ts-package.json",
"compilerOptions": {
"declarationDir": "dist/types",
"outDir": "dist/esm",
"rootDir": "src"
},
"include": [ "src" ],
"exclude": [ "**/test/*" ]
"extends": "@automattic/calypso-typescript-config/js-package.json"
}
1 change: 0 additions & 1 deletion packages/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
{ "path": "./launch" },
{ "path": "./onboarding" },
{ "path": "./page-pattern-modal" },
{ "path": "./photon" },
{ "path": "./plans-grid" },
{ "path": "./search" },
{ "path": "./shopping-cart" },
Expand Down
3 changes: 1 addition & 2 deletions packages/viewport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"access": "public"
},
"devDependencies": {
"@automattic/calypso-typescript-config": "workspace:^",
"typescript": "^4.5.3"
"@automattic/calypso-typescript-config": "workspace:^"
}
}
11 changes: 0 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,6 @@ __metadata:
resolution: "@automattic/viewport@workspace:packages/viewport"
dependencies:
"@automattic/calypso-typescript-config": "workspace:^"
typescript: ^4.5.3
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -1376,7 +1375,6 @@ __metadata:
"@automattic/plans-grid": "workspace:^"
"@automattic/tour-kit": "workspace:^"
"@automattic/typography": "workspace:^"
"@automattic/viewport": "workspace:^"
"@automattic/whats-new": "workspace:^"
"@babel/core": ^7.16.5
"@emotion/react": ^11.4.1
Expand Down Expand Up @@ -6922,13 +6920,6 @@ __metadata:
languageName: node
linkType: hard

"@types/seed-random@npm:^2.2.1":
version: 2.2.1
resolution: "@types/seed-random@npm:2.2.1"
checksum: 4efc78a6c2786b3c7d84c85ebef9b6d14a9e861d1852893b835eea8fb838fd602244b2a79cef6da6feedaefc89ecac7a3728746471e3f33265e5ccef533a21ab
languageName: node
linkType: hard

"@types/semver@npm:^7.3.4":
version: 7.3.9
resolution: "@types/semver@npm:7.3.9"
Expand Down Expand Up @@ -28035,11 +28026,9 @@ fsevents@~2.1.2:
resolution: "photon@workspace:packages/photon"
dependencies:
"@automattic/calypso-typescript-config": "workspace:^"
"@types/seed-random": ^2.2.1
crc32: ^0.2.2
debug: ^4.0.0
seed-random: ^2.2.0
typescript: ^4.5.3
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 2da950f

Please sign in to comment.