Add node modules and package files

This commit is contained in:
Rachael Sewell
2019-09-06 15:17:38 -07:00
parent e84489cd02
commit 714607abe9
165 changed files with 2227 additions and 4644 deletions

View File

@@ -1,7 +1,7 @@
module.exports = parseOptions
const { Deprecation } = require('deprecation')
const getUserAgent = require('universal-user-agent')
const { getUserAgent } = require('universal-user-agent')
const once = require('once')
const pkg = require('../package.json')

View File

@@ -1,35 +0,0 @@
language: node_js
cache: npm
# Trigger a push build on master and greenkeeper branches + PRs build on every branches
# Avoid double build on PRs (See https://github.com/travis-ci/travis-ci/issues/1147)
branches:
only:
- master
- /^greenkeeper.*$/
stages:
- test
- name: release
if: branch = master AND type IN (push)
jobs:
include:
- stage: test
node_js: 12
script: npm run test
- node_js: 8
script: npm run test
- node_js: 10
env: Node 10 & coverage upload
script:
- npm run test
- npm run coverage:upload
- node_js: lts/*
env: browser tests
script: npm run test:browser
- stage: release
node_js: lts/*
env: semantic-release
script: npm run semantic-release

View File

@@ -4,13 +4,13 @@
[![@latest](https://img.shields.io/npm/v/universal-user-agent.svg)](https://www.npmjs.com/package/universal-user-agent)
[![Build Status](https://travis-ci.com/gr2m/universal-user-agent.svg?branch=master)](https://travis-ci.com/gr2m/universal-user-agent)
[![Coverage Status](https://coveralls.io/repos/github/gr2m/universal-user-agent/badge.svg)](https://coveralls.io/github/gr2m/universal-user-agent)
[![Greenkeeper](https://badges.greenkeeper.io/gr2m/universal-user-agent.svg)](https://greenkeeper.io/)
```js
const getUserAgent = require('universal-user-agent')
const userAgent = getUserAgent()
const { getUserAgent } = require("universal-user-agent");
// or import { getUserAgent } from "universal-user-agent";
const userAgent = getUserAgent();
// userAgent will look like this
// in browser: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/61.0"
// in node: Node.js/v8.9.4 (macOS High Sierra; x64)

View File

@@ -1,6 +0,0 @@
module.exports = getUserAgentBrowser
function getUserAgentBrowser () {
/* global navigator */
return navigator.userAgent
}

View File

@@ -1,4 +0,0 @@
{
"integrationFolder": "test",
"video": false
}

View File

@@ -0,0 +1,22 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var osName = _interopDefault(require('os-name'));
function getUserAgent() {
try {
return `Node.js/${process.version.substr(1)} (${osName()}; ${process.arch})`;
} catch (error) {
if (/wmic os get Caption/.test(error.message)) {
return "Windows <version undetectable>";
}
throw error;
}
}
exports.getUserAgent = getUserAgent;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../dist-src/node.js"],"sourcesContent":["import osName from \"os-name\";\nexport function getUserAgent() {\n try {\n return `Node.js/${process.version.substr(1)} (${osName()}; ${process.arch})`;\n }\n catch (error) {\n if (/wmic os get Caption/.test(error.message)) {\n return \"Windows <version undetectable>\";\n }\n throw error;\n }\n}\n"],"names":["getUserAgent","process","version","substr","osName","arch","error","test","message"],"mappings":";;;;;;;;AACO,SAASA,YAAT,GAAwB;MACvB;WACQ,WAAUC,OAAO,CAACC,OAAR,CAAgBC,MAAhB,CAAuB,CAAvB,CAA0B,KAAIC,MAAM,EAAG,KAAIH,OAAO,CAACI,IAAK,GAA1E;GADJ,CAGA,OAAOC,KAAP,EAAc;QACN,sBAAsBC,IAAtB,CAA2BD,KAAK,CAACE,OAAjC,CAAJ,EAA+C;aACpC,gCAAP;;;UAEEF,KAAN;;;;;;"}

View File

@@ -0,0 +1,3 @@
export function getUserAgent() {
return navigator.userAgent;
}

View File

@@ -0,0 +1 @@
export { getUserAgent } from "./node";

View File

@@ -0,0 +1,12 @@
import osName from "os-name";
export function getUserAgent() {
try {
return `Node.js/${process.version.substr(1)} (${osName()}; ${process.arch})`;
}
catch (error) {
if (/wmic os get Caption/.test(error.message)) {
return "Windows <version undetectable>";
}
throw error;
}
}

