Skip to content

Commit

Permalink
feat: Use different versioning for User-Agent.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShogunPanda committed Jan 4, 2021
1 parent 27fc179 commit 06659da
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 18 deletions.
9 changes: 5 additions & 4 deletions dist/cjs/models.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultOptions = exports.FastImageError = void 0;
// The version is dynamically generated via build script in order not rely on require in the ESM case.
const version_1 = require("./version");
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultOptions = exports.userAgentVersion = exports.FastImageError = void 0;
class FastImageError extends Error {
constructor(message, code, url, httpResponseCode) {
super(message);
Expand All @@ -12,8 +11,10 @@ class FastImageError extends Error {
}
}
exports.FastImageError = FastImageError;
// Since it's harder to keep this in sync with package.json, let's use a different number.
exports.userAgentVersion = '1.0.0';
exports.defaultOptions = {
timeout: 30000,
threshold: 4096,
userAgent: `fastimage/${version_1.version}`
userAgent: `fastimage/${exports.userAgentVersion}`
};
4 changes: 0 additions & 4 deletions dist/cjs/version.js

This file was deleted.

5 changes: 3 additions & 2 deletions dist/mjs/models.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// The version is dynamically generated via build script in order not rely on require in the ESM case.
import { version } from "./version.mjs";
export class FastImageError extends Error {
constructor(message, code, url, httpResponseCode) {
super(message);
Expand All @@ -8,8 +7,10 @@ export class FastImageError extends Error {
this.httpResponseCode = httpResponseCode;
}
}
// Since it's harder to keep this in sync with package.json, let's use a different number.
export const userAgentVersion = '1.0.0';
export const defaultOptions = {
timeout: 30000,
threshold: 4096,
userAgent: `fastimage/${version}`
userAgent: `fastimage/${userAgentVersion}`
};
1 change: 0 additions & 1 deletion dist/mjs/version.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"test": "tap --reporter=spec --coverage-report=html --coverage-report=text --no-browser test/*.test.ts",
"test:ci": "tap --no-color --reporter=spec --coverage-report=json --coverage-report=text --branches 90 --functions 90 --lines 90 --statements 90 test/*.test.ts",
"ci": "yarn lint && yarn test:ci",
"prebuild": "rm -rf dist types && yarn lint && node -e \"console.log('export const version = \\'' + require('./package').version + '\\'')\" > src/version.ts",
"prebuild": "rm -rf dist types && yarn lint",
"build": "tsc -p . && tsc -p tsconfig.modules.json && renamer --find js --replace mjs dist/mjs/** >> /dev/null && jscodeshift -s --extensions=mjs -t node_modules/@cowtech/esm-package-utils dist/mjs/**",
"prepublishOnly": "yarn ci",
"postpublish": "git push origin && git push origin -f --tags"
Expand Down
6 changes: 4 additions & 2 deletions src/models.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// The version is dynamically generated via build script in order not rely on require in the ESM case.
import { version } from './version'

export interface ImageInfo {
width: number
Expand Down Expand Up @@ -30,8 +29,11 @@ export class FastImageError extends Error {
}
}

// Since it's harder to keep this in sync with package.json, let's use a different number.
export const userAgentVersion = '1.0.0'

export const defaultOptions: Options = {
timeout: 30000,
threshold: 4096,
userAgent: `fastimage/${version}`
userAgent: `fastimage/${userAgentVersion}`
}
1 change: 0 additions & 1 deletion src/version.ts

This file was deleted.

4 changes: 2 additions & 2 deletions test/urls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AddressInfo, createServer, Socket } from 'net'
import { resolve } from 'path'
import t from 'tap'
import { info } from '../src'
import { FastImageError } from '../src/models'
import { FastImageError, userAgentVersion } from '../src/models'

type Test = typeof t

Expand Down Expand Up @@ -112,7 +112,7 @@ t.test('fastimage.info', (t: Test) => {
server.close()

// eslint-disable-next-line @typescript-eslint/no-var-requires
t.same(agents, [`fastimage/${require('../package.json').version}`, 'FOO'])
t.same(agents, [`fastimage/${userAgentVersion}`, 'FOO'])
})

t.end()
Expand Down
1 change: 1 addition & 0 deletions types/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export declare class FastImageError extends Error {
httpResponseCode?: number;
constructor(message: string, code: string, url?: string, httpResponseCode?: number);
}
export declare const userAgentVersion = "1.0.0";
export declare const defaultOptions: Options;
1 change: 0 additions & 1 deletion types/version.d.ts

This file was deleted.

0 comments on commit 06659da

Please sign in to comment.