mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-10-06 12:50:10 +00:00
Adding sign with google in NPM
This commit is contained in:
12
node_modules/simple-update-notifier/src/borderedText.ts
generated
vendored
Normal file
12
node_modules/simple-update-notifier/src/borderedText.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
const borderedText = (text: string) => {
|
||||
const lines = text.split('\n');
|
||||
const width = Math.max(...lines.map((l) => l.length));
|
||||
const res = [`┌${'─'.repeat(width + 2)}┐`];
|
||||
for (const line of lines) {
|
||||
res.push(`│ ${line.padEnd(width)} │`);
|
||||
}
|
||||
res.push(`└${'─'.repeat(width + 2)}┘`);
|
||||
return res.join('\n');
|
||||
};
|
||||
|
||||
export default borderedText;
|
12
node_modules/simple-update-notifier/src/cache.spec.ts
generated
vendored
Normal file
12
node_modules/simple-update-notifier/src/cache.spec.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { createConfigDir, getLastUpdate, saveLastUpdate } from './cache';
|
||||
|
||||
createConfigDir();
|
||||
|
||||
jest.useFakeTimers().setSystemTime(new Date('2022-01-01'));
|
||||
|
||||
const fakeTime = new Date('2022-01-01').getTime();
|
||||
|
||||
test('can save update then get the update details', () => {
|
||||
saveLastUpdate('test');
|
||||
expect(getLastUpdate('test')).toBe(fakeTime);
|
||||
});
|
41
node_modules/simple-update-notifier/src/cache.ts
generated
vendored
Normal file
41
node_modules/simple-update-notifier/src/cache.ts
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
const homeDirectory = os.homedir();
|
||||
const configDir =
|
||||
process.env.XDG_CONFIG_HOME ||
|
||||
path.join(homeDirectory, '.config', 'simple-update-notifier');
|
||||
|
||||
const getConfigFile = (packageName: string) => {
|
||||
return path.join(configDir, `${packageName}.json`);
|
||||
};
|
||||
|
||||
export const createConfigDir = () => {
|
||||
if (!fs.existsSync(configDir)) {
|
||||
fs.mkdirSync(configDir, { recursive: true });
|
||||
}
|
||||
};
|
||||
|
||||
export const getLastUpdate = (packageName: string) => {
|
||||
const configFile = getConfigFile(packageName);
|
||||
|
||||
try {
|
||||
if (!fs.existsSync(configFile)) {
|
||||
return undefined;
|
||||
}
|
||||
const file = JSON.parse(fs.readFileSync(configFile, 'utf8'));
|
||||
return file.lastUpdateCheck as number;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const saveLastUpdate = (packageName: string) => {
|
||||
const configFile = getConfigFile(packageName);
|
||||
|
||||
fs.writeFileSync(
|
||||
configFile,
|
||||
JSON.stringify({ lastUpdateCheck: new Date().getTime() })
|
||||
);
|
||||
};
|
35
node_modules/simple-update-notifier/src/getDistVersion.spec.ts
generated
vendored
Normal file
35
node_modules/simple-update-notifier/src/getDistVersion.spec.ts
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import Stream from 'stream';
|
||||
import https from 'https';
|
||||
import getDistVersion from './getDistVersion';
|
||||
|
||||
jest.mock('https', () => ({
|
||||
get: jest.fn(),
|
||||
}));
|
||||
|
||||
test('Valid response returns version', async () => {
|
||||
const st = new Stream();
|
||||
(https.get as jest.Mock).mockImplementation((url, cb) => {
|
||||
cb(st);
|
||||
|
||||
st.emit('data', '{"latest":"1.0.0"}');
|
||||
st.emit('end');
|
||||
});
|
||||
|
||||
const version = await getDistVersion('test', 'latest');
|
||||
|
||||
expect(version).toEqual('1.0.0');
|
||||
});
|
||||
|
||||
test('Invalid response throws error', async () => {
|
||||
const st = new Stream();
|
||||
(https.get as jest.Mock).mockImplementation((url, cb) => {
|
||||
cb(st);
|
||||
|
||||
st.emit('data', 'some invalid json');
|
||||
st.emit('end');
|
||||
});
|
||||
|
||||
expect(getDistVersion('test', 'latest')).rejects.toThrow(
|
||||
'Could not parse version response'
|
||||
);
|
||||
});
|
29
node_modules/simple-update-notifier/src/getDistVersion.ts
generated
vendored
Normal file
29
node_modules/simple-update-notifier/src/getDistVersion.ts
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import https from 'https';
|
||||
|
||||
const getDistVersion = async (packageName: string, distTag: string) => {
|
||||
const url = `https://registry.npmjs.org/-/package/${packageName}/dist-tags`;
|
||||
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
https
|
||||
.get(url, (res) => {
|
||||
let body = '';
|
||||
|
||||
res.on('data', (chunk) => (body += chunk));
|
||||
res.on('end', () => {
|
||||
try {
|
||||
const json = JSON.parse(body);
|
||||
const version = json[distTag];
|
||||
if (!version) {
|
||||
reject(new Error('Error getting version'));
|
||||
}
|
||||
resolve(version);
|
||||
} catch {
|
||||
reject(new Error('Could not parse version response'));
|
||||
}
|
||||
});
|
||||
})
|
||||
.on('error', (err) => reject(err));
|
||||
});
|
||||
};
|
||||
|
||||
export default getDistVersion;
|
82
node_modules/simple-update-notifier/src/hasNewVersion.spec.ts
generated
vendored
Normal file
82
node_modules/simple-update-notifier/src/hasNewVersion.spec.ts
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
import hasNewVersion from './hasNewVersion';
|
||||
import { getLastUpdate } from './cache';
|
||||
import getDistVersion from './getDistVersion';
|
||||
|
||||
jest.mock('./getDistVersion', () => jest.fn().mockReturnValue('1.0.0'));
|
||||
jest.mock('./cache', () => ({
|
||||
getLastUpdate: jest.fn().mockReturnValue(undefined),
|
||||
createConfigDir: jest.fn(),
|
||||
saveLastUpdate: jest.fn(),
|
||||
}));
|
||||
|
||||
const pkg = { name: 'test', version: '1.0.0' };
|
||||
|
||||
afterEach(() => jest.clearAllMocks());
|
||||
|
||||
const defaultArgs = {
|
||||
pkg,
|
||||
shouldNotifyInNpmScript: true,
|
||||
alwaysRun: true,
|
||||
};
|
||||
|
||||
test('it should not trigger update for same version', async () => {
|
||||
const newVersion = await hasNewVersion(defaultArgs);
|
||||
|
||||
expect(newVersion).toBe(false);
|
||||
});
|
||||
|
||||
test('it should trigger update for patch version bump', async () => {
|
||||
(getDistVersion as jest.Mock).mockReturnValue('1.0.1');
|
||||
|
||||
const newVersion = await hasNewVersion(defaultArgs);
|
||||
|
||||
expect(newVersion).toBe('1.0.1');
|
||||
});
|
||||
|
||||
test('it should trigger update for minor version bump', async () => {
|
||||
(getDistVersion as jest.Mock).mockReturnValue('1.1.0');
|
||||
|
||||
const newVersion = await hasNewVersion(defaultArgs);
|
||||
|
||||
expect(newVersion).toBe('1.1.0');
|
||||
});
|
||||
|
||||
test('it should trigger update for major version bump', async () => {
|
||||
(getDistVersion as jest.Mock).mockReturnValue('2.0.0');
|
||||
|
||||
const newVersion = await hasNewVersion(defaultArgs);
|
||||
|
||||
expect(newVersion).toBe('2.0.0');
|
||||
});
|
||||
|
||||
test('it should not trigger update if version is lower', async () => {
|
||||
(getDistVersion as jest.Mock).mockReturnValue('0.0.9');
|
||||
|
||||
const newVersion = await hasNewVersion(defaultArgs);
|
||||
|
||||
expect(newVersion).toBe(false);
|
||||
});
|
||||
|
||||
it('should trigger update check if last update older than config', async () => {
|
||||
const TWO_WEEKS = new Date().getTime() - 1000 * 60 * 60 * 24 * 14;
|
||||
(getLastUpdate as jest.Mock).mockReturnValue(TWO_WEEKS);
|
||||
const newVersion = await hasNewVersion({
|
||||
pkg,
|
||||
shouldNotifyInNpmScript: true,
|
||||
});
|
||||
|
||||
expect(newVersion).toBe(false);
|
||||
expect(getDistVersion).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not trigger update check if last update is too recent', async () => {
|
||||
const TWELVE_HOURS = new Date().getTime() - 1000 * 60 * 60 * 12;
|
||||
(getLastUpdate as jest.Mock).mockReturnValue(TWELVE_HOURS);
|
||||
const newVersion = await hasNewVersion({
|
||||
pkg,
|
||||
shouldNotifyInNpmScript: true,
|
||||
});
|
||||
|
||||
expect(newVersion).toBe(false);
|
||||
expect(getDistVersion).not.toHaveBeenCalled();
|
||||
});
|
30
node_modules/simple-update-notifier/src/hasNewVersion.ts
generated
vendored
Normal file
30
node_modules/simple-update-notifier/src/hasNewVersion.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import semver from 'semver';
|
||||
import { createConfigDir, getLastUpdate, saveLastUpdate } from './cache';
|
||||
import getDistVersion from './getDistVersion';
|
||||
import { IUpdate } from './types';
|
||||
|
||||
const hasNewVersion = async ({
|
||||
pkg,
|
||||
updateCheckInterval = 1000 * 60 * 60 * 24,
|
||||
distTag = 'latest',
|
||||
alwaysRun,
|
||||
}: IUpdate) => {
|
||||
createConfigDir();
|
||||
const lastUpdateCheck = getLastUpdate(pkg.name);
|
||||
if (
|
||||
alwaysRun ||
|
||||
!lastUpdateCheck ||
|
||||
lastUpdateCheck < new Date().getTime() - updateCheckInterval
|
||||
) {
|
||||
const latestVersion = await getDistVersion(pkg.name, distTag);
|
||||
saveLastUpdate(pkg.name);
|
||||
if (semver.gt(latestVersion, pkg.version)) {
|
||||
return latestVersion;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export default hasNewVersion;
|
27
node_modules/simple-update-notifier/src/index.spec.ts
generated
vendored
Normal file
27
node_modules/simple-update-notifier/src/index.spec.ts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import simpleUpdateNotifier from '.';
|
||||
import hasNewVersion from './hasNewVersion';
|
||||
|
||||
const consoleSpy = jest.spyOn(console, 'log');
|
||||
|
||||
jest.mock('./hasNewVersion', () => jest.fn().mockResolvedValue('2.0.0'));
|
||||
|
||||
beforeEach(jest.clearAllMocks);
|
||||
|
||||
test('it logs message if update is available', async () => {
|
||||
await simpleUpdateNotifier({
|
||||
pkg: { name: 'test', version: '1.0.0' },
|
||||
alwaysRun: true,
|
||||
});
|
||||
|
||||
expect(consoleSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('it does not log message if update is not available', async () => {
|
||||
(hasNewVersion as jest.Mock).mockResolvedValue(false);
|
||||
await simpleUpdateNotifier({
|
||||
pkg: { name: 'test', version: '2.0.0' },
|
||||
alwaysRun: true,
|
||||
});
|
||||
|
||||
expect(consoleSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
28
node_modules/simple-update-notifier/src/index.ts
generated
vendored
Normal file
28
node_modules/simple-update-notifier/src/index.ts
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import isNpmOrYarn from './isNpmOrYarn';
|
||||
import hasNewVersion from './hasNewVersion';
|
||||
import { IUpdate } from './types';
|
||||
import borderedText from './borderedText';
|
||||
|
||||
const simpleUpdateNotifier = async (args: IUpdate) => {
|
||||
if (
|
||||
!args.alwaysRun &&
|
||||
(!process.stdout.isTTY || (isNpmOrYarn && !args.shouldNotifyInNpmScript))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const latestVersion = await hasNewVersion(args);
|
||||
if (latestVersion) {
|
||||
console.log(
|
||||
borderedText(`New version of ${args.pkg.name} available!
|
||||
Current Version: ${args.pkg.version}
|
||||
Latest Version: ${latestVersion}`)
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
// Catch any network errors or cache writing errors so module doesn't cause a crash
|
||||
}
|
||||
};
|
||||
|
||||
export default simpleUpdateNotifier;
|
12
node_modules/simple-update-notifier/src/isNpmOrYarn.ts
generated
vendored
Normal file
12
node_modules/simple-update-notifier/src/isNpmOrYarn.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import process from 'process';
|
||||
|
||||
const packageJson = process.env.npm_package_json;
|
||||
const userAgent = process.env.npm_config_user_agent;
|
||||
const isNpm6 = Boolean(userAgent && userAgent.startsWith('npm'));
|
||||
const isNpm7 = Boolean(packageJson && packageJson.endsWith('package.json'));
|
||||
|
||||
const isNpm = isNpm6 || isNpm7;
|
||||
const isYarn = Boolean(userAgent && userAgent.startsWith('yarn'));
|
||||
const isNpmOrYarn = isNpm || isYarn;
|
||||
|
||||
export default isNpmOrYarn;
|
7
node_modules/simple-update-notifier/src/types.ts
generated
vendored
Normal file
7
node_modules/simple-update-notifier/src/types.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export interface IUpdate {
|
||||
pkg: { name: string; version: string };
|
||||
updateCheckInterval?: number;
|
||||
shouldNotifyInNpmScript?: boolean;
|
||||
distTag?: string;
|
||||
alwaysRun?: boolean;
|
||||
}
|
Reference in New Issue
Block a user