View File

@@ -0,0 +1 @@
export declare function getUserAgent(): string;

View File

@@ -0,0 +1 @@
export { getUserAgent } from "./node";

View File

@@ -0,0 +1 @@
export declare function getUserAgent(): string;

View File

@@ -0,0 +1,6 @@
function getUserAgent() {
return navigator.userAgent;
}
export { getUserAgent };
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../dist-src/browser.js"],"sourcesContent":["export function getUserAgent() {\n return navigator.userAgent;\n}\n"],"names":[],"mappings":"AAAO,SAAS,YAAY,GAAG;IAC3B,OAAO,SAAS,CAAC,SAAS,CAAC;CAC9B;;;;"}

View File

@@ -1 +0,0 @@
export default function getUserAgentNode(): string;

View File

@@ -1,15 +0,0 @@
module.exports = getUserAgentNode
const osName = require('os-name')
function getUserAgentNode () {
try {
return `Node.js/${process.version.substr(1)} (${osName()}; ${process.arch})`
} catch (error) {
if (/wmic os get Caption/.test(error.message)) {
return 'Windows <version undetectable>'
}
throw error
}
}

View File

@@ -1,85 +1,65 @@
{
"_args": [
[
"universal-user-agent@3.0.0",
"/Users/rachmari/github-repos/hello-world-javascript-action"
]
],
"_from": "universal-user-agent@3.0.0",
"_id": "universal-user-agent@3.0.0",
"_from": "universal-user-agent@^4.0.0",
"_id": "universal-user-agent@4.0.0",
"_inBundle": false,
"_integrity": "sha512-T3siHThqoj5X0benA5H0qcDnrKGXzU8TKoX15x/tQHw1hQBvIEBHjxQ2klizYsqBOO/Q+WuxoQUihadeeqDnoA==",
"_integrity": "sha512-eM8knLpev67iBDizr/YtqkJsF3GK8gzDc6st/WKzrTuPtcsOKW/0IdL4cnMBsU69pOx0otavLWBDGTwg+dB0aA==",
"_location": "/@octokit/rest/universal-user-agent",
"_phantomChildren": {},
"_requested": {
"type": "version",
"type": "range",
"registry": true,
"raw": "universal-user-agent@3.0.0",
"raw": "universal-user-agent@^4.0.0",
"name": "universal-user-agent",
"escapedName": "universal-user-agent",
"rawSpec": "3.0.0",
"rawSpec": "^4.0.0",
"saveSpec": null,
"fetchSpec": "3.0.0"
"fetchSpec": "^4.0.0"
},
"_requiredBy": [
"/@octokit/rest"
],
"_resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-3.0.0.tgz",
"_spec": "3.0.0",
"_where": "/Users/rachmari/github-repos/hello-world-javascript-action",
"author": {
"name": "Gregor Martynus",
"url": "https://github.com/gr2m"
},
"browser": "browser.js",
"_resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-4.0.0.tgz",
"_shasum": "27da2ec87e32769619f68a14996465ea1cb9df16",
"_spec": "universal-user-agent@^4.0.0",
"_where": "/Users/rachmari/github-repos/hello-world-javascript-action/node_modules/@octokit/rest",
"bugs": {
"url": "https://github.com/gr2m/universal-user-agent/issues"
},
"bundleDependencies": false,
"dependencies": {
"os-name": "^3.0.0"
"os-name": "^3.1.0"
},
"deprecated": false,
"description": "Get a user agent string in both browser and node",
"devDependencies": {
"chai": "^4.1.2",
"coveralls": "^3.0.2",
"cypress": "^3.1.0",
"mocha": "^6.0.0",
"nyc": "^14.0.0",
"proxyquire": "^2.1.0",
"@gr2m/pika-plugin-build-web": "^0.6.0-issue-84.1",
"@pika/pack": "^0.5.0",
"@pika/plugin-build-node": "^0.6.0",
"@pika/plugin-ts-standard-pkg": "^0.6.0",
"@types/jest": "^24.0.18",
"jest": "^24.9.0",
"prettier": "^1.18.2",
"semantic-release": "^15.9.15",
"sinon": "^7.2.4",
"sinon-chai": "^3.2.0",
"standard": "^13.0.1",
"test": "^0.6.0",
"travis-deploy-once": "^5.0.7"
"ts-jest": "^24.0.2",
"typescript": "^3.6.2"
},
"files": [
"dist-*/",
"bin/"
],
"homepage": "https://github.com/gr2m/universal-user-agent#readme",
"keywords": [],
"license": "ISC",
"main": "index.js",
"main": "dist-node/index.js",
"module": "dist-web/index.js",
"name": "universal-user-agent",
"pika": true,
"repository": {
"type": "git",
"url": "git+https://github.com/gr2m/universal-user-agent.git"
},
"scripts": {
"coverage": "nyc report --reporter=html && open coverage/index.html",
"coverage:upload": "nyc report --reporter=text-lcov | coveralls",
"pretest": "standard",
"semantic-release": "semantic-release",
"test": "nyc mocha \"test/*-test.js\"",
"test:browser": "cypress run --browser chrome",
"travis-deploy-once": "travis-deploy-once"
},
"standard": {
"globals": [
"describe",
"it",
"beforeEach",
"afterEach",
"expect"
]
},
"types": "index.d.ts",
"version": "3.0.0"
"sideEffects": false,
"source": "dist-src/index.js",
"types": "dist-types/index.d.ts",
"version": "4.0.0"
}

View File

@@ -1,57 +0,0 @@
// make tests run in both Node & Express
if (!global.cy) {
const chai = require('chai')
const sinon = require('sinon')
const sinonChai = require('sinon-chai')
chai.use(sinonChai)
global.expect = chai.expect
let sandbox
beforeEach(() => {
sandbox = sinon.createSandbox()
global.cy = {
stub: function () {
return sandbox.stub.apply(sandbox, arguments)
},
log () {
console.log.apply(console, arguments)
}
}
})
afterEach(() => {
sandbox.restore()
})
}
const getUserAgent = require('..')
describe('smoke', () => {
it('works', () => {
expect(getUserAgent()).to.be.a('string')
expect(getUserAgent().length).to.be.above(10)
})
if (!process.browser) { // test on node only
const proxyquire = require('proxyquire').noCallThru()
it('works around wmic error on Windows (#5)', () => {
const getUserAgent = proxyquire('..', {
'os-name': () => {
throw new Error('Command failed: wmic os get Caption')
}
})
expect(getUserAgent()).to.equal('Windows <version undetectable>')
})
it('does not swallow unexpected errors', () => {
const getUserAgent = proxyquire('..', {
'os-name': () => {
throw new Error('oops')
}
})
expect(getUserAgent).to.throw('oops')
})
}
})

View File

@@ -1,35 +1,30 @@
{
"_args": [
[
"@octokit/rest@16.28.7",
"/Users/rachmari/github-repos/hello-world-javascript-action"
]
],
"_from": "@octokit/rest@16.28.7",
"_id": "@octokit/rest@16.28.7",
"_from": "@octokit/rest@^16.15.0",
"_id": "@octokit/rest@16.28.9",
"_inBundle": false,
"_integrity": "sha512-cznFSLEhh22XD3XeqJw51OLSfyL2fcFKUO+v2Ep9MTAFfFLS1cK1Zwd1yEgQJmJoDnj4/vv3+fGGZweG+xsbIA==",
"_integrity": "sha512-IKGnX+Tvzt7XHhs8f4ajqxyJvYAMNX5nWfoJm4CQj8LZToMiaJgutf5KxxpxoC3y5w7JTJpW5rnWnF4TsIvCLA==",
"_location": "/@octokit/rest",
"_phantomChildren": {
"os-name": "3.1.0"
},
"_requested": {
"type": "version",
"type": "range",
"registry": true,
"raw": "@octokit/rest@16.28.7",
"raw": "@octokit/rest@^16.15.0",
"name": "@octokit/rest",
"escapedName": "@octokit%2frest",
"scope": "@octokit",
"rawSpec": "16.28.7",
"rawSpec": "^16.15.0",
"saveSpec": null,
"fetchSpec": "16.28.7"
"fetchSpec": "^16.15.0"
},
"_requiredBy": [
"/@actions/github"
],
"_resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-16.28.7.tgz",
"_spec": "16.28.7",
"_where": "/Users/rachmari/github-repos/hello-world-javascript-action",
"_resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-16.28.9.tgz",
"_shasum": "ac8c5f3ff305e9e0a0989a5245e4286f057a95d7",
"_spec": "@octokit/rest@^16.15.0",
"_where": "/Users/rachmari/github-repos/hello-world-javascript-action/node_modules/@actions/github",
"author": {
"name": "Gregor Martynus",
"url": "https://github.com/gr2m"
@@ -37,6 +32,7 @@
"bugs": {
"url": "https://github.com/octokit/rest.js/issues"
},
"bundleDependencies": false,
"bundlesize": [
{
"path": "./dist/octokit-rest.min.js.gz",
@@ -73,9 +69,9 @@
"lodash.uniq": "^4.5.0",
"octokit-pagination-methods": "^1.1.0",
"once": "^1.4.0",
"universal-user-agent": "^3.0.0",
"url-template": "^2.0.8"
"universal-user-agent": "^4.0.0"
},
"deprecated": false,
"description": "GitHub REST API client for Node.js",
"devDependencies": {
"@gimenete/type-writer": "^0.1.3",
@@ -102,8 +98,8 @@
"semantic-release": "^15.0.0",
"sinon": "^7.2.4",
"sinon-chai": "^3.0.0",
"sort-keys": "^3.0.0",
"standard": "^13.0.1",
"sort-keys": "^4.0.0",
"standard": "^14.0.2",
"string-to-arraybuffer": "^1.0.0",
"string-to-jsdoc-comment": "^1.0.0",
"typescript": "^3.3.1",
@@ -185,5 +181,5 @@
]
},
"types": "index.d.ts",
"version": "16.28.7"
"version": "16.28.9"
}

View File

@@ -10,20 +10,20 @@ function authenticationBeforeRequest (state, options) {
if (state.auth.type === 'basic') {
const hash = btoa(`${state.auth.username}:${state.auth.password}`)
options.headers['authorization'] = `Basic ${hash}`
options.headers.authorization = `Basic ${hash}`
return
}
if (state.auth.type === 'token') {
options.headers['authorization'] = `token ${state.auth.token}`
options.headers.authorization = `token ${state.auth.token}`
return
}
if (state.auth.type === 'app') {
options.headers['authorization'] = `Bearer ${state.auth.token}`
const acceptHeaders = options.headers['accept'].split(',')
options.headers.authorization = `Bearer ${state.auth.token}`
const acceptHeaders = options.headers.accept.split(',')
.concat('application/vnd.github.machine-man-preview+json')
options.headers['accept'] = uniq(acceptHeaders).filter(Boolean).join(',')
options.headers.accept = uniq(acceptHeaders).filter(Boolean).join(',')
return
}

View File

@@ -6,13 +6,13 @@ const withAuthorizationPrefix = require('./with-authorization-prefix')
function authenticationBeforeRequest (state, options) {
if (typeof state.auth === 'string') {
options.headers['authorization'] = withAuthorizationPrefix(state.auth)
options.headers.authorization = withAuthorizationPrefix(state.auth)
// https://developer.github.com/v3/previews/#integrations
if (/^bearer /i.test(state.auth) && !/machine-man/.test(options.headers['accept'])) {
const acceptHeaders = options.headers['accept'].split(',')
if (/^bearer /i.test(state.auth) && !/machine-man/.test(options.headers.accept)) {
const acceptHeaders = options.headers.accept.split(',')
.concat('application/vnd.github.machine-man-preview+json')
options.headers['accept'] = acceptHeaders.filter(Boolean).join(',')
options.headers.accept = acceptHeaders.filter(Boolean).join(',')
}
return
@@ -20,7 +20,7 @@ function authenticationBeforeRequest (state, options) {
if (state.auth.username) {
const hash = btoa(`${state.auth.username}:${state.auth.password}`)
options.headers['authorization'] = `Basic ${hash}`
options.headers.authorization = `Basic ${hash}`
if (state.otp) {
options.headers['x-github-otp'] = state.otp
}
@@ -40,7 +40,7 @@ function authenticationBeforeRequest (state, options) {
// as well as "/applications/123/tokens/token456"
if (/\/applications\/:?[\w_]+\/tokens\/:?[\w_]+($|\?)/.test(options.url)) {
const hash = btoa(`${state.auth.clientId}:${state.auth.clientSecret}`)
options.headers['authorization'] = `Basic ${hash}`
options.headers.authorization = `Basic ${hash}`
return
}
@@ -56,6 +56,6 @@ function authenticationBeforeRequest (state, options) {
})
.then((authorization) => {
options.headers['authorization'] = withAuthorizationPrefix(authorization)
options.headers.authorization = withAuthorizationPrefix(authorization)
})
}

View File

@@ -2,7 +2,7 @@ module.exports = octokitDebug
function octokitDebug (octokit) {
octokit.hook.wrap('request', (request, options) => {
octokit.log.debug(`request`, options)
octokit.log.debug('request', options)
const start = Date.now()
const requestOptions = octokit.request.endpoint.parse(options)
const path = requestOptions.url.replace(options.baseUrl, '')